|
|
|
@ -3,18 +3,16 @@ package com.xypower.mpremote;
|
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.res.Resources;
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
|
import android.net.wifi.WifiManager;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.telephony.SignalStrength;
|
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
|
import android.telephony.ims.ImsMmTelManager;
|
|
|
|
|
import android.text.Html;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.text.format.Formatter;
|
|
|
|
@ -30,6 +28,7 @@ import com.xypower.common.JSONUtils;
|
|
|
|
|
import com.xypower.common.MicroPhotoContext;
|
|
|
|
|
import com.xypower.mpremote.databinding.ActivityDeviceBinding;
|
|
|
|
|
import com.xypower.mpremote.databinding.ActivityMainBinding;
|
|
|
|
|
import com.xypower.mpremote.utils.AdbUtils;
|
|
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
@ -87,6 +86,11 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
private static final String KEY_APP_MP_VERSION = "mpapp.version";
|
|
|
|
|
|
|
|
|
|
private static final String KEY_PREFIX_GLOBAL_SETTING = "settings.global.";
|
|
|
|
|
|
|
|
|
|
private static final String KEY_IMEI = KEY_PREFIX_GLOBAL_SETTING + "dev_imei";
|
|
|
|
|
private static final String KEY_IMEI2 = KEY_PREFIX_GLOBAL_SETTING + "dev_imei2";
|
|
|
|
|
|
|
|
|
|
private static final int ADB_SERVER_PORT = 5555;
|
|
|
|
|
|
|
|
|
|
// [vendor.ril.nw.signalstrength.lte.1]: [-85,27]
|
|
|
|
@ -192,8 +196,12 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void runImpl() {
|
|
|
|
|
Dadb adb = Dadb.discover(mDeviceIp, mAdbKeyPair);
|
|
|
|
|
Log.d(TAG, "Adb discovering " + mDeviceIp);
|
|
|
|
|
// Dadb adb = Dadb.discover(mDeviceIp, mAdbKeyPair);
|
|
|
|
|
|
|
|
|
|
Dadb adb = Dadb.create(mDeviceIp, AdbUtils.DEFAULT_ADB_PORT, mAdbKeyPair);
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "Adb Connected");
|
|
|
|
|
if (adb == null) {
|
|
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
@ -222,6 +230,8 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "App.json Pulled");
|
|
|
|
|
|
|
|
|
|
final int numberOfChannels = (mAppConfig != null) ? mAppConfig.channels : 0;
|
|
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
@ -249,7 +259,30 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "Channel config Pulled");
|
|
|
|
|
|
|
|
|
|
AdbShellResponse adbShellResponse = null;
|
|
|
|
|
try {
|
|
|
|
|
adbShellResponse = adb.shell("settings list global");
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (adbShellResponse.getExitCode() == 0) {
|
|
|
|
|
String[] lines = FilesUtils.splitLines(adbShellResponse.getAllOutput());
|
|
|
|
|
for (String line : lines) {
|
|
|
|
|
int pos = line.indexOf("=");
|
|
|
|
|
if (pos != -1) {
|
|
|
|
|
String key = line.substring(0, pos);
|
|
|
|
|
String val = line.substring(pos + 1);
|
|
|
|
|
mProps.put(KEY_PREFIX_GLOBAL_SETTING + key, val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "Global settings Pulled");
|
|
|
|
|
|
|
|
|
|
adbShellResponse = null;
|
|
|
|
|
try {
|
|
|
|
|
adbShellResponse = adb.shell("getprop");
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
@ -268,6 +301,8 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "getprop Finished");
|
|
|
|
|
|
|
|
|
|
if (mProps.containsKey(KEY_RO_SERIALNO)) {
|
|
|
|
|
mSerialNo = (String)mProps.get(KEY_RO_SERIALNO);
|
|
|
|
|
}
|
|
|
|
@ -291,8 +326,9 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String remoteFilePath = REMOTE_PATH_TMP + "bv.txt";
|
|
|
|
|
String cmd = "am start -n " + PACKAGE_NAME_MP + "/" + PACKAGE_NAME_MP + ".BridgeActivity --es action \"query_bv\" --es path \"" + remoteFilePath + "\"";
|
|
|
|
|
Log.d(TAG, "Dump App version Finished");
|
|
|
|
|
|
|
|
|
|
String cmd = "content query --uri content://com.xypower.mpapp.provider/queryBatVol";
|
|
|
|
|
adbShellResponse = null;
|
|
|
|
|
try {
|
|
|
|
|
adbShellResponse = adb.shell(cmd);
|
|
|
|
@ -301,49 +337,22 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (adbShellResponse.getExitCode() == 0) {
|
|
|
|
|
File localFilePath = new File(fileTmp, "bv.txt");
|
|
|
|
|
if (localFilePath.exists()) {
|
|
|
|
|
localFilePath.delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int idx = 0; idx < 10; idx++) {
|
|
|
|
|
|
|
|
|
|
res = pullFile(adb, remoteFilePath, localFilePath);
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
String content = FilesUtils.readTextFile(localFilePath.getAbsolutePath());
|
|
|
|
|
if (!TextUtils.isEmpty(content)) {
|
|
|
|
|
int pos = content.indexOf(" ");
|
|
|
|
|
if (pos != -1) {
|
|
|
|
|
String bv = content.substring(0, pos);
|
|
|
|
|
String bcv = content.substring(pos + 1);
|
|
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(bv)) {
|
|
|
|
|
mBatteryVoltage = Integer.parseInt(bv);
|
|
|
|
|
}
|
|
|
|
|
if (!TextUtils.isEmpty(bcv)) {
|
|
|
|
|
mBatteryChargingVoltage = Integer.parseInt(bcv);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
localFilePath.delete();
|
|
|
|
|
break;
|
|
|
|
|
Cursor cursor = AdbUtils.parseContentResponse(adbShellResponse.getAllOutput());
|
|
|
|
|
if (cursor != null && cursor.getCount() > 0) {
|
|
|
|
|
cursor.moveToFirst();
|
|
|
|
|
@SuppressLint("Range") String bv = cursor.getString(cursor.getColumnIndex("bv"));
|
|
|
|
|
@SuppressLint("Range") String bcv = cursor.getString(cursor.getColumnIndex("bcv"));
|
|
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(bv)) {
|
|
|
|
|
mBatteryVoltage = Integer.parseInt(bv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
if (!TextUtils.isEmpty(bcv)) {
|
|
|
|
|
mBatteryChargingVoltage = Integer.parseInt(bcv);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
adb.shell("rm " + remoteFilePath);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "queryBatVol Finished");
|
|
|
|
|
}
|
|
|
|
|
})).start();
|
|
|
|
|
}
|
|
|
|
@ -371,76 +380,91 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
|
|
Dadb adb = Dadb.discover(mDeviceIp, mAdbKeyPair);
|
|
|
|
|
Dadb adb = null;
|
|
|
|
|
|
|
|
|
|
if (adb == null) {
|
|
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
Toast.makeText(DeviceActivity.this, R.string.err_dev_failed_to_connect, Toast.LENGTH_LONG).show();
|
|
|
|
|
}
|
|
|
|
|
}, 100);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AdbShellResponse adbShellResponse = null;
|
|
|
|
|
try {
|
|
|
|
|
adbShellResponse = adb.shell(cmd);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
Log.i(TAG, "Start connecting " + mDeviceIp);
|
|
|
|
|
adb = Dadb.create(mDeviceIp, AdbUtils.DEFAULT_ADB_PORT, mAdbKeyPair);
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "Finish connecting " + mDeviceIp);
|
|
|
|
|
if (adb == null) {
|
|
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
Toast.makeText(DeviceActivity.this, R.string.err_dev_failed_to_connect, Toast.LENGTH_LONG).show();
|
|
|
|
|
}
|
|
|
|
|
}, 100);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (adbShellResponse != null) {
|
|
|
|
|
if (adbShellResponse.getExitCode() == 0) {
|
|
|
|
|
AdbShellResponse adbShellResponse = null;
|
|
|
|
|
try {
|
|
|
|
|
adbShellResponse = adb.shell(cmd);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sleepTime > 0) {
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(sleepTime);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
if (adbShellResponse != null) {
|
|
|
|
|
if (adbShellResponse.getExitCode() == 0) {
|
|
|
|
|
|
|
|
|
|
if (sleepTime > 0) {
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(sleepTime);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
File localDevicePath = new File(getFilesDir(), "Photos" + File.separator + mSerialNo);
|
|
|
|
|
if (!localDevicePath.exists()) {
|
|
|
|
|
localDevicePath.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
File localDevicePath = new File(getFilesDir(), "Photos" + File.separator + mSerialNo);
|
|
|
|
|
if (!localDevicePath.exists()) {
|
|
|
|
|
localDevicePath.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final File localFilePath = new File(localDevicePath, localFileName);
|
|
|
|
|
final File localFilePath = new File(localDevicePath, localFileName);
|
|
|
|
|
|
|
|
|
|
for (int idx = 0; idx < 10; idx++) {
|
|
|
|
|
for (int idx = 0; idx < 10; idx++) {
|
|
|
|
|
|
|
|
|
|
boolean res = pullFile(adb, remoteFilePath, localFilePath);
|
|
|
|
|
boolean res = pullFile(adb, remoteFilePath, localFilePath);
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
if (res) {
|
|
|
|
|
|
|
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
if (photoOrVideo) {
|
|
|
|
|
showPhoto(localFilePath.getAbsolutePath());
|
|
|
|
|
} else {
|
|
|
|
|
showVideo(localFilePath.getAbsolutePath());
|
|
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
if (photoOrVideo) {
|
|
|
|
|
showPhoto(localFilePath.getAbsolutePath());
|
|
|
|
|
} else {
|
|
|
|
|
showVideo(localFilePath.getAbsolutePath());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
// mAdb.shell("rm " + remoteFilePath);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// mAdb.shell("rm " + remoteFilePath);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
if (adb != null) {
|
|
|
|
|
adb.close();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -678,6 +702,16 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
appendKeyValue(stringBuilder, "ICCID", iccid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mProps.containsKey(KEY_IMEI)) {
|
|
|
|
|
String val = (String)mProps.get(KEY_IMEI);
|
|
|
|
|
appendKeyValue(stringBuilder, "IMEI1", val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mProps.containsKey(KEY_IMEI2)) {
|
|
|
|
|
String val = (String)mProps.get(KEY_IMEI2);
|
|
|
|
|
appendKeyValue(stringBuilder, "IMEI2", val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mBatteryVoltage != -1) {
|
|
|
|
|
appendKeyValue(stringBuilder, "电池电压", Integer.toString(mBatteryVoltage / 1000) + "." + Integer.toString((mBatteryVoltage % 1000) / 100));
|
|
|
|
|
}
|
|
|
|
|