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
(cherry picked from commit 38618f9)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:b8c2d03b720f0cc200ac59f6cfb411fddc3b119c)
Merged-In: I3f2c487ded405c0c1a83ef0a2fe99cff7cc9328e
Change-Id: I3f2c487ded405c0c1a83ef0a2fe99cff7cc9328e
  • Loading branch information
jmtrivi authored and thestinger committed Oct 3, 2023
1 parent c0a0616 commit 89489ff
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions media/java/android/media/RingtoneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -814,10 +814,10 @@ public static Uri getActualDefaultRingtoneUri(Context context, int type) {

return ringtoneUri;
}

/**
* Sets the {@link Uri} of the default sound for a given sound type.
*
*
* @param context A context used for querying.
* @param type The type whose default sound should be set. One of
* {@link #TYPE_RINGTONE}, {@link #TYPE_NOTIFICATION}, or
Expand All @@ -833,6 +833,21 @@ public static void setActualDefaultRingtoneUri(Context context, int type, Uri ri
if(!isInternalRingtoneUri(ringtoneUri)) {
ringtoneUri = ContentProvider.maybeAddUserId(ringtoneUri, context.getUserId());
}

if (ringtoneUri != null) {
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 89489ff

Please sign in to comment.