-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
828143b
commit c26298e
Showing
6 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
app/src/main/java/nep/timeline/cirno/hooks/android/anr/ANRErrorStateHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package nep.timeline.cirno.hooks.android.anr; | ||
|
||
import android.content.pm.ApplicationInfo; | ||
import android.os.Build; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Future; | ||
|
||
import de.robv.android.xposed.XC_MethodHook; | ||
import de.robv.android.xposed.XposedHelpers; | ||
import nep.timeline.cirno.framework.AbstractMethodHook; | ||
import nep.timeline.cirno.framework.MethodHook; | ||
import nep.timeline.cirno.utils.AnrHelper; | ||
|
||
public class ANRErrorStateHook extends MethodHook { | ||
public ANRErrorStateHook(ClassLoader classLoader) { | ||
super(classLoader); | ||
} | ||
|
||
@Override | ||
public String getTargetClass() { | ||
return "com.android.server.am.ProcessErrorStateRecord"; | ||
} | ||
|
||
@Override | ||
public String getTargetMethod() { | ||
return "appNotResponding"; | ||
} | ||
|
||
@Override | ||
public Object[] getTargetParam() { | ||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) | ||
return new Object[] { String.class, ApplicationInfo.class, String.class, "com.android.server.wm.WindowProcessController", boolean.class, "com.android.internal.os.TimeoutRecord", ExecutorService.class, boolean.class, boolean.class, Future.class }; | ||
return new Object[] { String.class, ApplicationInfo.class, String.class, "com.android.server.wm.WindowProcessController", boolean.class, String.class, boolean.class }; | ||
} | ||
|
||
@Override | ||
public XC_MethodHook getTargetHook() { | ||
return new AbstractMethodHook() { | ||
@Override | ||
protected void beforeMethod(MethodHookParam param) { | ||
Object app = XposedHelpers.getObjectField(param.thisObject, "mApp"); | ||
if (app == null) | ||
return; | ||
AnrHelper.processingAnr(param, app); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public int getMinVersion() { | ||
return Build.VERSION_CODES.S; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
app/src/main/java/nep/timeline/cirno/hooks/android/anr/ANRHelperHooks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package nep.timeline.cirno.hooks.android.anr; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import de.robv.android.xposed.XposedBridge; | ||
import de.robv.android.xposed.XposedHelpers; | ||
import nep.timeline.cirno.framework.AbstractMethodHook; | ||
import nep.timeline.cirno.utils.AnrHelper; | ||
|
||
public class ANRHelperHooks { | ||
public final Integer findIndex(Class<?>[] parameterTypes, String clazz) { | ||
for (int i = 0; i < parameterTypes.length; i++) | ||
if (clazz.equals(parameterTypes[i].getName())) | ||
return i; | ||
return null; | ||
} | ||
|
||
public ANRHelperHooks(ClassLoader classLoader) { | ||
try { | ||
Class<?> targetClass = XposedHelpers.findClassIfExists("com.android.server.am.AnrHelper", classLoader); | ||
|
||
if (targetClass == null) | ||
return; | ||
|
||
for (Method method : targetClass.getDeclaredMethods()) { | ||
if ((method.getName().equals("appNotResponding") || method.getName().equals("deferAppNotResponding")) && method.getReturnType().equals(void.class)) { | ||
Integer index = findIndex(method.getParameterTypes(), "com.android.server.am.ProcessRecord"); | ||
if (index == null) { // Not found | ||
Integer MIUIRecordIndex = findIndex(method.getParameterTypes(), "com.android.server.am.AnrHelper$AnrRecord"); | ||
if (MIUIRecordIndex != null) { | ||
XposedBridge.hookMethod(method, new AbstractMethodHook() { | ||
@Override | ||
protected void beforeMethod(MethodHookParam param) { | ||
Object anrRecord = param.args[MIUIRecordIndex]; | ||
if (anrRecord == null) | ||
return; | ||
Object app = XposedHelpers.getObjectField(anrRecord, "mApp"); | ||
if (app == null) | ||
return; | ||
AnrHelper.processingAnr(param, app); | ||
} | ||
}); | ||
} | ||
} else { | ||
XposedBridge.hookMethod(method, new AbstractMethodHook() { | ||
@Override | ||
protected void beforeMethod(MethodHookParam param) { | ||
Object record = param.args[index]; | ||
if (record == null) | ||
return; | ||
AnrHelper.processingAnr(param, record); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} catch (Throwable ignored) { | ||
|
||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/nep/timeline/cirno/hooks/android/anr/ANRHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package nep.timeline.cirno.hooks.android.anr; | ||
|
||
import de.robv.android.xposed.XC_MethodHook; | ||
import de.robv.android.xposed.XposedHelpers; | ||
import nep.timeline.cirno.framework.AbstractMethodHook; | ||
import nep.timeline.cirno.framework.MethodHook; | ||
import nep.timeline.cirno.utils.AnrHelper; | ||
|
||
public class ANRHook extends MethodHook { | ||
public ANRHook(ClassLoader classLoader) { | ||
super(classLoader); | ||
} | ||
|
||
@Override | ||
public String getTargetClass() { | ||
return "com.android.server.am.AnrHelper$AnrRecord"; | ||
} | ||
|
||
@Override | ||
public String getTargetMethod() { | ||
return "appNotResponding"; | ||
} | ||
|
||
@Override | ||
public Object[] getTargetParam() { | ||
return new Object[] { boolean.class }; | ||
} | ||
|
||
@Override | ||
public XC_MethodHook getTargetHook() { | ||
return new AbstractMethodHook() { | ||
@Override | ||
protected void beforeMethod(MethodHookParam param) { | ||
Object app = XposedHelpers.getObjectField(param.thisObject, "mApp"); | ||
if (app == null) | ||
return; | ||
AnrHelper.processingAnr(param, app); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package nep.timeline.cirno.utils; | ||
|
||
import de.robv.android.xposed.XC_MethodHook; | ||
import nep.timeline.cirno.entity.AppRecord; | ||
import nep.timeline.cirno.services.ProcessService; | ||
import nep.timeline.cirno.virtuals.ProcessRecord; | ||
|
||
public class AnrHelper { | ||
public static void processingAnr(XC_MethodHook.MethodHookParam param, Object app) { | ||
if (app == null) | ||
return; | ||
ProcessRecord processRecord = ProcessService.getProcessRecord(app); | ||
if (processRecord == null) | ||
return; | ||
AppRecord appRecord = processRecord.getAppRecord(); | ||
if (appRecord == null) | ||
return; | ||
if (!appRecord.isSystem()) | ||
param.setResult(null); | ||
} | ||
} |