summaryrefslogtreecommitdiff
path: root/apex
diff options
context:
space:
mode:
author “riyaghai” <riyaghai@google.com> 2025-01-30 16:37:52 +0000
committer Riya Ghai <riyaghai@google.com> 2025-02-17 01:27:32 -0800
commit804ffda5c53b853ef6b1d7297f8d4a0bf5354458 (patch)
treeec0152ee841ef7d324541bfbfacd9f340e914588 /apex
parentf73167ad3062290caa193a8df9ced47508911c69 (diff)
[MediaProvider] Exclude unreliable storage from
MediaStore.getExternalVolumeNames(). Test: MediaProviderChangeIdTest Bug: 391360514 Flag: com.android.providers.media.flags.exclude_unreliable_volumes Change-Id: I3fc6c71b6466ca195f77daf63764a3b3c9a3fc9c
Diffstat (limited to 'apex')
-rw-r--r--apex/framework/java/android/provider/MediaStore.java26
1 files changed, 25 insertions, 1 deletions
diff --git a/apex/framework/java/android/provider/MediaStore.java b/apex/framework/java/android/provider/MediaStore.java
index c9ee81196..b528bf649 100644
--- a/apex/framework/java/android/provider/MediaStore.java
+++ b/apex/framework/java/android/provider/MediaStore.java
@@ -32,6 +32,7 @@ import android.annotation.WorkerThread;
import android.app.Activity;
import android.app.AppOpsManager;
import android.app.PendingIntent;
+import android.app.compat.CompatChanges;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ClipData;
import android.content.ContentProvider;
@@ -61,6 +62,7 @@ import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Environment;
import android.os.OperationCanceledException;
+import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.Parcelable;
import android.os.RemoteException;
@@ -663,6 +665,11 @@ public final class MediaStore {
public static final String INTENT_ACTION_VIDEO_CAMERA = "android.media.action.VIDEO_CAMERA";
/**
+ * This is a copy of the flag that exists in MediaProvider.
+ */
+ static final long EXCLUDE_UNRELIABLE_STORAGE_VOLUMES = 391360514L;
+
+ /**
* Standard Intent action that can be sent to have the camera application
* capture an image and return it.
* <p>
@@ -4734,7 +4741,15 @@ public final class MediaStore {
case Environment.MEDIA_MOUNTED_READ_ONLY: {
final String volumeName = sv.getMediaStoreVolumeName();
if (volumeName != null) {
- res.add(volumeName);
+ File directory = sv.getDirectory();
+ if (shouldExcludeUnReliableStorageVolumes(context)
+ && directory != null
+ && directory.getAbsolutePath() != null
+ && directory.getAbsolutePath().startsWith("/mnt/")) {
+ Log.d(TAG, "skipping unreliable volume : " + volumeName);
+ } else {
+ res.add(volumeName);
+ }
}
break;
}
@@ -4744,6 +4759,15 @@ public final class MediaStore {
}
/**
+ * Checks if the EXCLUDE_UNRELIABLE_STORAGE_VOLUMES appcompat flag is enabled.
+ */
+ private static boolean shouldExcludeUnReliableStorageVolumes(Context context) {
+ return Flags.excludeUnreliableVolumes()
+ && CompatChanges.isChangeEnabled(
+ EXCLUDE_UNRELIABLE_STORAGE_VOLUMES, context.getApplicationInfo().uid);
+ }
+
+ /**
* Works exactly the same as
* {@link ContentResolver#openFileDescriptor(Uri, String, CancellationSignal)}, but only works
* for {@link Uri} whose scheme is {@link ContentResolver#SCHEME_CONTENT} and its authority is