refactor the codes.
authorTrillGates <williamtrillgates@gmail.com>
Fri, 27 Aug 2021 06:21:26 +0000 (14:21 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Fri, 27 Aug 2021 06:21:26 +0000 (14:21 +0800)
app/src/main/AndroidManifest.xml
app/src/main/java/com/ic/protocolSrv/Config.java
app/src/main/java/com/ic/protocolSrv/utils/DBHelper.java
app/src/main/java/com/ic/protocols/protocol_fzd.java
app/src/main/java/com/ic/protocols/protocol_s123.java
app/src/main/java/com/ic/view/webmsgresponse/WebMessageAdapter.java

index 8e6d619..6d927d1 100644 (file)
@@ -82,7 +82,7 @@
     <uses-permission android:name="android.permission.READ_LOGS"></uses-permission>
 
     <uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
-    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
 
     <uses-feature android:name="android.hardware.camera" />
     <uses-feature android:name="android.hardware.camera.autofocus" />
             android:name=".provider.ICContentProvider"
             android:authorities="com.ic.protocolSrv"
             android:exported="true" />
-        <!--        <receiver-->
-        <!--            android:name=".ICSmsManager"-->
-        <!--            android:exported="true">-->
-        <!--            <intent-filter>-->
-        <!--                <action android:name="android.provider.Telephony.SMS_RECEIVED" />-->
-        <!--                <action android:name="com.ic.protocolSrv.SMSCMD" />-->
-        <!--                <action android:name="com.ic.action.internaltest" />-->
-        <!--            </intent-filter>-->
-        <!--        </receiver>-->
+
         <receiver
             android:name=".BootCompleteReceiver"
             android:exported="true">
             android:name=".provider.ICNotificationProvider"
             android:authorities="com.ic.notification"
             android:exported="true" />
-        
+
         <provider
             android:name=".provider.ShootTextProvider"
             android:authorities="com.ic.shoot"
             android:exported="true" />
 
     </application>
-
 </manifest>
\ No newline at end of file
index a9796da..428c650 100644 (file)
@@ -30,6 +30,15 @@ import static com.ic.protocolSrv.bean.ICLocation.NORMAL_MOD;
 import static com.ic.protocolSrv.bean.Runtime.AlarmType.ALARM_LOWBATTERY;
 import static com.ic.protocolSrv.utils.Util.getSystemProperties;
 
+/**
+ * 优先级,
+ * 0.服务下发的:ip,端口,apn...
+ * 1.json配置
+ * 2.Android.mk配置
+ * 3.Config.java默认配置
+ *
+ * 数字越小,优先级越高
+ */
 public class Config {
     public static final boolean LOG_TOFILE = true;
     public static int sw_release_no = -1;
@@ -91,7 +100,6 @@ public class Config {
     //配置脱腕报警是否需要弹出剪断提示 默认开启
     public static boolean needBroadcastCutoffAlarm = true;
 
-
     //add by TrillGates=================start
     //各种阀值:血压,血氧,心率,体温
     //以下值的赋值时机:
@@ -783,13 +791,16 @@ public class Config {
     }
 
 
+    /**
+     * @param key
+     * @param value
+     */
     public static void setConfigValue(String key, String value) {
         ICLogger.d("( " + key + " , " + value + ")");
-
         try {
             if (key.trim().equals("AlarmConfig")) {
-                String[] alarmlist = value.split(",");
-                for (String al : alarmlist) {
+                String[] alarmList = value.split(",");
+                for (String al : alarmList) {
                     try {
                         AlarmConfiglist.put(Runtime.AlarmType.valueOf(al).ordinal(), Boolean.valueOf(value));
                     } catch (Exception e) {
@@ -803,15 +814,7 @@ public class Config {
             } else if (key.trim().equals("BLEScanProtocol")) {
                 BLEScanProtocol = Integer.valueOf(value);
             } else if (key.trim().equals("UsePolingCheckWeared")) {
-
-/*
-*
-    public static String DefaultHttpLogServerUrl = "http://icfota.snicker.com.cn:8089/UploadFile.jsp";
-
-    public static String DefaultWiFiSSID = "icwifi20210417";
-    public static String DefaultWiFiPWD = "87654321";
-    public static String DefaultWiFiEncryptType = "psk";
-* */
+                //TODO:配置
             }
         } catch (Exception e) {
             ICLogger.e(e.getMessage(), e);
@@ -847,7 +850,8 @@ public class Config {
         disableWiFiScan = Util.getSystemProperties("persist.sys.disableWiFiLocation", "false").equals("true");
         disableWristTemp = Util.getSystemProperties("persist.sys.disableWristTemp", "false").equals("true");
         BLEScanProtocol = Util.getSystemPropertiesInt("persist.sys.BLEScanProtocol", 0);
-        JsonConfigFilePath = Util.getSystemProperties("persist.sys.JsonConfigFilePath", "/system/etc/protocol_config.json");
+        JsonConfigFilePath = Util.getSystemProperties("persist.sys.JsonConfigFilePath",
+                "/system/etc/protocol_config.json");
         sendSOSAtOnce = Util.getSystemProperties("persist.sys.sos_at_once", "false").equals("true");
 
 
index 829f76c..6a20172 100644 (file)
@@ -180,7 +180,7 @@ public class DBHelper {
             if (contactCount != 0) {
                 ContentValues[] contentList = new ContentValues[contactCount];
                 for (int i = 0; i < contactCount; ++i) {
-                    Contact contact = (Contact) contactArray.get(i);
+                    Contact contact = contactArray.get(i);
                     ContentValues contentValues = new ContentValues();
                     contentList[i] = contentValues;
                     contentValues.put("CATEGORY", contact.category);
@@ -755,9 +755,6 @@ public class DBHelper {
     }
 
     public void saveContacts(final ArrayList<Contact> contactArray, boolean admin, boolean care, boolean call, boolean partner, boolean video, boolean sos) {
-        synchronized (this) {
-        }
-
         try {
             long currentTime = SystemClock.elapsedRealtime();
             if (currentTime - lastUpdateTime > 1000L) {
index 2fc4d6b..f78a00e 100644 (file)
@@ -1378,59 +1378,82 @@ public class protocol_fzd {
     public void handleSOS(Connection connection, Runtime runtime, String cmd, String data) {
         ICLogger.d("data is == > " + data);
         connection.send(SOS());
-        //TODO:保存到fzd的联系人里,类型为SOS
         if (data != null && data.length() > 0) {
             String[] list = data.split(CMD_SPLIT);
             ArrayList<Contact> contactArray = new ArrayList<>();
             ContentValues contentValues = new ContentValues();
             contentValues.put(ICDatabaseHelper.fType, ICDatabaseHelper.MemberType.SOS);
+            //删除成员里的数据内容,再进行添加
+            Uri memberUri = Uri.parse(ICMembersProvider.MEMBERS);
+            int delete = runtime.getContextProxy().getResolver().delete(memberUri,
+                    ICDatabaseHelper.fType + "=?", new String[]{String.valueOf(ICDatabaseHelper.MemberType.SOS)});
+            ICLogger.d("sos delete ==> " + delete);
             if (list.length == 1) {
                 if (regexUtil.isMobileNumber(list[0]) || regexUtil.isPhoneNumber(list[0])) {
                     contactArray.add(new Contact(Contact.CATEGORY_SOS, "sos1", list[0]));
                     ICLogger.i("find SOS1 number " + list[0]);
                     contentValues.put(ICDatabaseHelper.fUserName, "sos1");
                     contentValues.put(ICDatabaseHelper.fPhoneNum, list[0]);
-                    //runtime.getContextProxy().getResolver().insert(Uri.parse(FZDMembersProvider.MEMBERS), contentValues);
+                    contentValues.put(ICDatabaseHelper.fType, ICDatabaseHelper.MemberType.SOS);
+                    runtime.getContextProxy().getResolver()
+                            .insert(memberUri, contentValues);
                 }
+                contentValues.clear();
             } else if (list.length == 2) {
                 if (regexUtil.isMobileNumber(list[0]) || regexUtil.isPhoneNumber(list[0])) {
                     contactArray.add(new Contact(Contact.CATEGORY_SOS, "sos1", list[0]));
                     ICLogger.i("find SOS1 number " + list[0]);
                     contentValues.put(ICDatabaseHelper.fUserName, "sos1");
                     contentValues.put(ICDatabaseHelper.fPhoneNum, list[0]);
-                    //runtime.getContextProxy().getResolver().insert(Uri.parse(FZDMembersProvider.MEMBERS), contentValues);
+                    contentValues.put(ICDatabaseHelper.fType, ICDatabaseHelper.MemberType.SOS);
+                    runtime.getContextProxy().getResolver()
+                            .insert(memberUri, contentValues);
                 }
+                contentValues.clear();
                 if (regexUtil.isMobileNumber(list[1]) || regexUtil.isPhoneNumber(list[1])) {
                     contactArray.add(new Contact(Contact.CATEGORY_SOS, "sos2", list[1]));
                     ICLogger.i("find SOS2 number " + list[1]);
                     contentValues.put(ICDatabaseHelper.fUserName, "sos2");
                     contentValues.put(ICDatabaseHelper.fPhoneNum, list[1]);
-                    //runtime.getContextProxy().getResolver().insert(Uri.parse(FZDMembersProvider.MEMBERS), contentValues);
+                    contentValues.put(ICDatabaseHelper.fType, ICDatabaseHelper.MemberType.SOS);
+                    runtime.getContextProxy().getResolver()
+                            .insert(memberUri, contentValues);
                 }
+                contentValues.clear();
             } else if (list.length == 3) {
                 if (regexUtil.isMobileNumber(list[0]) || regexUtil.isPhoneNumber(list[0])) {
                     contactArray.add(new Contact(Contact.CATEGORY_SOS, "sos1", list[0]));
                     ICLogger.i("find SOS1 number " + list[0]);
                     contentValues.put(ICDatabaseHelper.fUserName, "sos1");
                     contentValues.put(ICDatabaseHelper.fPhoneNum, list[0]);
-                    //runtime.getContextProxy().getResolver().insert(Uri.parse(FZDMembersProvider.MEMBERS), contentValues);
+                    contentValues.put(ICDatabaseHelper.fType, ICDatabaseHelper.MemberType.SOS);
+                    runtime.getContextProxy().getResolver()
+                            .insert(memberUri, contentValues);
                 }
+                contentValues.clear();
                 if (regexUtil.isMobileNumber(list[1]) || regexUtil.isPhoneNumber(list[1])) {
                     contactArray.add(new Contact(Contact.CATEGORY_SOS, "sos2", list[1]));
                     ICLogger.i("find SOS2 number " + list[1]);
                     contentValues.put(ICDatabaseHelper.fUserName, "sos2");
                     contentValues.put(ICDatabaseHelper.fPhoneNum, list[1]);
-                    //runtime.getContextProxy().getResolver().insert(Uri.parse(FZDMembersProvider.MEMBERS), contentValues);
+                    contentValues.put(ICDatabaseHelper.fType, ICDatabaseHelper.MemberType.SOS);
+                    runtime.getContextProxy().getResolver()
+                            .insert(memberUri, contentValues);
                 }
+                contentValues.clear();
                 if (regexUtil.isMobileNumber(list[2]) || regexUtil.isPhoneNumber(list[2])) {
                     contactArray.add(new Contact(Contact.CATEGORY_SOS, "sos3", list[2]));
                     ICLogger.i("find SOS3 number " + list[2]);
                     contentValues.put(ICDatabaseHelper.fUserName, "sos3");
                     contentValues.put(ICDatabaseHelper.fPhoneNum, list[2]);
-                    //runtime.getContextProxy().getResolver().insert(Uri.parse(FZDMembersProvider.MEMBERS), contentValues);
+                    contentValues.put(ICDatabaseHelper.fType, ICDatabaseHelper.MemberType.SOS);
+                    runtime.getContextProxy().getResolver()
+                            .insert(memberUri, contentValues);
                 }
+                contentValues.clear();
             }
-            runtime.getDbHelper().saveContacts(contactArray, false, false, false, false, false, true);
+            runtime.getDbHelper().saveContacts(contactArray,
+                    false, false, false, false, false, true);
         }
 
 
@@ -2216,6 +2239,7 @@ public class protocol_fzd {
                         "W" + weekValue, "CON", "1".equals(state) ? "ON" : "OFF", "闹铃"));
             }
             mRuntime.getDbHelper().saveAlarm(alarmList);
+            //写入到官方的闹钟列表里
         }
     }
 
index 5492490..7f68dff 100644 (file)
@@ -175,6 +175,10 @@ public class protocol_s123 {
     }
 
     public void updateWebMsgState(String value, String type) {
+        if (TextUtils.isEmpty(value)) {
+            //如果没有回复消息,就会当成了已读处理
+            type = "1";
+        }
         ICLogger.d("updateWebMsgState==> " + value + " type==> " + type);
         StringMessage stringMessage = AP94(value, type);
         mConnection.send(stringMessage);
index b95398b..b8791d0 100644 (file)
@@ -67,6 +67,7 @@ public class WebMessageAdapter extends PagerAdapter {
                 }
             });
             View sendBtn = item.findViewById(R.id.send);
+            sendBtn.setEnabled(false);
             sendBtn.setOnClickListener(v -> {
                 if (mListener != null && shootItemAdapter != null) {
                     mListener.onReply(shootItemAdapter.getCurrentItemText());