Merge "AudioService: validate uid / package name match" into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e842065d99
@@ -2825,8 +2825,8 @@ public class AudioService extends IAudioService.Stub
|
|||||||
if (uid == android.os.Process.SYSTEM_UID) {
|
if (uid == android.os.Process.SYSTEM_UID) {
|
||||||
uid = UserHandle.getUid(getCurrentUserId(), UserHandle.getAppId(uid));
|
uid = UserHandle.getUid(getCurrentUserId(), UserHandle.getAppId(uid));
|
||||||
}
|
}
|
||||||
if (mAppOps.noteOp(STREAM_VOLUME_OPS[streamTypeAlias], uid, callingPackage)
|
// validate calling package and app op
|
||||||
!= AppOpsManager.MODE_ALLOWED) {
|
if (!checkNoteAppOp(STREAM_VOLUME_OPS[streamTypeAlias], uid, callingPackage)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3549,8 +3549,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
if (uid == android.os.Process.SYSTEM_UID) {
|
if (uid == android.os.Process.SYSTEM_UID) {
|
||||||
uid = UserHandle.getUid(getCurrentUserId(), UserHandle.getAppId(uid));
|
uid = UserHandle.getUid(getCurrentUserId(), UserHandle.getAppId(uid));
|
||||||
}
|
}
|
||||||
if (mAppOps.noteOp(STREAM_VOLUME_OPS[streamTypeAlias], uid, callingPackage)
|
if (!checkNoteAppOp(STREAM_VOLUME_OPS[streamTypeAlias], uid, callingPackage)) {
|
||||||
!= AppOpsManager.MODE_ALLOWED) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3985,8 +3984,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
uid = UserHandle.getUid(userId, UserHandle.getAppId(uid));
|
uid = UserHandle.getUid(userId, UserHandle.getAppId(uid));
|
||||||
}
|
}
|
||||||
// If OP_AUDIO_MASTER_VOLUME is set, disallow unmuting.
|
// If OP_AUDIO_MASTER_VOLUME is set, disallow unmuting.
|
||||||
if (!mute && mAppOps.noteOp(AppOpsManager.OP_AUDIO_MASTER_VOLUME, uid, callingPackage)
|
if (!mute && !checkNoteAppOp(AppOpsManager.OP_AUDIO_MASTER_VOLUME, uid, callingPackage)) {
|
||||||
!= AppOpsManager.MODE_ALLOWED) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (userId != UserHandle.getCallingUserId() &&
|
if (userId != UserHandle.getCallingUserId() &&
|
||||||
@@ -4117,8 +4115,7 @@ public class AudioService extends IAudioService.Stub
|
|||||||
? MediaMetrics.Value.MUTE : MediaMetrics.Value.UNMUTE);
|
? MediaMetrics.Value.MUTE : MediaMetrics.Value.UNMUTE);
|
||||||
|
|
||||||
// If OP_MUTE_MICROPHONE is set, disallow unmuting.
|
// If OP_MUTE_MICROPHONE is set, disallow unmuting.
|
||||||
if (!on && mAppOps.noteOp(AppOpsManager.OP_MUTE_MICROPHONE, uid, callingPackage)
|
if (!on && !checkNoteAppOp(AppOpsManager.OP_MUTE_MICROPHONE, uid, callingPackage)) {
|
||||||
!= AppOpsManager.MODE_ALLOWED) {
|
|
||||||
mmi.set(MediaMetrics.Property.EARLY_RETURN, "disallow unmuting").record();
|
mmi.set(MediaMetrics.Property.EARLY_RETURN, "disallow unmuting").record();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -10600,4 +10597,31 @@ public class AudioService extends IAudioService.Stub
|
|||||||
}
|
}
|
||||||
mFullVolumeDevices.remove(audioSystemDeviceOut);
|
mFullVolumeDevices.remove(audioSystemDeviceOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//====================
|
||||||
|
// Helper functions for app ops
|
||||||
|
//====================
|
||||||
|
/**
|
||||||
|
* Validates, and notes an app op for a given uid and package name.
|
||||||
|
* Validation comes from exception catching: a security exception indicates the package
|
||||||
|
* doesn't exist, an IAE indicates the uid and package don't match. The code only checks
|
||||||
|
* if exception was thrown for robustness to code changes in op validation
|
||||||
|
* @param op the app op to check
|
||||||
|
* @param uid the uid of the caller
|
||||||
|
* @param packageName the package to check
|
||||||
|
* @return true if the origin of the call is valid (no uid / package mismatch) and the caller
|
||||||
|
* is allowed to perform the operation
|
||||||
|
*/
|
||||||
|
private boolean checkNoteAppOp(int op, int uid, String packageName) {
|
||||||
|
try {
|
||||||
|
if (mAppOps.noteOp(op, uid, packageName) != AppOpsManager.MODE_ALLOWED) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Error noting op:" + op + " on uid:" + uid + " for package:"
|
||||||
|
+ packageName, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user