Apply audio restrictions to external vibration
Change ExternalVibratorService to also apply audio restictions from AppOpsManager to incoming external vibrations. Fix: b/162343845 Test: manual Change-Id: Ia874d9cd6eb54a6b984e1e2c10787460474d4b6c
This commit is contained in:
@@ -1066,18 +1066,18 @@ public class VibratorService extends IVibratorService.Stub
|
||||
return attrs.isFlagSet(VibrationAttributes.FLAG_BYPASS_INTERRUPTION_POLICY);
|
||||
}
|
||||
|
||||
private int getAppOpMode(Vibration vib) {
|
||||
private int getAppOpMode(int uid, String packageName, VibrationAttributes attrs) {
|
||||
int mode = mAppOps.checkAudioOpNoThrow(AppOpsManager.OP_VIBRATE,
|
||||
vib.attrs.getAudioAttributes().getUsage(), vib.uid, vib.opPkg);
|
||||
attrs.getAudioAttributes().getUsage(), uid, packageName);
|
||||
if (mode == AppOpsManager.MODE_ALLOWED) {
|
||||
mode = mAppOps.startOpNoThrow(AppOpsManager.OP_VIBRATE, vib.uid, vib.opPkg);
|
||||
mode = mAppOps.startOpNoThrow(AppOpsManager.OP_VIBRATE, uid, packageName);
|
||||
}
|
||||
|
||||
if (mode == AppOpsManager.MODE_IGNORED && shouldBypassDnd(vib.attrs)) {
|
||||
if (mode == AppOpsManager.MODE_IGNORED && shouldBypassDnd(attrs)) {
|
||||
// If we're just ignoring the vibration op then this is set by DND and we should ignore
|
||||
// if we're asked to bypass. AppOps won't be able to record this operation, so make
|
||||
// sure we at least note it in the logs for debugging.
|
||||
Slog.d(TAG, "Bypassing DND for vibration: " + vib);
|
||||
Slog.d(TAG, "Bypassing DND for vibrate from uid " + uid);
|
||||
mode = AppOpsManager.MODE_ALLOWED;
|
||||
}
|
||||
return mode;
|
||||
@@ -1099,7 +1099,7 @@ public class VibratorService extends IVibratorService.Stub
|
||||
return false;
|
||||
}
|
||||
|
||||
final int mode = getAppOpMode(vib);
|
||||
final int mode = getAppOpMode(vib.uid, vib.opPkg, vib.attrs);
|
||||
if (mode != AppOpsManager.MODE_ALLOWED) {
|
||||
if (mode == AppOpsManager.MODE_ERRORED) {
|
||||
// We might be getting calls from within system_server, so we don't actually
|
||||
@@ -1774,7 +1774,7 @@ public class VibratorService extends IVibratorService.Stub
|
||||
return SCALE_MUTE;
|
||||
}
|
||||
if (ActivityManager.checkComponentPermission(android.Manifest.permission.VIBRATE,
|
||||
vib.getUid(), -1 /*owningUid*/, true /*exported*/)
|
||||
vib.getUid(), -1 /*owningUid*/, true /*exported*/)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
Slog.w(TAG, "pkg=" + vib.getPackage() + ", uid=" + vib.getUid()
|
||||
+ " tried to play externally controlled vibration"
|
||||
@@ -1782,6 +1782,14 @@ public class VibratorService extends IVibratorService.Stub
|
||||
return SCALE_MUTE;
|
||||
}
|
||||
|
||||
int mode = getAppOpMode(vib.getUid(), vib.getPackage(), vib.getVibrationAttributes());
|
||||
if (mode != AppOpsManager.MODE_ALLOWED) {
|
||||
if (mode == AppOpsManager.MODE_ERRORED) {
|
||||
Slog.w(TAG, "Would be an error: external vibrate from uid " + vib.getUid());
|
||||
}
|
||||
return SCALE_MUTE;
|
||||
}
|
||||
|
||||
final int scaleLevel;
|
||||
synchronized (mLock) {
|
||||
if (!vib.equals(mCurrentExternalVibration)) {
|
||||
|
||||
Reference in New Issue
Block a user