Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9efa7b80 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

APIs to measure and delete contributed files.

In the new isolated storage world, apps can "contribute" media that
belongs to the user, which normally means it won't be deleted when
that app is uninstalled.  However, we're anticipating that some apps
might abuse this API to preserve data the user actually wants to
delete during uninstall.

This set of changes introduces new APIs to measure and delete these
contributed media items, along with tests to verify.

Bug: 116344240
Test: atest android.provider.cts.MediaStoreTest
Change-Id: Ib740e0ea74378569572cb17640ef607aaa6baf1f
parent e770d22d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -4533,6 +4533,11 @@ package android.provider {
    field public static final int FLAG_REMOVABLE_USB = 524288; // 0x80000
  }

  public final class MediaStore {
    method public static void deleteContributedMedia(android.content.Context, java.lang.String);
    method public static long getContributedMediaSize(android.content.Context, java.lang.String);
  }

  public abstract class SearchIndexableData {
    ctor public SearchIndexableData();
    ctor public SearchIndexableData(android.content.Context);
+5 −0
Original line number Diff line number Diff line
@@ -983,6 +983,11 @@ package android.provider {
    field public static final android.net.Uri CORP_CONTENT_URI;
  }

  public final class MediaStore {
    method public static void deleteContributedMedia(android.content.Context, java.lang.String);
    method public static long getContributedMediaSize(android.content.Context, java.lang.String);
  }

  public final class Settings {
    field public static final java.lang.String ACTION_ENTERPRISE_PRIVACY_SETTINGS = "android.settings.ENTERPRISE_PRIVACY_SETTINGS";
  }
+52 −0
Original line number Diff line number Diff line
@@ -16,11 +16,15 @@

package android.provider;

import android.annotation.BytesLong;
import android.annotation.IntRange;
import android.annotation.NonNull;
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;
import android.app.AppGlobals;
@@ -102,6 +106,11 @@ public final class MediaStore {
    /** {@hide} */
    public static final String GET_MEDIA_URI_CALL = "get_media_uri";

    /** {@hide} */
    public static final String GET_CONTRIBUTED_MEDIA_CALL = "get_contributed_media";
    /** {@hide} */
    public static final String DELETE_CONTRIBUTED_MEDIA_CALL = "delete_contributed_media";

    /**
     * This is for internal use by the media scanner only.
     * Name of the (optional) Uri parameter that determines whether to skip deleting
@@ -2865,4 +2874,47 @@ public final class MediaStore {
            throw e.rethrowAsRuntimeException();
        }
    }

    /**
     * Calculate size of media contributed by given package under the calling
     * user. The meaning of "contributed" means it won't automatically be
     * deleted when the app is uninstalled.
     *
     * @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();
        }
    }

    /**
     * Delete all media contributed by given package under the calling user. The
     * meaning of "contributed" means it won't automatically be deleted when the
     * app is uninstalled.
     *
     * @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();
        }
    }
}