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

Commit 3e84466d authored by yutingfang's avatar yutingfang
Browse files

Pass reject count in batched noteOp call

In batched noteOp calls we pass the aggregated count to the system
server. If the op access is allowed, it will be access count; if the
access is denied, it will be reject count. Currently we don't pass
reject count to HistoricalRegistry for tracking, the default count is 1.

When aggregating noted ops on the client side, we need to account for op
mode, since in rare cases the mode could change during 1 second of
batching time.

Bug: 406281478
Test: atest android.app.appops.cts.HistoricalAppopsTest
Flag: EXEMPT BUG_FIX
Change-Id: I9ea57074cd0024ae25dad65ff287333e5008562e
parent 9b3faeef
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -7731,8 +7731,8 @@ public class AppOpsManager {
                    && Objects.equals(mAttributionTag, that.mAttributionTag)
                    && mVirtualDeviceId == that.mVirtualDeviceId
                    && Objects.equals(mMessage, that.mMessage)
                    && Objects.equals(mShouldCollectAsyncNotedOp, that.mShouldCollectAsyncNotedOp)
                    && Objects.equals(mShouldCollectMessage, that.mShouldCollectMessage);
                    && mShouldCollectAsyncNotedOp == that.mShouldCollectAsyncNotedOp
                    && mShouldCollectMessage == that.mShouldCollectMessage;
        }

        @Override
+5 −5
Original line number Diff line number Diff line
@@ -3462,7 +3462,7 @@ public class AppOpsService extends IAppOpsService.Stub {
            final UidState uidState = ops.uidState;
            if (isOpRestrictedLocked(uid, code, packageName, attributionTag, virtualDeviceId,
                    pvr.bypass, false)) {
                attributedOp.rejected(uidState.getState(), flags);
                attributedOp.rejected(uidState.getState(), flags, notedCount);
                scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag,
                        virtualDeviceId, flags, AppOpsManager.MODE_IGNORED);
                return new SyncNotedAppOp(AppOpsManager.MODE_IGNORED, code, attributionTag,
@@ -3487,7 +3487,7 @@ public class AppOpsService extends IAppOpsService.Stub {
                    if (DEBUG) Slog.d(TAG, "noteOperation: uid reject #" + uidMode + " for code "
                            + switchCode + " (" + code + ") uid " + uid + " package "
                            + packageName + " flags: " + AppOpsManager.flagsToString(flags));
                    attributedOp.rejected(uidState.getState(), flags);
                    attributedOp.rejected(uidState.getState(), flags, notedCount);
                    scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag,
                            virtualDeviceId, flags, uidMode);
                    // TODO(b/333931259): Remove extra logging after this issue is diagnosed.
@@ -3511,7 +3511,7 @@ public class AppOpsService extends IAppOpsService.Stub {
                    if (DEBUG) Slog.d(TAG, "noteOperation: reject #" + mode + " for code "
                            + switchCode + " (" + code + ") uid " + uid + " package "
                            + packageName + " flags: " + AppOpsManager.flagsToString(flags));
                    attributedOp.rejected(uidState.getState(), flags);
                    attributedOp.rejected(uidState.getState(), flags, notedCount);
                    scheduleOpNotedIfNeededLocked(code, uid, packageName, attributionTag,
                            virtualDeviceId, flags, mode);
                    // TODO(b/333931259): Remove extra logging after this issue is diagnosed.
@@ -4126,7 +4126,7 @@ public class AppOpsService extends IAppOpsService.Stub {
                                + packageName + " flags: "
                                + AppOpsManager.flagsToString(flags));
                    }
                    attributedOp.rejected(uidState.getState(), flags);
                    attributedOp.rejected(uidState.getState(), flags, 1);
                    scheduleOpStartedIfNeededLocked(code, uid, packageName, attributionTag,
                            virtualDeviceId, flags, uidMode, startType, attributionFlags,
                            attributionChainId);
@@ -4150,7 +4150,7 @@ public class AppOpsService extends IAppOpsService.Stub {
                                + packageName + " flags: "
                                + AppOpsManager.flagsToString(flags));
                    }
                    attributedOp.rejected(uidState.getState(), flags);
                    attributedOp.rejected(uidState.getState(), flags, 1);
                    scheduleOpStartedIfNeededLocked(code, uid, packageName, attributionTag,
                            virtualDeviceId, flags, mode, startType, attributionFlags,
                            attributionChainId);
+3 −2
Original line number Diff line number Diff line
@@ -160,11 +160,12 @@ final class AttributedOp {
     * @param uidState UID state of the app noteOp is called for
     * @param flags    OpFlags of the call
     */
    public void rejected(@AppOpsManager.UidState int uidState, @AppOpsManager.OpFlags int flags) {
    public void rejected(@AppOpsManager.UidState int uidState, @AppOpsManager.OpFlags int flags,
            int rejectedCount) {
        rejected(System.currentTimeMillis(), uidState, flags);

        mAppOpsService.mHistoricalRegistry.incrementOpRejectedCount(parent.op, parent.uid,
                parent.packageName, tag, uidState, flags);
                parent.packageName, tag, uidState, flags, rejectedCount);
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ public interface HistoricalRegistryInterface {
     */
    void incrementOpRejectedCount(int op, int uid, @NonNull String packageName,
            @Nullable String attributionTag, @AppOpsManager.UidState int uidState,
            @AppOpsManager.OpFlags int flags);
            @AppOpsManager.OpFlags int flags, int rejectCount);

    /**
     * Read historical ops from both aggregated and discrete events based on input filter.
+1 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ public class HistoricalRegistrySql implements HistoricalRegistryInterface {

    @Override
    public void incrementOpRejectedCount(int op, int uid, @NonNull String packageName,
            @Nullable String attributionTag, int uidState, int flags) {
            @Nullable String attributionTag, int uidState, int flags, int rejectCount) {

    }

Loading