|
|
@ -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) {
|
|
|
|
|
|
|
|
|
|
|
|