Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09bb9095 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Check for role visibility in more places."

parents 5280516e 563ca11b
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -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);
+11 −0
Original line number Diff line number Diff line
@@ -261,6 +261,17 @@ public class Role {
        return true;
    }

    /**
     * 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.
     *
+4 −0
Original line number Diff line number Diff line
@@ -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()
+6 −0
Original line number Diff line number Diff line
@@ -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();