summaryrefslogtreecommitdiffstats
path: root/services/core/java/com/android/server/audio/AudioService.java
diff options
context:
space:
mode:
authorKenny Guy <kennyguy@google.com>2015-06-30 19:18:28 +0100
committerKenny Guy <kennyguy@google.com>2015-07-08 19:33:13 +0100
commit70e0c58c2269cd29dfd6420d690da13dc03fd457 (patch)
treec1e8c5954be896d9c7332f144cf01147259576cd /services/core/java/com/android/server/audio/AudioService.java
parent7fe86c4753e88058a7f1a1bf8d0302df9a64bd2e (diff)
downloadframeworks_base-70e0c58c2269cd29dfd6420d690da13dc03fd457.zip
frameworks_base-70e0c58c2269cd29dfd6420d690da13dc03fd457.tar.gz
frameworks_base-70e0c58c2269cd29dfd6420d690da13dc03fd457.tar.bz2
Mute correct user from device policy manager.
Add per user versions of mute methods so device policy manager can mute the correct user. Just persist change if the calling user isn't the current user. Treat calls to audio manager coming from uid 1000 as if they were coming from current user rather than user 0 so that the correct user's user restriction is checked. Bug: 21782066 Bug: 21778905 Change-Id: I51469b741096d8a2ffdc520eaf5b3fd754f2c819
Diffstat (limited to 'services/core/java/com/android/server/audio/AudioService.java')
-rw-r--r--services/core/java/com/android/server/audio/AudioService.java98
1 files changed, 78 insertions, 20 deletions
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index dd4111d..eef3d63 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -1166,6 +1166,11 @@ public class AudioService extends IAudioService.Stub {
return;
}
+ // If we are being called by the system (e.g. hardware keys) check for current user
+ // so we handle user restrictions correctly.
+ if (uid == android.os.Process.SYSTEM_UID) {
+ uid = UserHandle.getUid(getCurrentUserId(), UserHandle.getAppId(uid));
+ }
if (mAppOps.noteOp(STREAM_VOLUME_OPS[streamTypeAlias], uid, callingPackage)
!= AppOpsManager.MODE_ALLOWED) {
return;
@@ -1412,7 +1417,11 @@ public class AudioService extends IAudioService.Stub {
(flags & AudioManager.FLAG_BLUETOOTH_ABS_VOLUME) != 0) {
return;
}
-
+ // If we are being called by the system (e.g. hardware keys) check for current user
+ // so we handle user restrictions correctly.
+ if (uid == android.os.Process.SYSTEM_UID) {
+ uid = UserHandle.getUid(getCurrentUserId(), UserHandle.getAppId(uid));
+ }
if (mAppOps.noteOp(STREAM_VOLUME_OPS[streamTypeAlias], uid, callingPackage)
!= AppOpsManager.MODE_ALLOWED) {
return;
@@ -1540,6 +1549,19 @@ public class AudioService extends IAudioService.Stub {
}
}
+ private int getCurrentUserId() {
+ final long ident = Binder.clearCallingIdentity();
+ try {
+ UserInfo currentUser = ActivityManagerNative.getDefault().getCurrentUser();
+ return currentUser.id;
+ } catch (RemoteException e) {
+ // Activity manager not running, nothing we can do assume user 0.
+ } finally {
+ Binder.restoreCallingIdentity(ident);
+ }
+ return UserHandle.USER_OWNER;
+ }
+
// UI update and Broadcast Intent
private void sendVolumeUpdate(int streamType, int oldIndex, int index, int flags) {
streamType = mStreamVolumeAlias[streamType];
@@ -1733,22 +1755,41 @@ public class AudioService extends IAudioService.Stub {
}
}
- private void setMasterMuteInternal(boolean mute, int flags, String callingPackage, int uid) {
+ private void setMasterMuteInternal(boolean mute, int flags, String callingPackage, int uid,
+ int userId) {
+ // If we are being called by the system check for user we are going to change
+ // so we handle user restrictions correctly.
+ if (uid == android.os.Process.SYSTEM_UID) {
+ uid = UserHandle.getUid(userId, UserHandle.getAppId(uid));
+ }
if (mAppOps.noteOp(AppOpsManager.OP_AUDIO_MASTER_VOLUME, uid, callingPackage)
!= AppOpsManager.MODE_ALLOWED) {
return;
}
- if (mute != AudioSystem.getMasterMute()) {
- setSystemAudioMute(mute);
- AudioSystem.setMasterMute(mute);
- // Post a persist master volume msg
+ if (userId != UserHandle.getCallingUserId() &&
+ mContext.checkCallingOrSelfPermission(
+ android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
+ != PackageManager.PERMISSION_GRANTED) {
+ return;
+ }
+ if (getCurrentUserId() == userId) {
+ if (mute != AudioSystem.getMasterMute()) {
+ setSystemAudioMute(mute);
+ AudioSystem.setMasterMute(mute);
+ // Post a persist master volume msg
+ sendMsg(mAudioHandler, MSG_PERSIST_MASTER_VOLUME_MUTE, SENDMSG_REPLACE, mute ? 1
+ : 0, userId, null, PERSIST_DELAY);
+ sendMasterMuteUpdate(mute, flags);
+
+ Intent intent = new Intent(AudioManager.MASTER_MUTE_CHANGED_ACTION);
+ intent.putExtra(AudioManager.EXTRA_MASTER_VOLUME_MUTED, mute);
+ sendBroadcastToAll(intent);
+ }
+ } else {
+ // If not the current user just persist the setting which will be loaded
+ // on user switch.
sendMsg(mAudioHandler, MSG_PERSIST_MASTER_VOLUME_MUTE, SENDMSG_REPLACE, mute ? 1
- : 0, UserHandle.getCallingUserId(), null, PERSIST_DELAY);
- sendMasterMuteUpdate(mute, flags);
-
- Intent intent = new Intent(AudioManager.MASTER_MUTE_CHANGED_ACTION);
- intent.putExtra(AudioManager.EXTRA_MASTER_VOLUME_MUTED, mute);
- sendBroadcastToAll(intent);
+ : 0, userId, null, PERSIST_DELAY);
}
}
@@ -1757,8 +1798,9 @@ public class AudioService extends IAudioService.Stub {
return AudioSystem.getMasterMute();
}
- public void setMasterMute(boolean mute, int flags, String callingPackage) {
- setMasterMuteInternal(mute, flags, callingPackage, Binder.getCallingUid());
+ public void setMasterMute(boolean mute, int flags, String callingPackage, int userId) {
+ setMasterMuteInternal(mute, flags, callingPackage, Binder.getCallingUid(),
+ userId);
}
/** @see AudioManager#getStreamVolume(int) */
@@ -1804,20 +1846,36 @@ public class AudioService extends IAudioService.Stub {
return mStreamVolumeAlias[AudioSystem.STREAM_SYSTEM];
}
- /** @see AudioManager#setMicrophoneMute(boolean) */
- public void setMicrophoneMute(boolean on, String callingPackage) {
- if (mAppOps.noteOp(AppOpsManager.OP_MUTE_MICROPHONE, Binder.getCallingUid(),
- callingPackage) != AppOpsManager.MODE_ALLOWED) {
+ /** @see AudioManager#setMicrophoneMute(boolean, int) */
+ public void setMicrophoneMute(boolean on, String callingPackage, int userId) {
+ // If we are being called by the system check for user we are going to change
+ // so we handle user restrictions correctly.
+ int uid = Binder.getCallingUid();
+ if (uid == android.os.Process.SYSTEM_UID) {
+ uid = UserHandle.getUid(userId, UserHandle.getAppId(uid));
+ }
+ if (mAppOps.noteOp(AppOpsManager.OP_MUTE_MICROPHONE, uid, callingPackage)
+ != AppOpsManager.MODE_ALLOWED) {
return;
}
if (!checkAudioSettingsPermission("setMicrophoneMute()")) {
return;
}
+ if (userId != UserHandle.getCallingUserId() &&
+ mContext.checkCallingOrSelfPermission(
+ android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
+ != PackageManager.PERMISSION_GRANTED) {
+ return;
+ }
- AudioSystem.muteMicrophone(on);
+ // If mute is for current user actually mute, else just persist the setting
+ // which will be loaded on user switch.
+ if (getCurrentUserId() == userId) {
+ AudioSystem.muteMicrophone(on);
+ }
// Post a persist microphone msg.
sendMsg(mAudioHandler, MSG_PERSIST_MICROPHONE_MUTE, SENDMSG_REPLACE, on ? 1
- : 0, UserHandle.getCallingUserId(), null, PERSIST_DELAY);
+ : 0, userId, null, PERSIST_DELAY);
}
@Override