@Test public void testLoadNonSystemPartner() { mPackageManager.addResolveInfoForIntent( new Intent(ACTION_PARTNER_CUSTOMIZATION), Arrays.asList( createResolveInfo("foo.bar", false, true), createResolveInfo("test.partner.package", false, true)) ); Partner partner = Partner.get(mContext); assertNull("Partner should be null", partner); }
public static synchronized Partner get(Context context) { if (!sSearched) { PackageManager pm = context.getPackageManager(); final Intent intent = new Intent(ACTION_PARTNER_CUSTOMIZATION); List<ResolveInfo> receivers; if (VERSION.SDK_INT >= VERSION_CODES.N) { receivers = pm.queryBroadcastReceivers( intent, PackageManager.MATCH_SYSTEM_ONLY | PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE); } else { receivers = pm.queryBroadcastReceivers(intent, 0); } for (ResolveInfo info : receivers) { if (info.activityInfo == null) { continue; } final ApplicationInfo appInfo = info.activityInfo.applicationInfo; if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { try { final Resources res = pm.getResourcesForApplication(appInfo); sPartner = new Partner(appInfo.packageName, res); break; } catch (NameNotFoundException e) { Log.w(TAG, "Failed to find resources for " + appInfo.packageName); } } } sSearched = true; } return sPartner; }
Partner { public static synchronized Partner get(Context context) { if (!sSearched) { PackageManager pm = context.getPackageManager(); final Intent intent = new Intent(ACTION_PARTNER_CUSTOMIZATION); List<ResolveInfo> receivers; if (VERSION.SDK_INT >= VERSION_CODES.N) { receivers = pm.queryBroadcastReceivers( intent, PackageManager.MATCH_SYSTEM_ONLY | PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE); } else { receivers = pm.queryBroadcastReceivers(intent, 0); } for (ResolveInfo info : receivers) { if (info.activityInfo == null) { continue; } final ApplicationInfo appInfo = info.activityInfo.applicationInfo; if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { try { final Resources res = pm.getResourcesForApplication(appInfo); sPartner = new Partner(appInfo.packageName, res); break; } catch (NameNotFoundException e) { Log.w(TAG, "Failed to find resources for " + appInfo.packageName); } } } sSearched = true; } return sPartner; } }
Partner { public static synchronized Partner get(Context context) { if (!sSearched) { PackageManager pm = context.getPackageManager(); final Intent intent = new Intent(ACTION_PARTNER_CUSTOMIZATION); List<ResolveInfo> receivers; if (VERSION.SDK_INT >= VERSION_CODES.N) { receivers = pm.queryBroadcastReceivers( intent, PackageManager.MATCH_SYSTEM_ONLY | PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE); } else { receivers = pm.queryBroadcastReceivers(intent, 0); } for (ResolveInfo info : receivers) { if (info.activityInfo == null) { continue; } final ApplicationInfo appInfo = info.activityInfo.applicationInfo; if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { try { final Resources res = pm.getResourcesForApplication(appInfo); sPartner = new Partner(appInfo.packageName, res); break; } catch (NameNotFoundException e) { Log.w(TAG, "Failed to find resources for " + appInfo.packageName); } } } sSearched = true; } return sPartner; } private  Partner(String packageName, Resources res); }
Partner { public static synchronized Partner get(Context context) { if (!sSearched) { PackageManager pm = context.getPackageManager(); final Intent intent = new Intent(ACTION_PARTNER_CUSTOMIZATION); List<ResolveInfo> receivers; if (VERSION.SDK_INT >= VERSION_CODES.N) { receivers = pm.queryBroadcastReceivers( intent, PackageManager.MATCH_SYSTEM_ONLY | PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE); } else { receivers = pm.queryBroadcastReceivers(intent, 0); } for (ResolveInfo info : receivers) { if (info.activityInfo == null) { continue; } final ApplicationInfo appInfo = info.activityInfo.applicationInfo; if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { try { final Resources res = pm.getResourcesForApplication(appInfo); sPartner = new Partner(appInfo.packageName, res); break; } catch (NameNotFoundException e) { Log.w(TAG, "Failed to find resources for " + appInfo.packageName); } } } sSearched = true; } return sPartner; } private  Partner(String packageName, Resources res); static Drawable getDrawable(Context context, @DrawableRes int id); static String getString(Context context, @StringRes int id); static int getColor(Context context, @ColorRes int id); static CharSequence getText(Context context, @StringRes int id); static ResourceEntry getResourceEntry(Context context, @AnyRes int id); static synchronized Partner get(Context context); @VisibleForTesting static synchronized void resetForTesting(); String getPackageName(); Resources getResources(); int getIdentifier(String name, String defType); }
Partner { public static synchronized Partner get(Context context) { if (!sSearched) { PackageManager pm = context.getPackageManager(); final Intent intent = new Intent(ACTION_PARTNER_CUSTOMIZATION); List<ResolveInfo> receivers; if (VERSION.SDK_INT >= VERSION_CODES.N) { receivers = pm.queryBroadcastReceivers( intent, PackageManager.MATCH_SYSTEM_ONLY | PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DIRECT_BOOT_UNAWARE); } else { receivers = pm.queryBroadcastReceivers(intent, 0); } for (ResolveInfo info : receivers) { if (info.activityInfo == null) { continue; } final ApplicationInfo appInfo = info.activityInfo.applicationInfo; if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { try { final Resources res = pm.getResourcesForApplication(appInfo); sPartner = new Partner(appInfo.packageName, res); break; } catch (NameNotFoundException e) { Log.w(TAG, "Failed to find resources for " + appInfo.packageName); } } } sSearched = true; } return sPartner; } private  Partner(String packageName, Resources res); static Drawable getDrawable(Context context, @DrawableRes int id); static String getString(Context context, @StringRes int id); static int getColor(Context context, @ColorRes int id); static CharSequence getText(Context context, @StringRes int id); static ResourceEntry getResourceEntry(Context context, @AnyRes int id); static synchronized Partner get(Context context); @VisibleForTesting static synchronized void resetForTesting(); String getPackageName(); Resources getResources(); int getIdentifier(String name, String defType);  }