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

Commit 3a95f837 authored by Svet Ganov's avatar Svet Ganov
Browse files

Notify all affected UIDs for user/audio restriction changes

Test: pass: adb shell am instrument -w com.android.frameworks.servicestests
                /android.support.test.runner.AndroidJUnitRunner
      pass: cts-tradefed run cts-dev -m CtsPermissionTestCases
                -t android.permission.cts.AppOpsTest

Bug: 75274546

Change-Id: I788823fcc3ade8a4cf752d64bd11b87b212e4d31
parent c7f6eadf
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -97,6 +97,9 @@ public class AppOpsService extends IAppOpsService.Stub {
    // Write at most every 30 minutes.
    static final long WRITE_DELAY = DEBUG ? 1000 : 30*60*1000;

    // Constant meaning that any UID should be matched when dispatching callbacks
    private static final int UID_ANY = -2;

    Context mContext;
    final AtomicFile mFile;
    final Handler mHandler;
@@ -766,7 +769,7 @@ public class AppOpsService extends IAppOpsService.Stub {

    private void notifyOpChanged(ModeCallback callback, int code,
            int uid, String packageName) {
        if (callback.mUid >= 0 && callback.mUid != uid) {
        if (uid != UID_ANY && callback.mUid >= 0 && callback.mUid != uid) {
            return;
        }
        // There are components watching for mode changes such as window manager
@@ -1114,7 +1117,7 @@ public class AppOpsService extends IAppOpsService.Stub {
        }

        mHandler.sendMessage(PooledLambda.obtainMessage(
                AppOpsService::notifyWatchersOfChange, this, code));
                AppOpsService::notifyWatchersOfChange, this, code, UID_ANY));
    }

    @Override
@@ -2682,7 +2685,7 @@ public class AppOpsService extends IAppOpsService.Stub {

            if (restrictionState.setRestriction(code, restricted, exceptionPackages, userHandle)) {
                mHandler.sendMessage(PooledLambda.obtainMessage(
                        AppOpsService::notifyWatchersOfChange, this, code));
                        AppOpsService::notifyWatchersOfChange, this, code, UID_ANY));
            }

            if (restrictionState.isDefault()) {
@@ -2692,7 +2695,7 @@ public class AppOpsService extends IAppOpsService.Stub {
        }
    }

    private void notifyWatchersOfChange(int code) {
    private void notifyWatchersOfChange(int code, int uid) {
        final ArraySet<ModeCallback> clonedCallbacks;
        synchronized (this) {
            ArraySet<ModeCallback> callbacks = mOpModeWatchers.get(code);
@@ -2702,7 +2705,7 @@ public class AppOpsService extends IAppOpsService.Stub {
            clonedCallbacks = new ArraySet<>(callbacks);
        }

        notifyOpChanged(clonedCallbacks,  code, -1, null);
        notifyOpChanged(clonedCallbacks,  code, uid, null);
    }

    @Override
@@ -2937,7 +2940,7 @@ public class AppOpsService extends IAppOpsService.Stub {
                    for (int j = 0; j < restrictionCount; j++) {
                        if (restrictions[j]) {
                            final int changedCode = j;
                            mHandler.post(() -> notifyWatchersOfChange(changedCode));
                            mHandler.post(() -> notifyWatchersOfChange(changedCode, UID_ANY));
                        }
                    }
                }