修改短信命令
authorsnickersun <scy@incartech.cn>
Fri, 6 Mar 2020 07:33:36 +0000 (15:33 +0800)
committersnickersun <scy@incartech.cn>
Fri, 6 Mar 2020 07:33:36 +0000 (15:33 +0800)
添加对usb的控制,可以任意开启和关闭adb,mtp功能,方便调试以及获取数据。暂时不考虑给客户。
添加充电相关状态检测,以及存储相关日志。方便日志分析。
编译最新版本:V371

app/app.iml
app/release/ICSer_V370_2003051933_release.apk [deleted file]
app/release/ICSer_V371_2003061530_release.apk [new file with mode: 0644]
app/src/main/java/com/enqualcomm/support/CoreService.java
app/src/main/java/com/enqualcomm/support/ICSmsManager.java
app/src/main/java/com/enqualcomm/support/bean/Runtime.java
app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java
app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java
app/src/main/java/com/enqualcomm/support/utils/Util.java
app/version_code.properties

index 8fae7f3..438d013 100644 (file)
     <orderEntry type="library" name="Gradle: io.reactivex:rxandroid:1.1.0@aar" level="project" />\r
     <orderEntry type="module" module-name="dNSCache" />\r
     <orderEntry type="module" module-name="dNSCache" />\r
-    <orderEntry type="module" module-name="dNSCache" />\r
   </component>\r
 </module>
\ 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 (file)
index a6c2512..0000000
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 (file)
index 0000000..abf6b8d
Binary files /dev/null and b/app/release/ICSer_V371_2003061530_release.apk differ
index 4283fcb..1fe53e4 100644 (file)
@@ -551,6 +551,11 @@ public class CoreService extends Service {
         runtime.setBattery(String.format("%03d",batlevel));\r
         ICLogger.i("Battery get from api "+batlevel);\r
 \r
+\r
+        boolean charging = batteryUtil.isPowerConnected(this);\r
+        runtime.setPowerConnected(charging);\r
+        ICLogger.i("Charging  "+charging);\r
+\r
         //api直接获取batterylevel取消注册 receiver, 需要重新注册一下。\r
 \r
         batteryUtil.registerBroadReceiver();\r
index 88ae41e..2da348d 100644 (file)
@@ -558,6 +558,24 @@ public class ICSmsManager {
                 } else {\r
                     sendSMS(phonenumber, "TP cmd format error!");\r
                 }\r
+            }else if (sms.startsWith("#USB#=")) {\r
+                String tmp[] = sms.split("=");\r
+                if (tmp.length == 2) {\r
+                    if(tmp[1].equals("current"))\r
+                    {\r
+                       String conf= Util.getSystemProperties("persist.sys.usb.config");\r
+                        sendSMS(phonenumber, "Current USB config is "+conf+"!");\r
+                    }else if(tmp[1].equals("mtp")||tmp[1].equals("adb")||tmp[1].equals("mtp,adb")||tmp[1].equals("adb,mtp")||tmp[1].equals("none")) {\r
+                        sendSMS(phonenumber, "Set USB config to "+tmp[1]+"!");\r
+                        Util.setSystemProperties("persist.sys.usb.config", "none");\r
+                        Util.setSystemProperties("persist.sys.usb.config", tmp[1]);\r
+\r
+                    }else{\r
+                        sendSMS(phonenumber, "USB cmd format error only support current|adb|mtp|adb,mtp|mtp,adb|none !");\r
+                    }\r
+                } else {\r
+                    sendSMS(phonenumber, "USB cmd format error!");\r
+                }\r
             }else {\r
                 return false;\r
             }\r
