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

Commit 2bc2febd authored by Andrei Stingaceanu's avatar Andrei Stingaceanu
Browse files

Suspend apps - disable audio/vibrations

Do not allow audio or vibrations for suspended apps.

Bug: 22776761
Bug: 26949521
Bug: 26954754
Bug: 26953560
Change-Id: I181288823e38efdb1631bc26ee23278697eeb0f5
parent 186b5439
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server;

import static android.content.pm.ApplicationInfo.FLAG_SUSPENDED;

import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
@@ -882,6 +884,11 @@ public class AppOpsService extends IAppOpsService.Stub {

    @Override
    public int checkAudioOperation(int code, int usage, int uid, String packageName) {
        if (isApplicationSuspended(packageName, uid)) {
            Log.i(TAG, "Audio disabled for suspended package=" + packageName + " for uid=" + uid);
            return AppOpsManager.MODE_IGNORED;
        }

        synchronized (this) {
            final int mode = checkRestrictionLocked(code, usage, uid, packageName);
            if (mode != AppOpsManager.MODE_ALLOWED) {
@@ -891,6 +898,23 @@ public class AppOpsService extends IAppOpsService.Stub {
        return checkOperation(code, uid, packageName);
    }

    private boolean isApplicationSuspended(String pkg, int uid) {
        int userId = UserHandle.getUserId(uid);

        ApplicationInfo ai;
        try {
            ai = AppGlobals.getPackageManager().getApplicationInfo(pkg, 0, userId);
            if (ai == null) {
                Log.w(TAG, "No application info for package " + pkg + " and user " + userId);
                return false;
            }
        } catch (RemoteException re) {
            throw new SecurityException("Could not talk to package manager service");
        }

        return ((ai.flags & FLAG_SUSPENDED) != 0);
    }

    private int checkRestrictionLocked(int code, int usage, int uid, String packageName) {
        final SparseArray<Restriction> usageRestrictions = mAudioRestrictions.get(code);
        if (usageRestrictions != null) {