diff options
author | Julia Reynolds <juliacr@google.com> | 2014-08-22 11:42:43 -0400 |
---|---|---|
committer | Julia Reynolds <juliacr@google.com> | 2014-08-27 16:25:00 -0400 |
commit | b53453fae037d67e421011936c8fdffe7ba43922 (patch) | |
tree | fc6bc2a6580496a82b5391f360d53604c586cc0b | |
parent | c0dce273a8af0263b660b57c1a05395a0bd2d2e5 (diff) | |
download | frameworks_base-b53453fae037d67e421011936c8fdffe7ba43922.zip frameworks_base-b53453fae037d67e421011936c8fdffe7ba43922.tar.gz frameworks_base-b53453fae037d67e421011936c8fdffe7ba43922.tar.bz2 |
Audio/Micrphone user restriction/multiuser updates.
1. Persist microphone mute state.
2. Set mute state for correct user.
3. Check for settings restrictions as the correct user.
Bug: 17177502
Bug: 16701642
Change-Id: Id8b6cd90c5caceb67fbec862f90aac7ec7a00b3c
4 files changed, 56 insertions, 27 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 95d1351..ae11f47 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -2113,6 +2113,13 @@ public final class Settings { public static final String VOLUME_MASTER_MUTE = "volume_master_mute"; /** + * Microphone mute (int 1 = mute, 0 = not muted). + * + * @hide + */ + public static final String MICROPHONE_MUTE = "microphone_mute"; + + /** * Whether the notifications should use the ring volume (value of 1) or * a separate notification volume (value of 0). In most cases, users * will have this enabled so the notification and ringer volumes will be diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index dae539b..93be082 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -200,6 +200,7 @@ public class AudioService extends IAudioService.Stub { private static final int MSG_UNLOAD_SOUND_EFFECTS = 20; private static final int MSG_SYSTEM_READY = 21; private static final int MSG_PERSIST_MUSIC_ACTIVE_MS = 22; + private static final int MSG_PERSIST_MICROPHONE_MUTE = 23; // start of messages handled under wakelock // these messages can only be queued, i.e. sent with queueMsgUnderWakeLock(), // and not with sendMsg(..., ..., SENDMSG_QUEUE, ...) @@ -873,6 +874,10 @@ public class AudioService extends IAudioService.Stub { AudioSystem.setMasterMute(masterMute); broadcastMasterMuteStatus(masterMute); + boolean microphoneMute = + System.getIntForUser(cr, System.MICROPHONE_MUTE, 0, UserHandle.USER_CURRENT) == 1; + AudioSystem.muteMicrophone(microphoneMute); + // Each stream will read its own persisted settings // Broadcast the sticky intent @@ -1447,17 +1452,15 @@ public class AudioService extends IAudioService.Stub { if (mUseFixedVolume) { return; } - if (mAppOps.noteOp(AppOpsManager.OP_AUDIO_MASTER_VOLUME, Binder.getCallingUid(), callingPackage) != AppOpsManager.MODE_ALLOWED) { return; } - if (state != AudioSystem.getMasterMute()) { AudioSystem.setMasterMute(state); // Post a persist master volume msg sendMsg(mAudioHandler, MSG_PERSIST_MASTER_VOLUME_MUTE, SENDMSG_REPLACE, state ? 1 - : 0, 0, null, PERSIST_DELAY); + : 0, UserHandle.getCallingUserId(), null, PERSIST_DELAY); sendMasterMuteUpdate(state, flags); } } @@ -1563,6 +1566,9 @@ public class AudioService extends IAudioService.Stub { } AudioSystem.muteMicrophone(on); + // Post a persist microphone msg. + sendMsg(mAudioHandler, MSG_PERSIST_MICROPHONE_MUTE, SENDMSG_REPLACE, on ? 1 + : 0, UserHandle.getCallingUserId(), null, PERSIST_DELAY); } /** @see AudioManager#getRingerMode() */ @@ -3819,7 +3825,6 @@ public class AudioService extends IAudioService.Stub { @Override public void handleMessage(Message msg) { - switch (msg.what) { case MSG_SET_DEVICE_VOLUME: @@ -3851,7 +3856,7 @@ public class AudioService extends IAudioService.Stub { Settings.System.putIntForUser(mContentResolver, Settings.System.VOLUME_MASTER_MUTE, msg.arg1, - UserHandle.USER_CURRENT); + msg.arg2); break; case MSG_PERSIST_RINGER_MODE: @@ -4046,6 +4051,12 @@ public class AudioService extends IAudioService.Stub { Settings.Secure.UNSAFE_VOLUME_MUSIC_ACTIVE_MS, musicActiveMs, UserHandle.USER_CURRENT); break; + case MSG_PERSIST_MICROPHONE_MUTE: + Settings.System.putIntForUser(mContentResolver, + Settings.System.MICROPHONE_MUTE, + msg.arg1, + msg.arg2); + break; } } } diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java index 87c015c..4ef2189 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java @@ -318,10 +318,10 @@ public class SettingsProvider extends ContentProvider { } } - private void checkUserRestrictions(String setting) { + private void checkUserRestrictions(String setting, int userId) { String userRestriction = sRestrictedKeys.get(setting); if (!TextUtils.isEmpty(userRestriction) - && mUserManager.hasUserRestriction(userRestriction)) { + && mUserManager.hasUserRestriction(userRestriction, new UserHandle(userId))) { throw new SecurityException( "Permission denial: user is restricted from changing this setting."); } @@ -936,7 +936,7 @@ public class SettingsProvider extends ContentProvider { try { int numValues = values.length; for (int i = 0; i < numValues; i++) { - checkUserRestrictions(values[i].getAsString(Settings.Secure.NAME)); + checkUserRestrictions(values[i].getAsString(Settings.Secure.NAME), callingUser); if (db.insert(args.table, null, values[i]) < 0) return 0; SettingsCache.populate(cache, values[i]); if (LOCAL_LOGV) Log.v(TAG, args.table + " <- " + values[i]); @@ -1067,7 +1067,7 @@ public class SettingsProvider extends ContentProvider { // Check write permissions only after determining which table the insert will touch checkWritePermissions(args); - checkUserRestrictions(name); + checkUserRestrictions(name, desiredUserHandle); // The global table is stored under the owner, always if (TABLE_GLOBAL.equals(args.table)) { @@ -1143,7 +1143,7 @@ public class SettingsProvider extends ContentProvider { callingUser = UserHandle.USER_OWNER; } checkWritePermissions(args); - checkUserRestrictions(initialValues.getAsString(Settings.Secure.NAME)); + checkUserRestrictions(initialValues.getAsString(Settings.Secure.NAME), callingUser); final AtomicInteger mutationCount = sKnownMutationsInFlight.get(callingUser); mutationCount.incrementAndGet(); diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 3bc226a..554ed32 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -4595,7 +4595,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { @Override public void setUserRestriction(ComponentName who, String key, boolean enabled) { final UserHandle userHandle = new UserHandle(UserHandle.getCallingUserId()); - synchronized (this) { if (who == null) { throw new NullPointerException("ComponentName is null"); @@ -4606,13 +4605,28 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { if (!isDeviceOwner && DEVICE_OWNER_USER_RESTRICTIONS.contains(key)) { throw new SecurityException("Profile owners cannot set user restriction " + key); } + boolean alreadyRestricted = mUserManager.hasUserRestriction(key, userHandle); + + IAudioService iAudioService = null; + if (UserManager.DISALLOW_UNMUTE_MICROPHONE.equals(key) + || UserManager.DISALLOW_ADJUST_VOLUME.equals(key)) { + iAudioService = IAudioService.Stub.asInterface( + ServiceManager.getService(Context.AUDIO_SERVICE)); + } + if (enabled && !alreadyRestricted) { + try { + if (UserManager.DISALLOW_UNMUTE_MICROPHONE.equals(key)) { + iAudioService.setMicrophoneMute(true, who.getPackageName()); + } else if (UserManager.DISALLOW_ADJUST_VOLUME.equals(key)) { + iAudioService.setMasterMute(true, 0, who.getPackageName(), null); + } + } catch (RemoteException re) { + Slog.e(LOG_TAG, "Failed to talk to AudioService.", re); + } + } long id = Binder.clearCallingIdentity(); try { - AudioManager audioManager = - (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); - boolean alreadyRestricted = mUserManager.hasUserRestriction(key); - if (enabled && !alreadyRestricted) { if (UserManager.DISALLOW_CONFIG_WIFI.equals(key)) { Settings.Secure.putIntForUser(mContext.getContentResolver(), @@ -4643,25 +4657,22 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS, 0, userHandle.getIdentifier()); - } else if (UserManager.DISALLOW_UNMUTE_MICROPHONE.equals(key)) { - audioManager.setMicrophoneMute(true); - } else if (UserManager.DISALLOW_ADJUST_VOLUME.equals(key)) { - audioManager.setMasterMute(true); } } - mUserManager.setUserRestriction(key, enabled, userHandle); - - if (!enabled && alreadyRestricted) { + } finally { + restoreCallingIdentity(id); + } + if (!enabled && alreadyRestricted) { + try { if (UserManager.DISALLOW_UNMUTE_MICROPHONE.equals(key)) { - audioManager.setMicrophoneMute(false); + iAudioService.setMicrophoneMute(false, who.getPackageName()); } else if (UserManager.DISALLOW_ADJUST_VOLUME.equals(key)) { - audioManager.setMasterMute(false); + iAudioService.setMasterMute(false, 0, who.getPackageName(), null); } + } catch (RemoteException re) { + Slog.e(LOG_TAG, "Failed to talk to AudioService.", re); } - - } finally { - restoreCallingIdentity(id); } } } |