diff options
| author | 2024-10-29 16:18:29 -0700 | |
|---|---|---|
| committer | 2024-10-29 16:18:29 -0700 | |
| commit | 98f5bde4efe91e3c25fc0dfe5cddfc7beddca475 (patch) | |
| tree | 8a7ecbbf322c8c43194e6df648a4599cef2f1f5d | |
| parent | e1b76619401814ec889004f84ba29b5b4dab36a4 (diff) | |
Add a rate limiter in AppOpsService to prevent excessive loggings
The atom AppOpNoteOpOrCheckOpBinderApiCalled can log excessively on some devices. Add a rate limiter to put the atom logging frequency within the boundry of once per 10 miliseconds.
Flag: EXEMPT log only update
Bug: 365584286
Test: presubmit
Change-Id: Ifd4a5efbb66926c3e88c5fc68a469f75673d1c72
| -rw-r--r-- | services/core/java/com/android/server/appop/AppOpsService.java | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java index b4cce7da4416..e32e2c8c855c 100644 --- a/services/core/java/com/android/server/appop/AppOpsService.java +++ b/services/core/java/com/android/server/appop/AppOpsService.java @@ -182,6 +182,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; @@ -201,6 +202,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; @@ -351,6 +353,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); /* @@ -3135,10 +3141,12 @@ public class AppOpsService extends IAppOpsService.Stub { boolean shouldCollectMessage) { if (Binder.getCallingPid() != Process.myPid() && Flags.appopAccessTrackingLoggingEnabled()) { - 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); + 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, |