|
|
@ -1,37 +1,54 @@
|
|
|
|
package com.xypower.mpremote;
|
|
|
|
package com.xypower.mpremote;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.content.IntentFilter;
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
|
|
|
import android.graphics.Typeface;
|
|
|
|
|
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
|
|
|
|
import android.net.Network;
|
|
|
|
|
|
|
|
import android.net.NetworkCapabilities;
|
|
|
|
|
|
|
|
import android.net.NetworkInfo;
|
|
|
|
|
|
|
|
import android.net.NetworkRequest;
|
|
|
|
|
|
|
|
import android.net.wifi.ScanResult;
|
|
|
|
|
|
|
|
import android.net.wifi.WifiConfiguration;
|
|
|
|
|
|
|
|
import android.net.wifi.WifiInfo;
|
|
|
|
import android.net.wifi.WifiManager;
|
|
|
|
import android.net.wifi.WifiManager;
|
|
|
|
|
|
|
|
import android.net.wifi.WifiNetworkSpecifier;
|
|
|
|
|
|
|
|
import android.net.wifi.WifiNetworkSuggestion;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.text.Html;
|
|
|
|
import android.os.Parcelable;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.format.Formatter;
|
|
|
|
import android.text.format.Formatter;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.Menu;
|
|
|
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
|
|
|
|
import android.widget.SimpleAdapter;
|
|
|
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
|
|
import com.xypower.common.FileUtils;
|
|
|
|
|
|
|
|
import com.xypower.common.MicroPhotoContext;
|
|
|
|
|
|
|
|
import com.xypower.mpremote.databinding.ActivityMainBinding;
|
|
|
|
import com.xypower.mpremote.databinding.ActivityMainBinding;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import java.net.Socket;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
import dadb.AdbKeyPair;
|
|
|
|
|
|
|
|
import dadb.AdbShellResponse;
|
|
|
|
|
|
|
|
import dadb.Dadb;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
// Used to load the 'mpremote' library on application startup.
|
|
|
|
// Used to load the 'mpremote' library on application startup.
|
|
|
@ -41,38 +58,57 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "ADB";
|
|
|
|
private static final String TAG = "ADB";
|
|
|
|
|
|
|
|
|
|
|
|
private static final boolean DEBUG = false;
|
|
|
|
private static final boolean DEBUG = true;
|
|
|
|
|
|
|
|
|
|
|
|
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_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";
|
|
|
|
public static final int RSSI_LEVELS = 5;
|
|
|
|
private static final String KEY_APP_BCV = "app.bcv";
|
|
|
|
|
|
|
|
private static final String KEY_RO_SERIALNO = "ro.serialno";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String KEY_APP_MP_VERSION = "mpapp.version";
|
|
|
|
private static final String DEFAULT_PRE_SHARED_KEY = SettingsActivity.DEFAULT_PRE_SHARED_KEY;
|
|
|
|
|
|
|
|
|
|
|
|
private static final int ADB_SERVER_PORT = 5555;
|
|
|
|
private static final int REQUEST_CODE_PERMISSIONS = 1025;
|
|
|
|
|
|
|
|
private static final int REQUEST_CODE_SETTINGS = SettingsActivity.REQUEST_CODE_SETTINGS;
|
|
|
|
|
|
|
|
|
|
|
|
private static final String WIFI_IP_PREFIX = "192.168.";
|
|
|
|
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_DEVIDE = "192.168.50.1";
|
|
|
|
private static final String WIFI_IP_DEVICE = "192.168.50.137";
|
|
|
|
private static final String WIFI_IP_DEVICE = "192.168.50.92";
|
|
|
|
|
|
|
|
|
|
|
|
// [vendor.ril.nw.signalstrength.lte.1]: [-85,27]
|
|
|
|
|
|
|
|
//[vendor.ril.nw.signalstrength.lte.2]: [-86,27]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ActivityMainBinding binding;
|
|
|
|
private ActivityMainBinding binding;
|
|
|
|
private Handler mHandler;
|
|
|
|
private Handler mHandler;
|
|
|
|
private Dadb mAdb;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> mProps = new HashMap<>();
|
|
|
|
private List<ScanResult> mScanResults = null;
|
|
|
|
|
|
|
|
private ScanResult mCurrentScanResult;
|
|
|
|
|
|
|
|
private String mPassword = DEFAULT_PRE_SHARED_KEY;
|
|
|
|
|
|
|
|
private WifiAdaper mAdapter;
|
|
|
|
|
|
|
|
private List<Map<String, Object>> mItems = new ArrayList<Map<String, Object>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private MicroPhotoContext.AppConfig mAppConfig;
|
|
|
|
private ConnectivityManager mConnectivityManager;
|
|
|
|
private int mBatteryVoltage = -1;
|
|
|
|
private NetworkConnectChangedReceiver mNetworkConnectChangedReceiver;
|
|
|
|
private int mBatteryChargingVoltage = -1;
|
|
|
|
private ConnectivityManager.NetworkCallback mNetworkCallback;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class WifiAdaper extends SimpleAdapter{
|
|
|
|
|
|
|
|
public WifiAdaper(Context context, List<Map<String, Object>> items, int resource, String[] from, int[] to) {
|
|
|
|
|
|
|
|
super(context, items, resource, from, to);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent){
|
|
|
|
|
|
|
|
convertView = super.getView(position, convertView, parent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TextView textView = (TextView)convertView.findViewById(R.id.id_text);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ScanResult scanResult = mScanResults.get(position);
|
|
|
|
|
|
|
|
// if (scanResult.)
|
|
|
|
|
|
|
|
String text = (String)mItems.get(position).get("text");
|
|
|
|
|
|
|
|
if (text.startsWith("XY") || text.startsWith("xy")) {
|
|
|
|
|
|
|
|
textView.setTextColor(Color.RED);
|
|
|
|
|
|
|
|
textView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
textView.setTextColor(Color.BLACK);
|
|
|
|
|
|
|
|
textView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return convertView;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@ -81,433 +117,446 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
binding = ActivityMainBinding.inflate(getLayoutInflater());
|
|
|
|
binding = ActivityMainBinding.inflate(getLayoutInflater());
|
|
|
|
setContentView(binding.getRoot());
|
|
|
|
setContentView(binding.getRoot());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadSettings();
|
|
|
|
mHandler = new Handler();
|
|
|
|
mHandler = new Handler();
|
|
|
|
|
|
|
|
|
|
|
|
File file = new File(getFilesDir(), ".keypair");
|
|
|
|
mConnectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
if (!file.exists()) {
|
|
|
|
|
|
|
|
file.mkdirs();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final File pubKeyFile = new File(file, "pub.key");
|
|
|
|
|
|
|
|
final File priKeyFile = new File(file, "pri.key");
|
|
|
|
|
|
|
|
if (!priKeyFile.exists() || !pubKeyFile.exists()) {
|
|
|
|
|
|
|
|
AdbKeyPair.generate(priKeyFile, pubKeyFile);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final File fileTmp = new File(getFilesDir(), "tmp");
|
|
|
|
binding.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
if (!fileTmp.exists()) {
|
|
|
|
|
|
|
|
fileTmp.mkdirs();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final AdbKeyPair adbKeyPair = AdbKeyPair.read(priKeyFile, pubKeyFile);
|
|
|
|
|
|
|
|
final Context context = getApplicationContext();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(new Thread(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
|
|
|
|
|
|
|
|
|
|
|
|
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
|
|
|
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
|
|
|
|
|
|
|
|
|
|
|
String ipAddressByWifi = null;
|
|
|
|
if (!wifiManager.isWifiEnabled()) {
|
|
|
|
if (wifiManager != null) {
|
|
|
|
wifiManager.setWifiEnabled(true);
|
|
|
|
ipAddressByWifi = Formatter.formatIpAddress(wifiManager.getDhcpInfo().ipAddress);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ipAddressByWifi.contains(WIFI_IP_PREFIX)) {
|
|
|
|
mCurrentScanResult = mScanResults.get(position);
|
|
|
|
|
|
|
|
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
|
|
|
|
|
|
|
String s1 = normalizeSSID(mCurrentScanResult.SSID);
|
|
|
|
|
|
|
|
String s2 = normalizeSSID(wifiInfo.getSSID());
|
|
|
|
|
|
|
|
if (TextUtils.equals(s1, s2)) {
|
|
|
|
|
|
|
|
openDeviceActivity();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// connectWifi(mCurrentScanResult.SSID, mCurrentScanResult.BSSID, mPassword);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (applyForPermissions()) {
|
|
|
|
|
|
|
|
scanWifi();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String deviceIP = Formatter.formatIpAddress(wifiManager.getDhcpInfo().gateway);
|
|
|
|
@Override
|
|
|
|
if (DEBUG) {
|
|
|
|
protected void onDestroy() {
|
|
|
|
deviceIP = WIFI_IP_DEVICE;
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Socket mSocket = null;
|
|
|
|
if (mConnectivityManager != null && mNetworkCallback != null) {
|
|
|
|
try {
|
|
|
|
mConnectivityManager.bindProcessToNetwork(null);
|
|
|
|
mSocket = new Socket(deviceIP, ADB_SERVER_PORT);
|
|
|
|
mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
|
|
|
|
if (mSocket.isConnected()) {
|
|
|
|
}
|
|
|
|
mSocket.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dadb adb = Dadb.discover(deviceIP, adbKeyPair);
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
|
|
|
|
getMenuInflater().inflate(R.menu.main_activity_actions, menu);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (adb != null) {
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
|
|
|
//当点击不同的menu item 是执行不同的操作
|
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
|
|
|
|
case R.id.action_refresh:
|
|
|
|
|
|
|
|
scanWifi();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R.id.action_settings: {
|
|
|
|
|
|
|
|
Intent intent = new Intent(getApplicationContext(), SettingsActivity.class);
|
|
|
|
|
|
|
|
startActivityForResult(intent, REQUEST_CODE_SETTINGS);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mAdb = adb;
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
|
|
|
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ArrayList<String> requestList = new ArrayList<>();//允许询问列表
|
|
|
|
|
|
|
|
ArrayList<String> banList = new ArrayList<>();//禁止列表
|
|
|
|
|
|
|
|
for(int i = 0; i < permissions.length; i++) {
|
|
|
|
|
|
|
|
if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
|
|
|
Log.i(TAG,"【"+permissions[i]+"】权限授权成功");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//判断是否允许重新申请该权限
|
|
|
|
|
|
|
|
boolean nRet = ActivityCompat.shouldShowRequestPermissionRationale(this,permissions[i]);
|
|
|
|
|
|
|
|
Log.i(TAG,"shouldShowRequestPermissionRationale nRet="+nRet);
|
|
|
|
|
|
|
|
if (nRet) {//允许重新申请
|
|
|
|
|
|
|
|
requestList.add(permissions[i]);
|
|
|
|
|
|
|
|
} else {//禁止申请
|
|
|
|
|
|
|
|
banList.add(permissions[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AdbShellResponse adbShellResponse = null;
|
|
|
|
//优先对禁止列表进行判断
|
|
|
|
try {
|
|
|
|
if (banList.size() > 0) {
|
|
|
|
adbShellResponse = mAdb.shell("getprop");
|
|
|
|
//告知该权限作用,要求手动授予权限
|
|
|
|
} catch (Exception ex) {
|
|
|
|
showFinishedDialog();
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (requestList.size() > 0) {
|
|
|
|
|
|
|
|
//告知权限的作用,并重新申请
|
|
|
|
|
|
|
|
showTipDialog(requestList);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// showToast("权限授权成功");
|
|
|
|
|
|
|
|
scanWifi();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
// showToast("权限申请回调中发生异常");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (adbShellResponse.getExitCode() == 0) {
|
|
|
|
public void showFinishedDialog() {
|
|
|
|
String[] lines = FileUtils.splitLines(adbShellResponse.getAllOutput());
|
|
|
|
AlertDialog dialog = new AlertDialog.Builder(getApplicationContext())
|
|
|
|
for (String line : lines) {
|
|
|
|
.setTitle("警告")
|
|
|
|
int pos = line.indexOf("]: [");
|
|
|
|
.setMessage("请前往设置中打开相关权限,否则功能无法正常运行!")
|
|
|
|
if (pos != -1) {
|
|
|
|
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
|
|
|
String key = line.substring(1, pos);
|
|
|
|
@Override
|
|
|
|
String val = line.substring(pos + 4, line.length() - 1);
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
mProps.put(key, val);
|
|
|
|
// 一般情况下如果用户不授权的话,功能是无法运行的,做退出处理
|
|
|
|
}
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
.create();
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
|
|
|
|
|
|
|
// adb shell pm dump com.xypower.mpremote | grep "versionName"
|
|
|
|
if (requestCode == REQUEST_CODE_SETTINGS) {
|
|
|
|
adbShellResponse = null;
|
|
|
|
loadSettings();
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
adbShellResponse = mAdb.shell("pm dump " + PACKAGE_NAME_MP + " | grep \"versionName\"");
|
|
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (adbShellResponse.getExitCode() == 0) {
|
|
|
|
public void showTipDialog(ArrayList<String> pmList){
|
|
|
|
String[] lines = FileUtils.splitLines(adbShellResponse.getAllOutput());
|
|
|
|
AlertDialog dialog = new AlertDialog.Builder(getApplicationContext())
|
|
|
|
for (String line : lines) {
|
|
|
|
.setTitle("提示")
|
|
|
|
int pos = line.indexOf("versionName=");
|
|
|
|
.setMessage("【"+pmList.toString()+"】权限为应用必要权限,请授权")
|
|
|
|
if (pos != -1) {
|
|
|
|
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
|
|
|
String val = line.substring(pos + 12);
|
|
|
|
@Override
|
|
|
|
mProps.put(KEY_APP_MP_VERSION, val);
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
}
|
|
|
|
String[] sList=pmList.toArray(new String[0]);
|
|
|
|
}
|
|
|
|
//重新申请该权限
|
|
|
|
}
|
|
|
|
ActivityCompat.requestPermissions(MainActivity.this, sList, REQUEST_CODE_PERMISSIONS);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.create();
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 + "\"";
|
|
|
|
|
|
|
|
adbShellResponse = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
adbShellResponse = mAdb.shell(cmd);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (adbShellResponse.getExitCode() == 0) {
|
|
|
|
protected void scanWifi() {
|
|
|
|
File localFilePath = new File(fileTmp, "bv.txt");
|
|
|
|
|
|
|
|
if (localFilePath.exists()) {
|
|
|
|
|
|
|
|
localFilePath.delete();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int idx = 0; idx < 10; idx++) {
|
|
|
|
mScanResults = null;
|
|
|
|
|
|
|
|
|
|
|
|
boolean res = pullFile(mAdb, remoteFilePath, localFilePath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
|
|
|
String content = FileUtils.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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
(new Thread(new Runnable() {
|
|
|
|
Thread.sleep(1000);
|
|
|
|
@Override
|
|
|
|
} catch (Exception ex) {
|
|
|
|
public void run() {
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
|
|
|
mAdb.shell("rm " + remoteFilePath);
|
|
|
|
wifiManager.startScan();
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
mScanResults = wifiManager.getScanResults();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File appConfigFile = new File(fileTmp, "App.json");
|
|
|
|
// mAdapter = new ArrayAdapter<>()
|
|
|
|
boolean res = pullFile(adb, REMOTE_PATH_DATA + "App.json", appConfigFile);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final MicroPhotoContext.AppConfig appConfig = MicroPhotoContext.getMpAppConfig(context, appConfigFile.getAbsolutePath());
|
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
mAppConfig = appConfig;
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
refreshListView();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})).start();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MainActivity.this.mHandler.post(new Runnable() {
|
|
|
|
private void connectWifi(String ssid, String bssid, String pwd) {
|
|
|
|
|
|
|
|
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Android 10
|
|
|
|
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
|
|
|
|
|
|
|
|
WifiNetworkSuggestion suggestion =
|
|
|
|
|
|
|
|
new WifiNetworkSuggestion.Builder()
|
|
|
|
|
|
|
|
.setSsid(ssid)
|
|
|
|
|
|
|
|
.setWpa2Passphrase((pwd))
|
|
|
|
|
|
|
|
.setIsAppInteractionRequired(true)
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<WifiNetworkSuggestion> suggestionsList = new ArrayList<>();
|
|
|
|
|
|
|
|
suggestionsList.add(suggestion);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wifiManager.removeNetworkSuggestions(suggestionsList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int status = wifiManager.addNetworkSuggestions(suggestionsList);
|
|
|
|
|
|
|
|
// step2
|
|
|
|
|
|
|
|
if ((status == WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS) || (status == WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_DUPLICATE)) {
|
|
|
|
|
|
|
|
WifiNetworkSpecifier wifiNetworkSpecifier = new WifiNetworkSpecifier.Builder()
|
|
|
|
|
|
|
|
.setSsid(ssid)
|
|
|
|
|
|
|
|
.setWpa2Passphrase(pwd)
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NetworkRequest request = new NetworkRequest.Builder()
|
|
|
|
|
|
|
|
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
|
|
|
|
|
|
|
|
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
|
|
|
|
|
|
|
.setNetworkSpecifier(wifiNetworkSpecifier)
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mNetworkCallback = new ConnectivityManager.NetworkCallback() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onAvailable(@NonNull Network network) {
|
|
|
|
|
|
|
|
super.onAvailable(network);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NetworkInfo networkInfo = mConnectivityManager.getNetworkInfo(network);
|
|
|
|
|
|
|
|
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
|
|
|
|
|
|
|
String s1 = normalizeSSID(wifiInfo.getSSID());
|
|
|
|
|
|
|
|
String s2 = normalizeSSID(mCurrentScanResult.SSID);
|
|
|
|
|
|
|
|
if (TextUtils.equals(s1, s2)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
MainActivity.this.showAppInfo();
|
|
|
|
// requires android.permission.INTERNET
|
|
|
|
|
|
|
|
mConnectivityManager.bindProcessToNetwork(network);
|
|
|
|
|
|
|
|
openDeviceActivity();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
@Override
|
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
public void onUnavailable() {
|
|
|
|
|
|
|
|
super.onUnavailable();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
Toast.makeText(MainActivity.this, R.string.err_dev_not_found, Toast.LENGTH_LONG).show();
|
|
|
|
mConnectivityManager.bindProcessToNetwork(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
mConnectivityManager.requestNetwork(request, mNetworkCallback);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Dadb dadb = Dadb.create("localhost", 5555, adbKeyPair);
|
|
|
|
|
|
|
|
// Dadb.discover();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})).start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.takePhoto1.setOnClickListener(new View.OnClickListener() {
|
|
|
|
} else {
|
|
|
|
@Override
|
|
|
|
WifiConfiguration wifiConfiguration = new WifiConfiguration();
|
|
|
|
public void onClick(View view) {
|
|
|
|
wifiConfiguration.SSID = "\"" + ssid + "\"";
|
|
|
|
takePhoto(1, 255, true);
|
|
|
|
wifiConfiguration.BSSID = "\"" + bssid + "\"";
|
|
|
|
|
|
|
|
wifiConfiguration.preSharedKey = "\"" + pwd + "\"";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int nerworkId = wifiManager.addNetwork(wifiConfiguration);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
wifiManager.disconnect();
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.takeVideo1.setOnClickListener(new View.OnClickListener() {
|
|
|
|
/*
|
|
|
|
@Override
|
|
|
|
if (mNetworkConnectChangedReceiver != null) {
|
|
|
|
public void onClick(View view) {
|
|
|
|
unregisterReceiver(mNetworkConnectChangedReceiver);
|
|
|
|
takeVideo(1, 255, false);
|
|
|
|
mNetworkConnectChangedReceiver = null;
|
|
|
|
|
|
|
|
registerNetworkConnectChangeReceiver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
wifiManager.enableNetwork(nerworkId, true);
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
wifiManager.reconnect();
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
}
|
|
|
|
getMenuInflater().inflate(R.menu.main_activity_actions, menu);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void refreshListView() {
|
|
|
|
|
|
|
|
mAdapter = new WifiAdaper(this, getData(), R.layout.list_item, new String[] { "img", "text" },
|
|
|
|
|
|
|
|
new int[] { R.id.id_img, R.id.id_text });
|
|
|
|
|
|
|
|
|
|
|
|
protected boolean pullFile(Dadb adb, String remoteFilePath, File localFilePath) {
|
|
|
|
binding.listView.setAdapter(mAdapter);
|
|
|
|
if (localFilePath.exists()) {
|
|
|
|
|
|
|
|
localFilePath.delete();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.i(TAG, "PULL: " + remoteFilePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
boolean res = false;
|
|
|
|
private List<Map<String, Object>> getData() {
|
|
|
|
try {
|
|
|
|
mItems.clear();
|
|
|
|
adb.pull(localFilePath, remoteFilePath);
|
|
|
|
for (ScanResult scanResult : mScanResults) {
|
|
|
|
res = true;
|
|
|
|
Map map = new HashMap<String, Object>();
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
int signalLevel = WifiManager.calculateSignalLevel(scanResult.level, RSSI_LEVELS);
|
|
|
|
|
|
|
|
int drawableId = R.drawable.ic_wifi_signal_0;
|
|
|
|
|
|
|
|
switch (signalLevel) {
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
drawableId = R.drawable.ic_wifi_signal_1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
drawableId = R.drawable.ic_wifi_signal_2;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
drawableId = R.drawable.ic_wifi_signal_3;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
|
|
|
drawableId = R.drawable.ic_wifi_signal_4;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
drawableId = R.drawable.ic_wifi_signal_0;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
map.put("img", drawableId);
|
|
|
|
|
|
|
|
map.put("text", scanResult.SSID);
|
|
|
|
|
|
|
|
mItems.add(map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mItems;
|
|
|
|
return res && localFilePath.exists();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected void takePhotoImpl(final String cmd, final int channel, final int preset, final String localFileName, final String remoteFilePath, final boolean photoOrVideo, long sleepTime) {
|
|
|
|
class NetworkConnectChangedReceiver extends BroadcastReceiver {
|
|
|
|
Thread th = new Thread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
public void run() {
|
|
|
|
String action = intent.getAction();
|
|
|
|
if (sleepTime > 0) {
|
|
|
|
Bundle extras = intent.getExtras();
|
|
|
|
try {
|
|
|
|
|
|
|
|
Thread.sleep(sleepTime);
|
|
|
|
// 这个监听wifi的连接状态即是否连上了一个有效无线路由,当上边广播的状态是WifiManager.WIFI_STATE_DISABLING,和WIFI_STATE_DISABLED的时候,根本不会接到这个广播。
|
|
|
|
} catch (Exception ex) {
|
|
|
|
// 在上边广播接到广播是WifiManager.WIFI_STATE_ENABLED状态的同时也会接到这个广播,当然刚打开wifi肯定还没有连接到有效的无线
|
|
|
|
}
|
|
|
|
if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
|
|
|
|
|
|
|
|
Parcelable parcelableExtra = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
|
|
|
|
|
|
|
WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
|
|
|
|
|
|
|
|
String bssid = intent.getStringExtra(WifiManager.EXTRA_BSSID);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (null == parcelableExtra) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AdbShellResponse adbShellResponse = null;
|
|
|
|
if (mCurrentScanResult != null) {
|
|
|
|
try {
|
|
|
|
return;
|
|
|
|
adbShellResponse = mAdb.shell(cmd);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NetworkInfo networkInfo = (NetworkInfo) parcelableExtra;
|
|
|
|
|
|
|
|
NetworkInfo.State state = networkInfo.getState();
|
|
|
|
|
|
|
|
// Log.e("NetWork Sate Change:"+state+" connectedBssid:" + connectedBssid);
|
|
|
|
|
|
|
|
if(state == NetworkInfo.State.CONNECTED) {
|
|
|
|
|
|
|
|
String ssid = wifiInfo.getSSID();
|
|
|
|
|
|
|
|
String addSSID = mCurrentScanResult.SSID;
|
|
|
|
|
|
|
|
if (!(mCurrentScanResult.SSID.startsWith("\"") && mCurrentScanResult.SSID.endsWith("\""))) {
|
|
|
|
|
|
|
|
addSSID = "\"" + addSSID + "\"";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Log.i(ssid + "***>" + mCurrentScanResult.SSID);
|
|
|
|
|
|
|
|
// Log.i("总共耗时:"+((System.currentTimeMillis()-start)/1000.0));
|
|
|
|
|
|
|
|
if (ssid.equals(addSSID)) {
|
|
|
|
|
|
|
|
|
|
|
|
if (adbShellResponse != null) {
|
|
|
|
unregisterReceiver(mNetworkConnectChangedReceiver);
|
|
|
|
if (adbShellResponse.getExitCode() == 0) {
|
|
|
|
mNetworkConnectChangedReceiver = null;
|
|
|
|
|
|
|
|
|
|
|
|
File localFilePath = new File(getFilesDir(), localFileName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int idx = 0; idx < 10; idx++) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean res = pullFile(mAdb, remoteFilePath, localFilePath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mHandler.post(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
if (photoOrVideo) {
|
|
|
|
|
|
|
|
showPhoto(localFilePath.getAbsolutePath());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
showVideo(localFilePath.getAbsolutePath());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// mAdb.shell("rm " + remoteFilePath);
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
th.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected long takePhoto(int channel, int preset, final boolean photoOrVideo) {
|
|
|
|
|
|
|
|
if (mAdb == null) {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
|
|
|
|
private void registerNetworkConnectChangeReceiver() {
|
|
|
|
Date dt = new Date();
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
int cameraId = channel - 1;
|
|
|
|
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
|
|
|
|
|
|
|
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
|
|
|
final String fileName = "IMG-" + Integer.toString(channel) + "-" + simpleDateFormat.format(dt) + (photoOrVideo ? ".jpg" : ".mp4");
|
|
|
|
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
|
|
|
final String remoteFilePath = REMOTE_PATH_TMP + fileName;
|
|
|
|
filter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
|
|
|
|
|
|
|
|
filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
|
|
|
|
String leftTopOsd = "";
|
|
|
|
mNetworkConnectChangedReceiver = new NetworkConnectChangedReceiver();
|
|
|
|
if (mAppConfig != null) {
|
|
|
|
registerReceiver(mNetworkConnectChangedReceiver, filter);
|
|
|
|
leftTopOsd += mAppConfig.cmdid + " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
|
|
|
|
|
|
|
leftTopOsd += simpleDateFormat2.format(dt) + " ";
|
|
|
|
|
|
|
|
leftTopOsd += "CH:" + Integer.toString(channel) + " ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String usb = (channel == 4) ? "true" : "false";
|
|
|
|
public boolean applyForPermissions() {
|
|
|
|
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 + "\"";
|
|
|
|
|
|
|
|
// adbShellResponse = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
takePhotoImpl(cmd, channel, preset, fileName, remoteFilePath, photoOrVideo, 0);
|
|
|
|
String[] PM_MULTIPLE = {
|
|
|
|
|
|
|
|
Manifest.permission.ACCESS_COARSE_LOCATION,
|
|
|
|
|
|
|
|
Manifest.permission.READ_PHONE_STATE,
|
|
|
|
|
|
|
|
Manifest.permission.CHANGE_NETWORK_STATE,
|
|
|
|
|
|
|
|
Manifest.permission.CHANGE_WIFI_STATE,
|
|
|
|
|
|
|
|
Manifest.permission.ACCESS_FINE_LOCATION
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
ArrayList<String> pmList = new ArrayList<>();
|
|
|
|
|
|
|
|
//获取当前未授权的权限列表
|
|
|
|
|
|
|
|
for(String permission:PM_MULTIPLE) {
|
|
|
|
|
|
|
|
int nRet = ContextCompat.checkSelfPermission(this,permission);
|
|
|
|
|
|
|
|
if(nRet != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
|
|
|
pmList.add(permission);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected long takeVideo(int channel, int preset, final boolean photoOrVideo) {
|
|
|
|
if (pmList.size() > 0) {
|
|
|
|
if (mAdb == null) {
|
|
|
|
// Log.i(TAG,"进行权限申请...");
|
|
|
|
return 0;
|
|
|
|
String[] sList = pmList.toArray(new String[0]);
|
|
|
|
|
|
|
|
ActivityCompat.requestPermissions(this, sList,REQUEST_CODE_PERMISSIONS);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch(Exception e){
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
|
|
|
|
return true;
|
|
|
|
Date dt = new Date();
|
|
|
|
|
|
|
|
int cameraId = channel - 1;
|
|
|
|
|
|
|
|
int duration = 5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String leftTopOsd = "";
|
|
|
|
|
|
|
|
if (mAppConfig != null) {
|
|
|
|
|
|
|
|
leftTopOsd += mAppConfig.cmdid + " ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
|
|
|
|
|
|
|
leftTopOsd += simpleDateFormat2.format(dt) + " ";
|
|
|
|
|
|
|
|
leftTopOsd += "CH:" + Integer.toString(channel) + " ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final String fileName = "IMG-" + Integer.toString(channel) + "-" + simpleDateFormat.format(dt) + (photoOrVideo ? ".jpg" : ".mp4");
|
|
|
|
|
|
|
|
final String remoteFilePath = REMOTE_PATH_TMP + fileName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// int quality = intent.getIntExtra("quality", 0);
|
|
|
|
|
|
|
|
// int width = intent.getIntExtra("width", 1280);
|
|
|
|
|
|
|
|
// int height = intent.getIntExtra("height", 720);
|
|
|
|
|
|
|
|
// int duration = intent.getIntExtra("duration", 15);
|
|
|
|
|
|
|
|
// int orientation = intent.getIntExtra("orientation", 0);
|
|
|
|
|
|
|
|
// long videoId = System.currentTimeMillis() / 1000;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// String leftTopOsd = intent.getStringExtra("leftTopOsd");
|
|
|
|
|
|
|
|
// String rightTopOsd = intent.getStringExtra("rightTopOsd");
|
|
|
|
|
|
|
|
// String rightBottomOsd = intent.getStringExtra("rightBottomOsd");
|
|
|
|
|
|
|
|
// String leftBottomOsd = intent.getStringExtra("leftBottomOsd");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String usb = (channel == 4) ? "true" : "false";
|
|
|
|
|
|
|
|
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 + "\"";
|
|
|
|
|
|
|
|
// adbShellResponse = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, cmd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
takePhotoImpl(cmd, channel, preset, fileName, remoteFilePath, photoOrVideo, duration * 1000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void showPhoto(final String filePath) {
|
|
|
|
protected void loadSettings() {
|
|
|
|
Intent intent = new Intent(MainActivity.this, ImageActivity.class);
|
|
|
|
SharedPreferences preferences = getSharedPreferences("mpremote", MODE_PRIVATE);
|
|
|
|
intent.putExtra("path", filePath);
|
|
|
|
|
|
|
|
// intent.putExtra("info", info);
|
|
|
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void showVideo(final String filePath) {
|
|
|
|
mPassword = preferences.getString("password", DEFAULT_PRE_SHARED_KEY);
|
|
|
|
Intent intent = new Intent(MainActivity.this, VideoActivity.class);
|
|
|
|
|
|
|
|
intent.putExtra("path", filePath);
|
|
|
|
|
|
|
|
// intent.putExtra("info", info);
|
|
|
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void showAppInfo() {
|
|
|
|
protected void openDeviceActivity() {
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
String ipAddressByWifi = null;
|
|
|
|
|
|
|
|
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
|
|
|
// 视频浏览,拍照,设备信息及状态查询(编号,版本,双SIM卡状态,电池及太阳能电压等),可以参考东视
|
|
|
|
if (wifiManager != null) {
|
|
|
|
|
|
|
|
ipAddressByWifi = Formatter.formatIpAddress(wifiManager.getDhcpInfo().ipAddress);
|
|
|
|
Resources resources = getResources();
|
|
|
|
if (!wifiManager.isWifiEnabled()) {
|
|
|
|
// String buildTime = BuildConfig.BUILD_
|
|
|
|
wifiManager.setWifiEnabled(true);
|
|
|
|
// Date date = new Date(BuildConfig.BUILD_TIMESTAMP);
|
|
|
|
}
|
|
|
|
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
|
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
|
|
|
|
|
String title = resources.getString(R.string.app_name);
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(mAppConfig.cmdid)) {
|
|
|
|
|
|
|
|
title += " - " + mAppConfig.cmdid;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
actionBar.setTitle(title);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mProps.containsKey(KEY_RO_SERIALNO)) {
|
|
|
|
|
|
|
|
String val = (String)mProps.get(KEY_RO_SERIALNO);
|
|
|
|
|
|
|
|
appendKeyValue(stringBuilder, "序列号", val);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
appendKeyValue(stringBuilder, "CMDID", mAppConfig.cmdid);
|
|
|
|
if (ipAddressByWifi.contains(WIFI_IP_PREFIX)) {
|
|
|
|
|
|
|
|
|
|
|
|
appendKeyValue(stringBuilder, "主站", mAppConfig.server + ":" + Integer.toString(mAppConfig.port));
|
|
|
|
String deviceIP = Formatter.formatIpAddress(wifiManager.getDhcpInfo().gateway);
|
|
|
|
|
|
|
|
if (DEBUG) {
|
|
|
|
|
|
|
|
deviceIP = WIFI_IP_DEVICE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
appendKeyValue(stringBuilder, "通道数", Integer.toString(mAppConfig.channels));
|
|
|
|
Intent intent = new Intent(MainActivity.this, DeviceActivity.class);
|
|
|
|
|
|
|
|
// intent1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
|
|
|
intent.putExtra("deviceIp", deviceIP);
|
|
|
|
|
|
|
|
intent.putExtra("SSID", mCurrentScanResult.SSID);
|
|
|
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mProps.containsKey(KEY_APP_MP_VERSION)) {
|
|
|
|
|
|
|
|
String val = (String)mProps.get(KEY_APP_MP_VERSION);
|
|
|
|
|
|
|
|
appendKeyValue(stringBuilder, "APP版本", val);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mBatteryVoltage != -1) {
|
|
|
|
private String normalizeSSID(String ssid) {
|
|
|
|
appendKeyValue(stringBuilder, "电池电压", Integer.toString(mBatteryVoltage / 1000) + "." + Integer.toString((mBatteryVoltage % 1000) / 100));
|
|
|
|
if (TextUtils.isEmpty(ssid)) {
|
|
|
|
|
|
|
|
return ssid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mBatteryChargingVoltage != -1) {
|
|
|
|
if (!(ssid.startsWith("\"") && ssid.endsWith("\""))) {
|
|
|
|
appendKeyValue(stringBuilder, "充电电压", Integer.toString(mBatteryChargingVoltage / 1000) + "." + Integer.toString((mBatteryChargingVoltage % 1000) / 100));
|
|
|
|
return "\"" + ssid + "\"";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
binding.deviceInfo.setText(Html.fromHtml(stringBuilder.toString()));
|
|
|
|
return ssid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void appendKeyValue(StringBuilder stringBuilder, String key, String val) {
|
|
|
|
|
|
|
|
stringBuilder.append(key + ":<font color=\"red\"><b>" + val + "</b></font>");
|
|
|
|
|
|
|
|
stringBuilder.append("<br>");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|