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