Skip to content

Commit

Permalink
support configure suspend process by prop or file
Browse files Browse the repository at this point in the history
  • Loading branch information
5ec1cff committed Jan 18, 2025
1 parent 9fbb80b commit 92e8ca6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 11 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ content call --uri content://io.github.a13e300.tools.stethox.suspend --method cl
content call --uri content://io.github.a13e300.tools.stethox.suspend --method list
```

You can also configure it by prop or file:

```
# Separate with newline
setprop debug.stethox.suspend <processname>[,<processname>...]
# clear
setprop debug.stethox.suspend ''
# Separate with newline
echo '<processname>' > /data/local/tmp/stethox_suspend
# clear
rm /data/local/tmp/stethox_suspend
```

## ATTENTION

Never leave this Module enabled or installed on day to day use.
Expand Down Expand Up @@ -95,6 +109,20 @@ content call --uri content://io.github.a13e300.tools.stethox.suspend --method cl
content call --uri content://io.github.a13e300.tools.stethox.suspend --method list
```

你也可以使用 prop 或者文件配置:

```
# Separate with newline
setprop debug.stethox.suspend <processname>[,<processname>...]
# clear
setprop debug.stethox.suspend ''
# Separate with newline
echo '<processname>' > /data/local/tmp/stethox_suspend
# clear
rm /data/local/tmp/stethox_suspend
```

## 注意

日常使用请勿启用该模块,这样有安全风险,请只在开发时启用。
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.os.Handler;
import android.os.Looper;
import android.os.ServiceManager;
import android.os.SystemProperties;

import com.facebook.stetho.Stetho;
import com.facebook.stetho.rhino.JsRuntimeReplFactoryBuilder;
Expand All @@ -20,8 +21,12 @@
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XC_MethodHook;
Expand Down Expand Up @@ -59,20 +64,59 @@ private synchronized void initializeStetho(Context context) throws InterruptedEx
initialized = true;
return;
}
Logger.d("Install Stetho: " + packageName);
var processName = Utils.getProcessName();
Logger.d("Install Stetho: " + packageName + " proc=" + processName);
var suspendRequested = false;

try {
var r = context.getContentResolver().call(
Uri.parse("content://io.github.a13e300.tools.stethox.suspend"),
"process_started", Utils.getProcessName(), null
);
if (r != null && r.getBoolean("suspend", false)) {
Logger.d("suspend requested");
mWaiting = true;
Stetho.setSuspend(true);
var packages = SystemProperties.get("debug.stethox.suspend");
if (Arrays.asList(packages.split(",")).contains(processName)) {
suspendRequested = true;
Logger.d("suspend requested b prop");
}
} catch (IllegalArgumentException e) {
Logger.e("failed to find suspend provider, please ensure module process without restriction", e);
} catch (Throwable t) {
Logger.e("get suspend prop", t);
}

if (!suspendRequested) {

try {
var file = new File("/data/local/tmp/stethox_suspend");
if (!file.canRead()) return;
var bytes = new byte[(int) file.length()];
try (var is = new FileInputStream(file)) {
is.read(bytes);
}
var str = new String(bytes, StandardCharsets.UTF_8);
if (Arrays.asList(str.split("\n")).contains(processName)) {
suspendRequested = true;
Logger.d("suspend requested by file");
}
} catch (Throwable t) {
Logger.e("get suspend file", t);
}
}

if (!suspendRequested) {
try {
var r = context.getContentResolver().call(
Uri.parse("content://io.github.a13e300.tools.stethox.suspend"),
"process_started", processName, null
);
if (r != null && r.getBoolean("suspend", false)) {
suspendRequested = true;
Logger.d("suspend requested by provider");
}
} catch (IllegalArgumentException e) {
Logger.e("failed to find suspend provider, please ensure module process without restriction", e);
}
}

if (suspendRequested) {
mWaiting = true;
Stetho.setSuspend(true);
}

try {
mClassLoader = context.getClassLoader();
} catch (Throwable t) {
Expand Down
5 changes: 5 additions & 0 deletions hidden-api/src/main/java/android/os/SystemProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package android.os;

public class SystemProperties {
public native static String get(String key);
}

0 comments on commit 92e8ca6

Please sign in to comment.