completed disable dialer.
authorTrillGates <williamtrillgates@gmail.com>
Sat, 14 Aug 2021 07:04:14 +0000 (15:04 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Sat, 14 Aug 2021 07:04:14 +0000 (15:04 +0800)
app/src/main/java/com/enqualcomm/support/Config.java
app/src/main/java/com/enqualcomm/support/CoreService.java
app/src/main/java/com/enqualcomm/support/bean/SleepInfo.java
app/src/main/java/com/enqualcomm/support/utils/APNUtil.java
app/src/main/java/com/ic/protocols/protocolAPIHelper.java
app/src/main/java/com/ic/protocols/protocol_s123.java

index 6e348d6..252c2e0 100644 (file)
@@ -1050,7 +1050,7 @@ public class Config {
             Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY, true);
             Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true);
             Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true);
-            enableSleep = false;
+            enableSleep = true;
             DefaultLocationMode = CUSTOM_MOD8_GPS;
             DefaultLocationCycle = 15 * 60;
             DefaultPPGTestCycleInMinutes = 15;
index 61f623d..d0cc847 100644 (file)
@@ -1274,13 +1274,13 @@ public class CoreService extends Service {
                             + " light " + si.getLightsleep_minutes()
                             + " score " + si.getScore()
                     );
+
+                    //翻滚次数,设置到config里
                     if (Config.enableSleep) {
                         Deliver.sendLocationMSG(protocolAPIHelper.getSleepMSG(SleepInfo.getInstance(), runtime));
                     } else {
                         ICLogger.i(" 没有开启睡眠协议,skip send message!");
                     }
-//                        }
-//                    });
 
                 }
             }
index e2aa01b..01e6893 100644 (file)
@@ -1,20 +1,18 @@
 package com.enqualcomm.support.bean;
 
-import com.enqualcomm.support.Config;
 import com.enqualcomm.support.utils.ICLogger;
 import com.enqualcomm.support.utils.TimeUtil;
 
 import java.sql.Time;
 import java.util.ArrayList;
