summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2018-12-10 18:28:56 -0700
committerJeff Sharkey <jsharkey@android.com>2018-12-11 09:43:13 -0700
commitdc50d4ca389743e6a20af3507b4fa442ed6d07be (patch)
tree7c40b43bd7282b338ba8ce6226853ad29729b285 /core/java
parent52fe5dd97fb749aad4f570914a22aebf8d0de1c1 (diff)
Iteration on contributed media APIs.
Offer an explicit DELETE_CONTRIBUTED_MEDIA flag that can be used when uninstalling an app to indicate that any contributed media should be deleted. Adjust APIs to accept a specific UserHandle so we can pre-flight check for valid UserManager state. Bug: 116344240 Test: atest android.provider.cts.MediaStoreTest Change-Id: Ief0ba27c913791d60f86a5d7252525c9c4539fc6
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/content/pm/PackageManager.java10
-rw-r--r--core/java/android/provider/MediaStore.java52
2 files changed, 42 insertions, 20 deletions
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 0150f6a2765d..da39b6394f8f 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -1399,6 +1399,16 @@ public abstract class PackageManager {
public static final int DELETE_DONT_KILL_APP = 0x00000008;
/**
+ * Flag parameter for {@link #deletePackage} to indicate that any
+ * contributed media should also be deleted during this uninstall. The
+ * meaning of "contributed" means it won't automatically be deleted when the
+ * app is uninstalled.
+ *
+ * @hide
+ */
+ public static final int DELETE_CONTRIBUTED_MEDIA = 0x00000010;
+
+ /**
* Flag parameter for {@link #deletePackage} to indicate that package deletion
* should be chatty.
*
diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java
index 14511657f4d0..7dfd4cd0389e 100644
--- a/core/java/android/provider/MediaStore.java
+++ b/core/java/android/provider/MediaStore.java
@@ -23,7 +23,6 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
-import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
import android.app.Activity;
@@ -50,6 +49,7 @@ import android.os.OperationCanceledException;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.UserHandle;
+import android.os.UserManager;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import android.os.storage.VolumeInfo;
@@ -2882,18 +2882,24 @@ public final class MediaStore {
*
* @hide
*/
- @SystemApi
@TestApi
@RequiresPermission(android.Manifest.permission.CLEAR_APP_USER_DATA)
- public static @BytesLong long getContributedMediaSize(Context context, String packageName) {
- try (ContentProviderClient client = context.getContentResolver()
- .acquireContentProviderClient(AUTHORITY)) {
- final Bundle in = new Bundle();
- in.putString(Intent.EXTRA_PACKAGE_NAME, packageName);
- final Bundle out = client.call(GET_CONTRIBUTED_MEDIA_CALL, null, in);
- return out.getLong(Intent.EXTRA_INDEX);
- } catch (RemoteException e) {
- throw e.rethrowAsRuntimeException();
+ public static @BytesLong long getContributedMediaSize(Context context, String packageName,
+ UserHandle user) throws IOException {
+ final UserManager um = context.getSystemService(UserManager.class);
+ if (um.isUserUnlocked(user) && um.isUserRunning(user)) {
+ try {
+ final ContentResolver resolver = context
+ .createPackageContextAsUser(packageName, 0, user).getContentResolver();
+ final Bundle in = new Bundle();
+ in.putString(Intent.EXTRA_PACKAGE_NAME, packageName);
+ final Bundle out = resolver.call(AUTHORITY, GET_CONTRIBUTED_MEDIA_CALL, null, in);
+ return out.getLong(Intent.EXTRA_INDEX);
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ } else {
+ throw new IOException("User " + user + " must be unlocked and running");
}
}
@@ -2904,17 +2910,23 @@ public final class MediaStore {
*
* @hide
*/
- @SystemApi
@TestApi
@RequiresPermission(android.Manifest.permission.CLEAR_APP_USER_DATA)
- public static void deleteContributedMedia(Context context, String packageName) {
- try (ContentProviderClient client = context.getContentResolver()
- .acquireContentProviderClient(AUTHORITY)) {
- final Bundle in = new Bundle();
- in.putString(Intent.EXTRA_PACKAGE_NAME, packageName);
- client.call(DELETE_CONTRIBUTED_MEDIA_CALL, null, in);
- } catch (RemoteException e) {
- throw e.rethrowAsRuntimeException();
+ public static void deleteContributedMedia(Context context, String packageName,
+ UserHandle user) throws IOException {
+ final UserManager um = context.getSystemService(UserManager.class);
+ if (um.isUserUnlocked(user) && um.isUserRunning(user)) {
+ try {
+ final ContentResolver resolver = context
+ .createPackageContextAsUser(packageName, 0, user).getContentResolver();
+ final Bundle in = new Bundle();
+ in.putString(Intent.EXTRA_PACKAGE_NAME, packageName);
+ resolver.call(AUTHORITY, DELETE_CONTRIBUTED_MEDIA_CALL, null, in);
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ } else {
+ throw new IOException("User " + user + " must be unlocked and running");
}
}
}