[automerge] No-op refactor of ExternalDbFacade#getMediaCollectionInfo 2p: 4d6ecc85f6

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/providers/MediaProvider/+/17659185

Bug: 228312259
Change-Id: Icf2d8461c7db83890c813c17b588780cf66bb3ac
diff --git a/src/com/android/providers/media/photopicker/PhotoPickerProvider.java b/src/com/android/providers/media/photopicker/PhotoPickerProvider.java
index eab4085..00b17a9 100644
--- a/src/com/android/providers/media/photopicker/PhotoPickerProvider.java
+++ b/src/com/android/providers/media/photopicker/PhotoPickerProvider.java
@@ -149,19 +149,7 @@
         final CloudProviderQueryExtras queryExtras =
                 CloudProviderQueryExtras.fromCloudMediaBundle(extras);
 
-        Bundle bundle = new Bundle();
-        try (Cursor cursor = mDbFacade.getMediaCollectionInfo(queryExtras.getGeneration())) {
-            if (cursor.moveToFirst()) {
-                int generationIndex = cursor.getColumnIndexOrThrow(
-                        MediaCollectionInfo.LAST_MEDIA_SYNC_GENERATION);
-
-                bundle.putString(MediaCollectionInfo.MEDIA_COLLECTION_ID,
-                        MediaStore.getVersion(getContext()));
-                bundle.putLong(MediaCollectionInfo.LAST_MEDIA_SYNC_GENERATION,
-                        cursor.getLong(generationIndex));
-            }
-        }
-        return bundle;
+        return mDbFacade.getMediaCollectionInfo(queryExtras.getGeneration());
     }
 
     @Override
diff --git a/src/com/android/providers/media/photopicker/data/ExternalDbFacade.java b/src/com/android/providers/media/photopicker/data/ExternalDbFacade.java
index 4b89288..839fc9b 100644
--- a/src/com/android/providers/media/photopicker/data/ExternalDbFacade.java
+++ b/src/com/android/providers/media/photopicker/data/ExternalDbFacade.java
@@ -305,7 +305,7 @@
      * Returns the total count and max {@link MediaColumns#GENERATION_MODIFIED} value
      * of the media items in the files table greater than {@code generation}.
      */
-    public Cursor getMediaCollectionInfo(long generation) {
+    private Cursor getMediaCollectionInfoCursor(long generation) {
         final String[] selectionArgs = new String[] {String.valueOf(generation)};
         final String[] projection = new String[] {
             MediaCollectionInfo.LAST_MEDIA_SYNC_GENERATION
@@ -346,6 +346,22 @@
             });
     }
 
+    public Bundle getMediaCollectionInfo(long generation) {
+        final Bundle bundle = new Bundle();
+        try (Cursor cursor = getMediaCollectionInfoCursor(generation)) {
+            if (cursor.moveToFirst()) {
+                int generationIndex = cursor.getColumnIndexOrThrow(
+                        MediaCollectionInfo.LAST_MEDIA_SYNC_GENERATION);
+
+                bundle.putString(MediaCollectionInfo.MEDIA_COLLECTION_ID,
+                        MediaStore.getVersion(mContext));
+                bundle.putLong(MediaCollectionInfo.LAST_MEDIA_SYNC_GENERATION,
+                        cursor.getLong(generationIndex));
+            }
+        }
+        return bundle;
+    }
+
     /**
      * Returns the media item categories from the files table.
      * Categories are determined with the {@link #LOCAL_ALBUM_IDS}.
diff --git a/tests/src/com/android/providers/media/photopicker/data/ExternalDbFacadeTest.java b/tests/src/com/android/providers/media/photopicker/data/ExternalDbFacadeTest.java
index 31d2721..1f9cdb2 100644
--- a/tests/src/com/android/providers/media/photopicker/data/ExternalDbFacadeTest.java
+++ b/tests/src/com/android/providers/media/photopicker/data/ExternalDbFacadeTest.java
@@ -23,6 +23,7 @@
 import static android.provider.CloudMediaProviderContract.EXTRA_ALBUM_ID;
 import static android.provider.CloudMediaProviderContract.EXTRA_MEDIA_COLLECTION_ID;
 import static android.provider.CloudMediaProviderContract.EXTRA_SYNC_GENERATION;
+import static android.provider.CloudMediaProviderContract.MediaCollectionInfo;
 import static android.provider.MediaStore.Files.FileColumns._SPECIAL_FORMAT_GIF;
 import static android.provider.MediaStore.Files.FileColumns._SPECIAL_FORMAT_NONE;
 
@@ -625,26 +626,14 @@
             cv.put(MediaColumns.GENERATION_MODIFIED, GENERATION_MODIFIED2);
             helper.runWithTransaction(db -> db.insert(TABLE_FILES, null, cv));
 
-            try (Cursor cursor = facade.getMediaCollectionInfo(/* generation */ 0)) {
-                assertThat(cursor.getCount()).isEqualTo(1);
+            Bundle bundle = facade.getMediaCollectionInfo(/* generation */ 0);
+            assertMediaCollectionInfo(facade, bundle, /* generation */ 2);
 
-                cursor.moveToFirst();
-                assertMediaCollectionInfo(facade, cursor, /* count */ 2, /* generation */ 2);
-            }
+            bundle = facade.getMediaCollectionInfo(GENERATION_MODIFIED1);
+            assertMediaCollectionInfo(facade, bundle, /* generation */ 2);
 
