[Role Logic Move] Migrate isVisible behavior

The goal of this change is to move any remaining PermissionController-specific dependencies out of RoleControllerServiceImpl. This includes the following two methods calls:

- RoleUiBehaviorUtils::isVisibleAsUser
- RoleUiBehaviorUtils::isApplicationVisibleAsUser

...which in turn call RoleUiBehavior::isVisibleAsUser and RoleUiBehavior::isApplicationVisibleAsUser, which are implemented in various RoleUiBehavior implementations.

Move all of this logic into the role-controller module. After this change, RoleControllerServiceImpl now calls:

- Role::isVisibleAsUser
- Role::isApplicationVisibleAsUser

...which in turn call RoleBehavior::isVisibleAsUser and RoleBehavior::isApplicationVisibleAsUser, which are implemented in various RoleBehavior implementations. (All of these classes are in role-controller.)

Also, our RoleUiBehavior implementations fetch app resources. But, resources are app-specific, some of our behaviors need PermissionController-specific resources, and those behaviors currently assume that PermissionController is the "current" app, and therefore this will break if we move this code to SystemServer. So, change the behaviors to explicitly fetch the resource from SystemServer or PermissionController as needed (now encapsulated within VisibilityMixin), without assuming the current app.

Bug: 309139048
Test: atest CtsRoleTestCases
Change-Id: I949969aa59f18c26ce3e11c59c8d8f1e72f013a4
diff --git a/PermissionController/role-controller/java/com/android/role/controller/behavior/AssistantRoleBehavior.java b/PermissionController/role-controller/java/com/android/role/controller/behavior/AssistantRoleBehavior.java
index 7ab0b9b..c20734c 100644
--- a/PermissionController/role-controller/java/com/android/role/controller/behavior/AssistantRoleBehavior.java
+++ b/PermissionController/role-controller/java/com/android/role/controller/behavior/AssistantRoleBehavior.java
@@ -38,6 +38,7 @@
 
 import com.android.role.controller.model.Role;
 import com.android.role.controller.model.RoleBehavior;
+import com.android.role.controller.model.VisibilityMixin;
 import com.android.role.controller.util.UserUtils;
 
 import org.xmlpull.v1.XmlPullParserException;
@@ -193,4 +194,10 @@
 
         return true;
     }
+
+    @Override
+    public boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
+            @NonNull Context context) {
+        return VisibilityMixin.isVisible("config_showDefaultAssistant", false, user, context);
+    }
 }
diff --git a/PermissionController/role-controller/java/com/android/role/controller/behavior/BrowserRoleBehavior.java b/PermissionController/role-controller/java/com/android/role/controller/behavior/BrowserRoleBehavior.java
index f64c3bc..0261e1e 100644
--- a/PermissionController/role-controller/java/com/android/role/controller/behavior/BrowserRoleBehavior.java
+++ b/PermissionController/role-controller/java/com/android/role/controller/behavior/BrowserRoleBehavior.java
@@ -31,6 +31,7 @@
 import com.android.role.controller.model.Permissions;
 import com.android.role.controller.model.Role;
 import com.android.role.controller.model.RoleBehavior;
+import com.android.role.controller.model.VisibilityMixin;
 import com.android.role.controller.util.CollectionUtils;
 import com.android.role.controller.util.PackageUtils;
 import com.android.role.controller.util.UserUtils;
@@ -154,4 +155,10 @@
             }
         }
     }
+
+    @Override
+    public boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
+            @NonNull Context context) {
+        return VisibilityMixin.isVisible("config_showBrowserRole", true, user, context);
+    }
 }
diff --git a/PermissionController/role-controller/java/com/android/role/controller/behavior/DialerRoleBehavior.java b/PermissionController/role-controller/java/com/android/role/controller/behavior/DialerRoleBehavior.java
index d0ee2d5..57b5412 100644
--- a/PermissionController/role-controller/java/com/android/role/controller/behavior/DialerRoleBehavior.java
+++ b/PermissionController/role-controller/java/com/android/role/controller/behavior/DialerRoleBehavior.java
@@ -26,6 +26,7 @@
 import com.android.role.controller.model.Permissions;
 import com.android.role.controller.model.Role;
 import com.android.role.controller.model.RoleBehavior;
+import com.android.role.controller.model.VisibilityMixin;
 import com.android.role.controller.util.PackageUtils;
 
 import java.util.Arrays;
@@ -73,4 +74,10 @@
                     user, context);
         }
     }
+
+    @Override
+    public boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
+            @NonNull Context context) {
+        return VisibilityMixin.isVisible("config_showDialerRole", true, user, context);
+    }
 }
