优化MpAPP重启机制

hdrplus
Matthew 12 months ago
parent c06442b8a8
commit 1c87e22bf9

@ -165,8 +165,8 @@ public class MainActivity extends AppCompatActivity {
} }
break; break;
}
}
} }
}; };
// mMessenger = new Messenger(new Handler()); // mMessenger = new Messenger(new Handler());

@ -82,6 +82,7 @@ public class MicroPhotoService extends Service {
public static final String ACTION_START = "com.xypower.mpapp.ACT_START"; public static final String ACTION_START = "com.xypower.mpapp.ACT_START";
public static final String ACTION_STOP = "com.xypower.mpapp.ACT_STOP"; public static final String ACTION_STOP = "com.xypower.mpapp.ACT_STOP";
public static final String ACTION_RESTART = "com.xypower.mpapp.ACT_RESTART";
public static final String ACTION_MAIN = "com.xypower.mpapp.ACT_MAIN"; public static final String ACTION_MAIN = "com.xypower.mpapp.ACT_MAIN";
private static final String ACTION_HEARTBEAT = MicroPhotoContext.ACTION_HEARTBEAT_MP; private static final String ACTION_HEARTBEAT = MicroPhotoContext.ACTION_HEARTBEAT_MP;
private static final String ACTION_TAKE_PHOTO = "com.xypower.mpapp.ACT_TP"; private static final String ACTION_TAKE_PHOTO = "com.xypower.mpapp.ACT_TP";
@ -172,6 +173,7 @@ public class MicroPhotoService extends Service {
intentFilter.addAction(ACTION_IMP_PUBKRY); intentFilter.addAction(ACTION_IMP_PUBKRY);
intentFilter.addAction(ACTION_TAKE_PHOTO_MANUALLY); intentFilter.addAction(ACTION_TAKE_PHOTO_MANUALLY);
intentFilter.addAction(ACTION_GPS_TIMEOUT); intentFilter.addAction(ACTION_GPS_TIMEOUT);
intentFilter.addAction(ACTION_RESTART);
// intentFilter.addAction(ACTION_HEARTBEAT_MANUALLY); // intentFilter.addAction(ACTION_HEARTBEAT_MANUALLY);
// intentFilter.addAction(ACTION_MSG_BROADCAST); // intentFilter.addAction(ACTION_MSG_BROADCAST);
// intentFilter.addAction(ACTION_VIDEO_FINISHED); // intentFilter.addAction(ACTION_VIDEO_FINISHED);
@ -385,6 +387,8 @@ public class MicroPhotoService extends Service {
ex.printStackTrace(); ex.printStackTrace();
} }
mService.enableGps(false); mService.enableGps(false);
} else if (TextUtils.equals(ACTION_RESTART, action)) {
MicroPhotoService.restartApp(context.getApplicationContext(), MicroPhotoContext.PACKAGE_NAME_MPAPP);
} }
} }
} }

@ -32,6 +32,7 @@ public class MicroPhotoContext {
public static final String PACKAGE_NAME_MPAPP = "com.xypower.mpapp"; public static final String PACKAGE_NAME_MPAPP = "com.xypower.mpapp";
public static final String PACKAGE_NAME_MPMASTER = "com.xypower.mpmaster"; public static final String PACKAGE_NAME_MPMASTER = "com.xypower.mpmaster";
public static final String ACTION_HEARTBEAT_MP = "com.xypower.mpapp.ACT_HB"; public static final String ACTION_HEARTBEAT_MP = "com.xypower.mpapp.ACT_HB";
public static final String ACTION_RESTART_MP = "com.xypower.mpapp.ACT_RESTART";
public final static String DEFAULT_MASTER_URL = "http://61.169.135.150:40101/"; public final static String DEFAULT_MASTER_URL = "http://61.169.135.150:40101/";
public final static String MASTER_URL_CMDID = "cmdid"; public final static String MASTER_URL_CMDID = "cmdid";
@ -416,9 +417,17 @@ public class MicroPhotoContext {
*/ */
try { try {
if (TextUtils.equals(packageName, PACKAGE_NAME_MPAPP)) {
Intent intent = new Intent(ACTION_RESTART_MP);
intent.putExtra("noDelay", 1);
intent.setPackage(PACKAGE_NAME_MPAPP);
context.sendBroadcast(intent);
} else {
SysApi.forceStopApp(context, packageName); SysApi.forceStopApp(context, packageName);
}
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName); Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
if (intent != null) { if (intent != null) {
intent.putExtra("noDelay", 1); intent.putExtra("noDelay", 1);

@ -78,11 +78,9 @@ 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_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 EXTRA_PARAM_SCHEDULES = "Schedules";
private static final String EXTRA_PARAM_SCHEDULE = "Schedule_";
private static final String EXTRA_PARAM_TIME = "Time";
private static final String FOREGROUND_CHANNEL_ID = "foreground_channel_id"; private static final String FOREGROUND_CHANNEL_ID = "foreground_channel_id";
private SmsSendReceiver mSmsSnedReceiver; private SmsSendReceiver mSmsSnedReceiver;
@ -514,7 +512,7 @@ public class MpMasterService extends Service {
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);
if (restart != 0) { if (restart != 0) {
mService.restartApp(context, context.getPackageName()); MicroPhotoContext.restartApp(context, context.getPackageName());
} else { } else {
mService.loadConfig(); mService.loadConfig();
mService.registerHeartbeatTimer(); mService.registerHeartbeatTimer();
@ -897,7 +895,7 @@ public class MpMasterService extends Service {
if (rebootType == 0) { if (rebootType == 0) {
logger.warning("Recv REBOOT MpMst APP cmd"); logger.warning("Recv REBOOT MpMst APP cmd");
Context context = MpMasterService.this.getApplicationContext(); Context context = MpMasterService.this.getApplicationContext();
restartApp(context, context.getPackageName()); MicroPhotoContext.restartApp(context, context.getPackageName());
} else { } else {
logger.warning("Recv RESET cmd"); logger.warning("Recv RESET cmd");
@ -908,26 +906,6 @@ public class MpMasterService extends Service {
mHander.postDelayed(runnable, 1000); mHander.postDelayed(runnable, 1000);
} }
public static void restartApp(Context context, String packageName) {
/*
Context context = MicroPhotoService.this.getApplicationContext();
Intent intent = getPackageManager().getLaunchIntentForPackage(context.getPackageName());
int noDelay = 1;
intent.putExtra("noDelay", noDelay);
PendingIntent restartIntent = PendingIntent.getActivity(context, 0, intent, 0);
AlarmManager mgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, restartIntent); // 1秒钟后重启应用
System.exit(0);
*/
Intent LaunchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
LaunchIntent.putExtra("noDelay", 1);
LaunchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(LaunchIntent);
}
public int getActiveSlotIndex() { public int getActiveSlotIndex() {
Context context = getApplicationContext(); Context context = getApplicationContext();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {

Loading…
Cancel
Save