Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit b8c2d03

Browse files
committed
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 Change-Id: I3f2c487ded405c0c1a83ef0a2fe99cff7cc9328e Merged-In: I3f2c487ded405c0c1a83ef0a2fe99cff7cc9328e (cherry picked from commit 38618f9)
1 parent 6322292 commit b8c2d03

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

media/java/android/media/RingtoneManager.java

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

777777
return ringtoneUri;
778778
}
779-
779+
780780
/**
781781
* Sets the {@link Uri} of the default sound for a given sound type.
782-
*
782+
*
783783
* @param context A context used for querying.
784784
* @param type The type whose default sound should be set. One of
785785
* {@link #TYPE_RINGTONE}, {@link #TYPE_NOTIFICATION}, or
@@ -795,6 +795,21 @@ public static void setActualDefaultRingtoneUri(Context context, int type, Uri ri
795795
if(!isInternalRingtoneUri(ringtoneUri)) {
796796
ringtoneUri = ContentProvider.maybeAddUserId(ringtoneUri, context.getUserId());
797797
}
798+
799+
if (ringtoneUri != null) {
800+
final String mimeType = resolver.getType(ringtoneUri);
801+
if (mimeType == null) {
802+
Log.e(TAG, "setActualDefaultRingtoneUri for URI:" + ringtoneUri
803+
+ " ignored: failure to find mimeType (no access from this context?)");
804+
return;
805+
}
806+
if (!(mimeType.startsWith("audio/") || mimeType.equals("application/ogg"))) {
807+
Log.e(TAG, "setActualDefaultRingtoneUri for URI:" + ringtoneUri
808+
+ " ignored: associated mimeType:" + mimeType + " is not an audio type");
809+
return;
810+
}
811+
}
812+
798813
Settings.System.putStringForUser(resolver, setting,
799814
ringtoneUri != null ? ringtoneUri.toString() : null, context.getUserId());
800815

0 commit comments

Comments
 (0)