summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Sahana Rao <sahanas@google.com> 2020-09-09 10:20:52 +0100
committer android-build-team Robot <android-build-team-robot@google.com> 2020-09-19 10:11:23 +0000
commitd54bbd685bd1b93a24698007c092dcc656747fe4 (patch)
treea3c7fe78d4d12089496f57b450d3a1f2e69bdcdf
parented744c96e80fbc9614eebb2f02fc89026393b7e9 (diff)
Support Playlist#Members uri in LegacMediaProvider
Previously, LegacyMediaProvider mapped all uris to "files" table. To migrate playlist->audio map, we need to query "audio_playlists_map" table. To be able to query "audio_playlists_table", LegacyMediaProvider should map Playlist#Members uri to "audio_playlists_map" table. This is a minimal change in LegacyMediaProvider to map Playlist#Members uri to "audio_playlists_map" table. Any other uri still maps to "files" table. Bug: 165904660 Test: LegacyProviderMigrationTest#testLegacy_PlaylistMap Change-Id: Ib6210c214bab32dfca2a2254e7ca4cf9ff31a6db (cherry picked from commit b9f6864f54dade89afc7afad3a78da567f1c4f14) (cherry picked from commit 9a5c84884f6268ba463864924965419a1772fe12)
-rw-r--r--legacy/src/com/android/providers/media/LegacyMediaProvider.java48
1 files changed, 46 insertions, 2 deletions
diff --git a/legacy/src/com/android/providers/media/LegacyMediaProvider.java b/legacy/src/com/android/providers/media/LegacyMediaProvider.java
index 6e152d4af..e921155a5 100644
--- a/legacy/src/com/android/providers/media/LegacyMediaProvider.java
+++ b/legacy/src/com/android/providers/media/LegacyMediaProvider.java
@@ -26,6 +26,7 @@ import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.OperationApplicationException;
+import android.content.UriMatcher;
import android.content.pm.ProviderInfo;
import android.database.Cursor;
import android.net.Uri;
@@ -99,9 +100,10 @@ public class LegacyMediaProvider extends ContentProvider {
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
+ final String appendedSelection = getAppendedSelection(selection, uri);
final DatabaseHelper helper = getDatabaseForUri(uri);
return helper.runWithoutTransaction((db) -> {
- return db.query("files", projection, selection, selectionArgs,
+ return db.query(getTableName(uri), projection, appendedSelection, selectionArgs,
null, null, sortOrder);
});
}
@@ -151,7 +153,7 @@ public class LegacyMediaProvider extends ContentProvider {
final DatabaseHelper helper = getDatabaseForUri(uri);
final long id = helper.runWithTransaction((db) -> {
- return db.insert("files", null, values);
+ return db.insert(getTableName(uri), null, values);
});
return ContentUris.withAppendedId(uri, id);
}
@@ -166,6 +168,48 @@ public class LegacyMediaProvider extends ContentProvider {
throw new UnsupportedOperationException();
}
+ private static final int AUDIO_PLAYLISTS_ID_MEMBERS = 112;
+ private static final int FILES_ID = 701;
+ private static final UriMatcher BASIC_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
+ static {
+ final UriMatcher basicUriMatcher = BASIC_URI_MATCHER;
+ basicUriMatcher.addURI(MediaStore.AUTHORITY_LEGACY, "*/audio/playlists/#/members",
+ AUDIO_PLAYLISTS_ID_MEMBERS);
+ basicUriMatcher.addURI(MediaStore.AUTHORITY_LEGACY, "*/file/#", FILES_ID);
+ };
+
+ private static String getAppendedSelection(String selection, Uri uri) {
+ String whereClause = "";
+ final int match = BASIC_URI_MATCHER.match(uri);
+ switch (match) {
+ case AUDIO_PLAYLISTS_ID_MEMBERS:
+ whereClause = "playlist_id=" + uri.getPathSegments().get(3);
+ break;
+ case FILES_ID:
+ whereClause = "_id=" + uri.getPathSegments().get(2);
+ break;
+ default:
+ // No additional whereClause required
+ }
+ if (selection == null || selection.isEmpty()) {
+ return whereClause;
+ } else if (whereClause.isEmpty()) {
+ return selection;
+ } else {
+ return whereClause + " AND " + selection;
+ }
+ }
+
+ private static String getTableName(Uri uri) {
+ final int playlistMatch = BASIC_URI_MATCHER.match(uri);
+ if (playlistMatch == AUDIO_PLAYLISTS_ID_MEMBERS) {
+ return "audio_playlists_map";
+ } else {
+ // Return the "files" table by default for all other Uris.
+ return "files";
+ }
+ }
+
@Override
public Bundle call(String authority, String method, String arg, Bundle extras) {
switch (method) {