|
|
@ -3,6 +3,7 @@ package com.xypower.mpremote;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.content.res.Resources;
|
|
|
@ -61,8 +62,10 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
//[vendor.ril.nw.signalstrength.lte.2]: [-86,27]
|
|
|
|
//[vendor.ril.nw.signalstrength.lte.2]: [-86,27]
|
|
|
|
|
|
|
|
|
|
|
|
private ActivityDeviceBinding binding;
|
|
|
|
private ActivityDeviceBinding binding;
|
|
|
|
|
|
|
|
private ProgressDialog mProgressDialog;
|
|
|
|
private Handler mHandler;
|
|
|
|
private Handler mHandler;
|
|
|
|
private Dadb mAdb;
|
|
|
|
private String mDeviceIp;
|
|
|
|
|
|
|
|
private AdbKeyPair mAdbKeyPair;
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> mProps = new HashMap<>();
|
|
|
|
private Map<String, String> mProps = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
@ -80,6 +83,9 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Intent intent = getIntent();
|
|
|
|
|
|
|
|
mDeviceIp = intent.getStringExtra("deviceIp");
|
|
|
|
|
|
|
|
|
|
|
|
mHandler = new Handler();
|
|
|
|
mHandler = new Handler();
|
|
|
|
|
|
|
|
|
|
|
|
File file = new File(getFilesDir(), ".keypair");
|
|
|
|
File file = new File(getFilesDir(), ".keypair");
|
|
|
@ -98,47 +104,38 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
fileTmp.mkdirs();
|
|
|
|
fileTmp.mkdirs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final AdbKeyPair adbKeyPair = AdbKeyPair.read(priKeyFile, pubKeyFile);
|
|
|
|
mAdbKeyPair = AdbKeyPair.read(priKeyFile, pubKeyFile);
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
|
|
|
|
|
|
|
|
(new Thread(new Runnable() {
|
|
|
|
(new Thread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
|
|
|
|
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String ipAddressByWifi = null;
|
|
|
|
|
|
|
|
if (wifiManager != null) {
|
|
|
|
|
|
|
|
ipAddressByWifi = Formatter.formatIpAddress(wifiManager.getDhcpInfo().ipAddress);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ipAddressByWifi.contains(WIFI_IP_PREFIX)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String deviceIP = Formatter.formatIpAddress(wifiManager.getDhcpInfo().gateway);
|
|
|
|
|
|
|
|
if (DEBUG) {
|
|
|
|
|
|
|
|
deviceIP = WIFI_IP_DEVICE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Socket mSocket = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
mSocket = new Socket(deviceIP, ADB_SERVER_PORT);
|
|
|
|
runImpl();
|
|
|
|
if (mSocket.isConnected()) {
|
|
|
|
|
|
|
|
mSocket.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dadb adb = Dadb.discover(deviceIP, adbKeyPair);
|
|
|
|
mProgressDialog.dismiss();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (adb != null) {
|
|
|
|
private void runImpl() {
|
|
|
|
|
|
|
|
Dadb adb = Dadb.discover(mDeviceIp, mAdbKeyPair);
|
|
|
|
|
|
|
|
|
|
|
|
mAdb = adb;
|
|
|
|
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;
|
|
|
|
AdbShellResponse adbShellResponse = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
adbShellResponse = mAdb.shell("getprop");
|
|
|
|
adbShellResponse = adb.shell("getprop");
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -155,11 +152,10 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// adb shell pm dump com.xypower.mpremote | grep "versionName"
|
|
|
|
// adb shell pm dump com.xypower.mpremote | grep "versionName"
|
|
|
|
adbShellResponse = null;
|
|
|
|
adbShellResponse = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
adbShellResponse = mAdb.shell("pm dump " + PACKAGE_NAME_MP + " | grep \"versionName\"");
|
|
|
|
adbShellResponse = adb.shell("pm dump " + PACKAGE_NAME_MP + " | grep \"versionName\"");
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -179,7 +175,7 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
String cmd = "am start -n " + PACKAGE_NAME_MP + "/" + PACKAGE_NAME_MP + ".BridgeActivity --es action \"query_bv\" --es path \"" + remoteFilePath + "\"";
|
|
|
|
String cmd = "am start -n " + PACKAGE_NAME_MP + "/" + PACKAGE_NAME_MP + ".BridgeActivity --es action \"query_bv\" --es path \"" + remoteFilePath + "\"";
|
|
|
|
adbShellResponse = null;
|
|
|
|
adbShellResponse = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
adbShellResponse = mAdb.shell(cmd);
|
|
|
|
adbShellResponse = adb.shell(cmd);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -192,7 +188,7 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
for (int idx = 0; idx < 10; idx++) {
|
|
|
|
for (int idx = 0; idx < 10; idx++) {
|
|
|
|
|
|
|
|
|
|
|
|
boolean res = pullFile(mAdb, remoteFilePath, localFilePath);
|
|
|
|
boolean res = pullFile(adb, remoteFilePath, localFilePath);
|
|
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
if (res) {
|
|
|
|
String content = FileUtils.readTextFile(localFilePath.getAbsolutePath());
|
|
|
|
String content = FileUtils.readTextFile(localFilePath.getAbsolutePath());
|
|
|
@ -223,7 +219,7 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
mAdb.shell("rm " + remoteFilePath);
|
|
|
|
adb.shell("rm " + remoteFilePath);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -243,23 +239,6 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
Toast.makeText(DeviceActivity.this, R.string.err_dev_not_found, Toast.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Dadb dadb = Dadb.create("localhost", 5555, adbKeyPair);
|
|
|
|
|
|
|
|
// Dadb.discover();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})).start();
|
|
|
|
})).start();
|
|
|
|
|
|
|
|
|
|
|
@ -277,6 +256,7 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mProgressDialog = ProgressDialog.show(context, "", "连接中", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -302,16 +282,22 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
Thread th = new Thread(new Runnable() {
|
|
|
|
Thread th = new Thread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
if (sleepTime > 0) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
Dadb adb = Dadb.discover(mDeviceIp, mAdbKeyPair);
|
|
|
|
Thread.sleep(sleepTime);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
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;
|
|
|
|
AdbShellResponse adbShellResponse = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
adbShellResponse = mAdb.shell(cmd);
|
|
|
|
adbShellResponse = adb.shell(cmd);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -319,11 +305,18 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
if (adbShellResponse != null) {
|
|
|
|
if (adbShellResponse != null) {
|
|
|
|
if (adbShellResponse.getExitCode() == 0) {
|
|
|
|
if (adbShellResponse.getExitCode() == 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sleepTime > 0) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Thread.sleep(sleepTime);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
File localFilePath = new File(getFilesDir(), localFileName);
|
|
|
|
File localFilePath = new File(getFilesDir(), localFileName);
|
|
|
|
|
|
|
|
|
|
|
|
for (int idx = 0; idx < 10; idx++) {
|
|
|
|
for (int idx = 0; idx < 10; idx++) {
|
|
|
|
|
|
|
|
|
|
|
|
boolean res = pullFile(mAdb, remoteFilePath, localFilePath);
|
|
|
|
boolean res = pullFile(adb, remoteFilePath, localFilePath);
|
|
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
if (res) {
|
|
|
|
|
|
|
|
|
|
|
@ -362,9 +355,6 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected long takePhoto(int channel, int preset, final boolean photoOrVideo) {
|
|
|
|
protected long takePhoto(int channel, int preset, final boolean photoOrVideo) {
|
|
|
|
if (mAdb == null) {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
|
|
|
|
Date dt = new Date();
|
|
|
|
Date dt = new Date();
|
|
|
@ -393,9 +383,6 @@ public class DeviceActivity extends AppCompatActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected long takeVideo(int channel, int preset, final boolean photoOrVideo) {
|
|
|
|
protected long takeVideo(int channel, int preset, final boolean photoOrVideo) {
|
|
|
|
if (mAdb == null) {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
|
|
|
|
Date dt = new Date();
|
|
|
|
Date dt = new Date();
|
|
|
|