diff --git a/PermissionController/role-controller/java/com/android/role/controller/behavior/EmergencyRoleBehavior.java b/PermissionController/role-controller/java/com/android/role/controller/behavior/EmergencyRoleBehavior.java
index 5c23a99..f19c865 100644
--- a/PermissionController/role-controller/java/com/android/role/controller/behavior/EmergencyRoleBehavior.java
+++ b/PermissionController/role-controller/java/com/android/role/controller/behavior/EmergencyRoleBehavior.java
@@ -26,6 +26,7 @@
 
 import com.android.role.controller.model.Role;
 import com.android.role.controller.model.RoleBehavior;
+import com.android.role.controller.model.VisibilityMixin;
 import com.android.role.controller.util.PackageUtils;
 
 import java.util.List;
@@ -68,4 +69,10 @@
         }
         return fallbackPackageInfo != null ? fallbackPackageInfo.packageName : null;
     }
+
+    @Override
+    public boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
+            @NonNull Context context) {
+        return VisibilityMixin.isVisible("config_showDefaultEmergency", false, user, context);
+    }
 }
diff --git a/PermissionController/role-controller/java/com/android/role/controller/behavior/HomeRoleBehavior.java b/PermissionController/role-controller/java/com/android/role/controller/behavior/HomeRoleBehavior.java
index 5bdd5f6..4bf5a62 100644
--- a/PermissionController/role-controller/java/com/android/role/controller/behavior/HomeRoleBehavior.java
+++ b/PermissionController/role-controller/java/com/android/role/controller/behavior/HomeRoleBehavior.java
@@ -35,6 +35,7 @@
 import com.android.role.controller.model.Permissions;
 import com.android.role.controller.model.Role;
 import com.android.role.controller.model.RoleBehavior;
+import com.android.role.controller.model.VisibilityMixin;
 import com.android.role.controller.util.UserUtils;
 
 import java.util.Arrays;
@@ -113,7 +114,7 @@
     /**
      * Check if the application is a settings application
      */
-    public static boolean isSettingsApplicationAsUser(@NonNull ApplicationInfo applicationInfo,
+    private static boolean isSettingsApplicationAsUser(@NonNull ApplicationInfo applicationInfo,
             @NonNull UserHandle user, @NonNull Context context) {
         Context userContext = UserUtils.getUserContext(context, user);
         PackageManager userPackageManager = userContext.getPackageManager();
@@ -213,4 +214,17 @@
         final int flags = permissionInfo.getProtectionFlags();
         return (flags & PermissionInfo.PROTECTION_FLAG_ROLE) == PermissionInfo.PROTECTION_FLAG_ROLE;
     }
+
+    @Override
+    public boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
+            @NonNull Context context) {
+        return VisibilityMixin.isVisible("config_showDefaultHome", false, user, context);
+    }
+
+    @Override
+    public boolean isApplicationVisibleAsUser(@NonNull Role role,
+            @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user,
+            @NonNull Context context) {
+        return !isSettingsApplicationAsUser(applicationInfo, user, context);
+    }
 }
diff --git a/PermissionController/role-controller/java/com/android/role/controller/behavior/SmsRoleBehavior.java b/PermissionController/role-controller/java/com/android/role/controller/behavior/SmsRoleBehavior.java
index 6e5c5c9..b614594 100644
--- a/PermissionController/role-controller/java/com/android/role/controller/behavior/SmsRoleBehavior.java
+++ b/PermissionController/role-controller/java/com/android/role/controller/behavior/SmsRoleBehavior.java
@@ -30,6 +30,7 @@
 import com.android.role.controller.model.Permissions;
 import com.android.role.controller.model.Role;
 import com.android.role.controller.model.RoleBehavior;
+import com.android.role.controller.model.VisibilityMixin;
 import com.android.role.controller.util.CollectionUtils;
 import com.android.role.controller.util.PackageUtils;
 import com.android.role.controller.util.UserUtils;
@@ -129,4 +130,10 @@
                     user, context);
         }
     }
+
+    @Override
+    public boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
+            @NonNull Context context) {
+        return VisibilityMixin.isVisible("config_showSmsRole", true, user, context);
+    }
 }
diff --git a/PermissionController/role-controller/java/com/android/role/controller/model/Role.java b/PermissionController/role-controller/java/com/android/role/controller/model/Role.java
index e80ea11..6c7eb7d 100644
--- a/PermissionController/role-controller/java/com/android/role/controller/model/Role.java
+++ b/PermissionController/role-controller/java/com/android/role/controller/model/Role.java
@@ -949,6 +949,40 @@
         RoleManagerCompat.setRoleFallbackEnabledAsUser(this, false, user, context);
     }
 
