From 928191881df05c6520c1da8c208b6a7f47f52d45 Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Fri, 16 Aug 2013 13:59:40 -0700 Subject: [PATCH] Don't list apps that are disabled by the system This is to make sure that apps that were disabled for some reason such as inappropriateness for a locale or for a specific device, don't show up as available to enable for a restricted profile. But in the case that the app was already enabled for the target profile, show it in the list so that it can be disabled if necessary. Bug: 10229133 Change-Id: I3c19edb7364cea42d95b619781e0326543b9a1cf --- .../users/AppRestrictionsFragment.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/users/AppRestrictionsFragment.java b/src/com/android/settings/users/AppRestrictionsFragment.java index 0e15cece96d..edf321ac22d 100644 --- a/src/com/android/settings/users/AppRestrictionsFragment.java +++ b/src/com/android/settings/users/AppRestrictionsFragment.java @@ -475,13 +475,24 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen PackageManager.GET_DISABLED_COMPONENTS | PackageManager.GET_UNINSTALLED_PACKAGES); for (ResolveInfo app : launchableApps) { if (app.activityInfo != null && app.activityInfo.applicationInfo != null) { + final String packageName = app.activityInfo.packageName; int flags = app.activityInfo.applicationInfo.flags; if ((flags & ApplicationInfo.FLAG_SYSTEM) != 0 || (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { // System app // Skip excluded packages - if (excludePackages.contains(app.activityInfo.packageName)) continue; - + if (excludePackages.contains(packageName)) continue; + int enabled = pm.getApplicationEnabledSetting(packageName); + if (enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED + || enabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) { + // Check if the app is already enabled for the target user + ApplicationInfo targetUserAppInfo = getAppInfoForUser(packageName, + 0, mUser); + if (targetUserAppInfo == null + || (targetUserAppInfo.flags&ApplicationInfo.FLAG_INSTALLED) == 0) { + continue; + } + } SelectableAppInfo info = new SelectableAppInfo(); info.packageName = app.activityInfo.packageName; info.appName = app.activityInfo.applicationInfo.loadLabel(pm); @@ -495,6 +506,16 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen } } + private ApplicationInfo getAppInfoForUser(String packageName, int flags, UserHandle user) { + try { + ApplicationInfo targetUserAppInfo = mIPm.getApplicationInfo(packageName, flags, + user.getIdentifier()); + return targetUserAppInfo; + } catch (RemoteException re) { + return null; + } + } + private class AppLoadingTask extends AsyncTask { @Override @@ -563,6 +584,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen } } + // Get the list of apps already installed for the user mUserApps = null; try { mUserApps = ipm.getInstalledApplications( @@ -586,6 +608,8 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen } } } + + // Sort the list of visible apps Collections.sort(mVisibleApps, new AppLabelComparator()); // Remove dupes