From 8a145789522fff3ea6dd29f81e5124bc8f9c9a22 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 4 Mar 2025 17:23:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=88=9A=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=8A=A0=E5=A4=A7=E6=A3=80=E6=9F=A5=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=94=81=E6=AC=A1=E6=95=B0=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?mpapp=E5=B7=B2=E7=BB=8F=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 设备重启时,mpapp可能延迟启动 --- .../com/xypower/mpmaster/MpMasterService.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java index 6087ba31..ad48acb7 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java @@ -19,6 +19,7 @@ import android.os.Environment; import android.os.Handler; import android.os.IBinder; import android.os.PowerManager; +import android.os.SystemClock; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; @@ -397,15 +398,18 @@ public class MpMasterService extends Service { long ts = System.currentTimeMillis(); try { - boolean isMpAppRunning = detectMpAppRunning(); - if (!isMpAppRunning) { - try { - Thread.sleep(1000); - } catch (Exception ex) { - ex.printStackTrace(); - } - // Check twice + int detectionCnt = 4; + if (SystemClock.elapsedRealtime() < 180000) { + // In 3 minutes after device reboot + detectionCnt = 16; + } + boolean isMpAppRunning = false; + for (int idx = 0; idx < detectionCnt; idx++) { isMpAppRunning = detectMpAppRunning(); + if (isMpAppRunning) { + break; + } + sleep(1000); } if (!isMpAppRunning) { @@ -1308,11 +1312,8 @@ public class MpMasterService extends Service { @Override public void run() { - try { - Thread.sleep(5000); - } catch (Exception ex) { + sleep(5000); - } File tmpDestPath = new File(MicroPhotoContext.buildMasterAppDir(context)); tmpDestPath = new File(tmpDestPath, "mpdata"); if (tmpDestPath.exists()) { @@ -1430,6 +1431,13 @@ public class MpMasterService extends Service { } } + private static void sleep(long ms) { + try { + Thread.sleep(ms); + } catch (Exception ex) { + } + } + public native static int getInt(int cmd); public native static int setInt(int cmd, int val); public native static int[] getStats(long ts);