Add QUERY_ARG_DEFER_SCAN systemApi
The flag will indicate if the media scan that was triggered as part of
ContentResolver#update should be asynchronous. This flag should
only be used when ContentResolver#update operation needs to return
early without updating metadata for the file. This may make other
apps see incomplete metadata for the updated file as scan runs
asynchronously here.
When the flag is set, the published file will not appear in default
query until the deferred scan is complete.
Bug: 180326732
Test: presubmit
Change-Id: I1bcdd25c589e25a78f8d2cb501061fd247d550a3
diff --git a/apex/framework/api/system-current.txt b/apex/framework/api/system-current.txt
index 5ce4218..d29a6ed 100644
--- a/apex/framework/api/system-current.txt
+++ b/apex/framework/api/system-current.txt
@@ -8,6 +8,7 @@
method @WorkerThread public static void waitForIdle(@NonNull android.content.ContentResolver);
field public static final String AUTHORITY_LEGACY = "media_legacy";
field @NonNull public static final android.net.Uri AUTHORITY_LEGACY_URI;
+ field public static final String QUERY_ARG_DEFER_SCAN = "android:query-arg-defer-scan";
}
}
diff --git a/apex/framework/java/android/provider/MediaStore.java b/apex/framework/java/android/provider/MediaStore.java
index 4a12ce1..b522420 100644
--- a/apex/framework/java/android/provider/MediaStore.java
+++ b/apex/framework/java/android/provider/MediaStore.java
@@ -709,11 +709,15 @@
* only be used when {@link ContentResolver#update} operation needs to
* return early without updating metadata for the file. This may make other
* apps see incomplete metadata for the updated file as scan runs
- * asynchronously here. Most apps shouldn't set this flag.
+ * asynchronously here.
+ * Note that when this flag is set, the published file will not appear in
+ * default query until the deferred scan is complete.
+ * Most apps shouldn't set this flag.
*
* @hide
*/
- public static final String QUERY_ARG_DO_ASYNC_SCAN = "android:query-arg-do-async-scan";
+ @SystemApi
+ public static final String QUERY_ARG_DEFER_SCAN = "android:query-arg-defer-scan";
/**
* Specify how {@link MediaColumns#IS_PENDING} items should be filtered when
diff --git a/src/com/android/providers/media/MediaProvider.java b/src/com/android/providers/media/MediaProvider.java
index a7839aa..8d1a048 100644
--- a/src/com/android/providers/media/MediaProvider.java
+++ b/src/com/android/providers/media/MediaProvider.java
@@ -306,6 +306,12 @@
private static final String MATCH_PENDING_FROM_FUSE = String.format("lower(%s) NOT REGEXP '%s'",
MediaColumns.DATA, PATTERN_PENDING_FILEPATH_FOR_SQL);
+ /**
+ * This flag is replaced with {@link MediaStore#QUERY_ARG_DEFER_SCAN} from S onwards and only
+ * kept around for app compatibility in R.
+ */
+ private static final String QUERY_ARG_DO_ASYNC_SCAN = "android:query-arg-do-async-scan";
+
// Stolen from: UserHandle#getUserId
private static final int PER_USER_RANGE = 100000;
private static final int MY_UID = android.os.Process.myUid();
@@ -6078,7 +6084,7 @@
new String[] { FileColumns.DATA }, null, null, null)) {
final File file = new File(c.getString(0));
boolean runScanFileInBackground =
- extras.getBoolean(MediaStore.QUERY_ARG_DO_ASYNC_SCAN, false);
+ extras.getBoolean(QUERY_ARG_DO_ASYNC_SCAN, false);
final boolean notifyTranscodeHelper = isUriPublished;
if (runScanFileInBackground) {
helper.postBackground(() -> {