Skip to content

Commit ce2f8f4

Browse files
jmtriviAndroid Build Coastguard Worker
authored andcommitted
RingtoneManager: verify default ringtone is audio
When a ringtone picker tries to set a ringtone through RingtoneManager.setActualDefaultRingtoneUri (also called by com.android.settings.DefaultRingtonePreference), verify the mimeType can be obtained (not found when caller doesn't have access to it) and it is an audio resource. Bug: 205837340 Test: atest android.media.audio.cts.RingtoneManagerTest (cherry picked from commit 38618f9) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:88f5aae54cf522e4ec50c2dbf2c782872734db00) Merged-In: I3f2c487ded405c0c1a83ef0a2fe99cff7cc9328e Change-Id: I3f2c487ded405c0c1a83ef0a2fe99cff7cc9328e
1 parent 502a47c commit ce2f8f4

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

media/java/android/media/RingtoneManager.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,10 @@ public static Uri getActualDefaultRingtoneUri(Context context, int type) {
814814

815815
return ringtoneUri;
816816
}
817-
817+
818818
/**
819819
* Sets the {@link Uri} of the default sound for a given sound type.
820-
*
820+
*
821821
* @param context A context used for querying.
822822
* @param type The type whose default sound should be set. One of
823823
* {@link #TYPE_RINGTONE}, {@link #TYPE_NOTIFICATION}, or
@@ -833,6 +833,21 @@ public static void setActualDefaultRingtoneUri(Context context, int type, Uri ri
833833
if(!isInternalRingtoneUri(ringtoneUri)) {
834834
ringtoneUri = ContentProvider.maybeAddUserId(ringtoneUri, context.getUserId());
835835
}
836+
837+
if (ringtoneUri != null) {
838+
final String mimeType = resolver.getType(ringtoneUri);
839+
if (mimeType == null) {
840+
Log.e(TAG, "setActualDefaultRingtoneUri for URI:" + ringtoneUri
841+
+ " ignored: failure to find mimeType (no access from this context?)");
842+
return;
843+
}
844+
if (!(mimeType.startsWith("audio/") || mimeType.equals("application/ogg"))) {
845+
Log.e(TAG, "setActualDefaultRingtoneUri for URI:" + ringtoneUri
846+
+ " ignored: associated mimeType:" + mimeType + " is not an audio type");
847+
return;
848+
}
849+
}
850+
836851
Settings.System.putStringForUser(resolver, setting,
837852
ringtoneUri != null ? ringtoneUri.toString() : null, context.getUserId());
838853

0 commit comments

Comments
 (0)