|
|
|
@ -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,6 +63,14 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
// getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
|
|
|
|
|
|
Date date = new Date(BuildConfig.BUILD_TIMESTAMP);
|
|
|
|
@ -141,36 +144,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "MainActivity: reboot=" + rebootFlag + " noDelay=" + noDelay);
|
|
|
|
|
|
|
|
|
|
final MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getMpAppConfig(appContext);
|
|
|
|
|
if (TextUtils.isEmpty(appConfig.cmdid)) {
|
|
|
|
|
appConfig.cmdid = MicroPhotoService.getSerialNumber();
|
|
|
|
|
binding.cmdid.setText(appConfig.cmdid);
|
|
|
|
|
} else {
|
|
|
|
|
binding.cmdid.setText(appConfig.cmdid);
|
|
|
|
|
}
|
|
|
|
|
binding.server.setText(appConfig.server);
|
|
|
|
|
binding.port.setText(appConfig.port != 0 ? Integer.toString(appConfig.port) : "");
|
|
|
|
|
String protocolStr = appConfig.protocol + "-";
|
|
|
|
|
for (int idx = 0; idx < binding.protocol.getCount(); idx++) {
|
|
|
|
|
String item = binding.protocol.getItemAtPosition(idx).toString();
|
|
|
|
|
if (item.startsWith(protocolStr)) {
|
|
|
|
|
binding.protocol.setSelection(idx);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (appConfig.networkProtocol < binding.networkProtocol.getCount()) {
|
|
|
|
|
binding.networkProtocol.setSelection(appConfig.networkProtocol);
|
|
|
|
|
}
|
|
|
|
|
if (appConfig.encryption < binding.encryptions.getCount()) {
|
|
|
|
|
binding.encryptions.setSelection(appConfig.encryption);
|
|
|
|
|
}
|
|
|
|
|
binding.heartbeat.setText((appConfig.heartbeat > 0) ? Integer.toString(appConfig.heartbeat) : "");
|
|
|
|
|
binding.packetSize.setText((appConfig.packetSize > 0) ? Integer.toString(appConfig.packetSize) : "");
|
|
|
|
|
|
|
|
|
|
if (appConfig.network < binding.network.getCount()) {
|
|
|
|
|
binding.network.setSelection(appConfig.network);
|
|
|
|
|
}
|
|
|
|
|
MicroPhotoContext.AppConfig appConfig = loadConfigInfo();
|
|
|
|
|
|
|
|
|
|
binding.btnStartServ.setEnabled(!MicroPhotoService.isRunning);
|
|
|
|
|
binding.btnStopServ.setEnabled(MicroPhotoService.isRunning);
|
|
|
|
@ -207,6 +181,9 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
handler.postDelayed(runnable, timeout);
|
|
|
|
|
Log.i(TAG, "Set AutoStart after " + Long.toString(timeout) + "ms");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -214,6 +191,63 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
File file = MicroPhotoContext.getMpAppConfigFile(getApplicationContext());
|
|
|
|
|
if (file.lastModified() > mConfigModificationTime) {
|
|
|
|
|
loadConfigInfo();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected MicroPhotoContext.AppConfig loadConfigInfo() {
|
|
|
|
|
final MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getMpAppConfig(getApplicationContext());
|
|
|
|
|
mConfigModificationTime = appConfig.modificationTime;
|
|
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(appConfig.cmdid)) {
|
|
|
|
|
appConfig.cmdid = MicroPhotoService.getSerialNumber();
|
|
|
|
|
binding.cmdid.setText(appConfig.cmdid);
|
|
|
|
|
} else {
|
|
|
|
|
binding.cmdid.setText(appConfig.cmdid);
|
|
|
|
|
}
|
|
|
|
|
binding.server.setText(appConfig.server);
|
|
|
|
|
binding.port.setText(appConfig.port != 0 ? Integer.toString(appConfig.port) : "");
|
|
|
|
|
String protocolStr = appConfig.protocol + "-";
|
|
|
|
|
for (int idx = 0; idx < binding.protocol.getCount(); idx++) {
|
|
|
|
|
String item = binding.protocol.getItemAtPosition(idx).toString();
|
|
|
|
|
if (item.startsWith(protocolStr)) {
|
|
|
|
|
binding.protocol.setSelection(idx);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
binding.heartbeat.setText((appConfig.heartbeat > 0) ? Integer.toString(appConfig.heartbeat) : "");
|
|
|
|
|
binding.packetSize.setText((appConfig.packetSize > 0) ? Integer.toString(appConfig.packetSize) : "");
|
|
|
|
|
|
|
|
|
|
if (appConfig.network < binding.network.getCount()) {
|
|
|
|
|
binding.network.setSelection(appConfig.network);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return appConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void initListener() {
|
|
|
|
|
|
|
|
|
|
this.binding.btnStartServ.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|