Search in sources :

Example 1 with AppsQueryHelper

use of android.content.pm.AppsQueryHelper in project platform_frameworks_base by android.

the class PackageManagerService method enableSystemUserPackages.

private void enableSystemUserPackages() {
    if (!UserManager.isSplitSystemUser()) {
        return;
    }
    // For system user, enable apps based on the following conditions:
    // - app is whitelisted or belong to one of these groups:
    //   -- system app which has no launcher icons
    //   -- system app which has INTERACT_ACROSS_USERS permission
    //   -- system IME app
    // - app is not in the blacklist
    AppsQueryHelper queryHelper = new AppsQueryHelper(this);
    Set<String> enableApps = new ArraySet<>();
    enableApps.addAll(queryHelper.queryApps(AppsQueryHelper.GET_NON_LAUNCHABLE_APPS | AppsQueryHelper.GET_APPS_WITH_INTERACT_ACROSS_USERS_PERM | AppsQueryHelper.GET_IMES, /* systemAppsOnly */
    true, UserHandle.SYSTEM));
    ArraySet<String> wlApps = SystemConfig.getInstance().getSystemUserWhitelistedApps();
    enableApps.addAll(wlApps);
    enableApps.addAll(queryHelper.queryApps(AppsQueryHelper.GET_REQUIRED_FOR_SYSTEM_USER, /* systemAppsOnly */
    false, UserHandle.SYSTEM));
    ArraySet<String> blApps = SystemConfig.getInstance().getSystemUserBlacklistedApps();
    enableApps.removeAll(blApps);
    Log.i(TAG, "Applications installed for system user: " + enableApps);
    List<String> allAps = queryHelper.queryApps(0, /* systemAppsOnly */
    false, UserHandle.SYSTEM);
    final int allAppsSize = allAps.size();
    synchronized (mPackages) {
        for (int i = 0; i < allAppsSize; i++) {
            String pName = allAps.get(i);
            PackageSetting pkgSetting = mSettings.mPackages.get(pName);
            // Should not happen, but we shouldn't be failing if it does
            if (pkgSetting == null) {
                continue;
            }
            boolean install = enableApps.contains(pName);
            if (pkgSetting.getInstalled(UserHandle.USER_SYSTEM) != install) {
                Log.i(TAG, (install ? "Installing " : "Uninstalling ") + pName + " for system user");
                pkgSetting.setInstalled(install, UserHandle.USER_SYSTEM);
            }
        }
    }
}
Also used : ArraySet(android.util.ArraySet) AppsQueryHelper(android.content.pm.AppsQueryHelper)

Example 2 with AppsQueryHelper

use of android.content.pm.AppsQueryHelper in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerService method enableSystemUserPackages.

private void enableSystemUserPackages() {
    if (!UserManager.isSplitSystemUser()) {
        return;
    }
    // For system user, enable apps based on the following conditions:
    // - app is whitelisted or belong to one of these groups:
    //   -- system app which has no launcher icons
    //   -- system app which has INTERACT_ACROSS_USERS permission
    //   -- system IME app
    // - app is not in the blacklist
    AppsQueryHelper queryHelper = new AppsQueryHelper(this);
    Set<String> enableApps = new ArraySet<>();
    enableApps.addAll(queryHelper.queryApps(AppsQueryHelper.GET_NON_LAUNCHABLE_APPS | AppsQueryHelper.GET_APPS_WITH_INTERACT_ACROSS_USERS_PERM | AppsQueryHelper.GET_IMES, /* systemAppsOnly */
    true, UserHandle.SYSTEM));
    ArraySet<String> wlApps = SystemConfig.getInstance().getSystemUserWhitelistedApps();
    enableApps.addAll(wlApps);
    enableApps.addAll(queryHelper.queryApps(AppsQueryHelper.GET_REQUIRED_FOR_SYSTEM_USER, /* systemAppsOnly */
    false, UserHandle.SYSTEM));
    ArraySet<String> blApps = SystemConfig.getInstance().getSystemUserBlacklistedApps();
    enableApps.removeAll(blApps);
    Log.i(TAG, "Applications installed for system user: " + enableApps);
    List<String> allAps = queryHelper.queryApps(0, /* systemAppsOnly */
    false, UserHandle.SYSTEM);
    final int allAppsSize = allAps.size();
    synchronized (mPackages) {
        for (int i = 0; i < allAppsSize; i++) {
            String pName = allAps.get(i);
            PackageSetting pkgSetting = mSettings.mPackages.get(pName);
            // Should not happen, but we shouldn't be failing if it does
            if (pkgSetting == null) {
                continue;
            }
            boolean install = enableApps.contains(pName);
            if (pkgSetting.getInstalled(UserHandle.USER_SYSTEM) != install) {
                Log.i(TAG, (install ? "Installing " : "Uninstalling ") + pName + " for system user");
                pkgSetting.setInstalled(install, UserHandle.USER_SYSTEM);
            }
        }
    }
}
Also used : ArraySet(android.util.ArraySet) AppsQueryHelper(android.content.pm.AppsQueryHelper)

Aggregations

AppsQueryHelper (android.content.pm.AppsQueryHelper)2 ArraySet (android.util.ArraySet)2