Skip to content

Commit

Permalink
RingtoneManager: verify default ringtone is audio
Browse files Browse the repository at this point in the history
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
Change-Id: I3f2c487ded405c0c1a83ef0a2fe99cff7cc9328e
  • Loading branch information
jmtrivi committed Dec 7, 2022
1 parent 2591d9d commit 38618f9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions media/java/android/media/RingtoneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,19 @@ public static void setActualDefaultRingtoneUri(Context context, int type, Uri ri
if(!isInternalRingtoneUri(ringtoneUri)) {
ringtoneUri = ContentProvider.maybeAddUserId(ringtoneUri, context.getUserId());
}

final String mimeType = resolver.getType(ringtoneUri);
if (mimeType == null) {
Log.e(TAG, "setActualDefaultRingtoneUri for URI:" + ringtoneUri
+ " ignored: failure to find mimeType (no access from this context?)");
return;
}
if (!(mimeType.startsWith("audio/") || mimeType.equals("application/ogg"))) {
Log.e(TAG, "setActualDefaultRingtoneUri for URI:" + ringtoneUri
+ " ignored: associated mimeType:" + mimeType + " is not an audio type");
return;
}

Settings.System.putStringForUser(resolver, setting,
ringtoneUri != null ? ringtoneUri.toString() : null, context.getUserId());

Expand Down

0 comments on commit 38618f9

Please sign in to comment.