Merge "RingtoneManager: verify default ringtone is audio" into tm-dev am: 763762e2ec

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21027430

Change-Id: Ief934e66580c718e04a6224be5991f482b6dc2b1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2023-06-08 02:20:50 +00:00
committed by Automerger Merge Worker

View File

@@ -776,10 +776,10 @@ public class RingtoneManager {
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
@@ -795,6 +795,21 @@ public class RingtoneManager {
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());