Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 065391ff authored by Lais Andrade's avatar Lais Andrade Committed by Automerger Merge Worker
Browse files

Apply audio restrictions to external vibration am: dae1a663 am: bc6b42f5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12322067

Change-Id: Ie0aa8bcb13cd572a25f8f5bfcc02f23571e05b92
parents 97e02fa1 bc6b42f5
Loading
Loading
Loading
Loading
+15 −7
Original line number Diff line number Diff line
@@ -1062,18 +1062,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;
@@ -1095,7 +1095,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
@@ -1873,6 +1873,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)) {