+    /**
+     * Check whether this role should be visible to user.
+     *
+     * @param user the user to check for
+     * @param context the `Context` to retrieve system services
+     *
+     * @return whether this role should be visible to user
+     */
+    public boolean isVisibleAsUser(@NonNull UserHandle user, @NonNull Context context) {
+        RoleBehavior behavior = getBehavior();
+        if (behavior == null) {
+            return isVisible();
+        }
+        return isVisible() && behavior.isVisibleAsUser(this, user, context);
+    }
+
+    /**
+     * Check whether a qualifying application should be visible to user.
+     *
+     * @param applicationInfo the {@link ApplicationInfo} for the application
+     * @param user the user for the application
+     * @param context the {@code Context} to retrieve system services
+     *
+     * @return whether the qualifying application should be visible to user
+     */
+    public boolean isApplicationVisibleAsUser(@NonNull ApplicationInfo applicationInfo,
+            @NonNull UserHandle user,  @NonNull Context context) {
+        RoleBehavior behavior = getBehavior();
+        if (behavior == null) {
+            return true;
+        }
+        return behavior.isApplicationVisibleAsUser(this, applicationInfo, user, context);
+    }
+
     @Override
     public String toString() {
         return "Role{"
diff --git a/PermissionController/role-controller/java/com/android/role/controller/model/RoleBehavior.java b/PermissionController/role-controller/java/com/android/role/controller/model/RoleBehavior.java
index 34d2282..4bc1873 100644
--- a/PermissionController/role-controller/java/com/android/role/controller/model/RoleBehavior.java
+++ b/PermissionController/role-controller/java/com/android/role/controller/model/RoleBehavior.java
@@ -17,6 +17,7 @@
 package com.android.role.controller.model;
 
 import android.content.Context;
+import android.content.pm.ApplicationInfo;
 import android.os.UserHandle;
 
 import androidx.annotation.NonNull;
@@ -112,4 +113,34 @@
      */
     default void onHolderChangedAsUser(@NonNull Role role, @NonNull UserHandle user,
             @NonNull Context context) {}
+
+    /**
+     * Check whether this role should be visible to user.
+     *
+     * @param role the role to check for
+     * @param user the user to check for
+     * @param context the `Context` to retrieve system services
+     *
+     * @return whether this role should be visible to user
+     */
+    default boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
+            @NonNull Context context) {
+        return true;
+    }
+
+    /**
+     * Check whether a qualifying application should be visible to user.
+     *
+     * @param role the role to check for
+     * @param applicationInfo the {@link ApplicationInfo} for the application
+     * @param user the user for the application
+     * @param context the {@code Context} to retrieve system services
+     *
+     * @return whether the qualifying application should be visible to user
+     */
+    default boolean isApplicationVisibleAsUser(@NonNull Role role,
+            @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user,
+            @NonNull Context context) {
+        return true;
+    }
 }
