|
|
|
@ -50,17 +50,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
private Messenger mMessenger = null;
|
|
|
|
|
|
|
|
|
|
private long mConfigModificationTime = 0;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
|
|
|
|
|
int activeSubId = SubscriptionManager.getActiveDataSubscriptionId();
|
|
|
|
|
if (activeSubId == -1) {
|
|
|
|
|
MicroPhotoContext.selectSimCard(getApplicationContext(), 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "Start inflate");
|
|
|
|
|
binding = ActivityMainBinding.inflate(getLayoutInflater());
|
|
|
|
|
Log.d(TAG, "Finish inflate");
|
|
|
|
@ -68,80 +63,152 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
// getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
|
|
|
|
|
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
|
try {
|
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
|
|
|
|
|
int activeSubId = SubscriptionManager.getActiveDataSubscriptionId();
|
|
|
|
|
if (activeSubId == -1) {
|
|
|
|
|
MicroPhotoContext.selectSimCard(getApplicationContext(), 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Date date = new Date(BuildConfig.BUILD_TIMESTAMP);
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
|
|
String caption = "MP";
|
|
|
|
|
switch (MicroPhotoService.getCustomAppId()) {
|
|
|
|
|
case 1:
|
|
|
|
|
caption = "RP";
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
caption = "N938";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
caption += " v" + MicroPhotoContext.getVersionName(getApplicationContext()) + " " + sdf.format(date);
|
|
|
|
|
sdf = new SimpleDateFormat("MM-dd HH:mm:ss");
|
|
|
|
|
caption += " / " + sdf.format(new Date());
|
|
|
|
|
actionBar.setTitle(caption);
|
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
|
|
|
|
|
|
Date date = new Date(BuildConfig.BUILD_TIMESTAMP);
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
|
|
String caption = "MP";
|
|
|
|
|
switch (MicroPhotoService.getCustomAppId()) {
|
|
|
|
|
case 1:
|
|
|
|
|
caption = "RP";
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
caption = "N938";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
caption += " v" + MicroPhotoContext.getVersionName(getApplicationContext()) + " " + sdf.format(date);
|
|
|
|
|
sdf = new SimpleDateFormat("MM-dd HH:mm:ss");
|
|
|
|
|
caption += " / " + sdf.format(new Date());
|
|
|
|
|
actionBar.setTitle(caption);
|
|
|
|
|
|
|
|
|
|
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
|
|
|
|
StrictMode.setThreadPolicy(policy);
|
|
|
|
|
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
|
|
|
|
StrictMode.setThreadPolicy(policy);
|
|
|
|
|
|
|
|
|
|
initListener();
|
|
|
|
|
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();
|
|
|
|
|
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)) {
|
|
|
|
|
if (!MicroPhotoContext.hasMpAppConfig(appContext)) {
|
|
|
|
|
|
|
|
|
|
String mstPath = MicroPhotoContext.buildMasterAppDir(appContext);
|
|
|
|
|
File mstPathFile = new File(mstPath);
|
|
|
|
|
File mpdataFile = new File(mstPathFile, "mpdata");
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mpdataFile.exists()) {
|
|
|
|
|
File dataFile = new File(appPathFile, "data");
|
|
|
|
|
if (dataFile.exists()) {
|
|
|
|
|
try {
|
|
|
|
|
dataFile.delete();
|
|
|
|
|
mpdataFile.renameTo(dataFile);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Intent intent = getIntent();
|
|
|
|
|
final int noDelay = intent.getIntExtra("noDelay", 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) {
|
|
|
|
|
Log.i(TAG, "After Reboot");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "MainActivity: reboot=" + rebootFlag + " noDelay=" + noDelay);
|
|
|
|
|
|
|
|
|
|
MicroPhotoContext.AppConfig appConfig = loadConfigInfo();
|
|
|
|
|
|
|
|
|
|
binding.btnStartServ.setEnabled(!MicroPhotoService.isRunning);
|
|
|
|
|
binding.btnStopServ.setEnabled(MicroPhotoService.isRunning);
|
|
|
|
|
|
|
|
|
|
if (MicroPhotoService.isRunning) {
|
|
|
|
|
Intent intent2 = new Intent(MainActivity.this, MicroPhotoService.class);
|
|
|
|
|
try {
|
|
|
|
|
mpdataFile.renameTo(dataFile);
|
|
|
|
|
// stopService(intent2);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Intent intent = getIntent();
|
|
|
|
|
final int noDelay = intent.getIntExtra("noDelay", 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 (MicroPhotoContext.hasMpAppConfig(appContext)) {
|
|
|
|
|
final 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()) {
|
|
|
|
|
Log.i(TAG, "Perform AutoStart");
|
|
|
|
|
binding.btnStartServ.performClick();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
long timeout = 500;
|
|
|
|
|
if (SystemClock.elapsedRealtime() < 180000) {
|
|
|
|
|
// In 3 minutes
|
|
|
|
|
timeout = 10000; // in 10 seconds
|
|
|
|
|
}
|
|
|
|
|
Handler handler = new Handler();
|
|
|
|
|
handler.postDelayed(runnable, timeout);
|
|
|
|
|
Log.i(TAG, "Set AutoStart after " + Long.toString(timeout) + "ms");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if (rebootFlag == 1) {
|
|
|
|
|
Log.i(TAG, "After Reboot");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
File file = MicroPhotoContext.getMpAppConfigFile(getApplicationContext());
|
|
|
|
|
if (file.lastModified() > mConfigModificationTime) {
|
|
|
|
|
loadConfigInfo();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "MainActivity: reboot=" + rebootFlag + " noDelay=" + noDelay);
|
|
|
|
|
protected MicroPhotoContext.AppConfig loadConfigInfo() {
|
|
|
|
|
final MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getMpAppConfig(getApplicationContext());
|
|
|
|
|
mConfigModificationTime = appConfig.modificationTime;
|
|
|
|
|
|
|
|
|
|
final MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getMpAppConfig(appContext);
|
|
|
|
|
if (TextUtils.isEmpty(appConfig.cmdid)) {
|
|
|
|
|
appConfig.cmdid = MicroPhotoService.getSerialNumber();
|
|
|
|
|
binding.cmdid.setText(appConfig.cmdid);
|
|
|
|
@ -159,9 +226,15 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (appConfig.networkProtocol < binding.networkProtocol.getCount()) {
|
|
|
|
|
binding.networkProtocol.setSelection(appConfig.networkProtocol);
|
|
|
|
|
protocolStr = appConfig.networkProtocol + "-";
|
|
|
|
|
for (int idx = 0; idx < binding.networkProtocol.getCount(); idx++) {
|
|
|
|
|
String item = binding.networkProtocol.getItemAtPosition(idx).toString();
|
|
|
|
|
if (item.startsWith(protocolStr)) {
|
|
|
|
|
binding.networkProtocol.setSelection(idx);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (appConfig.encryption < binding.encryptions.getCount()) {
|
|
|
|
|
binding.encryptions.setSelection(appConfig.encryption);
|
|
|
|
|
}
|
|
|
|
@ -172,46 +245,7 @@ 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)) {
|
|
|
|
|
final 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()) {
|
|
|
|
|
Log.i(TAG, "Perform AutoStart");
|
|
|
|
|
binding.btnStartServ.performClick();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
long timeout = 500;
|
|
|
|
|
if (SystemClock.elapsedRealtime() < 180000) {
|
|
|
|
|
// In 3 minutes
|
|
|
|
|
timeout = 10000; // in 10 seconds
|
|
|
|
|
}
|
|
|
|
|
Handler handler = new Handler();
|
|
|
|
|
handler.postDelayed(runnable, timeout);
|
|
|
|
|
Log.i(TAG, "Set AutoStart after " + Long.toString(timeout) + "ms");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
return appConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void initListener() {
|
|
|
|
|