@Override protected List<AppInfo> doInBackground(Object... objects) { List<AppInfo> labelsPackages = new ArrayList<>(); PackageManager packageManager = activity.getPackageManager(); Iterable<ApplicationInfo> appInfos = packageManager.getInstalledApplications(0); for (PackageItemInfo appInfo : appInfos) { String packageName = appInfo.packageName; if (!isHidden(packageName)) { CharSequence label = appInfo.loadLabel(packageManager); Drawable icon = appInfo.loadIcon(packageManager); if (label != null) { labelsPackages.add(new AppInfo(packageName, label.toString(), icon)); } } } Collections.sort(labelsPackages); return labelsPackages; }
@Override protected List<AppInfo> doInBackground(Void... objects) { List<AppInfo> labelsPackages = new ArrayList<AppInfo>(); PackageManager packageManager = activity.getPackageManager(); Iterable<ApplicationInfo> appInfos = packageManager.getInstalledApplications(0); for (PackageItemInfo appInfo : appInfos) { String packageName = appInfo.packageName; if (!isHidden(packageName)) { CharSequence label = appInfo.loadLabel(packageManager); Drawable icon = appInfo.loadIcon(packageManager); if (label != null) { labelsPackages.add(new AppInfo(packageName, label.toString(), icon)); } } } Collections.sort(labelsPackages); return labelsPackages; }
<T extends PackageItemInfo>List substract(List<T> left, List<T> right){ List<T> list = new ArrayList<>(); for (int i = 0; i < left.size() ; i++) { boolean found = false; for (int j = 0; j < right.size() ; j++) { if (left.get(i).name.equals(right.get(j).name)){ found = true; break; } } if (!found) { list.add(left.get(i)); } } return list; }
private static void checkServices(Context context, PackageInfo packageInfo) { Map hashMap = new HashMap(); hashMap.put("com.xiaomi.push.service.XMPushService", new Boolean[]{Boolean.valueOf(true), Boolean.valueOf(false)}); hashMap.put(PushMessageHandler.class.getCanonicalName(), new Boolean[]{Boolean.valueOf (true), Boolean.valueOf(true)}); hashMap.put(MessageHandleService.class.getCanonicalName(), new Boolean[]{Boolean.valueOf (true), Boolean.valueOf(false)}); if (packageInfo.services != null) { for (PackageItemInfo packageItemInfo : packageInfo.services) { if (!TextUtils.isEmpty(packageItemInfo.name) && hashMap.containsKey (packageItemInfo.name)) { Boolean[] boolArr = (Boolean[]) hashMap.remove(packageItemInfo.name); if (boolArr[0].booleanValue() != packageItemInfo.enabled) { throw new a(String.format("Wrong attribute: %n <service " + "android:name=\"%1$s\" .../> android:enabled should be %<b.", new Object[]{packageItemInfo.name, boolArr[0]}), packageItemInfo); } else if (boolArr[1].booleanValue() != packageItemInfo.exported) { throw new a(String.format("Wrong attribute: %n <service " + "android:name=\"%1$s\" .../> android:exported should be %<b.", new Object[]{packageItemInfo.name, boolArr[1]}), packageItemInfo); } else if (hashMap.isEmpty()) { break; } } } } if (!hashMap.isEmpty()) { throw new a(String.format("<service android:name=\"%1$s\" /> is missing or disabled" + ".", new Object[]{hashMap.keySet().iterator().next()}), null); } }
private static void findAndCheckReceiverInfo(PackageManager packageManager, Intent intent, Class<?> cls, Boolean[] boolArr) { int i; for (ResolveInfo resolveInfo : packageManager.queryBroadcastReceivers(intent, 16384)) { PackageItemInfo packageItemInfo = resolveInfo.activityInfo; if (packageItemInfo != null && cls.getCanonicalName().equals(packageItemInfo.name)) { if (boolArr[0].booleanValue() != packageItemInfo.enabled) { throw new a(String.format("Wrong attribute: %n <receiver " + "android:name=\"%1$s\" .../> android:enabled should be %<b.", new Object[]{packageItemInfo.name, boolArr[0]}), packageItemInfo); } else if (boolArr[1].booleanValue() != packageItemInfo.exported) { throw new a(String.format("Wrong attribute: %n <receiver " + "android:name=\"%1$s\" .../> android:exported should be %<b.", new Object[]{packageItemInfo.name, boolArr[1]}), packageItemInfo); } else { i = 1; if (i == 0) { throw new a(String.format("<receiver android:name=\"%1$s\" /> is missing " + "or disabled.", new Object[]{cls.getCanonicalName()}), null); } } } } i = 0; if (i == 0) { throw new a(String.format("<receiver android:name=\"%1$s\" /> is missing or disabled" + ".", new Object[]{cls.getCanonicalName()}), null); } }
private boolean parsePackageItemInfo(DynamicApkInfo owner, PackageItemInfo outInfo, String[] outError, String tag, TypedArray sa, int nameRes, int labelRes, int iconRes, int logoRes, int bannerRes) { String name = sa.getString(nameRes); if (name == null) { outError[0] = tag + " does not specify android:name"; return false; } outInfo.name = buildClassName(owner.applicationInfo.packageName, name, outError); if (outInfo.name == null) { return false; } int iconVal = sa.getResourceId(iconRes, 0); if (iconVal != 0) { outInfo.icon = iconVal; outInfo.nonLocalizedLabel = null; } int logoVal = sa.getResourceId(logoRes, 0); if (logoVal != 0) { outInfo.logo = logoVal; } int bannerVal = sa.getResourceId(bannerRes, 0); if (bannerVal != 0) { outInfo.banner = bannerVal; } TypedValue v = sa.peekValue(labelRes); if (v != null && (outInfo.labelRes=v.resourceId) == 0) { outInfo.nonLocalizedLabel = v.coerceToString(); } outInfo.packageName = owner.packageName; return true; }
public Component(final ParseComponentArgs args, final ComponentInfo outInfo) { this(args, (PackageItemInfo)outInfo); if (args.outError[0] != null) { return; } if (args.processRes != 0) { CharSequence pname; if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) { // pname = args.sa.getNonConfigurationString(args.processRes, // Configuration.NATIVE_CONFIG_VERSION); pname = args.sa.getNonResourceString(args.processRes); } else { // Some older apps have been seen to use a resource reference // here that on older builds was ignored (with a warning). We // need to continue to do this for them so they don't break. pname = args.sa.getNonResourceString(args.processRes); } outInfo.processName = buildProcessName(owner.applicationInfo.packageName, owner.applicationInfo.processName, pname, args.sepProcesses, args.outError); } if (args.descriptionRes != 0) { outInfo.descriptionRes = args.sa.getResourceId(args.descriptionRes, 0); } outInfo.enabled = args.sa.getBoolean(args.enabledRes, true); }
public static Drawable loadItemIcon(PackageManager object, PackageItemInfo itemInfo, ApplicationInfo appInfo) { try { Method m = object.getClass().getDeclaredMethod("loadItemIcon", new Class[]{PackageItemInfo.class, ApplicationInfo.class}); return (Drawable) m.invoke(object, new Object[]{itemInfo, appInfo}); } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { e.printStackTrace(); } return null; }
/** * @see <href a="http://developer.android.com/reference/android/content/pm/PackageItemInfo.html">PackageItemInfo</href> * * @param parser * @param info */ private static void parsePackageItem(XmlResourceParser parser, PackageItemInfo info) { final int attCount = parser.getAttributeCount(); for (int i = 0; i < attCount; i++) { String attName = parser.getAttributeName(i); String attValue = parser.getAttributeValue(i); if (ATTR_BANNER.equals(attName) && afterApiLevel(20)) { info.logo = toResId(attValue); } else if (ATTR_ICON.equals(attName)) { info.icon = toResId(attValue); } else if (ATTR_NAME.equals(attName)) { String cName = attValue; info.name = cName; } else if (ATTR_LABEL.equals(attName)) { if (attValue.startsWith("@")) { info.labelRes = Integer.parseInt(attValue.substring(1)); } else { info.nonLocalizedLabel = attValue; } } else if (ATTR_LOGO.equals(attName) && afterApiLevel(9)) { info.logo = toResId(attValue); } else { if (LOG_UN_HANDLED_ITEM) { Log.w(TAG, "un-handled att: " + attName + "=" + attValue); } } } }
/** @hide */ @Override public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) { return mBase.loadItemIcon(itemInfo, appInfo); }
/** @hide */ @Override public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) { return mBase.loadUnbadgedItemIcon(itemInfo, appInfo); }
public a(String str, PackageItemInfo packageItemInfo) { super(str); this.a = packageItemInfo; }
public Component(final ParsePackageItemArgs args, final PackageItemInfo outInfo) { owner = args.owner; intents = new ArrayList<II>(0); String name = args.sa.getString(args.nameRes); if (name == null) { className = null; args.outError[0] = args.tag + " does not specify android:name"; return; } outInfo.name = buildClassName(owner.applicationInfo.packageName, name, args.outError); if (outInfo.name == null) { className = null; args.outError[0] = args.tag + " does not have valid android:name"; return; } className = outInfo.name; int iconVal = args.sa.getResourceId(args.iconRes, 0); if (iconVal != 0) { outInfo.icon = iconVal; outInfo.nonLocalizedLabel = null; } int logoVal = args.sa.getResourceId(args.logoRes, 0); if (logoVal != 0) { outInfo.logo = logoVal; } // int bannerVal = args.sa.getResourceId(args.bannerRes, 0); // if (bannerVal != 0) { // outInfo.banner = bannerVal; // } TypedValue v = args.sa.peekValue(args.labelRes); if (v != null && (outInfo.labelRes=v.resourceId) == 0) { outInfo.nonLocalizedLabel = v.coerceToString(); } outInfo.packageName = owner.packageName; }
public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo){ return ReflectUtil.loadItemIcon(mProxy, itemInfo, appInfo); }
private void updateList(List<ServiceInfo> services) { final PreferenceScreen screen = getPreferenceScreen(); screen.removeAll(); Collections.sort(services, new PackageItemInfo.DisplayNameComparator(mPM)); for (ServiceInfo service : services) { final ComponentName cn = new ComponentName(service.packageName, service.name); final String title = service.loadLabel(mPM).toString(); final SwitchPreference pref = new SwitchPreference(mContext); pref.setPersistent(false); pref.setIcon(service.loadIcon(mPM)); pref.setTitle(title); pref.setChecked(mServiceListing.isEnabled(cn)); pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { final boolean enable = (boolean) newValue; return setEnabled(cn, title, enable); } }); screen.addPreference(pref); } }