diff --git a/PermissionController/role-controller/java/com/android/role/controller/model/VisibilityMixin.java b/PermissionController/role-controller/java/com/android/role/controller/model/VisibilityMixin.java
new file mode 100644
index 0000000..d4f56fe
--- /dev/null
+++ b/PermissionController/role-controller/java/com/android/role/controller/model/VisibilityMixin.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.role.controller.model;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.os.UserHandle;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+
+import com.android.role.controller.util.ContextUtils;
+
+/**
+ * Mixin for {@link RoleBehavior#isVisibleAsUser(Role, UserHandle, Context)} that returns whether
+ * the role should be visible from a corresponding boolean resource.
+ */
+public class VisibilityMixin {
+
+    private static final String LOG_TAG = VisibilityMixin.class.getSimpleName();
+
+    private VisibilityMixin() {}
+
+    /**
+     * Get the boolean resource value that represents whether a role is visible to the user.
+     *
+     * @param resourceName the name of the resource
+     * @param isPermissionControllerResource if {@code true}, and if the current SDK level is at
+     *        least V, get the resource from a PermissionController context for the given user.
+     *        Otherwise, get the resource the provided context.
+     * @param user the user to get the PermissionController context for
+     * @param context the `Context` to retrieve the resource (and system services)
+     *
+     * @return whether this role should be visible to user
+     */
+    public static boolean isVisible(@NonNull String resourceName,
+            boolean isPermissionControllerResource, @NonNull UserHandle user,
+            @NonNull Context context) {
+        Context packageContext = isPermissionControllerResource
+                ? ContextUtils.getPermissionControllerContext(user, context) : context;
+        Resources resources = packageContext.getResources();
+        String packageName = isPermissionControllerResource ? packageContext.getPackageName() :
+                "android";
+        int resourceId = resources.getIdentifier(resourceName, "bool", packageName);
+        if (resourceId == 0) {
+            Log.w(LOG_TAG, "Cannot find resource for visibility: " + resourceName);
+            return true;
+        }
+        try {
+            return resources.getBoolean(resourceId);
+        } catch (Resources.NotFoundException e) {
+            Log.w(LOG_TAG, "Cannot get resource for visibility: " + resourceName, e);
+            return true;
+        }
+    }
+}
diff --git a/PermissionController/role-controller/java/com/android/role/controller/util/ContextUtils.java b/PermissionController/role-controller/java/com/android/role/controller/util/ContextUtils.java
new file mode 100644
index 0000000..73ac266
--- /dev/null
+++ b/PermissionController/role-controller/java/com/android/role/controller/util/ContextUtils.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.role.controller.util;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.UserHandle;
+
+import androidx.annotation.NonNull;
+
+import com.android.modules.utils.build.SdkLevel;
+
+/**
+ * Utility methods for dealing with {@link Context}s.
+ */
+public final class ContextUtils {
+
+    private ContextUtils() {}
+
+    /**
+     * Create a Context for the PermissionController app for the given user.
+     *
+     * @param user the user of the application
+     * @param context the context to clone
+     *
+     * @return The PermissionController context for the given user
+     */
+    @NonNull
+    public static Context getPermissionControllerContext(@NonNull UserHandle user,
+            @NonNull Context context) {
+        if (!SdkLevel.isAtLeastV()) {
+            // We don't have the getPermissionControllerPackageName() API below V,
+            // but role controller always runs in PermissionController and in its own user below V.
+            return context;
+        }
+        String packageName = context.getPackageManager().getPermissionControllerPackageName();
+        try {
+            return context.createPackageContextAsUser(packageName, 0, user);
+        } catch (PackageManager.NameNotFoundException e) {
+            throw new RuntimeException("Cannot create PermissionController context", e);
+        }
+    }
+}
diff --git a/PermissionController/src/com/android/permissioncontroller/PermissionControllerApplication.java b/PermissionController/src/com/android/permissioncontroller/PermissionControllerApplication.java
index 729a5ec..50da281 100644
--- a/PermissionController/src/com/android/permissioncontroller/PermissionControllerApplication.java
+++ b/PermissionController/src/com/android/permissioncontroller/PermissionControllerApplication.java
@@ -33,7 +33,6 @@
 import com.android.permissioncontroller.privacysources.SafetyCenterAccessibilityListener;
 import com.android.permissioncontroller.role.model.RoleParserInitializer;
 import com.android.permissioncontroller.role.ui.SpecialAppAccessListActivity;
-import com.android.permissioncontroller.role.utils.RoleUiBehaviorUtils;
 import com.android.role.controller.model.Role;
 import com.android.role.controller.model.Roles;
 
