summaryrefslogtreecommitdiff
path: root/framework-s/java
diff options
context:
space:
mode:
author Yi-an Chen <theianchen@google.com> 2023-10-09 23:44:57 +0000
committer Yi-an Chen <theianchen@google.com> 2023-10-23 19:02:04 +0000
commitcdc0ad9ab640f68b3583cb466f07f6ad2c1cb89b (patch)
tree1930c2a07b385576e51cea1af6597abd534c45c6 /framework-s/java
parent2f340f2a8c730fd4b0a9628e560e89d5d5a4b473 (diff)
[Role Logic Move] Migrate isRoleFallbackEnabled (system server)
Add the isFallbackEnabled related fields (and setting/getting this value) in System Server. We will assume all current RolesState have version=0. If the version is undefined, it will be -1. If the isFallbackEnabled is migrated, it will be 1. What's not included in this CL: (1) Code in PC to read this value from System Server (2) Code in System Server to read from SharedPreference, migrate the current user settings, and update RolesState version Notes for the reviewer(s): (and open for discussions) (1) If the version doesn't support isFallbackEnabled (when version < 1), it will assume isFallbackEnabled is false. I think if the version < 1, we should try to migrate (in a followup CL) this user settings and update the version to be >= 1 instead of asssuming isFallbackEnabled to true. Hence there's a constructor for RolesState that sets mFallbackEnabledRoles to null. This should be used when version < 1. (2) If the roles doesn't present or the version doesn't support fallbackEnabled (see the condition in RoleUserState.setFallbackEnabled), we don't allow setting fallbackEnabled to true. Bug: 302563864 Test: Will add it after fallback logic described in Notes (2) is discussed. Change-Id: Iaeb037ae014323f0af0c43031b20f3239e359027
Diffstat (limited to 'framework-s/java')
-rw-r--r--framework-s/java/android/app/role/IRoleManager.aidl4
-rw-r--r--framework-s/java/android/app/role/RoleManager.java49
2 files changed, 53 insertions, 0 deletions
diff --git a/framework-s/java/android/app/role/IRoleManager.aidl b/framework-s/java/android/app/role/IRoleManager.aidl
index 5f7cb1bf5..5bcda037e 100644
--- a/framework-s/java/android/app/role/IRoleManager.aidl
+++ b/framework-s/java/android/app/role/IRoleManager.aidl
@@ -54,6 +54,10 @@ interface IRoleManager {
void setBypassingRoleQualification(boolean bypassRoleQualification);
+ boolean isRoleFallbackEnabledAsUser(in String roleName, int userId);
+
+ void setRoleFallbackEnabledAsUser(in String roleName, boolean fallbackEnabled, int userId);
+
void setRoleNamesFromController(in List<String> roleNames);
boolean addRoleHolderFromController(in String roleName, in String packageName);
diff --git a/framework-s/java/android/app/role/RoleManager.java b/framework-s/java/android/app/role/RoleManager.java
index d8e7149f2..cb3ebfe3c 100644
--- a/framework-s/java/android/app/role/RoleManager.java
+++ b/framework-s/java/android/app/role/RoleManager.java
@@ -18,6 +18,7 @@ package android.app.role;
import android.Manifest;
import android.annotation.CallbackExecutor;
+import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -35,6 +36,7 @@ import android.os.Process;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.UserHandle;
+import android.permission.flags.Flags;
import android.util.ArrayMap;
import android.util.SparseArray;
@@ -690,6 +692,53 @@ public final class RoleManager {
}
/**
+ * Check whether role currently enables fallback to default holder.
+ * <p>
+ * This is based on the "None" holder being actively selected, in which case don't fallback.
+ *
+ * @param roleName the name of the role being queried
+ *
+ * @return whether fallback is enabled for the provided role
+ *
+ * @hide
+ */
+ @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
+ @RequiresPermission(Manifest.permission.MANAGE_ROLE_HOLDERS)
+ @FlaggedApi(Flags.FLAG_ROLE_CONTROLLER_IN_SYSTEM_SERVER)
+ @UserHandleAware
+ @SystemApi
+ public boolean isRoleFallbackEnabled(@NonNull String roleName) {
+ try {
+ return mService.isRoleFallbackEnabledAsUser(roleName,
+ mContext.getUser().getIdentifier());
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * Set whether role should fallback to a default role holder.
+ *
+ * @param roleName the name of the role being queried.
+ * @param fallbackEnabled whether to enable fallback holders for this role.
+ *
+ * @hide
+ */
+ @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
+ @RequiresPermission(Manifest.permission.MANAGE_ROLE_HOLDERS)
+ @FlaggedApi(Flags.FLAG_ROLE_CONTROLLER_IN_SYSTEM_SERVER)
+ @UserHandleAware
+ @SystemApi
+ public void setRoleFallbackEnabled(@NonNull String roleName, boolean fallbackEnabled) {
+ try {
+ mService.setRoleFallbackEnabledAsUser(roleName, fallbackEnabled,
+ mContext.getUser().getIdentifier());
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Set the names of all the available roles. Should only be called from
* {@link android.app.role.RoleControllerService}.
* <p>