Search in sources :

Example 71 with ContextWrapper

use of android.content.ContextWrapper in project VirtualXposed by android-hacker.

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)

Example 72 with ContextWrapper

use of android.content.ContextWrapper in project MVPFrames by RockyQu.

the class Helper method unwrap.

/**
 * Unwrap wactivity
 *
 * @param context Context
 * @return Activity
 */
public static Activity unwrap(Context context) {
    while (!(context instanceof Activity)) {
        ContextWrapper wrapper = (ContextWrapper) context;
        context = wrapper.getBaseContext();
    }
    return (Activity) context;
}
Also used : Activity(android.app.Activity) ContextWrapper(android.content.ContextWrapper)

Example 73 with ContextWrapper

use of android.content.ContextWrapper in project android_packages_apps_Settings by omnirom.

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 74 with ContextWrapper

use of android.content.ContextWrapper in project BaseProject by fly803.

the class SharedPreferencesUtils method setSharedPreferencesToPath.

public static void setSharedPreferencesToPath(Context context, String dirName, String sharePreName, String key, String value) {
    SharedPreferences mySharedPreferences = null;
    SharedPreferences.Editor editor = null;
    try {
        Field field;
        // 获取ContextWrapper对象中的mBase变量。该变量保存了ContextImpl对象
        field = ContextWrapper.class.getDeclaredField("mBase");
        field.setAccessible(true);
        // 获取mBase变量
        Object obj = field.get(context);
        // 获取ContextImpl。mPreferencesDir变量,该变量保存了数据文件的保存路径
        field = obj.getClass().getDeclaredField("mPreferencesDir");
        field.setAccessible(true);
        // 创建自定义路径
        File file;
        if (isHaveSD()) {
            file = new File(SDCARDDIR, dirName);
        } else {
            file = new File(context.getCacheDir().getAbsolutePath() + File.separator, dirName);
        }
        // System.out.println("@@@context.getCacheDir().getAbsolutePath()+java.io.File.separator:"+context.getCacheDir().getAbsolutePath()+java.io.File.separator);
        // 修改mPreferencesDir变量的值
        field.set(obj, file);
        mySharedPreferences = context.getSharedPreferences(sharePreName, Context.MODE_PRIVATE);
        editor = mySharedPreferences.edit();
        // if (isExistFile) {
        // Toast.makeText(this, "文件还不存在", 5000).show();
        editor.putString(key, value);
        editor.commit();
    // }
    // new Handler().postDelayed(delayRunable,5000);
    // firstUseTime = mySharedPreferences.getString("time", null);
    // // 使用Toast提示信息
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) SharedPreferences(android.content.SharedPreferences) ContextWrapper(android.content.ContextWrapper) File(java.io.File)

Example 75 with ContextWrapper

use of android.content.ContextWrapper in project Applozic-Android-SDK by AppLozic.

the class FileClientService method getFilePath.

public static File getFilePath(String fileName, Context context, String contentType, boolean isThumbnail) {
    File filePath;
    File dir;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
        String folder = "/" + Utils.getMetaDataValue(context, MAIN_FOLDER_META_DATA) + MOBI_COM_OTHER_FILES_FOLDER;
        if (contentType.startsWith("image")) {
            folder = "/" + Utils.getMetaDataValue(context, MAIN_FOLDER_META_DATA) + MOBI_COM_IMAGES_FOLDER;
        } else if (contentType.startsWith("video")) {
            folder = "/" + Utils.getMetaDataValue(context, MAIN_FOLDER_META_DATA) + MOBI_COM_VIDEOS_FOLDER;
        } else if (contentType.equalsIgnoreCase("text/x-vCard")) {
            folder = "/" + Utils.getMetaDataValue(context, MAIN_FOLDER_META_DATA) + MOBI_COM_CONTACT_FOLDER;
        }
        if (isThumbnail) {
            folder = folder + MOBI_COM_THUMBNAIL_SUFIX;
        }
        dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + folder);
        if (!dir.exists()) {
            dir.mkdirs();
        }
    } else {
        ContextWrapper cw = new ContextWrapper(context);
        // path to /data/data/yourapp/app_data/imageDir
        dir = cw.getDir(IMAGE_DIR, Context.MODE_PRIVATE);
    }
    // Create image name
    // String extention = "." + contentType.substring(contentType.indexOf("/") + 1);
    filePath = new File(dir, fileName);
    return filePath;
}
Also used : File(java.io.File) ContextWrapper(android.content.ContextWrapper)

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