List of usage examples for android.content Context CONTEXT_IGNORE_SECURITY
int CONTEXT_IGNORE_SECURITY
To view the source code for android.content Context CONTEXT_IGNORE_SECURITY.
Click Source Link
From source file:Main.java
static String getString(Context context, int resourceID) { String stringResult = "Instagram"; try {//from ww w.ja v a 2 s. c om Context packageContext = context.createPackageContext("com.ihelp101.instagram", Context.CONTEXT_IGNORE_SECURITY); stringResult = packageContext.getString(resourceID); } catch (Exception e) { } return stringResult; }
From source file:Main.java
private static void loadApplicationResources(Context context, Map<String, String> iconPackResources, String packageName) {//from w w w . j a v a2 s.c o m Field[] drawableItems = null; try { Context appContext = context.createPackageContext(packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); drawableItems = Class.forName(packageName + ".R$drawable", true, appContext.getClassLoader()) .getFields(); } catch (Exception e) { return; } for (Field f : drawableItems) { String name = f.getName(); String icon = name.toLowerCase(); name = name.replaceAll("_", "."); iconPackResources.put(name, icon); int activityIndex = name.lastIndexOf("."); if (activityIndex <= 0 || activityIndex == name.length() - 1) { continue; } String iconPackage = name.substring(0, activityIndex); if (TextUtils.isEmpty(iconPackage)) { continue; } iconPackResources.put(iconPackage, icon); String iconActivity = name.substring(activityIndex + 1); if (TextUtils.isEmpty(iconActivity)) { continue; } iconPackResources.put(iconPackage + "." + iconActivity, icon); } }
From source file:Main.java
public static Drawable getIconFromPackageName(String packageName, Context context) { PackageManager pm = context.getPackageManager(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { try {// w w w. j a v a 2 s . c o m PackageInfo pi = pm.getPackageInfo(packageName, 0); Context otherAppCtx = context.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY); int displayMetrics[] = { DisplayMetrics.DENSITY_XXXHIGH, DisplayMetrics.DENSITY_XXHIGH, DisplayMetrics.DENSITY_XHIGH, DisplayMetrics.DENSITY_HIGH, DisplayMetrics.DENSITY_MEDIUM, DisplayMetrics.DENSITY_TV }; for (int displayMetric : displayMetrics) { try { Drawable d = otherAppCtx.getResources().getDrawableForDensity(pi.applicationInfo.icon, displayMetric); if (d != null) { return d; } } catch (Resources.NotFoundException e) { } } } catch (Exception e) { // Handle Error here } } ApplicationInfo appInfo = null; try { appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { return null; } return appInfo.loadIcon(pm); }
From source file:com.anysoftkeyboard.addons.AddOnImpl.java
@Nullable public final Context getPackageContext() { Context c = mPackageContext.get(); if (c == null) { try {/*ww w .j av a2 s . com*/ c = mAskAppContext.createPackageContext(mPackageName, Context.CONTEXT_IGNORE_SECURITY); mPackageContext = new WeakReference<>(c); } catch (NameNotFoundException e) { Logger.w(TAG, "Failed to find package %s!", mPackageName); Logger.w(TAG, "Failed to find package! ", e); } } return c; }
From source file:com.xlythe.engine.theme.Theme.java
public static Context getThemeContext(Context context) { try {//from w w w . j ava 2s . com return context.createPackageContext(getPackageName(), context.CONTEXT_INCLUDE_CODE + Context.CONTEXT_IGNORE_SECURITY); } catch (NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:com.germainz.identiconizer.xposed.XposedMod.java
@Override public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable { if ("com.android.providers.contacts".equals(lpparam.packageName)) { try {/*from w w w . j ava2s. c o m*/ findAndHookMethod("com.android.providers.contacts.DataRowHandlerForStructuredName", lpparam.classLoader, "insert", SQLiteDatabase.class, "com.android.providers.contacts.TransactionContext", long.class, ContentValues.class, new XC_MethodHook() { @Override protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable { CONFIG.reload(); if (CONFIG.isEnabled()) { ContentValues values = (ContentValues) param.args[3]; String name = values.getAsString( ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME); if (!TextUtils.isEmpty(name)) { long rawContactId = ((Number) param.args[2]).longValue(); SQLiteDatabase db = (SQLiteDatabase) param.args[0]; Identicon identicon = IdenticonFactory.makeIdenticon( CONFIG.getIdenticonStyle(), CONFIG.getIdenticonSize(), CONFIG.getIdenticonBgColor()); ContentValues identiconValues = new ContentValues(); identiconValues.put("mimetype_id", 10); identiconValues.put(ContactsContract.Data.RAW_CONTACT_ID, rawContactId); identiconValues.put(ContactsContract.CommonDataKinds.Photo.PHOTO, identicon.generateIdenticonByteArray(name)); identiconValues.put(ContactsContract.Data.IS_PRIMARY, 1); identiconValues.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1); db.insert(ContactsContract.Contacts.Data.CONTENT_DIRECTORY, null, identiconValues); } } } }); } catch (Throwable e) { Context systemContext = (Context) getStaticObjectField( findClass("android.app.ActivityThread", null), "mSystemContext"); if (systemContext == null) { Object activityThread = callStaticMethod(findClass("android.app.ActivityThread", null), "currentActivityThread"); systemContext = (Context) callMethod(activityThread, "getSystemContext"); } Context contactsProviderContext = systemContext .createPackageContext("com.android.providers.contacts", Context.CONTEXT_IGNORE_SECURITY); Context identiconizerContext = systemContext.createPackageContext(Config.PACKAGE_NAME, Context.CONTEXT_IGNORE_SECURITY); String contentText = identiconizerContext.getString(R.string.xposed_error_text); Notification notice = new NotificationCompat.Builder(contactsProviderContext) .setSmallIcon(NOTIF_ICON_RES_ID) .setContentTitle(identiconizerContext.getString(R.string.xposed_error_title)) .setContentText(contentText) .setStyle(new NotificationCompat.BigTextStyle().bigText(contentText)).build(); NotificationManager nm = (NotificationManager) contactsProviderContext .getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(1, notice); } } if (Config.PACKAGE_NAME.equals(lpparam.packageName)) { findAndHookMethod(Config.PACKAGE_NAME + ".Config", lpparam.classLoader, "isXposedModActive", XC_MethodReplacement.returnConstant(true)); } }
From source file:com.gnuroot.rsinstaller.RSLauncherMain.java
/** * Renames assets from .mp3 to .tar.gz.// w w w .ja v a 2s .c o m * @param packageName */ private void copyAssets(String packageName) { Context friendContext = null; try { friendContext = this.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY); } catch (NameNotFoundException e1) { return; } AssetManager assetManager = friendContext.getAssets(); String[] files = null; try { files = assetManager.list(""); } catch (IOException e) { Log.e("tag", "Failed to get asset file list.", e); } for (String filename : files) { Log.i("files ", filename); InputStream in = null; OutputStream out = null; try { in = assetManager.open(filename); filename = filename.replace(".mp3", ".tar.gz"); out = openFileOutput(filename, MODE_PRIVATE); copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; } catch (IOException e) { Log.e("tag", "Failed to copy asset file: " + filename, e); } } }
From source file:com.aware.ui.Plugins_Manager.java
/** * Given a package and class name, check if the class exists or not. * @param String package_name//from w w w . j a v a2 s . c o m * @param String class_name * @return true if exists, false otherwise */ private boolean isClassAvailable(String package_name, String class_name) { try { Context package_context = createPackageContext(package_name, Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE); package_context.getClassLoader().loadClass(package_name + "." + class_name); } catch (ClassNotFoundException e) { return false; } catch (NameNotFoundException e) { return false; } return true; }
From source file:com.anysoftkeyboard.addons.AddOnsFactory.java
private List<E> getExternalAddOns() { if (!mReadExternalPacksToo)//this will disable external packs (API careful stage) return Collections.emptyList(); final PackageManager packageManager = mContext.getPackageManager(); final List<ResolveInfo> broadcastReceivers = packageManager .queryBroadcastReceivers(new Intent(mReceiverInterface), PackageManager.GET_META_DATA); final List<E> externalAddOns = new ArrayList<>(); for (final ResolveInfo receiver : broadcastReceivers) { if (receiver.activityInfo == null) { Logger.e(mTag, "BroadcastReceiver has null ActivityInfo. Receiver's label is " + receiver.loadLabel(packageManager)); Logger.e(mTag, "Is the external keyboard a service instead of BroadcastReceiver?"); // Skip to next receiver continue; }/* w ww . ja va2 s . c o m*/ if (!receiver.activityInfo.enabled || !receiver.activityInfo.applicationInfo.enabled) continue; try { final Context externalPackageContext = mContext .createPackageContext(receiver.activityInfo.packageName, Context.CONTEXT_IGNORE_SECURITY); final List<E> packageAddOns = getAddOnsFromActivityInfo(externalPackageContext, receiver.activityInfo); externalAddOns.addAll(packageAddOns); } catch (final NameNotFoundException e) { Logger.e(mTag, "Did not find package: " + receiver.activityInfo.packageName); } } return externalAddOns; }
From source file:org.mozilla.gecko.GeckoApp.java
Class<?> getPluginClass(String packageName, String className) throws NameNotFoundException, ClassNotFoundException { Context pluginContext = mAppContext.createPackageContext(packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); ClassLoader pluginCL = pluginContext.getClassLoader(); return pluginCL.loadClass(className); }