|
|
@ -1,11 +1,13 @@
|
|
|
|
package com.xypower.mpres;
|
|
|
|
package com.xypower.mpres;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.ActivityManager;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.res.AssetManager;
|
|
|
|
import android.content.res.AssetManager;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.core.graphics.Insets;
|
|
|
|
import androidx.core.graphics.Insets;
|
|
|
@ -24,36 +26,65 @@ import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final static String TAG = "MPRES";
|
|
|
|
|
|
|
|
|
|
|
|
private Handler mHandler;
|
|
|
|
private Handler mHandler;
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mHandler = new Handler();
|
|
|
|
|
|
|
|
|
|
|
|
Intent intent = getIntent();
|
|
|
|
Intent intent = getIntent();
|
|
|
|
int initres = intent.getIntExtra("initres", 0);
|
|
|
|
int initres = intent.getIntExtra("initres", 0);
|
|
|
|
if (initres != 0) {
|
|
|
|
if (initres == 1) {
|
|
|
|
mHandler = new Handler();
|
|
|
|
Log.i(TAG, "Init Config for MpApp");
|
|
|
|
|
|
|
|
|
|
|
|
final String sn = intent.getStringExtra("sn");
|
|
|
|
final String sn = intent.getStringExtra("sn");
|
|
|
|
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
|
|
|
|
|
|
|
|
Runnable runnable = new Runnable() {
|
|
|
|
Runnable runnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
notifyMpApp();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
restartMpApp(getApplicationContext(), "FIRST Config Init");
|
|
|
|
|
|
|
|
sleep(100);
|
|
|
|
|
|
|
|
System.exit(0);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
initMpAppConfigurations(getApplicationContext(), mHandler, sn, runnable);
|
|
|
|
initMpAppConfigurations(context, mHandler, sn, runnable);
|
|
|
|
|
|
|
|
} else if (initres == 2) {
|
|
|
|
|
|
|
|
Log.i(TAG, "Init Config for MpMaster");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
|
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (initMpMasterConfigurations(context)) {
|
|
|
|
|
|
|
|
restartMpMasterApp(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void notifyMpApp() {
|
|
|
|
sleep(1000);
|
|
|
|
restartMpApp(getApplicationContext(), "FIRST Config Init");
|
|
|
|
|
|
|
|
sleep(100);
|
|
|
|
|
|
|
|
System.exit(0);
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean initMpAppConfigurations(final Context context, final Handler handler, final String sn, final Runnable runnable) {
|
|
|
|
public static boolean initMpAppConfigurations(final Context context, final Handler handler, final String sn, final Runnable runnable) {
|
|
|
|
|
|
|
|
|
|
|
@ -169,7 +200,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
copyAssetsDir(context, "mpmst", dataPath.getAbsolutePath());
|
|
|
|
copyAssetsDir(context, "mpmst/data", dataPath.getAbsolutePath());
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -262,7 +293,8 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
public static void restartMpApp(Context context, String reason) {
|
|
|
|
public static void restartMpApp(Context context, String reason) {
|
|
|
|
|
|
|
|
|
|
|
|
SysApi.forceStopApp(context, MicroPhotoContext.PACKAGE_NAME_MPAPP);
|
|
|
|
// SysApi.forceStopApp(context, MicroPhotoContext.PACKAGE_NAME_MPAPP);
|
|
|
|
|
|
|
|
killAppProcess(context, MicroPhotoContext.PACKAGE_NAME_MPAPP);
|
|
|
|
sleep(100);
|
|
|
|
sleep(100);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -279,4 +311,65 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void restartMpMasterApp(Context context) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
killAppProcess(context, MicroPhotoContext.PACKAGE_NAME_MPMASTER);
|
|
|
|
|
|
|
|
sleep(50);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Intent intent = context.getPackageManager().getLaunchIntentForPackage(MicroPhotoContext.PACKAGE_NAME_MPMASTER);
|
|
|
|
|
|
|
|
if (intent != null) {
|
|
|
|
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static boolean killAppProcess(final Context context, String packageName) {
|
|
|
|
|
|
|
|
boolean killed = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
|
|
|
|
|
List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (ActivityManager.RunningAppProcessInfo rapi : processes) {
|
|
|
|
|
|
|
|
if (rapi.pkgList == null || rapi.pkgList.length == 0) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (String pkg : rapi.pkgList) {
|
|
|
|
|
|
|
|
if (TextUtils.equals(pkg, packageName)) {
|
|
|
|
|
|
|
|
killed = true;
|
|
|
|
|
|
|
|
android.os.Process.killProcess(rapi.pid);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (killed) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return killed;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean killAppByService(final Context context, String packageName, String serviceClassName) {
|
|
|
|
|
|
|
|
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
|
|
|
|
|
|
List<ActivityManager.RunningServiceInfo> services = am.getRunningServices(Integer.MAX_VALUE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean isRunning = false;
|
|
|
|
|
|
|
|
for (ActivityManager.RunningServiceInfo rsi : services) {
|
|
|
|
|
|
|
|
if (packageName.equalsIgnoreCase(rsi.service.getPackageName()) && TextUtils.equals(serviceClassName, rsi.service.getClassName())) {
|
|
|
|
|
|
|
|
isRunning = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return isRunning;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|