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

Commit 5208f1b0 authored by Yuting Fang's avatar Yuting Fang Committed by Android (Google) Code Review
Browse files

Merge "Impose a threshold on the number of attributed op entries returned in a...

Merge "Impose a threshold on the number of attributed op entries returned in a binder call" into main
parents 12a36837 eec34e27
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -237,6 +237,13 @@ public class AppOpsService extends IAppOpsService.Stub {
     */
    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;


    private SensorPrivacyManager mSensorPrivacyManager;

    // Write at most every 30 minutes.
@@ -1702,6 +1709,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++) {
@@ -1709,7 +1718,12 @@ public class AppOpsService extends IAppOpsService.Stub {
                if (opRestrictsRead(curOp.op) && !shouldReturnRestrictedAppOps) {
                    continue;
                }
                resOps.add(getOpEntryForResult(curOp, persistentDeviceId));
                if (totalAttributedOpEntryCount > NUM_ATTRIBUTED_OP_ENTRY_THRESHOLD) {
                    break;
                }
                OpEntry opEntry = getOpEntryForResult(curOp, persistentDeviceId);
                resOps.add(opEntry);
                totalAttributedOpEntryCount += opEntry.getAttributedOpEntries().size();
            }
        } else {
            for (int j = 0; j < ops.length; j++) {
@@ -1721,10 +1735,21 @@ public class AppOpsService extends IAppOpsService.Stub {
                    if (opRestrictsRead(curOp.op) && !shouldReturnRestrictedAppOps) {
                        continue;
                    }
                    resOps.add(getOpEntryForResult(curOp, persistentDeviceId));
                    if (totalAttributedOpEntryCount > NUM_ATTRIBUTED_OP_ENTRY_THRESHOLD) {
                        break;
                    }
                    OpEntry opEntry = getOpEntryForResult(curOp, persistentDeviceId);
                    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;
    }