index 7110bdb..bfa9c06 100644 (file)
@@ -160,7 +160,14 @@ public class Runtime {
   private boolean shutdown;\r
   \r
 \r
+  private boolean PowerConnected=false;\r
 \r
+  public void setPowerConnected(boolean connected){\r
+      PowerConnected=connected;\r
+  }\r
+  public boolean isPowerConnected(){\r
+      return PowerConnected;\r
+  }\r
  private DnsUtil dnsUtil=null;\r
 \r
  public void initDnsUtil(Context context){\r
index 0edad1b..b8a52be 100644 (file)
@@ -23,7 +23,7 @@ import static com.enqualcomm.support.Constants.ACTION_BATTERY_LOW_MSG;
 public class BatteryUtil {\r
   private BroadcastReceiver batteryChangedReceiver = new BroadcastReceiver() {\r
       public void onReceive(Context param1Context, Intent param1Intent) {\r
-        if ("android.intent.action.BATTERY_CHANGED".equals(param1Intent.getAction())) {\r
+        if (Intent.ACTION_BATTERY_CHANGED.equals(param1Intent.getAction())) {\r
           if (param1Intent.getIntExtra("status", 1) == 2) {\r
             BatteryUtil.this.mRuntime.setBatterychanging(true);\r
             BatteryUtil.this.mRuntime.setBatteryLow(false);\r
@@ -89,15 +89,30 @@ public class BatteryUtil {
             BatteryUtil.this.mRuntime.setHaveBatteryChange(true);\r
           }\r
           BatteryUtil.this.mBuffer.setLength(0);\r
-        }\r
-        if ("android.intent.action.BATTERY_LOW".equals(param1Intent.getAction())) {\r
+        }else if (Intent.ACTION_BATTERY_LOW.equals(param1Intent.getAction())) {\r
           BatteryUtil.this.mRuntime.setBatteryLow(true);\r
           ICLogger.i("lowbattery finish video_end_call");\r
+          if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(mRuntime.getCacheDir(),"Battery","BatteryLow !");\r
 \r
           mRuntime.setAlarmType(false,mRuntime.getBatteryLow(),false,false);\r
           //trigger AP10 报警定位\r
           connection.send(protocolAPIHelper.genStringMessage("AP10",protocolAPIHelper.AP10(mRuntime)));\r
 \r
+        }else if (Intent.ACTION_BATTERY_OKAY.equals(param1Intent.getAction())){\r
+\r
+          ICLogger.i("Battery OKAY !");\r
+          if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(mRuntime.getCacheDir(),"Battery","Battery OKAY !");\r
+\r
+        }else if (Intent.ACTION_POWER_CONNECTED.equals(param1Intent.getAction())){\r
+          ICLogger.i("ACTION_POWER_CONNECTED !");\r
+          mRuntime.setPowerConnected(true);\r
+          if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(mRuntime.getCacheDir(),"Battery","ACTION_POWER_CONNECTED!");\r
+\r
+        }else if (Intent.ACTION_POWER_DISCONNECTED.equals(param1Intent.getAction())){\r
+          ICLogger.i("ACTION_POWER_DISCONNECTED!");\r
+          mRuntime.setPowerConnected(false);\r
+          if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(mRuntime.getCacheDir(),"Battery","ACTION_POWER_DISCONNECTED !");\r
+\r
         }\r
       }\r
     };\r
@@ -114,8 +129,10 @@ public class BatteryUtil {
   public void registerBroadReceiver() {\r
     this.mBuffer = new StringBuffer();\r
     IntentFilter intentFilter = new IntentFilter();\r
-    intentFilter.addAction("android.intent.action.BATTERY_CHANGED");\r
-    intentFilter.addAction("android.intent.action.BATTERY_LOW");\r
+    intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);\r
+    intentFilter.addAction(Intent.ACTION_BATTERY_LOW);\r
+    intentFilter.addAction(Intent.ACTION_POWER_CONNECTED);\r
+    intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);\r
     (this.mRuntime.getContextProxy()).context.registerReceiver(this.batteryChangedReceiver, intentFilter);\r
   }\r
 \r
@@ -129,6 +146,20 @@ public class BatteryUtil {
               intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);\r
     }\r
   }\r
+\r
+\r
+  public boolean isPowerConnected(Context context){\r
+\r
+    IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);\r
+    Intent batteryStatus = context.registerReceiver(null, ifilter);\r
+//你可以读到充电状态,如果在充电,可以读到是usb还是交流电\r
+\r
+// 是否在充电\r
+    int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);\r
+    boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING  ;//||     status == BatteryManager.BATTERY_STATUS_FULL;\r
+\r
+    return isCharging;\r
+  }\r
   public void unregisterBroadReceiver() { (this.mRuntime.getContextProxy()).context.unregisterReceiver(this.batteryChangedReceiver); }\r
 }\r
 \r
index 87dc469..b4333fe 100644 (file)
@@ -198,6 +198,7 @@ public class DeviceInfoUtil {
             .append("\n SocketConnection ").append(KeepAlive.isConnected).append(" , HBcycle ").append(runtime.getHeartBeatCycle())\r
             .append("\n ServerConnected is ").append(runtime.isServerProtocolConnected())\r
             .append(" \n Bat ").append(runtime.getBattery()).append(",").append(runtime.getBatteryVotage())\r
+            .append(" charged ").append(runtime.isPowerConnected())\r
             .append(" StepCount ").append(runtime.getTotalStepCount())\r
             .append( "\n Working Mode ").append(runtime.getLocationInstance().getWorkingMod())\r
             .append(" \n Location Cycle ").append(runtime.getLocationInstance().getLocation_cycle())\r
@@ -219,6 +220,7 @@ public class DeviceInfoUtil {
             .append("[").append(runtime.getSignalStrength()).append("]")\r
             .append("\nHeartbeat[").append(runtime.getSrvIP()).append(":").append(runtime.getPort()).append(",").append(runtime.isServerProtocolConnected()).append(",").append(runtime.getHeartBeatCycle())\r
             .append("]\nBat").append(runtime.getBattery()).append(",").append(runtime.getBatteryVotage())\r
+            .append(" charged ").append(runtime.isPowerConnected())\r
             .append(",Step").append(runtime.getTotalStepCount())\r
             .append( "\nLocation[M").append(runtime.getLocationInstance().getWorkingMod())\r
             .append(",C").append(runtime.getLocationInstance().getLocation_cycle())\r
index d565e7d..0e165ea 100644 (file)
@@ -225,7 +225,24 @@ public class Util {
     }\r
     return str;\r
   }\r
+  static public void setSystemProperties(String key, String defaultValue) {\r
 \r
+    String value = defaultValue;\r
+\r
+    try {\r
+\r
+      Class<?> c = Class.forName("android.os.SystemProperties");\r
+\r
+      Method get = c.getMethod("set", String.class, String.class );\r
+\r
+      get.invoke(c, key, value );\r
+\r
+    } catch (Exception e) {\r
+\r
+      e.printStackTrace();\r
+\r
+    }\r
+  }\r
   public static WifiConfiguration GetconfigWifiInfo(Context context, String ssid, String pwd, String encryptType) {\r
     WifiConfiguration wifiConfiguration=null;\r
     StringBuilder stringBuilder;\r
index 05c27cb..29f92bf 100644 (file)
@@ -1,2 +1,2 @@
-#Thu Mar 05 19:33:06 CST 2020\r
-VERSION_CODE=370\r
+#Fri Mar 06 15:30:32 CST 2020\r
+VERSION_CODE=371\r