From d188c50e8d9b019ef1e46b327e8cde34822d3952 Mon Sep 17 00:00:00 2001 From: Jay Thomas Sullivan Date: Thu, 9 Nov 2023 19:40:17 -0800 Subject: [Role Logic Move] Call SS, not PC Currently, the methods: - RoleManager::isRoleVisible - RoleManager::isApplicationVisibleForRole ...directly call corresponding RoleControllerManager methods. These are the only two methods in RoleManager that call RoleControllerManager. But, RoleControllerManager calls the RoleControllerService API which runs in PermissionController, and, we want to invoke this logic in System Server. So, call RoleService instead, and have RoleService conditionally route to either System Server or PermissionController depending on the flag state. Bug: 309139048 Test: atest CtsRoleTestCases Change-Id: I417637269d70e28bd2bebcabc85f9ac6a033b0f8 --- .../java/android/app/role/IRoleManager.aidl | 5 +++ framework-s/java/android/app/role/RoleManager.java | 36 ++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) (limited to 'framework-s/java') diff --git a/framework-s/java/android/app/role/IRoleManager.aidl b/framework-s/java/android/app/role/IRoleManager.aidl index 581bb20fa..0aef871e6 100644 --- a/framework-s/java/android/app/role/IRoleManager.aidl +++ b/framework-s/java/android/app/role/IRoleManager.aidl @@ -73,4 +73,9 @@ interface IRoleManager { boolean setBrowserRoleHolder(String packageName, int userId); String getSmsRoleHolder(int userId); + + boolean isRoleVisibleAsUser(in String roleName, int userId); + + boolean isApplicationVisibleForRoleAsUser(in String roleName, in String packageName, + int userId); } diff --git a/framework-s/java/android/app/role/RoleManager.java b/framework-s/java/android/app/role/RoleManager.java index c441d72b6..231c72c2c 100644 --- a/framework-s/java/android/app/role/RoleManager.java +++ b/framework-s/java/android/app/role/RoleManager.java @@ -47,6 +47,7 @@ import androidx.annotation.RequiresApi; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.Preconditions; +import com.android.modules.utils.build.SdkLevel; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -975,10 +976,29 @@ public final class RoleManager { */ @RequiresApi(Build.VERSION_CODES.S) @RequiresPermission(Manifest.permission.MANAGE_ROLE_HOLDERS) + @UserHandleAware(enabledSinceTargetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM) @SystemApi public void isRoleVisible(@NonNull String roleName, @NonNull @CallbackExecutor Executor executor, @NonNull Consumer callback) { - getRoleControllerManager().isRoleVisible(roleName, executor, callback); + if (SdkLevel.isAtLeastV() && Flags.roleControllerInSystemServer()) { + int userId = getContextUserIfAppropriate().getIdentifier(); + boolean visible; + try { + visible = mService.isRoleVisibleAsUser(roleName, userId); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + executor.execute(() -> { + final long token = Binder.clearCallingIdentity(); + try { + callback.accept(visible); + } finally { + Binder.restoreCallingIdentity(token); + } + }); + } else { + getRoleControllerManager().isRoleVisible(roleName, executor, callback); + } } /** @@ -997,11 +1017,21 @@ public final class RoleManager { */ @RequiresApi(Build.VERSION_CODES.S) @RequiresPermission(Manifest.permission.MANAGE_ROLE_HOLDERS) + @UserHandleAware(enabledSinceTargetSdkVersion = Build.VERSION_CODES.VANILLA_ICE_CREAM) @SystemApi public void isApplicationVisibleForRole(@NonNull String roleName, @NonNull String packageName, @NonNull @CallbackExecutor Executor executor, @NonNull Consumer callback) { - getRoleControllerManager().isApplicationVisibleForRole(roleName, packageName, executor, - callback); + if (SdkLevel.isAtLeastV() && Flags.roleControllerInSystemServer()) { + int userId = getContextUserIfAppropriate().getIdentifier(); + try { + mService.isApplicationVisibleForRoleAsUser(roleName, packageName, userId); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } else { + getRoleControllerManager().isApplicationVisibleForRole(roleName, packageName, executor, + callback); + } } @NonNull -- cgit v1.2.3-59-g8ed1b