diff options
author | 2025-02-12 15:12:38 +0000 | |
---|---|---|
committer | 2025-02-12 15:12:38 +0000 | |
commit | 36b75ed3dcd834271d45f4743cfeb25581d0bd3a (patch) | |
tree | e8fc93184b6b1080c97b4b10bdfd0806d4fe434a /src | |
parent | 3d86ac6147ad6979c3bd2277a22d6609cc8a148e (diff) |
Fix the uri for local copies of cloud album cover
Bug: 395887352
Test: atest MediaGroupCursorUtilsTest
Flag: EXEMPT bug fix
Change-Id: Id96115ad30e6213634e1e53dac79ee30249c6363
Diffstat (limited to 'src')
3 files changed, 15 insertions, 8 deletions
diff --git a/src/com/android/providers/media/photopicker/v2/PickerDataLayerV2.java b/src/com/android/providers/media/photopicker/v2/PickerDataLayerV2.java index b39bc5472..3f970463f 100644 --- a/src/com/android/providers/media/photopicker/v2/PickerDataLayerV2.java +++ b/src/com/android/providers/media/photopicker/v2/PickerDataLayerV2.java @@ -354,7 +354,7 @@ public class PickerDataLayerV2 { // This is an external query into the CMP, so catch any exceptions that might get thrown // so that at a minimum, the local results are sent back to the UI. try { - allAlbumCursors.add(getCloudAlbumsCursor(appContext, query, effectiveLocalAuthority, + allAlbumCursors.add(getCloudAlbumsCursor(appContext, query, localAuthority, effectiveCloudAuthority)); } catch (RuntimeException ex) { Log.w(TAG, "Cloud provider exception while fetching cloud albums cursor", ex); @@ -466,7 +466,7 @@ public class PickerDataLayerV2 { // so that at a minimum, the local results are sent back to the UI. try { final Cursor cloudAlbumsCursor = getCloudAlbumsCursor(appContext, query, - effectiveLocalAuthority, effectiveCloudAuthority); + localAuthority, effectiveCloudAuthority); allMediaGroupCursors.add( MediaGroupCursorUtils.getMediaGroupCursorForAlbums(cloudAlbumsCursor, index)); } catch (RuntimeException ex) { diff --git a/src/com/android/providers/media/photopicker/v2/model/AlbumsCursorWrapper.java b/src/com/android/providers/media/photopicker/v2/model/AlbumsCursorWrapper.java index ca82f6db4..a11035868 100644 --- a/src/com/android/providers/media/photopicker/v2/model/AlbumsCursorWrapper.java +++ b/src/com/android/providers/media/photopicker/v2/model/AlbumsCursorWrapper.java @@ -121,15 +121,15 @@ public class AlbumsCursorWrapper extends CursorWrapper { return mCoverAuthority; case UNWRAPPED_COVER_URI: - // TODO(b/317118334): Use local copy of the cover image when available. final String mediaId = getMediaIdFromWrappedCursor(); + if (EMPTY_MEDIA_ID.equals(mediaId)) { return Uri.EMPTY.toString(); } else { return PickerUriResolver .getMediaUri(getEncodedUserAuthority(mCoverAuthority)) .buildUpon() - .appendPath(getMediaIdFromWrappedCursor()) + .appendPath(mediaId) .build() .toString(); } diff --git a/src/com/android/providers/media/photopicker/v2/sqlite/MediaGroupCursorUtils.java b/src/com/android/providers/media/photopicker/v2/sqlite/MediaGroupCursorUtils.java index 443a784e2..8e3034869 100644 --- a/src/com/android/providers/media/photopicker/v2/sqlite/MediaGroupCursorUtils.java +++ b/src/com/android/providers/media/photopicker/v2/sqlite/MediaGroupCursorUtils.java @@ -28,6 +28,7 @@ import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; import com.android.providers.media.PickerUriResolver; import com.android.providers.media.photopicker.PickerSyncController; @@ -80,7 +81,7 @@ public class MediaGroupCursorUtils { * {@link CloudMediaProviderContract.MediaSetColumns} cursor. * @return Cursor with the columns {@link PickerSQLConstants.MediaGroupResponseColumns}. */ - public static Cursor getMediaGroupCursorForMediaSets(Cursor cursor) { + public static Cursor getMediaGroupCursorForMediaSets(@Nullable Cursor cursor) { if (cursor == null) { return null; } @@ -413,18 +414,20 @@ public class MediaGroupCursorUtils { * find the local copy of it and returns the URI of the local copy. Otherwise returns the input * coverUri as it is. */ - private static String maybeGetLocalUri( + @VisibleForTesting + public static String maybeGetLocalUri( @Nullable String rawCoverUri, @NonNull Map<String, String> cloudToLocalIdMap) { if (rawCoverUri == null) { return null; } + final String localAuthority = PickerSyncController.getInstanceOrThrow().getLocalProvider(); try { final Uri coverUri = Uri.parse(rawCoverUri); final String mediaId = coverUri.getLastPathSegment(); if (cloudToLocalIdMap.containsKey(mediaId)) { - return getUri(cloudToLocalIdMap.get(mediaId), coverUri.getAuthority()).toString(); + return getUri(cloudToLocalIdMap.get(mediaId), localAuthority).toString(); } else { return rawCoverUri; } @@ -444,6 +447,10 @@ public class MediaGroupCursorUtils { } private static String getEncodedUserAuthority(String authority) { - return MY_USER_ID + "@" + authority; + if (authority.contains("@")) { + return authority; + } else { + return MY_USER_ID + "@" + authority; + } } } |