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: Ifb8a2f4a1e87278ac7df9ff7a579a64bc4a790a8
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:19:42 +00:00
committed by Automerger Merge Worker

View File

@@ -776,10 +776,10 @@ public class RingtoneManager {
return ringtoneUri; return ringtoneUri;
} }
/** /**
* Sets the {@link Uri} of the default sound for a given sound type. * Sets the {@link Uri} of the default sound for a given sound type.
* *
* @param context A context used for querying. * @param context A context used for querying.
* @param type The type whose default sound should be set. One of * @param type The type whose default sound should be set. One of
* {@link #TYPE_RINGTONE}, {@link #TYPE_NOTIFICATION}, or * {@link #TYPE_RINGTONE}, {@link #TYPE_NOTIFICATION}, or
@@ -795,6 +795,21 @@ public class RingtoneManager {
if(!isInternalRingtoneUri(ringtoneUri)) { if(!isInternalRingtoneUri(ringtoneUri)) {
ringtoneUri = ContentProvider.maybeAddUserId(ringtoneUri, context.getUserId()); 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, Settings.System.putStringForUser(resolver, setting,
ringtoneUri != null ? ringtoneUri.toString() : null, context.getUserId()); ringtoneUri != null ? ringtoneUri.toString() : null, context.getUserId());