|
|
@ -74,7 +74,7 @@ public class MpMasterService extends Service {
|
|
|
|
private static final String ACTION_HEARTBEAT = "com.xypower.mpmaster.ACT_HB";
|
|
|
|
private static final String ACTION_HEARTBEAT = "com.xypower.mpmaster.ACT_HB";
|
|
|
|
private static final String ACTION_TAKE_PHOTO = "com.xypower.mpapp.ACT_TP";
|
|
|
|
private static final String ACTION_TAKE_PHOTO = "com.xypower.mpapp.ACT_TP";
|
|
|
|
|
|
|
|
|
|
|
|
public static final String ACTION_MP_RESTART = "com.xypower.mpapp.ACT_START";
|
|
|
|
public static final String ACTION_MP_RESTART = "com.xypower.mpapp.ACT_RESTART";
|
|
|
|
public static final String ACTION_IMP_PUBKRY = "com.xypower.mpapp.ACT_IMP_PUBKEY";
|
|
|
|
public static final String ACTION_IMP_PUBKRY = "com.xypower.mpapp.ACT_IMP_PUBKEY";
|
|
|
|
|
|
|
|
|
|
|
|
private static final String FOREGROUND_CHANNEL_ID = "fg_mpmst";
|
|
|
|
private static final String FOREGROUND_CHANNEL_ID = "fg_mpmst";
|
|
|
@ -196,6 +196,8 @@ public class MpMasterService extends Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mMpAppVersion = packageInfo == null ? "" : packageInfo.versionName;
|
|
|
|
mMpAppVersion = packageInfo == null ? "" : packageInfo.versionName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mPreviousMpHbTime = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("MpMaster started version=" + mMpMasterVersion);
|
|
|
|
logger.info("MpMaster started version=" + mMpMasterVersion);
|
|
|
|
|
|
|
|
|
|
|
|
mHander = new Handler();
|
|
|
|
mHander = new Handler();
|
|
|
@ -358,21 +360,22 @@ public class MpMasterService extends Service {
|
|
|
|
public void startMpApp() {
|
|
|
|
public void startMpApp() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
|
|
|
|
long ts = System.currentTimeMillis();
|
|
|
|
if (!MicroPhotoContext.isAppAlive(context, MicroPhotoContext.PACKAGE_NAME_MPAPP)) {
|
|
|
|
|
|
|
|
MicroPhotoContext.restartMpApp(context);
|
|
|
|
if (ts - mPreviousMpHbTime > mMpHeartbeatDuration * 2) {
|
|
|
|
mTimeToStartMpApp = System.currentTimeMillis();
|
|
|
|
// MpApp is not running
|
|
|
|
logger.warning("Restart MpAPP as it is NOT Running");
|
|
|
|
if (ts - mTimeToStartMpApp >= 30000) {
|
|
|
|
|
|
|
|
MicroPhotoContext.restartMpApp(context);
|
|
|
|
|
|
|
|
mTimeToStartMpApp = ts;
|
|
|
|
|
|
|
|
logger.warning("Restart MpAPP as it is NOT Running Prev MPAPP HB=" + Long.toString((ts - mPreviousMpHbTime) / 1000));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
logger.warning("MpAPP has restarted during 30s, skip the check.");
|
|
|
|
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MpApp is alive
|
|
|
|
final String appPath = MicroPhotoContext.buildMpAppDir(context);
|
|
|
|
final String appPath = MicroPhotoContext.buildMpAppDir(context);
|
|
|
|
final long ts = System.currentTimeMillis();
|
|
|
|
|
|
|
|
if (ts - mTimeToStartMpApp < 30000) {
|
|
|
|
|
|
|
|
logger.warning("MpAPP has restarted in 30s, skip the check.");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final File mpappHb = new File(appPath + "data/alive/hb");
|
|
|
|
final File mpappHb = new File(appPath + "data/alive/hb");
|
|
|
|
final long modifiedTimeOfHb = getFileModificationTime(appPath + "data/alive/hb");
|
|
|
|
final long modifiedTimeOfHb = getFileModificationTime(appPath + "data/alive/hb");
|
|
|
|
final long modifiedTimeOfPhoto = getFileModificationTime(appPath + "data/alive/taking");
|
|
|
|
final long modifiedTimeOfPhoto = getFileModificationTime(appPath + "data/alive/taking");
|
|
|
@ -381,17 +384,20 @@ public class MpMasterService extends Service {
|
|
|
|
if (((ts - modifiedTimeOfHb) > mTimeOfMpAppAlive) ||
|
|
|
|
if (((ts - modifiedTimeOfHb) > mTimeOfMpAppAlive) ||
|
|
|
|
((ts - modifiedTimeOfPhoto) > mTimeOfMpAppAlive * 4) ||
|
|
|
|
((ts - modifiedTimeOfPhoto) > mTimeOfMpAppAlive * 4) ||
|
|
|
|
((ts - modifiedTimeOfUpload) > mTimeOfMpAppAlive * 4)) {
|
|
|
|
((ts - modifiedTimeOfUpload) > mTimeOfMpAppAlive * 4)) {
|
|
|
|
mHander.postDelayed(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
// greater than 30m
|
|
|
|
|
|
|
|
logger.warning("Restart MpAPP as it is NOT Running hb=" + Long.toString(ts - modifiedTimeOfHb) +
|
|
|
|
|
|
|
|
" taking=" + Long.toString(ts - modifiedTimeOfPhoto) + " sending=" + Long.toString(ts - modifiedTimeOfUpload));
|
|
|
|
|
|
|
|
MicroPhotoContext.restartMpApp(context);
|
|
|
|
|
|
|
|
mTimeToStartMpApp = System.currentTimeMillis();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, mDelayedRestartMpTime);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String msg = "Restart MpAPP as it is NOT Running hb=" + Long.toString(ts - modifiedTimeOfHb) +
|
|
|
|
|
|
|
|
" taking=" + Long.toString(ts - modifiedTimeOfPhoto) + " sending=" + Long.toString(ts - modifiedTimeOfUpload) +
|
|
|
|
|
|
|
|
" Will restart MpApp in " + Long.toString(mDelayedRestartMpTime / 1000) + " seconds";
|
|
|
|
|
|
|
|
logger.warning(msg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
|
|
|
|
Intent alarmIntent = new Intent();
|
|
|
|
|
|
|
|
alarmIntent.setAction(ACTION_MP_RESTART);
|
|
|
|
|
|
|
|
alarmIntent.putExtra("reason", msg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, ts + mDelayedRestartMpTime, pendingIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
ex.printStackTrace();
|
|
|
@ -519,11 +525,11 @@ public class MpMasterService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
} else if (TextUtils.equals(MicroPhotoContext.ACTION_HEARTBEAT_MP, action)) {
|
|
|
|
} else if (TextUtils.equals(MicroPhotoContext.ACTION_HEARTBEAT_MP, action)) {
|
|
|
|
|
|
|
|
|
|
|
|
mService.mPreviousMpHbTime = System.currentTimeMillis();
|
|
|
|
|
|
|
|
if (intent.hasExtra("HeartbeatDuration")) {
|
|
|
|
if (intent.hasExtra("HeartbeatDuration")) {
|
|
|
|
mService.mMpHeartbeatDuration = intent.getIntExtra("HeartbeatDuration", 600000);
|
|
|
|
mService.mMpHeartbeatDuration = intent.getIntExtra("HeartbeatDuration", 600000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mService.mPreviousMpHbTime = intent.getLongExtra("HeartbeatTime", System.currentTimeMillis());
|
|
|
|
mService.logger.info("Heartbeat Timer Fired By MpAPP ACTION=" + action + " MpHB=" + Long.toString(mService.mMpHeartbeatDuration));
|
|
|
|
mService.logger.info("Heartbeat Timer Fired By MpAPP ACTION=" + action + " MpHB=" + Long.toString(mService.mMpHeartbeatDuration));
|
|
|
|
|
|
|
|
|
|
|
|
mService.registerHeartbeatTimer();
|
|
|
|
mService.registerHeartbeatTimer();
|
|
|
@ -532,8 +538,6 @@ public class MpMasterService extends Service {
|
|
|
|
mService.startMaster(true);
|
|
|
|
mService.startMaster(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mService.startMpApp();
|
|
|
|
mService.startMpApp();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (TextUtils.equals(ACTION_UPDATE_CONFIGS, action)) {
|
|
|
|
} else if (TextUtils.equals(ACTION_UPDATE_CONFIGS, action)) {
|
|
|
|
int restart = intent.getIntExtra("restart", 0);
|
|
|
|
int restart = intent.getIntExtra("restart", 0);
|
|
|
|
mService.logger.info("Update Config Fired ACTION=" + action + " restart=" + restart);
|
|
|
|
mService.logger.info("Update Config Fired ACTION=" + action + " restart=" + restart);
|
|
|
@ -1052,6 +1056,7 @@ public class MpMasterService extends Service {
|
|
|
|
public native static int[] getStats(long ts);
|
|
|
|
public native static int[] getStats(long ts);
|
|
|
|
public native static String getSystemProperty(String key);
|
|
|
|
public native static String getSystemProperty(String key);
|
|
|
|
public native static void rebootDevice();
|
|
|
|
public native static void rebootDevice();
|
|
|
|
|
|
|
|
public native static boolean isMpAppRunning();
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////GPS////////////////////
|
|
|
|
////////////////////////GPS////////////////////
|
|
|
|
|
|
|
|
|
|
|
|