From 374a7d704cd70d5b6c6810b3af85d0c0861536eb Mon Sep 17 00:00:00 2001 From: Jay Thomas Sullivan Date: Fri, 24 Jun 2022 13:57:16 -0700 Subject: [PATCH] Fix null handling of getPackagesForOps This method's "ops" argument is documented as null being an acceptable value: @param ops The set of operations you are interested in, or null if you want all of them. However, passing null in fact always leads to a NullPointerException, and so the "if you want all of them" functionality is effectively uninvocable. This commit allows null to be passed, resulting in behavior that matches the documentation. Fix: 182472424 Test: atest RuntimePermissionsAppOpTrackingTest#testGetAllPackagesForAllAppOps Change-Id: Ieba1f401aba6f5607e89fa8b932c66ddf6b73ad4 --- core/java/android/app/AppOpsManager.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index cb64173b78090..4130f80742245 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -7563,10 +7563,15 @@ public class AppOpsManager { @SystemApi @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) public @NonNull List getPackagesForOps(@Nullable String[] ops) { - final int opCount = ops.length; - final int[] opCodes = new int[opCount]; - for (int i = 0; i < opCount; i++) { - opCodes[i] = sOpStrToOp.get(ops[i]); + final int[] opCodes; + if (ops != null) { + final int opCount = ops.length; + opCodes = new int[opCount]; + for (int i = 0; i < opCount; i++) { + opCodes[i] = sOpStrToOp.get(ops[i]); + } + } else { + opCodes = null; } final List result = getPackagesForOps(opCodes); return (result != null) ? result : Collections.emptyList();