From 7a8ab729af71dc525911c2812ada051f489fe7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christofer=20=C3=85kersten?= Date: Wed, 20 Mar 2019 17:05:46 -0700 Subject: Fix artist to album link on Q devices In Q a bug in MediaStore is fixed where artist to album mapping was keyed with _id column rather than album_id. This changes so we prefer the album_id column but resort to _id if not found. Bug: 128918172 Test: Manual test on P & Q devices Change-Id: If01eb7b3d64160eb3d08c3e61f36097a9576c397 --- java/com/android/pump/db/AudioStore.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/java/com/android/pump/db/AudioStore.java b/java/com/android/pump/db/AudioStore.java index 9d8edf9..5acac70 100644 --- a/java/com/android/pump/db/AudioStore.java +++ b/java/com/android/pump/db/AudioStore.java @@ -423,14 +423,20 @@ class AudioStore extends ContentObserver { // TODO Remove hardcoded value Uri contentUri = MediaStore.Audio.Artists.Albums.getContentUri("external", artist.getId()); - String[] projection = { - MediaStore.Audio.Media._ID // TODO MediaStore.Audio.Artists.Albums.ALBUM_ID - }; + /* + * On some devices MediaStore doesn't use ALBUM_ID as key from Artist to Album, but rather + * _ID. In order to support these devices we don't pass a projection, to avoid the + * IllegalArgumentException(Invalid column) exception, and then resort to _ID. + */ + String[] projection = null; // { MediaStore.Audio.Artists.Albums.ALBUM_ID }; Cursor cursor = mContentResolver.query(contentUri, projection, null, null, null); if (cursor != null) { try { - int albumIdColumn = cursor.getColumnIndexOrThrow( - MediaStore.Audio.Media._ID); // TODO MediaStore.Audio.Artists.Albums.ALBUM_ID + int albumIdColumn = cursor.getColumnIndex(MediaStore.Audio.Artists.Albums.ALBUM_ID); + if (albumIdColumn < 0) { + // On some devices the ALBUM_ID column doesn't exist and _ID is used instead. + albumIdColumn = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID); + } for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { long albumId = cursor.getLong(albumIdColumn); -- cgit v1.2.3