From 9959d337c13f6d7a52209cb275cad0143ff1cd34 Mon Sep 17 00:00:00 2001 From: Robin Lee Date: Wed, 3 Nov 2021 10:45:24 +0100 Subject: [PATCH] Remove RingtoneManager.*SyncFromParent APIs These operations can be done already if the caller has WRITE_SECURE_SETTINGS_PERMISSION, and the only approved callers are settings apps which have that permission. We don't want anyone else to bypass the permission check and turn off parent sounds sync. Test: atest SettingsRoboTests Bug: 204555055 Change-Id: I47956428f5363affef29af9dbe3d3dde21c5a392 --- media/java/android/media/IAudioService.aidl | 2 -- media/java/android/media/RingtoneManager.java | 31 ------------------- .../android/server/audio/AudioService.java | 16 ---------- 3 files changed, 49 deletions(-) diff --git a/media/java/android/media/IAudioService.aidl b/media/java/android/media/IAudioService.aidl index 5b05cd3216c6b..436a3a5d8c617 100755 --- a/media/java/android/media/IAudioService.aidl +++ b/media/java/android/media/IAudioService.aidl @@ -268,8 +268,6 @@ interface IAudioService { List getActivePlaybackConfigurations(); - void disableRingtoneSync(in int userId); - int getFocusRampTimeMs(in int focusGain, in AudioAttributes attr); int dispatchFocusChange(in AudioFocusInfo afi, in int focusChange, diff --git a/media/java/android/media/RingtoneManager.java b/media/java/android/media/RingtoneManager.java index 3e7b8860c8181..a6f244fa796fb 100644 --- a/media/java/android/media/RingtoneManager.java +++ b/media/java/android/media/RingtoneManager.java @@ -748,32 +748,6 @@ public class RingtoneManager { return null; } - /** - * Disables Settings.System.SYNC_PARENT_SOUNDS. - * - * @hide - */ - public static void disableSyncFromParent(Context userContext) { - IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); - IAudioService audioService = IAudioService.Stub.asInterface(b); - try { - audioService.disableRingtoneSync(userContext.getUserId()); - } catch (RemoteException e) { - Log.e(TAG, "Unable to disable ringtone sync."); - } - } - - /** - * Enables Settings.System.SYNC_PARENT_SOUNDS for the content's user - * - * @hide - */ - @RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS) - public static void enableSyncFromParent(Context userContext) { - Settings.Secure.putIntForUser(userContext.getContentResolver(), - Settings.Secure.SYNC_PARENT_SOUNDS, 1 /* true */, userContext.getUserId()); - } - /** * Gets the current default sound's {@link Uri}. This will give the actual * sound {@link Uri}, instead of using this, most clients can use @@ -818,11 +792,6 @@ public class RingtoneManager { if (setting == null) return; final ContentResolver resolver = context.getContentResolver(); - if (Settings.Secure.getIntForUser(resolver, Settings.Secure.SYNC_PARENT_SOUNDS, 0, - context.getUserId()) == 1) { - // Parent sound override is enabled. Disable it using the audio service. - disableSyncFromParent(context); - } if(!isInternalRingtoneUri(ringtoneUri)) { ringtoneUri = ContentProvider.maybeAddUserId(ringtoneUri, context.getUserId()); } diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 34277a2b64b8e..a0817a51cb7a0 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -10023,22 +10023,6 @@ public class AudioService extends IAudioService.Stub mRecordMonitor.releaseRecorder(riid); } - public void disableRingtoneSync(final int userId) { - final int callingUserId = UserHandle.getCallingUserId(); - if (callingUserId != userId) { - mContext.enforceCallingOrSelfPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, - "disable sound settings syncing for another profile"); - } - final long token = Binder.clearCallingIdentity(); - try { - // Disable the sync setting so the profile uses its own sound settings. - Settings.Secure.putIntForUser(mContentResolver, Settings.Secure.SYNC_PARENT_SOUNDS, - 0 /* false */, userId); - } finally { - Binder.restoreCallingIdentity(token); - } - } - //====================== // Audio playback notification //======================