Use separate variables as indices in nested loops
Otherwise the loop might be stuck forever if
- mActiveWatchers.size() > mActiveWatchers.get(0).size()
Test: adb shell dumpsys appops
Fixes: 133230634
Change-Id: I324b1750cf1e45a543e7a498407fbeadc98aba1b
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index 3bed9c3..0a76845 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -3814,8 +3814,9 @@
if (mActiveWatchers.size() > 0 && dumpMode < 0) {
needSep = true;
boolean printedHeader = false;
- for (int i = 0; i < mActiveWatchers.size(); i++) {
- final SparseArray<ActiveCallback> activeWatchers = mActiveWatchers.valueAt(i);
+ for (int watcherNum = 0; watcherNum < mActiveWatchers.size(); watcherNum++) {
+ final SparseArray<ActiveCallback> activeWatchers =
+ mActiveWatchers.valueAt(watcherNum);
if (activeWatchers.size() <= 0) {
continue;
}
@@ -3833,16 +3834,16 @@
}
pw.print(" ");
pw.print(Integer.toHexString(System.identityHashCode(
- mActiveWatchers.keyAt(i))));
+ mActiveWatchers.keyAt(watcherNum))));
pw.println(" ->");
pw.print(" [");
final int opCount = activeWatchers.size();
- for (i = 0; i < opCount; i++) {
- if (i > 0) {
+ for (int opNum = 0; opNum < opCount; opNum++) {
+ if (opNum > 0) {
pw.print(' ');
}
- pw.print(AppOpsManager.opToName(activeWatchers.keyAt(i)));
- if (i < opCount - 1) {
+ pw.print(AppOpsManager.opToName(activeWatchers.keyAt(opNum)));
+ if (opNum < opCount - 1) {
pw.print(',');
}
}