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

Commit 3255d1a2 authored by Atneya Nair's avatar Atneya Nair
Browse files

appops: checkOp uid mode fgd translation

checkOp (non-raw) currently evaluates the foreground mode in most cases, except if the default mode is MODE_FOREGROUND.

While this is generally not an issue, since this mode is mainly used
with runtime permissions, remove this inconsistency since we are moving
some appops to default mode MODE_FOREGROUND.

Test: CtsAppOpsTestCases
Flag: EXEMPT bugfix
Bug: 294609684
Change-Id: Ic5139358bd5b9e37871decc022cd90bb654a8424
parent 91f155a9
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -423,7 +423,7 @@ public class AppOpsService extends IAppOpsService.Stub {

    /** Hands the definition of foreground and uid states */
    @GuardedBy("this")
    public AppOpsUidStateTracker getUidStateTracker() {
    private AppOpsUidStateTracker getUidStateTracker() {
        if (mUidStateTracker == null) {
            mUidStateTracker = new AppOpsUidStateTrackerImpl(
                    LocalServices.getService(ActivityManagerInternal.class),
@@ -2895,21 +2895,28 @@ public class AppOpsService extends IAppOpsService.Stub {
                        uidState.uid, getPersistentId(virtualDeviceId), code);

                if (rawUidMode != AppOpsManager.opToDefaultMode(code)) {
                    return raw ? rawUidMode : uidState.evalMode(code, rawUidMode);
                    return raw ? rawUidMode :
                        evaluateForegroundMode(/* uid= */ uid, /* op= */ code,
                        /* rawUidMode= */ rawUidMode);
                }
            }

            Op op = getOpLocked(code, uid, packageName, null, false, pvr.bypass, /* edit */ false);
            if (op == null) {
                return AppOpsManager.opToDefaultMode(code);
                return evaluateForegroundMode(
                        /* uid= */ uid,
                        /* op= */ code,
                        /* rawUidMode= */ AppOpsManager.opToDefaultMode(code));
            }
            return raw
                    ? mAppOpsCheckingService.getPackageMode(
                            op.packageName, op.op, UserHandle.getUserId(op.uid))
                    : op.uidState.evalMode(
            var packageMode = mAppOpsCheckingService.getPackageMode(
                    op.packageName,
                    op.op,
                            mAppOpsCheckingService.getPackageMode(
                                    op.packageName, op.op, UserHandle.getUserId(op.uid)));
                    UserHandle.getUserId(op.uid));
            return raw ? packageMode :
                    evaluateForegroundMode(
                        /* uid= */ uid,
                        /* op= */op.op,
                        /* rawUidMode= */ packageMode);
        }
    }

@@ -7003,6 +7010,11 @@ public class AppOpsService extends IAppOpsService.Stub {
                "Requested persistentId for invalid virtualDeviceId: " + virtualDeviceId);
    }

    @GuardedBy("this")
    private int evaluateForegroundMode(int uid, int op, int rawUidMode) {
        return getUidStateTracker().evalMode(uid, op, rawUidMode);
    }

    private final class ClientUserRestrictionState implements DeathRecipient {
        private final IBinder token;