diff --git a/core/api/test-current.txt b/core/api/test-current.txt index a9b21463ebf65..775ded777f43a 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -467,13 +467,10 @@ package android.app.prediction { package android.app.role { - public class RoleControllerManager { - method @RequiresPermission(android.Manifest.permission.MANAGE_ROLE_HOLDERS) public void isApplicationVisibleForRole(@NonNull String, @NonNull String, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer); - method @RequiresPermission(android.Manifest.permission.MANAGE_ROLE_HOLDERS) public void isRoleVisible(@NonNull String, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer); - } - public final class RoleManager { method @Nullable public String getSmsRoleHolder(int); + method @RequiresPermission(android.Manifest.permission.MANAGE_ROLE_HOLDERS) public void isApplicationVisibleForRole(@NonNull String, @NonNull String, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer); + method @RequiresPermission(android.Manifest.permission.MANAGE_ROLE_HOLDERS) public void isRoleVisible(@NonNull String, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer); } } diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index dd016a2cf78e3..fe13fd48109aa 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -31,7 +31,6 @@ import android.app.contentsuggestions.IContentSuggestionsManager; import android.app.job.JobSchedulerFrameworkInitializer; import android.app.people.PeopleManager; import android.app.prediction.AppPredictionManager; -import android.app.role.RoleControllerManager; import android.app.role.RoleManager; import android.app.search.SearchUiManager; import android.app.slice.SliceManager; @@ -1315,14 +1314,6 @@ public final class SystemServiceRegistry { return new RoleManager(ctx.getOuterContext()); }}); - registerService(Context.ROLE_CONTROLLER_SERVICE, RoleControllerManager.class, - new CachedServiceFetcher() { - @Override - public RoleControllerManager createService(ContextImpl ctx) - throws ServiceNotFoundException { - return new RoleControllerManager(ctx.getOuterContext()); - }}); - registerService(Context.DYNAMIC_SYSTEM_SERVICE, DynamicSystemManager.class, new CachedServiceFetcher() { @Override diff --git a/core/java/android/app/role/RoleControllerManager.java b/core/java/android/app/role/RoleControllerManager.java index 8dde2c55d7d30..ba1f612906317 100644 --- a/core/java/android/app/role/RoleControllerManager.java +++ b/core/java/android/app/role/RoleControllerManager.java @@ -20,8 +20,6 @@ import android.Manifest; import android.annotation.CallbackExecutor; import android.annotation.NonNull; import android.annotation.RequiresPermission; -import android.annotation.SystemService; -import android.annotation.TestApi; import android.app.ActivityThread; import android.content.ComponentName; import android.content.Context; @@ -48,8 +46,6 @@ import java.util.function.Consumer; * * @hide */ -@SystemService(Context.ROLE_CONTROLLER_SERVICE) -@TestApi public class RoleControllerManager { private static final String LOG_TAG = RoleControllerManager.class.getSimpleName(); @@ -198,33 +194,12 @@ public class RoleControllerManager { propagateCallback(operation, "onClearRoleHolders", callback); } - /** - * @see RoleControllerService#onIsApplicationQualifiedForRole(String, String) - * - * @deprecated Use {@link #isApplicationVisibleForRole(String, String, Executor, Consumer)} - * instead. - * - * @hide - */ - @RequiresPermission(Manifest.permission.MANAGE_ROLE_HOLDERS) - public void isApplicationQualifiedForRole(@NonNull String roleName, @NonNull String packageName, - @NonNull @CallbackExecutor Executor executor, @NonNull Consumer callback) { - AndroidFuture operation = mRemoteService.postAsync(service -> { - AndroidFuture future = new AndroidFuture<>(); - service.isApplicationQualifiedForRole(roleName, packageName, - new RemoteCallback(future::complete)); - return future; - }); - propagateCallback(operation, "isApplicationQualifiedForRole", executor, callback); - } - /** * @see RoleControllerService#onIsApplicationVisibleForRole(String, String) * * @hide */ @RequiresPermission(Manifest.permission.MANAGE_ROLE_HOLDERS) - @TestApi public void isApplicationVisibleForRole(@NonNull String roleName, @NonNull String packageName, @NonNull @CallbackExecutor Executor executor, @NonNull Consumer callback) { AndroidFuture operation = mRemoteService.postAsync(service -> { @@ -242,7 +217,6 @@ public class RoleControllerManager { * @hide */ @RequiresPermission(Manifest.permission.MANAGE_ROLE_HOLDERS) - @TestApi public void isRoleVisible(@NonNull String roleName, @NonNull @CallbackExecutor Executor executor, @NonNull Consumer callback) { AndroidFuture operation = mRemoteService.postAsync(service -> { diff --git a/core/java/android/app/role/RoleManager.java b/core/java/android/app/role/RoleManager.java index 8b2e07b097019..0fcf44d2dda63 100644 --- a/core/java/android/app/role/RoleManager.java +++ b/core/java/android/app/role/RoleManager.java @@ -174,6 +174,9 @@ public final class RoleManager { @NonNull private final Object mListenersLock = new Object(); + @NonNull + private final RoleControllerManager mRoleControllerManager; + /** * @hide */ @@ -181,6 +184,7 @@ public final class RoleManager { mContext = context; mService = IRoleManager.Stub.asInterface(ServiceManager.getServiceOrThrow( Context.ROLE_SERVICE)); + mRoleControllerManager = new RoleControllerManager(context); } /** @@ -676,6 +680,44 @@ public final class RoleManager { } } + /** + * Check whether a role should be visible to user. + * + * @param roleName name of the role to check for + * @param executor the executor to execute callback on + * @param callback the callback to receive whether the role should be visible to user + * + * @hide + */ + @RequiresPermission(Manifest.permission.MANAGE_ROLE_HOLDERS) + @TestApi + public void isRoleVisible(@NonNull String roleName, + @NonNull @CallbackExecutor Executor executor, @NonNull Consumer callback) { + mRoleControllerManager.isRoleVisible(roleName, executor, callback); + } + + /** + * Check whether an application is visible for a role. + * + * While an application can be qualified for a role, it can still stay hidden from user (thus + * not visible). If an application is visible for a role, we may show things related to the role + * for it, e.g. showing an entry pointing to the role settings in its application info page. + * + * @param roleName the name of the role to check for + * @param packageName the package name of the application to check for + * @param executor the executor to execute callback on + * @param callback the callback to receive whether the application is visible for the role + * + * @hide + */ + @RequiresPermission(Manifest.permission.MANAGE_ROLE_HOLDERS) + @TestApi + public void isApplicationVisibleForRole(@NonNull String roleName, @NonNull String packageName, + @NonNull @CallbackExecutor Executor executor, @NonNull Consumer callback) { + mRoleControllerManager.isApplicationVisibleForRole(roleName, packageName, executor, + callback); + } + private static class OnRoleHoldersChangedListenerDelegate extends IOnRoleHoldersChangedListener.Stub { diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 5ccceca9a69dc..5214e026073f4 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -4832,16 +4832,6 @@ public abstract class Context { */ public static final String ROLE_SERVICE = "role"; - /** - * Official published name of the (internal) role controller service. - * - * @see #getSystemService(String) - * @see android.app.role.RoleControllerService - * - * @hide - */ - public static final String ROLE_CONTROLLER_SERVICE = "role_controller"; - /** * Use with {@link #getSystemService(String)} to retrieve a * {@link android.hardware.camera2.CameraManager} for interacting with