diff --git a/CHANGELOG.md b/CHANGELOG.md index 32ff1cd11..97ebc58a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ Changelog **Next release** -* Fixed on demand restricting on some Android Lollipop ROMs (OPPO) +* Fixed on demand restricting for some custom ROMs (OPPO) [Open issues](https://github.com/M66B/XPrivacy/issues?state=open) diff --git a/src/biz/bokhorst/xprivacy/PrivacyService.java b/src/biz/bokhorst/xprivacy/PrivacyService.java index e6cb9ccba..e624ccb23 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyService.java +++ b/src/biz/bokhorst/xprivacy/PrivacyService.java @@ -167,9 +167,18 @@ public static void register(List listError, ClassLoader classLoader, Str XActivityManagerService.setSemaphore(mOndemandSemaphore); // Get context - Field fContext = am.getClass().getField("mContext"); - fContext.setAccessible(true); - mContext = (Context) fContext.get(am); + Field fContext = null; + Class cam = am.getClass(); + while (cam != null && fContext == null) + try { + fContext = cam.getDeclaredField("mContext"); + fContext.setAccessible(true); + mContext = (Context) fContext.get(am); + } catch (NoSuchFieldException ignored) { + cam = cam.getSuperclass(); + } + if (mContext == null) + Util.log(null, Log.ERROR, "No am context found"); // Start a worker thread mWorker = new Thread(new Runnable() { diff --git a/src/biz/bokhorst/xprivacy/XPrivacy.java b/src/biz/bokhorst/xprivacy/XPrivacy.java index 24bb5265b..f17ebf42b 100644 --- a/src/biz/bokhorst/xprivacy/XPrivacy.java +++ b/src/biz/bokhorst/xprivacy/XPrivacy.java @@ -110,8 +110,8 @@ public void initZygote(StartupParam startupParam) throws Throwable { protected void afterHookedMethod(MethodHookParam param) throws Throwable { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); try { - Class ams = Class.forName("com.android.server.am.ActivityManagerService", false, loader); - XposedBridge.hookAllConstructors(ams, new XC_MethodHook() { + Class am = Class.forName("com.android.server.am.ActivityManagerService", false, loader); + XposedBridge.hookAllConstructors(am, new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { PrivacyService.register(mListHookError, loader, mSecret, param.thisObject);