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

Commit 6d5c0133 authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by android-build-merger
Browse files

Merge "Notify all affected UIDs for user/audio restriction changes" into pi-dev

am: 069aa9dc

Change-Id: I661b94bbf31828963cd1b752fcdc457f72fa88b8
parents b334f1b2 069aa9dc
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
@@ -2698,7 +2701,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()) {
@@ -2708,7 +2711,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);
@@ -2718,7 +2721,7 @@ public class AppOpsService extends IAppOpsService.Stub {
            clonedCallbacks = new ArraySet<>(callbacks);
        }

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

    @Override
@@ -2953,7 +2956,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));
                        }
                    }
                }