diff options
Diffstat (limited to 'framework-s/java')
-rw-r--r-- | framework-s/java/android/app/role/IRoleManager.aidl | 5 | ||||
-rw-r--r-- | framework-s/java/android/app/role/RoleManager.java | 36 |
2 files changed, 38 insertions, 3 deletions
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<Boolean> 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<Boolean> 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 |