-            try (Cursor cursor = facade.getMediaCollectionInfo(GENERATION_MODIFIED1)) {
-                assertThat(cursor.getCount()).isEqualTo(1);
-
-                cursor.moveToFirst();
-                assertMediaCollectionInfo(facade, cursor, /* count */ 1, GENERATION_MODIFIED2);
-            }
-
-            try (Cursor cursor = facade.getMediaCollectionInfo(GENERATION_MODIFIED2)) {
-                assertThat(cursor.getCount()).isEqualTo(1);
-
-                cursor.moveToFirst();
-                assertMediaCollectionInfo(facade, cursor, /* count */ 0, /* generation */ 0);
-            }
+            bundle = facade.getMediaCollectionInfo(GENERATION_MODIFIED2);
+            assertMediaCollectionInfo(facade, bundle, /* generation */ 0);
         }
     }
 
@@ -661,12 +650,8 @@
             cvDeleted.put(MediaColumns.GENERATION_MODIFIED, GENERATION_MODIFIED2);
             helper.runWithTransaction(db -> db.insert(TABLE_DELETED_MEDIA, null, cvDeleted));
 
-            try (Cursor cursor = facade.getMediaCollectionInfo(/* generation */ 0)) {
-                assertThat(cursor.getCount()).isEqualTo(1);
-
-                cursor.moveToFirst();
-                assertMediaCollectionInfo(facade, cursor, /* count */ 1, /* generation */ 2);
-            }
+            Bundle bundle = facade.getMediaCollectionInfo(/* generation */ 0);
+            assertMediaCollectionInfo(facade, bundle, /* generation */ 2);
         }
     }
 
@@ -867,12 +852,13 @@
         assertThat(cursor.getLong(countIndex)).isEqualTo(count);
     }
 
-    private static void assertMediaCollectionInfo(ExternalDbFacade facade, Cursor cursor,
-            long count, long generation) {
-        int generationIndex = cursor.getColumnIndex(
-                CloudMediaProviderContract.MediaCollectionInfo.LAST_MEDIA_SYNC_GENERATION);
+    private static void assertMediaCollectionInfo(ExternalDbFacade facade, Bundle bundle,
+            long expectedGeneration) {
+        long generation = bundle.getLong(MediaCollectionInfo.LAST_MEDIA_SYNC_GENERATION);
+        String mediaCollectionId = bundle.getString(MediaCollectionInfo.MEDIA_COLLECTION_ID);
 
-        assertThat(cursor.getLong(generationIndex)).isEqualTo(generation);
+        assertThat(generation).isEqualTo(expectedGeneration);
+        assertThat(mediaCollectionId).isEqualTo(MediaStore.getVersion(sIsolatedContext));
     }
 
     private static Cursor queryAllMedia(ExternalDbFacade facade) {