use of android.content.ContextWrapper in project kcanotify by antest1.
the class KcaUtils method getFairyImageFromStorage.
public static Bitmap getFairyImageFromStorage(Context context, String name, KcaDBHelper helper) {
ContextWrapper cw = new ContextWrapper(context);
File directory = cw.getDir("fairy", Context.MODE_PRIVATE);
File myImageFile = new File(directory, KcaUtils.format("%s.png", name));
Bitmap bitmap = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
int fairy_id = Integer.parseInt(name.replace("noti_icon_", ""));
if (fairy_id == 0) {
bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.noti_icon_0);
} else if (FAIRY_SPECIAL_FLAG && fairy_id >= FAIRY_SPECIAL_PREFIX) {
bitmap = BitmapFactory.decodeResource(context.getResources(), getId(name, R.mipmap.class));
} else {
try {
bitmap = BitmapFactory.decodeStream(new FileInputStream(myImageFile), null, options);
} catch (FileNotFoundException e) {
e.printStackTrace();
setPreferences(context, PREF_DATALOAD_ERROR_FLAG, true);
if (helper != null)
helper.recordErrorLog(ERROR_TYPE_DATALOAD, name, "getFairyImageFromStorage", "0", getStringFromException(e));
bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.noti_icon_0);
}
if (bitmap == null) {
setPreferences(context, PREF_DATALOAD_ERROR_FLAG, true);
if (helper != null)
helper.recordErrorLog(ERROR_TYPE_DATALOAD, name, "getFairyImageFromStorage", "0", "bitmap==null");
bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.noti_icon_0);
}
}
return bitmap;
}
use of android.content.ContextWrapper in project kcanotify by antest1.
the class KcaUtils method setFairyImageFromStorage.
public static void setFairyImageFromStorage(Context context, String name, ImageView view, int dp) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int fairy_id = Integer.parseInt(name.replace("noti_icon_", ""));
int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);
ContextWrapper cw = new ContextWrapper(context);
File directory = cw.getDir("fairy", Context.MODE_PRIVATE);
File myImageFile = new File(directory, KcaUtils.format("%s.png", name));
if (myImageFile.exists()) {
if (px > 0) {
GlideApp.with(context).load(myImageFile.getPath()).dontAnimate().override(px, px).into(view);
} else {
GlideApp.with(context).load(myImageFile.getPath()).into(view);
}
} else if (FAIRY_SPECIAL_FLAG && fairy_id >= FAIRY_SPECIAL_PREFIX) {
view.setImageResource(getId(name, R.mipmap.class));
} else {
view.setImageResource(R.mipmap.noti_icon_0);
}
}
use of android.content.ContextWrapper in project android_packages_apps_GmsCore by microg.
the class DynamiteLoaderImpl method createModuleContext.
@Override
public IObjectWrapper createModuleContext(IObjectWrapper wrappedContext, String moduleId, int minVersion) throws RemoteException {
Log.d(TAG, "unimplemented Method: createModuleContext for " + moduleId + " at version " + minVersion + ", returning gms context");
final Context context = (Context) ObjectWrapper.unwrap(wrappedContext);
try {
return ObjectWrapper.wrap(new ContextWrapper(context.createPackageContext(Constants.GMS_PACKAGE_NAME, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY)) {
@Override
public Context getApplicationContext() {
return context;
}
});
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "returning null instead", e);
return null;
}
}
use of android.content.ContextWrapper in project android_packages_apps_Settings by SudaMod.
the class ThemePreferenceControllerTest method setup.
@Before
public void setup() {
mMockOverlayManager = mock(OverlayManager.class);
mMockPackageManager = mock(PackageManager.class);
mContext = new ContextWrapper(InstrumentationRegistry.getTargetContext()) {
@Override
public PackageManager getPackageManager() {
return mMockPackageManager;
}
};
mPreferenceController = new ThemePreferenceController(mContext, mMockOverlayManager);
}
use of android.content.ContextWrapper in project UnityModManager by xausky.
the class ContextFixer method fixContext.
/**
* Fuck AppOps
*
* @param context Context
*/
public static void fixContext(Context context) {
try {
context.getPackageName();
} catch (Throwable e) {
return;
}
InvocationStubManager.getInstance().checkEnv(GraphicsStatsStub.class);
int deep = 0;
while (context instanceof ContextWrapper) {
context = ((ContextWrapper) context).getBaseContext();
deep++;
if (deep >= 10) {
return;
}
}
ContextImpl.mPackageManager.set(context, null);
try {
context.getPackageManager();
} catch (Throwable e) {
e.printStackTrace();
}
if (!VirtualCore.get().isVAppProcess()) {
return;
}
DropBoxManager dm = (DropBoxManager) context.getSystemService(Context.DROPBOX_SERVICE);
BinderInvocationStub boxBinder = InvocationStubManager.getInstance().getInvocationStub(DropBoxManagerStub.class);
if (boxBinder != null) {
try {
Reflect.on(dm).set("mService", boxBinder.getProxyInterface());
} catch (ReflectException e) {
e.printStackTrace();
}
}
String hostPkg = VirtualCore.get().getHostPkg();
ContextImpl.mBasePackageName.set(context, hostPkg);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
ContextImplKitkat.mOpPackageName.set(context, hostPkg);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
ContentResolverJBMR2.mPackageName.set(context.getContentResolver(), hostPkg);
}
}
Aggregations