|
|
@ -1,34 +1,54 @@
|
|
|
|
package com.xypower.mpres;
|
|
|
|
package com.xypower.mpres;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
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.text.TextUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.activity.EdgeToEdge;
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.core.graphics.Insets;
|
|
|
|
import androidx.core.graphics.Insets;
|
|
|
|
import androidx.core.view.ViewCompat;
|
|
|
|
import androidx.core.view.ViewCompat;
|
|
|
|
import androidx.core.view.WindowInsetsCompat;
|
|
|
|
import androidx.core.view.WindowInsetsCompat;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.dev.devapi.api.SysApi;
|
|
|
|
|
|
|
|
import com.xypower.common.FilesUtils;
|
|
|
|
|
|
|
|
import com.xypower.common.MicroPhotoContext;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Handler mHandler;
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
EdgeToEdge.enable(this);
|
|
|
|
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
|
|
|
|
|
|
|
|
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
|
|
|
Intent intent = getIntent();
|
|
|
|
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
|
|
|
int initres = intent.getIntExtra("initres", 0);
|
|
|
|
return insets;
|
|
|
|
if (initres != 0) {
|
|
|
|
});
|
|
|
|
mHandler = new Handler();
|
|
|
|
|
|
|
|
Runnable runnable = new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
notifyMpApp();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
initMpAppConfigurations(getApplicationContext(), mHandler, runnable);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void notifyMpApp() {
|
|
|
|
|
|
|
|
restartMpApp(getApplicationContext(), "FIRST Config Init");
|
|
|
|
|
|
|
|
sleep(100);
|
|
|
|
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean initMpAppConfigurations(final Context context) {
|
|
|
|
public static boolean initMpAppConfigurations(final Context context, final Handler handler, final Runnable runnable) {
|
|
|
|
|
|
|
|
|
|
|
|
boolean existed = true;
|
|
|
|
boolean existed = true;
|
|
|
|
String destPath = MicroPhotoContext.buildMpAppDir(context);
|
|
|
|
String destPath = MicroPhotoContext.buildMpAppDir(context);
|
|
|
@ -65,13 +85,13 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Runnable runnable = new Runnable() {
|
|
|
|
Runnable thRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
|
|
|
|
sleep(5000);
|
|
|
|
sleep(5000);
|
|
|
|
|
|
|
|
|
|
|
|
File tmpDestPath = new File(MicroPhotoContext.buildMasterAppDir(context));
|
|
|
|
File tmpDestPath = new File(MicroPhotoContext.buildMpResAppDir(context));
|
|
|
|
tmpDestPath = new File(tmpDestPath, "mpdata");
|
|
|
|
tmpDestPath = new File(tmpDestPath, "mpdata");
|
|
|
|
if (tmpDestPath.exists()) {
|
|
|
|
if (tmpDestPath.exists()) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -81,11 +101,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
copyAssetsDir(context, "mpapp/data", tmpDestPath.getAbsolutePath());
|
|
|
|
copyAssetsDir(context, "mpapp/data", tmpDestPath.getAbsolutePath());
|
|
|
|
MpMasterService.restartMpApp(context.getApplicationContext(), "FIRST Config Init");
|
|
|
|
|
|
|
|
|
|
|
|
handler.postDelayed(runnable, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Thread th = new Thread(runnable);
|
|
|
|
Thread th = new Thread(thRunnable);
|
|
|
|
th.start();
|
|
|
|
th.start();
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -187,4 +208,31 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
FilesUtils.closeFriendly(fos);
|
|
|
|
FilesUtils.closeFriendly(fos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void sleep(long ms) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Thread.sleep(ms);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void restartMpApp(Context context, String reason) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SysApi.forceStopApp(context, MicroPhotoContext.PACKAGE_NAME_MPAPP);
|
|
|
|
|
|
|
|
sleep(100);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|