@@ -73,7 +72,7 @@
             Role role = roles.valueAt(i);
 
             if (!role.isAvailableAsUser(Process.myUserHandle(), this)
-                    || !RoleUiBehaviorUtils.isVisible(role, this)) {
+                    || !role.isVisibleAsUser(Process.myUserHandle(), this)) {
                 continue;
             }
             if (!role.isExclusive()) {
diff --git a/PermissionController/src/com/android/permissioncontroller/role/model/VisibilityMixin.java b/PermissionController/src/com/android/permissioncontroller/role/model/VisibilityMixin.java
deleted file mode 100644
index 90cda72..0000000
--- a/PermissionController/src/com/android/permissioncontroller/role/model/VisibilityMixin.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.permissioncontroller.role.model;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.os.UserHandle;
-import android.util.Log;
-
-import androidx.annotation.NonNull;
-
-import com.android.role.controller.model.Role;
-import com.android.role.controller.model.RoleBehavior;
-
-/**
- * Mixin for {@link RoleBehavior#isVisibleAsUser(Role, UserHandle, Context)} that returns whether
- * the role should be visible from a corresponding boolean resource.
- */
-public class VisibilityMixin {
-
-    private static final String LOG_TAG = VisibilityMixin.class.getSimpleName();
-
-    private VisibilityMixin() {}
-
-    /**
-     * @see Role#isVisibleAsUser(UserHandle, Context)
-     */
-    public static boolean isVisible(@NonNull String resourceName, @NonNull Context context) {
-        Resources resources = context.getResources();
-        int resourceId = resources.getIdentifier(resourceName, "bool", "android");
-        if (resourceId == 0) {
-            Log.w(LOG_TAG, "Cannot find resource for visibility: " + resourceName);
-            return true;
-        }
-        try {
-            return resources.getBoolean(resourceId);
-        } catch (Resources.NotFoundException e) {
-            Log.w(LOG_TAG, "Cannot get resource for visibility: " + resourceName, e);
-            return true;
-        }
-    }
-}
diff --git a/PermissionController/src/com/android/permissioncontroller/role/service/RoleControllerServiceImpl.java b/PermissionController/src/com/android/permissioncontroller/role/service/RoleControllerServiceImpl.java
index 45f1236..38fe22b 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/service/RoleControllerServiceImpl.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/service/RoleControllerServiceImpl.java
@@ -31,7 +31,6 @@
 
 import com.android.permissioncontroller.permission.utils.CollectionUtils;
 import com.android.permissioncontroller.role.utils.PackageUtils;
-import com.android.permissioncontroller.role.utils.RoleUiBehaviorUtils;
 import com.android.role.controller.model.Role;
 import com.android.role.controller.model.Roles;
 import com.android.role.controller.util.UserUtils;
@@ -437,8 +436,8 @@
         }
         ApplicationInfo applicationInfo = PackageUtils.getApplicationInfoAsUser(packageName,
                 mUser, this);
-        if (applicationInfo == null || !RoleUiBehaviorUtils.isApplicationVisibleAsUser(role,
-                applicationInfo, mUser, this)) {
+        if (applicationInfo == null || !role.isApplicationVisibleAsUser(applicationInfo, mUser,
+                this)) {
             return false;
         }
         return true;
@@ -454,7 +453,7 @@
             return false;
         }
 
