diff options
| author | Nate Myren <ntmyren@google.com> | 2021-04-27 15:18:06 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-04-27 15:18:06 +0000 |
| commit | 2af054a29ff82b20fc60508371f4fa811ff64fd6 (patch) | |
| tree | b8686a648ed51d1ec4760716eb765560ea1df384 /core/java/android | |
| parent | 49b78296edaeff1da76eb744be5d690311318df2 (diff) | |
| parent | 599d4db0bda72950c79ac8077fc0d0f6be0aff02 (diff) | |
Merge "Add Executor to Permission Group methods in PermissionControllerManager" into sc-dev
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/permission/PermissionControllerManager.java | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/core/java/android/permission/PermissionControllerManager.java b/core/java/android/permission/PermissionControllerManager.java index a56e821889e0..ca132e975e85 100644 --- a/core/java/android/permission/PermissionControllerManager.java +++ b/core/java/android/permission/PermissionControllerManager.java @@ -725,12 +725,14 @@ public final class PermissionControllerManager { * Get the platform permissions which belong to a particular permission group. * * @param permissionGroupName The permission group whose permissions are desired + * @param executor Executor on which to invoke the callback * @param callback A callback which will receive a list of the platform permissions in the * group, or empty if the group is not a valid platform group, or there * was an exception. */ @RequiresPermission(Manifest.permission.GET_RUNTIME_PERMISSION_GROUP_MAPPING) public void getPlatformPermissionsForGroup(@NonNull String permissionGroupName, + @NonNull @CallbackExecutor Executor executor, @NonNull Consumer<List<String>> callback) { enforceSomePermissionsGrantedToSelf( Manifest.permission.GET_RUNTIME_PERMISSION_GROUP_MAPPING); @@ -738,14 +740,19 @@ public final class PermissionControllerManager { AndroidFuture<List<String>> future = new AndroidFuture<>(); service.getPlatformPermissionsForGroup(permissionGroupName, future); return future; - }).whenComplete((result, err) -> { - if (err != null) { - Log.e(TAG, "Failed to get permissions of " + permissionGroupName, err); - callback.accept(new ArrayList<>()); - } else { - callback.accept(result); + }).whenCompleteAsync((result, err) -> { + final long token = Binder.clearCallingIdentity(); + try { + if (err != null) { + Log.e(TAG, "Failed to get permissions of " + permissionGroupName, err); + callback.accept(new ArrayList<>()); + } else { + callback.accept(result); + } + } finally { + Binder.restoreCallingIdentity(token); } - }); + }, executor); } /** @@ -753,26 +760,32 @@ public final class PermissionControllerManager { * permission. * * @param permissionName The permission name whose group is desired + * @param executor Executor on which to invoke the callback * @param callback A callback which will receive the name of the permission group this * permission belongs to, or null if it has no group, is not a platform * permission, or there was an exception. */ @RequiresPermission(Manifest.permission.GET_RUNTIME_PERMISSION_GROUP_MAPPING) public void getGroupOfPlatformPermission(@NonNull String permissionName, - @NonNull Consumer<String> callback) { + @NonNull @CallbackExecutor Executor executor, @NonNull Consumer<String> callback) { enforceSomePermissionsGrantedToSelf( Manifest.permission.GET_RUNTIME_PERMISSION_GROUP_MAPPING); mRemoteService.postAsync(service -> { AndroidFuture<String> future = new AndroidFuture<>(); service.getGroupOfPlatformPermission(permissionName, future); return future; - }).whenComplete((result, err) -> { - if (err != null) { - Log.e(TAG, "Failed to get group of " + permissionName, err); - callback.accept(null); - } else { - callback.accept(result); + }).whenCompleteAsync((result, err) -> { + final long token = Binder.clearCallingIdentity(); + try { + if (err != null) { + Log.e(TAG, "Failed to get group of " + permissionName, err); + callback.accept(null); + } else { + callback.accept(result); + } + } finally { + Binder.restoreCallingIdentity(token); } - }); + }, executor); } } |
