修复命令错误以及优化判断规则

lowmem
Matthew 1 month ago
parent eb5af62ad3
commit b916e63a00

@ -1781,12 +1781,12 @@ public class MicroPhotoService extends Service {
Process process = Runtime.getRuntime().exec("/system/xbin/su root"); Process process = Runtime.getRuntime().exec("/system/xbin/su root");
DataOutputStream os = new DataOutputStream(process.getOutputStream()); DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("/system/bin/ip route delete 192.168.68.0/24 table 20 2>/dev/null || true\n"); // os.writeBytes("/system/bin/ip route delete 192.168.68.0/24 table 20 2>/dev/null || true\n");
os.writeBytes("/system/bin/ip route add 192.168.68.0/24 dev eth0 proto static scope link table 20\n"); os.writeBytes("/system/bin/ip route replace 192.168.68.0/24 dev eth0 proto static scope link table 20\n");
os.writeBytes("/system/bin/ip route flush cache\n"); os.writeBytes("/system/bin/ip route flush cache\n");
// os.writeBytes("echo 'nameserver 8.8.8.8' > /etc/resolv.conf\n"); // os.writeBytes("echo 'nameserver 8.8.8.8' > /etc/resolv.conf\n");
os.writeBytes("/system/bin/ip rule del to 192.168.68.0/24 2>/dev/null || true\n"); os.writeBytes("/system/bin/ip rule del to 192.168.68.0/24 2>/dev/null || true\n");
os.writeBytes("/system/bin/ip rule add from all to 192.168.68.0/24 lookup 20 prio 1000"); os.writeBytes("/system/bin/ip rule add from all to 192.168.68.0/24 lookup 20 prio 1000\n");
os.writeBytes("/system/bin/ip route flush cache\n"); os.writeBytes("/system/bin/ip route flush cache\n");
os.writeBytes("exit\n"); // 重要退出su shell os.writeBytes("exit\n"); // 重要退出su shell
os.flush(); os.flush();
@ -1795,24 +1795,35 @@ public class MicroPhotoService extends Service {
} }
sleep(100); sleep(100);
String routeCommand = "/system/xbin/su root /system/bin/ip rule add from all to 192.168.68.0/24 lookup 20 prio 1000";
for (int idx = 0; idx < 10; idx++) { for (int idx = 0; idx < 10; idx++) {
Process routeProcess3 = Runtime.getRuntime().exec(routeCommand); Process routeProcess3 = Runtime.getRuntime().exec("/system/xbin/su root");
exitValue = routeProcess3.waitFor(); DataOutputStream os3 = new DataOutputStream(routeProcess3.getOutputStream());
if (exitValue == 0 || exitValue == 2) { // os3.writeBytes("/system/bin/ip rule del to 192.168.68.0/24 2>/dev/null || true\n");
infoLog("Add route successfully"); os3.writeBytes("/system/bin/ip rule add from all to 192.168.68.0/24 lookup 20 prio 1000\n");
break; os3.writeBytes("CMD_EXIT_CODE=$?\n"); // 保存返回值
} else { os3.writeBytes("echo \"CMD_RESULT:$CMD_EXIT_CODE\"\n"); // 输出标记和返回值
os3.writeBytes("/system/bin/ip route flush cache\n");
os3.writeBytes("exit\n"); // 重要退出su shell
os3.flush();
int commandExitCode = -1;
BufferedReader reader = new BufferedReader(new InputStreamReader(routeProcess3.getErrorStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(routeProcess3.getErrorStream()));
String line; String line;
StringBuilder error = new StringBuilder(); StringBuilder error = new StringBuilder();
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
error.append(line).append("\n"); if (line.startsWith("CMD_RESULT:")) {
commandExitCode = Integer.parseInt(line.substring(11));
Log.d("RouteConfig", "Command exit code: " + commandExitCode);
break;
} }
if (error.length() > 0) {
Log.e("RouteConfig", "Error output: " + error);
} }
exitValue = routeProcess3.waitFor();
if (exitValue == 0 || commandExitCode == 2) {
infoLog("Add route successfully Code=" + exitValue);
break;
} else {
} }
sleep(500); sleep(500);
} }

Loading…
Cancel
Save