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

Commit 70c7ced6 authored by yutingfang's avatar yutingfang Committed by Automerger Merge Worker
Browse files

[DO NOT MERGE] Impose a threshold on the number of attributed op entries...

[DO NOT MERGE] Impose a threshold on the number of attributed op entries returned in a binder call am: 8e7990ce

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/31593362



Change-Id: Id84212886e54e4f0f823e6c1721bb7ec5f1e3942
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents cde50eaa 8e7990ce
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -231,6 +231,12 @@ public class AppOpsService extends IAppOpsService.Stub {
     *  {@link #upgradeLocked(int)} below. The first version was 1 */
    private static final int CURRENT_VERSION = 1;

    /**
     * The upper limit of total number of attributed op entries that can be returned in a binder
     * transaction to avoid TransactionTooLargeException
     */
    private static final int NUM_ATTRIBUTED_OP_ENTRY_THRESHOLD = 2000;

    // Write at most every 30 minutes.
    static final long WRITE_DELAY = DEBUG ? 1000 : 30*60*1000;

@@ -2190,6 +2196,8 @@ public class AppOpsService extends IAppOpsService.Stub {
                Manifest.permission.GET_APP_OPS_STATS,
                Binder.getCallingPid(), Binder.getCallingUid())
                == PackageManager.PERMISSION_GRANTED;
        int totalAttributedOpEntryCount = 0;

        if (ops == null) {
            resOps = new ArrayList<>();
            for (int j = 0; j < pkgOps.size(); j++) {
@@ -2197,7 +2205,12 @@ public class AppOpsService extends IAppOpsService.Stub {
                if (opRestrictsRead(curOp.op) && !shouldReturnRestrictedAppOps) {
                    continue;
                }
                resOps.add(getOpEntryForResult(curOp, elapsedNow));
                if (totalAttributedOpEntryCount > NUM_ATTRIBUTED_OP_ENTRY_THRESHOLD) {
                    break;
                }
                OpEntry opEntry = getOpEntryForResult(curOp, elapsedNow);
                resOps.add(opEntry);
                totalAttributedOpEntryCount += opEntry.getAttributedOpEntries().size();
            }
        } else {
            for (int j = 0; j < ops.length; j++) {
@@ -2209,10 +2222,21 @@ public class AppOpsService extends IAppOpsService.Stub {
                    if (resOps == null) {
                        resOps = new ArrayList<>();
                    }
                    resOps.add(getOpEntryForResult(curOp, elapsedNow));
                    if (totalAttributedOpEntryCount > NUM_ATTRIBUTED_OP_ENTRY_THRESHOLD) {
                        break;
                    }
                    OpEntry opEntry = getOpEntryForResult(curOp, elapsedNow);
                    resOps.add(opEntry);
                    totalAttributedOpEntryCount += opEntry.getAttributedOpEntries().size();
                }
            }
        }

        if (totalAttributedOpEntryCount > NUM_ATTRIBUTED_OP_ENTRY_THRESHOLD) {
            Slog.w(TAG, "The number of attributed op entries has exceeded the threshold. This "
                    + "could be due to DoS attack from malicious apps. The result is throttled.");
        }

        return resOps;
    }