利用共享uid的方式来判断mpapp是否正在运行

加入时间变化监控的一些定义
lowmem
Matthew 2 months ago
parent 897b53e44e
commit 4976337878

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

Loading…
Cancel
Save