Always include default system IMEs for restricted profiles

Add default IMEs to an exclusion set so that we don't include them in the
list of toggleable system apps that we show the user.

Bug: 8724246

Unrevert the change to include disabled apps, as the above change fixes the
reason for the revert.

Bug: 8713202

Change-Id: Ifced841ad3bfbde33d2403356216dd1749b7fa9a
This commit is contained in:
Amith Yamasani
2013-04-25 21:35:54 -07:00
parent 0cb93523b2
commit a7a93784d1

View File

@@ -34,6 +34,7 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
@@ -63,6 +64,9 @@ import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethod;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.AdapterView; import android.widget.AdapterView;
@@ -102,6 +106,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
private static final int DIALOG_ID_EDIT_USER_INFO = 1; private static final int DIALOG_ID_EDIT_USER_INFO = 1;
private PackageManager mPackageManager;
private UserManager mUserManager; private UserManager mUserManager;
private UserHandle mUser; private UserHandle mUser;
@@ -262,6 +267,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
} }
mNewUser = args.getBoolean(EXTRA_NEW_USER, false); mNewUser = args.getBoolean(EXTRA_NEW_USER, false);
} }
mPackageManager = getActivity().getPackageManager();
mUserManager = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); mUserManager = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
addPreferencesFromResource(R.xml.app_restrictions); addPreferencesFromResource(R.xml.app_restrictions);
mAppList = getPreferenceScreen(); mAppList = getPreferenceScreen();
@@ -347,22 +353,74 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
} }
} }
private void addSystemApps(List<SelectableAppInfo> visibleApps, Intent intent) { private boolean isSystemPackage(String packageName) {
try {
final PackageInfo pi = mPackageManager.getPackageInfo(packageName, 0);
if (pi.applicationInfo == null) return false;
final int flags = pi.applicationInfo.flags;
if ((flags & ApplicationInfo.FLAG_SYSTEM) != 0
|| (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
return true;
}
} catch (NameNotFoundException nnfe) {
// Missing package?
}
return false;
}
/**
* Find all pre-installed input methods that are marked as default
* and add them to an exclusion list so that they aren't
* presented to the user for toggling.
* Don't add non-default ones, as they may include other stuff that we
* don't need to auto-include.
* @param excludePackages the set of package names to append to
*/
private void addSystemImes(Set<String> excludePackages) {
final Context context = getActivity();
if (context == null) return;
InputMethodManager imm = (InputMethodManager)
context.getSystemService(Context.INPUT_METHOD_SERVICE);
List<InputMethodInfo> imis = imm.getInputMethodList();
for (InputMethodInfo imi : imis) {
try {
if (imi.isDefault(context) && isSystemPackage(imi.getPackageName())) {
excludePackages.add(imi.getPackageName());
}
} catch (Resources.NotFoundException rnfe) {
// Not default
}
}
}
/**
* Add system apps that match an intent to the list, excluding any packages in the exclude list.
* @param visibleApps list of apps to append the new list to
* @param intent the intent to match
* @param excludePackages the set of package names to be excluded, since they're required
*/
private void addSystemApps(List<SelectableAppInfo> visibleApps, Intent intent,
Set<String> excludePackages) {
if (getActivity() == null) return; if (getActivity() == null) return;
final PackageManager pm = getActivity().getPackageManager(); final PackageManager pm = mPackageManager;
List<ResolveInfo> launchableApps = pm.queryIntentActivities(intent, 0); List<ResolveInfo> launchableApps = pm.queryIntentActivities(intent,
PackageManager.GET_DISABLED_COMPONENTS);
for (ResolveInfo app : launchableApps) { for (ResolveInfo app : launchableApps) {
if (app.activityInfo != null && app.activityInfo.applicationInfo != null) { if (app.activityInfo != null && app.activityInfo.applicationInfo != null) {
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
if (excludePackages.contains(app.activityInfo.packageName)) 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);
info.icon = app.activityInfo.loadIcon(pm); info.icon = app.activityInfo.loadIcon(pm);
info.activityName = app.activityInfo.loadLabel(pm); info.activityName = app.activityInfo.loadLabel(pm);
if (info.activityName == null) info.activityName = info.appName; if (info.activityName == null) info.activityName = info.appName;
visibleApps.add(info); visibleApps.add(info);
} }
} }
@@ -392,17 +450,20 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
mVisibleApps = new ArrayList<SelectableAppInfo>(); mVisibleApps = new ArrayList<SelectableAppInfo>();
final Context context = getActivity(); final Context context = getActivity();
if (context == null) return; if (context == null) return;
PackageManager pm = context.getPackageManager(); final PackageManager pm = mPackageManager;
IPackageManager ipm = AppGlobals.getPackageManager(); IPackageManager ipm = AppGlobals.getPackageManager();
final HashSet<String> excludePackages = new HashSet<String>();
addSystemImes(excludePackages);
// Add launchers // Add launchers
Intent launcherIntent = new Intent(Intent.ACTION_MAIN); Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER); launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
addSystemApps(mVisibleApps, launcherIntent); addSystemApps(mVisibleApps, launcherIntent, excludePackages);
// Add widgets // Add widgets
Intent widgetIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE); Intent widgetIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
addSystemApps(mVisibleApps, widgetIntent); addSystemApps(mVisibleApps, widgetIntent, excludePackages);
List<ApplicationInfo> installedApps = pm.getInstalledApplications(0); List<ApplicationInfo> installedApps = pm.getInstalledApplications(0);
for (ApplicationInfo app : installedApps) { for (ApplicationInfo app : installedApps) {
@@ -470,7 +531,7 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
private void populateApps() { private void populateApps() {
final Context context = getActivity(); final Context context = getActivity();
if (context == null) return; if (context == null) return;
PackageManager pm = context.getPackageManager(); final PackageManager pm = mPackageManager;
IPackageManager ipm = AppGlobals.getPackageManager(); IPackageManager ipm = AppGlobals.getPackageManager();
mAppList.removeAll(); mAppList.removeAll();
Intent restrictionsIntent = new Intent(Intent.ACTION_GET_RESTRICTION_ENTRIES); Intent restrictionsIntent = new Intent(Intent.ACTION_GET_RESTRICTION_ENTRIES);