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

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

Merge "Disable SpecialAppAccessListActivity when there are none."

parents f46f0d13 0c151146
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -17,12 +17,46 @@
package com.android.packageinstaller;

import android.app.Application;
import android.content.ComponentName;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.util.ArrayMap;

import com.android.packageinstaller.role.model.Role;
import com.android.packageinstaller.role.model.Roles;
import com.android.packageinstaller.role.ui.SpecialAppAccessListActivity;

public class PackageInstallerApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        PackageItemInfo.forceSafeLabels();
        updateSpecialAppAccessListActivityEnabledState();
    }

    private void updateSpecialAppAccessListActivityEnabledState() {
        ArrayMap<String, Role> roles = Roles.get(this);
        boolean hasSpecialAppAccess = false;
        int rolesSize = roles.size();
        for (int i = 0; i < rolesSize; i++) {
            Role role = roles.valueAt(i);

            if (!role.isAvailable(this)) {
                continue;
            }
            if (!role.isExclusive()) {
                hasSpecialAppAccess = true;
                break;
            }
        }

        PackageManager packageManager = getPackageManager();
        ComponentName componentName = new ComponentName(this, SpecialAppAccessListActivity.class);
        int enabledState = hasSpecialAppAccess ? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
        packageManager.setComponentEnabledSetting(componentName, enabledState,
                PackageManager.DONT_KILL_APP);
    }
}