-        return RoleUiBehaviorUtils.isVisibleAsUser(role, mUser, this);
+        return role.isVisibleAsUser(mUser, this);
     }
 
     private static boolean checkFlags(int flags, int allowedFlags) {
diff --git a/PermissionController/src/com/android/permissioncontroller/role/service/RoleSearchIndexablesProvider.java b/PermissionController/src/com/android/permissioncontroller/role/service/RoleSearchIndexablesProvider.java
index 9a0067d..870e2c0 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/service/RoleSearchIndexablesProvider.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/service/RoleSearchIndexablesProvider.java
@@ -29,7 +29,6 @@
 import com.android.permissioncontroller.R;
 import com.android.permissioncontroller.permission.service.BaseSearchIndexablesProvider;
 import com.android.permissioncontroller.role.model.RoleParserInitializer;
-import com.android.permissioncontroller.role.utils.RoleUiBehaviorUtils;
 import com.android.role.controller.model.Role;
 import com.android.role.controller.model.Roles;
 
@@ -63,7 +62,7 @@
             long token = Binder.clearCallingIdentity();
             try {
                 if (!role.isAvailableAsUser(Process.myUserHandle(), context)
-                        || !RoleUiBehaviorUtils.isVisible(role, context)) {
+                        || !role.isVisibleAsUser(Process.myUserHandle(), context)) {
                     continue;
                 }
             } finally {
diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppActivity.java b/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppActivity.java
index 0e7e51a..41f1a06 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppActivity.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/ui/DefaultAppActivity.java
@@ -32,7 +32,6 @@
 import com.android.permissioncontroller.role.ui.auto.AutoDefaultAppFragment;
 import com.android.permissioncontroller.role.ui.handheld.HandheldDefaultAppFragment;
 import com.android.permissioncontroller.role.ui.wear.WearDefaultAppFragment;
-import com.android.permissioncontroller.role.utils.RoleUiBehaviorUtils;
 import com.android.role.controller.model.Role;
 import com.android.role.controller.model.Roles;
 
@@ -89,7 +88,7 @@
             return;
         }
 
-        if (!RoleUiBehaviorUtils.isVisibleAsUser(role, user, this)) {
+        if (!role.isVisibleAsUser(user, this)) {
             Log.e(LOG_TAG, "Role is invisible: " + roleName);
             finish();
             return;
diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/RequestRoleActivity.java b/PermissionController/src/com/android/permissioncontroller/role/ui/RequestRoleActivity.java
index 856416f..279e552 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/ui/RequestRoleActivity.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/ui/RequestRoleActivity.java
@@ -39,7 +39,6 @@
 import com.android.permissioncontroller.role.model.UserDeniedManager;
 import com.android.permissioncontroller.role.ui.wear.WearRequestRoleFragment;
 import com.android.permissioncontroller.role.utils.PackageUtils;
-import com.android.permissioncontroller.role.utils.RoleUiBehaviorUtils;
 import com.android.role.controller.model.Role;
 import com.android.role.controller.model.Roles;
 
@@ -113,7 +112,7 @@
             return;
         }
 
-        if (!RoleUiBehaviorUtils.isVisible(role, this)) {
+        if (!role.isVisibleAsUser(Process.myUserHandle(), this)) {
             Log.e(LOG_TAG, "Role is invisible: " + mRoleName);
             reportRequestResult(
                     PermissionControllerStatsLog.ROLE_REQUEST_RESULT_REPORTED__RESULT__IGNORED);
diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/RoleListLiveData.java b/PermissionController/src/com/android/permissioncontroller/role/ui/RoleListLiveData.java
index b9011bd..e6df3ed 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/ui/RoleListLiveData.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/ui/RoleListLiveData.java
@@ -30,7 +30,6 @@
 
 import com.android.permissioncontroller.AsyncTaskLiveData;
 import com.android.permissioncontroller.role.utils.PackageUtils;
-import com.android.permissioncontroller.role.utils.RoleUiBehaviorUtils;
 import com.android.role.controller.model.Role;
 import com.android.role.controller.model.Roles;
 
@@ -97,7 +96,7 @@
                 continue;
             }
 
-            if (!RoleUiBehaviorUtils.isVisibleAsUser(role, mUser, mContext)) {
+            if (!role.isVisibleAsUser(mUser, mContext)) {
                 continue;
             }
 
diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/RoleLiveData.java b/PermissionController/src/com/android/permissioncontroller/role/ui/RoleLiveData.java
index 3ccb1d8..bb492f7 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/ui/RoleLiveData.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/ui/RoleLiveData.java
@@ -30,7 +30,6 @@
 
 import com.android.permissioncontroller.AsyncTaskLiveData;
 import com.android.permissioncontroller.role.utils.PackageUtils;
-import com.android.permissioncontroller.role.utils.RoleUiBehaviorUtils;
 import com.android.role.controller.model.Role;
 
 import java.util.ArrayList;
@@ -95,8 +94,7 @@
                         + qualifyingPackageName);
                 continue;
             }
-            if (!RoleUiBehaviorUtils.isApplicationVisibleAsUser(mRole, qualifyingApplicationInfo,
-                    mUser, mContext)) {
+            if (!mRole.isApplicationVisibleAsUser(qualifyingApplicationInfo, mUser, mContext)) {
                 continue;
             }
             boolean isHolderApplication = holderPackageNames.contains(qualifyingPackageName);
diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/AssistantRoleUiBehavior.java b/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/AssistantRoleUiBehavior.java
index 40bd7a3..4df3ccf 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/AssistantRoleUiBehavior.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/AssistantRoleUiBehavior.java
@@ -26,7 +26,6 @@
 import androidx.annotation.Nullable;
 
 import com.android.permissioncontroller.R;
-import com.android.permissioncontroller.role.model.VisibilityMixin;
 import com.android.role.controller.model.Role;
 
 /***
@@ -34,12 +33,6 @@
  */
 public class AssistantRoleUiBehavior implements RoleUiBehavior {
 
-    @Override
-    public boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
-            @NonNull Context context) {
-        return VisibilityMixin.isVisible("config_showDefaultAssistant", context);
-    }
-
     @Nullable
     @Override
     public Intent getManageIntentAsUser(@NonNull Role role, @NonNull UserHandle user,
diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/BrowserRoleUiBehavior.java b/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/BrowserRoleUiBehavior.java
deleted file mode 100644
index 018b0db..0000000
--- a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/BrowserRoleUiBehavior.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.permissioncontroller.role.ui.behavior;
-
-import android.content.Context;
-import android.os.UserHandle;
-
-import androidx.annotation.NonNull;
-
-import com.android.permissioncontroller.R;
-import com.android.role.controller.model.Role;
-
-/***
- * Class for UI behavior of Browser role
- */
-public class BrowserRoleUiBehavior implements RoleUiBehavior {
-
-    @Override
-    public boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
-            @NonNull Context context) {
-        return context.getResources().getBoolean(R.bool.config_showBrowserRole);
-    }
-}
diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/DialerRoleUiBehavior.java b/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/DialerRoleUiBehavior.java
index e6b8dab..ab87e24 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/DialerRoleUiBehavior.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/DialerRoleUiBehavior.java
@@ -49,12 +49,6 @@
         }
     }
 
-    @Override
-    public boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
-            @NonNull Context context) {
-        return context.getResources().getBoolean(R.bool.config_showDialerRole);
-    }
-
     @Nullable
     @Override
     public CharSequence getConfirmationMessage(@NonNull Role role, @NonNull String packageName,
diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/EmergencyRoleUiBehavior.java b/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/EmergencyRoleUiBehavior.java
index 8a62ee7..f891bb3 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/EmergencyRoleUiBehavior.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/EmergencyRoleUiBehavior.java
@@ -17,13 +17,11 @@
 package com.android.permissioncontroller.role.ui.behavior;
 
 import android.content.Context;
-import android.os.UserHandle;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
 import com.android.permissioncontroller.role.model.EncryptionUnawareConfirmationMixin;
-import com.android.permissioncontroller.role.model.VisibilityMixin;
 import com.android.role.controller.model.Role;
 
 /***
@@ -31,12 +29,6 @@
  */
 public class EmergencyRoleUiBehavior implements RoleUiBehavior {
 
-    @Override
-    public boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
-            @NonNull Context context) {
-        return VisibilityMixin.isVisible("config_showDefaultEmergency", context);
-    }
-
     @Nullable
     @Override
     public CharSequence getConfirmationMessage(@NonNull Role role, @NonNull String packageName,
diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/HomeRoleUiBehavior.java b/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/HomeRoleUiBehavior.java
index e49fc0d..323325d 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/HomeRoleUiBehavior.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/HomeRoleUiBehavior.java
@@ -34,10 +34,8 @@
 import com.android.permissioncontroller.R;
 import com.android.permissioncontroller.permission.utils.CollectionUtils;
 import com.android.permissioncontroller.permission.utils.Utils;
-import com.android.permissioncontroller.role.model.VisibilityMixin;
 import com.android.permissioncontroller.role.ui.TwoTargetPreference;
 import com.android.permissioncontroller.role.utils.UserUtils;
-import com.android.role.controller.behavior.HomeRoleBehavior;
 import com.android.role.controller.model.Role;
 
 /***
@@ -48,12 +46,6 @@
     private static final String LOG_TAG = HomeRoleUiBehavior.class.getSimpleName();
 
     @Override
-    public boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
-            @NonNull Context context) {
-        return VisibilityMixin.isVisible("config_showDefaultHome", context);
-    }
-
-    @Override
     public void preparePreferenceAsUser(@NonNull Role role, @NonNull TwoTargetPreference preference,
             @NonNull UserHandle user, @NonNull Context context) {
         TwoTargetPreference.OnSecondTargetClickListener listener = null;
@@ -82,14 +74,6 @@
     }
 
     @Override
-    public boolean isApplicationVisibleAsUser(@NonNull Role role,
-            @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user,
-            @NonNull Context context) {
-        // Home is not available for work profile, so we can just use the current user.
-        return !HomeRoleBehavior.isSettingsApplicationAsUser(applicationInfo, user, context);
-    }
-
-    @Override
     public void prepareApplicationPreferenceAsUser(@NonNull Role role,
             @NonNull Preference preference, @NonNull ApplicationInfo applicationInfo,
             @NonNull UserHandle user, @NonNull Context context) {
diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/RoleUiBehavior.java b/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/RoleUiBehavior.java
index 6e3b47f..29dc5d2 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/RoleUiBehavior.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/RoleUiBehavior.java
@@ -34,20 +34,6 @@
 public interface RoleUiBehavior {
 
     /**
-     * Check whether this role should be visible to user.
-     *
-     * @param role the role to check for
-     * @param user the user to check for
-     * @param context the `Context` to retrieve system services
-     *
-     * @return whether this role should be visible to user
-     */
-    default boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
-            @NonNull Context context) {
-        return true;
-    }
-
-    /**
      * Get the {@link Intent} to manage this role, or {@code null} to use the default UI.
      *
      * @param role the role to get the intent for
@@ -76,21 +62,6 @@
             @NonNull Context context) {}
 
     /**
-     * Check whether a qualifying application should be visible to user.
-     *
-     * @param applicationInfo the {@link ApplicationInfo} for the application
-     * @param user the user for the application
-     * @param context the {@code Context} to retrieve system services
-     *
-     * @return whether the qualifying application should be visible to user
-     */
-    default boolean isApplicationVisibleAsUser(@NonNull Role role,
-            @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user,
-            @NonNull Context context) {
-        return true;
-    }
-
-    /**
      * Prepare a {@link Preference} for this role.
      *
      * @param role the role to prepare the preference for
diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/SmsRoleUiBehavior.java b/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/SmsRoleUiBehavior.java
index 9fc9be3..e27bc1a 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/SmsRoleUiBehavior.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/ui/behavior/SmsRoleUiBehavior.java
@@ -17,12 +17,10 @@
 package com.android.permissioncontroller.role.ui.behavior;
 
 import android.content.Context;
-import android.os.UserHandle;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
-import com.android.permissioncontroller.R;
 import com.android.permissioncontroller.role.model.EncryptionUnawareConfirmationMixin;
 import com.android.role.controller.model.Role;
 
@@ -31,12 +29,6 @@
  */
 public class SmsRoleUiBehavior implements RoleUiBehavior {
 
-    @Override
-    public boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
-            @NonNull Context context) {
-        return context.getResources().getBoolean(R.bool.config_showSmsRole);
-    }
-
     @Nullable
     @Override
     public CharSequence getConfirmationMessage(@NonNull Role role, @NonNull String packageName,
diff --git a/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/SpecialAppAccessActivity.java b/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/SpecialAppAccessActivity.java
index 1616d9f..4724640 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/SpecialAppAccessActivity.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/ui/specialappaccess/SpecialAppAccessActivity.java
@@ -31,7 +31,6 @@
 import com.android.permissioncontroller.role.ui.SettingsActivity;
 import com.android.permissioncontroller.role.ui.auto.AutoSpecialAppAccessFragment;
 import com.android.permissioncontroller.role.ui.specialappaccess.handheld.HandheldSpecialAppAccessFragment;
-import com.android.permissioncontroller.role.utils.RoleUiBehaviorUtils;
 import com.android.role.controller.model.Role;
 import com.android.role.controller.model.Roles;
 
@@ -78,7 +77,7 @@
             return;
         }
 
-        if (!RoleUiBehaviorUtils.isVisible(role, this)) {
+        if (!role.isVisibleAsUser(Process.myUserHandle(), this)) {
             Log.e(LOG_TAG, "Role is invisible: " + roleName);
             finish();
             return;
diff --git a/PermissionController/src/com/android/permissioncontroller/role/utils/RoleUiBehaviorUtils.java b/PermissionController/src/com/android/permissioncontroller/role/utils/RoleUiBehaviorUtils.java
index 6081695..7ebc1eb 100644
--- a/PermissionController/src/com/android/permissioncontroller/role/utils/RoleUiBehaviorUtils.java
+++ b/PermissionController/src/com/android/permissioncontroller/role/utils/RoleUiBehaviorUtils.java
@@ -19,7 +19,6 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
-import android.os.Process;
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.util.Log;
@@ -63,30 +62,6 @@
     }
 
     /**
-     * @see RoleUiBehavior#isVisibleAsUser
-     */
-    public static boolean isVisibleAsUser(@NonNull Role role, @NonNull UserHandle user,
-            @NonNull Context context) {
-        RoleUiBehavior uiBehavior = getUiBehavior(role);
-        if (uiBehavior == null) {
-            return role.isVisible();
-        }
-        return role.isVisible() && uiBehavior.isVisibleAsUser(role, user, context);
-    }
-
-    /**
-     * Check whether this role should be visible to user, for current user.
-     *
-     * @param context the `Context` to retrieve system services
-     *
-     * @return whether this role should be visible to user.
-     */
-    public static boolean isVisible(@NonNull Role role, @NonNull Context context) {
-        return isVisibleAsUser(role, Process.myUserHandle(), context);
-    }
-
-
-    /**
      * @see RoleUiBehavior#getManageIntentAsUser
      */
     @Nullable
@@ -115,19 +90,6 @@
     }
 
     /**
-     * @see RoleUiBehavior#isApplicationVisibleAsUser
-     */
-    public static boolean isApplicationVisibleAsUser(@NonNull Role role,
-            @NonNull ApplicationInfo applicationInfo, @NonNull UserHandle user,
-            @NonNull Context context) {
-        RoleUiBehavior uiBehavior = getUiBehavior(role);
-        if (uiBehavior == null) {
-            return true;
-        }
-        return uiBehavior.isApplicationVisibleAsUser(role, applicationInfo, user, context);
-    }
-
-    /**
      * @see RoleUiBehavior#prepareApplicationPreferenceAsUser
      */
     public static void prepareApplicationPreferenceAsUser(@NonNull Role role,