|
|
|
@ -156,9 +156,9 @@ public class MpMasterService extends Service {
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = new Intent(this, MainActivity.class);
|
|
|
|
|
int uniqueReqCode = reqCode.getAndIncrement();
|
|
|
|
|
PendingIntent pi = PendingIntent.getActivity(this,uniqueReqCode, intent,0);
|
|
|
|
|
AlarmManager alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE);
|
|
|
|
|
alarmManager.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + 5000, pi);
|
|
|
|
|
PendingIntent pi = PendingIntent.getActivity(this, uniqueReqCode, intent, 0);
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
|
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, pi);
|
|
|
|
|
logger.info("Restart MpApp after 5s as for LowMemory");
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
@ -391,7 +391,9 @@ public class MpMasterService extends Service {
|
|
|
|
|
return mMntnMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean shouldSyncTime() { return mSyncTime; }
|
|
|
|
|
public boolean shouldSyncTime() {
|
|
|
|
|
return mSyncTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void detectMpAppAlive() {
|
|
|
|
|
final MpMasterService thisObj = this;
|
|
|
|
@ -426,7 +428,7 @@ public class MpMasterService extends Service {
|
|
|
|
|
|
|
|
|
|
if (!isMpAppRunning) {
|
|
|
|
|
// Restart MpApp
|
|
|
|
|
MicroPhotoContext.restartMpApp(context, "MpMST Keep Alive Detection: NO Lock");
|
|
|
|
|
MpMasterService.restartMpApp(context,"MpMST Keep Alive Detection: NO Lock");
|
|
|
|
|
logger.warning("Restart MpAPP as There is NO Lock");
|
|
|
|
|
mTimeToStartMpApp = ts;
|
|
|
|
|
return;
|
|
|
|
@ -436,18 +438,18 @@ public class MpMasterService extends Service {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long tempduration = mMpHeartbeatDuration;
|
|
|
|
|
if(mMpHeartbeatDuration < 600000)
|
|
|
|
|
if (mMpHeartbeatDuration < 600000)
|
|
|
|
|
tempduration = 290000;
|
|
|
|
|
if (mPreviousMpHbTime <= ts && ts - mPreviousMpHbTime > tempduration * 2) {
|
|
|
|
|
// MpApp is not running
|
|
|
|
|
if (ts - mTimeToStartMpApp >= 1800000) { // 30 minutes 30 * 60 * 1000
|
|
|
|
|
if (false) {
|
|
|
|
|
MicroPhotoContext.restartMpApp(context, "MpMST Keep Alive Detection");
|
|
|
|
|
MpMasterService.restartMpApp(context.getApplicationContext(),"MpMST Keep Alive Detection");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.warning("Restart MpAPP as it is NOT Running Prev MPAPP HB=" +
|
|
|
|
|
Long.toString((ts - mPreviousMpHbTime) / 1000) + " MPAPP HBDuration=" + Long.toString(mMpHeartbeatDuration)
|
|
|
|
|
+ " Prev MpRestart Time=" + Long.toString(mTimeToStartMpApp) + " last MPAPPHB =" + (mPreviousMpHbTime/1000));
|
|
|
|
|
+ " Prev MpRestart Time=" + Long.toString(mTimeToStartMpApp) + " last MPAPPHB =" + (mPreviousMpHbTime / 1000));
|
|
|
|
|
|
|
|
|
|
mTimeToStartMpApp = ts;
|
|
|
|
|
} else {
|
|
|
|
@ -644,12 +646,15 @@ public class MpMasterService extends Service {
|
|
|
|
|
|
|
|
|
|
public static class AlarmReceiver extends BroadcastReceiver {
|
|
|
|
|
private MpMasterService mService;
|
|
|
|
|
|
|
|
|
|
public AlarmReceiver() {
|
|
|
|
|
mService = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AlarmReceiver(MpMasterService service) {
|
|
|
|
|
mService = service;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
String action = intent.getAction();
|
|
|
|
|
if (TextUtils.equals(ACTION_HEARTBEAT, action)) {
|
|
|
|
@ -690,7 +695,7 @@ public class MpMasterService extends Service {
|
|
|
|
|
int restart = intent.getIntExtra("restart", 0);
|
|
|
|
|
mService.logger.info("Update Config Fired ACTION=" + action + " restart=" + restart);
|
|
|
|
|
if (restart != 0) {
|
|
|
|
|
MicroPhotoContext.restartApp(context, context.getPackageName(), "Config Updated");
|
|
|
|
|
MpMasterService.restartMpMasterApp(context,"Config Updated");
|
|
|
|
|
} else {
|
|
|
|
|
mService.loadConfig();
|
|
|
|
|
mService.registerHeartbeatTimer();
|
|
|
|
@ -700,18 +705,14 @@ public class MpMasterService extends Service {
|
|
|
|
|
String cmd = intent.getStringExtra("cmd");
|
|
|
|
|
String msg = intent.getStringExtra("msg");
|
|
|
|
|
// mService.logger.info("cmd=" + cmd + " msg=" + msg);
|
|
|
|
|
if("write".equals(cmd)) {
|
|
|
|
|
if ("write".equals(cmd)) {
|
|
|
|
|
// int progress = Integer.parseInt(msg);
|
|
|
|
|
}
|
|
|
|
|
else if("update".equals(cmd)) {
|
|
|
|
|
} else if ("update".equals(cmd)) {
|
|
|
|
|
// int progress = Integer.parseInt(msg);
|
|
|
|
|
}
|
|
|
|
|
else if("info".equals(cmd)) {
|
|
|
|
|
}
|
|
|
|
|
else if("error".equals(cmd)) {
|
|
|
|
|
} else if ("info".equals(cmd)) {
|
|
|
|
|
} else if ("error".equals(cmd)) {
|
|
|
|
|
mService.logger.warning("UPD OTA Failed");
|
|
|
|
|
}
|
|
|
|
|
else if("success".equals(cmd)) {
|
|
|
|
|
} else if ("success".equals(cmd)) {
|
|
|
|
|
//confirm to reboot device ??
|
|
|
|
|
mService.logger.warning("UPD OTA Succeeded, will REBOOT device");
|
|
|
|
|
Handler handler = new Handler();
|
|
|
|
@ -824,6 +825,7 @@ public class MpMasterService extends Service {
|
|
|
|
|
}
|
|
|
|
|
return nextAbsSec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void registerHeartbeatTimer(long triggerTime, boolean keepAlive) {
|
|
|
|
|
|
|
|
|
|
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
|
|
|
|
@ -1130,7 +1132,7 @@ public class MpMasterService extends Service {
|
|
|
|
|
File file = new File(tempPath);
|
|
|
|
|
file.mkdirs();
|
|
|
|
|
final String filePath = tempPath + File.separator + "mp.apk";
|
|
|
|
|
Thread th =new Thread(new Runnable() {
|
|
|
|
|
Thread th = new Thread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
|
@ -1161,8 +1163,7 @@ public class MpMasterService extends Service {
|
|
|
|
|
if (rebootType == 0) {
|
|
|
|
|
logger.warning("Recv REBOOT MpMst APP cmd");
|
|
|
|
|
Context context = MpMasterService.this.getApplicationContext();
|
|
|
|
|
MicroPhotoContext.restartApp(context, context.getPackageName(), reason);
|
|
|
|
|
|
|
|
|
|
MpMasterService.restartMpMasterApp(context,reason);
|
|
|
|
|
} else {
|
|
|
|
|
logger.warning("Recv RESET cmd");
|
|
|
|
|
SysApi.reboot(MpMasterService.this.getApplicationContext());
|
|
|
|
@ -1255,13 +1256,68 @@ public class MpMasterService extends Service {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void restartApp(Context context) {
|
|
|
|
|
//重启运维应用
|
|
|
|
|
public static void restartMpMasterApp(Context context,String reason) {
|
|
|
|
|
Intent intent = new Intent(context, MainActivity.class);
|
|
|
|
|
if (intent != null) {
|
|
|
|
|
if (!TextUtils.isEmpty(reason)) {
|
|
|
|
|
intent.putExtra("reason", reason);
|
|
|
|
|
}
|
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//重启MpApp应用
|
|
|
|
|
public static void restartMpApp(Context context, String reason) {
|
|
|
|
|
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
|
|
|
SysApi.forceStopApp(context, MicroPhotoContext.PACKAGE_NAME_MPAPP);
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(100);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
//// 然后启动目标应用
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = context.getPackageManager().getLaunchIntentForPackage(MicroPhotoContext.PACKAGE_NAME_MPAPP);
|
|
|
|
|
if (intent != null) {
|
|
|
|
|
intent.putExtra("noDelay", 1);
|
|
|
|
|
if (!TextUtils.isEmpty(reason)) {
|
|
|
|
|
intent.putExtra("reason", reason);
|
|
|
|
|
}
|
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.exit(0);
|
|
|
|
|
//根据包名重启应用
|
|
|
|
|
public static void restartAppByPackage(Context context,String packagename, String reason) {
|
|
|
|
|
|
|
|
|
|
SysApi.forceStopApp(context, packagename);
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(100);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
//// 然后启动目标应用
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packagename);
|
|
|
|
|
if (intent != null) {
|
|
|
|
|
intent.putExtra("noDelay", 1);
|
|
|
|
|
if (!TextUtils.isEmpty(reason)) {
|
|
|
|
|
intent.putExtra("reason", reason);
|
|
|
|
|
}
|
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateTime(long ms) {
|
|
|
|
@ -1334,7 +1390,7 @@ public class MpMasterService extends Service {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
copyAssetsDir(context, "mpapp/data", tmpDestPath.getAbsolutePath());
|
|
|
|
|
MicroPhotoContext.restartMpApp(context, "FIRST Config Init");
|
|
|
|
|
MpMasterService.restartMpApp(context.getApplicationContext(),"FIRST Config Init");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -1427,10 +1483,10 @@ public class MpMasterService extends Service {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fos = new FileOutputStream(file);
|
|
|
|
|
int len=-1;
|
|
|
|
|
int len = -1;
|
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
while ((len=inputStream.read(buffer)) != -1) {
|
|
|
|
|
fos.write(buffer,0, len);
|
|
|
|
|
while ((len = inputStream.read(buffer)) != -1) {
|
|
|
|
|
fos.write(buffer, 0, len);
|
|
|
|
|
}
|
|
|
|
|
fos.flush();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
@ -1449,10 +1505,15 @@ public class MpMasterService extends Service {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public native static int getInt(int cmd);
|
|
|
|
|
|
|
|
|
|
public native static int setInt(int cmd, int val);
|
|
|
|
|
|
|
|
|
|
public native static int[] getStats(long ts);
|
|
|
|
|
|
|
|
|
|
public native static String getSystemProperty(String key);
|
|
|
|
|
|
|
|
|
|
public native static void rebootDevice();
|
|
|
|
|
|
|
|
|
|
public native static boolean isMpAppRunning();
|
|
|
|
|
|
|
|
|
|
////////////////////////GPS////////////////////
|
|
|
|
|