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
This commit is contained in:
@@ -7563,10 +7563,15 @@ public class AppOpsManager {
|
||||
@SystemApi
|
||||
@RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS)
|
||||
public @NonNull List<AppOpsManager.PackageOps> 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<AppOpsManager.PackageOps> result = getPackagesForOps(opCodes);
|
||||
return (result != null) ? result : Collections.emptyList();
|
||||
|
||||
Reference in New Issue
Block a user