diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index d193a07d..d6fbdaed 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -1602,7 +1602,7 @@ bool CPhoneDevice::TakePhotoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c if(!GpioControl::GetSelftestStatus(waitTime)) { m_isSelfTesting.store(true); - waitTime = (waitTime != 0) ? (waitTime * 1024) : 10240; + waitTime = (waitTime != 0) ? (waitTime * 1000) : 10000; std::this_thread::sleep_for(std::chrono::milliseconds(waitTime)); m_isSelfTesting.store(false); } @@ -1809,7 +1809,7 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c if(!GpioControl::GetSelftestStatus(waitTime)) { m_isSelfTesting.store(true); - waitTime = (waitTime != 0) ? (waitTime * 1024) : 10240; + waitTime = (waitTime != 0) ? (waitTime * 1000) : 10000; std::this_thread::sleep_for(std::chrono::milliseconds(waitTime)); m_isSelfTesting.store(false); } @@ -1931,7 +1931,7 @@ bool CPhoneDevice::StartPushStreaming(IDevice::PHOTO_INFO& photoInfo, const std: if(!GpioControl::GetSelftestStatus(waitTime)) { m_isSelfTesting.store(true); - waitTime = (waitTime != 0) ? (waitTime * 1024) : 10240; + waitTime = (waitTime != 0) ? (waitTime * 1000) : 10000; std::this_thread::sleep_for(std::chrono::milliseconds(waitTime)); m_isSelfTesting.store(false); } @@ -2234,7 +2234,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< { uint32_t waitTime = localPhotoInfo.selfTestingTime; XYLOG(XYLOG_SEVERITY_INFO, "Camera is SelfTesting Time=%u s", waitTime); - waitTime = (waitTime <= 5 ) ? 0 : ((waitTime - 5) * 1024); + waitTime = (waitTime <= 5 ) ? 0 : ((waitTime - 5) * 1000); if (waitTime > 0) { std::this_thread::sleep_for(std::chrono::milliseconds(waitTime)); @@ -2340,7 +2340,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< pThis->m_isSelfTesting.store(true); time_t remaintime = GpioControl::GetSelfTestRemain(waitTime); XYLOG(XYLOG_SEVERITY_INFO, "Camera is SeltTesting,remaining selfTestingtime=%u", remaintime); - remaintime = (remaintime != 0) ? (remaintime * 1024) : 10240; + remaintime = (remaintime != 0) ? (remaintime * 1000) : 10000; std::this_thread::sleep_for(std::chrono::milliseconds(remaintime)); pThis->m_isSelfTesting.store(false); XYLOG(XYLOG_SEVERITY_INFO, "Camera SeltTesting is over"); @@ -2397,7 +2397,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< pThis->m_isSelfTesting.store(true); time_t remaintime = GpioControl::GetSelfTestRemain(waitTime); XYLOG(XYLOG_SEVERITY_INFO, "Camera is SeltTesting,remaining selfTestingtime=%u", remaintime); - remaintime = (remaintime != 0) ? (remaintime * 1024) : 10240; + remaintime = (remaintime != 0) ? (remaintime * 1000) : 10000; std::this_thread::sleep_for(std::chrono::milliseconds(remaintime)); pThis->m_isSelfTesting.store(false); XYLOG(XYLOG_SEVERITY_INFO, "Camera SeltTesting is over"); @@ -2432,7 +2432,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< pThis->m_isSelfTesting.store(true); time_t remaintime = GpioControl::GetSelfTestRemain(waitTime); XYLOG(XYLOG_SEVERITY_INFO, "Camera is SeltTesting,remaining selfTestingtime=%u", remaintime); - remaintime = (remaintime != 0) ? (remaintime * 1024) : 10240; + remaintime = (remaintime != 0) ? (remaintime * 1000) : 10000; std::this_thread::sleep_for(std::chrono::milliseconds(remaintime)); pThis->m_isSelfTesting.store(false); XYLOG(XYLOG_SEVERITY_INFO, "Camera SeltTesting is over"); diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index 4d2f29a2..2d5c0860 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -193,6 +193,14 @@ public class MicroPhotoService extends Service { public MicroPhotoService() { } + private static void sleep(long ms) { + try { + Thread.sleep(ms); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + public void convertDngToPng(String dngFile, String pngFile) { ImageDecoder.Source src = ImageDecoder.createSource(new File(dngFile)); Bitmap bmp = null; @@ -732,11 +740,7 @@ public class MicroPhotoService extends Service { } else if (TextUtils.equals(ACTION_RESTART, action)) { String reason = intent.getStringExtra("reason"); MicroPhotoService.infoLog("Recv RESTART APP cmd, reason=" + (TextUtils.isEmpty(reason) ? "" : reason)); - try { - Thread.sleep(100); - } catch (Exception ex) { - ex.printStackTrace(); - } + sleep(100); restartSelfImpl(context, reason); } else if (TextUtils.equals(Intent.ACTION_TIME_CHANGED, action)) { mService.notifyTimeUpdated(mService.mNativeHandle); @@ -1672,19 +1676,26 @@ public class MicroPhotoService extends Service { 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("/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("/system/bin/ifconfig " + iface + " down\n"); + os.writeBytes("/system/bin/ifconfig " + iface + " " + ip + " netmask " + netmask + " up\n"); + // os.writeBytes("/system/bin/ip route add default via " + gateway + " dev " + iface + "\n"); + os.writeBytes("/system/bin/ip route delete 192.168.68.0/24 table eth0 2>/dev/null || true\n"); + os.writeBytes("/system/bin/ip route add 192.168.68.0/24 dev eth0 proto static scope link table eth0\n"); + os.writeBytes("/system/bin/ip route flush cache\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("/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 eth0 prio 1000"); + os.writeBytes("/system/bin/ip route flush cache\n"); + os.writeBytes("exit\n"); // 重要:退出su shell + os.flush(); + exitValue = process.waitFor(); + if (exitValue != 0) { + } + /* String downCommand = "/system/xbin/su root ifconfig " + iface + " down"; Process downProcess = Runtime.getRuntime().exec(downCommand); exitValue = downProcess.waitFor(); @@ -1698,30 +1709,42 @@ public class MicroPhotoService extends Service { 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"; + // String routeCommand = "/system/xbin/su root /system/bin/ip route delete 192.168.68.0/24 table 20"; + String routeCommand = "/system/xbin/su root /system/bin/ip route delete 192.168.68.0/24 table eth0"; 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"; + // routeCommand = "/system/xbin/su root /system/bin/ip route add 192.168.68.0/24 dev eth0 proto static scope link table 20"; + routeCommand = "/system/xbin/su root /system/bin/ip route add 192.168.68.0/24 dev eth0 proto static scope link table eth0"; 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"; - for (int idx = 0; idx < 3; idx++) { + + */ + sleep(100); + String routeCommand = "/system/xbin/su root /system/bin/ip rule add from all to 192.168.68.0/24 lookup eth0 prio 1000"; + for (int idx = 0; idx < 10; idx++) { Process routeProcess3 = Runtime.getRuntime().exec(routeCommand); exitValue = routeProcess3.waitFor(); - if (exitValue == 0) { + if (exitValue == 0 || exitValue == 2) { + infoLog("Add route successfully"); break; + } else { + BufferedReader reader = new BufferedReader(new InputStreamReader(routeProcess3.getErrorStream())); + String line; + StringBuilder error = new StringBuilder(); + while ((line = reader.readLine()) != null) { + error.append(line).append("\n"); + } + + if (error.length() > 0) { + Log.e("RouteConfig", "Error output: " + error); + } } - try { - Thread.sleep(100); - } catch (Exception ex) { - ex.printStackTrace(); - } + sleep(500); } if (exitValue != 0) { - } // os.writeBytes("/system/bin/ip route delete 192.168.68.0/24 table 20\n");