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);
}
}
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;
}
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);
}
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();
}
}
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;
}
Aggregations