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
This commit is contained in:
Amith Yamasani
2013-08-16 13:59:40 -07:00
parent 53083ab2bb
commit 928191881d

View File

@@ -475,13 +475,24 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
PackageManager.GET_DISABLED_COMPONENTS | PackageManager.GET_UNINSTALLED_PACKAGES); PackageManager.GET_DISABLED_COMPONENTS | PackageManager.GET_UNINSTALLED_PACKAGES);
for (ResolveInfo app : launchableApps) { for (ResolveInfo app : launchableApps) {
if (app.activityInfo != null && app.activityInfo.applicationInfo != null) { if (app.activityInfo != null && app.activityInfo.applicationInfo != null) {
final String packageName = app.activityInfo.packageName;
int flags = app.activityInfo.applicationInfo.flags; int flags = app.activityInfo.applicationInfo.flags;
if ((flags & ApplicationInfo.FLAG_SYSTEM) != 0 if ((flags & ApplicationInfo.FLAG_SYSTEM) != 0
|| (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { || (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
// System app // System app
// Skip excluded packages // 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(); SelectableAppInfo info = new SelectableAppInfo();
info.packageName = app.activityInfo.packageName; info.packageName = app.activityInfo.packageName;
info.appName = app.activityInfo.applicationInfo.loadLabel(pm); 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<Void, Void, Void> { private class AppLoadingTask extends AsyncTask<Void, Void, Void> {
@Override @Override
@@ -563,6 +584,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
} }
} }
// Get the list of apps already installed for the user
mUserApps = null; mUserApps = null;
try { try {
mUserApps = ipm.getInstalledApplications( mUserApps = ipm.getInstalledApplications(
@@ -586,6 +608,8 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
} }
} }
} }
// Sort the list of visible apps
Collections.sort(mVisibleApps, new AppLabelComparator()); Collections.sort(mVisibleApps, new AppLabelComparator());
// Remove dupes // Remove dupes