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

Commit 39b34a18 authored by Evan Severson's avatar Evan Severson Committed by Android (Google) Code Review
Browse files

Merge "Add a rate limiter in AppOpsService to prevent excessive loggings" into main

parents ddeb4564 98f5bde4
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -184,6 +184,7 @@ import com.android.server.pm.UserManagerInternal;
import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.PackageState;
import com.android.server.policy.AppOpsPolicy;
import com.android.server.selinux.RateLimiter;

import dalvik.annotation.optimization.NeverCompile;

@@ -203,6 +204,7 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
@@ -353,6 +355,10 @@ public class AppOpsService extends IAppOpsService.Stub {
    @GuardedBy("this")
    private boolean mUidStatesInitialized;

    // A rate limiter to prevent excessive Atom pushing. Used by noteOperation.
    private static final Duration RATE_LIMITER_WINDOW = Duration.ofMillis(10);
    private final RateLimiter mRateLimiter = new RateLimiter(RATE_LIMITER_WINDOW);

    volatile @NonNull HistoricalRegistry mHistoricalRegistry = new HistoricalRegistry(this);

    /*
@@ -3137,11 +3143,13 @@ public class AppOpsService extends IAppOpsService.Stub {
            boolean shouldCollectMessage) {
        if (Binder.getCallingPid() != Process.myPid()
                && Flags.appopAccessTrackingLoggingEnabled()) {
            if (mRateLimiter.tryAcquire()) {
                FrameworkStatsLog.write(
                        APP_OP_NOTE_OP_OR_CHECK_OP_BINDER_API_CALLED, uid, code,
                        APP_OP_NOTE_OP_OR_CHECK_OP_BINDER_API_CALLED__BINDER_API__NOTE_OPERATION,
                        attributionTag != null);
            }
        }
        return mCheckOpsDelegateDispatcher.noteOperation(code, uid, packageName,
                attributionTag, Context.DEVICE_ID_DEFAULT, shouldCollectAsyncNotedOp, message,
                shouldCollectMessage);