From: TrillGates Date: Wed, 10 Mar 2021 02:42:57 +0000 (+0800) Subject: add CH version for fall down. X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=9dbb775d271357171aa1d0e333956b5621e8bd4e;p=protocol_srv.git add CH version for fall down. --- diff --git a/app/src/main/java/com/enqualcomm/support/Config.java b/app/src/main/java/com/enqualcomm/support/Config.java index e5c6c7af..ff36321e 100644 --- a/app/src/main/java/com/enqualcomm/support/Config.java +++ b/app/src/main/java/com/enqualcomm/support/Config.java @@ -23,840 +23,861 @@ import java.util.HashMap; import static com.enqualcomm.support.utils.Util.getSystemProperties; public class Config { - public static final boolean LOG_TOFILE=true; - public static int antioff = 0; - public static int heart_rate = 0; - private static String json; - public static int defaultHeartbeatCycle=5; - public static int sw_release_no = -1; - - - //如果重试都失败,则丢弃命令不进行盲点续传 - public static boolean discard_cmd_after_retryfailed=true; - - public static boolean forceMoveCheck=true; - public static boolean forceWearCheck=true; - - private static final String KEYDurationOfVibration = "DurationVib"; - private static final String KeyMasterVolume = "MasterVolume"; - - public static final String DefaultLogFtpServer="icfota.snicker.com.cn"; - public static final String DefaultLogFtpUser="ftpuser"; - public static final String DefaultLogFtpPWD="iclog"; - + public static final boolean LOG_TOFILE = true; + public static int antioff = 0; + public static int heart_rate = 0; + private static String json; + public static int defaultHeartbeatCycle = 5; + public static int sw_release_no = -1; - public static final String DefaultWiFiSSID="Xplay6"; - public static final String DefaultWiFiPWD="87654321"; - public static final String DefaultWiFiEncryptType="psk"; - public static final int GPSLocationTimeoutInSeconds=50; - public static final int WiFiLocationTimeoutInSeconds=12; + //如果重试都失败,则丢弃命令不进行盲点续传 + public static boolean discard_cmd_after_retryfailed = true; - public static String c43_branch_name="none"; - public static String custom_name="none"; + public static boolean forceMoveCheck = true; + public static boolean forceWearCheck = true; - //配置是否广播提示框信息给外部应用显示 - public static boolean noBroadCastSMSNotify=false; - public static boolean noBroadCastPushTxtNotify=false; + private static final String KEYDurationOfVibration = "DurationVib"; + private static final String KeyMasterVolume = "MasterVolume"; + public static final String DefaultLogFtpServer = "icfota.snicker.com.cn"; + public static final String DefaultLogFtpUser = "ftpuser"; + public static final String DefaultLogFtpPWD = "iclog"; - //protocol内部Dialog配置,true表示用外部提示窗,false表示用协议内部提示窗 - public static boolean noSMSNotifyDialog=false; - public static boolean noPushTxtNotifyDialog=false; - public static boolean noVoiceNotifyDialog=false; - //是否SOS拨号的开关,false表示只发送系统sosalarm,不发起SOS拨号 - public static boolean SOSNoNeedDial=false; + public static final String DefaultWiFiSSID = "Xplay6"; + public static final String DefaultWiFiPWD = "87654321"; + public static final String DefaultWiFiEncryptType = "psk"; - //ic68只有体温没有腕温,它开启代表原来的腕温函数取出的就是体温,不需要再进行换算了。 - public static boolean disableWristTemp=false; - //配置是否有温度传感器 - public static boolean noTempSensor=false; - //配置是否有心率传感器 - public static boolean noPPGSensor=false; - //配置脱腕报警是否需要弹出脱腕提示 默认关闭 - public static boolean needBroadcastAntiAlarm=false; - //配置脱腕报警是否需要弹出剪断提示 默认开启 - public static boolean needBroadcastCutoffAlarm=true; + public static final int GPSLocationTimeoutInSeconds = 50; + public static final int WiFiLocationTimeoutInSeconds = 12; + public static String c43_branch_name = "none"; + public static String custom_name = "none"; - //定位是否使用wifi的配置。 - public static boolean disableWiFiScan=false; + //配置是否广播提示框信息给外部应用显示 + public static boolean noBroadCastSMSNotify = false; + public static boolean noBroadCastPushTxtNotify = false; - public static int BLEScanProtocol=0; /** 0 代表扫描beacon后 自行判断是否在指定区域,需要协议绑定beacon地址。 - * 1 代表扫描beacon后,直接把扫描结果上报即可。 - **/ - public static boolean UsePolingCheckWeared=false; + //protocol内部Dialog配置,true表示用外部提示窗,false表示用协议内部提示窗 + public static boolean noSMSNotifyDialog = false; + public static boolean noPushTxtNotifyDialog = false; + public static boolean noVoiceNotifyDialog = false; - static { - 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); - UsePolingCheckWeared=Util.getSystemProperties("persist.sys.PolingCheckAnti","false").equals("true"); - } - - private static String make() { - try { - return (new JSONStringer()).object() - .key("cmd").value("Init") - .key("sw_version").value("eiot_V1.0.0") - .key("protocol_version").value("2.0") - .key("product").value(2L) - .key("swReleaseNo").value(sw_release_no) - .endObject().toString(); - } catch (JSONException jSONException) { - jSONException.printStackTrace(); - return ""; - } - } - - public static String toJson() { - if (TextUtils.isEmpty(json)) - json = make(); - return json; - } + //是否SOS拨号的开关,false表示只发送系统sosalarm,不发起SOS拨号 + public static boolean SOSNoNeedDial = false; + //ic68只有体温没有腕温,它开启代表原来的腕温函数取出的就是体温,不需要再进行换算了。 + public static boolean disableWristTemp = false; + //配置是否有温度传感器 + public static boolean noTempSensor = false; + //配置是否有心率传感器 + public static boolean noPPGSensor = false; + //配置脱腕报警是否需要弹出脱腕提示 默认关闭 + public static boolean needBroadcastAntiAlarm = false; + //配置脱腕报警是否需要弹出剪断提示 默认开启 + public static boolean needBroadcastCutoffAlarm = true; - public final static boolean isL03Tracker=getIsL03tracker(); - public final static boolean upload_logs_via_ftp=false; - final static String KeyProtocolServerIP="ProtocolServerIP"; - final static String KeyProtocolServerHOST="ProtocolServerHOST"; - final static String KeyProtocolServerPort="ProtoclServerPort";; - final static String KeyLogServerIP="LogServerIP"; - final static String KeyLogServerPort="LogServerPort"; - final static String KeyFotaServerUrl="FotaServerUrl"; + //定位是否使用wifi的配置。 + public static boolean disableWiFiScan = false; - final static String KeyPpgTestCycle="PPGTestCycle"; - final static String KeyLocationCycle="LocationCycle"; - final static String KeyLocationMode="LocationMode";; + public static int BLEScanProtocol = 0; + /** + * 0 代表扫描beacon后 自行判断是否在指定区域,需要协议绑定beacon地址。 + * 1 代表扫描beacon后,直接把扫描结果上报即可。 + **/ - final static String KeyAlarmCycle="HeartBeatCycle"; + public static boolean UsePolingCheckWeared = false; - final static String KeyContactsList="ContactsList"; - final static String KeySOSNumbersList="SOSNumbersList"; + static { + 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); + UsePolingCheckWeared = Util.getSystemProperties("persist.sys.PolingCheckAnti", "false").equals("true"); + } - final static String KeyIMEI = "persist.sys.protocol_IMEI"; - public final static String KeyQRURIFILE = "persist.sys.qrUriFile"; + private static String make() { + try { + return (new JSONStringer()).object() + .key("cmd").value("Init") + .key("sw_version").value("eiot_V1.0.0") + .key("protocol_version").value("2.0") + .key("product").value(2L) + .key("swReleaseNo").value(sw_release_no) + .endObject().toString(); + } catch (JSONException jSONException) { + jSONException.printStackTrace(); + return ""; + } + } - final static String KeyPractiseState = "persist.sys.practising"; + public static String toJson() { + if (TextUtils.isEmpty(json)) + json = make(); + return json; + } - final static String KeyHeartBeatCycle="ServerHeartBeatCycle"; + public final static boolean isL03Tracker = getIsL03tracker(); + public final static boolean upload_logs_via_ftp = false; + final static String KeyProtocolServerIP = "ProtocolServerIP"; + final static String KeyProtocolServerHOST = "ProtocolServerHOST"; + final static String KeyProtocolServerPort = "ProtoclServerPort"; + ; + final static String KeyLogServerIP = "LogServerIP"; + final static String KeyLogServerPort = "LogServerPort"; + final static String KeyFotaServerUrl = "FotaServerUrl"; - final static String KeyLogFtpServer="FtpServerHost"; - final static String KeyLogFtpUser="FtpServerUser"; - final static String KeyLogFtpPWD="FtpServerPWD"; + final static String KeyPpgTestCycle = "PPGTestCycle"; + final static String KeyLocationCycle = "LocationCycle"; + final static String KeyLocationMode = "LocationMode"; + ; - final static String KeyWiFiSSID="WiFiSSID"; - final static String KeyWiFiPasswd="WiFiPWD"; - final static String KeyWiFiEncyptType="WiFiEncryptType"; + final static String KeyAlarmCycle = "HeartBeatCycle"; - final static String KeySMSPassword="SMSPWD"; - final static String DefaultSMSPassword="non"; + final static String KeyContactsList = "ContactsList"; + final static String KeySOSNumbersList = "SOSNumbersList"; - final static String KeyTempTestCycle="TempTestCycle"; + final static String KeyIMEI = "persist.sys.protocol_IMEI"; + public final static String KeyQRURIFILE = "persist.sys.qrUriFile"; + final static String KeyPractiseState = "persist.sys.practising"; - final static String KeyPPGadust="KeyPPGAdjust"; - final static String KeyBPHadust="KeyBPHAdjust"; - final static String KeyBPLadust="KeyBPLAdjust"; - final static String KeySPo2adust="KeySPo2Adjust"; + final static String KeyHeartBeatCycle = "ServerHeartBeatCycle"; - final static String KeyPolingCycleCheckAnti="PolingCycleCheckAnti"; - final static String KeyBleScanCycle="BleScanCycle"; - final static String KeyLastUnReadMessage="UnreadMsg"; + final static String KeyLogFtpServer = "FtpServerHost"; + final static String KeyLogFtpUser = "FtpServerUser"; + final static String KeyLogFtpPWD = "FtpServerPWD"; - public static void setDurationOfVibration(Context context, int cycle){ - SharPreferenceUtil.setPrefInt(context,KEYDurationOfVibration,cycle); - } + final static String KeyWiFiSSID = "WiFiSSID"; + final static String KeyWiFiPasswd = "WiFiPWD"; + final static String KeyWiFiEncyptType = "WiFiEncryptType"; - public static int getDurationOfVibration(Context context){ - return SharPreferenceUtil.getPrefInt(context,KEYDurationOfVibration,1); - } + final static String KeySMSPassword = "SMSPWD"; + final static String DefaultSMSPassword = "non"; - public static void setMasterVolume(Context context, int cycle){ - SharPreferenceUtil.setPrefInt(context,KeyMasterVolume,cycle); - } + final static String KeyTempTestCycle = "TempTestCycle"; - public static int getMasterVolume(Context context){ - return SharPreferenceUtil.getPrefInt(context,KeyMasterVolume,15); - } + final static String KeyPPGadust = "KeyPPGAdjust"; + final static String KeyBPHadust = "KeyBPHAdjust"; + final static String KeyBPLadust = "KeyBPLAdjust"; + final static String KeySPo2adust = "KeySPo2Adjust"; - public static void setCheckAntiPolingCycle(Context context, int cycle){ - SharPreferenceUtil.setPrefInt(context,KeyPolingCycleCheckAnti,cycle); - } + final static String KeyPolingCycleCheckAnti = "PolingCycleCheckAnti"; + final static String KeyBleScanCycle = "BleScanCycle"; - public static int getCheckAntiPolingCycle(Context context){ - return SharPreferenceUtil.getPrefInt(context,KeyPolingCycleCheckAnti,0); - } + final static String KeyLastUnReadMessage = "UnreadMsg"; - public static void setBleScanCycle(Context context, int cycle){ - SharPreferenceUtil.setPrefInt(context,KeyBleScanCycle,cycle); - } - public static int getBleScanCycle(Context context){ - return SharPreferenceUtil.getPrefInt(context,KeyBleScanCycle,0); - } + public static void setDurationOfVibration(Context context, int cycle) { + SharPreferenceUtil.setPrefInt(context, KEYDurationOfVibration, cycle); + } - public static String getLastUnReadMessage(Context context){ - return SharPreferenceUtil.getPrefString(context,KeyLastUnReadMessage,""); - } + public static int getDurationOfVibration(Context context) { + return SharPreferenceUtil.getPrefInt(context, KEYDurationOfVibration, 1); + } - public static void setLastUnReadMessage(Context context,String smsPWD){ - SharPreferenceUtil.setPrefString(context,KeyLastUnReadMessage,smsPWD); - } + public static void setMasterVolume(Context context, int cycle) { + SharPreferenceUtil.setPrefInt(context, KeyMasterVolume, cycle); + } - public static String getSMSPwd(Context context){ - return SharPreferenceUtil.getPrefString(context,KeySMSPassword,DefaultSMSPassword); - } + public static int getMasterVolume(Context context) { + return SharPreferenceUtil.getPrefInt(context, KeyMasterVolume, 15); + } - public static void setSMSPwd(Context context,String smsPWD){ - SharPreferenceUtil.setPrefString(context,KeySMSPassword,smsPWD); - } - public static boolean getIsL03tracker(){ - boolean ret=getSystemProperties("persist.sys.isL03tracker").toLowerCase().equals("true"); - return ret; - } - public static String getWiFiSSID(Context context){ - return SharPreferenceUtil.getPrefString(context,KeyWiFiSSID,DefaultWiFiSSID); - } - public static void setWiFiSSID(Context context,String ssid){ - SharPreferenceUtil.setPrefString(context,KeyWiFiSSID,ssid); - } + public static void setCheckAntiPolingCycle(Context context, int cycle) { + SharPreferenceUtil.setPrefInt(context, KeyPolingCycleCheckAnti, cycle); + } - public static String getWiFiPasswd(Context context){ - return SharPreferenceUtil.getPrefString(context,KeyWiFiPasswd,DefaultWiFiPWD); - } + public static int getCheckAntiPolingCycle(Context context) { + return SharPreferenceUtil.getPrefInt(context, KeyPolingCycleCheckAnti, 0); + } - public static void setWiFiPasswd(Context context,String pwd){ - SharPreferenceUtil.setPrefString(context,KeyWiFiPasswd,pwd); - } + public static void setBleScanCycle(Context context, int cycle) { + SharPreferenceUtil.setPrefInt(context, KeyBleScanCycle, cycle); + } - public static String getWiFiEncryptType(Context context){ - return SharPreferenceUtil.getPrefString(context,KeyWiFiEncyptType,DefaultWiFiEncryptType); + public static int getBleScanCycle(Context context) { + return SharPreferenceUtil.getPrefInt(context, KeyBleScanCycle, 0); } - public static void setWiFiEncryptType(Context context,String type){ - SharPreferenceUtil.setPrefString(context,KeyWiFiEncyptType,type); + public static String getLastUnReadMessage(Context context) { + return SharPreferenceUtil.getPrefString(context, KeyLastUnReadMessage, ""); } - public static String getFotaServerUrl(Context context){ - return SharPreferenceUtil.getPrefString(context,KeyFotaServerUrl,""); - } + public static void setLastUnReadMessage(Context context, String smsPWD) { + SharPreferenceUtil.setPrefString(context, KeyLastUnReadMessage, smsPWD); + } + + public static String getSMSPwd(Context context) { + return SharPreferenceUtil.getPrefString(context, KeySMSPassword, DefaultSMSPassword); + } + + public static void setSMSPwd(Context context, String smsPWD) { + SharPreferenceUtil.setPrefString(context, KeySMSPassword, smsPWD); + } - public static void setFotaServerUrl(Context context,String url){ - SharPreferenceUtil.setPrefString(context,KeyFotaServerUrl,url); - } - public static String getFtpUser(Context context){ - return SharPreferenceUtil.getPrefString(context,KeyLogFtpUser,DefaultLogFtpUser); - } + public static boolean getIsL03tracker() { + boolean ret = getSystemProperties("persist.sys.isL03tracker").toLowerCase().equals("true"); + return ret; + } - public static void setFtpUser(Context context,String user){ - SharPreferenceUtil.setPrefString(context,KeyLogFtpUser,user); - } + public static String getWiFiSSID(Context context) { + return SharPreferenceUtil.getPrefString(context, KeyWiFiSSID, DefaultWiFiSSID); + } - public static String getFtpServer(Context context){ - return SharPreferenceUtil.getPrefString(context,KeyLogFtpServer,DefaultLogFtpServer); - } + public static void setWiFiSSID(Context context, String ssid) { + SharPreferenceUtil.setPrefString(context, KeyWiFiSSID, ssid); + } - public static void setFtpServer(Context context,String host){ - SharPreferenceUtil.setPrefString(context,KeyLogFtpServer,host); - } + public static String getWiFiPasswd(Context context) { + return SharPreferenceUtil.getPrefString(context, KeyWiFiPasswd, DefaultWiFiPWD); + } - public static String getFtpPWD(Context context){ - return SharPreferenceUtil.getPrefString(context,KeyLogFtpPWD,DefaultLogFtpPWD); - } - public static void setFtpPWD(Context context,String PWD){ - SharPreferenceUtil.setPrefString(context,KeyLogFtpPWD,PWD); - } + public static void setWiFiPasswd(Context context, String pwd) { + SharPreferenceUtil.setPrefString(context, KeyWiFiPasswd, pwd); + } + + public static String getWiFiEncryptType(Context context) { + return SharPreferenceUtil.getPrefString(context, KeyWiFiEncyptType, DefaultWiFiEncryptType); + } + + public static void setWiFiEncryptType(Context context, String type) { + SharPreferenceUtil.setPrefString(context, KeyWiFiEncyptType, type); + } + + public static String getFotaServerUrl(Context context) { + return SharPreferenceUtil.getPrefString(context, KeyFotaServerUrl, ""); + } + + public static void setFotaServerUrl(Context context, String url) { + SharPreferenceUtil.setPrefString(context, KeyFotaServerUrl, url); + } + + public static String getFtpUser(Context context) { + return SharPreferenceUtil.getPrefString(context, KeyLogFtpUser, DefaultLogFtpUser); + } + + public static void setFtpUser(Context context, String user) { + SharPreferenceUtil.setPrefString(context, KeyLogFtpUser, user); + } + + public static String getFtpServer(Context context) { + return SharPreferenceUtil.getPrefString(context, KeyLogFtpServer, DefaultLogFtpServer); + } + + public static void setFtpServer(Context context, String host) { + SharPreferenceUtil.setPrefString(context, KeyLogFtpServer, host); + } + + public static String getFtpPWD(Context context) { + return SharPreferenceUtil.getPrefString(context, KeyLogFtpPWD, DefaultLogFtpPWD); + } + + public static void setFtpPWD(Context context, String PWD) { + SharPreferenceUtil.setPrefString(context, KeyLogFtpPWD, PWD); + } - public static void setAlarmCycle(Context context, int cycle){ - SharPreferenceUtil.setPrefInt(context,KeyAlarmCycle,cycle); - } + public static void setAlarmCycle(Context context, int cycle) { + SharPreferenceUtil.setPrefInt(context, KeyAlarmCycle, cycle); + } - //默认3分钟,刚刚wakeup的时候1分钟 - public static int getAlarmCycle(Context context){ - return SharPreferenceUtil.getPrefInt(context,KeyAlarmCycle,3); - } + //默认3分钟,刚刚wakeup的时候1分钟 + public static int getAlarmCycle(Context context) { + return SharPreferenceUtil.getPrefInt(context, KeyAlarmCycle, 3); + } - public static void setProtocolServerPort(Context context, int serverPort){ + public static void setProtocolServerPort(Context context, int serverPort) { // SharPreferenceUtil.setPrefString(context,KeyProtocolServerIP,serverIP); - SharPreferenceUtil.setPrefInt(context,KeyProtocolServerPort,serverPort); - } - - public static void setProtocolServerHost(Context context,String host){ - SharPreferenceUtil.setPrefString(context,KeyProtocolServerHOST,host); - } - //public static String getProtocolServerIP(Context context){ - // return SharPreferenceUtil.getPrefString(context,KeyProtocolServerIP,"118.178.155.223"); - // } + SharPreferenceUtil.setPrefInt(context, KeyProtocolServerPort, serverPort); + } - public static void loadModCycleSettings(Runtime runtime){ - Context context=runtime.getContextProxy().context; - ICLogger.i("current Cycles PPG "+ runtime.getPpgTestCycle()+" , LocationCycle "+runtime.getLocationInstance().getLocation_cycle()+" LocationMode "+runtime.getLocationInstance().getWorkingMod()); - runtime.setPpgTestCycle(Config.getPPGTestCycle(context)); - runtime.getLocationInstance().setLocation_cycle(Config.getLocationCycle(context)); - runtime.getLocationInstance().setWorkingMod(Config.getLocationMode(context)); - ICLogger.i("current Cycles PPG "+ runtime.getPpgTestCycle()+" , LocationCycle "+runtime.getLocationInstance().getLocation_cycle()+" LocationMode "+runtime.getLocationInstance().getWorkingMod()); + public static void setProtocolServerHost(Context context, String host) { + SharPreferenceUtil.setPrefString(context, KeyProtocolServerHOST, host); + } + //public static String getProtocolServerIP(Context context){ + // return SharPreferenceUtil.getPrefString(context,KeyProtocolServerIP,"118.178.155.223"); + // } - int mastervolume = getMasterVolume(context); - ICAudioManager.setMasterVolumn(context,mastervolume); + public static void loadModCycleSettings(Runtime runtime) { + Context context = runtime.getContextProxy().context; + ICLogger.i("current Cycles PPG " + runtime.getPpgTestCycle() + " , LocationCycle " + runtime.getLocationInstance().getLocation_cycle() + " LocationMode " + runtime.getLocationInstance().getWorkingMod()); + runtime.setPpgTestCycle(Config.getPPGTestCycle(context)); + runtime.getLocationInstance().setLocation_cycle(Config.getLocationCycle(context)); + runtime.getLocationInstance().setWorkingMod(Config.getLocationMode(context)); + ICLogger.i("current Cycles PPG " + runtime.getPpgTestCycle() + " , LocationCycle " + runtime.getLocationInstance().getLocation_cycle() + " LocationMode " + runtime.getLocationInstance().getWorkingMod()); - int duration= getDurationOfVibration(context); - VibrateUtil.setVibPattern(duration*1000); + int mastervolume = getMasterVolume(context); + ICAudioManager.setMasterVolumn(context, mastervolume); - } + int duration = getDurationOfVibration(context); + VibrateUtil.setVibPattern(duration * 1000); - public static void loadHearBeatSetting(Runtime runtime){ - runtime.setHeartBeatCycle(Config.getHeartBeatCycle(runtime.getContextProxy().context)); - } - public static void loadServerSettings(Runtime runtime){ - runtime.setHostAndPort(Config.getProtocolServerHost(runtime.getContextProxy().context),Config.getProtocolServerPort(runtime.getContextProxy().context)); - } + } - public static void setIMEI(Context context, String imei){ - Util.setSystemProperties(KeyIMEI,imei); - } + public static void loadHearBeatSetting(Runtime runtime) { + runtime.setHeartBeatCycle(Config.getHeartBeatCycle(runtime.getContextProxy().context)); + } - public static String getIMEI(Context context){ - return Util.getSystemProperties(KeyIMEI,""); - } + public static void loadServerSettings(Runtime runtime) { + runtime.setHostAndPort(Config.getProtocolServerHost(runtime.getContextProxy().context), Config.getProtocolServerPort(runtime.getContextProxy().context)); + } - public static String getProtocolServerHost(Context context){ - String host; - host= SharPreferenceUtil.getPrefString(context,KeyProtocolServerHOST,protocolAPIHelper.getDefaultServerIP()); - return host; - } + public static void setIMEI(Context context, String imei) { + Util.setSystemProperties(KeyIMEI, imei); + } + public static String getIMEI(Context context) { + return Util.getSystemProperties(KeyIMEI, ""); + } - public static int getProtocolServerPort(Context context){ - int port; - port= SharPreferenceUtil.getPrefInt(context,KeyProtocolServerPort,protocolAPIHelper.getDefaultServerPort()); - return port; - } + public static String getProtocolServerHost(Context context) { + String host; + host = SharPreferenceUtil.getPrefString(context, KeyProtocolServerHOST, protocolAPIHelper.getDefaultServerIP()); + return host; + } - public static void setConfigInitFlag(Context context,int flag){ - SharPreferenceUtil.setPrefInt(context,"ConfigInitFlag",flag); - } - public static int getConfigInitFlag(Context context){ - return SharPreferenceUtil.getPrefInt(context,"ConfigInitFlag",0); - } - public static void setLogServerIP(Context context,String serverIP,int serverPort){ + public static int getProtocolServerPort(Context context) { + int port; + port = SharPreferenceUtil.getPrefInt(context, KeyProtocolServerPort, protocolAPIHelper.getDefaultServerPort()); + return port; + } - SharPreferenceUtil.setPrefString(context,KeyLogServerIP,serverIP); - SharPreferenceUtil.setPrefInt(context,KeyLogServerPort,serverPort); + public static void setConfigInitFlag(Context context, int flag) { + SharPreferenceUtil.setPrefInt(context, "ConfigInitFlag", flag); + } - } - public static String getLogServerIP(Context context){ - return SharPreferenceUtil.getPrefString(context,KeyLogServerIP,"http://icfota.snicker.com.cn:8089/UploadFile.jsp"); - } + public static int getConfigInitFlag(Context context) { + return SharPreferenceUtil.getPrefInt(context, "ConfigInitFlag", 0); + } - public static int getLogServerPort(Context context){ - return SharPreferenceUtil.getPrefInt(context,KeyLogServerPort,8089); - } + public static void setLogServerIP(Context context, String serverIP, int serverPort) { + SharPreferenceUtil.setPrefString(context, KeyLogServerIP, serverIP); + SharPreferenceUtil.setPrefInt(context, KeyLogServerPort, serverPort); - public static void setPPGTestCycle(Context context,int cycle){ - SharPreferenceUtil.setPrefInt(context,KeyPpgTestCycle,cycle); - } + } - public static int getPPGTestCycle(Context context){ - return SharPreferenceUtil.getPrefInt(context,KeyPpgTestCycle,0); - } + public static String getLogServerIP(Context context) { + return SharPreferenceUtil.getPrefString(context, KeyLogServerIP, "http://icfota.snicker.com.cn:8089/UploadFile.jsp"); + } + public static int getLogServerPort(Context context) { + return SharPreferenceUtil.getPrefInt(context, KeyLogServerPort, 8089); + } - public static int getHeartBeatCycle(Context context){ - return SharPreferenceUtil.getPrefInt(context,KeyHeartBeatCycle,5); - } - public static void setHeartBeatCycle(Context context,int cycle){ - SharPreferenceUtil.setPrefInt(context,KeyHeartBeatCycle,cycle); - } - public static void setLocationCycle(Context context,int cycle_second){ - SharPreferenceUtil.setPrefInt(context,KeyLocationCycle,cycle_second); - } + public static void setPPGTestCycle(Context context, int cycle) { + SharPreferenceUtil.setPrefInt(context, KeyPpgTestCycle, cycle); + } - public static int getLocationCycle(Context context){ - return SharPreferenceUtil.getPrefInt(context,KeyLocationCycle,900); - } + public static int getPPGTestCycle(Context context) { + return SharPreferenceUtil.getPrefInt(context, KeyPpgTestCycle, 0); + } - public static void setLocationMode(Context context,int mode){ - ICLogger.i("setLocationMode "+mode); - SharPreferenceUtil.setPrefInt(context,KeyLocationMode,mode); - } + public static int getHeartBeatCycle(Context context) { + return SharPreferenceUtil.getPrefInt(context, KeyHeartBeatCycle, 5); + } - public static int getLocationMode(Context context){ - return SharPreferenceUtil.getPrefInt(context,KeyLocationMode, ICLocation.NORMAL_MOD); - } + public static void setHeartBeatCycle(Context context, int cycle) { + SharPreferenceUtil.setPrefInt(context, KeyHeartBeatCycle, cycle); + } + + public static void setLocationCycle(Context context, int cycle_second) { + SharPreferenceUtil.setPrefInt(context, KeyLocationCycle, cycle_second); + } + + public static int getLocationCycle(Context context) { + return SharPreferenceUtil.getPrefInt(context, KeyLocationCycle, 900); + } + + public static void setLocationMode(Context context, int mode) { + ICLogger.i("setLocationMode " + mode); + SharPreferenceUtil.setPrefInt(context, KeyLocationMode, mode); + } + + + public static int getLocationMode(Context context) { + return SharPreferenceUtil.getPrefInt(context, KeyLocationMode, ICLocation.NORMAL_MOD); + } private static final String KeyBootUpDate = "bootupdate"; - public static boolean logBootDate(Context context){ - //如果时间和最后一次时间不同,则重置,否则启动次数+1 - if (isFirstBootToday(context)) { - SharPreferenceUtil.setPrefString(context, KeyBootUpDate, TimeUtil.getSystemTime4()); - return true; - }else{ - return false; - } - } - - private static String getLastBootupDate(Context context){ - return SharPreferenceUtil.getPrefString(context,KeyBootUpDate,""); - } - private static boolean isFirstBootToday(Context context){ - //第一次启动记录的日期,当前日期只要相同,就认为有启动过。 - //如果手表一直没有重启过,则每次resetStepCount的时候把启动时间更新到当天, - //从而解决第二天重启就会被重置的问题! - String currentDate=TimeUtil.getSystemTime4(); - String lastDate=getLastBootupDate(context); - boolean ret=false; - if (currentDate.equals(lastDate)) { - ret= false; - }else - { - ret= true; - } - ICLogger.i("Current BootDate="+currentDate+", Last BootDate="+lastDate+", ret="+ret); - return ret; - } - - //收到语音微聊广播消息给外部窗口 - public static boolean do_broadCast_message=false; - - //每次心跳时都检测逃逸并报警 - public static boolean needAllwaysAlarmFenceOut=false; - //每次心跳时都检测剪断并报警,只报警 - public static boolean needAllwaysAlarmCutOff=false; - - //体温非正常报警 - public static boolean needTemperature_abnormal_alarm=false; - public static boolean A9_noBroadCastActionStrip=false; - public static boolean C5_noBroadCastActionStrip=false; - public static boolean L004_BroadCastActionStrip=false; - - //停止系统NTP时钟同步标志 - public static boolean disable_ntp_server=false; - - //需要系统发送已阅读消息的标志 - public static boolean noPushTxtReadReply=true; - //蓝牙定位扫描 协议0模式,扫到beacon信标时,如果属于第一次扫到的进入状态(解除逃逸状态),发送服务器的标志位,主要由于C5客户只要逃逸,不要解除逃逸消息。 - public static boolean noBLE_RelaseEscapeAlarm=true; - - public static void enable_NTP_Server(Context context,boolean enable){ - try { - int autotime = Settings.Global.getInt(context.getContentResolver(),Settings.Global.AUTO_TIME); - int autotimezone = Settings.Global.getInt(context.getContentResolver(),Settings.Global.AUTO_TIME_ZONE); - - ICLogger.i("get NTP Settings AutoTime "+autotime+" AutoTimeZone "+autotimezone); - - if(enable) - { - Settings.Global.putInt(context.getContentResolver(), Settings.Global.AUTO_TIME_ZONE, 1); - Settings.Global.putInt(context.getContentResolver(), Settings.Global.AUTO_TIME, 1); - }else { - Settings.Global.putInt(context.getContentResolver(), Settings.Global.AUTO_TIME_ZONE, 0); - Settings.Global.putInt(context.getContentResolver(), Settings.Global.AUTO_TIME, 0); - } - autotime = Settings.Global.getInt(context.getContentResolver(),Settings.Global.AUTO_TIME); - autotimezone = Settings.Global.getInt(context.getContentResolver(),Settings.Global.AUTO_TIME_ZONE); - ICLogger.i("get NTP Settings AutoTime "+autotime+" AutoTimeZone "+autotimezone); - } catch (Settings.SettingNotFoundException e) { - e.printStackTrace(); - ICLogger.e(e.getMessage(),e); - } - } - public static void LoadMessageConfigs(){ - - String tmp=Util.getSystemProperties("persist.sys.doBroadcastMSG"); - boolean ret=false; - if (tmp.equals("true")) - ret=true; - - do_broadCast_message = ret; - - noPPGSensor=(ICJniUtils.isPPGavailable()==0); - noTempSensor=(ICJniUtils.isTemperatureDevAvailable()==0); - - //默认关闭NTP - disable_ntp_server=Util.getSystemProperties("persist.sys.disableNTP","false").equals("true"); - - c43_branch_name=Util.getSystemProperties("persist.sys.c43.branch"); - - if ((c43_branch_name.equals("l03")) ||(c43_branch_name.equals("l05"))){ - noPushTxtNotifyDialog=true; - noSMSNotifyDialog=true; - noVoiceNotifyDialog=true; - noTempSensor=true; - if (c43_branch_name.equals("l05")) { - SOSNoNeedDial=true;//采用新写的SOS,协议只需要发送消息,无需控制拨号。 - noPPGSensor=false; - }else{ - noPPGSensor=true; + + public static boolean logBootDate(Context context) { + //如果时间和最后一次时间不同,则重置,否则启动次数+1 + if (isFirstBootToday(context)) { + SharPreferenceUtil.setPrefString(context, KeyBootUpDate, TimeUtil.getSystemTime4()); + return true; + } else { + return false; + } + } + + private static String getLastBootupDate(Context context) { + return SharPreferenceUtil.getPrefString(context, KeyBootUpDate, ""); + } + + private static boolean isFirstBootToday(Context context) { + //第一次启动记录的日期,当前日期只要相同,就认为有启动过。 + //如果手表一直没有重启过,则每次resetStepCount的时候把启动时间更新到当天, + //从而解决第二天重启就会被重置的问题! + String currentDate = TimeUtil.getSystemTime4(); + String lastDate = getLastBootupDate(context); + boolean ret = false; + if (currentDate.equals(lastDate)) { + ret = false; + } else { + ret = true; + } + ICLogger.i("Current BootDate=" + currentDate + ", Last BootDate=" + lastDate + ", ret=" + ret); + return ret; + } + + //收到语音微聊广播消息给外部窗口 + public static boolean do_broadCast_message = false; + + //每次心跳时都检测逃逸并报警 + public static boolean needAllwaysAlarmFenceOut = false; + //每次心跳时都检测剪断并报警,只报警 + public static boolean needAllwaysAlarmCutOff = false; + + //体温非正常报警 + public static boolean needTemperature_abnormal_alarm = false; + public static boolean A9_noBroadCastActionStrip = false; + public static boolean C5_noBroadCastActionStrip = false; + public static boolean L004_BroadCastActionStrip = false; + + //停止系统NTP时钟同步标志 + public static boolean disable_ntp_server = false; + + //需要系统发送已阅读消息的标志 + public static boolean noPushTxtReadReply = true; + //蓝牙定位扫描 协议0模式,扫到beacon信标时,如果属于第一次扫到的进入状态(解除逃逸状态),发送服务器的标志位,主要由于C5客户只要逃逸,不要解除逃逸消息。 + public static boolean noBLE_RelaseEscapeAlarm = true; + + public static void enable_NTP_Server(Context context, boolean enable) { + try { + int autotime = Settings.Global.getInt(context.getContentResolver(), Settings.Global.AUTO_TIME); + int autotimezone = Settings.Global.getInt(context.getContentResolver(), Settings.Global.AUTO_TIME_ZONE); + + ICLogger.i("get NTP Settings AutoTime " + autotime + " AutoTimeZone " + autotimezone); + + if (enable) { + Settings.Global.putInt(context.getContentResolver(), Settings.Global.AUTO_TIME_ZONE, 1); + Settings.Global.putInt(context.getContentResolver(), Settings.Global.AUTO_TIME, 1); + } else { + Settings.Global.putInt(context.getContentResolver(), Settings.Global.AUTO_TIME_ZONE, 0); + Settings.Global.putInt(context.getContentResolver(), Settings.Global.AUTO_TIME, 0); + } + autotime = Settings.Global.getInt(context.getContentResolver(), Settings.Global.AUTO_TIME); + autotimezone = Settings.Global.getInt(context.getContentResolver(), Settings.Global.AUTO_TIME_ZONE); + ICLogger.i("get NTP Settings AutoTime " + autotime + " AutoTimeZone " + autotimezone); + } catch (Settings.SettingNotFoundException e) { + e.printStackTrace(); + ICLogger.e(e.getMessage(), e); } } - custom_name=Util.getSystemProperties("persist.sys.customname"); - ICLogger.i("get CUSTOMNAME "+custom_name); - if (custom_name.equals("H88")||custom_name.equals("H88A") ){ - noPushTxtNotifyDialog=true; - noSMSNotifyDialog=false; - noVoiceNotifyDialog=false; - noPPGSensor=false; - noTempSensor=false; - needBroadcastAntiAlarm=false; - }else if ((custom_name.equals("AK")) ){ - noPushTxtNotifyDialog=true; - noSMSNotifyDialog=true; - noVoiceNotifyDialog=true; - noPPGSensor=false; - noTempSensor=true; - SOSNoNeedDial=true; //采用新写的SOS,协议只需要发送消息,无需控制拨号。 - }else if ((custom_name.equals("YT")) ){ - noPushTxtNotifyDialog=false; - noSMSNotifyDialog=false; - noVoiceNotifyDialog=false; - noPPGSensor=false; - noTempSensor=true; - }else if ((custom_name.equals("l004")) ) { - noPushTxtNotifyDialog=true; - noSMSNotifyDialog=true; - noVoiceNotifyDialog=true; - needBroadcastAntiAlarm=false; - needBroadcastCutoffAlarm=true; - needAllwaysAlarmCutOff=false; - needAllwaysAlarmFenceOut=false; - needTemperature_abnormal_alarm=false; - noPPGSensor=false; - noTempSensor=false; - L004_BroadCastActionStrip=true; - }else if (custom_name.equals("YQ") ||custom_name.equals("YQ_EN") ) { //A9-YQ - noPushTxtNotifyDialog=false; - noSMSNotifyDialog=true; - noVoiceNotifyDialog=true; - noBroadCastPushTxtNotify=true; - noBroadCastSMSNotify=true; - needBroadcastAntiAlarm=false; - needBroadcastCutoffAlarm=true; - needAllwaysAlarmCutOff=true; - needAllwaysAlarmFenceOut=true; - needTemperature_abnormal_alarm=true; - noPushTxtReadReply=false;//A9需要阅读反馈 - noPPGSensor=false; - noTempSensor=false; - A9_noBroadCastActionStrip=true; - }else if (custom_name.equals("SGL")) - { - noPushTxtNotifyDialog=false; - noSMSNotifyDialog=false; - noVoiceNotifyDialog=true; - needBroadcastAntiAlarm=true; - needBroadcastCutoffAlarm=true; - needAllwaysAlarmCutOff=true; - needAllwaysAlarmFenceOut=false; - needTemperature_abnormal_alarm=false; - noPPGSensor=true; - noTempSensor=true; - C5_noBroadCastActionStrip=true; - }else if(custom_name.equals("L02")){ - noPushTxtReadReply=false;//即爱需要阅读反馈 - }else{ - noBroadCastPushTxtNotify=true; - } - - - } - - public static void loadTemperatureSettings(Runtime runtime){ - runtime.temp_test_Cycle = SharPreferenceUtil.getPrefInt(runtime.getContextProxy().context, KeyTempTestCycle, 60*60); - } - - public static void setTemperatureTestCycle(Runtime runtime,int cycle_seconds) { - SharPreferenceUtil.setPrefInt(runtime.getContextProxy().context,KeyTempTestCycle,cycle_seconds); - loadTemperatureSettings(runtime); - } - public static boolean isUsingCustomServer=false; - - public static void setCustomServer(Context context,boolean isusingCutomerServer,String serverip,int serverport) { - - if (isusingCutomerServer) - Util.setSystemProperties("persist.sys.UsingCustomServer","true"); - else - Util.setSystemProperties("persist.sys.UsingCustomServer","false"); - - - Util.setSystemProperties("persist.sys.customserverip",serverip); - Util.setSystemProperties("persist.sys.customserverport",String.valueOf(serverport)); - setProtocolServerHost(context,serverip); - setProtocolServerPort(context,serverport); - - loadCustomServerAddr(context); - - } - public static void loadCustomServerAddr(Context context){ - String tmp=Util.getSystemProperties("persist.sys.UsingCustomServer"); - boolean ret=false; - if (tmp.equals("true")) - ret=true; - - isUsingCustomServer=ret; - - String serverip=""; - int serverport=0; - if(isUsingCustomServer){ - serverip= Util.getSystemProperties("persist.sys.customserverip"); - serverport= Integer.valueOf(Util.getSystemProperties("persist.sys.customserverport")); - setProtocolServerHost(context,serverip); - setProtocolServerPort(context,serverport); - - }else{ - setProtocolServerHost(context, protocolAPIHelper.getDefaultServerIP()); - setProtocolServerPort(context,protocolAPIHelper.getDefaultServerPort()); - } - ICLogger.i("current protocol_no="+protocol_no+" , isUsingCustomServier="+isUsingCustomServer+", server host="+ - getProtocolServerHost(context)+", server port="+getProtocolServerPort(context)); - } - - public static boolean noLocationCycle=getNoLocationCycleFlag(); - public static boolean getNoLocationCycleFlag(){ - String tmp=Util.getSystemProperties("persist.sys.NoLocationCycle"); - boolean ret=false; - if (tmp.equals("true")) - ret=true; - - noLocationCycle=ret; - return ret; - } - - public static final int PROTOCOL_JIAI=0; - public static final int PROTOCOL_BEEHOME=1; - public static final int PROTOCOL_IC=2; - public static final int PROTOCOL_FZD=3; - public static final int PROTOCOL_MQTT=4; - - public static int protocol_no=getProtocolNumber(); - public static int getProtocolNumber(){ - String tmp=Util.getSystemProperties("persist.sys.protocol_no"); - int ret=0; - if (tmp!=null && !tmp.isEmpty()&& Util.isNumeric(tmp)) { - ret = Integer.parseInt(tmp); - switch(ret){ - case PROTOCOL_JIAI: - ICLogger.i("协议 JIAI"); - break; - case PROTOCOL_BEEHOME: - ICLogger.i("协议 BEEHOME"); - break; - case PROTOCOL_IC: - ICLogger.i("协议 IC"); - break; - case PROTOCOL_FZD: - ICLogger.i("协议 FZD"); - break; - case PROTOCOL_MQTT: - ICLogger.i("协议 MQTT"); - break; - default: - ICLogger.i("协议版本 目前支持0,1,2,3,4 。"); - break; - } - }else{ - ICLogger.i("协议版本要是数字,目前支持0,1,2,3,4 。"); - } - protocol_no=ret; - return ret; - } - - - public static void setPPGAdjust(Context context,int adjust){ - SharPreferenceUtil.setPrefInt(context,KeyPPGadust,adjust); - } - - - public static int getPPGAdjust(Context context){ - return SharPreferenceUtil.getPrefInt(context,KeyPPGadust, 0); - } - - public static void setBPHAdjust(Context context,int adjust){ - SharPreferenceUtil.setPrefInt(context,KeyBPHadust,adjust); - } - - - public static int getBPHAdjust(Context context){ - return SharPreferenceUtil.getPrefInt(context,KeyBPHadust, 0); - } - - - - public static int getBPLAdjust(Context context){ - return SharPreferenceUtil.getPrefInt(context,KeyBPLadust, 0); - } - - public static void setBPLAdjust(Context context,int adjust){ - SharPreferenceUtil.setPrefInt(context,KeyBPLadust,adjust); - } - - public static void setSPo2Adjust(Context context,int adjust){ - SharPreferenceUtil.setPrefInt(context,KeySPo2adust,adjust); - } - - public static int getSPo2Adjust(Context context){ - return SharPreferenceUtil.getPrefInt(context,KeySPo2adust, 0); - } - - public static void loadPPG_BPH_BPL_SPO2_adjustvalue(Context context,Runtime runtime){ - int ppgadj,bphadj,bpladj,spo2adj; - ppgadj=getPPGAdjust(context); - bphadj=getBPHAdjust(context); - bpladj=getBPLAdjust(context); - spo2adj=getSPo2Adjust(context); - runtime.getHRS().setAdjust(ppgadj,bphadj,bpladj,spo2adj); - ICLogger.i("Load Health adjust value ppg "+ppgadj+", bph "+bphadj+", bpl "+bpladj+", spo2 "+spo2adj); - } - - - - //心率血压血氧校准值 - public static String getPPG_ECG_adjustValue(){ - return Util.getSystemProperties("persist.sys."+Constants.SHAREKEY_SETTING_PPG_ECG_ADJUST,"0,0,0,0"); - } - - public static void setPPG_ECG_adjustValue(String adjvalue){ - Util.setSystemProperties("persist.sys."+Constants.SHAREKEY_SETTING_PPG_ECG_ADJUST,adjvalue); - } - - //久坐时间获取 - public static int getKeepSitRangeInMinutes(Context context ){ - return Util.getSystemPropertiesInt("persist.sys."+Constants.SHAREKEY_SETTING_SIT_ALARM_RANGE_IN_MINUTES,0); + + public static void LoadMessageConfigs() { + + String tmp = Util.getSystemProperties("persist.sys.doBroadcastMSG"); + boolean ret = false; + if (tmp.equals("true")) + ret = true; + + do_broadCast_message = ret; + + noPPGSensor = (ICJniUtils.isPPGavailable() == 0); + noTempSensor = (ICJniUtils.isTemperatureDevAvailable() == 0); + + //默认关闭NTP + disable_ntp_server = Util.getSystemProperties("persist.sys.disableNTP", "false").equals("true"); + + c43_branch_name = Util.getSystemProperties("persist.sys.c43.branch"); + + if ((c43_branch_name.equals("l03")) || (c43_branch_name.equals("l05")) || (c43_branch_name.equals("CH"))) { + noPushTxtNotifyDialog = true; + noSMSNotifyDialog = true; + noVoiceNotifyDialog = true; + noTempSensor = true; + if (c43_branch_name.equals("l05") || c43_branch_name.equals("CH")) { + SOSNoNeedDial = true;//采用新写的SOS,协议只需要发送消息,无需控制拨号。 + noPPGSensor = false; + } else { + noPPGSensor = true; + } + } + custom_name = Util.getSystemProperties("persist.sys.customname"); + ICLogger.i("get CUSTOMNAME " + custom_name); + if (custom_name.equals("H88") || custom_name.equals("H88A")) { + noPushTxtNotifyDialog = true; + noSMSNotifyDialog = false; + noVoiceNotifyDialog = false; + noPPGSensor = false; + noTempSensor = false; + needBroadcastAntiAlarm = false; + } else if ((custom_name.equals("AK"))) { + noPushTxtNotifyDialog = true; + noSMSNotifyDialog = true; + noVoiceNotifyDialog = true; + noPPGSensor = false; + noTempSensor = true; + SOSNoNeedDial = true; //采用新写的SOS,协议只需要发送消息,无需控制拨号。 + } else if ((custom_name.equals("YT"))) { + noPushTxtNotifyDialog = false; + noSMSNotifyDialog = false; + noVoiceNotifyDialog = false; + noPPGSensor = false; + noTempSensor = true; + } else if ((custom_name.equals("l004"))) { + noPushTxtNotifyDialog = true; + noSMSNotifyDialog = true; + noVoiceNotifyDialog = true; + needBroadcastAntiAlarm = false; + needBroadcastCutoffAlarm = true; + needAllwaysAlarmCutOff = false; + needAllwaysAlarmFenceOut = false; + needTemperature_abnormal_alarm = false; + noPPGSensor = false; + noTempSensor = false; + L004_BroadCastActionStrip = true; + } else if (custom_name.equals("YQ") || custom_name.equals("YQ_EN")) { //A9-YQ + noPushTxtNotifyDialog = false; + noSMSNotifyDialog = true; + noVoiceNotifyDialog = true; + noBroadCastPushTxtNotify = true; + noBroadCastSMSNotify = true; + needBroadcastAntiAlarm = false; + needBroadcastCutoffAlarm = true; + needAllwaysAlarmCutOff = true; + needAllwaysAlarmFenceOut = true; + needTemperature_abnormal_alarm = true; + noPushTxtReadReply = false;//A9需要阅读反馈 + noPPGSensor = false; + noTempSensor = false; + A9_noBroadCastActionStrip = true; + } else if (custom_name.equals("SGL")) { + noPushTxtNotifyDialog = false; + noSMSNotifyDialog = false; + noVoiceNotifyDialog = true; + needBroadcastAntiAlarm = true; + needBroadcastCutoffAlarm = true; + needAllwaysAlarmCutOff = true; + needAllwaysAlarmFenceOut = false; + needTemperature_abnormal_alarm = false; + noPPGSensor = true; + noTempSensor = true; + C5_noBroadCastActionStrip = true; + } else if (custom_name.equals("L02")) { + noPushTxtReadReply = false;//即爱需要阅读反馈 + } else { + noBroadCastPushTxtNotify = true; + } + + + } + + public static void loadTemperatureSettings(Runtime runtime) { + runtime.temp_test_Cycle = SharPreferenceUtil.getPrefInt(runtime.getContextProxy().context, KeyTempTestCycle, 60 * 60); + } + + public static void setTemperatureTestCycle(Runtime runtime, int cycle_seconds) { + SharPreferenceUtil.setPrefInt(runtime.getContextProxy().context, KeyTempTestCycle, cycle_seconds); + loadTemperatureSettings(runtime); + } + + public static boolean isUsingCustomServer = false; + + public static void setCustomServer(Context context, boolean isusingCutomerServer, String serverip, int serverport) { + + if (isusingCutomerServer) + Util.setSystemProperties("persist.sys.UsingCustomServer", "true"); + else + Util.setSystemProperties("persist.sys.UsingCustomServer", "false"); + + + Util.setSystemProperties("persist.sys.customserverip", serverip); + Util.setSystemProperties("persist.sys.customserverport", String.valueOf(serverport)); + setProtocolServerHost(context, serverip); + setProtocolServerPort(context, serverport); + + loadCustomServerAddr(context); + + } + + public static void loadCustomServerAddr(Context context) { + String tmp = Util.getSystemProperties("persist.sys.UsingCustomServer"); + boolean ret = false; + if (tmp.equals("true")) + ret = true; + + isUsingCustomServer = ret; + + String serverip = ""; + int serverport = 0; + if (isUsingCustomServer) { + serverip = Util.getSystemProperties("persist.sys.customserverip"); + serverport = Integer.valueOf(Util.getSystemProperties("persist.sys.customserverport")); + Integer.valueOf(Util.getSystemProperties("persist.sys.customserverport")); + setProtocolServerHost(context, serverip); + setProtocolServerPort(context, serverport); + + } else { + setProtocolServerHost(context, protocolAPIHelper.getDefaultServerIP()); + setProtocolServerPort(context, protocolAPIHelper.getDefaultServerPort()); + } + ICLogger.i("current protocol_no=" + protocol_no + " , isUsingCustomServier=" + isUsingCustomServer + ", server host=" + + getProtocolServerHost(context) + ", server port=" + getProtocolServerPort(context)); + } + + public static boolean noLocationCycle = getNoLocationCycleFlag(); + + public static boolean getNoLocationCycleFlag() { + String tmp = Util.getSystemProperties("persist.sys.NoLocationCycle"); + boolean ret = false; + if (tmp.equals("true")) + ret = true; + + noLocationCycle = ret; + return ret; + } + + public static final int PROTOCOL_JIAI = 0; + public static final int PROTOCOL_BEEHOME = 1; + public static final int PROTOCOL_IC = 2; + public static final int PROTOCOL_FZD = 3; + public static final int PROTOCOL_MQTT = 4; + + public static int protocol_no = getProtocolNumber(); + + public static int getProtocolNumber() { + String tmp = Util.getSystemProperties("persist.sys.protocol_no"); + int ret = 0; + if (tmp != null && !tmp.isEmpty() && Util.isNumeric(tmp)) { + ret = Integer.parseInt(tmp); + switch (ret) { + case PROTOCOL_JIAI: + ICLogger.i("协议 JIAI"); + break; + case PROTOCOL_BEEHOME: + ICLogger.i("协议 BEEHOME"); + break; + case PROTOCOL_IC: + ICLogger.i("协议 IC"); + break; + case PROTOCOL_FZD: + ICLogger.i("协议 FZD"); + break; + case PROTOCOL_MQTT: + ICLogger.i("协议 MQTT"); + break; + default: + ICLogger.i("协议版本 目前支持0,1,2,3,4 。"); + break; + } + } else { + ICLogger.i("协议版本要是数字,目前支持0,1,2,3,4 。"); + } + protocol_no = ret; + return ret; + } + + + public static void setPPGAdjust(Context context, int adjust) { + SharPreferenceUtil.setPrefInt(context, KeyPPGadust, adjust); + } + + + public static int getPPGAdjust(Context context) { + return SharPreferenceUtil.getPrefInt(context, KeyPPGadust, 0); + } + + public static void setBPHAdjust(Context context, int adjust) { + SharPreferenceUtil.setPrefInt(context, KeyBPHadust, adjust); + } + + + public static int getBPHAdjust(Context context) { + return SharPreferenceUtil.getPrefInt(context, KeyBPHadust, 0); + } + + + public static int getBPLAdjust(Context context) { + return SharPreferenceUtil.getPrefInt(context, KeyBPLadust, 0); + } + + public static void setBPLAdjust(Context context, int adjust) { + SharPreferenceUtil.setPrefInt(context, KeyBPLadust, adjust); + } + + public static void setSPo2Adjust(Context context, int adjust) { + SharPreferenceUtil.setPrefInt(context, KeySPo2adust, adjust); + } + + public static int getSPo2Adjust(Context context) { + return SharPreferenceUtil.getPrefInt(context, KeySPo2adust, 0); + } + + public static void loadPPG_BPH_BPL_SPO2_adjustvalue(Context context, Runtime runtime) { + int ppgadj, bphadj, bpladj, spo2adj; + ppgadj = getPPGAdjust(context); + bphadj = getBPHAdjust(context); + bpladj = getBPLAdjust(context); + spo2adj = getSPo2Adjust(context); + runtime.getHRS().setAdjust(ppgadj, bphadj, bpladj, spo2adj); + ICLogger.i("Load Health adjust value ppg " + ppgadj + ", bph " + bphadj + ", bpl " + bpladj + ", spo2 " + spo2adj); + } + + + //心率血压血氧校准值 + public static String getPPG_ECG_adjustValue() { + return Util.getSystemProperties("persist.sys." + Constants.SHAREKEY_SETTING_PPG_ECG_ADJUST, "0,0,0,0"); + } + + public static void setPPG_ECG_adjustValue(String adjvalue) { + Util.setSystemProperties("persist.sys." + Constants.SHAREKEY_SETTING_PPG_ECG_ADJUST, adjvalue); + } + + //久坐时间获取 + public static int getKeepSitRangeInMinutes(Context context) { + return Util.getSystemPropertiesInt("persist.sys." + Constants.SHAREKEY_SETTING_SIT_ALARM_RANGE_IN_MINUTES, 0); // return SharPreferenceUtil.getPrefIntPublic(context,Constants.SHAREKEY_SETTING_SIT_ALARM_RANGE_IN_MINUTES,0); - } + } - //久坐时间设置 - public static void setKeepSitRangeInMinutes(Context context, int RangeInMinutes){ - Util.setSystemProperties("persist.sys."+Constants.SHAREKEY_SETTING_SIT_ALARM_RANGE_IN_MINUTES,RangeInMinutes); + //久坐时间设置 + public static void setKeepSitRangeInMinutes(Context context, int RangeInMinutes) { + Util.setSystemProperties("persist.sys." + Constants.SHAREKEY_SETTING_SIT_ALARM_RANGE_IN_MINUTES, RangeInMinutes); // SharPreferenceUtil.setPrefIntPublic(context,Constants.SHAREKEY_SETTING_SIT_ALARM_RANGE_IN_MINUTES,RangeInMinutes); - } + } - public static void setSleepDate(Context context,String dateyyyyMMddHHmmss){ - Util.setSystemProperties("persist.sys."+Constants.SHAREKEY_SETTING_SLEEP_SCORE_DATE,dateyyyyMMddHHmmss); + public static void setSleepDate(Context context, String dateyyyyMMddHHmmss) { + Util.setSystemProperties("persist.sys." + Constants.SHAREKEY_SETTING_SLEEP_SCORE_DATE, dateyyyyMMddHHmmss); // SharPreferenceUtil.setPrefStringPublic(context,Constants.SHAREKEY_SETTING_SLEEP_SCORE_DATE,dateyyyyMMddHHmmss); - } + } - public static void setSleepScore(Context context,int score){ + public static void setSleepScore(Context context, int score) { // SharPreferenceUtil.setPrefIntPublic(context,Constants.SHAREKEY_SETTING_SLEEP_SCORE,score); - Util.setSystemProperties("persist.sys."+Constants.SHAREKEY_SETTING_SLEEP_SCORE,score); + Util.setSystemProperties("persist.sys." + Constants.SHAREKEY_SETTING_SLEEP_SCORE, score); + + } + + public static String getSleepDate(Context context) { + return Util.getSystemProperties("persist.sys." + Constants.SHAREKEY_SETTING_SLEEP_SCORE_DATE, ""); + } + + + public static int getSleepScore(Context context) { + + return Util.getSystemPropertiesInt("persist.sys." + Constants.SHAREKEY_SETTING_SLEEP_SCORE, 0); + + } - } + public static void setNeedCutOff(Context context, boolean enAnti) { + SharPreferenceUtil.setPrefBoolean(context, "NeedCutOff", enAnti); + } - public static String getSleepDate(Context context){ - return Util.getSystemProperties("persist.sys."+Constants.SHAREKEY_SETTING_SLEEP_SCORE_DATE,""); + public static boolean getNeedCutOff(Context context) { + return SharPreferenceUtil.getPrefBoolean(context, "NeedCutOff", false); } + public static void setNeedAntiOff(Context context, boolean enAnti) { + SharPreferenceUtil.setPrefBoolean(context, "NeedAntiOff", enAnti); + } - public static int getSleepScore(Context context){ + public static boolean getNeedAntiOff(Context context) { + return SharPreferenceUtil.getPrefBoolean(context, "NeedAntiOff", false); + } - return Util.getSystemPropertiesInt("persist.sys."+Constants.SHAREKEY_SETTING_SLEEP_SCORE,0); + public static boolean enableSleep = false; + /** + * 参考数据,平均每分钟步数来判断,大于 KeepSitJudgementRefValue 认为没有坐着。小于等于这个值认为坐着。 + */ + public static int KeepSitJudgementRefValue = 30; + + /*** + * persist.sys.alarmConfig=ALARM_SOS,ALARM_LOWBATTERY,ALARM_ANTIOFF,ALARM_WEARED,ALARM_CUTOFF,ALARM_FALL,ALARM_ABNORMAL_HEART_RATE,ALARM_HEART_RATE_HIGH,ALARM_HEART_RATE_LOW,ALARM_BPH_HIGH,ALARM_BPH_LOW,ALARM_BPL_HIGH,ALARM_BPL_LOW,ALARM_SEDENTARY,ALARM_ILLEGAL_CUTOFF,ALARM_LOCK_WATCH,ALARM_TEMP_HIGH,ALARM_TEMP_LOW,ALARM_POWER_OFF,ALARM_ESCAPE,ALARM_NONE + * 配在里面的表示开启,没配的表示关闭。 默认ALARM_SOS,ALARM_LOWBATTERY,ALARM_POWER_OFF开启 + * ALARM_ILLEGAL_CUTOFF,ALARM_FALL,ALARM_ABNORMAL_HEART_RATE 没有使用,设置了也没有用 + */ + public static void loadAlarmConfig() { + String configvalues = Util.getSystemProperties("persist.sys.alarmConfig", ""); + String[] values = configvalues.split(","); + if (values.length > 0) { + for (int i = 0; i < values.length; i++) { + for (Runtime.AlarmType at : Runtime.AlarmType.values()) { + if (values[i].trim().equals(at.name())) { + ConfigAlarm(at, true); + break; + } + } + } + } + dumpAlarmConfig(); + } + public static void ConfigAlarm(Runtime.AlarmType alarmType, boolean enabled) { + AlarmConfiglist.put(alarmType.ordinal(), enabled); } - public static void setNeedCutOff(Context context,boolean enAnti){ - SharPreferenceUtil.setPrefBoolean(context,"NeedCutOff",enAnti); - } - public static boolean getNeedCutOff(Context context){ - return SharPreferenceUtil.getPrefBoolean(context,"NeedCutOff", false); - } - public static void setNeedAntiOff(Context context,boolean enAnti){ - SharPreferenceUtil.setPrefBoolean(context,"NeedAntiOff",enAnti); + public static void dumpAlarmConfig() { + for (int i = 0; i < AlarmConfiglist.size(); i++) { + ICLogger.i(Runtime.AlarmType.values()[i].name() + " " + AlarmConfiglist.get(i)); + } } - public static boolean getNeedAntiOff(Context context){ - return SharPreferenceUtil.getPrefBoolean(context,"NeedAntiOff", false); + private static HashMap AlarmConfiglist; + + static { + AlarmConfiglist = new HashMap(); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_SOS.ordinal(), true); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_LOWBATTERY.ordinal(), true); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_ANTIOFF.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_WEARED.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_CUTOFF.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_FALL.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_ABNORMAL_HEART_RATE.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_HEART_RATE_HIGH.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_HEART_RATE_LOW.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPH_HIGH.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPH_LOW.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPL_HIGH.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPL_LOW.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_SEDENTARY.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_LOCK_WATCH.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_TEMP_HIGH.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_TEMP_LOW.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_POWER_OFF.ordinal(), true); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_ESCAPE.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_NONE.ordinal(), false); + AlarmConfiglist.put(Runtime.AlarmType.ALARM_REMOVE_SOS.ordinal(), true); } - public static boolean enableSleep=false; - /** - * 参考数据,平均每分钟步数来判断,大于 KeepSitJudgementRefValue 认为没有坐着。小于等于这个值认为坐着。 - */ - public static int KeepSitJudgementRefValue=30; - /*** - * persist.sys.alarmConfig=ALARM_SOS,ALARM_LOWBATTERY,ALARM_ANTIOFF,ALARM_WEARED,ALARM_CUTOFF,ALARM_FALL,ALARM_ABNORMAL_HEART_RATE,ALARM_HEART_RATE_HIGH,ALARM_HEART_RATE_LOW,ALARM_BPH_HIGH,ALARM_BPH_LOW,ALARM_BPL_HIGH,ALARM_BPL_LOW,ALARM_SEDENTARY,ALARM_ILLEGAL_CUTOFF,ALARM_LOCK_WATCH,ALARM_TEMP_HIGH,ALARM_TEMP_LOW,ALARM_POWER_OFF,ALARM_ESCAPE,ALARM_NONE - * 配在里面的表示开启,没配的表示关闭。 默认ALARM_SOS,ALARM_LOWBATTERY,ALARM_POWER_OFF开启 - * ALARM_ILLEGAL_CUTOFF,ALARM_FALL,ALARM_ABNORMAL_HEART_RATE 没有使用,设置了也没有用 - */ - public static void loadAlarmConfig(){ - String configvalues=Util.getSystemProperties("persist.sys.alarmConfig",""); - String[] values=configvalues.split(","); - if (values.length>0){ - for (int i=0; i< values.length;i++) - { - for (Runtime.AlarmType at: Runtime.AlarmType.values()) { - if (values[i].trim().equals(at.name())){ - ConfigAlarm(at,true); - break; - } + public static boolean isAlarmTypeEnabled(Runtime.AlarmType alarmType) { + + boolean en = false; + if (AlarmConfiglist.containsKey(alarmType.ordinal())) { + en = AlarmConfiglist.get(alarmType.ordinal()); } - } - } - dumpAlarmConfig(); - } - - public static void ConfigAlarm(Runtime.AlarmType alarmType,boolean enabled){ - AlarmConfiglist.put(alarmType.ordinal(),enabled); - } - public static void dumpAlarmConfig(){ - for (int i=0;i AlarmConfiglist; - static { - AlarmConfiglist=new HashMap(); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_SOS.ordinal(),true); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_LOWBATTERY.ordinal(),true); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_ANTIOFF.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_WEARED.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_CUTOFF.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_FALL.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_ABNORMAL_HEART_RATE.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_HEART_RATE_HIGH.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_HEART_RATE_LOW.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPH_HIGH.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPH_LOW.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPL_HIGH.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPL_LOW.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_SEDENTARY.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_LOCK_WATCH.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_TEMP_HIGH.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_TEMP_LOW.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_POWER_OFF.ordinal(),true); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_ESCAPE.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_NONE.ordinal(),false); - AlarmConfiglist.put(Runtime.AlarmType.ALARM_REMOVE_SOS.ordinal(),true); - } - - public static boolean isAlarmTypeEnabled(Runtime.AlarmType alarmType){ - - boolean en=false; - if (AlarmConfiglist.containsKey(alarmType.ordinal())){ - en=AlarmConfiglist.get(alarmType.ordinal()); - } - return en; - } - public static boolean needWaterMark(){ - String customname=getSystemProperties("persist.sys.needWaterMark","true"); - if(customname.trim().equals("true")){ - return true; - }else - return false; - } + return en; + } + + public static boolean needWaterMark() { + String customname = getSystemProperties("persist.sys.needWaterMark", "true"); + if (customname.trim().equals("true")) { + return true; + } else + return false; + } } diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 9756a510..9e9acfe5 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -4,42 +4,27 @@ import android.app.AlarmManager; import android.app.Notification; import android.app.PendingIntent; import android.app.Service; -import android.content.IClipboard; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.media.AudioManager; -import android.media.MediaRouter; import android.os.Handler; import android.os.IBinder; - import android.os.Message; import android.os.Messenger; import android.os.PowerManager; import android.os.SystemClock; import android.widget.Toast; -import com.enqualcomm.support.adapter.BTHelper; +import com.enqualcomm.support.adapter.LBSHelper; import com.enqualcomm.support.bean.Contact; -import com.enqualcomm.support.bean.ICLocation; +import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.bean.SleepInfo; import com.enqualcomm.support.bean.SleepRecord; -import com.enqualcomm.support.service.AntiMonitorService; -import com.enqualcomm.support.utils.CellInfoUtil; -import com.enqualcomm.support.utils.Connection; -import com.enqualcomm.support.utils.DeviceInfoUtil; -import com.enqualcomm.support.utils.ICHttpUtil; -import com.enqualcomm.support.utils.LedUtil; -import com.enqualcomm.support.utils.StorageUtils; -import com.enqualcomm.support.utils.TemperatureUtil; -import com.enqualcomm.support.utils.TimeUtil; -import com.enqualcomm.support.utils.VibrateUtil; -import com.enqualcomm.support.utils.WakeLockUtil; -import com.enqualcomm.support.utils.mqttConnection; -import com.ic.jni.ICJniUtils; -import com.enqualcomm.support.adapter.LBSHelper; -import com.ic.protocols.protocolAPIHelper; -import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.bean.StringMessage; import com.enqualcomm.support.bean.heartRateStatus; +import com.enqualcomm.support.service.AntiMonitorService; import com.enqualcomm.support.service.CheckSIM; import com.enqualcomm.support.service.Deliver; import com.enqualcomm.support.service.HeartRateManager; @@ -52,39 +37,44 @@ import com.enqualcomm.support.service.base.AbstractInvokeHandlerService; import com.enqualcomm.support.utils.AlarmHelper; import com.enqualcomm.support.utils.AlarmWakeUp; import com.enqualcomm.support.utils.BatteryUtil; +import com.enqualcomm.support.utils.CellInfoUtil; +import com.enqualcomm.support.utils.Connection; import com.enqualcomm.support.utils.ConnectionListener; import com.enqualcomm.support.utils.ContextProxy; import com.enqualcomm.support.utils.DBHelper; +import com.enqualcomm.support.utils.DeviceInfoUtil; import com.enqualcomm.support.utils.FileOutputUtil; import com.enqualcomm.support.utils.ICLogger; +import com.enqualcomm.support.utils.LedUtil; import com.enqualcomm.support.utils.NettyConnection; import com.enqualcomm.support.utils.SharPreferenceUtil; import com.enqualcomm.support.utils.SimSignalUtil; +import com.enqualcomm.support.utils.TemperatureUtil; +import com.enqualcomm.support.utils.TimeUtil; import com.enqualcomm.support.utils.Util; +import com.enqualcomm.support.utils.VibrateUtil; +import com.enqualcomm.support.utils.WakeLockUtil; +import com.enqualcomm.support.utils.mqttConnection; +import com.ic.jni.ICJniUtils; +import com.ic.protocols.protocolAPIHelper; import java.lang.ref.WeakReference; -import chestnut.ui.Toastc; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.IntentFilter; - import java.util.ArrayList; import java.util.Random; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import chestnut.ui.Toastc; + import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; import static com.enqualcomm.support.Constants.ACTION_ALARM_ADD_DATAPOINTS; import static com.enqualcomm.support.Constants.ACTION_ALARM_ALARM_CHANGE; import static com.enqualcomm.support.Constants.ACTION_ALARM_BLE_SCAN; -import static com.enqualcomm.support.Constants.ACTION_ALARM_CHECK_ANTI; import static com.enqualcomm.support.Constants.ACTION_CHECK_ANTIOFF_EVENT; import static com.enqualcomm.support.Constants.ACTION_EQC_ALARM; import static com.enqualcomm.support.Constants.ACTION_HEATR_RATE_START; import static com.enqualcomm.support.Constants.ACTION_LOCAL_SOS_ACTION; import static com.enqualcomm.support.Constants.ACTION_LOCATION_ALARM; -import static com.enqualcomm.support.Constants.ACTION_PRACTICE_REPORT_ALARM; import static com.enqualcomm.support.Constants.ACTION_QUERY_WEATHER; import static com.enqualcomm.support.Constants.ACTION_SEND_EMEGENCY_LOCATION_START; import static com.enqualcomm.support.Constants.ACTION_SEND_EMEGENCY_LOCATION_STOP; @@ -92,12 +82,15 @@ import static com.enqualcomm.support.Constants.ANTI_ALARM; import static com.enqualcomm.support.Constants.HEART_ALARM; import static com.enqualcomm.support.Constants.KEY_SAVE_STEP_COUNT; import static com.enqualcomm.support.Constants.KEY_STEP_COUNT; -import static com.enqualcomm.support.Constants.KEY_TEMP_BODY; -import static com.enqualcomm.support.Constants.KEY_TEMP_WRIST; import static com.enqualcomm.support.Constants.STEP_COUNT_ALARM_ACTION; import static com.enqualcomm.support.Constants.TEMP_ALARM; -import static com.enqualcomm.support.bean.ICLocation.*; -import static com.ic.protocols.protocolAPIHelper.getTemperatureMSG; +import static com.enqualcomm.support.bean.ICLocation.CUSTOM_MOD; +import static com.enqualcomm.support.bean.ICLocation.CUSTOM_MOD8_GPS; +import static com.enqualcomm.support.bean.ICLocation.CUSTOM_MOD8_WIFI; +import static com.enqualcomm.support.bean.ICLocation.EMERGNECY_MOD; +import static com.enqualcomm.support.bean.ICLocation.LOWPOWER_MOD; +import static com.enqualcomm.support.bean.ICLocation.NORMAL_MOD; +import static com.enqualcomm.support.bean.ICLocation.REALTIME_MOD; public class CoreService extends Service { @@ -105,20 +98,20 @@ public class CoreService extends Service { private Toastc toast = null; - private static CoreService mProtocolServer=null; - private static LBSHelper lbshelper=null; + private static CoreService mProtocolServer = null; + private static LBSHelper lbshelper = null; public static final String ACTION_ALARM = "com.enqualcomm.support.ACTION_ALARM"; - private static final int GRAY_SERVICE_ID =android.os.Process.myPid(); + private static final int GRAY_SERVICE_ID = android.os.Process.myPid(); - private static final String MY_WAKE_LOCKTAG =CoreService.class.getSimpleName(); + private static final String MY_WAKE_LOCKTAG = CoreService.class.getSimpleName(); public static int alarmCycle = 5; public static final int interval = 60000; - public static boolean needLocateInAfterHeartBeat=false; + public static boolean needLocateInAfterHeartBeat = false; private static int is_allowed_in_sleep_mode = 1; private static boolean is_in_sleep_mode = false; @@ -127,10 +120,11 @@ public class CoreService extends Service { // SPRD: add outdoorMode public static final int RINGER_MODE_OUTDOOR = 3; - public static Handler mHandler=new Handler(); - private static ICSmsManager smsManager=null; - public String getServerAlive(){ - return DeviceInfoUtil.getDeviceInfo(runtime); + public static Handler mHandler = new Handler(); + private static ICSmsManager smsManager = null; + + public String getServerAlive() { + return DeviceInfoUtil.getDeviceInfo(runtime); } private BroadcastReceiver AtCallbackBroadcastReceiver = new BroadcastReceiver() { @@ -152,7 +146,7 @@ public class CoreService extends Service { stringBuilder1.append(Integer.valueOf(str, 16)); stringBuilder1.append(",CELLID="); stringBuilder1.append(Integer.valueOf(str1, 16)); - if (Config.LOG_TOFILE) ICLogger.logToFile( "LBS", stringBuilder1.toString()); + if (Config.LOG_TOFILE) ICLogger.logToFile("LBS", stringBuilder1.toString()); } } } @@ -164,10 +158,10 @@ public class CoreService extends Service { StringBuilder stringBuilder2 = new StringBuilder(); stringBuilder2.append("broadcastReceiver alarmCycle action=="); stringBuilder2.append(param1Intent.getAction()); - if (Config.LOG_TOFILE) ICLogger.logToFile( "alarmCycle", stringBuilder2.toString()); + if (Config.LOG_TOFILE) ICLogger.logToFile("alarmCycle", stringBuilder2.toString()); StringBuilder stringBuilder1 = new StringBuilder(); stringBuilder1.append("时间变化"); - stringBuilder1.append(param1Intent.getAction()+stringBuilder2.toString()); + stringBuilder1.append(param1Intent.getAction() + stringBuilder2.toString()); ICLogger.i(stringBuilder1.toString()); //只有需要确定绝对时间点启动的Alarm需要重置,相对时间点的Alarm不需要重置。防止永远不能正常登陆。 @@ -176,8 +170,8 @@ public class CoreService extends Service { // setHeartAlarm(); // setHeartRateDetectAlarm(runtime.getPpgTestCycle()); setWeatherAlarm(); - runtime.getContextProxy().sendBroadcast(ACTION_ALARM_ALARM_CHANGE,runtime); //更新Alarm - // setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); + runtime.getContextProxy().sendBroadcast(ACTION_ALARM_ALARM_CHANGE, runtime); //更新Alarm + // setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); if (cmcm_call_eiot_into_powersave_mode() == 0) AlarmWakeUp.isNeedWakeUpAlarm(runtime); } @@ -190,7 +184,7 @@ public class CoreService extends Service { stringBuilder2.append(param1Intent.getAction()); ICLogger.i(stringBuilder2.toString()); - if (ACTION_SEND_EMEGENCY_LOCATION_START.equals(param1Intent.getAction())){ + if (ACTION_SEND_EMEGENCY_LOCATION_START.equals(param1Intent.getAction())) { runtime.getLocationInstance().setWorkingMod(EMERGNECY_MOD); //runtime.setPpgTestCycle(1); setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); @@ -200,67 +194,69 @@ public class CoreService extends Service { setEmegencyLocationSTOPAlarm(5); - }else if (ACTION_LOCAL_SOS_ACTION.endsWith(param1Intent.getAction())){ + } else if (ACTION_LOCAL_SOS_ACTION.endsWith(param1Intent.getAction())) { VibrateUtil.getInstance(runtime.getContextProxy().context).VibrateOn(true); // if( param1Intent.getIntExtra("type", 1) == 1) { - boolean needHRSTestOnSOS = Util.getSystemProperties("persist.sys.needHRSOnSOS","false").equals("true"); - if(needHRSTestOnSOS) { + boolean needHRSTestOnSOS = Util.getSystemProperties("persist.sys.needHRSOnSOS", "false").equals("true"); + if (needHRSTestOnSOS) { //触发一次心率检测 setHeartRateDetectAlarm(1); } - runtime.setAlarmType(Runtime.AlarmType.ALARM_SOS); - //trigger AP10 报警定位 - ICLogger.i("triggerSOSLocationProcess "); - LocationClient.getInstance().triggerSOSLocationProcess(); + runtime.setAlarmType(Runtime.AlarmType.ALARM_SOS); + //trigger AP10 报警定位 + ICLogger.i("triggerSOSLocationProcess "); + LocationClient.getInstance().triggerSOSLocationProcess(); // Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); - //开启紧急定位模式,GPS 优先1分钟一次定位,持续5分钟 - runtime.getLocationInstance().setWorkingMod(EMERGNECY_MOD); - setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); + //开启紧急定位模式,GPS 优先1分钟一次定位,持续5分钟 + runtime.getLocationInstance().setWorkingMod(EMERGNECY_MOD); + setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); - //SOS模式,心率测试1分钟一次,持续5分钟 - if(needHRSTestOnSOS) { - //只触发一次心率检测 - setHeartRateDetectAlarm(1); - } - //设置5分钟后结束紧急定位模式 - setEmegencyLocationSTOPAlarm(5); + //SOS模式,心率测试1分钟一次,持续5分钟 + if (needHRSTestOnSOS) { + //只触发一次心率检测 + setHeartRateDetectAlarm(1); + } + //设置5分钟后结束紧急定位模式 + setEmegencyLocationSTOPAlarm(5); - if(Config.SOSNoNeedDial==false) { - //50ms后开始拨打电话 - mHandler.postDelayed(mTriggerSOSCALLThread,500); - } - }else if (ACTION_QUERY_WEATHER.equals(param1Intent.getAction())) { + if (Config.SOSNoNeedDial == false) { + //50ms后开始拨打电话 + mHandler.postDelayed(mTriggerSOSCALLThread, 500); + } + } else if (ACTION_QUERY_WEATHER.equals(param1Intent.getAction())) { ICLogger.i("ACTION_QUERY_WEATHER "); connection.send(protocolAPIHelper.getWeatherMSG(runtime)); - } + } } }; - private TriggerSOSCALLThread mTriggerSOSCALLThread=new TriggerSOSCALLThread(); + private TriggerSOSCALLThread mTriggerSOSCALLThread = new TriggerSOSCALLThread(); - private class TriggerSOSCALLThread implements Runnable{ + private class TriggerSOSCALLThread implements Runnable { @Override public void run() { trigger_SOS_Call(); } } - private void trigger_SOS_Call(){ + + private void trigger_SOS_Call() { try { Intent intent = new Intent("com.eqc.shutdown_sos"); - intent.putExtra("type",1); + intent.putExtra("type", 1); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } } - private Runnable mupdatePracticeData=new Runnable(){ + + private Runnable mupdatePracticeData = new Runnable() { @Override public void run() { //ICHttpUtil.uploadData(Runtime.healthInfo.getBufferDataStr(),runtime,TimeUtil.getSystemTime2(),null); @@ -272,31 +268,30 @@ public class CoreService extends Service { private BroadcastReceiver broadcastPracticeCMDReceiver = new BroadcastReceiver() { public void onReceive(Context param1Context, Intent param1Intent) { - if(param1Intent.getAction().equals(Constants.ACTION_START_PRACTISE)) - { - int cmd=param1Intent.getIntExtra(Constants.KeyPractice,0); - if (cmd==1){ + if (param1Intent.getAction().equals(Constants.ACTION_START_PRACTISE)) { + int cmd = param1Intent.getIntExtra(Constants.KeyPractice, 0); + if (cmd == 1) { //开始自由锻炼 - Runtime.practising=true; - Util.setSystemProperties( Config.KeyPractiseState,"true"); + Runtime.practising = true; + Util.setSystemProperties(Config.KeyPractiseState, "true"); Runtime.healthInfo.reset(); Runtime.healthInfo.resetBuffer(); setPracticeAlarm(); - }else{ + } else { //停止自由锻炼,恢复正常 - Runtime.practising=false; - Util.setSystemProperties( Config.KeyPractiseState,"false"); + Runtime.practising = false; + Util.setSystemProperties(Config.KeyPractiseState, "false"); HeartRateManager.stopPPGtest(); //最后检测是否还有数据需要发送 - if(Runtime.healthInfo.check_info_item_finished()){ + if (Runtime.healthInfo.check_info_item_finished()) { Runtime.healthInfo.appendBuffer(Runtime.healthInfo.getHealthInfoString()); Runtime.healthInfo.reset(); - } - if(Runtime.healthInfo.getInfoCount()>=0){ + } + if (Runtime.healthInfo.getInfoCount() >= 0) { //超过30次发送数据给服务器 - ICLogger.i("自由锻炼结束,发送数据给服务器 "+Runtime.healthInfo.getBufferData().length); + ICLogger.i("自由锻炼结束,发送数据给服务器 " + Runtime.healthInfo.getBufferData().length); mHandler.post(mupdatePracticeData); } @@ -308,19 +303,22 @@ public class CoreService extends Service { private static class ServerHandler implements ConnectionListener { private final WeakReference mReference; - ServerHandler(CoreService param1CoreService) { this.mReference = new WeakReference(param1CoreService); } + ServerHandler(CoreService param1CoreService) { + this.mReference = new WeakReference(param1CoreService); + } @Override public void onConnectionClose(String errorName) { - CoreService coreService = (CoreService)this.mReference.get(); + CoreService coreService = (CoreService) this.mReference.get(); if (coreService == null) return; - ICLogger.i("onConnectionClose++ retry to connect again! Close Error "+errorName); - coreService.connectionServiceChain.processConnectionClose(coreService.connection, coreService.runtime,errorName); + ICLogger.i("onConnectionClose++ retry to connect again! Close Error " + errorName); + coreService.connectionServiceChain.processConnectionClose(coreService.connection, coreService.runtime, errorName); } + @Override public void onConnectionOpen() { - CoreService coreService = (CoreService)this.mReference.get(); + CoreService coreService = (CoreService) this.mReference.get(); if (coreService == null) return; coreService.connectionServiceChain.processConnectionOpen(coreService.connection, coreService.runtime); @@ -329,14 +327,15 @@ public class CoreService extends Service { public void onReceive(StringMessage param1StringMessage) { - CoreService coreService = (CoreService)this.mReference.get(); - ICLogger.i("onReceive " +param1StringMessage.cmd() +" coreService " + coreService ); + CoreService coreService = (CoreService) this.mReference.get(); + ICLogger.i("onReceive " + param1StringMessage.cmd() + " coreService " + coreService); if (coreService == null) return; coreService.connectionServiceChain.processServerResponse(param1StringMessage, coreService.connection, coreService.runtime); coreService.locationClient.onReceive(param1StringMessage); } } + Connection connection = null; AbstractConnectionService connectionServiceChain; @@ -389,7 +388,7 @@ public class CoreService extends Service { //为了保证唤醒时各个状态及时更新到服务器,发送一个同步心跳包,这样用户体验更好 CoreService.this.locationClient.updateStepCount(); - mHandler.postDelayed(mRetryConnectSrvThread,500); + mHandler.postDelayed(mRetryConnectSrvThread, 500); if (CoreService.is_wifi_network_ok) { @@ -399,35 +398,35 @@ public class CoreService extends Service { // if (!Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)) // Util.turnOnWifiForConnect(runtime.getContextProxy().context, runtime); } - } else if ("android.intent.action.SCREEN_OFF".equals(intent.getAction()) && Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)) { - // CoreService.is_wifi_network_ok = true; + } else if ("android.intent.action.SCREEN_OFF".equals(intent.getAction()) && Util.isWifiIsOpen(runtime.getContextProxy().context, runtime)) { + // CoreService.is_wifi_network_ok = true; if (!runtime.isNoTurnOffWifiOnScreenOff()) { //不关闭wifi when ScreenOff ICLogger.i("turnOffWifiForConnect"); // if (Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)) // Util.turnOffWifiForSleep(runtime.getContextProxy().context, runtime); } - }else if (intent.getAction().equals("android.media.VOLUME_CHANGED_ACTION")) { + } else if (intent.getAction().equals("android.media.VOLUME_CHANGED_ACTION")) { int streamType = intent.getIntExtra("android.media.EXTRA_VOLUME_STREAM_TYPE", -1); - ICLogger.i("Volume changed stream type "+streamType); + ICLogger.i("Volume changed stream type " + streamType); int newVolume = intent.getIntExtra("android.media.EXTRA_VOLUME_STREAM_VALUE", 0); int oldVolume = intent.getIntExtra("android.media.EXTRA_PREV_VOLUME_STREAM_VALUE", 0); - boolean isSilence = SharPreferenceUtil.getPrefBoolean(context, "KEY_ISSILENCE", false); + boolean isSilence = SharPreferenceUtil.getPrefBoolean(context, "KEY_ISSILENCE", false); if (newVolume != oldVolume && !isSilence) { - ICLogger.i("Volume changed old "+oldVolume+" new "+newVolume); - Config.setMasterVolume(context,newVolume); + ICLogger.i("Volume changed old " + oldVolume + " new " + newVolume); + Config.setMasterVolume(context, newVolume); } } } }; - private Runnable mRetryConnectSrvThread=new Runnable(){ + private Runnable mRetryConnectSrvThread = new Runnable() { @Override public void run() { - if (connection.isServerConnected()&& runtime.isServerProtocolConnected()) { + if (connection.isServerConnected() && runtime.isServerProtocolConnected()) { mKeepAlive.onHeartAlarm(connection, runtime); - }else{ + } else { ICLogger.i("mRetryConnectSrvThread 发送心跳包时,如果发现服务器没有响应,或者socket连接,则重新尝试连接服务器!"); connection.disconnectServer(); startConnectionRetryTimer(); @@ -444,7 +443,7 @@ public class CoreService extends Service { // Initialize initialize = new Initialize(); CheckSIM checkSIM = new CheckSIM(); this.mKeepAlive = new KeepAlive(); - this.mDeliver = new Deliver(this.connection,this.runtime); + this.mDeliver = new Deliver(this.connection, this.runtime); // initialize.setNext(checkSIM); checkSIM.setNext(this.mKeepAlive); this.mKeepAlive.setNext(this.mDeliver); @@ -453,10 +452,11 @@ public class CoreService extends Service { SilentManager silentManager; + private AbstractInvokeHandlerService getInvokeHandlerServiceChain() { ICLogger.i("getInvokeHandlerServiceChain"); SendChatMessage sendChatMessage = new SendChatMessage(); - HeartRateManager heartRateManager= new HeartRateManager(this.runtime,this.connection); + HeartRateManager heartRateManager = new HeartRateManager(this.runtime, this.connection); antiservice = new AntiMonitorService(); silentManager = SilentManager.getInstance();// new SilentManager(); sendChatMessage.setNext(heartRateManager); @@ -465,35 +465,38 @@ public class CoreService extends Service { return sendChatMessage; } - private void resetStepCount(){ - if ( ICJniUtils.isPedometerEnabled() == 0)ICJniUtils.enablePedometer(); + private void resetStepCount() { + if (ICJniUtils.isPedometerEnabled() == 0) ICJniUtils.enablePedometer(); ICJniUtils.resetStepCount(); SharPreferenceUtil.setPrefInt(this, KEY_STEP_COUNT, 0); SharPreferenceUtil.setPrefInt(this, KEY_SAVE_STEP_COUNT, 0); - ICLogger.i("Reset StepCount , "+ICJniUtils.getStepCount()); + ICLogger.i("Reset StepCount , " + ICJniUtils.getStepCount()); this.runtime.setSaveStepCount(0); this.runtime.setTotalStepCount(0); } + private void loadStepCount() { int i = SharPreferenceUtil.getPrefInt(this, KEY_STEP_COUNT, 0); int j = SharPreferenceUtil.getPrefInt(this, KEY_SAVE_STEP_COUNT, 0); - if ( ICJniUtils.isPedometerEnabled() == 0)ICJniUtils.enablePedometer(); + if (ICJniUtils.isPedometerEnabled() == 0) ICJniUtils.enablePedometer(); //ICJniUtils.recoverStepCount(); - if (ICJniUtils.getStepCount()>i){ - i=ICJniUtils.getStepCount(); + if (ICJniUtils.getStepCount() > i) { + i = ICJniUtils.getStepCount(); } this.runtime.setSaveStepCount(j); this.runtime.setTotalStepCount(i); runtime.setLastStepCountForBT(runtime.getTotalStepCount()); runtime.setLastStepCount(runtime.getTotalStepCount()); } - public void saveStepCount(){ + + public void saveStepCount() { int i = runtime.getTotalStepCount(); int j = runtime.getSaveStepCount(); SharPreferenceUtil.setPrefInt(this, KEY_STEP_COUNT, i); SharPreferenceUtil.setPrefInt(this, KEY_SAVE_STEP_COUNT, j); //ICJniUtils.saveStepCount(); } + private void setCleanStepCountAlarm() { /*一天清零一次 计步*/ // AlarmHelper.setCleanStepCountAlarm(this, 23, 59, STEP_COUNT_ALARM_ACTION); @@ -534,38 +537,39 @@ public class CoreService extends Service { private void setPracticeAlarm() { - ICLogger.i("setPracticeAlarm "+Runtime.practice_cycle+ " seconds!"); + ICLogger.i("setPracticeAlarm " + Runtime.practice_cycle + " seconds!"); //只有周期大于1才有效,否则就等于单次测量 - if (Runtime.practice_cycle>1) - AlarmHelper.setRealTimeAlarmInSeconds(runtime.getContextProxy().context,Runtime.practice_cycle,Constants.ACTION_PRACTICE_REPORT_ALARM); + if (Runtime.practice_cycle > 1) + AlarmHelper.setRealTimeAlarmInSeconds(runtime.getContextProxy().context, Runtime.practice_cycle, Constants.ACTION_PRACTICE_REPORT_ALARM); mHandler.post(mdoPracticeCheck); } - private Runnable mdoPracticeCheck=new Runnable(){ + + private Runnable mdoPracticeCheck = new Runnable() { @Override public void run() { //获取并设置当前步数 - ICLogger.i("自由锻炼中,设置步数 "+runtime.getTotalStepCount()); + ICLogger.i("自由锻炼中,设置步数 " + runtime.getTotalStepCount()); Runtime.healthInfo.setStepCount(runtime.getTotalStepCount()); //开启定位 // locationClient.triggerLocationProcess(); //开启测温 - if(runtime.check_stat_do_temp_test()) + if (runtime.check_stat_do_temp_test()) TemperatureUtil.DoTempTest(); //开启测量PPG - if(runtime.check_stat_do_ppg_test()) + if (runtime.check_stat_do_ppg_test()) HeartRateManager.triggerPPGtest(); } }; - private void checkconnection(){ + private void checkconnection() { - if (!this.connection.isServerConnected()) - { + if (!this.connection.isServerConnected()) { startConnectionRetryTimer(); } } + private void wakeUpFromSleep() { this.startAlarmCount = 0; // alarmCycle = 1; @@ -588,11 +592,13 @@ public class CoreService extends Service { Toast.makeText((this.runtime.getContextProxy()).context, "从深度睡眠中切换模式,联网中", Toast.LENGTH_SHORT).show(); } - public int cmcm_call_eiot_into_powersave_mode() { return 0; } + public int cmcm_call_eiot_into_powersave_mode() { + return 0; + } public PowerManager.WakeLock getWakeLock(int paramInt) { - PowerManager.WakeLock wakeLock = ((PowerManager)(this.runtime.getContextProxy()).context.getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MY_WAKE_LOCKTAG); + PowerManager.WakeLock wakeLock = ((PowerManager) (this.runtime.getContextProxy()).context.getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MY_WAKE_LOCKTAG); // wakeLock.acquire(paramInt*60*1000L); wakeLock.acquire(3000L); return wakeLock; @@ -603,27 +609,29 @@ public class CoreService extends Service { } - - public Runtime getRuntime(){ + public Runtime getRuntime() { return runtime; } - public Connection getConnection(){ + + public Connection getConnection() { return connection; } - private static boolean server_starting=true; + + private static boolean server_starting = true; + @Override public void onCreate() { - server_starting=true; + server_starting = true; log("初始化网络协议服务"); - mProtocolServer=this; - java.lang.Runtime.getRuntime().addShutdownHook(new Thread(){ + mProtocolServer = this; + java.lang.Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { super.run(); //设置断网状态 ICLogger.i("shutdown !"); - Util.setSystemProperties("persist.sys.server_connected","false"); + Util.setSystemProperties("persist.sys.server_connected", "false"); } }); this.runtime = new Runtime(); @@ -631,17 +639,16 @@ public class CoreService extends Service { this.runtime.setCacheDir(getExternalCacheDir()); this.runtime.setDBHelper(new DBHelper(getContentResolver(), this)); this.runtime.setContextProxy(new ContextProxy(this)); - this.runtime.setLbsHelper(new LBSHelper(this,this.runtime.getContextProxy().getWifiManager(), this.runtime)); + this.runtime.setLbsHelper(new LBSHelper(this, this.runtime.getContextProxy().getWifiManager(), this.runtime)); this.runtime.setHRS(new heartRateStatus()); this.runtime.setUseQueue(true); this.runtime.initDnsUtil(ICApplication.getInstance().getApplicationContext()); - if (Config.protocol_no==Config.PROTOCOL_MQTT) - { + if (Config.protocol_no == Config.PROTOCOL_MQTT) { connection = new mqttConnection(new ServerHandler(this), runtime); - }else { + } else { connection = new NettyConnection(new ServerHandler(this), runtime); } this.connectionServiceChain = getConnectionServiceChain(); @@ -651,12 +658,12 @@ public class CoreService extends Service { // return; // } - smsManager= new ICSmsManager(runtime); + smsManager = new ICSmsManager(runtime); //保证获取正确的计步数据及其他参数初始化 loadStepCount(); - if (Config.logBootDate(this)){ + if (Config.logBootDate(this)) { resetStepCount(); } @@ -665,8 +672,8 @@ public class CoreService extends Service { Config.LoadMessageConfigs(); if (Config.custom_name.equals("H88")) { - Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED,true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true); if (Config.getConfigInitFlag(this) == 0) { Config.setLocationMode(this, CUSTOM_MOD8_GPS); Config.setLocationCycle(this, 3600); @@ -674,10 +681,10 @@ public class CoreService extends Service { Config.setTemperatureTestCycle(runtime, 60 * 60); Config.setConfigInitFlag(this, 1); } - }else if (Config.custom_name.equals("l004")) { - Config.ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH,true); + } else if (Config.custom_name.equals("l004")) { + Config.ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH, true); if (Config.getConfigInitFlag(this) == 0) { Config.setLocationMode(this, CUSTOM_MOD8_GPS); @@ -687,32 +694,32 @@ public class CoreService extends Service { Config.setConfigInitFlag(this, 1); } - }else if (Config.custom_name.equals("YQ") || Config.custom_name.equals("YQ_EN")) { - Config.ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_UNREADMSG,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_MSGREAD,true); + } else if (Config.custom_name.equals("YQ") || Config.custom_name.equals("YQ_EN")) { + Config.ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_UNREADMSG, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_MSGREAD, true); if (Config.getConfigInitFlag(this) == 0) { Config.setLocationMode(this, NORMAL_MOD); - Config.setLocationCycle(this, 15*60); + Config.setLocationCycle(this, 15 * 60); Config.setPPGTestCycle(this, 0); Config.setTemperatureTestCycle(runtime, 0); Config.setConfigInitFlag(this, 1); } - }else if (Config.custom_name.equals("AK")) { + } else if (Config.custom_name.equals("AK")) { - Config.ConfigAlarm(Runtime.AlarmType.ALARM_SOS,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF,true); - Config.enableSleep=true; + Config.ConfigAlarm(Runtime.AlarmType.ALARM_SOS, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true); + Config.enableSleep = true; - if (Config.getConfigInitFlag(this)==0) { + if (Config.getConfigInitFlag(this) == 0) { Config.setPPGTestCycle(this, 0); Config.setTemperatureTestCycle(runtime, 0); Config.setConfigInitFlag(this, 1); @@ -726,38 +733,38 @@ public class CoreService extends Service { // runtime.getDbHelper().saveContacts(contactArray,false,false,false,false,false,true); // } } - }else if (Config.custom_name.equals("YT")) { + } else if (Config.custom_name.equals("YT")) { - Config.ConfigAlarm(Runtime.AlarmType.ALARM_SOS,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF,true); - Config.enableSleep=true; + Config.ConfigAlarm(Runtime.AlarmType.ALARM_SOS, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true); + Config.enableSleep = true; - if (Config.getConfigInitFlag(this)==0) { + if (Config.getConfigInitFlag(this) == 0) { Config.setPPGTestCycle(this, 0); Config.setTemperatureTestCycle(runtime, 0); Config.setConfigInitFlag(this, 1); - int contactcount=runtime.getDbHelper().getContactCount(getContentResolver()); - ICLogger.i("=====Contact count "+contactcount); - if(contactcount==0){ //如果没有SOS + int contactcount = runtime.getDbHelper().getContactCount(getContentResolver()); + ICLogger.i("=====Contact count " + contactcount); + if (contactcount == 0) { //如果没有SOS ICLogger.i("=====add hotline 96885 "); - ArrayList contactArray=new ArrayList(); + ArrayList contactArray = new ArrayList(); contactArray.add(new Contact(Contact.CATEGORY_CALL, this.getResources().getString(R.string.hotline), "96885")); - runtime.getDbHelper().saveContacts(contactArray,false,false,false,false,false,true); + runtime.getDbHelper().saveContacts(contactArray, false, false, false, false, false, true); } } - }else if (Config.custom_name.equals("SGL")) { //C5项目 - Config.ConfigAlarm(Runtime.AlarmType.ALARM_ESCAPE,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH,true); + } else if (Config.custom_name.equals("SGL")) { //C5项目 + Config.ConfigAlarm(Runtime.AlarmType.ALARM_ESCAPE, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH, true); Config.forceMoveCheck = false; //对定位不进行运动检测。 - if (Config.getConfigInitFlag(this)==0) { + if (Config.getConfigInitFlag(this) == 0) { Config.setLocationMode(this, CUSTOM_MOD8_GPS); // Config.setLocationMode(this, CUSTOM_MOD8_WIFI); - Config.setLocationCycle(this, 5*60); + Config.setLocationCycle(this, 5 * 60); Config.setPPGTestCycle(this, 0); Config.setTemperatureTestCycle(runtime, 0); Config.setConfigInitFlag(this, 1); @@ -771,11 +778,14 @@ public class CoreService extends Service { // runtime.getDbHelper().saveContacts(contactArray,false,false,false,false,false,true); // } } - }else if (Config.custom_name.equals("L02") || Config.custom_name.equals("L03")||Config.custom_name.equals("L05")) { //L02 + } else if (Config.custom_name.equals("L02") || + Config.custom_name.equals("L03") + || Config.custom_name.equals("L05") + || Config.custom_name.equals("CH")) { //L02 Config.forceMoveCheck = false; //即爱对gps不进行运动检测,此变量专门为了给其他协议进行强制运动检测用的。 - Config.ConfigAlarm(Runtime.AlarmType.ALARM_SOS,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_FALL,true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_SOS, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_FALL, true); if (Config.getConfigInitFlag(this) == 0) { Config.setPPGTestCycle(this, 0); @@ -783,24 +793,24 @@ public class CoreService extends Service { Config.setConfigInitFlag(this, 1); } - }else if (Config.custom_name.equals("VitracK")){ + } else if (Config.custom_name.equals("VitracK")) { - Config.ConfigAlarm(Runtime.AlarmType.ALARM_SOS,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED,true); - Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF,true); - Config.enableSleep=false; - if (Config.getConfigInitFlag(this)==0) { + Config.ConfigAlarm(Runtime.AlarmType.ALARM_SOS, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true); + Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true); + Config.enableSleep = false; + if (Config.getConfigInitFlag(this) == 0) { Config.setLocationMode(this, CUSTOM_MOD8_GPS); - Config.setLocationCycle(this, 30*60); + Config.setLocationCycle(this, 30 * 60); Config.setPPGTestCycle(this, 0); Config.setTemperatureTestCycle(runtime, 0); Config.setConfigInitFlag(this, 1); } - }else{ + } else { - if (Config.getConfigInitFlag(this)==0) { + if (Config.getConfigInitFlag(this) == 0) { Config.setPPGTestCycle(this, 0); Config.setTemperatureTestCycle(runtime, 0); Config.setConfigInitFlag(this, 1); @@ -813,8 +823,7 @@ public class CoreService extends Service { runtime.setNeedAntioff(Config.getNeedAntiOff(this)); - - Config.setHeartBeatCycle(this,alarmCycle); //临时设置为5分钟,给L03测试用。测试断线问题未解决,取消测试。 + Config.setHeartBeatCycle(this, alarmCycle); //临时设置为5分钟,给L03测试用。测试断线问题未解决,取消测试。 //初始化ServerHeartBeat Cycle Config.loadHearBeatSetting(runtime); //初始化PPG,LocationMod,LocationCycle @@ -826,7 +835,7 @@ public class CoreService extends Service { //读取Alarm环境配置,项目不需要的Alarm不要发送, 目前环境变量配置优先。默认值会被覆盖。 Config.loadAlarmConfig(); - Config.enable_NTP_Server(this,!Config.disable_ntp_server); + Config.enable_NTP_Server(this, !Config.disable_ntp_server); //初始化温度测试相关参数 @@ -835,7 +844,7 @@ public class CoreService extends Service { //加载存储的健康数据校准值 - Config.loadPPG_BPH_BPL_SPO2_adjustvalue(this,runtime); + Config.loadPPG_BPH_BPL_SPO2_adjustvalue(this, runtime); this.connectionServiceChain.processAttach(this.connection, this.runtime); this.invokeHandlerServiceChain.processAttach(this.connection, this.runtime); @@ -883,35 +892,35 @@ public class CoreService extends Service { intentFilter.addAction(ACTION_QUERY_WEATHER); intentFilter.addAction(ACTION_SEND_EMEGENCY_LOCATION_START); intentFilter.addAction(ACTION_LOCAL_SOS_ACTION); - registerReceiver(broadcastSOSReceiver,intentFilter); + registerReceiver(broadcastSOSReceiver, intentFilter); //添加自由锻炼 接收 intentFilter = new IntentFilter(); intentFilter.addAction(Constants.ACTION_START_PRACTISE); - registerReceiver(broadcastPracticeCMDReceiver,intentFilter); + registerReceiver(broadcastPracticeCMDReceiver, intentFilter); //初始化Sim信号 this.mSignalUtil = SimSignalUtil.getInstance(this); //初始化 电池电量监控工具(内部注册接收电池变化) - batteryUtil = new BatteryUtil(this.runtime,connection); + batteryUtil = new BatteryUtil(this.runtime, connection); //保证发送心跳时提前获取BatLevel数据 - int batlevel=batteryUtil.getBatteryLevel(this); - runtime.setBattery(String.format("%03d",batlevel)); + int batlevel = batteryUtil.getBatteryLevel(this); + runtime.setBattery(String.format("%03d", batlevel)); runtime.setBattery(batlevel); - ICLogger.i("Battery get from api "+batlevel); + ICLogger.i("Battery get from api " + batlevel); boolean charging = batteryUtil.isPowerConnected(this); runtime.setPowerConnected(charging); - ICLogger.i("Charging "+charging); + ICLogger.i("Charging " + charging); // LedUtil.setRedLedOn(false); - if (Config.isL03Tracker){ + if (Config.isL03Tracker) { - if (runtime.isPowerConnected()) { + if (runtime.isPowerConnected()) { LedUtil.setRedLedOn(true); - }else{ + } else { LedUtil.setRedLedOn(false); } } @@ -940,7 +949,7 @@ public class CoreService extends Service { //获取定位时间 - needLocateInAfterHeartBeat=true; + needLocateInAfterHeartBeat = true; setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); //设置温度测量间隔时间 @@ -949,36 +958,35 @@ public class CoreService extends Service { //初始化佩戴检测 - runtime.anti_test_cycle=Config.getCheckAntiPolingCycle(this); - if( runtime.anti_test_cycle>0){ - // setAntiAlarm(); + runtime.anti_test_cycle = Config.getCheckAntiPolingCycle(this); + if (runtime.anti_test_cycle > 0) { + // setAntiAlarm(); } //初始化蓝牙检测 - runtime.bleInfo.bleScanCycle=Config.getBleScanCycle(this); - if(Config.BLEScanProtocol==1 && runtime.bleInfo.bleScanCycle>0) - { + runtime.bleInfo.bleScanCycle = Config.getBleScanCycle(this); + if (Config.BLEScanProtocol == 1 && runtime.bleInfo.bleScanCycle > 0) { setBleScanAlarm(runtime.bleInfo.bleScanCycle); } //设置来电模式 - Util.SetRingMode(this, AudioManager.RINGER_MODE_NORMAL,true); + Util.SetRingMode(this, AudioManager.RINGER_MODE_NORMAL, true); //备份DB数据到sd cache目录,为调试方便 Util.getDBFile(); // test(); //test function - //更新MCC MNC + //更新MCC MNC CellInfoUtil.setCurrentAttachCellInfo(CoreService.getInstance().runtime); - //更新IMEI + //更新IMEI DeviceInfoUtil.updateImei(runtime); //设置断网状态 - Util.setSystemProperties("persist.sys.server_connected","false"); + Util.setSystemProperties("persist.sys.server_connected", "false"); //启动结束设置标志位,让心率和体温检测可以正常执行。 - server_starting=false; + server_starting = false; //重置缓存中的在等待命令 Deliver.resetCMDReocrdsDB(); @@ -986,45 +994,46 @@ public class CoreService extends Service { ReConnectToServer(); } - private void test(){ + private void test() { ICLogger.i("周一清除所有睡眠数据Record"); runtime.getDbHelper().deleteSleepData(); } //检查是否有未读消息需要提醒 - private void checkUnreadMessage(){ + private void checkUnreadMessage() { - String msg=Config.getLastUnReadMessage(this); - Util.checkMesageNeedNotifi(msg,runtime); + String msg = Config.getLastUnReadMessage(this); + Util.checkMesageNeedNotifi(msg, runtime); } //内部广播StringMessage - public static void DevliverStringMessage(String cmd){ - CoreService.getInstance().connection.DeliverCMDMessageToSystem(cmd,""); + public static void DevliverStringMessage(String cmd) { + CoreService.getInstance().connection.DeliverCMDMessageToSystem(cmd, ""); } + //内部广播StringMessage - public static void DevliverStringMessage(String cmd,String str){ - CoreService.getInstance().connection.DeliverCMDMessageToSystem(cmd,str); + public static void DevliverStringMessage(String cmd, String str) { + CoreService.getInstance().connection.DeliverCMDMessageToSystem(cmd, str); } //表带剪断检测报警,此处只是设备本地提醒,并不发送报警信息给服务器。 - public void checkAlarmMessage(){ + public void checkAlarmMessage() { - if (runtime.Fence_Warning_flag>0 && Config.needAllwaysAlarmFenceOut){ + if (runtime.Fence_Warning_flag > 0 && Config.needAllwaysAlarmFenceOut) { runtime.Fence_Warning_flag++; WakeLockUtil.ScreenOnWakeLockTemperary(runtime.getContextProxy().context); - runtime.getContextProxy().sendMsgBroadcast(runtime.getContextProxy().context.getResources().getString(R.string.alarm_out_wall),2); + runtime.getContextProxy().sendMsgBroadcast(runtime.getContextProxy().context.getResources().getString(R.string.alarm_out_wall), 2); } - if(runtime.Cut_off_flag>0 && Config.needAllwaysAlarmCutOff){ + if (runtime.Cut_off_flag > 0 && Config.needAllwaysAlarmCutOff) { runtime.Cut_off_flag++; // WakeLockUtil.ScreenOnWakeLockTemperary(runtime.getContextProxy().context); if (Config.A9_noBroadCastActionStrip) { - if(Config.needBroadcastCutoffAlarm) { + if (Config.needBroadcastCutoffAlarm) { antiservice.send_cutoff_event_broadcast(1); } @@ -1034,21 +1043,21 @@ public class CoreService extends Service { } //检测久坐提醒 - public void checkKeepSitting(){ - String dateyyyyMMDDhhmmss=TimeUtil.getSystemTime3(); + public void checkKeepSitting() { + String dateyyyyMMDDhhmmss = TimeUtil.getSystemTime3(); //为了更新 isInSleepRange, 下面的语句必须执行 TimeUtil.getCurrentSleepRecordDate(dateyyyyMMDDhhmmss); - if(TimeUtil.isInSleepRange == false) { //不在睡眠时间就是久坐时间段。 - if (Runtime.lastSitCheckStepCount == -1){ - Runtime.lastSitCheckStepCount=runtime.getTotalStepCount(); - Runtime.lastSitCheckTiimeyyyyMMddHHmmss=TimeUtil.getSystemTime3(); - } - int keepsitRange=Config.getKeepSitRangeInMinutes(this); - int minutes=(int)TimeUtil.diffBetween2DateInMinutes(Runtime.lastSitCheckTiimeyyyyMMddHHmmss,dateyyyyMMDDhhmmss); - ICLogger.i("SitCheck last SitCheckTime "+ Runtime.lastSitCheckTiimeyyyyMMddHHmmss + " , current checktime "+dateyyyyMMDDhhmmss); - ICLogger.i("SitCheck minutes "+ minutes + " , keepsitRange "+keepsitRange); - if (minutes >=keepsitRange && keepsitRange>0){ - if ( (runtime.getTotalStepCount() - Runtime.lastSitCheckStepCount)/minutes < Config.KeepSitJudgementRefValue){ + if (TimeUtil.isInSleepRange == false) { //不在睡眠时间就是久坐时间段。 + if (Runtime.lastSitCheckStepCount == -1) { + Runtime.lastSitCheckStepCount = runtime.getTotalStepCount(); + Runtime.lastSitCheckTiimeyyyyMMddHHmmss = TimeUtil.getSystemTime3(); + } + int keepsitRange = Config.getKeepSitRangeInMinutes(this); + int minutes = (int) TimeUtil.diffBetween2DateInMinutes(Runtime.lastSitCheckTiimeyyyyMMddHHmmss, dateyyyyMMDDhhmmss); + ICLogger.i("SitCheck last SitCheckTime " + Runtime.lastSitCheckTiimeyyyyMMddHHmmss + " , current checktime " + dateyyyyMMDDhhmmss); + ICLogger.i("SitCheck minutes " + minutes + " , keepsitRange " + keepsitRange); + if (minutes >= keepsitRange && keepsitRange > 0) { + if ((runtime.getTotalStepCount() - Runtime.lastSitCheckStepCount) / minutes < Config.KeepSitJudgementRefValue) { //平均 每分钟活动数 小于参考久坐计步值,表示久坐 ICLogger.i("SitCheck 平均 每分钟活动数 小于参考久坐计步值,表示久坐"); WakeLockUtil.ScreenOnWakeLockTemperary(this); @@ -1058,50 +1067,50 @@ public class CoreService extends Service { //提醒后 重置 lastCheckSitTime 以及 lastSitCheckStepCount , 重新计时 - Runtime.lastSitCheckStepCount=runtime.getTotalStepCount(); - Runtime.lastSitCheckTiimeyyyyMMddHHmmss=TimeUtil.getSystemTime3(); + Runtime.lastSitCheckStepCount = runtime.getTotalStepCount(); + Runtime.lastSitCheckTiimeyyyyMMddHHmmss = TimeUtil.getSystemTime3(); - if(Config.isAlarmTypeEnabled(Runtime.AlarmType.ALARM_SEDENTARY)){ + if (Config.isAlarmTypeEnabled(Runtime.AlarmType.ALARM_SEDENTARY)) { runtime.setAlarmType(Runtime.AlarmType.ALARM_SEDENTARY); // Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime)); ICLogger.i("triggerSOSLocationProcess "); locationClient.triggerSOSLocationProcess(); } - }else{ + } else { //只要 平均每分钟活动数大于参考值,则重置 lastCheckSitTime 以及 lastSitCheckStepCount ICLogger.i("SitCheck 平均每分钟活动数大于参考值,则重置 lastCheckSitTime 以及 lastSitCheckStepCount"); - Runtime.lastSitCheckStepCount=runtime.getTotalStepCount(); - Runtime.lastSitCheckTiimeyyyyMMddHHmmss=TimeUtil.getSystemTime3(); + Runtime.lastSitCheckStepCount = runtime.getTotalStepCount(); + Runtime.lastSitCheckTiimeyyyyMMddHHmmss = TimeUtil.getSystemTime3(); } } - }else{ - Runtime.lastSitCheckStepCount=-1; //不在时间段就重置数据,以便下一次使用能过重新开始计数。 + } else { + Runtime.lastSitCheckStepCount = -1; //不在时间段就重置数据,以便下一次使用能过重新开始计数。 } } - public void updateSleepDate(){ - String dateyyyyMMDDhhmmss=TimeUtil.getSystemTime3(); - String sleepdate=TimeUtil.getCurrentSleepRecordDate(dateyyyyMMDDhhmmss); - ICLogger.i("updateSleepDate "+sleepdate); - if(TimeUtil.isInSleepRange == true) { - runtime.getDbHelper().insertSleepRecord(new SleepRecord(dateyyyyMMDDhhmmss,sleepdate,runtime.getTotalStepCount())); - runtime.sleepDataReported=false; //只要记录过数据 就证明有数据没有report - }else{ + public void updateSleepDate() { + String dateyyyyMMDDhhmmss = TimeUtil.getSystemTime3(); + String sleepdate = TimeUtil.getCurrentSleepRecordDate(dateyyyyMMDDhhmmss); + ICLogger.i("updateSleepDate " + sleepdate); + if (TimeUtil.isInSleepRange == true) { + runtime.getDbHelper().insertSleepRecord(new SleepRecord(dateyyyyMMDDhhmmss, sleepdate, runtime.getTotalStepCount())); + runtime.sleepDataReported = false; //只要记录过数据 就证明有数据没有report + } else { if (runtime.sleepDataReported == false) { //calculate sleep data and report it randomly within 1 hour runtime.sleepDataReported = true; int score = runtime.getDbHelper().querySleepScore(sleepdate); if (score > 0) { - ICLogger.i("已经有"+sleepdate+"的睡眠数据!"); + ICLogger.i("已经有" + sleepdate + "的睡眠数据!"); } else { SleepInfo si = SleepInfo.getInstance(); si.setDate(sleepdate); si.calculate_sleepInfo(runtime); runtime.getDbHelper().updateSleepInfo(si); - if (TimeUtil.getWeek().equals("周一")){ + if (TimeUtil.getWeek().equals("周一")) { ICLogger.i("周一清除所有睡眠数据Record"); runtime.getDbHelper().deleteSleepData(); } @@ -1117,16 +1126,16 @@ public class CoreService extends Service { // Observable.timer(randomint * 60 * 1000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { // public void call(Long param1Long) { // connection.send(protocolAPIHelper); - ICLogger.i("Send sleep info " + si.getCurrentDate() - + " deep " + si.getDeepsleep_minutes() - + " light " + si.getLightsleep_minutes() - + " score " + si.getScore() - ); - if (Config.enableSleep) { - Deliver.sendLocationMSG(protocolAPIHelper.getSleepMSG(SleepInfo.getInstance(), runtime)); - }else{ - ICLogger.i(" 没有开启睡眠协议,skip send message!"); - } + ICLogger.i("Send sleep info " + si.getCurrentDate() + + " deep " + si.getDeepsleep_minutes() + + " light " + si.getLightsleep_minutes() + + " score " + si.getScore() + ); + if (Config.enableSleep) { + Deliver.sendLocationMSG(protocolAPIHelper.getSleepMSG(SleepInfo.getInstance(), runtime)); + } else { + ICLogger.i(" 没有开启睡眠协议,skip send message!"); + } // } // }); @@ -1134,8 +1143,9 @@ public class CoreService extends Service { } } } + public int onStartCommand(Intent paramIntent, int paramInt1, int paramInt2) { - if (paramIntent != null && paramIntent.getAction()!=null) { + if (paramIntent != null && paramIntent.getAction() != null) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("onStartCommand action="); stringBuilder.append(paramIntent.getAction()); @@ -1184,7 +1194,7 @@ public class CoreService extends Service { if (Config.LOG_TOFILE) ICLogger.logToFile("alarmCycle", "HEART_ALARM alarmCycle "); return Service.START_STICKY; - }else if (ACTION_LOCATION_ALARM.equals(paramIntent.getAction())) { + } else if (ACTION_LOCATION_ALARM.equals(paramIntent.getAction())) { // if (cmcm_call_eiot_into_powersave_mode() == 1) { @@ -1223,29 +1233,29 @@ public class CoreService extends Service { if (Config.LOG_TOFILE) ICLogger.logToFile("alarmCycle", stringBuilder1.toString()); // this.locationClient.triggerLocationProcess(); - }else if (Constants.OTHER_ALARM_END.equals(paramIntent.getAction())) { + } else if (Constants.OTHER_ALARM_END.equals(paramIntent.getAction())) { ICLogger.i("OTHER_ALARM_END set Ringmode Normal vib true"); - SilentManager.setSilentConfig(this,false); - }else if (Constants.OTHER_ALARM_START.equals(paramIntent.getAction())) { + SilentManager.setSilentConfig(this, false); + } else if (Constants.OTHER_ALARM_START.equals(paramIntent.getAction())) { ICLogger.i("OTHER_ALARM_START set Ringmode Silent vib false"); - SilentManager.setSilentConfig(this,true); - }else if (Constants.ACTION_ALARM_BLE_SCAN.equals(paramIntent.getAction())) { - //循环蓝牙扫描 + SilentManager.setSilentConfig(this, true); + } else if (Constants.ACTION_ALARM_BLE_SCAN.equals(paramIntent.getAction())) { + //循环蓝牙扫描 setBleScanAlarm(runtime.bleInfo.bleScanCycle); - }else if (Constants.ACTION_PRACTICE_REPORT_ALARM.equals(paramIntent.getAction())) { + } else if (Constants.ACTION_PRACTICE_REPORT_ALARM.equals(paramIntent.getAction())) { //alarm是延迟的,所以这个判断主要是给最后一次可能无效的测量 - if (Runtime.practising==true) { + if (Runtime.practising == true) { //开始下一轮健康测量 setPracticeAlarm(); } - }else if (Constants.ACTION_CHECK_SERVER_RESPONSE.equals(paramIntent.getAction())) { + } else if (Constants.ACTION_CHECK_SERVER_RESPONSE.equals(paramIntent.getAction())) { //暂时还使用 ScheduledThreadPoolExecutor , 时间要求不是那么的严格 - }else if (Constants.ACTION_RETRY_SERVER_CONNECT.equals(paramIntent.getAction())) { + } else if (Constants.ACTION_RETRY_SERVER_CONNECT.equals(paramIntent.getAction())) { //暂时还使用 ScheduledThreadPoolExecutor , 时间要求不是那么的严格 - }else if (Constants.ACTION_CHECK_LOCATION_RESULT.equals(paramIntent.getAction())) { + } else if (Constants.ACTION_CHECK_LOCATION_RESULT.equals(paramIntent.getAction())) { locationClient.waitAndSendLocation(); - }else if (Constants.SLEEP_ALARM.equals(paramIntent.getAction())) { + } else if (Constants.SLEEP_ALARM.equals(paramIntent.getAction())) { StringBuilder stringBuilder1; ICLogger.i("SLEEP_ALARM"); is_allowed_in_sleep_mode = 1; @@ -1293,7 +1303,7 @@ public class CoreService extends Service { setTempAlarm(); - return Service.START_STICKY; + return Service.START_STICKY; } else if (STEP_COUNT_ALARM_ACTION.equals(paramIntent.getAction())) { ICLogger.i("Reset Count At 00:00 "); //update stepCount and broadcast before reset @@ -1304,7 +1314,7 @@ public class CoreService extends Service { //更新 运动控制的上次步数 然后再resetstecount //runtime.setLastStepCount(runtime.getTotalStepCount()-runtime.getLastStepCount()); //runtime.setLastStepCountForBT(runtime.getTotalStepCount()-runtime.getLastStepCountForBT()); - resetStepCount(); + resetStepCount(); //此处本来应该把刚刚reset前运动的步数设置到计步器里,继续开始计步。 // 由于计步接口没有提供设置步数。所以暂时只能清零,不能解决午夜还在运动的情况,会丢失一两次的数据。但是影响不大 runtime.setLastStepCountForBT(0); @@ -1324,11 +1334,11 @@ public class CoreService extends Service { //此消息来源于BroadCaset,收到开始测试的消息。 //此时需要重置HeartRateDetect Timer //倘若有 参数 PPGTestCycle,则根据这个数值进行设置 - int ppgtestCycle=paramIntent.getIntExtra("PPGTestCycle",-1); - if (ppgtestCycle >0){ - Config.setPPGTestCycle(runtime.getContextProxy().context,ppgtestCycle); + int ppgtestCycle = paramIntent.getIntExtra("PPGTestCycle", -1); + if (ppgtestCycle > 0) { + Config.setPPGTestCycle(runtime.getContextProxy().context, ppgtestCycle); runtime.setPpgTestCycle(Config.getPPGTestCycle(runtime.getContextProxy().context)); - ICLogger.i("get and set PPGTestCycle "+ppgtestCycle); + ICLogger.i("get and set PPGTestCycle " + ppgtestCycle); } setHeartRateDetectAlarm(runtime.getPpgTestCycle());//重置心率检测周期,并触发一次检测 @@ -1338,7 +1348,7 @@ public class CoreService extends Service { LocationClient.setForceLocation(1); setLocationAlarm(runtime.getLocationInstance().getWorkingMod());//同时重置alarm并触发定位 - }else if(ACTION_CHECK_ANTIOFF_EVENT.equals(paramIntent.getAction())){ + } else if (ACTION_CHECK_ANTIOFF_EVENT.equals(paramIntent.getAction())) { //只在中断式检测过程中延时用 antiservice.check_ant_event(); } @@ -1349,93 +1359,96 @@ public class CoreService extends Service { return Service.START_NOT_STICKY; } - public boolean onUnbind(Intent paramIntent) { return false; } + public boolean onUnbind(Intent paramIntent) { + return false; + } //每一分钟设置一次 public void setAlarm(int paramInt) { // AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,paramInt,ACTION_ALARM); } - public void setHeartRateDetectAlarm(int heartRateDetectAlarmCycle){ + public void setHeartRateDetectAlarm(int heartRateDetectAlarmCycle) { if (Config.noPPGSensor) { ICLogger.i("setHeartRateDetectAlarm oPPGSensor"); return; } - StringBuilder sb=new StringBuilder(); - if (heartRateDetectAlarmCycle>1) { + StringBuilder sb = new StringBuilder(); + if (heartRateDetectAlarmCycle > 1) { AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context, heartRateDetectAlarmCycle, ACTION_HEATR_RATE_START); } - if(runtime.check_stat_do_ppg_test()) { + if (runtime.check_stat_do_ppg_test()) { if (Runtime.practising == true) { sb.append("自由锻炼中,跳过原有的循环心率检测!"); ICLogger.i("自由锻炼中,跳过原有的循环心率检测!"); } else { sb.append("setHeartRateDetectAlarm " + heartRateDetectAlarmCycle); - if(!server_starting) + if (!server_starting) HeartRateManager.triggerPPGtest(); } } - if (Config.LOG_TOFILE)ICLogger.logToFile("alarmCycle",sb.toString()); + if (Config.LOG_TOFILE) ICLogger.logToFile("alarmCycle", sb.toString()); } - public void setBleScanAlarm(int cycle){ + public void setBleScanAlarm(int cycle) { //只有蓝牙扫描协议1才需要设置周期,蓝牙扫描协议0 为心跳及定位时才进行扫描 - if (Config.BLEScanProtocol!=1) { + if (Config.BLEScanProtocol != 1) { ICLogger.i("BLEScanProtocol!=1 skip setPolingCheckAntiAlarm"); return; } - StringBuilder sb=new StringBuilder(); - if (cycle>=15) { + StringBuilder sb = new StringBuilder(); + if (cycle >= 15) { //由于蓝牙扫描一次15秒,所以周期要大于等于15秒 - AlarmHelper.setRealTimeAlarmInMicorSeconds(runtime.getContextProxy().context, cycle*1000, ACTION_ALARM_BLE_SCAN); + AlarmHelper.setRealTimeAlarmInMicorSeconds(runtime.getContextProxy().context, cycle * 1000, ACTION_ALARM_BLE_SCAN); } - sb.append("setBleScanAlarm " + cycle+" seconds"); + sb.append("setBleScanAlarm " + cycle + " seconds"); locationClient.triggerBLEProcess(); ICLogger.i(sb.toString()); - if (Config.LOG_TOFILE)ICLogger.logToFile("alarmCycle",sb.toString()); + if (Config.LOG_TOFILE) ICLogger.logToFile("alarmCycle", sb.toString()); } - public void setEmegencyLocationSTOPAlarm(int delayTimeInMinutes){ - StringBuilder sb=new StringBuilder(); - AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,delayTimeInMinutes, ACTION_SEND_EMEGENCY_LOCATION_STOP); - sb.append(" tEmegencyLocationSTOPAlarm "+ACTION_SEND_EMEGENCY_LOCATION_STOP); + public void setEmegencyLocationSTOPAlarm(int delayTimeInMinutes) { + StringBuilder sb = new StringBuilder(); + AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context, delayTimeInMinutes, ACTION_SEND_EMEGENCY_LOCATION_STOP); + sb.append(" tEmegencyLocationSTOPAlarm " + ACTION_SEND_EMEGENCY_LOCATION_STOP); // ICLogger.i(sb.toString()); - if (Config.LOG_TOFILE)ICLogger.logToFile("alarmCycle",sb.toString()); + if (Config.LOG_TOFILE) ICLogger.logToFile("alarmCycle", sb.toString()); } + public void setLocationAlarm(int mod) { // int mod=runtime.getLocationInstance().getWorkingMod(); - StringBuilder sb=new StringBuilder(); - int cycle=60; - switch(mod){ + StringBuilder sb = new StringBuilder(); + int cycle = 60; + switch (mod) { case EMERGNECY_MOD: case REALTIME_MOD: - cycle=60; + cycle = 60; break; case NORMAL_MOD: - cycle=15*60; + cycle = 15 * 60; break; case LOWPOWER_MOD: - cycle=60*60; + cycle = 60 * 60; break; case CUSTOM_MOD: case CUSTOM_MOD8_GPS: case CUSTOM_MOD8_WIFI: - cycle=runtime.getLocationInstance().getLocation_cycle(); + cycle = runtime.getLocationInstance().getLocation_cycle(); break; } - if(cycle == 0) - { + if (cycle == 0) { ICLogger.i("locationCycle == 0 stop Location !"); - Config.noLocationCycle=true; + Config.noLocationCycle = true; } - if (Config.noLocationCycle==false) - AlarmHelper.setRealTimeAlarmInSeconds(runtime.getContextProxy().context,cycle, ACTION_LOCATION_ALARM); + if (Config.noLocationCycle == false) + AlarmHelper.setRealTimeAlarmInSeconds(runtime.getContextProxy().context, cycle, ACTION_LOCATION_ALARM); else - ICLogger.i("skip set LocationAlarm " ); - sb.append(" setLocationAlarm "+ACTION_LOCATION_ALARM+" mod "+mod+", cycle in Seconds "+cycle); + ICLogger.i("skip set LocationAlarm "); + sb.append(" setLocationAlarm " + ACTION_LOCATION_ALARM + " mod " + mod + ", cycle in Seconds " + cycle); ICLogger.i(sb.toString()); - if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(),"alarmCycle",sb.toString()); + if (Config.LOG_TOFILE) + FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", sb.toString()); // if (Runtime.practising==true) { // ICLogger.i("自由锻炼中,跳过原有的循环定位!"); @@ -1446,63 +1459,66 @@ public class CoreService extends Service { } - public void setHeartAlarm(){ + public void setHeartAlarm() { // int mod=runtime.getLocationInstance().getWorkingMod(); - StringBuilder sb=new StringBuilder(); - int cycle=runtime.getHeartBeatCycle(); + StringBuilder sb = new StringBuilder(); + int cycle = runtime.getHeartBeatCycle(); //心跳指令默认设置 - AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,cycle, HEART_ALARM); - sb.append(" setHeartAlarm "+HEART_ALARM+", cycle "+cycle); + AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context, cycle, HEART_ALARM); + sb.append(" setHeartAlarm " + HEART_ALARM + ", cycle " + cycle); // locationClient.triggerLocationProcess(); ICLogger.i(sb.toString()); - FileOutputUtil.fileOutput(runtime.getCacheDir(),"alarmCycle",sb.toString()); + FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", sb.toString()); // AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,1, HEART_ALARM); } - public void setAntiAlarm(){ + + public void setAntiAlarm() { // int mod=runtime.getLocationInstance().getWorkingMod(); - StringBuilder sb=new StringBuilder(); - int cycle=runtime.anti_test_cycle; - if(cycle>1) { + StringBuilder sb = new StringBuilder(); + int cycle = runtime.anti_test_cycle; + if (cycle > 1) { AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context, cycle, ANTI_ALARM); } - sb.append(" setHeartAlarm "+ANTI_ALARM+", cycle "+cycle); + sb.append(" setHeartAlarm " + ANTI_ALARM + ", cycle " + cycle); ICLogger.i(sb.toString()); - FileOutputUtil.fileOutput(runtime.getCacheDir(),"alarmCycle",sb.toString()); + FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", sb.toString()); } - public void setTempAlarm(){ + + public void setTempAlarm() { // int mod=runtime.getLocationInstance().getWorkingMod(); - StringBuilder sb=new StringBuilder(); - int cycle=runtime.temp_test_Cycle; + StringBuilder sb = new StringBuilder(); + int cycle = runtime.temp_test_Cycle; - if(Config.noTempSensor) { + if (Config.noTempSensor) { ICLogger.i("setTempAlarm noTempSensor"); return; } - if (cycle>1) { + if (cycle > 1) { AlarmHelper.setRealTimeAlarmInSeconds(runtime.getContextProxy().context, cycle, TEMP_ALARM); sb.append(" setTempAlarm " + TEMP_ALARM + ", cycle " + cycle); - }else { - sb.append(" setTempAlarm " + TEMP_ALARM + ", cycle " + cycle+"<=1 skip!"); + } else { + sb.append(" setTempAlarm " + TEMP_ALARM + ", cycle " + cycle + "<=1 skip!"); } // locationClient.triggerLocationProcess(); ICLogger.i(sb.toString()); - FileOutputUtil.fileOutput(runtime.getCacheDir(),"alarmCycle",sb.toString()); + FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", sb.toString()); - if(runtime.check_stat_do_temp_test()) { + if (runtime.check_stat_do_temp_test()) { if (Runtime.practising == true) { ICLogger.i("自由锻炼中,跳过原有的循环温度检测!"); } else { - if(!server_starting) + if (!server_starting) TemperatureUtil.doTempTestInThread(); } } } + public void setUpLocationDataAlarm(long paramLong) { - AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); + AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Intent intent = new Intent(this, CoreService.class); intent.setAction(ACTION_ALARM_ADD_DATAPOINTS); PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, FLAG_UPDATE_CURRENT); @@ -1512,11 +1528,13 @@ public class CoreService extends Service { stringBuilder.append("interval="); stringBuilder.append(paramLong); ICLogger.i(stringBuilder.toString()); - AlarmHelper.setRealTimeAlarm( runtime.getContextProxy().context,(int)((System.currentTimeMillis() + paramLong)/1000),ACTION_ALARM_ADD_DATAPOINTS); + AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context, (int) ((System.currentTimeMillis() + paramLong) / 1000), ACTION_ALARM_ADD_DATAPOINTS); } public static class InnerService extends Service { - public IBinder onBind(Intent param1Intent) { return null; } + public IBinder onBind(Intent param1Intent) { + return null; + } /*给 API >= 18 的平台上用的灰色保活手段*/ public int onStartCommand(Intent param1Intent, int param1Int1, int param1Int2) { @@ -1535,7 +1553,7 @@ public class CoreService extends Service { } public void handleMessage(Message param1Message) { - CoreService coreService = (CoreService)this.mReference.get(); + CoreService coreService = (CoreService) this.mReference.get(); if (coreService == null) return; coreService.invokeHandlerServiceChain.processUserRequest(param1Message, coreService.connection, coreService.runtime); @@ -1544,66 +1562,70 @@ public class CoreService extends Service { private static final String TAG = "ICSrv." + CoreService.class.getSimpleName(); - private ScheduledThreadPoolExecutor mTimer_retry_connect=null; + private ScheduledThreadPoolExecutor mTimer_retry_connect = null; + + private static int retry_connect_count = 0; //当前重试次数 + private static int retry_connect_max_times = 6; //最大重试次数 6次 , 即只重试2分钟,下一次重试将在下一个心跳包时进行。 + private static int retry_cocnnect_cycle = 20; //重试间隔20秒 - private static int retry_connect_count=0; //当前重试次数 - private static int retry_connect_max_times=6; //最大重试次数 6次 , 即只重试2分钟,下一次重试将在下一个心跳包时进行。 - private static int retry_cocnnect_cycle=20; //重试间隔20秒 private void log(String msg) { - ICLogger.log(TAG,msg); + ICLogger.log(TAG, msg); } - public static CoreService getInstance(){ + public static CoreService getInstance() { return mProtocolServer; } - public void startConnectionRetryTimer(){ + public void startConnectionRetryTimer() { //联网再重试连接服务器, 不能够联网的情况下不管是不是有sim卡,以及是否联网,都进行重试,以便处理下面情况: //1、sim卡接触不良,掉卡,可以尝试用此法恢复 //2、网络信号不好,造成临时掉线,但是恢复慢或不恢复,可以用此法尝试恢复 // if (SimSignalUtil.checkNet(runtime.getContextProxy().context) ) { - stopConnectionRetryTimer(); - if (mTimer_retry_connect == null) { - mTimer_retry_connect = new ScheduledThreadPoolExecutor(10); - } - //如果开始进行连接重 - // { - // 试,证明网络断开的,那么KeepAlive也需要重连(心跳包) - retry_connect_count=0; - KeepAlive.isConnected = false; - if (mTimer_retry_connect != null) { - mTimer_retry_connect.remove(mReConnectSrvThread); - mTimer_retry_connect.scheduleAtFixedRate(mReConnectSrvThread, 5000, 20000, TimeUnit.MILLISECONDS); //每次都是断网才需要重连,delay 5秒重连,并且每20秒重试一次 - } + stopConnectionRetryTimer(); + if (mTimer_retry_connect == null) { + mTimer_retry_connect = new ScheduledThreadPoolExecutor(10); + } + //如果开始进行连接重 + // { + // 试,证明网络断开的,那么KeepAlive也需要重连(心跳包) + retry_connect_count = 0; + KeepAlive.isConnected = false; + if (mTimer_retry_connect != null) { + mTimer_retry_connect.remove(mReConnectSrvThread); + mTimer_retry_connect.scheduleAtFixedRate(mReConnectSrvThread, 5000, 20000, TimeUnit.MILLISECONDS); //每次都是断网才需要重连,delay 5秒重连,并且每20秒重试一次 + } // } } - private ReConnectSrvThread mReConnectSrvThread=new ReConnectSrvThread(); - private class ReConnectSrvThread implements Runnable{ + + private ReConnectSrvThread mReConnectSrvThread = new ReConnectSrvThread(); + + private class ReConnectSrvThread implements Runnable { @Override public void run() { ReConnectToServer(); } } - private static int no_network_Heartbeats_Count=0; + private static int no_network_Heartbeats_Count = 0; - public void ReConnectToServer(){ - long timeSincelastReceive=0; - if(Runtime.lastLinkReceiveStamp>0) - timeSincelastReceive=(System.currentTimeMillis()-Runtime.lastLinkReceiveStamp)/1000; - if (timeSincelastReceive>0) ICLogger.i("距离上次从服务器收到数据,已经有 " + timeSincelastReceive + " 秒!"); - if (SimSignalUtil.checkNet(runtime.getContextProxy().context) ) { + public void ReConnectToServer() { + long timeSincelastReceive = 0; + if (Runtime.lastLinkReceiveStamp > 0) + timeSincelastReceive = (System.currentTimeMillis() - Runtime.lastLinkReceiveStamp) / 1000; + if (timeSincelastReceive > 0) + ICLogger.i("距离上次从服务器收到数据,已经有 " + timeSincelastReceive + " 秒!"); + if (SimSignalUtil.checkNet(runtime.getContextProxy().context)) { //里面如果连接成功 connectionOpen 会先发送 AP00 登录包 和发送AP03 心跳包 , // isServerConnected 成功则停止重试, KeepAlive会检测AP03心跳包的成功与否。此处只管socket连接是否成功 if (connection.isServerConnected()) { ICLogger.i("retry 如果连接成功则停止重试!"); - no_network_Heartbeats_Count=0; + no_network_Heartbeats_Count = 0; stopConnectionRetryTimer(); - }else { + } else { if (retry_connect_count >= retry_connect_max_times) { no_network_Heartbeats_Count++; - ICLogger.i("retry " + retry_connect_count + " 次 >= " + retry_connect_max_times + " ,停止重试!等待下一次心跳再重试! 已经第"+no_network_Heartbeats_Count+"次心跳都没有连接服务器成功!"); + ICLogger.i("retry " + retry_connect_count + " 次 >= " + retry_connect_max_times + " ,停止重试!等待下一次心跳再重试! 已经第" + no_network_Heartbeats_Count + "次心跳都没有连接服务器成功!"); stopConnectionRetryTimer(); } else { @@ -1617,32 +1639,34 @@ public class CoreService extends Service { } } - }else{ + } else { //没有网络就不用重新尝试连接网络了。网络连接后再重新尝试联网 - ICLogger.i("retry "+no_network_Heartbeats_Count+" 没有网络就不用重新尝试连接网络了。网络连接后再重新尝试联网!"); + ICLogger.i("retry " + no_network_Heartbeats_Count + " 没有网络就不用重新尝试连接网络了。网络连接后再重新尝试联网!"); no_network_Heartbeats_Count++; stopConnectionRetryTimer(); } - if( no_network_Heartbeats_Count >12){ - ICLogger.i("当前第"+no_network_Heartbeats_Count+"次心跳都没有连接服务器成功 > 10 ,重置SIM卡尝试重新注册网络!"); + if (no_network_Heartbeats_Count > 12) { + ICLogger.i("当前第" + no_network_Heartbeats_Count + "次心跳都没有连接服务器成功 > 10 ,重置SIM卡尝试重新注册网络!"); SimSignalUtil.send_at_to_reset_simcard(runtime); //直接下此命令不能实现断网重连,所以干脆采用关闭网络再打开的方式。 - SimSignalUtil.setAirMode(this,"OpenAirplane"); - mHandler.postDelayed(reopenSim,5000); //5秒后重新链接服务器。 - no_network_Heartbeats_Count=0;//重置Sim卡后重置计数。防止后面多次重置Sim卡。 + SimSignalUtil.setAirMode(this, "OpenAirplane"); + mHandler.postDelayed(reopenSim, 5000); //5秒后重新链接服务器。 + no_network_Heartbeats_Count = 0;//重置Sim卡后重置计数。防止后面多次重置Sim卡。 } } - private Runnable reopenSim =new Runnable(){ + + private Runnable reopenSim = new Runnable() { @Override public void run() { - if (CoreService.getInstance()!=null) { + if (CoreService.getInstance() != null) { SimSignalUtil.setAirMode(CoreService.getInstance(), "CloseAirplane"); - // disconnect_server(); - // ReConnectToServer(); + // disconnect_server(); + // ReConnectToServer(); } } }; - public void stopConnectionRetryTimer(){ - if (mTimer_retry_connect !=null){ + + public void stopConnectionRetryTimer() { + if (mTimer_retry_connect != null) { mTimer_retry_connect.shutdownNow(); // while(!mTimer_retry_connect.isTerminated()) // { @@ -1658,13 +1682,11 @@ public class CoreService extends Service { } } - private boolean needLogin(){ + private boolean needLogin() { return true; } - - @Override public void onDestroy() { super.onDestroy(); @@ -1682,7 +1704,7 @@ public class CoreService extends Service { } - public void disconnect_server(){ + public void disconnect_server() { this.connection.close(); }