|
|
@ -145,9 +145,15 @@ public class MpMasterService extends Service {
|
|
|
|
private String mIccid1 = null;
|
|
|
|
private String mIccid1 = null;
|
|
|
|
private String mIccid2 = null;
|
|
|
|
private String mIccid2 = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public final static int BROADCAST_REQUEST_CODE_NOTIFICATION = 11;
|
|
|
|
|
|
|
|
public final static int BROADCAST_REQUEST_CODE_NOTIFICATION_STOP = 12;
|
|
|
|
|
|
|
|
public final static int BROADCAST_REQUEST_CODE_HEARTBEAT = 15;
|
|
|
|
|
|
|
|
public final static int BROADCAST_REQUEST_CODE_REAL_HEARTBEAT = 16;
|
|
|
|
|
|
|
|
public final static int BROADCAST_REQUEST_CODE_SYS_KEEPALIVE = 17;
|
|
|
|
|
|
|
|
public final static int BROADCAST_REQUEST_CODE_RELAUNCH = 18;
|
|
|
|
|
|
|
|
|
|
|
|
//用于创建单例线程保证该线程在项目中唯一
|
|
|
|
//用于创建单例线程保证该线程在项目中唯一
|
|
|
|
private static final AtomicBoolean created = new AtomicBoolean(false);
|
|
|
|
private static final AtomicBoolean created = new AtomicBoolean(false);
|
|
|
|
AtomicInteger reqCode = new AtomicInteger(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MpMasterService() {
|
|
|
|
public MpMasterService() {
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -157,8 +163,7 @@ public class MpMasterService extends Service {
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Intent intent = new Intent(this, MainActivity.class);
|
|
|
|
Intent intent = new Intent(this, MainActivity.class);
|
|
|
|
int uniqueReqCode = reqCode.getAndIncrement();
|
|
|
|
PendingIntent pi = PendingIntent.getActivity(this, BROADCAST_REQUEST_CODE_RELAUNCH, intent, 0);
|
|
|
|
PendingIntent pi = PendingIntent.getActivity(this, uniqueReqCode, intent, 0);
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, pi);
|
|
|
|
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, pi);
|
|
|
|
logger.info("Restart MpApp after 5s as for LowMemory");
|
|
|
|
logger.info("Restart MpApp after 5s as for LowMemory");
|
|
|
@ -857,8 +862,8 @@ public class MpMasterService extends Service {
|
|
|
|
if (keepAlive) {
|
|
|
|
if (keepAlive) {
|
|
|
|
alarmIntent.putExtra("keepAlive", keepAlive);
|
|
|
|
alarmIntent.putExtra("keepAlive", keepAlive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uniqueReqCode, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
int reqCode = keepAlive ? BROADCAST_REQUEST_CODE_HEARTBEAT : BROADCAST_REQUEST_CODE_REAL_HEARTBEAT;
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, keepAlive ? 0 : 1, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, reqCode, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
|
|
Date dt = new Date(triggerTime);
|
|
|
|
Date dt = new Date(triggerTime);
|
|
|
|
|
|
|
|
|
|
|
@ -870,6 +875,16 @@ public class MpMasterService extends Service {
|
|
|
|
mPreviousHB = pendingIntent;
|
|
|
|
mPreviousHB = pendingIntent;
|
|
|
|
mPreviousHeartbeatTime = triggerTime;
|
|
|
|
mPreviousHeartbeatTime = triggerTime;
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerTime, pendingIntent);
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerTime, pendingIntent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Intent relaunchIntent = new Intent();
|
|
|
|
|
|
|
|
relaunchIntent.putExtra("cmd", "forceLaunch");
|
|
|
|
|
|
|
|
relaunchIntent.putExtra("pkname", MicroPhotoContext.PACKAGE_NAME_MPMASTER);
|
|
|
|
|
|
|
|
relaunchIntent.setAction("com.xy.xsetting.action");
|
|
|
|
|
|
|
|
relaunchIntent.setPackage("com.android.systemui");
|
|
|
|
|
|
|
|
// getApplicationContext().sendBroadcast(restartIntent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PendingIntent sysKAPendingIntent = PendingIntent.getBroadcast(this, BROADCAST_REQUEST_CODE_SYS_KEEPALIVE, relaunchIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime() + (mHeartbeatDuration + 2) * 1000, sysKAPendingIntent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -967,14 +982,12 @@ public class MpMasterService extends Service {
|
|
|
|
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
int uniqueReqCode = reqCode.getAndIncrement();
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(this, BROADCAST_REQUEST_CODE_NOTIFICATION, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getActivity(this, uniqueReqCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// make a stop intent
|
|
|
|
// make a stop intent
|
|
|
|
Intent stopIntent = new Intent(this, MpMasterService.class);
|
|
|
|
Intent stopIntent = new Intent(this, MpMasterService.class);
|
|
|
|
stopIntent.setAction(ACTION_STOP);
|
|
|
|
stopIntent.setAction(ACTION_STOP);
|
|
|
|
uniqueReqCode = reqCode.getAndIncrement();
|
|
|
|
PendingIntent pendingStopIntent = PendingIntent.getService(this, BROADCAST_REQUEST_CODE_NOTIFICATION_STOP, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
PendingIntent pendingStopIntent = PendingIntent.getService(this, uniqueReqCode, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification);
|
|
|
|
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification);
|
|
|
|
remoteViews.setOnClickPendingIntent(R.id.btn_stop, pendingStopIntent);
|
|
|
|
remoteViews.setOnClickPendingIntent(R.id.btn_stop, pendingStopIntent);
|
|
|
|
|
|
|
|
|
|
|
|