@Override public Context createPackageContext(String packageName, int flags) throws PackageManager.NameNotFoundException { return mBase.createPackageContext(packageName, flags); }
@NonNull private Context findContextForPackage(Uri source, String packageName) { // Fast path if (packageName.equals(context.getPackageName())) { return context; } try { return context.createPackageContext(packageName, /*flags=*/ 0); } catch (NameNotFoundException e) { // The parent APK holds the correct context if the resource is located in a split if (packageName.contains(context.getPackageName())) { return context; } throw new IllegalArgumentException( "Failed to obtain context or unrecognized Uri format for: " + source, e); } }
Context getAppContext(final String packageName) { Context context = null; try { context = getHostContext().createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return context; }
Context context; try { context = mContext.createPackageContext(packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); if (context == null) {
private Context createPackageContext(String packageName) { try { Context hostContext = VirtualCore.get().getContext(); return hostContext.createPackageContext(packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); VirtualRuntime.crash(new RemoteException()); } throw new RuntimeException(); }
public static List<Library> detect(Context mCtx, List<Library> libraries) { ArrayList<Library> foundLibraries = new ArrayList<>(); // Loop through known libraries for (Library library : libraries) { if (!TextUtils.isEmpty(library.getClassPath())) { try { Context ctx = mCtx.createPackageContext(mCtx.getPackageName(), Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); Class<?> clazz = Class.forName(library.getClassPath(), false, ctx.getClassLoader()); // Detected a library!!! if (clazz != null) { foundLibraries.add(library); } } catch (ClassNotFoundException e) { //e.printStackTrace(); } catch (PackageManager.NameNotFoundException e) { //e.printStackTrace(); } } } // Only return AppSource if app has a library //return libraries.size() > 0 ? new AppSource(pkg, libraries) : null; return foundLibraries; } }
Context systemUi = context.createPackageContext(NotificationCompat.SYSTEM_UI_PKG, Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE); int layoutId = getSystemId(systemUi, "status_bar_notification_row", "layout");
Context systemUi = context.createPackageContext(NotificationCompat.SYSTEM_UI_PKG, Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE); int layoutId = getSystemId(systemUi, "time_axis", "layout");
String applicationPackageName, int iconResourceId) { try { Context current = context.createPackageContext(applicationPackageName, /*flags=*/ 0); String resourcePackageName = current.getResources().getResourcePackageName(iconResourceId); return applicationPackageName.equals(resourcePackageName);
public void clearALLCache() { List<PackageInfo> packList = getPackageManager().getInstalledPackages(0); for (int i=0; i < packList.size(); i++) { PackageInfo packInfo = packList.get(i); if ( (packInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { String appName = packInfo.applicationInfo.loadLabel(getPackageManager()).toString(); try { // clearing app data // Runtime runtime = Runtime.getRuntime(); // runtime.exec("pm clear "+packInfo.packageName); Context context = getApplicationContext().createPackageContext(packInfo.packageName,Context.CONTEXT_IGNORE_SECURITY); deleteCache(context); } catch (Exception e) { e.printStackTrace(); } } } }
Context systemUi = null; try { systemUi = context.createPackageContext(NotificationCompat.SYSTEM_UI_PKG, Context.CONTEXT_IGNORE_SECURITY); } catch (PackageManager.NameNotFoundException e) {
@Test public void load_withApplicationIconResourceNameUri_asDrawable_producesNonNullDrawable() throws ExecutionException, InterruptedException, NameNotFoundException { for (String packageName : getInstalledPackages()) { int iconResourceId = getResourceId(packageName); Context toUse = context.createPackageContext(packageName, /*flags=*/ 0); Resources resources = toUse.getResources(); Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(packageName) .appendPath(resources.getResourceTypeName(iconResourceId)) .appendPath(resources.getResourceEntryName(iconResourceId)) .build(); Drawable drawable = Glide.with(context) .load(uri) .submit() .get(); assertThat(drawable).isNotNull(); } }
@Test public void load_withApplicationIconResourceNameUri_asDrawable_withTransform_nonNullDrawable() throws ExecutionException, InterruptedException, NameNotFoundException { for (String packageName : getInstalledPackages()) { int iconResourceId = getResourceId(packageName); Context toUse = context.createPackageContext(packageName, /*flags=*/ 0); Resources resources = toUse.getResources(); Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(packageName) .appendPath(resources.getResourceTypeName(iconResourceId)) .appendPath(resources.getResourceEntryName(iconResourceId)) .build(); Drawable drawable = Glide.with(context) .load(uri) .apply(centerCropTransform()) .submit() .get(); assertThat(drawable).isNotNull(); } }
@Test public void load_withApplicationIconResourceNameUri_asBitmap_producesNonNullBitmap() throws ExecutionException, InterruptedException, NameNotFoundException { for (String packageName : getInstalledPackages()) { int iconResourceId = getResourceId(packageName); Context toUse = context.createPackageContext(packageName, /*flags=*/ 0); Resources resources = toUse.getResources(); Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(packageName) .appendPath(resources.getResourceTypeName(iconResourceId)) .appendPath(resources.getResourceEntryName(iconResourceId)) .build(); Bitmap bitmap = Glide.with(context) .asBitmap() .load(uri) .submit() .get(); assertThat(bitmap).isNotNull(); } }
@Override public Context createPackageContext(String packageName, int flags) throws PackageManager.NameNotFoundException { return mBase.createPackageContext(packageName, flags); }
@Test public void load_withApplicationIconResourceNameUri_asBitmap_withTransform_nonNullBitmap() throws ExecutionException, InterruptedException, NameNotFoundException { for (String packageName : getInstalledPackages()) { int iconResourceId = getResourceId(packageName); Context toUse = context.createPackageContext(packageName, /*flags=*/ 0); Resources resources = toUse.getResources(); Uri uri = new Uri.Builder() .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE) .authority(packageName) .appendPath(resources.getResourceTypeName(iconResourceId)) .appendPath(resources.getResourceEntryName(iconResourceId)) .build(); Bitmap bitmap = Glide.with(context) .asBitmap() .apply(centerCropTransform()) .load(uri) .submit() .get(); assertThat(bitmap).isNotNull(); } }
try { contextImpl = systemContextImpl.createPackageContext( applicationInfo.packageName, Context.CONTEXT_INCLUDE_CODE); } catch (PackageManager.NameNotFoundException e) {
private static String getString(int resId, Context context) throws PackageManager.NameNotFoundException { try { Context appContext = context.createPackageContext("ml.qingsu.fuckview", Context.CONTEXT_IGNORE_SECURITY); return appContext.getResources().getString(resId); } catch (NullPointerException e) { return null; } }
.createPackageContext(applicationInfo.packageName, Context.CONTEXT_INCLUDE_CODE);
static Context getPackageContext(String packageName) throws PackageManager.NameNotFoundException { Object currentThread = callStaticMethod(findClass("android.app.ActivityThread", null), "currentActivityThread"); Context systemContext = (Context) callMethod(currentThread, "getSystemContext"); return systemContext.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY); }