From: snickersun Date: Thu, 6 Feb 2020 06:55:37 +0000 (+0800) Subject: 1、通过Config.LOG_TOFILE控制输出log到文件 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=f592c1536a094d0b3c1fd7e5821c89cc2d919ed2;p=icsupport.git 1、通过Config.LOG_TOFILE控制输出log到文件 2、打通设置心率检测周期的协议 3、调整优化定位控制逻辑。为设置第5种随意定时cycle做准备 --- diff --git a/app/src/main/java/com/enqualcomm/support/Config.java b/app/src/main/java/com/enqualcomm/support/Config.java index d8f3975e..351b79f1 100644 --- a/app/src/main/java/com/enqualcomm/support/Config.java +++ b/app/src/main/java/com/enqualcomm/support/Config.java @@ -1,10 +1,18 @@ package com.enqualcomm.support; +import android.content.Context; +import android.content.SharedPreferences; import android.text.TextUtils; + +import com.enqualcomm.support.bean.ICLocation; +import com.enqualcomm.support.utils.SharPreferenceUtil; + import org.json.JSONException; import org.json.JSONStringer; public class Config { + + public static final boolean LOG_TOFILE=true; public static final String AUDIO_FORMAT = "1"; private static final String BT = "1@4.0"; @@ -263,5 +271,84 @@ public class Config { json = make(); return json; } + + final static String KeyProtocolServerIP="ProtocolServerIP"; + final static String KeyProtocolServerPort="ProtoclServerPort";; + final static String KeyFotaServerIP="FotaServerIP"; + final static String KeyFotaServerPort="FotaServerPort"; + + final static String KeyPpgTestCycle="PPGTestCycle"; + final static String KeyLocationCycle="LocationCycle"; + final static String KeyLocationMode="LocationMode";; + + final static String KeyAlarmCycle="HeartBeatCycle"; + + final static String KeyContactsList="ContactsList"; + final static String KeySOSNumbersList="SOSNumbersList"; + + + + 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); + } + + public static void setProtocolServerAddr(Context context, String serverIP,int serverPort){ + SharPreferenceUtil.setPrefString(context,KeyProtocolServerIP,serverIP); + SharPreferenceUtil.setPrefInt(context,KeyProtocolServerPort,serverPort); + } + + public static String getProtocolServerIP(Context context){ + return SharPreferenceUtil.getPrefString(context,KeyProtocolServerIP,"118.178.155.223"); + } + + public static int getProtocolServerPort(Context context){ + return SharPreferenceUtil.getPrefInt(context,KeyProtocolServerPort,8090); + } + + public static void setFotaServerIP(Context context,String serverIP,int serverPort){ + + SharPreferenceUtil.setPrefString(context,KeyFotaServerIP,serverIP); + SharPreferenceUtil.setPrefInt(context,KeyFotaServerPort,serverPort); + + } + public static String getFotaServerIP(Context context){ + return SharPreferenceUtil.getPrefString(context,KeyFotaServerIP,"icfota.snicker.com.cn"); + } + + public static int getFotaServerPort(Context context){ + return SharPreferenceUtil.getPrefInt(context,KeyFotaServerPort,8089); + } + + + public static void setPPGTestCycle(Context context,int cycle){ + SharPreferenceUtil.setPrefInt(context,KeyPpgTestCycle,cycle); + } + + public static int getPPGTestCycle(Context context){ + return SharPreferenceUtil.getPrefInt(context,KeyPpgTestCycle,30); + } + + public static void setLocationCycle(Context context,int cycle){ + SharPreferenceUtil.setPrefInt(context,KeyLocationCycle,cycle); + } + + public static int getLocationCycle(Context context){ + return SharPreferenceUtil.getPrefInt(context,KeyLocationCycle,15); + } + + public static void setLocationMode(Context context,int mode){ + SharPreferenceUtil.setPrefInt(context,KeyLocationMode,mode); + } + + + public static int getLocationMode(Context context){ + return SharPreferenceUtil.getPrefInt(context,KeyLocationMode, ICLocation.NORMAL_MOD); + } + } diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 415c55e1..83f2bd23 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -135,7 +135,7 @@ public class CoreService extends Service { stringBuilder1.append(Integer.valueOf(str, 16)); stringBuilder1.append(",CELLID="); stringBuilder1.append(Integer.valueOf(str1, 16)); - FileOutputUtil.fileOutput(runtime.getCacheDir(), "cellInfoTest", stringBuilder1.toString()); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "cellInfoTest", stringBuilder1.toString()); } } } @@ -147,7 +147,7 @@ public class CoreService extends Service { StringBuilder stringBuilder2 = new StringBuilder(); stringBuilder2.append("broadcastReceiver alarmCycle action=="); stringBuilder2.append(param1Intent.getAction()); - FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder2.toString()); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder2.toString()); StringBuilder stringBuilder1 = new StringBuilder(); stringBuilder1.append("时间变化"); stringBuilder1.append(param1Intent.getAction()); @@ -155,7 +155,7 @@ public class CoreService extends Service { CoreService.this.setSleepAlarm(); CoreService.this.setWakeAlarm(); CoreService.this.setHeartAlarm(); - CoreService.this.setHeartRateDetectAlarm(3); + CoreService.this.setHeartRateDetectAlarm(runtime.getPpgTestCycle()); CoreService.this.setWeatherAlarm(); CoreService.this.setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); if (CoreService.this.cmcm_call_eiot_into_powersave_mode() == 0) @@ -290,6 +290,11 @@ public class CoreService extends Service { } + private void loadSettings(){ + this.runtime.setPpgTestCycle(Config.getPPGTestCycle(this)); + this.runtime.getLocationInstance().setLocation_cycle(Config.getLocationCycle(this)); + this.runtime.getLocationInstance().setWorkingMod(Config.getLocationMode(this)); + } private void loadStepCount() { int i = SharPreferenceUtil.getPrefInt(this, KEY_STEP_COUNT, 0); @@ -399,10 +404,16 @@ public class CoreService extends Service { Logger.i("1 into powersave return"); return; } + + + //保证获取正确的计步数据及其他参数初始化 + loadStepCount(); + loadSettings(); + this.connectionServiceChain.processAttach(this.connection, this.runtime); this.invokeHandlerServiceChain.processAttach(this.connection, this.runtime); setAlarm(alarmCycle); - FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "设置闹钟服务 alarmCycle"); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "设置闹钟服务 alarmCycle"); this.locationClient = new LocationClient(this.connection, this.runtime); this.connection.open(); this.connection.connect(this.runtime.getSrvIP(), this.runtime.getPort()); @@ -444,8 +455,6 @@ public class CoreService extends Service { batteryUtil = new BatteryUtil(this.runtime); batteryUtil.registerBroadReceiver(); - //保证获取正确的计步数据 - loadStepCount(); //设置计步清零时间。 setCleanStepCountAlarm(); @@ -460,7 +469,7 @@ public class CoreService extends Service { setHeartAlarm(); //设置心率检测频率 - setHeartRateDetectAlarm(3); //3分钟一次 + setHeartRateDetectAlarm(runtime.getPpgTestCycle()); //3分钟一次 //获取天气时间 setWeatherAlarm(); @@ -489,10 +498,12 @@ public class CoreService extends Service { Logger.i("2 into powersave return"); return Service.START_NOT_STICKY; } + + //wakeup后1分钟唤醒一次,5分钟后,心跳改为从配置信息读取的值,默认为3分钟 if (this.startAlarmCount < 5 && alarmCycle == 1) { this.startAlarmCount++; } else { - alarmCycle = SharPreferenceUtil.getPrefInt((this.runtime.getContextProxy()).context, "location_cycle", 3); + alarmCycle = Config.getAlarmCycle(this); } AlarmWakeUp.setAlarmWakeUpTime(); boolean screenon = ((PowerManager)getSystemService(POWER_SERVICE)).isScreenOn(); @@ -505,7 +516,7 @@ public class CoreService extends Service { Util.turnOffWifiForSleep((this.runtime.getContextProxy()).context, this.runtime); } setAlarm(alarmCycle); - FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "ALARM alarmCycle"); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "ALARM alarmCycle"); //发送心跳间隔广播给其他应用 this.runtime.getContextProxy().sendBroadcast(ACTION_EQC_ALARM, this.runtime); @@ -522,7 +533,7 @@ public class CoreService extends Service { if (Constants.SLEEP_ALARM.equals(paramIntent.getAction())) { Logger.i("SLEEP_ALARM"); is_allowed_in_sleep_mode = 1; - FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "SLEEP_ALARM alarmCycle"); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "SLEEP_ALARM alarmCycle"); setSleepAlarm(); boolean bool = ((PowerManager)getSystemService(POWER_SERVICE)).isScreenOn(); stringBuilder1 = new StringBuilder(); @@ -540,7 +551,7 @@ public class CoreService extends Service { if (Constants.WAKE_ALARM.equals(paramIntent.getAction())) { if (is_in_sleep_mode) { is_in_sleep_mode = false; - FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "WAKE_ALARM alarmCycle"); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "WAKE_ALARM alarmCycle"); if (this.mKeepAlive != null) this.mKeepAlive.setSleepMode(false); wakeUpFromSleep(); @@ -553,7 +564,7 @@ public class CoreService extends Service { if (this.mKeepAlive != null) { this.mKeepAlive.onHeartAlarm(this.connection, this.runtime); setHeartAlarm(); - FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "HEART_ALARM alarmCycle " ); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "HEART_ALARM alarmCycle " ); return Service.START_STICKY; } } else { @@ -579,21 +590,33 @@ public class CoreService extends Service { stringBuilder1 = new StringBuilder(); stringBuilder1.append("STWORKMODE_ALARM alarmCycle="); stringBuilder1.append(alarmCycle); - FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder1.toString()); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder1.toString()); return Service.START_STICKY; } if (ACTION_LOCATION_ALARM.equals(paramIntent.getAction())){ + //收到定时定位消息 setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); stringBuilder1 = new StringBuilder(); stringBuilder1.append("LOCATION_ALARM work mod="); stringBuilder1.append(runtime.getLocationInstance().getWorkingMod()); - FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder1.toString()); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder1.toString()); this.locationClient.triggerLocationProcess(); return Service.START_STICKY; } if(ACTION_HEATR_RATE_START.equals(paramIntent.getAction())){ + //此消息来源于BroadCaset以及Timer,收到开始测试的消息,马上发送消息给HeartRateManager开始测试。 + //此时需要重置HeartRateDetect Timer + //倘若有 参数 PPGTestCycle,则根据这个数值进行设置 + int ppgtestCycle=paramIntent.getIntExtra("PPGTestCycle",-1); + if (ppgtestCycle >0){ + Config.setPPGTestCycle(this,ppgtestCycle); + runtime.setPpgTestCycle(Config.getPPGTestCycle(this)); + Logger.i("get and set PPGTestCycle "+ppgtestCycle); + } + setHeartRateDetectAlarm(runtime.getPpgTestCycle()); this.invokeHandlerServiceChain.processUserRequest(paramIntent, this.connection, this.runtime); + } } } @@ -657,7 +680,7 @@ public class CoreService extends Service { locationClient.triggerLocationProcess(); Logger.i(sb.toString()); - FileOutputUtil.fileOutput(runtime.getCacheDir(),"LocationAlarm",sb.toString()); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(),"LocationAlarm",sb.toString()); } public void setHeartAlarm(){ diff --git a/app/src/main/java/com/enqualcomm/support/CrashHandler.java b/app/src/main/java/com/enqualcomm/support/CrashHandler.java index e0fc8028..5f958004 100644 --- a/app/src/main/java/com/enqualcomm/support/CrashHandler.java +++ b/app/src/main/java/com/enqualcomm/support/CrashHandler.java @@ -34,7 +34,7 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler { // 系统默认的UncaughtException处理类 private Thread.UncaughtExceptionHandler mDefaultHandler; // CrashHandler实例 - private static CrashHandler INSTANCE = new CrashHandler(); + private static CrashHandler INSTANCE = null; // 程序的Context对象 private Context mContext; // 用来存储设备信息和异常信息 @@ -52,7 +52,9 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler { /** * 获取CrashHandler实例 ,单例模式 */ - public static CrashHandler getInstance() { + public synchronized static CrashHandler getInstance() { + if (INSTANCE==null) + INSTANCE=new CrashHandler(); return INSTANCE; } diff --git a/app/src/main/java/com/enqualcomm/support/GSensorListener.java b/app/src/main/java/com/enqualcomm/support/GSensorListener.java index d660cafd..0e744eb5 100644 --- a/app/src/main/java/com/enqualcomm/support/GSensorListener.java +++ b/app/src/main/java/com/enqualcomm/support/GSensorListener.java @@ -32,7 +32,7 @@ public class GSensorListener { Logger.i(stringBuilder1.toString()); runtime.setTotalStepCount(CURRENT_STEP); GSensorListener.getStepCountOver=false; - FileOutputUtil.fileOutput(runtime.getCacheDir(), "CURRENT_STEP", stringBuilder1.toString()); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "CURRENT_STEP", stringBuilder1.toString()); } }; diff --git a/app/src/main/java/com/enqualcomm/support/LocationClient.java b/app/src/main/java/com/enqualcomm/support/LocationClient.java index b09d1525..6beaf95a 100644 --- a/app/src/main/java/com/enqualcomm/support/LocationClient.java +++ b/app/src/main/java/com/enqualcomm/support/LocationClient.java @@ -242,7 +242,7 @@ public class LocationClient { public void call(Object param1Object) { LocationClient.this.waitAndSendLocation(); } }); }else if (msg.what == 0){ - startLocationProcess(WorkingMod); + startLocationProcess(runtime.getLocationInstance().getWorkingMod()); } @@ -377,14 +377,14 @@ public void updateCellInfo() { public void startLocationProcess(int mod){ updateStepCount();//update StepCount,保证每次定位前,计步数据是最新的。防止丢数据。 - Logger.i("forceLocation="+forceLocation+", WorkingMod="+WorkingMod+", isLocating="+isLocating+", lastStep="+runtime.getLastStepCount()+", currentStep="+ runtime.getTotalStepCount()); + Logger.i("forceLocation="+forceLocation+", WorkingMod="+mod+", isLocating="+isLocating+", lastStep="+runtime.getLastStepCount()+", currentStep="+ runtime.getTotalStepCount()); if (isLocating ) { Logger.i("locating ,skip location!"); return; } // 不强制定位 且 WorkingMod 不是紧急模式,且 没有移动过 - if ( !(( forceLocation == 1 ) || ( WorkingMod == 4 )) && ( runtime.getLastStepCount() == runtime.getTotalStepCount()) ){ + if ( !(( forceLocation == 1 ) || ( mod == 4 )) && ( runtime.getLastStepCount() == runtime.getTotalStepCount()) ){ Logger.i("No Move ,skip location!"); return ; } @@ -407,7 +407,6 @@ public void updateCellInfo() { startCheckResult(); } - private static int WorkingMod=1; private static int forceLocation=0; public void onReceive(StringMessage paramStringMessage) { @@ -416,28 +415,15 @@ public void updateCellInfo() { //响应定位指令 if ("StartLocate".equals(paramStringMessage.cmd()) ){ forceLocation=1; - this.startLocationProcess(WorkingMod); + this.startLocationProcess(runtime.getLocationInstance().getWorkingMod()); } if ("setWorkMod".equals(paramStringMessage.cmd())) { - int mod = 0; - try - { - String[] cmdlist=paramStringMessage.isFromCache().split(","); - if (cmdlist.length == 4) - mod = Integer.valueOf(cmdlist[3]); - }catch (Exception e){ - e.printStackTrace(); - } - SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, LOCATION_MODE, mod); - runtime.getLocationInstance().setWorkingMod(mod); -// runtime.getLocationInstance().setLocation_cycle(3); + int mod = runtime.getLocationInstance().getWorkingMod(); Logger.i("Set WorkMODE "+mod +" and reset Location AlarmCycle"); CoreService.getInstance().setLocationAlarm(mod); -// Logger.i("ResartLOCATION_MODE 2"); - runtime.getContextProxy().sendBroadcast(LOCATION_MODE,runtime); forceLocation=1; this.startLocationProcess(mod); - WorkingMod=mod; + } } @@ -450,27 +436,12 @@ public void updateCellInfo() { //获取LBS定位服务 this.mLbsHelper = runtime.getLbsHelper(); - //初始化设定当前工作模式及循环频率 - if (SharPreferenceUtil.getPrefInt((runtime.getContextProxy()).context, "value_setting_ver", 0) == Config.value_setting) { - //如果value_setting_ver = Config.value_setting 表示采用已经保存的模式 - runtime.getLocationInstance().setWorkingMod(SharPreferenceUtil.getPrefInt((runtime.getContextProxy()).context, LOCATION_MODE, ICLocation.NORMAL_MOD)); -// runtime.getLocationInstance().setLocation_cycle(SharPreferenceUtil.getPrefInt((runtime.getContextProxy()).context, LOCATION_CYCLE, 3)); -// runtime.getLocationInstance().setLocation_cycle(15); - } else { - //否则设置一个默认值 - SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, "value_setting_ver", Config.value_setting); - SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, LOCATION_MODE, ICLocation.NORMAL_MOD); -// SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, LOCATION_CYCLE, 3); - runtime.getLocationInstance().setWorkingMod(ICLocation.NORMAL_MOD); -// runtime.getLocationInstance().setLocation_cycle(15); - } +// StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("value_setting="); - stringBuilder.append(SharPreferenceUtil.getPrefInt((runtime.getContextProxy()).context, "value_setting_ver", 0)); stringBuilder.append("LOCATION_MODE="); - stringBuilder.append(SharPreferenceUtil.getPrefInt((runtime.getContextProxy()).context, LOCATION_MODE, 1)); + stringBuilder.append(runtime.getLocationInstance().getWorkingMod()); stringBuilder.append("LOCATION_CYCLE="); - stringBuilder.append(SharPreferenceUtil.getPrefInt((runtime.getContextProxy()).context, LOCATION_CYCLE, 3)); + stringBuilder.append(runtime.getLocationInstance().getLocation_cycle()); Logger.i(stringBuilder.toString()); diff --git a/app/src/main/java/com/enqualcomm/support/NMEAListener.java b/app/src/main/java/com/enqualcomm/support/NMEAListener.java index b9bbaf5b..11113eaa 100644 --- a/app/src/main/java/com/enqualcomm/support/NMEAListener.java +++ b/app/src/main/java/com/enqualcomm/support/NMEAListener.java @@ -234,7 +234,7 @@ public class NMEAListener implements NmeaListener, LocationListener { stop(200); } - FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",sb2.toString()); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",sb2.toString()); Logger.i( sb2.toString()); getBestLocation(locationManager,status); @@ -336,7 +336,7 @@ public class NMEAListener implements NmeaListener, LocationListener { Logger.i( sb.toString()); - FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",sb.toString()); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",sb.toString()); runtime.getLocationInstance().setLocation(latitude,longitude,speed,0,status.getMaxSatellites()); } diff --git a/app/src/main/java/com/enqualcomm/support/adapter/LBSHelper.java b/app/src/main/java/com/enqualcomm/support/adapter/LBSHelper.java index 98dc2bb7..a4865ff0 100644 --- a/app/src/main/java/com/enqualcomm/support/adapter/LBSHelper.java +++ b/app/src/main/java/com/enqualcomm/support/adapter/LBSHelper.java @@ -21,6 +21,7 @@ import android.telephony.TelephonyManager; import android.telephony.cdma.CdmaCellLocation; import android.telephony.gsm.GsmCellLocation; +import com.enqualcomm.support.Config; import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.utils.FileOutputUtil; import com.enqualcomm.support.utils.Logger; @@ -268,7 +269,7 @@ public class LBSHelper { this.runtime.setCellinfo(gsmSb.toString()); this.runtime.setCdmaInfo(null); Logger.i("GsmCellLocation "+ gsmSb.toString()); - FileOutputUtil.fileOutput(this.runtime.getCacheDir(), "onCellLocationChanged", gsmSb.toString()); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(this.runtime.getCacheDir(), "onCellLocationChanged", gsmSb.toString()); List neighboringCell_list = telephonyManager.getNeighboringCellInfo(); if (neighboringCell_list != null && !neighboringCell_list.isEmpty()) { @@ -318,7 +319,7 @@ public class LBSHelper { this.runtime.setCellinfo(null); this.runtime.setCdmaInfo(cdmaSB.toString()); - FileOutputUtil.fileOutput(this.runtime.getCacheDir(), "onCellLocationChanged", var8.toString()); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(this.runtime.getCacheDir(), "onCellLocationChanged", var8.toString()); return cdmaSB.toString(); } diff --git a/app/src/main/java/com/enqualcomm/support/adapter/protocolAPIHelper.java b/app/src/main/java/com/enqualcomm/support/adapter/protocolAPIHelper.java index f9c80cbb..fa87037b 100644 --- a/app/src/main/java/com/enqualcomm/support/adapter/protocolAPIHelper.java +++ b/app/src/main/java/com/enqualcomm/support/adapter/protocolAPIHelper.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.HashMap; 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_IMESSAGE; import static com.enqualcomm.support.LocationClient.LOCATION_CYCLE; import static com.enqualcomm.support.LocationClient.LOCATION_MODE; @@ -910,13 +911,11 @@ public class protocolAPIHelper { connection.send(genStringMessage("AP33",msg)); log("reply msg "+msg); log("LOCATION_MODE "+LOCATION_MODE+" mod "+ mod); - SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, "value_setting_ver", Config.value_setting); - SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, LOCATION_MODE, mod); -// SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, LOCATION_CYCLE, Cycle); - runtime.getLocationInstance().setWorkingMod(mod); + Config.setLocationMode(runtime.getContextProxy().context,mod); + Config.setLocationCycle(runtime.getContextProxy().context,Cycle); runtime.getLocationInstance().setLocation_cycle(Cycle); - - + runtime.getLocationInstance().setWorkingMod(mod); + //此处设置好配置后,会在LocationClient通过消息开始执行及时定位操作。 } } @@ -1231,7 +1230,7 @@ public static String AP15(String index){ .append(CMDEND).toString(); } - public void handleBP86(String cmd,Connection connection){ + public void handleBP86(String cmd,Connection connection,Runtime runtime){ //示例: //IWBP86, 353456789012345, 080835,1,720# @@ -1251,6 +1250,11 @@ public static String AP15(String index){ String cycle=list[4]; connection.send(protocolAPIHelper.genStringMessage("AP86",AP86(index))); Logger.i("收到服务器指令:设置"+(type.equals("1")?"心率周期 ":"血压周期 ")+cycle+"分钟"); + + //发送重置PPGCycle的广播,会在CoreServer里面执行 + Intent intent = new Intent(); + intent.putExtra("PPGTestCycle",Integer.valueOf(cycle)); + runtime.getContextProxy().sendBrodcast(ACTION_HEATR_RATE_START,intent); }else{ Logger.i("BP86 format error!"); } diff --git a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java index 2d341413..a5867ab7 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java +++ b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java @@ -39,7 +39,8 @@ public class Runtime { private String currentCellInfo; // public String currentWifiInfo=""; - + private int ppgTestCycle; + private DBHelper dbHelper; private String device_id; @@ -89,6 +90,14 @@ public class Runtime { private boolean lockSimInfo=false; + public void setPpgTestCycle(int cycle){ + ppgTestCycle=cycle; + } + + public int getPpgTestCycle(){ + return ppgTestCycle; + } + public void setUseQueue(boolean usequeue){ UseQueue=usequeue; } diff --git a/app/src/main/java/com/enqualcomm/support/bean/voicePacket.java b/app/src/main/java/com/enqualcomm/support/bean/voicePacket.java index b7dcee42..bfcc9923 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/voicePacket.java +++ b/app/src/main/java/com/enqualcomm/support/bean/voicePacket.java @@ -7,13 +7,13 @@ public class voicePacket { private static voicePacket gvoicePacket=null; - public static voicePacket getInstance(){ + public synchronized static voicePacket getInstance(){ if (gvoicePacket==null) gvoicePacket=new voicePacket(); return gvoicePacket; } private static voicePacket gvoicepacket_sent=null; - public static voicePacket getInstanceSent(){ + public synchronized static voicePacket getInstanceSent(){ if (gvoicepacket_sent==null) gvoicepacket_sent=new voicePacket(); return gvoicepacket_sent; diff --git a/app/src/main/java/com/enqualcomm/support/service/Deliver.java b/app/src/main/java/com/enqualcomm/support/service/Deliver.java index 31e05a84..4d6e8021 100644 --- a/app/src/main/java/com/enqualcomm/support/service/Deliver.java +++ b/app/src/main/java/com/enqualcomm/support/service/Deliver.java @@ -16,6 +16,7 @@ import android.os.PowerManager; import android.os.SystemClock; import android.text.TextUtils; +import com.enqualcomm.support.Config; import com.enqualcomm.support.CoreService; import com.enqualcomm.support.LocationClient; import com.enqualcomm.support.adapter.protocolAPIHelper; @@ -279,7 +280,7 @@ public class Deliver extends AbstractConnectionService { stringBuilder.append(stringMessage.cmd()); stringBuilder.append(", "); stringBuilder.append(stringMessage.isFromCache()); - FileOutputUtil.fileOutput(mRuntime.getCacheDir(), "MessageInfo", stringBuilder.toString()); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(mRuntime.getCacheDir(), "MessageInfo", stringBuilder.toString()); Logger.i(stringBuilder.toString()); if( connection.isServerConnected() ==false && !KeepAlive.isConnected ) { @@ -341,7 +342,7 @@ public static void sendLocationMSG( String Msg){ connection.send(protocolAPIHelper.genStringMessage("queue",Msg)); } else { Logger.i("offline skip " + Msg); - FileOutputUtil.fileOutput(mRuntime.getCacheDir(), "APILog", " offlineskip " + Msg); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(mRuntime.getCacheDir(), "APILog", " offlineskip " + Msg); } } } diff --git a/app/src/main/java/com/enqualcomm/support/utils/AlarmWakeUp.java b/app/src/main/java/com/enqualcomm/support/utils/AlarmWakeUp.java index 7b273be5..56d82a77 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/AlarmWakeUp.java +++ b/app/src/main/java/com/enqualcomm/support/utils/AlarmWakeUp.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.os.SystemClock; import android.util.Log; +import com.enqualcomm.support.Config; import com.enqualcomm.support.bean.Contact; import com.enqualcomm.support.bean.Runtime; import com.enqualcomm.support.CoreService; @@ -13,21 +14,21 @@ import com.enqualcomm.support.CoreService; public class AlarmWakeUp { private static long lastAlarmTime; - public static void isNeedWakeUpAlarm(Runtime dev) { + public static void isNeedWakeUpAlarm(Runtime runtime) { long l = SystemClock.elapsedRealtime(); - int i = SharPreferenceUtil.getPrefInt((dev.getContextProxy()).context, "location_cycle", 3); + int i = Config.getAlarmCycle(runtime.getContextProxy().context); if (l - lastAlarmTime > ((i + 1) * 60 * 1000)) { ComponentName componentName = new ComponentName("com.enqualcomm.support", "com.enqualcomm.support.CoreService"); Intent intent = (new Intent(CoreService.ACTION_ALARM)).setComponent(componentName); - (dev.getContextProxy()).context.startService(intent); + (runtime.getContextProxy()).context.startService(intent); StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("currentTimeMillis="); + stringBuilder.append("isNeedWakeUpAlarm currentTimeMillis="); stringBuilder.append(l); stringBuilder.append("---lastAlarmTime="); stringBuilder.append(lastAlarmTime); Logger.i("AlarmWakeUp "+ stringBuilder.toString()); - FileOutputUtil.fileOutput(dev.getCacheDir(), "alarmWakeUp", stringBuilder.toString()); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmWakeUp", stringBuilder.toString()); } } diff --git a/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java b/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java index 9d94eb7a..7303f785 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/BatteryUtil.java @@ -6,6 +6,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import com.enqualcomm.support.Config; import com.enqualcomm.support.bean.Runtime; public class BatteryUtil { @@ -20,7 +21,7 @@ public class BatteryUtil { } int i = param1Intent.getIntExtra("level", 0) * 100 / param1Intent.getIntExtra("scale", 100); - FileOutputUtil.fileOutput(mRuntime.getCacheDir(),"Battery","BatteryLevel "+i); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(mRuntime.getCacheDir(),"Battery","BatteryLevel "+i); if (i >= 100) { Runtime runtime = BatteryUtil.this.mRuntime; StringBuffer stringBuffer = BatteryUtil.this.mBuffer; diff --git a/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java b/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java index c0c1f5f4..27b2877f 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java @@ -4,6 +4,7 @@ import android.os.Handler; import android.os.Message; import android.os.PowerManager; +import com.enqualcomm.support.Config; import com.enqualcomm.support.GSensorListener; import com.enqualcomm.support.bean.Runtime; @@ -106,7 +107,7 @@ public class CellInfoUtil { // EqcAlgorithmNative.native_EqcAlgorithmMethod4(0, 0, CellInfoUtil.BSSS, CellInfoUtil.MCC, CellInfoUtil.MNC, CellInfoUtil.LAC, CellInfoUtil.CELL_ID); mRuntime.cellinfo = mCellInfo; } - FileOutputUtil.fileOutput(mRuntime.getCacheDir(),"onCellLocationChanged", mCellInfo); + if (Config.LOG_TOFILE)FileOutputUtil.fileOutput(mRuntime.getCacheDir(),"onCellLocationChanged", mCellInfo); CellInfoUtil.releaseWakeLock(mWakeLock); Logger.i(" setCurrentAttachCellInfo " + mCellInfo); @@ -132,7 +133,7 @@ public class CellInfoUtil { stringBuilder.append(CellInfoUtil.BSSS); runtime.cellinfo = stringBuilder.toString(); // EqcAlgorithmNative.native_EqcAlgorithmMethod4(1, 0, CellInfoUtil.BSSS, CellInfoUtil.MCC, CellInfoUtil.MNC, CellInfoUtil.LAC, CellInfoUtil.CELL_ID); - FileOutputUtil.fileOutput(mRuntime.getCacheDir(), "onCellLocationChanged", mRuntime.cellinfo); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(mRuntime.getCacheDir(), "onCellLocationChanged", mRuntime.cellinfo); CellInfoUtil.releaseWakeLock(mWakeLock); Logger.i(" setCurrentAttachCellInfo " + mCellInfo); diff --git a/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java b/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java index 369852dd..22a2b25f 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java +++ b/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java @@ -280,6 +280,10 @@ public class ContextProxy { } } + public void sendBrodcast(String action,Intent intent){ + intent.setAction(action); + this.context.sendBroadcast(intent); + } public void sendBroadcast(String cmd, Runtime dev) { Intent intent = new Intent(); diff --git a/app/src/main/java/com/enqualcomm/support/utils/Logger.java b/app/src/main/java/com/enqualcomm/support/utils/Logger.java index eb8597a9..6b6514b5 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/Logger.java +++ b/app/src/main/java/com/enqualcomm/support/utils/Logger.java @@ -2,6 +2,7 @@ package com.enqualcomm.support.utils; import android.util.Log; +import com.enqualcomm.support.Config; import com.enqualcomm.support.CoreService; public class Logger { @@ -68,8 +69,9 @@ public class Logger { public static void log(String TAG, String msg) { if (DEBUG) { Log.e(TAG, msg); - if (CoreService.getInstance()!=null) - FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"log",TAG + " "+ msg); + if (CoreService.getInstance()!=null) { + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(), "log", TAG + " " + msg); + } } @@ -78,8 +80,9 @@ public class Logger { public static void log(String TAG,String funcName, String msg) { if (DEBUG) { Log.e(TAG, "[" + funcName + "]" + msg); - if (CoreService.getInstance()!=null) - FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"log",TAG + " "+ "[" + funcName + "]" + msg); + if (CoreService.getInstance()!=null) { + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(), "log", TAG + " " + "[" + funcName + "]" + msg); + } } } } diff --git a/app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java b/app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java index 35b963e2..932b6436 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java +++ b/app/src/main/java/com/enqualcomm/support/utils/NettyConnection.java @@ -7,6 +7,7 @@ import android.os.Message; import android.os.SystemClock; +import com.enqualcomm.support.Config; import com.enqualcomm.support.LocationClient; import com.enqualcomm.support.adapter.protocolAPIHelper; import com.enqualcomm.support.bean.StringMessage; @@ -51,7 +52,7 @@ public class NettyConnection implements Connection { Runtime runtime=CoreService.getInstance().getRuntime(); boolean ret=true; Logger.i("handleCmd "+type.name() + " strLen="+cmd.length()); - FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog", " recv " + cmd); + if (Config.LOG_TOFILE)FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog", " recv " + cmd); switch (type){ case BP00: API.handleBP00(cmd); @@ -158,7 +159,7 @@ public class NettyConnection implements Connection { break; case BP86: - API.handleBP86(cmd,NettyConnection.this); + API.handleBP86(cmd,NettyConnection.this,runtime); // Logger.i(""); break; case BP89: @@ -177,7 +178,7 @@ public class NettyConnection implements Connection { Runtime runtime=CoreService.getInstance().getRuntime(); boolean ret=true; Logger.i("handleCmd "+type.name() + " "+cmd+" bytelen="+bytes.length ); - FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog", " recv " +new String(bytes)); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog", " recv " +new String(bytes)); switch (type) { case BP28: API.handleBP28(NettyConnection.this,cmd, runtime,bytes); @@ -291,7 +292,7 @@ public class NettyConnection implements Connection { if (!isServerConnected()){ log("skiped"+cmd); - FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog"," skiped " + cmd); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog"," skiped " + cmd); return false; }else{ log("send "+cmd); @@ -312,7 +313,7 @@ public class NettyConnection implements Connection { } ); - FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog"," sent " + cmd); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog"," sent " + cmd); } @@ -329,7 +330,7 @@ public class NettyConnection implements Connection { if (!isServerConnected()){ log("skipedBytes "+new String(cmdArray)); - FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog"," skiped " + new String(cmdArray)); + if (Config.LOG_TOFILE)FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog"," skiped " + new String(cmdArray)); return false; }else{ log("sendBytes "+new String(cmdArray)); @@ -349,7 +350,7 @@ public class NettyConnection implements Connection { } ); - FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog"," sentBytes " + new String(cmdArray)); + if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(CoreService.getInstance().getRuntime().getCacheDir(),"APILog"," sentBytes " + new String(cmdArray)); } diff --git a/app/src/main/java/com/enqualcomm/support/utils/RxSocket.java b/app/src/main/java/com/enqualcomm/support/utils/RxSocket.java index 599e4467..55bc205a 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/RxSocket.java +++ b/app/src/main/java/com/enqualcomm/support/utils/RxSocket.java @@ -51,7 +51,7 @@ public class RxSocket { readSubject = new SerializedSubject(PublishSubject.create()); connectStatus = new SerializedSubject(PublishSubject.create()); } - public static RxSocket getInstance() { + public synchronized static RxSocket getInstance() { RxSocket rxSocket = defaultInstance; if (defaultInstance == null) { synchronized (chestnut.RxSocket.RxSocket.class) { diff --git a/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java b/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java index baba2021..640f45d8 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java @@ -45,7 +45,7 @@ public class SimSignalUtil { init(); } - public static SimSignalUtil getInstance(Context paramContext) { + public synchronized static SimSignalUtil getInstance(Context paramContext) { if (simSignalUtil ==null) simSignalUtil = new SimSignalUtil(paramContext); return simSignalUtil;