Mpapp对运维app保活机制的调整

避免运维app启动多个activity
nx2024
Matthew 2 months ago
parent b578f95501
commit 87dbbb00d7

@ -400,10 +400,38 @@ public class MicroPhotoService extends Service {
public AlarmReceiver() { public AlarmReceiver() {
mService = null; mService = null;
} }
public AlarmReceiver(MicroPhotoService service) { public AlarmReceiver(MicroPhotoService service) {
mService = service; mService = service;
} }
private void keepMpMasterAlive(final Context context, long ts) {
try {
File mpmstLogFile = new File(MicroPhotoContext.buildMasterAppDir(context) + "logs/mlog.txt");
long mlogTime = mpmstLogFile.exists() ? mpmstLogFile.lastModified() : 0;
if ((ts - mlogTime) > 1800000 /*86400000*/) {
// More than 1 day, try restart it
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(MicroPhotoContext.PACKAGE_NAME_MPMASTER);
if (launchIntent != null) {
launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(launchIntent);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
try {
processNotification(context, intent);
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void processNotification(final Context context, final Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
if (TextUtils.equals(ACTION_HEARTBEAT, action)) { if (TextUtils.equals(ACTION_HEARTBEAT, action)) {
Log.i(TAG, "HB Timer Fired ACTION=" + action); Log.i(TAG, "HB Timer Fired ACTION=" + action);
@ -426,31 +454,12 @@ public class MicroPhotoService extends Service {
mService.registerHeartbeatTimer(timeout); mService.registerHeartbeatTimer(timeout);
try { try {
mService.detectGpsStatus(); mService.detectGpsStatus();
ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null) {
if (!connectivityManager.isDefaultNetworkActive()) {
infoLog("DefaultNetwork is NOT Active");
}
}
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
try { keepMpMasterAlive(context, ts);
Date dt = new Date();
if ((dt.getHours() == 1 || dt.getHours() == 2) && dt.getMinutes() > 35 && dt.getMinutes() < 55) {
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(MicroPhotoContext.PACKAGE_NAME_MPMASTER);
// launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (launchIntent != null) {
context.startActivity(launchIntent);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
} else if (TextUtils.equals(ACTION_TAKE_PHOTO, action)) { } else if (TextUtils.equals(ACTION_TAKE_PHOTO, action)) {
long ts = intent.getLongExtra(EXTRA_PARAM_TIME, 0); long ts = intent.getLongExtra(EXTRA_PARAM_TIME, 0);
int cnt = intent.getIntExtra(EXTRA_PARAM_SCHEDULES, 0); int cnt = intent.getIntExtra(EXTRA_PARAM_SCHEDULES, 0);

Loading…
Cancel
Save