diff --git a/app/src/main/java/com/xypower/mpremote/DeviceActivity.java b/app/src/main/java/com/xypower/mpremote/DeviceActivity.java index 7058786..414be85 100644 --- a/app/src/main/java/com/xypower/mpremote/DeviceActivity.java +++ b/app/src/main/java/com/xypower/mpremote/DeviceActivity.java @@ -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 mProps = new HashMap<>(); + private Map 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)); } diff --git a/app/src/main/java/com/xypower/mpremote/MainActivity.java b/app/src/main/java/com/xypower/mpremote/MainActivity.java index 6fbc36f..cfdba59 100644 --- a/app/src/main/java/com/xypower/mpremote/MainActivity.java +++ b/app/src/main/java/com/xypower/mpremote/MainActivity.java @@ -69,12 +69,12 @@ public class MainActivity extends AppCompatActivity { private static final String WIFI_IP_PREFIX = "192.168."; // private static final String WIFI_IP_DEVIDE = "192.168.50.1"; - private static final String WIFI_IP_DEVICE = "192.168.50.92"; + private static final String WIFI_IP_DEVICE = "192.168.50.137"; private ActivityMainBinding binding; private Handler mHandler; - private List mScanResults = null; + private List mScanResults = new ArrayList<>(); private ScanResult mCurrentScanResult; private String mPassword = DEFAULT_PRE_SHARED_KEY; private WifiAdaper mAdapter; @@ -267,7 +267,7 @@ public class MainActivity extends AppCompatActivity { protected void scanWifi() { - mScanResults = null; + mScanResults.clear(); (new Thread(new Runnable() { @Override @@ -276,8 +276,21 @@ public class MainActivity extends AppCompatActivity { WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); wifiManager.startScan(); - mScanResults = wifiManager.getScanResults(); + List scanResults = wifiManager.getScanResults(); + Map ssids = new HashMap<>(); + for (ScanResult scanResult : scanResults) { + if (TextUtils.isEmpty(scanResult.SSID)) { + continue; + } + + if (ssids.containsKey(scanResult.SSID)) { + continue; + } + + ssids.put(scanResult.SSID, scanResult.SSID); + mScanResults.add(scanResult); + } // mAdapter = new ArrayAdapter<>() mHandler.post(new Runnable() { @@ -399,6 +412,20 @@ public class MainActivity extends AppCompatActivity { private List> getData() { mItems.clear(); + + WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); + WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + + String ssid = ""; + if (wifiInfo != null) { + ssid = wifiInfo.getSSID(); + if (!TextUtils.isEmpty(ssid)) { + if (ssid.startsWith("\"") && ssid.endsWith("\"")) { + ssid = ssid.substring(1, ssid.length() - 1); + } + } + } + for (ScanResult scanResult : mScanResults) { Map map = new HashMap(); @@ -422,7 +449,8 @@ public class MainActivity extends AppCompatActivity { break; } map.put("img", drawableId); - map.put("text", scanResult.SSID); + // if (scanR) + map.put("text", scanResult.SSID + (TextUtils.equals(ssid, scanResult.SSID) ? " 当前已连接" : "")); mItems.add(map); } return mItems; @@ -463,11 +491,8 @@ public class MainActivity extends AppCompatActivity { unregisterReceiver(mNetworkConnectChangedReceiver); mNetworkConnectChangedReceiver = null; - - } } - } } } diff --git a/app/src/main/res/layout/activity_device.xml b/app/src/main/res/layout/activity_device.xml index 9bf68d4..4173e96 100644 --- a/app/src/main/res/layout/activity_device.xml +++ b/app/src/main/res/layout/activity_device.xml @@ -25,18 +25,88 @@ android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginBottom="8dp" + android:minWidth="72dp" + android:visibility="gone" android:text="通道1" app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toTopOf="@+id/takeVideo1" /> +