Search in sources :

Example 91 with ContextWrapper

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;
}
Also used : Bitmap(android.graphics.Bitmap) FileNotFoundException(java.io.FileNotFoundException) BitmapFactory(android.graphics.BitmapFactory) ContextWrapper(android.content.ContextWrapper) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 92 with ContextWrapper

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);
    }
}
Also used : PREF_UPDATE_SERVER(com.antest1.kcanotify.KcaConstants.PREF_UPDATE_SERVER) DisplayMetrics(android.util.DisplayMetrics) ContextWrapper(android.content.ContextWrapper) File(java.io.File)

Example 93 with ContextWrapper

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;
    }
}
Also used : Context(android.content.Context) PackageManager(android.content.pm.PackageManager) ContextWrapper(android.content.ContextWrapper)

Example 94 with ContextWrapper

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);
}
Also used : OverlayManager(com.android.settings.display.ThemePreferenceController.OverlayManager) ThemePreferenceController(com.android.settings.display.ThemePreferenceController) PackageManager(android.content.pm.PackageManager) ContextWrapper(android.content.ContextWrapper) Before(org.junit.Before)

Example 95 with ContextWrapper

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);
    }
}
Also used : DropBoxManager(android.os.DropBoxManager) BinderInvocationStub(com.lody.virtual.client.hook.base.BinderInvocationStub) ContextWrapper(android.content.ContextWrapper) ReflectException(com.lody.virtual.helper.utils.ReflectException)

Aggregations

ContextWrapper (android.content.ContextWrapper)109 Context (android.content.Context)37 Activity (android.app.Activity)25 File (java.io.File)16 Test (org.junit.Test)13 Intent (android.content.Intent)11 MockContentResolver (android.test.mock.MockContentResolver)11 PackageManager (android.content.pm.PackageManager)10 View (android.view.View)10 Resources (android.content.res.Resources)9 IOException (java.io.IOException)8 Before (org.junit.Before)8 ContentResolver (android.content.ContentResolver)6 UserManager (android.os.UserManager)6 LayoutInflater (android.view.LayoutInflater)6 ThemePreferenceController (com.android.settings.display.ThemePreferenceController)6 OverlayManager (com.android.settings.display.ThemePreferenceController.OverlayManager)6 ArrayList (java.util.ArrayList)6 AppWidgetHostView (android.appwidget.AppWidgetHostView)5 JsonParser (com.google.gson.JsonParser)5