From 49763378787bdf2d5ff135bc9ed1181c7b0fd905 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 17 Apr 2025 16:52:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A9=E7=94=A8=E5=85=B1=E4=BA=ABuid?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F=E6=9D=A5=E5=88=A4=E6=96=ADmpapp?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=AD=A3=E5=9C=A8=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 加入时间变化监控的一些定义 --- .../com/xypower/mpmaster/MpMasterService.java | 48 ++----------------- 1 file changed, 3 insertions(+), 45 deletions(-) diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java index 8985eb0f..c42178d4 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java @@ -425,7 +425,7 @@ public class MpMasterService extends Service { } boolean isMpAppRunning = false; for (int idx = 0; idx < detectionCnt; idx++) { - isMpAppRunning = detectMpAppRunning(); + isMpAppRunning = MicroPhotoContext.isAppAlive(context, MicroPhotoContext.PACKAGE_NAME_MPAPP); if (isMpAppRunning) { break; } @@ -434,8 +434,8 @@ public class MpMasterService extends Service { if (!isMpAppRunning) { // Restart MpApp - MpMasterService.restartMpApp(context, "MpMST Keep Alive Detection: NO Lock"); - logger.warning("Restart MpAPP as There is NO Lock"); + MpMasterService.restartMpApp(context, "MpMST Alive Detection: NO Service Running"); + logger.warning("Restart MpAPP as NO Service Running"); mTimeToStartMpApp = ts; return; } @@ -492,48 +492,6 @@ public class MpMasterService extends Service { } } - private boolean detectMpAppRunning() { - boolean isMpAppRunning = true; - FileOutputStream runningFile = null; - FileLock fileLock = null; - try { - String mpappDir = MicroPhotoContext.buildMpAppDir(getApplicationContext()); - File file = new File(mpappDir); - file = new File(file, "data/alive/running"); - if (file.exists()) { - runningFile = new FileOutputStream(file); - fileLock = runningFile.getChannel().tryLock(); - if (fileLock != null && fileLock.isValid()) { - isMpAppRunning = false; - } - try { - if (fileLock != null) { - fileLock.close(); - fileLock = null; - } - } catch (Exception ex) { - ex.printStackTrace(); - } - FilesUtils.closeFriendly(runningFile); - } else { - isMpAppRunning = false; - } - } catch (Exception ex) { - ex.printStackTrace(); - } finally { - try { - if (fileLock != null) { - fileLock.close(); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - FilesUtils.closeFriendly(runningFile); - } - - return isMpAppRunning; - } - long getFileModificationTime(String path) { File file = new File(path); long mt = 0;