修复网络问题

lowmem
Matthew 1 month ago
parent 8abeaf9e04
commit 0c57bca352

@ -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");

Loading…
Cancel
Save