From daf5e2a5b18042870d4b17bae1b48494cf7b4b6f Mon Sep 17 00:00:00 2001 From: "wan.li" Date: Fri, 18 Sep 2020 03:09:39 +0800 Subject: Ringtone uri should add type query When only DisplayName is used to query the default ringtone, the query may be incorrect, because other types of ringtones may contain resources with the same name. It should not happen that other types of ringtone uri are set as the default ringtone of the current type by mistake. Test: manual set all types of default ringtones to use the audio with the same DisplayName as the preset value. See if all types of ringtones are selected in RingtonePickerActivity. Bug: 168431815 Change-Id: Iec46c80b1da929cacc0e04fd9641955ce6e8cfcf --- media/java/android/media/RingtoneManager.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/media/java/android/media/RingtoneManager.java b/media/java/android/media/RingtoneManager.java index 8deb0c4451ea..c75296c73a90 100644 --- a/media/java/android/media/RingtoneManager.java +++ b/media/java/android/media/RingtoneManager.java @@ -1130,11 +1130,13 @@ public class RingtoneManager { // Try finding the scanned ringtone final String filename = getDefaultRingtoneFilename(type); + final String whichAudio = getQueryStringForType(type); + final String where = MediaColumns.DISPLAY_NAME + "=? AND " + 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(); + } + } } -- cgit v1.2.3-59-g8ed1b From 813857d851cf7815038d27bd9246a880dfbcbb06 Mon Sep 17 00:00:00 2001 From: "guofei.xue" Date: Mon, 27 Jul 2020 16:26:39 +0800 Subject: When the mUri is null,it will happen NullPointerException. When test the monkey, the mUri is existed to be null pointer high probability. In order to prevent a null pointer exception, added a judgment condition that the mUri is not null or empty. Test:Perform the monkey test,and See if this NullPointerException will happen again when call the method of android.media.Ringtone#play. Bug: 169292270 Change-Id: I7907f0a376d67bb0a0f50ea155e2aa2f4552b1de --- media/java/android/media/Ringtone.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/media/java/android/media/Ringtone.java b/media/java/android/media/Ringtone.java index d35bc4176cb3..d02b49697821 100644 --- a/media/java/android/media/Ringtone.java +++ b/media/java/android/media/Ringtone.java @@ -372,7 +372,7 @@ public class Ringtone { AudioAttributes.toLegacyStreamType(mAudioAttributes)) != 0) { startLocalPlayer(); } - } else if (mAllowRemote && (mRemotePlayer != null)) { + } else if (mAllowRemote && (mRemotePlayer != null) && (mUri != null)) { final Uri canonicalUri = mUri.getCanonicalUri(); final boolean looping; final float volume; -- cgit v1.2.3-59-g8ed1b