From d559e782533e1b9071c9945c1b7c056872c4ff29 Mon Sep 17 00:00:00 2001 From: Sahana Rao Date: Tue, 27 Apr 2021 17:13:42 +0100 Subject: [PATCH] Change hasRequestRawExternalStorageAccess() to return integer Previously, hasRequestRawExternalStorageAccess would return null if the app doesn't have requestRawExternalStorageAccess attribute in the manifest. And, return true/false based on the value specified in manifest. Based on API review comments, changed the method to getRequestRawExternalStorageAccess which returns * RAW_EXTERNAL_STORAGE_ACCESS_DEFAULT if app didn't specify requestRawExternalStorageAccess attribute in the manifest. * RAW_EXTERNAL_STORAGE_ACCESS_REQUESTED if the app requested raw external storage access. * RAW_EXTERNAL_STORAGE_ACCESS_NOT_REQUESTED if the app requests to disable raw external storage access The API is not guarded with any system level API permissions, hence changing the API to public API instead of system API. Also added documentation to ensure apps don't misunderstand this API Bug: 185484514 Test: atest packages/providers/MediaProvider Change-Id: Ib7e41ab8ee38389bf44a360e4288d03e58ef44cf --- core/api/current.txt | 4 ++ core/api/system-current.txt | 1 - .../android/content/pm/ApplicationInfo.java | 63 ++++++++++++++----- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index 7ed8b6c17574e..413dc541edc3a 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -11921,6 +11921,7 @@ package android.content.pm { method public int getGwpAsanMode(); method public int getMemtagMode(); method public int getNativeHeapZeroInitialized(); + method public int getRequestRawExternalStorageAccess(); method public boolean isProfileable(); method public boolean isProfileableByShell(); method public boolean isResourceOverlay(); @@ -11976,6 +11977,9 @@ package android.content.pm { field public static final int MEMTAG_DEFAULT = -1; // 0xffffffff field public static final int MEMTAG_OFF = 0; // 0x0 field public static final int MEMTAG_SYNC = 2; // 0x2 + field public static final int RAW_EXTERNAL_STORAGE_ACCESS_DEFAULT = 0; // 0x0 + field public static final int RAW_EXTERNAL_STORAGE_ACCESS_NOT_REQUESTED = 2; // 0x2 + field public static final int RAW_EXTERNAL_STORAGE_ACCESS_REQUESTED = 1; // 0x1 field public static final int ZEROINIT_DEFAULT = -1; // 0xffffffff field public static final int ZEROINIT_DISABLED = 0; // 0x0 field public static final int ZEROINIT_ENABLED = 1; // 0x1 diff --git a/core/api/system-current.txt b/core/api/system-current.txt index c7960dd406ed7..990f43de5ec57 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -2520,7 +2520,6 @@ package android.content.om { package android.content.pm { public class ApplicationInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable { - method @Nullable public Boolean hasRequestRawExternalStorageAccess(); method public boolean isEncryptionAware(); method public boolean isInstantApp(); method public boolean isOem(); diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java index e302f9e404fb1..a3e0473e39ccf 100644 --- a/core/java/android/content/pm/ApplicationInfo.java +++ b/core/java/android/content/pm/ApplicationInfo.java @@ -2141,22 +2141,57 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { } /** - * @return - * - * + * Use default value for + * {@link android.R.styleable#AndroidManifestApplication_requestRawExternalStorageAccess}. + */ + public static final int RAW_EXTERNAL_STORAGE_ACCESS_DEFAULT = 0; + + /** + * Raw external storage was requested by this app. + */ + public static final int RAW_EXTERNAL_STORAGE_ACCESS_REQUESTED = 1; + + /** + * Raw external storage was not requested by this app. + */ + public static final int RAW_EXTERNAL_STORAGE_ACCESS_NOT_REQUESTED = 2; + + /** + * These constants need to match the value of + * {@link android.R.styleable#AndroidManifestApplication_requestRawExternalStorageAccess}. + * in application manifest. * @hide */ - @SuppressWarnings("AutoBoxing") - @SystemApi - @Nullable - public Boolean hasRequestRawExternalStorageAccess() { - return requestRawExternalStorageAccess; + @IntDef(prefix = {"RAW_EXTERNAL_STORAGE_"}, value = { + RAW_EXTERNAL_STORAGE_ACCESS_DEFAULT, + RAW_EXTERNAL_STORAGE_ACCESS_REQUESTED, + RAW_EXTERNAL_STORAGE_ACCESS_NOT_REQUESTED, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface RawExternalStorage {} + + /** + * @return + * + * Note that this doesn't give any hints on whether the app gets raw external storage access or + * not. Also, apps may get raw external storage access by default in some cases, see + * {@link android.R.styleable#AndroidManifestApplication_requestRawExternalStorageAccess}. + */ + public @RawExternalStorage int getRequestRawExternalStorageAccess() { + if (requestRawExternalStorageAccess == null) { + return RAW_EXTERNAL_STORAGE_ACCESS_DEFAULT; + } + return requestRawExternalStorageAccess ? RAW_EXTERNAL_STORAGE_ACCESS_REQUESTED + : RAW_EXTERNAL_STORAGE_ACCESS_NOT_REQUESTED; } /**