Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Restore original code for pre Lollipop
Browse files Browse the repository at this point in the history
Refs #2209
  • Loading branch information
M66B committed May 27, 2015
1 parent 78e2e80 commit 5761d2f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
49 changes: 35 additions & 14 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,22 @@ public static void register(List<String> 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
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions src/biz/bokhorst/xprivacy/XPrivacy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
});
}
Expand Down

0 comments on commit 5761d2f

Please sign in to comment.