-import java.util.Date;
 
 public class SleepInfo {
     private String currentDate;
-    private Time sleep_start=new Time(21,0,0);
-    private Time sleep_end=new Time(9,0,0);
+    private Time sleep_start = new Time(21, 0, 0);
+    private Time sleep_end = new Time(9, 0, 0);
     private int deepsleep_minutes;
     private int lightsleep_minutes;
-    private ArrayList<SleepRecord> turnovertimesArray ;
+    private ArrayList<SleepRecord> turnovertimesArray;
 
     private int Score;
     /**
@@ -23,38 +21,39 @@ public class SleepInfo {
      * 每30秒记录一次
      * 深睡眠,通过加速度传感器,在30秒内翻身次数小于3
      * 浅睡眠,通过加速度传感器,在30秒内翻身次数大于3
-     *
+     * <p>
      * 本方案换算为每分钟翻身几次来计算。
      * 并设置了浅睡的翻身次数,如果太多认为没睡。
      */
-    private int DEEP_TURN_LEVEL=6;
-    private int LIGHT_TURN_LEVEL=12;
+    private int DEEP_TURN_LEVEL = 6;
+    private int LIGHT_TURN_LEVEL = 12;
+
+    private static SleepInfo sleepinfo = null;
 
-    private static SleepInfo sleepinfo=null;
-    public static SleepInfo getInstance(){
-        if (sleepinfo==null)
-            sleepinfo=new SleepInfo();
+    public static SleepInfo getInstance() {
+        if (sleepinfo == null)
+            sleepinfo = new SleepInfo();
 
         return sleepinfo;
     }
-    public void setDate(String _date){
-        currentDate=_date;
+
+    public void setDate(String _date) {
+        currentDate = _date;
     }
-    public String getCurrentDate()
-    {
+
+    public String getCurrentDate() {
         return currentDate;
     }
 
-    public int getScore(){
+    public int getScore() {
         return Score;
     }
 
-    public Time getSleep_start()
-    {
+    public Time getSleep_start() {
         return sleep_start;
     }
-    public Time getSleep_end()
-    {
+
+    public Time getSleep_end() {
         return sleep_end;
     }
 
@@ -68,10 +67,25 @@ public class SleepInfo {
      * 系统设置的 睡眠停止监测时间 例如第二天早9点
      */
 
-    public SleepInfo(){
-        currentDate= TimeUtil.getSystemDateYYMMDD();
+    public SleepInfo() {
+        currentDate = TimeUtil.getSystemDateYYMMDD();
     }
 
+    public int getRollTimes(Runtime runtime) {
+        turnovertimesArray = runtime.getDbHelper().querySleepRecord(currentDate);
+        int turnOverTime = 0;
+        if (turnovertimesArray.size() > 0) {
+            int i;
+            for (i = 0; i < turnovertimesArray.size(); i++) {
+                if (i > 0) {
+                    turnOverTime += (turnovertimesArray.get(i).stepCount - turnovertimesArray.get(i - 1).stepCount);
+                }
+            }
+        }
+        return turnOverTime;
+    }
+
+
     /***
      *  每次加入的turnovertime 是一个计量周期(心跳周期)内翻滚的次数(此处暂时用计步数据进行代替)
      *  翻滚次数小于最低阈值DEEP_TURN_LEVEL 认为是深度睡眠
@@ -80,41 +94,41 @@ public class SleepInfo {
      * @param runtime
      *
      */
-    public void calculate_sleepInfo(Runtime runtime){
+    public void calculate_sleepInfo(Runtime runtime) {
 
-        int i=0;
-        int turnovertime=0;
-        deepsleep_minutes=0;
-        lightsleep_minutes=0;
+        int i = 0;
+        int turnovertime = 0;
+        deepsleep_minutes = 0;
+        lightsleep_minutes = 0;
         turnovertimesArray = runtime.getDbHelper().querySleepRecord(currentDate);
-        if (turnovertimesArray.size()>0) {
-            for( i = 0;i < turnovertimesArray.size();i++ ){
-                if (i>0){
-                    turnovertime = (turnovertimesArray.get(i).stepCount - turnovertimesArray.get(i-1).stepCount);
-                    String before=turnovertimesArray.get(i-1).date;
-                    String after =turnovertimesArray.get(i).date;
-                    ICLogger.i("======diffBetween2DateInMinutes before "+before+", after "+after);
-                    long minutes=TimeUtil.diffBetween2DateInMinutes(before,after);
-                    if (minutes>0){
-                        long avg_turnovertime= turnovertime/minutes; //平均每分钟翻滚次数
-                        if (  avg_turnovertime<= DEEP_TURN_LEVEL) { //小于深度睡眠标准都属于深度睡眠
+        if (turnovertimesArray.size() > 0) {
+            for (i = 0; i < turnovertimesArray.size(); i++) {
+                if (i > 0) {
+                    turnovertime = (turnovertimesArray.get(i).stepCount - turnovertimesArray.get(i - 1).stepCount);
+                    String before = turnovertimesArray.get(i - 1).date;
+                    String after = turnovertimesArray.get(i).date;
+                    ICLogger.i("======diffBetween2DateInMinutes before " + before + ", after " + after);
+                    long minutes = TimeUtil.diffBetween2DateInMinutes(before, after);
+                    if (minutes > 0) {
+                        long avg_turnovertime = turnovertime / minutes; //平均每分钟翻滚次数
+                        if (avg_turnovertime <= DEEP_TURN_LEVEL) { //小于深度睡眠标准都属于深度睡眠
                             deepsleep_minutes += minutes;
-                            ICLogger.i("======深度睡眠+="+ minutes);
+                            ICLogger.i("======深度睡眠+=" + minutes);
                         } else if (avg_turnovertime > DEEP_TURN_LEVEL && avg_turnovertime < LIGHT_TURN_LEVEL) { //深度睡眠和浅睡标准之间属于浅睡。
                             lightsleep_minutes += minutes;
-                            ICLogger.i("======浅睡+="+minutes);
-                        }else{
-                            ICLogger.i("======未睡+="+minutes);
+                            ICLogger.i("======浅睡+=" + minutes);
+                        } else {
+                            ICLogger.i("======未睡+=" + minutes);
                         }
-                    }else{
+                    } else {
                         //
                         ICLogger.i("=====两条睡眠记录间隔小于1分钟,skip计算"); //此处可以有效解决0点 reset步数造成的计算问题。
                     }
 
                 }
             }
-            ICLogger.i("======深睡 = "+deepsleep_minutes+" , 浅睡 = "+lightsleep_minutes);
-            Score=(int)calculateScore(deepsleep_minutes,lightsleep_minutes,runtime);
+            ICLogger.i("======深睡 = " + deepsleep_minutes + " , 浅睡 = " + lightsleep_minutes);
+            Score = (int) calculateScore(deepsleep_minutes, lightsleep_minutes, runtime);
 
         }
 
@@ -138,33 +152,32 @@ public class SleepInfo {
      * @param runtime
      * @return
      */
-    private long calculateScore(long deepsleep,long lightsleep , Runtime runtime){
-            long sleeptime=deepsleep+lightsleep;
-
-            if (sleeptime>0 && sleeptime <= 3*60) {
-                return (sleeptime/3);
-            }else if (sleeptime >3*60 ){
-                long tmp1= 100*deepsleep/sleeptime; //深度睡眠/睡眠时间  百分比
-                ICLogger.i("======深度睡眠/睡眠时间  百分比"+tmp1);
-                if (tmp1 >=0 && tmp1 < 20){
-                     return 60+tmp1;
-                }else if (tmp1 >=21 && tmp1 < 25 ){
-                     return (80+ (tmp1-20)*3);
-                }else if (tmp1 >=26){
-                    return 98;
-                }
+    private long calculateScore(long deepsleep, long lightsleep, Runtime runtime) {
+        long sleeptime = deepsleep + lightsleep;
+
+        if (sleeptime > 0 && sleeptime <= 3 * 60) {
+            return (sleeptime / 3);
+        } else if (sleeptime > 3 * 60) {
+            long tmp1 = 100 * deepsleep / sleeptime; //深度睡眠/睡眠时间  百分比
+            ICLogger.i("======深度睡眠/睡眠时间  百分比" + tmp1);
+            if (tmp1 >= 0 && tmp1 < 20) {
+                return 60 + tmp1;
+            } else if (tmp1 >= 21 && tmp1 < 25) {
+                return (80 + (tmp1 - 20) * 3);
+            } else if (tmp1 >= 26) {
+                return 98;
             }
-            return 0;
+        }
+        return 0;
     }
 
-    public int getDeepsleep_minutes(){
+    public int getDeepsleep_minutes() {
         return deepsleep_minutes;
     }
 
-    public int getLightsleep_minutes(){
+    public int getLightsleep_minutes() {
         return lightsleep_minutes;
     }
 
 
-
 }
index 35efdc7..30704f9 100644 (file)
@@ -1,20 +1,8 @@
 package com.enqualcomm.support.utils;
 
-import android.content.ContentResolver;
-import android.content.ContentValues;
 import android.content.Context;
-import android.database.Cursor;
-import android.net.Uri;
-import android.provider.Telephony;
-import android.sim.Sim;
-import android.telephony.TelephonyManager;
-import android.util.Log;
-import android.widget.Toast;
 
 import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.PhoneFactory;
-import com.enqualcomm.support.bean.ApnSetting;
-import android.sim.SimManager;
 
 import java.lang.reflect.Method;
 
@@ -54,7 +42,7 @@ public class APNUtil {
     }
     public static boolean addVPN(String apnName, String apn, String mcc,String mnc , String user,String passwd,Context context) {
 
-        if (checkAPN(mcc,mnc,apn,context)==true){
+        if (checkAPN(mcc, mnc, apn, context)){
             ICLogger.i("VPN 已经存在,不需要添加!");
             return false;
         }
index ef5c03b..0e3b99e 100644 (file)
@@ -58,8 +58,8 @@ public class protocolAPIHelper {
         }
     }
 
-    public void release(){
-        if(protocolanan_handler != null){
+    public void release() {
+        if (protocolanan_handler != null) {
             protocolanan_handler.unregister();
         }
     }
@@ -140,6 +140,10 @@ public class protocolAPIHelper {
             case PROTOCOL_ANAN:
                 break;
             case Config.PROTOCOL_S123:
+                //飞行模式,断开所有网络,不报定位,持续120分钟。进入飞行模式前,
+                // 先回复AP33,再发送APFX到服务端,平台会改变设备状态为休眠,知道再次收到消息。
+                // 没有指令号
+                //protocols123_handler.sendAp33();
                 protocols123_handler.sendFlyModeMsg();
                 break;
             case Config.PROTOCOL_GATOR:
index 832925a..da97dcb 100644 (file)
@@ -30,6 +30,7 @@ import com.enqualcomm.support.bean.Contact;
 import com.enqualcomm.support.bean.Content;
 import com.enqualcomm.support.bean.ICLocation;
 import com.enqualcomm.support.bean.Runtime;
+import com.enqualcomm.support.bean.SleepInfo;
 import com.enqualcomm.support.bean.StringMessage;
 import com.enqualcomm.support.bean.VoiceContent;
 import com.enqualcomm.support.bean.voicePacket;
@@ -180,6 +181,7 @@ public class protocol_s123 {
         mConnection.send(stringMessage);
     }
 
+
     public enum CMD_TYPE {
         /*终端发起*/
         AP00,//登录包
@@ -214,6 +216,8 @@ public class protocol_s123 {
         APFF,//定位数据包
         BPFF,
         /* 服务器发起*/
+        BPTW,//测量体温
+        APTW,
         AP12,
         BP12,//SOS 号码设置
         AP14,
@@ -357,6 +361,8 @@ public class protocol_s123 {
         cmdMap.put(CMD_TYPE.APFF, "APFF");
         cmdMap.put(CMD_TYPE.BPFF, "BPFF");
         /* 服务器发起*/
+        cmdMap.put(CMD_TYPE.BPTW, "BPTW");
+        cmdMap.put(CMD_TYPE.APTW, "APTW");
         cmdMap.put(CMD_TYPE.AP12, "AP12");
         cmdMap.put(CMD_TYPE.BP12, "BP12");
         cmdMap.put(CMD_TYPE.AP14, "AP14");
@@ -830,7 +836,7 @@ public class protocol_s123 {
                         .append(ds.getWorkModeStr()).append(CMDSPLIT)
                         .append(ds.getTotalStepCount())
                         .append(CMDSPLIT)
-                        .append(ds.getRolltimes())
+                        .append(SleepInfo.getInstance().getRollTimes(ds))
                         .append(CMDSPLIT).append(calorie)
                         .append(CMDEND).toString());
     }
@@ -861,6 +867,7 @@ public class protocol_s123 {
                         .append(CMDSPLIT).append(mRuntime.getBatterylevel())
                         .append(CMDSPLIT).append(mRuntime.getLBSData())
                         .append(CMDSPLIT).append(mRuntime.getWifiInfo())
+                        .append(CMDEND)
                         .toString());
     }
 
@@ -1115,6 +1122,7 @@ public class protocol_s123 {
         //IWBP31,867155030001063,161723
         String[] cmdlist = cmd.split(CMDSPLIT);
         if (cmdlist.length == 3) {
+            connection.send(APGJ(mRuntime));
             connection.send(AP31(cmdlist[2]));
         } else {
             ICLogger.d("parse error...");
@@ -1487,14 +1495,14 @@ public class protocol_s123 {
     }
 
 
-    public static StringMessage AP33(String cmdindex, int workMode) {
+    public static StringMessage AP33(String cmdIndex, int workMode) {
         //IWAP33,080835,1#
         //080835:指令流水号
         //1:设置信息,供服务器同步
         return genStringMessage("AP33",
                 new StringBuffer(CMDHEADER)
                         .append(cmdMap.get(CMD_TYPE.AP33))
-                        .append(CMDSPLIT).append(cmdindex)
+                        .append(CMDSPLIT).append(cmdIndex)
                         .append(CMDSPLIT).append(workMode)
                         // 下发内容与文档字段对不上
                         // - 文档内容:IW**BP33**,353456789012345,080835,1,15,**0**#
@@ -1616,8 +1624,6 @@ public class protocol_s123 {
         ICLogger.d("cmdlist length == > " + cmdlist.length);
         if (cmdlist.length == 5) {
             String cmdIndex = cmdlist[2];
-            //新增加的类型
-            //TODO:
             String type = cmdlist[3];
             ICLogger.d("web msg type ==> " + type);
             String txtMsg = Util.hexStr2Str(cmdlist[4], "gb2312");
@@ -1635,9 +1641,6 @@ public class protocol_s123 {
                 } else {
                     txtMsg = Util.UrlGB2312ToUTF8(txtMsg);
                 }
-                StringMessage msg = AP40(cmdIndex, 1);
-                //设定当前工作模式及循环频率
-                connection.send(msg);
                 ICLogger.i("received Txt Msg " + txtMsg);
                 if (!Config.noPushTxtReadReply) {
                     Config.setLastUnReadMessage(runtime.getContextProxy().context, sb.toString());
@@ -1660,7 +1663,13 @@ public class protocol_s123 {
                 resolver.insert(Uri.parse(WebSmsProvider.WEB_MSG), contentValues);
                 //保存到数据库里,以下是原来的做法
                 //runtime.getContextProxy().saveMstToSMSDB(txtmsg);
+            } else if ("0".equals(type)) {
+                //保存到数据库中
+                updateSettingValue("devices_custom_name", txtMsg);
             }
+            StringMessage msg = AP40(cmdIndex, 1);
+            //设定当前工作模式及循环频率
+            connection.send(msg);
         } else {
             ICLogger.i("BP40 format error!");
         }
@@ -2258,8 +2267,9 @@ public class protocol_s123 {
                 ICLogger.i("收到服务器指令:测量体温 " + freq + "分钟一次。");
                 Config.setTemperatureTestCycle(runtime, freq * 60);
                 CoreService.getInstance().setTempAlarm(true);
-                if (runtime.check_stat_do_temp_test())
+                if (runtime.check_stat_do_temp_test()) {
                     TemperatureUtil.getInstance().doTempTestInThread(FROM_SERVER);
+                }
             } catch (Exception e) {
                 ICLogger.e(e.getMessage(), e);
             }
@@ -2686,24 +2696,24 @@ public class protocol_s123 {
     }
 
     public static StringMessage APSL(String date, int deepsleep, int lightsleep, int score) {
-/***
- * 示例:
- * IWAPSL,20200803,240,120,90#
- * 说明:睡眠计算时间 当日21:00至 次日 9:00, 睡眠时间记录为当日时间。如2020-8-3的睡眠时间段为 2020-8-3 21:00 ~ 2020-8-4 09:00
- * IW:标识符
- * APSL:命令字
- * 202008003:睡眠时间 (手表本地时间)
- * 240:深睡时间 (手表本地时间),单位分钟
- * 120:浅睡时间(手表本地时间),单位分钟
- * 90睡眠分数
- * 睡眠算法
- * 使用记步同样的算法,计算翻身次数
- * 平均每60秒记录一次
- * 深睡眠,通过加速度传感器,在60秒内翻身次数小于6
- * 浅睡眠,通过加速度传感器,在60秒内翻身次数大于等于6, 且小于12 ,否则认为未睡
- * 换算分数后发送到服务器
- * #:结束符
- */
+        /***
+         * 示例:
+         * IWAPSL,20200803,240,120,90#
+         * 说明:睡眠计算时间 当日21:00至 次日 9:00, 睡眠时间记录为当日时间。如2020-8-3的睡眠时间段为 2020-8-3 21:00 ~ 2020-8-4 09:00
+         * IW:标识符
+         * APSL:命令字
+         * 202008003:睡眠时间 (手表本地时间)
+         * 240:深睡时间 (手表本地时间),单位分钟
+         * 120:浅睡时间(手表本地时间),单位分钟
+         * 90睡眠分数
+         * 睡眠算法
+         * 使用记步同样的算法,计算翻身次数
+         * 平均每60秒记录一次
+         * 深睡眠,通过加速度传感器,在60秒内翻身次数小于6
+         * 浅睡眠,通过加速度传感器,在60秒内翻身次数大于等于6, 且小于12 ,否则认为未睡
+         * 换算分数后发送到服务器
+         * #:结束符
+         */
         String sb = new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.APSL))
                 .append(CMDSPLIT).append(date)
                 .append(CMDSPLIT).append(deepsleep)
@@ -3413,6 +3423,8 @@ public class protocol_s123 {
                 ICLogger.i("服务器收到定位AP01");
                 mConnection.DeliverCMDMessageToSystem("AP01", cmd);//通知下面线程状态变化
                 break;
+            case BP02:
+                break;
             case AP92:
                 break;
             case BP92:
@@ -3422,6 +3434,8 @@ public class protocol_s123 {
             case BP94:
                 ICLogger.d("服务器收到文字确认/快捷回复");
                 break;
+            case AP03:
+                break;
             case BP03: //心跳包
                 ICLogger.i("服务器收到心跳包AP03");
                 //通知下面线程状态变化
@@ -3548,6 +3562,8 @@ public class protocol_s123 {
                 handleBPJZ(cmd, mConnection, mRuntime);
                 ICLogger.i("收到服务器血压校准命令");
                 break;
+            case APAL:
+                break;
             case AP49:
                 break;
             case BP49:
@@ -3582,7 +3598,9 @@ public class protocol_s123 {
                 handleBP89(cmd, mConnection);
                 mConnection.DeliverCMDMessageToSystem("AP89", cmd);//通知下面线程状态变化
                 break;
-
+            case BPTW://马上测试体温
+                handleBPTW(cmd);
+                break;
             case BPTE: //设置测试体温
                 handleBPTE(cmd, mConnection, mRuntime);
                 mConnection.DeliverCMDMessageToSystem("APTE", cmd);//通知下面线程状态变化
@@ -3600,7 +3618,6 @@ public class protocol_s123 {
                 ICLogger.i("收到服务器设置 心率血压血氧修正值BPX1");
                 mConnection.DeliverCMDMessageToSystem("APX1", cmd);//通知下面线程状态变化
                 break;
-
             case BPS4: //提醒设置(时间段) 主要为久坐设置提醒时长。
                 handleBPS4(cmd, mConnection, mRuntime);
                 ICLogger.i("收到 提醒设置(时间段)");
@@ -3697,6 +3714,8 @@ public class protocol_s123 {
                 ICLogger.d("服务器收到飞行模式打开请求.");
                 handleBPFX();
                 break;
+            case APRP:
+                break;
             case BPRP:
                 ICLogger.d("服务器收到签到信息.");
                 handleBPRP();
@@ -3815,10 +3834,34 @@ public class protocol_s123 {
                 break;
             case APSM:
                 break;
+            case APFF:
+                break;
+            case APTW:
+                break;
+            case APCM:
+                break;
+            case APFX:
+                break;
         }
         return ret;
     }
 
+    //测量体温
+    //响应服务器
+    private void handleBPTW(String cmd) {
+        String[] split = cmd.split(CMDSPLIT);
+        if (split.length == 3) {
+            String indexId = split[2];
+            responseWithId(cmdMap.get(CMD_TYPE.APTW), indexId);
+            //测量体温
+            if (mRuntime.check_stat_do_temp_test()) {
+                TemperatureUtil.getInstance().doTempTestInThread(FROM_SERVER);
+            }
+        } else {
+            ICLogger.d("parse error ==> " + cmd);
+        }
+    }
+
     /**
      * 修改配置项的值为success,让UI展示Success
      */
@@ -3994,7 +4037,7 @@ public class protocol_s123 {
      */
     private void handleBPAP(String cmd) {
         //IWBPAP,353456789012345,080835,460,01,CMNET,cmnet,user,password
-        String[] split = cmd.split(CMDSPLIT);
+        String[] split = cmd.split(CMDSPLIT, -1);
         if (split.length == 9) {
             String id = split[2];
             //APNUtil.addVPN(apnName, apn, mcc, mnc, user, password, mContext)
@@ -4011,7 +4054,7 @@ public class protocol_s123 {
             // 1:表示设备接受数据成功,0表示设备接受数据失败
             responseWithId(cmdMap.get(CMD_TYPE.APAP), id, "1");
         } else {
-            ICLogger.d("parse error ==> " + cmd);
+            ICLogger.d("parse error ==> " + cmd + " split.length == > " + split.length);
         }
     }