From: snickersun Date: Fri, 6 Mar 2020 07:33:36 +0000 (+0800) Subject: 修改短信命令 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=949de1dd3f03c66a2bf536d76b79a9e84e9759a0;p=protocol_srv.git 修改短信命令 添加对usb的控制,可以任意开启和关闭adb,mtp功能,方便调试以及获取数据。暂时不考虑给客户。 添加充电相关状态检测,以及存储相关日志。方便日志分析。 编译最新版本:V371 --- diff --git a/app/app.iml b/app/app.iml index 8fae7f39..438d0136 100644 --- a/app/app.iml +++ b/app/app.iml @@ -125,6 +125,5 @@ - \ No newline at end of file diff --git a/app/release/ICSer_V370_2003051933_release.apk b/app/release/ICSer_V370_2003051933_release.apk deleted file mode 100644 index a6c2512e..00000000 Binary files a/app/release/ICSer_V370_2003051933_release.apk and /dev/null differ diff --git a/app/release/ICSer_V371_2003061530_release.apk b/app/release/ICSer_V371_2003061530_release.apk new file mode 100644 index 00000000..abf6b8da Binary files /dev/null and b/app/release/ICSer_V371_2003061530_release.apk differ diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 4283fcbc..1fe53e4e 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -551,6 +551,11 @@ public class CoreService extends Service { runtime.setBattery(String.format("%03d",batlevel)); ICLogger.i("Battery get from api "+batlevel); + + boolean charging = batteryUtil.isPowerConnected(this); + runtime.setPowerConnected(charging); + ICLogger.i("Charging "+charging); + //api直接获取batterylevel取消注册 receiver, 需要重新注册一下。 batteryUtil.registerBroadReceiver(); diff --git a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java index 88ae41e7..2da348d7 100644 --- a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java +++ b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java @@ -558,6 +558,24 @@ public class ICSmsManager { } else { sendSMS(phonenumber, "TP cmd format error!"); } + }else if (sms.startsWith("#USB#=")) { + String tmp[] = sms.split("="); + if (tmp.length == 2) { + if(tmp[1].equals("current")) + { + String conf= Util.getSystemProperties("persist.sys.usb.config"); + sendSMS(phonenumber, "Current USB config is "+conf+"!"); + }else if(tmp[1].equals("mtp")||tmp[1].equals("adb")||tmp[1].equals("mtp,adb")||tmp[1].equals("adb,mtp")||tmp[1].equals("none")) { + sendSMS(phonenumber, "Set USB config to "+tmp[1]+"!"); + Util.setSystemProperties("persist.sys.usb.config", "none"); + Util.setSystemProperties("persist.sys.usb.config", tmp[1]); + + }else{ + sendSMS(phonenumber, "USB cmd format error only support current|adb|mtp|adb,mtp|mtp,adb|none !"); + } + } else { + sendSMS(phonenumber, "USB cmd format error!"); + } }else { return false; } diff --git a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java index 7110bdbd..bfa9c063 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java +++ b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java @@ -160,7 +160,14 @@ public class Runtime { private boolean shutdown; + private boolean PowerConnected=false; + public void setPowerConnected(boolean connected){ + PowerConnected=connected; + } + public boolean isPowerConnected(){ + return PowerConnected; + } private DnsUtil dnsUtil=null; public void initDnsUtil(Context context){ diff --git a/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java b/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java index 0edad1b3..b8a52be9 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java @@ -23,7 +23,7 @@ import static com.enqualcomm.support.Constants.ACTION_BATTERY_LOW_MSG; public class BatteryUtil { private BroadcastReceiver batteryChangedReceiver = new BroadcastReceiver() { public void onReceive(Context param1Context, Intent param1Intent) { - if ("android.intent.action.BATTERY_CHANGED".equals(param1Intent.getAction())) { + if (Intent.ACTION_BATTERY_CHANGED.equals(param1Intent.getAction())) { if (param1Intent.getIntExtra("status", 1) == 2) { BatteryUtil.this.mRuntime.setBatterychanging(true); BatteryUtil.this.mRuntime.setBatteryLow(false); @@ -89,15 +89,30 @@ public class BatteryUtil { BatteryUtil.this.mRuntime.setHaveBatteryChange(true); } BatteryUtil.this.mBuffer.setLength(0); - } - if ("android.intent.action.BATTERY_LOW".equals(param1Intent.getAction())) { + }else if (Intent.ACTION_BATTERY_LOW.equals(param1Intent.getAction())) { BatteryUtil.this.mRuntime.setBatteryLow(true); ICLogger.i("lowbattery finish video_end_call"); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(mRuntime.getCacheDir(),"Battery","BatteryLow !"); mRuntime.setAlarmType(false,mRuntime.getBatteryLow(),false,false); //trigger AP10 报警定位 connection.send(protocolAPIHelper.genStringMessage("AP10",protocolAPIHelper.AP10(mRuntime))); + }else if (Intent.ACTION_BATTERY_OKAY.equals(param1Intent.getAction())){ + + ICLogger.i("Battery OKAY !"); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(mRuntime.getCacheDir(),"Battery","Battery OKAY !"); + + }else if (Intent.ACTION_POWER_CONNECTED.equals(param1Intent.getAction())){ + ICLogger.i("ACTION_POWER_CONNECTED !"); + mRuntime.setPowerConnected(true); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(mRuntime.getCacheDir(),"Battery","ACTION_POWER_CONNECTED!"); + + }else if (Intent.ACTION_POWER_DISCONNECTED.equals(param1Intent.getAction())){ + ICLogger.i("ACTION_POWER_DISCONNECTED!"); + mRuntime.setPowerConnected(false); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(mRuntime.getCacheDir(),"Battery","ACTION_POWER_DISCONNECTED !"); + } } }; @@ -114,8 +129,10 @@ public class BatteryUtil { public void registerBroadReceiver() { this.mBuffer = new StringBuffer(); IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction("android.intent.action.BATTERY_CHANGED"); - intentFilter.addAction("android.intent.action.BATTERY_LOW"); + intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); + intentFilter.addAction(Intent.ACTION_BATTERY_LOW); + intentFilter.addAction(Intent.ACTION_POWER_CONNECTED); + intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED); (this.mRuntime.getContextProxy()).context.registerReceiver(this.batteryChangedReceiver, intentFilter); } @@ -129,6 +146,20 @@ public class BatteryUtil { intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); } } + + + public boolean isPowerConnected(Context context){ + + IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); + Intent batteryStatus = context.registerReceiver(null, ifilter); +//你可以读到充电状态,如果在充电,可以读到是usb还是交流电 + +// 是否在充电 + int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); + boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ;//|| status == BatteryManager.BATTERY_STATUS_FULL; + + return isCharging; + } public void unregisterBroadReceiver() { (this.mRuntime.getContextProxy()).context.unregisterReceiver(this.batteryChangedReceiver); } } diff --git a/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java b/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java index 87dc469c..b4333fea 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java @@ -198,6 +198,7 @@ public class DeviceInfoUtil { .append("\n SocketConnection ").append(KeepAlive.isConnected).append(" , HBcycle ").append(runtime.getHeartBeatCycle()) .append("\n ServerConnected is ").append(runtime.isServerProtocolConnected()) .append(" \n Bat ").append(runtime.getBattery()).append(",").append(runtime.getBatteryVotage()) + .append(" charged ").append(runtime.isPowerConnected()) .append(" StepCount ").append(runtime.getTotalStepCount()) .append( "\n Working Mode ").append(runtime.getLocationInstance().getWorkingMod()) .append(" \n Location Cycle ").append(runtime.getLocationInstance().getLocation_cycle()) @@ -219,6 +220,7 @@ public class DeviceInfoUtil { .append("[").append(runtime.getSignalStrength()).append("]") .append("\nHeartbeat[").append(runtime.getSrvIP()).append(":").append(runtime.getPort()).append(",").append(runtime.isServerProtocolConnected()).append(",").append(runtime.getHeartBeatCycle()) .append("]\nBat").append(runtime.getBattery()).append(",").append(runtime.getBatteryVotage()) + .append(" charged ").append(runtime.isPowerConnected()) .append(",Step").append(runtime.getTotalStepCount()) .append( "\nLocation[M").append(runtime.getLocationInstance().getWorkingMod()) .append(",C").append(runtime.getLocationInstance().getLocation_cycle()) diff --git a/app/src/main/java/com/enqualcomm/support/utils/Util.java b/app/src/main/java/com/enqualcomm/support/utils/Util.java index d565e7da..0e165ea2 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/Util.java +++ b/app/src/main/java/com/enqualcomm/support/utils/Util.java @@ -225,7 +225,24 @@ public class Util { } return str; } + static public void setSystemProperties(String key, String defaultValue) { + String value = defaultValue; + + try { + + Class c = Class.forName("android.os.SystemProperties"); + + Method get = c.getMethod("set", String.class, String.class ); + + get.invoke(c, key, value ); + + } catch (Exception e) { + + e.printStackTrace(); + + } + } public static WifiConfiguration GetconfigWifiInfo(Context context, String ssid, String pwd, String encryptType) { WifiConfiguration wifiConfiguration=null; StringBuilder stringBuilder; diff --git a/app/version_code.properties b/app/version_code.properties index 05c27cbf..29f92bfa 100644 --- a/app/version_code.properties +++ b/app/version_code.properties @@ -1,2 +1,2 @@ -#Thu Mar 05 19:33:06 CST 2020 -VERSION_CODE=370 +#Fri Mar 06 15:30:32 CST 2020 +VERSION_CODE=371