From 0c57bca35256b0318b7477a5a882d6d6fa110722 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 9 May 2025 21:26:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BD=91=E7=BB=9C=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xypower/mpapp/MicroPhotoService.java | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index 2e9299d1..7a35f4b3 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -1668,31 +1668,51 @@ public class MicroPhotoService extends Service { sendBroadcast(getApplicationContext(), intent); } + int exitValue = -1; boolean success = false; try { - Process process = Runtime.getRuntime().exec("/system/xbin/su root"); - DataOutputStream os = new DataOutputStream(process.getOutputStream()); + // Process process = Runtime.getRuntime().exec("/system/xbin/su root"); + // DataOutputStream os = new DataOutputStream(process.getOutputStream()); - os.writeBytes("ifconfig " + iface + " down\n"); - os.writeBytes("ifconfig " + iface + " " + ip + " netmask " + netmask + " up\n"); - os.writeBytes("route add default gw " + gateway + "\n"); - os.writeBytes("/system/bin/ip route delete 192.168.68.0/24 table 20\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/ifconfig " + iface + " down\n"); + // os.writeBytes("/system/bin/ifconfig " + iface + " " + ip + " netmask " + netmask + " up\n"); + // os.writeBytes("route add default gw " + gateway + "\n"); + // os.writeBytes("/system/bin/ip route delete 192.168.68.0/24 table 20\n"); + // os.writeBytes("/system/bin/ip route add 192.168.68.0/24 dev eth0 proto static scope link table 20\n"); // os.writeBytes("echo 'nameserver 8.8.8.8' > /etc/resolv.conf\n"); - os.writeBytes("exit\n"); // 重要:退出su shell - os.flush(); - int exitValue = process.waitFor(); + // os.writeBytes("exit\n"); // 重要:退出su shell + // os.flush(); + // int exitValue = process.waitFor(); - // Process downProcess = Runtime.getRuntime().exec("/system/xbin/su root ifconfig " + iface + " down"); - // downProcess.waitFor(); + String downCommand = "/system/xbin/su root ifconfig " + iface + " down"; + Process downProcess = Runtime.getRuntime().exec(downCommand); + exitValue = downProcess.waitFor(); // 2. 配置IP地址和子网掩码 - // String ipCommand = "/system/xbin/su root ifconfig " + iface + " " + ip + " netmask " + netmask + " up"; - // Process ipProcess = Runtime.getRuntime().exec(ipCommand); - // if (ipProcess.waitFor() != 0) { - // } + String ipCommand = "/system/xbin/su root ifconfig " + iface + " " + ip + " netmask " + netmask + " up"; + Process ipProcess = Runtime.getRuntime().exec(ipCommand); + exitValue = ipProcess.waitFor(); + + String gwCommand = "/system/xbin/su root /system/bin/ip route add default via " + gateway + " dev " + iface; + Process gwProcess = Runtime.getRuntime().exec(gwCommand); + exitValue = gwProcess.waitFor(); + + String routeCommand = "/system/xbin/su root /system/bin/ip route delete 192.168.68.0/24 table 20"; + Process routeProcess = Runtime.getRuntime().exec(routeCommand); + exitValue = routeProcess.waitFor(); + routeCommand = "/system/xbin/su root /system/bin/ip route add 192.168.68.0/24 dev eth0 proto static scope link table 20"; + Process routeProcess2 = Runtime.getRuntime().exec(routeCommand); + exitValue = routeProcess2.waitFor(); + + routeCommand = "/system/xbin/su root /system/bin/ip rule add from all to 192.168.68.0/24 lookup eth0 prio 1000"; + Process routeProcess3 = Runtime.getRuntime().exec(routeCommand); + exitValue = routeProcess3.waitFor(); + + if (exitValue != 0) { + + } // os.writeBytes("/system/bin/ip route delete 192.168.68.0/24 table 20\n"); // os.writeBytes("/system/bin/ip route add 192.168.68.0/24 dev eth0 proto static scope link table 20\n");