summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHai Zhang <zhanghai@google.com>2019-03-14 17:02:54 -0700
committerHai Zhang <zhanghai@google.com>2019-03-14 17:02:54 -0700
commit563ca11b5fd6a59146219208cbffb9b41bf6eb0e (patch)
tree08487b141e1c8bf2c64cccca4d9a1f4d6facf34b
parentaecc5ef045060895578e44b3370d9181fbc15487 (diff)
downloadandroid_packages_apps_PackageInstaller-563ca11b5fd6a59146219208cbffb9b41bf6eb0e.tar.gz
android_packages_apps_PackageInstaller-563ca11b5fd6a59146219208cbffb9b41bf6eb0e.tar.bz2
android_packages_apps_PackageInstaller-563ca11b5fd6a59146219208cbffb9b41bf6eb0e.zip
Check for role visibility in more places.
Bug: 124452117 Test: build Change-Id: Iea5d5e3801383058e585e0247a5392bd6577f246
-rw-r--r--src/com/android/packageinstaller/PackageInstallerApplication.java9
-rw-r--r--src/com/android/packageinstaller/role/model/Role.java11
-rw-r--r--src/com/android/packageinstaller/role/service/RoleSearchIndexablesProvider.java4
-rw-r--r--src/com/android/packageinstaller/role/ui/RequestRoleActivity.java6
4 files changed, 26 insertions, 4 deletions
diff --git a/src/com/android/packageinstaller/PackageInstallerApplication.java b/src/com/android/packageinstaller/PackageInstallerApplication.java
index 871cc35b..a1aa539d 100644
--- a/src/com/android/packageinstaller/PackageInstallerApplication.java
+++ b/src/com/android/packageinstaller/PackageInstallerApplication.java
@@ -38,23 +38,24 @@ public class PackageInstallerApplication extends Application {
private void updateSpecialAppAccessListActivityEnabledState() {
ArrayMap<String, Role> roles = Roles.get(this);
- boolean hasSpecialAppAccess = false;
+ boolean hasVisibleSpecialAppAccess = false;
int rolesSize = roles.size();
for (int i = 0; i < rolesSize; i++) {
Role role = roles.valueAt(i);
- if (!role.isAvailable(this)) {
+ if (!role.isAvailable(this) || !role.isVisible(this)) {
continue;
}
if (!role.isExclusive()) {
- hasSpecialAppAccess = true;
+ hasVisibleSpecialAppAccess = true;
break;
}
}
PackageManager packageManager = getPackageManager();
ComponentName componentName = new ComponentName(this, SpecialAppAccessListActivity.class);
- int enabledState = hasSpecialAppAccess ? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
+ int enabledState = hasVisibleSpecialAppAccess
+ ? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
packageManager.setComponentEnabledSetting(componentName, enabledState,
PackageManager.DONT_KILL_APP);
diff --git a/src/com/android/packageinstaller/role/model/Role.java b/src/com/android/packageinstaller/role/model/Role.java
index 89837d38..86842f61 100644
--- a/src/com/android/packageinstaller/role/model/Role.java
+++ b/src/com/android/packageinstaller/role/model/Role.java
@@ -262,6 +262,17 @@ public class Role {
}
/**
+ * Check whether this role should be visible to user, for current user.
+ *
+ * @param context the {@code Context} to retrieve system services
+ *
+ * @return whether this role should be visible to user.
+ */
+ public boolean isVisible(@NonNull Context context) {
+ return isVisibleAsUser(Process.myUserHandle(), context);
+ }
+
+ /**
* Get the {@link Intent} to manage this role, or {@code null} to use the default UI.
*
* @param user the user to manage this role for
diff --git a/src/com/android/packageinstaller/role/service/RoleSearchIndexablesProvider.java b/src/com/android/packageinstaller/role/service/RoleSearchIndexablesProvider.java
index d105f58c..55076278 100644
--- a/src/com/android/packageinstaller/role/service/RoleSearchIndexablesProvider.java
+++ b/src/com/android/packageinstaller/role/service/RoleSearchIndexablesProvider.java
@@ -50,6 +50,10 @@ public class RoleSearchIndexablesProvider extends BaseSearchIndexablesProvider {
for (int i = 0; i < rolesSize; i++) {
Role role = roles.valueAt(i);
+ if (!role.isAvailable(context) || !role.isVisible(context)) {
+ continue;
+ }
+
String label = context.getString(role.getLabelResource());
boolean isExclusive = role.isExclusive();
cursor.newRow()
diff --git a/src/com/android/packageinstaller/role/ui/RequestRoleActivity.java b/src/com/android/packageinstaller/role/ui/RequestRoleActivity.java
index e6fb868a..2f991ac4 100644
--- a/src/com/android/packageinstaller/role/ui/RequestRoleActivity.java
+++ b/src/com/android/packageinstaller/role/ui/RequestRoleActivity.java
@@ -83,6 +83,12 @@ public class RequestRoleActivity extends FragmentActivity {
return;
}
+ if (!role.isVisible(this)) {
+ Log.e(LOG_TAG, "Role is invisible: " + mRoleName);
+ finish();
+ return;
+ }
+
if (PackageUtils.getApplicationInfo(mPackageName, this) == null) {
Log.w(LOG_TAG, "Unknown application: " + mPackageName);
finish();