Merge "Ringtone uri should add type query" am: 96d98a9fad am: caf558ecdc am: 8e9f6c8db1

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1426651

Change-Id: Iee41dc3a0540cfd39014a47db43e2ca2c1592e32
This commit is contained in:
Robert Chou
2020-09-17 04:43:11 +00:00
committed by Automerger Merge Worker

View File

@@ -1129,12 +1129,14 @@ public class RingtoneManager {
}
// Try finding the scanned ringtone
final String whichAudio = getQueryStringForType(type);
final String filename = getDefaultRingtoneFilename(type);
final String where = MediaColumns.DISPLAY_NAME + "=?," + whichAudio + "=?";
final Uri baseUri = MediaStore.Audio.Media.INTERNAL_CONTENT_URI;
try (Cursor cursor = context.getContentResolver().query(baseUri,
new String[] { MediaColumns._ID },
MediaColumns.DISPLAY_NAME + "=?",
new String[] { filename }, null)) {
where,
new String[] { filename , "1"}, null)) {
if (cursor.moveToFirst()) {
final Uri ringtoneUri = context.getContentResolver().canonicalizeOrElse(
ContentUris.withAppendedId(baseUri, cursor.getLong(0)));
@@ -1162,4 +1164,13 @@ public class RingtoneManager {
default: throw new IllegalArgumentException();
}
}
private static String getQueryStringForType(int type) {
switch (type) {
case TYPE_RINGTONE: return MediaStore.Audio.AudioColumns.IS_RINGTONE;
case TYPE_NOTIFICATION: return MediaStore.Audio.AudioColumns.IS_NOTIFICATION;
case TYPE_ALARM: return MediaStore.Audio.AudioColumns.IS_ALARM;
default: throw new IllegalArgumentException();
}
}
}