diff --git a/src/biz/bokhorst/xprivacy/PrivacyService.java b/src/biz/bokhorst/xprivacy/PrivacyService.java index 6e071623d..d721b5173 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyService.java +++ b/src/biz/bokhorst/xprivacy/PrivacyService.java @@ -167,20 +167,22 @@ public static void register(List listError, ClassLoader classLoader, Str XActivityManagerService.setSemaphore(mOndemandSemaphore); // Get context - Field fContext = null; - Class cam = am.getClass(); - while (cam != null && fContext == null) - try { - fContext = cam.getDeclaredField("mContext"); - } catch (NoSuchFieldException ignored) { - cam = cam.getSuperclass(); - } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Field fContext = null; + Class cam = am.getClass(); + while (cam != null && fContext == null) + try { + fContext = cam.getDeclaredField("mContext"); + } catch (NoSuchFieldException ignored) { + cam = cam.getSuperclass(); + } - if (fContext == null) - Util.log(null, Log.ERROR, am.getClass().getName() + ".mContext not found"); - else { - fContext.setAccessible(true); - mContext = (Context) fContext.get(am); + if (fContext == null) + Util.log(null, Log.ERROR, am.getClass().getName() + ".mContext not found"); + else { + fContext.setAccessible(true); + mContext = (Context) fContext.get(am); + } } // Start a worker thread @@ -2302,7 +2304,26 @@ private boolean isAMLocked(int uid) { } private Context getContext() { - return mContext; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) + return mContext; + else { + // public static ActivityManagerService self() + // frameworks/base/services/java/com/android/server/am/ActivityManagerService.java + try { + Class cam = Class.forName("com.android.server.am.ActivityManagerService"); + Object am = cam.getMethod("self").invoke(null); + if (am == null) { + Util.log(null, Log.ERROR, cam.getName() + ".mContext not found"); + return null; + } + Field mContext = cam.getDeclaredField("mContext"); + mContext.setAccessible(true); + return (Context) mContext.get(am); + } catch (Throwable ex) { + Util.bug(null, ex); + return null; + } + } } private int getIsolatedUid(int uid) { diff --git a/src/biz/bokhorst/xprivacy/XPrivacy.java b/src/biz/bokhorst/xprivacy/XPrivacy.java index 0ba5fdab9..09f51425e 100644 --- a/src/biz/bokhorst/xprivacy/XPrivacy.java +++ b/src/biz/bokhorst/xprivacy/XPrivacy.java @@ -114,8 +114,8 @@ public void initZygote(StartupParam startupParam) throws Throwable { XposedBridge.hookAllMethods(at, "systemMain", new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { - final ClassLoader loader = Thread.currentThread().getContextClassLoader(); try { + final ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class am = Class.forName("com.android.server.am.ActivityManagerService", false, loader); XposedBridge.hookAllConstructors(am, new XC_MethodHook() { @Override @@ -136,7 +136,11 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { XposedBridge.hookMethod(mMain, new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { - PrivacyService.register(mListHookError, null, mSecret, param.thisObject); + try { + PrivacyService.register(mListHookError, null, mSecret, null); + } catch (Throwable ex) { + Util.bug(null, ex); + } } }); }