|
|
|
@ -20,15 +20,20 @@ import android.view.View;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import com.xypower.common.FileUtils;
|
|
|
|
|
import com.xypower.common.JSONUtils;
|
|
|
|
|
import com.xypower.common.MicroPhotoContext;
|
|
|
|
|
import com.xypower.mpremote.databinding.ActivityDeviceBinding;
|
|
|
|
|
import com.xypower.mpremote.databinding.ActivityMainBinding;
|
|
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.net.Socket;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import dadb.AdbKeyPair;
|
|
|
|
@ -41,15 +46,30 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
private static final boolean DEBUG = false;
|
|
|
|
|
|
|
|
|
|
public static final int RSSI_LEVELS = 5;
|
|
|
|
|
|
|
|
|
|
private static final String PACKAGE_NAME_MP = "com.xypower.mpapp";
|
|
|
|
|
private static final String REMOTE_PATH_ROOT = "/sdcard/" + PACKAGE_NAME_MP + "/";
|
|
|
|
|
private static final String REMOTE_PATH_DATA = REMOTE_PATH_ROOT + "data/";
|
|
|
|
|
private static final String REMOTE_PATH_DATA_CHANNELS = REMOTE_PATH_ROOT + "data/channels/";
|
|
|
|
|
private static final String REMOTE_PATH_PHOTOS = REMOTE_PATH_ROOT + "photos/";
|
|
|
|
|
private static final String REMOTE_PATH_TMP = REMOTE_PATH_ROOT + "tmp/";
|
|
|
|
|
|
|
|
|
|
private static final String KEY_APP_BV = "app.bv";
|
|
|
|
|
private static final String KEY_APP_BCV = "app.bcv";
|
|
|
|
|
private static final String KEY_RO_SERIALNO = "ro.serialno";
|
|
|
|
|
private static final String KEY_RO_MODEMS_MAX_COUNT = "telephony.active_modems.max_count";
|
|
|
|
|
private static final String KEY_RO_SIGNAL_STRNGTH_PREFIX = "vendor.ril.nw.signalstrength.lte.";
|
|
|
|
|
// private static final String KEY_RO_MODEMS_MAX_COUNT = "telephony.active_modems.max_count";
|
|
|
|
|
|
|
|
|
|
// // [ro.bootimage.build.date.utc]: [1716880263]
|
|
|
|
|
// // [ro.build.date.utc]: [1716880263]
|
|
|
|
|
// // [ro.product.model]: [MSRDT-1-WP]
|
|
|
|
|
// // [ro.serialno]: [XYV12WPC202406215]
|
|
|
|
|
// // [telephony.active_modems.max_count]: [2]
|
|
|
|
|
// // [vendor.ril.nw.signalstrength.lte.1]: [-93,-2]
|
|
|
|
|
// //[vendor.ril.nw.signalstrength.lte.2]: [-103,21]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String KEY_APP_MP_VERSION = "mpapp.version";
|
|
|
|
|
|
|
|
|
@ -70,6 +90,8 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
private Map<String, String> mProps = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
private Map<Integer, JSONObject> mChannelCfgs = new HashMap();
|
|
|
|
|
|
|
|
|
|
private MicroPhotoContext.AppConfig mAppConfig;
|
|
|
|
|
private int mBatteryVoltage = -1;
|
|
|
|
|
private int mBatteryChargingVoltage = -1;
|
|
|
|
@ -140,6 +162,50 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean res = false;
|
|
|
|
|
|
|
|
|
|
File appConfigFile = new File(fileTmp, "App.json");
|
|
|
|
|
res = pullFile(adb, REMOTE_PATH_DATA + "App.json", appConfigFile);
|
|
|
|
|
if (res) {
|
|
|
|
|
|
|
|
|
|
final MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getMpAppConfig(context, appConfigFile.getAbsolutePath());
|
|
|
|
|
mAppConfig = appConfig;
|
|
|
|
|
|
|
|
|
|
DeviceActivity.this.mHandler.post(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
DeviceActivity.this.showAppInfo();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final int numberOfChannels = (mAppConfig != null) ? mAppConfig.channels : 0;
|
|
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
updateButtons(numberOfChannels);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mChannelCfgs.clear();
|
|
|
|
|
if (mAppConfig != null && mAppConfig.channels > 0) {
|
|
|
|
|
for (int channel = 1; channel <= mAppConfig.channels; channel++) {
|
|
|
|
|
String remoteFilePath = REMOTE_PATH_DATA_CHANNELS + Integer.toString(channel) + ".json";
|
|
|
|
|
File localFilePath = new File(fileTmp, Integer.toString(channel) + ".json");
|
|
|
|
|
if (localFilePath.exists()) {
|
|
|
|
|
localFilePath.delete();
|
|
|
|
|
}
|
|
|
|
|
res = pullFile(adb, remoteFilePath, localFilePath);
|
|
|
|
|
if (res) {
|
|
|
|
|
JSONObject channelJson = JSONUtils.loadJson(localFilePath.getAbsolutePath());
|
|
|
|
|
if (channelJson != null) {
|
|
|
|
|
mChannelCfgs.put(new Integer(channel), channelJson);
|
|
|
|
|
}
|
|
|
|
|
localFilePath.delete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AdbShellResponse adbShellResponse = null;
|
|
|
|
|
try {
|
|
|
|
|
adbShellResponse = adb.shell("getprop");
|
|
|
|
@ -196,7 +262,7 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
for (int idx = 0; idx < 10; idx++) {
|
|
|
|
|
|
|
|
|
|
boolean res = pullFile(adb, remoteFilePath, localFilePath);
|
|
|
|
|
res = pullFile(adb, remoteFilePath, localFilePath);
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
String content = FileUtils.readTextFile(localFilePath.getAbsolutePath());
|
|
|
|
@ -233,20 +299,7 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File appConfigFile = new File(fileTmp, "App.json");
|
|
|
|
|
boolean res = pullFile(adb, REMOTE_PATH_DATA + "App.json", appConfigFile);
|
|
|
|
|
if (res) {
|
|
|
|
|
|
|
|
|
|
final MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getMpAppConfig(context, appConfigFile.getAbsolutePath());
|
|
|
|
|
mAppConfig = appConfig;
|
|
|
|
|
|
|
|
|
|
DeviceActivity.this.mHandler.post(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
DeviceActivity.this.showAppInfo();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})).start();
|
|
|
|
|
|
|
|
|
@ -385,6 +438,12 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
leftTopOsd += "CH:" + Integer.toString(channel) + " ";
|
|
|
|
|
|
|
|
|
|
String usb = (channel == 4) ? "true" : "false";
|
|
|
|
|
JSONObject channelJson = (JSONObject) mChannelCfgs.get(Integer.valueOf(channel));
|
|
|
|
|
if (channelJson != null) {
|
|
|
|
|
int usbCamera = channelJson.optInt("usbCamera", 0);
|
|
|
|
|
usb = (usbCamera != 0) ? "true" : "false";
|
|
|
|
|
cameraId = channelJson.optInt("cameraId", cameraId);
|
|
|
|
|
}
|
|
|
|
|
final String cmd = "am start -n " + PACKAGE_NAME_MP + "/" + PACKAGE_NAME_MP + ".BridgeActivity --es action \"take_photo\" --es path \""
|
|
|
|
|
+ remoteFilePath + "\" --ez usb " + usb + " --ei cameraId " + Integer.toString(cameraId) + " --ei channel "
|
|
|
|
|
+ Integer.toString(channel) + " --ei preset " + Integer.toString(preset) + " --es leftTopOsd \"" + leftTopOsd + "\"";
|
|
|
|
@ -425,11 +484,23 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
// String rightBottomOsd = intent.getStringExtra("rightBottomOsd");
|
|
|
|
|
// String leftBottomOsd = intent.getStringExtra("leftBottomOsd");
|
|
|
|
|
|
|
|
|
|
int width = 1280;
|
|
|
|
|
int height = 720;
|
|
|
|
|
String usb = (channel == 4) ? "true" : "false";
|
|
|
|
|
JSONObject channelJson = (JSONObject) mChannelCfgs.get(Integer.valueOf(channel));
|
|
|
|
|
if (channelJson != null) {
|
|
|
|
|
int usbCamera = channelJson.optInt("usbCamera", 0);
|
|
|
|
|
usb = (usbCamera != 0) ? "true" : "false";
|
|
|
|
|
cameraId = channelJson.optInt("cameraId", cameraId);
|
|
|
|
|
width = channelJson.optInt("videoCX", width);
|
|
|
|
|
height = channelJson.optInt("videoCY", height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final String cmd = "am start -n " + PACKAGE_NAME_MP + "/" + PACKAGE_NAME_MP + ".BridgeActivity --es action \"recording\" --es path \""
|
|
|
|
|
+ remoteFilePath + "\" --ez usb " + usb + " --ei cameraId " + Integer.toString(cameraId) + " --ei channel "
|
|
|
|
|
+ Integer.toString(channel) + " --ei preset " + Integer.toString(preset) + " --ei duration " + Integer.toString(duration)
|
|
|
|
|
+ " --el videoId " + Long.toString(dt.getTime() / 1000) + " --es leftTopOsd \"" + leftTopOsd + "\"";
|
|
|
|
|
+ " --el videoId " + Long.toString(dt.getTime() / 1000) + " --ei width " + Integer.toString(height) + " --ei height "
|
|
|
|
|
+ Integer.toString(height) + " --es leftTopOsd \"" + leftTopOsd + "\"";
|
|
|
|
|
// adbShellResponse = null;
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, cmd);
|
|
|
|
@ -454,6 +525,25 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateButtons(int numberOfChannels) {
|
|
|
|
|
if (numberOfChannels > 0) {
|
|
|
|
|
binding.takePhoto1.setVisibility(View.VISIBLE);
|
|
|
|
|
binding.takeVideo1.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
if (numberOfChannels > 1) {
|
|
|
|
|
binding.takePhoto2.setVisibility(View.VISIBLE);
|
|
|
|
|
binding.takeVideo2.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
if (numberOfChannels > 2) {
|
|
|
|
|
binding.takePhoto3.setVisibility(View.VISIBLE);
|
|
|
|
|
binding.takeVideo3.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
if (numberOfChannels > 3) {
|
|
|
|
|
binding.takePhoto4.setVisibility(View.VISIBLE);
|
|
|
|
|
binding.takeVideo4.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showAppInfo() {
|
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
|
|
|
|
|
@ -477,6 +567,29 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
appendKeyValue(stringBuilder, "序列号", val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int numberOfSimcard = 0;
|
|
|
|
|
if (mProps.containsKey(KEY_RO_MODEMS_MAX_COUNT)) {
|
|
|
|
|
String val = (String)mProps.get(KEY_RO_MODEMS_MAX_COUNT);
|
|
|
|
|
numberOfSimcard = Integer.parseInt(val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String signalLevel = "";
|
|
|
|
|
for (int idx = 1; idx <= numberOfSimcard; idx++) {
|
|
|
|
|
String key = KEY_RO_SIGNAL_STRNGTH_PREFIX + Integer.toString(idx);
|
|
|
|
|
if (mProps.containsKey(key)) {
|
|
|
|
|
String val = (String)mProps.get(key);
|
|
|
|
|
int pos = val.indexOf(",");
|
|
|
|
|
if (pos != -1) {
|
|
|
|
|
int signalStrength = Integer.parseInt(val.substring(0, pos));
|
|
|
|
|
if (!TextUtils.isEmpty(signalLevel)) {
|
|
|
|
|
signalLevel += "/";
|
|
|
|
|
}
|
|
|
|
|
int ss = WifiManager.calculateSignalLevel(signalStrength, RSSI_LEVELS);
|
|
|
|
|
signalLevel += Integer.toString(ss);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
appendKeyValue(stringBuilder, "CMDID", mAppConfig.cmdid);
|
|
|
|
|
|
|
|
|
|
appendKeyValue(stringBuilder, "主站", mAppConfig.server + ":" + Integer.toString(mAppConfig.port));
|
|
|
|
@ -488,6 +601,8 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
appendKeyValue(stringBuilder, "APP版本", val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
appendKeyValue(stringBuilder, "移动信号", signalLevel);
|
|
|
|
|
|
|
|
|
|
if (mBatteryVoltage != -1) {
|
|
|
|
|
appendKeyValue(stringBuilder, "电池电压", Integer.toString(mBatteryVoltage / 1000) + "." + Integer.toString((mBatteryVoltage % 1000) / 100));
|
|
|
|
|
}
|
|
|
|
|