diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 012a5f3a..f95f9c1d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -99,7 +99,10 @@
android:supportsRtl="true"
android:theme="@style/Theme.MicroPhoto"
tools:targetApi="28">
-
+
binding.logs.getHeight()) {
+ binding.logs.scrollTo(0, offset - binding.logs.getHeight() + binding.logs.getLineHeight());
+ }
+ }
+ }
+ break;
+ }
+ }
+ };
+
+ }
+
+
+ @Override
+ protected void onResume() {
+ // call the superclass method first
+ super.onResume();
+
+ try {
+ String logFilePath = MicroPhotoContext.buildAppDir(this.getApplicationContext());
+ logFilePath += "logs";
+ File file = new File(logFilePath);
+ if (!file.exists()) {
+ file.mkdirs();
+ }
+ logFilePath += "/log.txt";
+ file = new File(logFilePath);
+ if (!file.exists()) {
+ file.createNewFile();
+ }
+
+ mLogFileObserver = new LogFileObserver(logFilePath);
+ mLogFileObserver.startWatching();
+ Log.i(TAG, "Log Observer Started");
+
+ int lines = binding.logs.getLineCount();
+ if (lines > MAX_LOG_LINES) {
+ int excessLineNumber = lines - MIN_LOG_LINES;
+ int eolIndex = -1;
+ CharSequence charSequence = binding.logs.getText();
+ for (int i = 0; i < excessLineNumber; i++) {
+ do {
+ eolIndex++;
+ } while (eolIndex < charSequence.length() && charSequence.charAt(eolIndex) != '\n');
+ }
+ if (eolIndex < charSequence.length()) {
+ binding.logs.getEditableText().delete(0, eolIndex + 1);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ protected void onPause() {
+ // call the superclass method first
+ super.onPause();
+
+ try {
+ if (mLogFileObserver != null) {
+ mLogFileObserver.stopWatching();
+ mLogFileObserver = null;
+ Log.i(TAG, "Log Observer Stopped");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ // todo: goto back activity from here
+
+ finish();
+ return true;
+
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
+
+ private class LogFileObserver extends FileObserver {
+
+ private long mOffset = 0;
+ private String mPath = null;
+ public LogFileObserver(String path) {
+ super(path, FileObserver.MODIFY | FileObserver.CREATE);
+
+ mPath = path;
+ File file = new File(path);
+ if (file.exists()) {
+ mOffset = file.length();
+ }
+ }
+ @Override
+ public void onEvent(int event, String s) {
+ int e = event & FileObserver.ALL_EVENTS;
+
+ if (e == FileObserver.MODIFY) {
+ File file = new File(mPath);
+ long newOffset = file.length();
+ if (newOffset > mOffset) {
+ RandomReader reader = new RandomReader(mPath, mOffset);
+
+ byte[] bytes = new byte[(int)(newOffset - mOffset)];
+ int bytesRead = reader.read(bytes);
+ mOffset += bytesRead;
+
+ Message msg = Message.obtain();
+ msg.what = MSG_WHAT_LOG_OBSERVER;
+ msg.obj = bytes;
+ msg.arg1 = bytesRead;
+ mHandler.sendMessage(msg);
+ }
+ } else if (e == FileObserver.CREATE) {
+ mOffset = 0;
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/xypower/mpapp/MainActivity.java b/app/src/main/java/com/xypower/mpapp/MainActivity.java
index 5f140950..07078d68 100644
--- a/app/src/main/java/com/xypower/mpapp/MainActivity.java
+++ b/app/src/main/java/com/xypower/mpapp/MainActivity.java
@@ -50,60 +50,12 @@ public class MainActivity extends AppCompatActivity {
public static final String TAG = "MPLOG";
private static int MY_PERMISSIONS_REQUEST_FOREGROUND_SERVICE = 100;
- public static final int MSG_WHAT_LOG_OBSERVER = MicroPhotoService.MSG_WHAT_MAX + 10;
-
// Used to load the 'microphoto' library on application startup.
-
- public static final int MAX_LOG_LINES = 480;
- public static final int MIN_LOG_LINES = 120;
-
private ActivityMainBinding binding;
- private Handler mHandler = null;
private Messenger mMessenger = null;
- private LogFileObserver mLogFileObserver = null;
-
- private class LogFileObserver extends FileObserver {
-
- private long mOffset = 0;
- private String mPath = null;
- public LogFileObserver(String path) {
- super(path, FileObserver.MODIFY | FileObserver.CREATE);
-
- mPath = path;
- File file = new File(path);
- if (file.exists()) {
- mOffset = file.length();
- }
- }
- @Override
- public void onEvent(int event, String s) {
- int e = event & FileObserver.ALL_EVENTS;
-
- if (e == FileObserver.MODIFY) {
- File file = new File(mPath);
- long newOffset = file.length();
- if (newOffset > mOffset) {
- RandomReader reader = new RandomReader(mPath, mOffset);
-
- byte[] bytes = new byte[(int)(newOffset - mOffset)];
- int bytesRead = reader.read(bytes);
- mOffset += bytesRead;
-
- Message msg = Message.obtain();
- msg.what = MSG_WHAT_LOG_OBSERVER;
- msg.obj = bytes;
- msg.arg1 = bytesRead;
- mHandler.sendMessage(msg);
- }
- } else if (e == FileObserver.CREATE) {
- mOffset = 0;
- }
- }
- }
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -128,39 +80,45 @@ public class MainActivity extends AppCompatActivity {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
actionBar.setTitle(actionBar.getTitle().toString() + " v" + MicroPhotoContext.getVersionName(getApplicationContext()) + " " + sdf.format(date));
- binding.logs.setText("");
- binding.logs.setMovementMethod(ScrollingMovementMethod.getInstance());
- binding.logs.setScrollbarFadingEnabled(false);
+ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
+ StrictMode.setThreadPolicy(policy);
- mHandler = new Handler(Looper.myLooper()) {
- @Override
- public void handleMessage(@NonNull Message msg) {
- switch (msg.what) {
- case MSG_WHAT_LOG_OBSERVER:
- {
- byte[] bytes = (byte[])msg.obj;
- int bytesRead = msg.arg1;
- String log = null;
- try {
- log = new String(bytes, 0, bytesRead, "UTF-8");
- } catch (Exception e) {
- e.printStackTrace();
- }
- if (log != null) {
- binding.logs.append(log);
- int offset = binding.logs.getLineCount() * binding.logs.getLineHeight();
- if (offset > binding.logs.getHeight()) {
- binding.logs.scrollTo(0, offset - binding.logs.getHeight() + binding.logs.getLineHeight());
- }
- }
+ initListener();
+
+ Context appContext = getApplicationContext();
+ String appPath = MicroPhotoContext.buildMpAppDir(appContext);
+ File appPathFile = new File(appPath);
+ if (!appPathFile.exists()) {
+ try {
+ appPathFile.mkdirs();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ if (!MicroPhotoContext.hasMpAppConfig(appContext)) {
+
+ String mstPath = MicroPhotoContext.buildMasterAppDir(appContext);
+ File mstPathFile = new File(mstPath);
+ File mpdataFile = new File(mstPathFile, "mpdata");
+
+ if (mpdataFile.exists()) {
+ File dataFile = new File(appPathFile, "data");
+ if (dataFile.exists()) {
+ try {
+ dataFile.delete();
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
- break;
}
- }
- };
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
+ try {
+ mpdataFile.renameTo(dataFile);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
Intent intent = getIntent();
final int noDelay = intent.getIntExtra("noDelay", 0);
@@ -175,7 +133,9 @@ public class MainActivity extends AppCompatActivity {
Log.d(TAG, "MainActivity: reboot=" + rebootFlag + " noDelay=" + noDelay);
- final MicroPhotoContext.AppConfig appConfig = getAppConfig();
+
+
+ final MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getMpAppConfig(appContext);
if (TextUtils.isEmpty(appConfig.cmdid)) {
appConfig.cmdid = MicroPhotoService.getSerialNumber();
binding.cmdid.setText(appConfig.cmdid);
@@ -206,6 +166,45 @@ public class MainActivity extends AppCompatActivity {
binding.network.setSelection(appConfig.network);
}
+ binding.btnStartServ.setEnabled(!MicroPhotoService.isRunning);
+ binding.btnStopServ.setEnabled(MicroPhotoService.isRunning);
+
+ if (MicroPhotoService.isRunning) {
+ Intent intent2 = new Intent(MainActivity.this, MicroPhotoService.class);
+ try {
+ stopService(intent2);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+
+
+ if (MicroPhotoContext.hasMpAppConfig(appContext)) {
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+
+ if (!MicroPhotoService.isRunning && !TextUtils.isEmpty(appConfig.cmdid) && !TextUtils.isEmpty(appConfig.server) && appConfig.port != 0) {
+ if (binding.btnStartServ.isEnabled()) {
+ binding.btnStartServ.performClick();
+ }
+ }
+ }
+ };
+
+ Handler handler = new Handler();
+ handler.postDelayed(runnable, 500);
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ }
+
+ protected void initListener() {
+
this.binding.btnStartServ.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -226,17 +225,10 @@ public class MainActivity extends AppCompatActivity {
// return;
}
- binding.logs.setText("");
- MicroPhotoContext.AppConfig curAppConfig = retrieveAndSaveAppConfig();
+ Context appContext = getApplicationContext();
+ MicroPhotoContext.AppConfig curAppConfig = MicroPhotoContext.getMpAppConfig(appContext);
- // TakeAndThrowPhoto(2, 0xFF);
- try {
- // Thread.sleep(20);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
-
- startMicroPhotoService(MainActivity.this.getApplicationContext(), appConfig, mMessenger);
+ startMicroPhotoService(appContext, curAppConfig, mMessenger);
binding.btnStartServ.setEnabled(false);
binding.btnStopServ.setEnabled(true);
@@ -356,30 +348,13 @@ public class MainActivity extends AppCompatActivity {
}
});
- if (MicroPhotoService.isRunning) {
- Intent intent2 = new Intent(MainActivity.this, MicroPhotoService.class);
- try {
- stopService(intent2);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
-
- Runnable runnable = new Runnable() {
+ binding.btnLogs.setOnClickListener(new View.OnClickListener() {
@Override
- public void run() {
-
- if (!MicroPhotoService.isRunning && !TextUtils.isEmpty(appConfig.cmdid) && !TextUtils.isEmpty(appConfig.server) && appConfig.port != 0) {
- if (binding.btnStartServ.isEnabled()) {
- binding.btnStartServ.performClick();
- }
- }
+ public void onClick(View v) {
+ Intent intent = new Intent(MainActivity.this, LogActivity.class);
+ startActivity(intent);
}
- };
- mHandler.postDelayed(runnable, noDelay != 0 ? 1000 : 5000);
-
- binding.btnStartServ.setEnabled(!MicroPhotoService.isRunning);
- binding.btnStopServ.setEnabled(MicroPhotoService.isRunning);
+ });
binding.btnSendHb.setOnClickListener(new View.OnClickListener() {
@Override
@@ -443,17 +418,13 @@ public class MainActivity extends AppCompatActivity {
}
};
- mHandler.postDelayed(runnable, 1500);
+ Handler handler = new Handler();
+ handler.postDelayed(runnable, 1500);
}
});
}
- @Override
- protected void onDestroy() {
- super.onDestroy();
- }
-
public static void startMicroPhotoService(Context context, MicroPhotoContext.AppConfig curAppConfig, Messenger messenger) {
if (TextUtils.isEmpty(curAppConfig.cmdid) || TextUtils.isEmpty(curAppConfig.server) || curAppConfig.port == 0) {
@@ -524,63 +495,6 @@ public class MainActivity extends AppCompatActivity {
MicroPhotoService.takePhoto(channel, preset, true, configFile.getAbsolutePath(), photoFile.getAbsolutePath());
}
- @Override
- protected void onResume() {
- // call the superclass method first
- super.onResume();
-
- try {
- String logFilePath = MicroPhotoContext.buildAppDir(this.getApplicationContext());
- logFilePath += "logs";
- File file = new File(logFilePath);
- if (!file.exists()) {
- file.mkdirs();
- }
- logFilePath += "/log.txt";
- file = new File(logFilePath);
- if (!file.exists()) {
- file.createNewFile();
- }
-
- mLogFileObserver = new LogFileObserver(logFilePath);
- mLogFileObserver.startWatching();
- Log.i(TAG, "Log Observer Started");
-
- int lines = binding.logs.getLineCount();
- if (lines > MAX_LOG_LINES) {
- int excessLineNumber = lines - MIN_LOG_LINES;
- int eolIndex = -1;
- CharSequence charSequence = binding.logs.getText();
- for (int i = 0; i < excessLineNumber; i++) {
- do {
- eolIndex++;
- } while (eolIndex < charSequence.length() && charSequence.charAt(eolIndex) != '\n');
- }
- if (eolIndex < charSequence.length()) {
- binding.logs.getEditableText().delete(0, eolIndex + 1);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Override
- protected void onPause() {
- // call the superclass method first
- super.onPause();
-
- try {
- if (mLogFileObserver != null) {
- mLogFileObserver.stopWatching();
- mLogFileObserver = null;
- Log.i(TAG, "Log Observer Stopped");
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
private MicroPhotoContext.AppConfig retrieveAndSaveAppConfig() {
MicroPhotoContext.AppConfig appConfig = new MicroPhotoContext.AppConfig();
diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml
index 305f41a3..36b42e29 100644
--- a/app/src/main/res/layout-land/activity_main.xml
+++ b/app/src/main/res/layout-land/activity_main.xml
@@ -204,6 +204,16 @@
app:layout_constraintStart_toEndOf="@+id/btnSaveCfg"
app:layout_constraintTop_toTopOf="@+id/btnStartServ" />
+
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_log.xml b/app/src/main/res/layout/activity_log.xml
new file mode 100644
index 00000000..123135e9
--- /dev/null
+++ b/app/src/main/res/layout/activity_log.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 5d47f29a..0d181f9d 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -211,6 +211,16 @@
android:layout_marginTop="8dp"
android:text="通道设置"
app:layout_constraintStart_toEndOf="@+id/simchange2"
+ app:layout_constraintTop_toTopOf="@+id/btnStartServ" />
+
+
-
-
-
-
\ No newline at end of file
diff --git a/common/src/main/java/com/xypower/common/FilesUtils.java b/common/src/main/java/com/xypower/common/FilesUtils.java
index e8c31708..8320b8d3 100644
--- a/common/src/main/java/com/xypower/common/FilesUtils.java
+++ b/common/src/main/java/com/xypower/common/FilesUtils.java
@@ -127,7 +127,6 @@ public class FilesUtils {
return intValue;
}
-
public static void writeTextFile(String path, String content) {
FileOutputStream fileOutputStream = null;
try {
diff --git a/common/src/main/java/com/xypower/common/MicroPhotoContext.java b/common/src/main/java/com/xypower/common/MicroPhotoContext.java
index 9246d6d9..d7596dce 100644
--- a/common/src/main/java/com/xypower/common/MicroPhotoContext.java
+++ b/common/src/main/java/com/xypower/common/MicroPhotoContext.java
@@ -1,6 +1,8 @@
package com.xypower.common;
import android.app.ActivityManager;
+import android.app.AlarmManager;
+import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -224,6 +226,14 @@ public class MicroPhotoContext {
return path;
}
+ public static boolean hasMpAppConfig(Context context) {
+ boolean existed = true;
+ String appPath = MicroPhotoContext.buildMpAppDir(context);
+ File appPathFile = new File(appPath);
+ File appConfigFile = new File(appPathFile, "data/App.json");
+ return appConfigFile.exists();
+ }
+
public static AppConfig getMpAppConfig(Context context) {
String appPath = buildMpAppDir(context);
@@ -379,6 +389,20 @@ public class MicroPhotoContext {
restartApp(context, PACKAGE_NAME_MPAPP, reason);
}
+ public static void restartMpApp(Context context, String reason, long delayedTimeMs) {
+ Intent intent = context.getPackageManager().getLaunchIntentForPackage(PACKAGE_NAME_MPAPP);
+
+ int noDelay = 1;
+ intent.putExtra("noDelay", noDelay);
+ if (!TextUtils.isEmpty(reason)) {
+ intent.putExtra("reason", reason);
+ }
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ PendingIntent restartIntent = PendingIntent.getActivity(context, 0, intent, 0);
+ AlarmManager mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
+ mgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + delayedTimeMs, restartIntent);
+ }
+
public static void restartApp(Context context, String packageName, String reason) {
/*
Context context = MicroPhotoService.this.getApplicationContext();
diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/MainActivity.java b/mpmaster/src/main/java/com/xypower/mpmaster/MainActivity.java
index 7da6d20f..d96cf0e6 100644
--- a/mpmaster/src/main/java/com/xypower/mpmaster/MainActivity.java
+++ b/mpmaster/src/main/java/com/xypower/mpmaster/MainActivity.java
@@ -154,7 +154,6 @@ public class MainActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item);
}
-
private void loadConfigInfo() {
Context context = getApplicationContext();
MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getMpAppConfig(context);
diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java
index 0b9219f2..4e2cabe9 100644
--- a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java
+++ b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java
@@ -27,7 +27,6 @@ import android.widget.RemoteViews;
import android.widget.Toast;
import androidx.core.app.NotificationCompat;
-import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.dev.devapi.api.SysApi;
import com.xypower.common.FileDownloader;
@@ -45,14 +44,12 @@ import org.json.JSONObject;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
-import java.io.RandomAccessFile;
import java.lang.reflect.Method;
import java.nio.channels.FileLock;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
-import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.concurrent.atomic.AtomicInteger;;
@@ -389,10 +386,7 @@ public class MpMasterService extends Service {
public boolean shouldSyncTime() { return mSyncTime; }
- public void startMpApp() {
- if (true) {
- return;
- }
+ public void detectMpAppAlive() {
try {
final Context context = getApplicationContext();
long ts = System.currentTimeMillis();
@@ -457,17 +451,9 @@ public class MpMasterService extends Service {
" Will restart MpApp in " + Long.toString(mDelayedRestartMpTime / 1000) + " seconds";
logger.warning(msg);
- AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
- Intent alarmIntent = new Intent();
- alarmIntent.setAction(ACTION_MP_RESTART);
- alarmIntent.putExtra("reason", msg);
-
- int uniqueReqCode = reqCode.getAndIncrement();
- PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uniqueReqCode, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
-
- alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, ts + mDelayedRestartMpTime, pendingIntent);
+ MicroPhotoContext.restartMpApp(context, msg, mDelayedRestartMpTime);
- mTimeToStartMpApp = ts;
+ mTimeToStartMpApp = ts + mDelayedRestartMpTime / 1000;
}
}
} catch (Exception ex) {
@@ -657,7 +643,7 @@ public class MpMasterService extends Service {
if (!keepAlive) {
mService.startMaster(false);
}
- mService.startMpApp();
+ mService.detectMpAppAlive();
} else if (TextUtils.equals(MicroPhotoContext.ACTION_HEARTBEAT_MP, action)) {
@@ -675,7 +661,7 @@ public class MpMasterService extends Service {
if (!mService.mSeparateNetwork && (!mService.mMntnMode)) {
mService.startMaster(true);
}
- mService.startMpApp();
+ mService.detectMpAppAlive();
} else if (TextUtils.equals(ACTION_UPDATE_CONFIGS, action)) {
int restart = intent.getIntExtra("restart", 0);
mService.logger.info("Update Config Fired ACTION=" + action + " restart=" + restart);
@@ -867,7 +853,7 @@ public class MpMasterService extends Service {
mHander.postDelayed(new Runnable() {
@Override
public void run() {
- startMpApp();
+ detectMpAppAlive();
}
}, 5000);
@@ -1244,34 +1230,59 @@ public class MpMasterService extends Service {
public static boolean initMpAppConfigurations(final Context context) {
+ boolean existed = true;
+ String destPath = MicroPhotoContext.buildMpAppDir(context);
+ File destPathFile = new File(destPath);
+ if (destPathFile.exists()) {
+ File dataPath = new File(destPathFile, "data");
+ if (dataPath.exists()) {
+ File file = new File(destPathFile, "App.json");
+ if (file.exists()) {
+ return false;
+ } else {
+ existed = false;
+ }
+ } else {
+ existed = false;
+ try {
+ dataPath.mkdirs();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ } else {
+ existed = false;
+ File dataPath = new File(destPathFile, "data");
+ try {
+ dataPath.mkdirs();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ if (existed) {
+ return false;
+ }
+
Runnable runnable = new Runnable() {
@Override
public void run() {
- String destPath = MicroPhotoContext.buildMpAppDir(context);
- File destPathFile = new File(destPath);
- if (destPathFile.exists()) {
- File dataPath = new File(destPathFile, "data");
- if (dataPath.exists()) {
- File file = new File(destPathFile, "data/App.json");
- if (file.exists()) {
- return;
- }
- } else {
- try {
- dataPath.mkdirs();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- } else {
+
+ try {
+ Thread.sleep(5000);
+ } catch (Exception ex) {
+
+ }
+ File tmpDestPath = new File(MicroPhotoContext.buildMasterAppDir(context));
+ tmpDestPath = new File(tmpDestPath, "mpdata");
+ if (tmpDestPath.exists()) {
try {
- destPathFile.mkdirs();
+ tmpDestPath.delete();
} catch (Exception ex) {
ex.printStackTrace();
}
}
-
- copyAssetsDir(context, "mpapp", destPath);
+ copyAssetsDir(context, "mpapp/data", tmpDestPath.getAbsolutePath());
MicroPhotoContext.restartMpApp(context, "FIRST Config Init");
}
};
@@ -1279,26 +1290,27 @@ public class MpMasterService extends Service {
Thread th = new Thread(runnable);
th.start();
- return false;
+ return true;
}
public static boolean initMpMasterConfigurations(final Context context) {
String destPath = MicroPhotoContext.buildMasterAppDir(context);
File destPathFile = new File(destPath);
- if (destPathFile.exists()) {
- File file = new File(destPathFile, "data/Master.json");
- if (file.exists()) {
- return false;
- }
+ File dataPath = new File(destPathFile, "data");
+ File file = new File(dataPath, "Master.json");
+ if (file.exists()) {
+ return false;
}
- try {
- destPathFile.mkdirs();
- } catch (Exception ex) {
- ex.printStackTrace();
+ if (!dataPath.exists()) {
+ try {
+ dataPath.mkdirs();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
}
- copyAssetsDir(context, "mpmst", destPath);
+ copyAssetsDir(context, "mpmst", dataPath.getAbsolutePath());
return true;
}