增加重启原因

TempBranch
Matthew 8 months ago
parent 091dfc86f0
commit 827890deed

@ -420,7 +420,7 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
mGetSystemInfoMid = env->GetMethodID(classService, "getSystemInfo", "()Ljava/lang/String;"); mGetSystemInfoMid = env->GetMethodID(classService, "getSystemInfo", "()Ljava/lang/String;");
mInstallAppMid = env->GetMethodID(classService, "installApp", "(Ljava/lang/String;J)Z"); mInstallAppMid = env->GetMethodID(classService, "installApp", "(Ljava/lang/String;J)Z");
mRebootMid = env->GetMethodID(classService, "reboot", "(IJ)V"); mRebootMid = env->GetMethodID(classService, "reboot", "(IJLjava/lang/String;)V");
mEnableGpsMid = env->GetMethodID(classService, "enableGps", "(Z)V"); mEnableGpsMid = env->GetMethodID(classService, "enableGps", "(Z)V");
mRequestPositionMid = env->GetMethodID(classService, "requestPosition", "()Z"); mRequestPositionMid = env->GetMethodID(classService, "requestPosition", "()Z");
@ -1013,7 +1013,7 @@ bool CPhoneDevice::Reboot(int resetType)
return true; return true;
} }
void CPhoneDevice::RestartApp(int resetType, long timeout) void CPhoneDevice::RestartApp(int resetType, long timeout, const std::string& reason)
{ {
JNIEnv* env = NULL; JNIEnv* env = NULL;
bool didAttachThread = false; bool didAttachThread = false;
@ -1022,7 +1022,13 @@ void CPhoneDevice::RestartApp(int resetType, long timeout)
{ {
ALOGE("Failed to get JNI Env"); ALOGE("Failed to get JNI Env");
} }
env->CallVoidMethod(m_javaService, mRebootMid, resetType, timeout);
jstring jreason = NULL;
if (!reason.empty())
{
jreason = env->NewStringUTF(reason.c_str());
}
env->CallVoidMethod(m_javaService, mRebootMid, resetType, timeout, jreason);
if (didAttachThread) if (didAttachThread)
{ {
m_vm->DetachCurrentThread(); m_vm->DetachCurrentThread();
@ -1166,7 +1172,7 @@ void CPhoneDevice::handleRebootTimer(union sigval v)
CPhoneDevice* pDevice = (CPhoneDevice*)(v.sival_ptr); CPhoneDevice* pDevice = (CPhoneDevice*)(v.sival_ptr);
// Reboot APP // Reboot APP
XYLOG(XYLOG_SEVERITY_ERROR, "Camera Close Thread is DEAD, will RESTART app"); XYLOG(XYLOG_SEVERITY_ERROR, "Camera Close Thread is DEAD, will RESTART app");
pDevice->RestartApp(0, 2000); pDevice->RestartApp(0, 2000, "Camera Can't Close");
} }
// void CPhoneDevice::handleRebootTimerImpl() // void CPhoneDevice::handleRebootTimerImpl()

File diff suppressed because it is too large Load Diff

@ -205,7 +205,7 @@ public:
virtual bool UpdateSchedules(); virtual bool UpdateSchedules();
virtual bool QuerySystemProperties(map<string, string>& properties); virtual bool QuerySystemProperties(map<string, string>& properties);
virtual bool InstallAPP(const std::string& path, unsigned int delayedTime); virtual bool InstallAPP(const std::string& path, unsigned int delayedTime);
virtual bool Reboot(int resetType); virtual bool Reboot(int resetType, const std::string& reason);
virtual bool EnableGPS(bool enabled); virtual bool EnableGPS(bool enabled);
virtual float QueryBattaryVoltage(int timesForAvg, bool* isCharging); virtual float QueryBattaryVoltage(int timesForAvg, bool* isCharging);
virtual bool RequestPosition(); virtual bool RequestPosition();
@ -293,7 +293,7 @@ protected:
void handleTimerImpl(TIMER_CONTEXT* context); void handleTimerImpl(TIMER_CONTEXT* context);
void static handleRebootTimer(union sigval v); void static handleRebootTimer(union sigval v);
// void handleRebootTimerImpl(); // void handleRebootTimerImpl();
void RestartApp(int rebootType, long timeout); void RestartApp(int rebootType, long timeout, const std::string& reason);
int QueryBatteryVoltage(int retries); int QueryBatteryVoltage(int retries);

@ -163,6 +163,10 @@ public class MainActivity extends AppCompatActivity {
Intent intent = getIntent(); Intent intent = getIntent();
final int noDelay = intent.getIntExtra("noDelay", 0); final int noDelay = intent.getIntExtra("noDelay", 0);
int rebootFlag = intent.getIntExtra("reboot", 0); int rebootFlag = intent.getIntExtra("reboot", 0);
String reason = intent.getStringExtra("reason");
if (!TextUtils.isEmpty(reason)) {
Log.w(TAG, "App Started with reason: " + reason);
}
if (rebootFlag == 1) { if (rebootFlag == 1) {
Log.i(TAG, "After Reboot"); Log.i(TAG, "After Reboot");
} }

@ -9,6 +9,7 @@ import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentCallbacks2;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -156,6 +157,42 @@ public class MicroPhotoService extends Service {
public MicroPhotoService() { public MicroPhotoService() {
} }
@Override
public void onTrimMemory(int level) {
if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) {
// Clear the caches. Note all pending requests will be removed too.
final Context context = getApplicationContext();
try {
infoLog("Restart MpApp as for TrimMemory");
mHander.postDelayed(new Runnable() {
@Override
public void run() {
restartApp(context, MicroPhotoContext.PACKAGE_NAME_MPAPP);
}
}, 1000);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
@Override
public void onLowMemory() {
final Context context = getApplicationContext();
try {
Intent intent = new Intent(this, MainActivity.class);
int noDelay = 1;
intent.putExtra("noDelay", noDelay);
PendingIntent pi = PendingIntent.getActivity(this,0, intent,0);
AlarmManager alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + 5000, pi);
infoLog("Restart MpApp after 5s as for LowMemory");
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service. // TODO: Return the communication channel to the service.

@ -362,7 +362,7 @@ public class MicroPhotoContext {
} }
} }
public static void restartMpApp(Context context) { public static void restartMpApp(Context context, String reason) {
/* /*
Context context = MicroPhotoService.this.getApplicationContext(); Context context = MicroPhotoService.this.getApplicationContext();
Intent intent = getPackageManager().getLaunchIntentForPackage(context.getPackageName()); Intent intent = getPackageManager().getLaunchIntentForPackage(context.getPackageName());
@ -376,10 +376,10 @@ public class MicroPhotoContext {
*/ */
restartApp(context, PACKAGE_NAME_MPAPP); restartApp(context, PACKAGE_NAME_MPAPP, reason);
} }
public static void restartApp(Context context, String packageName) { public static void restartApp(Context context, String packageName, String reason) {
/* /*
Context context = MicroPhotoService.this.getApplicationContext(); Context context = MicroPhotoService.this.getApplicationContext();
Intent intent = getPackageManager().getLaunchIntentForPackage(context.getPackageName()); Intent intent = getPackageManager().getLaunchIntentForPackage(context.getPackageName());
@ -398,6 +398,9 @@ public class MicroPhotoContext {
Intent intent = new Intent(ACTION_RESTART_MP); Intent intent = new Intent(ACTION_RESTART_MP);
intent.putExtra("noDelay", 1); intent.putExtra("noDelay", 1);
if (!TextUtils.isEmpty(reason)) {
intent.putExtra("reason", reason);
}
intent.setPackage(PACKAGE_NAME_MPAPP); intent.setPackage(PACKAGE_NAME_MPAPP);
context.sendBroadcast(intent); context.sendBroadcast(intent);
@ -407,6 +410,9 @@ public class MicroPhotoContext {
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);
if (!TextUtils.isEmpty(reason)) {
intent.putExtra("reason", reason);
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent); context.startActivity(intent);
} }

@ -900,7 +900,7 @@ public class AppMaster {
String packageName = jsonObject.optString("packageName", null); String packageName = jsonObject.optString("packageName", null);
if (packageName != null) { if (packageName != null) {
MicroPhotoContext.restartApp(mService.getApplicationContext(), packageName); MicroPhotoContext.restartApp(mService.getApplicationContext(), packageName, "Config Updated");
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
@ -952,7 +952,7 @@ public class AppMaster {
} catch (Exception ex) { } catch (Exception ex) {
} }
MicroPhotoContext.restartMpApp(context); MicroPhotoContext.restartMpApp(context, "CMA Updated");
} }
}); });
@ -978,7 +978,7 @@ public class AppMaster {
MicroPhotoContext.saveMpAppConfig(context, appConfig); MicroPhotoContext.saveMpAppConfig(context, appConfig);
MicroPhotoContext.restartMpApp(mService.getApplicationContext()); MicroPhotoContext.restartMpApp(mService.getApplicationContext(), "HB Duration Updated");
return true; return true;
} }

@ -130,7 +130,7 @@ public class MainActivity extends AppCompatActivity {
} }
break; break;
case R.id.action_reboot_mp:{ case R.id.action_reboot_mp:{
MicroPhotoContext.restartMpApp(getApplicationContext()); MicroPhotoContext.restartMpApp(getApplicationContext(), "Manual Restart from MpMst");
} }
break; break;
case R.id.action_reboot_mpmst:{ case R.id.action_reboot_mpmst:{

@ -141,6 +141,20 @@ public class MpMasterService extends Service {
public MpMasterService() { public MpMasterService() {
} }
@Override
public void onLowMemory() {
final Context context = getApplicationContext();
try {
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0, 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();
}
}
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service. // TODO: Return the communication channel to the service.
@ -376,7 +390,7 @@ public class MpMasterService extends Service {
if (mPreviousMpHbTime <= ts && ts - mPreviousMpHbTime > mMpHeartbeatDuration * 2) { if (mPreviousMpHbTime <= ts && ts - mPreviousMpHbTime > mMpHeartbeatDuration * 2) {
// MpApp is not running // MpApp is not running
if (ts - mTimeToStartMpApp >= 30000) { if (ts - mTimeToStartMpApp >= 30000) {
MicroPhotoContext.restartMpApp(context); MicroPhotoContext.restartMpApp(context, "MpMST Keep Alive Detection");
mTimeToStartMpApp = ts; mTimeToStartMpApp = ts;
logger.warning("Restart MpAPP as it is NOT Running Prev MPAPP HB=" + logger.warning("Restart MpAPP as it is NOT Running Prev MPAPP HB=" +
Long.toString((ts - mPreviousMpHbTime) / 1000) + " MPAPP HBDuration=" + Long.toString(mMpHeartbeatDuration)); Long.toString((ts - mPreviousMpHbTime) / 1000) + " MPAPP HBDuration=" + Long.toString(mMpHeartbeatDuration));
@ -578,7 +592,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) {
MicroPhotoContext.restartApp(context, context.getPackageName()); MicroPhotoContext.restartApp(context, context.getPackageName(), "Config Updated");
} else { } else {
mService.loadConfig(); mService.loadConfig();
mService.registerHeartbeatTimer(); mService.registerHeartbeatTimer();
@ -1023,7 +1037,7 @@ public class MpMasterService extends Service {
th.start(); th.start();
} }
public void reboot(final int rebootType) { public void reboot(final int rebootType, String reason) {
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
@Override @Override
@ -1031,7 +1045,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();
MicroPhotoContext.restartApp(context, context.getPackageName()); MicroPhotoContext.restartApp(context, context.getPackageName(), reason);
} else { } else {
logger.warning("Recv RESET cmd"); logger.warning("Recv RESET cmd");
@ -1167,7 +1181,7 @@ public class MpMasterService extends Service {
} }
copyAssetsDir(context, "mpapp", destPath); copyAssetsDir(context, "mpapp", destPath);
MicroPhotoContext.restartMpApp(context); MicroPhotoContext.restartMpApp(context, "FIRST Config Init");
} }
}; };

@ -31,7 +31,7 @@ public class UpdateReceiver extends BroadcastReceiver {
MpMasterService.resetVersions(context); MpMasterService.resetVersions(context);
if (packageName.equals("package:" + targetPackageName)) { if (packageName.equals("package:" + targetPackageName)) {
// SysApi.enableApp(context, targetPackageName); // SysApi.enableApp(context, targetPackageName);
restartAPP(context, targetPackageName); restartAPP(context, targetPackageName, "App Upgraded");
} }
} else if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {// Install broadcast } else if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {// Install broadcast
Log.e(TAG, "onReceive:Installed and Start the App:" + targetPackageName); Log.e(TAG, "onReceive:Installed and Start the App:" + targetPackageName);
@ -39,7 +39,7 @@ public class UpdateReceiver extends BroadcastReceiver {
if (packageName.equals("package:" + targetPackageName)) { if (packageName.equals("package:" + targetPackageName)) {
/*SystemUtil.reBootDevice();*/ /*SystemUtil.reBootDevice();*/
// SysApi.enableApp(context, targetPackageName); // SysApi.enableApp(context, targetPackageName);
restartAPP(context, targetPackageName); restartAPP(context, targetPackageName, "App Installed");
} }
} else if (action.equals(Intent.ACTION_PACKAGE_REMOVED)) { // Uninstall } else if (action.equals(Intent.ACTION_PACKAGE_REMOVED)) { // Uninstall
// Logger.e(TAG, "onReceive:uninstall" + packageName); // Logger.e(TAG, "onReceive:uninstall" + packageName);
@ -52,7 +52,7 @@ public class UpdateReceiver extends BroadcastReceiver {
MpMasterService.resetVersions(context); MpMasterService.resetVersions(context);
if (packageName.equals("package:" + targetPackageName)) { if (packageName.equals("package:" + targetPackageName)) {
// SysApi.enableApp(context, targetPackageName); // SysApi.enableApp(context, targetPackageName);
tryToRestartApp(context, targetPackageName); tryToRestartApp(context, targetPackageName, "App Upgraded");
} }
} else if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {// Install broadcast } else if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {// Install broadcast
Log.e(TAG, "onReceive:Installed and Start the App:" + targetPackageName); Log.e(TAG, "onReceive:Installed and Start the App:" + targetPackageName);
@ -60,36 +60,39 @@ public class UpdateReceiver extends BroadcastReceiver {
if (packageName.equals("package:" + targetPackageName)) { if (packageName.equals("package:" + targetPackageName)) {
/*SystemUtil.reBootDevice();*/ /*SystemUtil.reBootDevice();*/
// SysApi.enableApp(context, targetPackageName); // SysApi.enableApp(context, targetPackageName);
tryToRestartApp(context, targetPackageName); tryToRestartApp(context, targetPackageName, "App Installed");
} }
} else if (action.equals(Intent.ACTION_PACKAGE_REMOVED)) { // Uninstall } else if (action.equals(Intent.ACTION_PACKAGE_REMOVED)) { // Uninstall
// Logger.e(TAG, "onReceive:uninstall" + packageName); // Logger.e(TAG, "onReceive:uninstall" + packageName);
} }
} }
private void tryToRestartApp(final Context context, final String targetPackageName) { private void tryToRestartApp(final Context context, final String targetPackageName, String reason) {
Handler handler = new Handler(); Handler handler = new Handler();
handler.postDelayed(new Runnable() { handler.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (TextUtils.equals(targetPackageName, APP_PACKAGE_MPAPP)) { if (TextUtils.equals(targetPackageName, APP_PACKAGE_MPAPP)) {
startMpApp(context); startMpApp(context, reason);
} else { } else {
restartAPP(context, targetPackageName); restartAPP(context, targetPackageName, reason);
} }
} }
}, 10000); }, 10000);
} }
public static void restartAPP(Context context, String packageName) { public static void restartAPP(Context context, String packageName, String reason) {
Intent intent = context.getPackageManager() Intent intent = context.getPackageManager()
.getLaunchIntentForPackage(packageName); .getLaunchIntentForPackage(packageName);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (!TextUtils.isEmpty(reason)) {
intent.putExtra("reason", reason);
}
context.startActivity(intent); context.startActivity(intent);
// ActManager.getAppManager().finishAllActivity(); // ActManager.getAppManager().finishAllActivity();
} }
public void startMpApp(final Context context) { private void startMpApp(final Context context, String reason) {
try { try {
if (MicroPhotoContext.isAppAlive(context, MicroPhotoContext.PACKAGE_NAME_MPAPP)) { if (MicroPhotoContext.isAppAlive(context, MicroPhotoContext.PACKAGE_NAME_MPAPP)) {
@ -107,7 +110,7 @@ public class UpdateReceiver extends BroadcastReceiver {
if ((ts - modifiedTimeOfDb) > 12 * 1000) { if ((ts - modifiedTimeOfDb) > 12 * 1000) {
// greater than 12 seconds // greater than 12 seconds
// logger.warning("Start MpAPP as it is NOT running"); // logger.warning("Start MpAPP as it is NOT running");
MicroPhotoContext.restartMpApp(context); MicroPhotoContext.restartMpApp(context, reason);
} }
} catch (Exception ex) { } catch (Exception ex) {

Loading…
Cancel
Save