From: snickersun Date: Tue, 28 Jan 2020 14:26:35 +0000 (+0800) Subject: 1、修改 FileOutputUtil.fileOutput 函数,减少日志中查找路径出错信息。 函数需要的路径,都通过runtime的getCacheDir来获得。 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=2148e6c93ae21d1c3657c5fc6cd0c9573aa3db30;p=icsupport.git 1、修改 FileOutputUtil.fileOutput 函数,减少日志中查找路径出错信息。 函数需要的路径,都通过runtime的getCacheDir来获得。 2、增加HeartRateManger,解析BPXL,BPXY,BPJZ等函数,并通过APHT同时上报血压心率。(手表端apk手动检测和上传心率血压还没接入) --- diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5072e555..65ffeaae 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -133,6 +133,7 @@ + @@ -159,6 +160,7 @@ + diff --git a/app/src/main/java/com/ic/protocol/GSensorListener.java b/app/src/main/java/com/ic/protocol/GSensorListener.java index f99b7f86..17c1c1d6 100644 --- a/app/src/main/java/com/ic/protocol/GSensorListener.java +++ b/app/src/main/java/com/ic/protocol/GSensorListener.java @@ -11,6 +11,7 @@ import android.os.PowerManager; import com.ic.jni.ICJniUtils; import com.ic.protocol.bean.Runtime; +import com.ic.protocol.service.protocolMainServer; import com.ic.protocol.utils.CellInfoUtil; import com.ic.protocol.utils.FileOutputUtil; import com.ic.protocol.utils.Logger; @@ -54,7 +55,7 @@ public class GSensorListener implements SensorEventListener { // GSensorListener.getStepCountOver=false; // EqcAlgorithmNative.native_EqcAlgorithmMethod6(0.0F, 0.0F, 0.0F, GSensorListener.this.CURRENT_STEP); Context context = GSensorListener.this.mContext; - FileOutputUtil.fileOutput(context, "CURRENT_STEP", stringBuilder1.toString()); + FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(), "CURRENT_STEP", stringBuilder1.toString()); // GSensorListener.access$502(GSensorListener.this, null); GSensorListener.this.releaseWakeLock(GSensorListener.this.mWakeLock); } @@ -147,7 +148,7 @@ public class GSensorListener implements SensorEventListener { StringBuilder stringBuilder2 = new StringBuilder(); stringBuilder2.append("CURRENT_STEP="); stringBuilder2.append(this.CURRENT_STEP); - FileOutputUtil.fileOutput(context, "CURRENT_STEP", stringBuilder2.toString()); + FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(), "CURRENT_STEP", stringBuilder2.toString()); this.sensorManager.unregisterListener(this); releaseWakeLock(this.mWakeLock); } diff --git a/app/src/main/java/com/ic/protocol/LocationClient.java b/app/src/main/java/com/ic/protocol/LocationClient.java index 3a90f629..b1f506fa 100644 --- a/app/src/main/java/com/ic/protocol/LocationClient.java +++ b/app/src/main/java/com/ic/protocol/LocationClient.java @@ -342,7 +342,7 @@ public class LocationClient { && runtime.getLocationInstance().getMCC().equals("0") && runtime.getLocationInstance().getGSMStationCID() ==0 && runtime.getLocationInstance().getLAC()==0)) ?false:true; - Logger.i("getMNC "+runtime.getLocationInstance().getMNC()+" getMCC "+runtime.getLocationInstance().getMCC()+" getGSMStationCID " + runtime.getLocationInstance().getGSMStationCID()+ " getLAC "+runtime.getLocationInstance().getLAC()+" changed "+runtime.getLocationInstance().isDataChanged()); +// Logger.i("getMNC "+runtime.getLocationInstance().getMNC()+" getMCC "+runtime.getLocationInstance().getMCC()+" getGSMStationCID " + runtime.getLocationInstance().getGSMStationCID()+ " getLAC "+runtime.getLocationInstance().getLAC()+" changed "+runtime.getLocationInstance().isDataChanged()); Logger.i("lbs_ok "+lbs_ok+" waitAndSendLocation wifi_ok " + wifi_ok+ " gps_ok "+gps_ok + " mode "+mode); switch(mode){ @@ -354,8 +354,16 @@ public class LocationClient { if ((lbs_ok && timeout==true) ||(lbs_ok && gps_ok && wifi_ok )||(lbs_ok&&gps_nosignal&&wifi_ok)){ - Logger.i("offerQueue "+protocolAPIHelper.AP01(runtime)); - connection.send(protocolAPIHelper.genStringMessage("AP01", protocolAPIHelper.AP01(runtime))); + String AP01_CMD=protocolAPIHelper.AP01(runtime); + if (connection.isServerConnected() && KeepAlive.isConnected) + { + Logger.i("gps first send "+AP01_CMD); + connection.send(protocolAPIHelper.genStringMessage("AP01", AP01_CMD)); + }else{ + Logger.i("offline skip gps "+AP01_CMD); + FileOutputUtil.fileOutput(runtime.getCacheDir(),"APILog"," offlineskip "+AP01_CMD); + } + // triggerSendThread(); if (mTimer!=null){ mTimer.cancel(); @@ -380,11 +388,11 @@ public class LocationClient { String AP01_CMD=protocolAPIHelper.AP01(runtime); if (connection.isServerConnected() && KeepAlive.isConnected) { - Logger.i("send "+AP01_CMD); - connection.send(protocolAPIHelper.genStringMessage("AP01", protocolAPIHelper.AP01(runtime))); + Logger.i("wifi first send "+AP01_CMD); + connection.send(protocolAPIHelper.genStringMessage("AP01", AP01_CMD)); }else{ - Logger.i("offline skip "+AP01_CMD); - FileOutputUtil.fileOutput(runtime.getContextProxy().context,"APILog"," offlineskip "+AP01_CMD); + Logger.i("offline skip wifi "+AP01_CMD); + FileOutputUtil.fileOutput(runtime.getCacheDir(),"APILog"," offlineskip "+AP01_CMD); } // triggerSendThread(); if (mTimer!=null){ @@ -525,11 +533,10 @@ public void updateCellInfo() { private static int WorkingMod=1; private static int forceLocation=0; public void onReceive(StringMessage paramStringMessage) { - Logger.i("LocationClient onReceive " +paramStringMessage.cmd()+" linkOK "+linkOK ); - if ("Sport:OK".equals(paramStringMessage.cmd())) - this.mPedometer2 = this.H12StepCount; - - +// Logger.i("LocationClient onReceive " +paramStringMessage.cmd()+" linkOK "+linkOK ); +// if ("Sport:OK".equals(paramStringMessage.cmd())) +// this.mPedometer2 = this.H12StepCount; + Logger.i("LocationClient onReceive " +paramStringMessage.cmd() ); // if (linkOK) // return; @@ -565,8 +572,6 @@ public void updateCellInfo() { this.startLocationProcess(mod); WorkingMod=mod; - - } @@ -692,7 +697,7 @@ public void updateCellInfo() { stringBuilder.append(stringMessage.cmd()); stringBuilder.append(", "); stringBuilder.append(stringMessage.isFromCache()); - FileOutputUtil.fileOutput(context, "MessageInfo", stringBuilder.toString()); + FileOutputUtil.fileOutput(runtime.getCacheDir(), "MessageInfo", stringBuilder.toString()); Logger.i(stringBuilder.toString()); if( connection.isServerConnected() ==false && !KeepAlive.isConnected ) { diff --git a/app/src/main/java/com/ic/protocol/NMEAListener.java b/app/src/main/java/com/ic/protocol/NMEAListener.java index edc9a0ba..4b90094a 100644 --- a/app/src/main/java/com/ic/protocol/NMEAListener.java +++ b/app/src/main/java/com/ic/protocol/NMEAListener.java @@ -234,7 +234,7 @@ public class NMEAListener implements NmeaListener, LocationListener { stop(200); } - FileOutputUtil.fileOutput(this.runtime.getContextProxy().context,"GPS",sb2.toString()); + 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.getContextProxy().context,"GPS",sb.toString()); + 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/ic/protocol/adapter/LBSHelper.java b/app/src/main/java/com/ic/protocol/adapter/LBSHelper.java index a8662907..9c8f4999 100644 --- a/app/src/main/java/com/ic/protocol/adapter/LBSHelper.java +++ b/app/src/main/java/com/ic/protocol/adapter/LBSHelper.java @@ -268,7 +268,7 @@ public class LBSHelper { this.runtime.setCellinfo(gsmSb.toString()); this.runtime.setCdmaInfo(null); Logger.i("GsmCellLocation "+ gsmSb.toString()); - FileOutputUtil.fileOutput(this.context, "onCellLocationChanged", gsmSb.toString()); + FileOutputUtil.fileOutput(this.runtime.getCacheDir(), "onCellLocationChanged", gsmSb.toString()); List neighboringCell_list = telephonyManager.getNeighboringCellInfo(); if (neighboringCell_list != null && !neighboringCell_list.isEmpty()) { @@ -311,7 +311,6 @@ public class LBSHelper { cdmaSB.append(","); cdmaSB.append(this.mLastSignal); Logger.i("CdmaCellLocation"); - Context var16 = this.context; StringBuilder var8 = new StringBuilder(); var8.append("CDMA_info="); var8.append(cdmaSB.toString()); @@ -319,7 +318,7 @@ public class LBSHelper { this.runtime.setCellinfo(null); this.runtime.setCdmaInfo(cdmaSB.toString()); - FileOutputUtil.fileOutput(var16, "onCellLocationChanged", var8.toString()); + FileOutputUtil.fileOutput(this.runtime.getCacheDir(), "onCellLocationChanged", var8.toString()); return cdmaSB.toString(); } diff --git a/app/src/main/java/com/ic/protocol/adapter/protocolAPIHelper.java b/app/src/main/java/com/ic/protocol/adapter/protocolAPIHelper.java index fd0b26cf..ec136d75 100644 --- a/app/src/main/java/com/ic/protocol/adapter/protocolAPIHelper.java +++ b/app/src/main/java/com/ic/protocol/adapter/protocolAPIHelper.java @@ -74,7 +74,11 @@ public class protocolAPIHelper { AP33, BP33,//工作模式 APXL, - BPXL,//测量血压 + BPXL,//测量心率 + APXY, + BPXY,//测量血压 + APJZ, + BPJZ,//血压校准 AP84, BP84,//白名单开关 AP85, @@ -134,6 +138,10 @@ public class protocolAPIHelper { cmdMap.put(CMD_TYPE.BP33, "BP33"); cmdMap.put(CMD_TYPE.APXL, "APXL"); cmdMap.put(CMD_TYPE.BPXL, "BPXL"); + cmdMap.put(CMD_TYPE.APXY, "APXY"); + cmdMap.put(CMD_TYPE.BPXY, "BPXY"); + cmdMap.put(CMD_TYPE.APJZ, "APJZ"); + cmdMap.put(CMD_TYPE.BPJZ, "BPJZ"); cmdMap.put(CMD_TYPE.AP84, "AP84"); cmdMap.put(CMD_TYPE.BP84, "BP84"); cmdMap.put(CMD_TYPE.AP85, "AP85"); @@ -316,6 +324,125 @@ public class protocolAPIHelper { .append(ds.getLBSData()).append(CMDSPLIT).append(ds.getWifiInfo()).append(CMDEND).toString(); } + + public static String APXL(String id){ +//设备响应: IWAPXL,080835# + //080835:指令流水号 + return new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.APXL)) + .append(CMDSPLIT).append(id) + .append(CMDEND).toString(); + } + + /** + * 测量心率 + * @param cmd + * @param connection + */ + public void handleBPXL(String cmd,Connection connection){ + //IWBPXL,353456789012345,080835# + //说明: + //IW:标识符 + //BPXL : 命令字符 + //353456789012345:IMEI号,设备唯一ID + //080835 :指令流水号 + //设备响应: IWAPXL,080835# + //080835:指令流水号 + String[] list=cmd.split(CMDSPLIT); + if (list.length==3){ + String index=list[2]; + String imei=list[1]; + Logger.i("Handle BPXL IMEI "+imei+",index "+index); + connection.send(protocolAPIHelper.genStringMessage("APXL",APXL(index))); + }else{ + Logger.i("BPXL format error!"); + } + + } + + public static String APXY(String id){ +//设备响应: IWAPXY,080835# + //080835:指令流水号 + return new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.APXY)) + .append(CMDSPLIT).append(id) + .append(CMDEND).toString(); + } + + /** + * 测量血压 + * @param cmd + * @param connection + */ + public void handleBPXY(String cmd,Connection connection){ + //IWBPXY,353456789012345,080835# + //说明: + //IW:标识符 + //BPXL : 命令字符 + //353456789012345:IMEI号,设备唯一ID + //080835 :指令流水号 + //设备响应: IWAPXY,080835# + //080835:指令流水号 + String[] list=cmd.split(CMDSPLIT); + if (list.length==3){ + String index=list[2]; + String imei=list[1]; + Logger.i("Handle BPXY IMEI "+imei+",index "+index); + connection.send(protocolAPIHelper.genStringMessage("APXY",APXY(index))); + }else{ + Logger.i("BPXY format error!"); + } + + } + + + + public static String APJZ(String id,String BPH,String BPL,String Age,String Sex){ + //设备响应: IWAPJZ,792997,120,85,42,1# + //792997:指令流水号 + // 高压120,低压85,年龄42,1 男性 + return new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.APJZ)) + .append(CMDSPLIT).append(id) + .append(CMDSPLIT).append(BPH) + .append(CMDSPLIT).append(BPL) + .append(CMDSPLIT).append(Age) + .append(CMDSPLIT).append(Sex) + .append(CMDEND).toString(); + } + + /** + * + * @param cmd + * @param connection + * @param runtime + */ + public void handleBPJZ(String cmd,Connection connection,Runtime runtime){ + //cmdbuf.size 42 IWBPJZ,867155030001063,199600,120,85,45,1# 高压120,低压85,年龄45,男性 +// cmdbuf.size 42 IWBPJZ,867155030001063,909957,120,85,42,0# 高压120,低压85,年龄42,女性 + //IWBPJZ,353456789012345,080835,110,75# + //说明: + //IW:标识符 + //BPJZ : 命令字符 + //353456789012345:IMEI号,设备唯一ID + //110:高压值 + //75:低压值 + //080835 :指令流水号 + //设备响应: IWAPJZ,792997,120,85,42,1# + //792997:指令流水号 + String[] list=cmd.split(CMDSPLIT); + if (list.length==7){ + String index=list[2]; + String imei=list[1]; + String strBPH=list[3]; + String strBPL=list[4]; + String strAge=list[5]; + String strSex=list[6]; + + connection.send(protocolAPIHelper.genStringMessage("APJZ",APJZ(index,strBPH,strBPL,strAge,strSex))); + runtime.getHRS().setXY_Ref(Integer.valueOf(strBPH),Integer.valueOf(strBPL),Integer.valueOf(strAge),Integer.valueOf(strSex)); + Logger.i("Handle BPJZ IMEI "+imei+",index "+index+", BPH "+strBPH+", BPL "+strBPL+", Age "+ strAge +", Sex "+ (strSex.equals("1")?"男":"女")); + }else{ + Logger.i("BPXY format error!"); + } + } /*语音下行反馈*/ public static String AP28(String name, String msg, int packagecount, int currentpackageindex, int received_success) { //示例数据:IWAP28,D3590D54,xxxx,6,1,1# @@ -663,14 +790,42 @@ public class protocolAPIHelper { .append(CMDEND).toString(); } - /*心率数据上传*/ + + /** + * 心率上传,返回协议字串 + * @param ds + * @return + */ public static String AP49(Runtime ds){ //示例数据:IWAP49,68## return new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.AP49)) - .append(CMDSPLIT).append(ds.get) + .append(CMDSPLIT).append(ds.getHRS().getPPG()) .append(CMDEND).toString(); } + + /** + * 返回上传心率血压的协议字串 + * @param ds + * @return + */ + public static String APHT(Runtime ds){ + //IWAPHT,60,130,85# + //说明: + //IW:标识符 + //APHT : 命令字符 + //60 : 表示心率 + //130: 血压高压 [收缩压] + //85 : 血压低压 [舒张压] + //平台响应: IWBPHT# + //表示平台已接收,可不作响应 + return new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.APHT)) + .append(CMDSPLIT).append(ds.getHRS().getPPG()) + .append(CMDSPLIT).append(ds.getHRS().getBPH()) + .append(CMDSPLIT).append(ds.getHRS().getBPL()) + .append(CMDEND).toString(); + } + // 立即定位指令(长链接有效) public void handleBP16(Connection connection,Runtime runtime,String cmd){ //示例数据:IWBP16,867155030001063,335386 @@ -697,19 +852,7 @@ public class protocolAPIHelper { .append(CMDSPLIT).append(cmdindex) .append(CMDEND).toString(); } - /*上传心率与血压*/ - public static String APHT(Runtime ds){ - //示例数据:IWAPHT,60,130,85# - // 60 : 表示心率 - //130: 血压高压 [收缩压] - //85 : 血压低压 [舒张压] - return new StringBuffer(CMDHEADER).append(cmdMap.get(CMD_TYPE.APHT)) - .append(CMDSPLIT).append("60") - .append(CMDSPLIT).append("130") - .append(CMDSPLIT).append("85") - .append(CMDEND).toString(); - } /*通过基站获取时间和坐标*/ public static String APTM(Runtime ds){ //示例数据:IWAPTM,460,0,9750,3613# diff --git a/app/src/main/java/com/ic/protocol/bean/Runtime.java b/app/src/main/java/com/ic/protocol/bean/Runtime.java index a552804a..8617a009 100644 --- a/app/src/main/java/com/ic/protocol/bean/Runtime.java +++ b/app/src/main/java/com/ic/protocol/bean/Runtime.java @@ -81,7 +81,10 @@ public class Runtime { private String latitude; private LBSHelper lbsHelper; - + + + private heartRateStatus HRS=null; + // private String location; private boolean lockSimInfo=false; @@ -108,6 +111,13 @@ public class Runtime { public int totalStepCount; + public heartRateStatus getHRS(){ + return HRS; + } + + public void setHRS(heartRateStatus hrs){ + HRS=hrs; + } public int getLastStepCount(){ return lastStepCount; } diff --git a/app/src/main/java/com/ic/protocol/bean/StheartRate.java b/app/src/main/java/com/ic/protocol/bean/StheartRate.java index 4ebc898a..6da73fb8 100644 --- a/app/src/main/java/com/ic/protocol/bean/StheartRate.java +++ b/app/src/main/java/com/ic/protocol/bean/StheartRate.java @@ -15,19 +15,19 @@ public class StheartRate { public String week; - public StheartRate(String paramString1, String paramString2, String paramString3, String paramString4) { - this.start = paramString1; - this.end = paramString2; - this.week = paramString3; - this.status = paramString4; + public StheartRate(String _start, String _end, String _week, String _status) { + this.start = _start; + this.end = _end; + this.week = _week; + this.status = _status; } - public StheartRate(String paramString1, String paramString2, String paramString3, String paramString4, String paramString5) { - this.start = paramString1; - this.end = paramString2; - this.week = paramString3; - this.status = paramString4; - this.interval = paramString5; + public StheartRate(String _start, String _end, String _week, String _status, String _inteval) { + this.start = _start; + this.end = _end; + this.week = _week; + this.status = _status; + this.interval = _inteval; } public boolean equals(Object obj) { diff --git a/app/src/main/java/com/ic/protocol/bean/heartRateStatus.java b/app/src/main/java/com/ic/protocol/bean/heartRateStatus.java index 742bf84a..080f295e 100644 --- a/app/src/main/java/com/ic/protocol/bean/heartRateStatus.java +++ b/app/src/main/java/com/ic/protocol/bean/heartRateStatus.java @@ -5,6 +5,23 @@ import com.ic.jni.ICJniUtils; public class heartRateStatus { private int lastHeartrate; + private String lastTestTime; + private int lastBPH; + private int lastBPL; + private int BPH_ref; + private int BPL_ref; + private int Age; + private int Sex; + + + public void setXY_Ref(int refBPH,int refBPL,int refSex,int refAge){ + BPH_ref=refBPH; + BPL_ref=refBPL; + Age=refAge; + Sex=refSex; + } + + private HEARTRATE_WORKINGSTAT currentStat; public enum HEARTRATE_WORKINGSTAT { HEARTRATE_CLOSED, @@ -21,31 +38,47 @@ public class heartRateStatus { public HEARTRATE_WORKINGSTAT getHeartrateWorkingStat(){ - int PPG=ICJniUtils.getPPG();//调用底层函数保证状态更新。 - if (ICJniUtils.isPPGStarted()==1 ){ - if ( ICJniUtils.isWeared()==1) { - if (PPG > 0) { - currentStat = HEARTRATE_WORKINGSTAT.HEARTRATE_TEST_SUCCESS; - } else { - currentStat = HEARTRATE_WORKINGSTAT.HEARTRATE_WARED_AND_TESTING; - } - }else{ - currentStat=HEARTRATE_WORKINGSTAT.HEARTRATE_NOTWARED; - } - }else{ - currentStat=HEARTRATE_WORKINGSTAT.HEARTRATE_CLOSED; - } return currentStat; } public void setHeartrateStat(HEARTRATE_WORKINGSTAT stat){ + currentStat = stat; } - public int getHeartrateData(){ + public int getPPG(){ + return lastHeartrate; } - public void setLastHeartrate(int value){ + public int getBPH() { + int BPH=lastBPH; + if (lastBPH > BPH_ref+20) + BPH=BPL_ref+20; + if (lastBPH < BPH_ref-20) + BPH=BPH_ref-20; + return BPH; + } + public int getBPL() { + + int BPL=lastBPL; + if (lastBPL > BPL_ref+20) + BPL=BPL_ref+20; + if (lastBPL < BPL_ref-20) + BPL=BPL_ref-20; + return BPL; + } + + public String getTestTime(){ + return lastTestTime; + } + public void setLastTestTime(String testtime){ + lastTestTime=testtime; + } + + + public void setLastHeartrate(int value,int bph,int bpl){ lastHeartrate=value; + lastBPH=bph; + lastBPL=bpl; } } diff --git a/app/src/main/java/com/ic/protocol/service/HeartRateManager.java b/app/src/main/java/com/ic/protocol/service/HeartRateManager.java index 62bb1250..6af88018 100644 --- a/app/src/main/java/com/ic/protocol/service/HeartRateManager.java +++ b/app/src/main/java/com/ic/protocol/service/HeartRateManager.java @@ -4,203 +4,303 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.os.SystemClock; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.os.Messenger; +import android.os.PowerManager; -import com.eiot.watch_lib.LauncherCtrl; +import com.ic.jni.ICJniUtils; +import com.ic.protocol.LocationClient; import com.ic.protocol.adapter.protocolAPIHelper; import com.ic.protocol.bean.Runtime; import com.ic.protocol.bean.StringMessage; -import com.ic.protocol.service.base.AbstractConnectionService; -import com.ic.protocol.utils.AlarmWakeUp; +import com.ic.protocol.bean.heartRateStatus; +import com.ic.protocol.service.base.AbstractInvokeHandlerService; import com.ic.protocol.utils.Connection; import com.ic.protocol.utils.Logger; import com.ic.protocol.utils.NettyConnection; -import com.ic.protocol.utils.NetworkObservable; - -import rx.Subscription; -import rx.functions.Action1; - -import static com.eiot.watch_lib.LauncherCtrl.STATUS_BAR_STATE_SERVER_CONNECTED_OFF; -import static com.eiot.watch_lib.LauncherCtrl.STATUS_BAR_STATE_SERVER_CONNECTED_ON; - -public class HeartRateManager extends AbstractConnectionService { - private static final long HEARTBEAT_TIMEOUT = 660000L; - private static String TAG = HeartRateManager.class.getSimpleName(); - public static boolean connectionError = false; - - public static boolean isConnected = false; - - private static boolean isInSleepMode = false; - - private static int mFlag = 30; - - Connection connection; - - private int currentReConnectInterval = 11; - - private boolean firstReConnected = true; - - private long idleTimeMillis; - - private int isFirstAsjust; - - private int lastReConnectInterval = -1; - - private int lastReConnectionNumber = -1; - - Context mContext; - - NetworkObservable mNetworkObservable = new NetworkObservable(); - - Runtime mRuntime; - - private ShutDownReceiver mShutDownReceiver; - - private Subscription mSubscription; - - private int reConnectionNumber; - - private int reCycleTimes; - - private int timeout = 660; - - private int totalAdjustTimes; - - private int whichTimeAdjust; - - static { - - } +import com.ic.protocol.utils.SimSignalUtil; +import com.ic.protocol.utils.TimeUtil; - - public void onAlarmClock(Connection paramConnection, Runtime paramRuntime) { +import java.util.Timer; +import java.util.TimerTask; - Logger.i("onAlarmClock"); +import static com.ic.protocol.Constants.ACTION_HEATR_RATE_START; - long l = SystemClock.elapsedRealtime(); +public class HeartRateManager extends AbstractInvokeHandlerService { + private int mNetworkType; - //如果 没有连接成功 或者 时间超过了11分钟 ,则进行重新连接服务 - if (!isConnected || l - this.idleTimeMillis > 660000L) { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("重连"); - stringBuilder.append(isConnected); - Logger.i(stringBuilder.toString()); - if (!isConnected && this.firstReConnected) { - this.reConnectionNumber++; - this.firstReConnected = false; - } -// if (paramRuntime.getLockSimInfo()) { -// paramConnection.disconnect(); -// return; -// } - - } - } - - public void onAttach(final Connection connection, final Runtime runtime) { - this.mRuntime = runtime; - this.mContext = (runtime.getContextProxy()).context; - this.mNetworkObservable.register(this.mContext); - this.connection = connection; - this.mSubscription = this.mNetworkObservable.onChange().subscribe(new Action1() { - private boolean first; - - public void call(Integer param1Integer) { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("yls aBoolean="); - stringBuilder.append(param1Integer); - stringBuilder.append(",,first="); - stringBuilder.append(this.first); - Logger.i(stringBuilder.toString()); - if (param1Integer.intValue() > 0) { - if (this.first) { - this.first = false; - return; - } - connection.connect(runtime.getSrvIP(), runtime.getPort()); - } + private SimSignalUtil mSignalUtil; + + private Runtime runtime; + private NettyConnection connection; + private TimerTaskPPG timerTaskPPG; + + private Timer timerPPG; + private static Handler mHandler=null; + + + public HeartRateManager(Runtime _runtime,NettyConnection _connection){ + runtime=_runtime; + connection=_connection; + currentStat= heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_CLOSED; + isTimerStarted=false; + mHandler=new Handler(new Handler.Callback() { + @Override + public boolean handleMessage(Message message) { + + switch (message.what) { + case 100: { + //只有检测PPG成功,且网络连接中才发送数据 + if (runtime.getHRS().getHeartrateWorkingStat() == heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_TEST_SUCCESS) { + runtime.getHRS().setLastTestTime(TimeUtil.getLocalTime()); + String PPGDATA = protocolAPIHelper.APHT(runtime); + if (connection.isServerConnected()) { + connection.send(protocolAPIHelper.genStringMessage("APHT", PPGDATA)); + Logger.i("Send PPG " + PPGDATA); + } else { + Logger.i("Skip PPG " + PPGDATA); + } + } else { + Logger.i("PPG Failed for Timeout!"); + } + stopPPG(); } - }); + break; + case 200: { + startPPG(); + } + break; + } + return false; + } + }); + + } + + private BroadcastReceiver PPGStartReceiver = new BroadcastReceiver() { + public void onReceive(Context param1Context, Intent param1Intent) { + if (ACTION_HEATR_RATE_START.equals(param1Intent.getAction())) { + HeartRateManager.this.startPPG(); + } + } + }; + + public void regReceiver(){ + //注册“网络变化”的广播接收器 IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction("android.intent.action.ACTION_SHUTDOWN_MOREINFO"); - this.mShutDownReceiver = new ShutDownReceiver(); - this.mContext.registerReceiver(this.mShutDownReceiver, intentFilter); + intentFilter.addAction(ACTION_HEATR_RATE_START); + runtime.getContextProxy().context.registerReceiver(PPGStartReceiver, intentFilter); } - - public boolean onConnectionClose(Connection paramConnection, Runtime paramRuntime) { - if (isConnected) protocolMainServer.getInstance().startConnectionRetryTimer(); - connectionError = true; - isConnected = false; - paramRuntime.getContextProxy().sendBroadcast(isConnected); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("onConnectionClose="); - stringBuilder.append(",set KeepAlive isConnected = false"); - Logger.i(stringBuilder.toString()); - LauncherCtrl.getInstance(this.mContext).setStatusBarIcon("server_connected", STATUS_BAR_STATE_SERVER_CONNECTED_OFF); - return false; + + public void unRegReceiver(){ + runtime.getContextProxy().context.unregisterReceiver(PPGStartReceiver); } - - public boolean onConnectionOpen(Connection paramConnection, Runtime paramRuntime) { - - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("onConnectionOpen connectionError="); - stringBuilder.append(connectionError); - stringBuilder.append(",sInSleepMode ="); - stringBuilder.append(isInSleepMode); - stringBuilder.append(",set KeepAlive isConnected = true"); - Logger.i(stringBuilder.toString()); -// if (!connectionError) { - connectionError = false; -// connection.send(protocolAPIHelper.genStringMessage("AP00",protocolAPIHelper.AP00(paramRuntime))); - connection.send(protocolAPIHelper.genStringMessage("heart",protocolAPIHelper.AP03(paramRuntime))); -// if (Deliver.haveSendH42) { -// ServiceUtil.offerQueue(new StringMessage(protocolAPIHelper.AP03(paramRuntime))); -// Deliver.haveSendH42 = false; -// } -// } - - isConnected = true; - this.firstReConnected = true; - this.idleTimeMillis = SystemClock.elapsedRealtime(); - paramRuntime.getContextProxy().sendBroadcast(isConnected); - - LauncherCtrl.getInstance(this.mContext).setStatusBarIcon("server_connected", STATUS_BAR_STATE_SERVER_CONNECTED_ON); - return false; + + public class TimerTaskPPG extends TimerTask{ + @Override + public void run() { + doPPGtest(); + } + }; + + int PPG; + int BPH; + int BPL; + boolean isWared ; + boolean isPPGTesting ; + static boolean isTimerStarted; + static heartRateStatus.HEARTRATE_WORKINGSTAT currentStat; + static int delayCount; + static int testCount; + private final int MAX_TESTTIMES=30000;//最大延迟测试时间为30秒 + + + public void doPPGtest(){ + PPG= ICJniUtils.getPPG();//调用底层函数保证状态更新。 + BPH=ICJniUtils.getHighBloodPressure(); + BPL=ICJniUtils.getLowBloodPressure(); + isWared = (ICJniUtils.isWeared()==1); + isPPGTesting = (ICJniUtils.isPPGStarted()==1 ); + Logger.i("PPG TESTING="+isPPGTesting+", isWared="+isWared+", PPG="+PPG+", BPH="+BPH+", BPL="+BPL); + if (isPPGTesting){ + if (isWared ) { + if (PPG > 0) { + currentStat = heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_TEST_SUCCESS; + + } else { + currentStat = heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_WARED_AND_TESTING; + } + }else{ + currentStat= heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_NOTWARED; + } + }else{ + currentStat= heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_CLOSED; + } + + + if (currentStat==heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_TEST_SUCCESS){ + runtime.getHRS().setLastHeartrate(PPG,BPH,BPL); + delayCount--; + if (delayCount<0) //达到延迟时间后,停止检测并发送数据 + sendAndStopPPG(); + + }else{ + runtime.getHRS().setLastHeartrate(0,0,0); + } + runtime.getHRS().setHeartrateStat(currentStat); + + testCount--; + if (testCount<0) + { + Logger.i("PPG 超过 "+MAX_TESTTIMES+"秒 未能得出结果,取消检测报告!"); + stopPPG(); + } + } - public void onDetach(Connection paramConnection, Runtime paramRuntime) { - if (this.mSubscription != null && !this.mSubscription.isUnsubscribed()) - this.mSubscription.unsubscribe(); - this.mNetworkObservable.unregister(this.mContext); - this.mContext.unregisterReceiver(this.mShutDownReceiver); + + private void sendAndStopPPG(){ + //结束和发送数据 + mHandler.sendEmptyMessage(100); + } + PowerManager.WakeLock mWakeLock=null; + public PowerManager.WakeLock getPPGWakeLock() { + mWakeLock = ((PowerManager)(runtime.getContextProxy()).context.getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "PPGTest"); + mWakeLock.acquire(30000L); + return mWakeLock; } - - public void onHeartAlarm(NettyConnection paramNettyConnection, Runtime paramRuntime) { - Logger.i("onHeartAlarm"); -// UpdateHeartBeatTimeout(); -// if (this.reCycleTimes == 0 && this.currentReConnectInterval != 11){ -// paramNettyConnection.send(protocolAPIHelper.genStringMessage("AP00",protocolAPIHelper.AP00(paramRuntime))); - paramNettyConnection.send(protocolAPIHelper.genStringMessage("heart",protocolAPIHelper.AP03(paramRuntime))); - // } + public void releaseWakeLock(){ + if (mWakeLock!=null){ + mWakeLock.release(); + } + mWakeLock=null; + } + public void startPPG(){ + if (ICJniUtils.isPPGavailable()==1 && isTimerStarted==false) { + currentStat=heartRateStatus.HEARTRATE_WORKINGSTAT.HEARTRATE_OPEN; + delayCount=3;//检测成功后三秒发送数据 + testCount=MAX_TESTTIMES;//测试MAX_TESTTIMES后没有结果也要强制退出 + isTimerStarted=true; + ICJniUtils.enablePPG(); + getPPGWakeLock(); + timerTaskPPG = new TimerTaskPPG(); + timerPPG = new Timer(); + timerPPG.scheduleAtFixedRate(timerTaskPPG,0, 1000); //1 秒更新一次数据 + + } } - public boolean onReceive(StringMessage paramStringMessage, Connection paramConnection, Runtime paramRuntime) { - this.idleTimeMillis = SystemClock.elapsedRealtime(); - Logger.i(TAG+paramStringMessage.cmd()); + public void stopPPG(){ + if( isTimerStarted ) + { + timerPPG.cancel(); + isTimerStarted=false; + } + ICJniUtils.disablePPG(); + releaseWakeLock(); + } + + private void callback(Messenger paramMessenger, int paramInt) { + if (paramMessenger != null) + try { + paramMessenger.send(Message.obtain(null, paramInt)); + return; + } catch (Exception e) { + e.printStackTrace(); + } + } + + + + public void onAlarmClock(Connection paramConnection, Runtime paramRuntime) {} + public void onAttach(Connection paramConnection, Runtime paramRuntime) { +// this.mSignalUtil = SimSignalUtil.getInstance((paramRuntime.getContextProxy()).context); + regReceiver(); + } + + public void onDetach(Connection paramConnection, Runtime paramRuntime) { + unRegReceiver(); + } + + public boolean onUserRequest(Intent paramIntent, Connection paramConnection, final Runtime runtime) { + String str = paramIntent.getAction(); + if (ACTION_HEATR_RATE_START.equals(str)) { +// this.mSignalUtil = SimSignalUtil.getInstance((runtime.getContextProxy()).context); +// str = paramIntent.getStringExtra("filepath"); +// String str1 = paramIntent.getStringExtra("number"); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("PPG Started on Action "+ACTION_HEATR_RATE_START); +// stringBuilder.append(str); +// stringBuilder.append("number == "); +// stringBuilder.append(str1); + Logger.i(stringBuilder.toString()); + //do something + startPPG(); + } return false; } - - class ShutDownReceiver extends BroadcastReceiver { - public void onReceive(Context param1Context, Intent param1Intent) { - boolean bool = param1Intent.getBooleanExtra("reboot", false); - if (HeartRateManager.this.mRuntime.getBatteryLow() && !HeartRateManager.this.mRuntime.getBatterychanging() && !bool && !HeartRateManager.this.mRuntime.isShutdown()){ -// KeepAlive.this.connection.send(new StringMessage(protocolAPIHelper.AP00(KeepAlive.this.mRuntime))); - } +public static void triggerPPGtest(){ + if (mHandler !=null) mHandler.sendEmptyMessage(200); +} + + public boolean onUserRequest(Message message, Connection connection, final Runtime runtime) { + Bundle bundle3; + String str3; + String str2; + String str1; + Bundle bundle2; + final Messenger callback2; + + int i = 1; + switch (message.what) { + case 1002: + this.mNetworkType = this.mSignalUtil.getNetworkType(); + bundle3 = message.getData(); + str1 = bundle3.getString("filepath"); + str2 = bundle3.getString("number"); + if (str1 != null) { + if (str2 == null) + return true; + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("filepath == "); + stringBuilder.append(str1); + stringBuilder.append("number == "); + stringBuilder.append(str2); + Logger.i(stringBuilder.toString()); +//do something + } else { + return true; + } + case 1001: + this.mSignalUtil = SimSignalUtil.getInstance((runtime.getContextProxy()).context); + this.mNetworkType = this.mSignalUtil.getNetworkType(); + bundle2 = message.getData(); + str2 = bundle2.getString("filepath"); + str3 = bundle2.getString("number"); + + if (str2 != null && str3 != null) { +// send + } else { + return true; + } + case 1000: + break; + + default: + return false; } +// Bundle bundle1 = paramMessage.getData(); +// i = bundle1.getInt("category"); + + return true; } } + diff --git a/app/src/main/java/com/ic/protocol/service/KeepAlive.java b/app/src/main/java/com/ic/protocol/service/KeepAlive.java index e196ff23..6fa23437 100644 --- a/app/src/main/java/com/ic/protocol/service/KeepAlive.java +++ b/app/src/main/java/com/ic/protocol/service/KeepAlive.java @@ -204,7 +204,9 @@ public class KeepAlive extends AbstractConnectionService { } - public void setSleepMode(boolean paramBoolean) { isInSleepMode = paramBoolean; } + public void setSleepMode(boolean paramBoolean) { + isInSleepMode = paramBoolean; + } class ShutDownReceiver extends BroadcastReceiver { public void onReceive(Context param1Context, Intent param1Intent) { diff --git a/app/src/main/java/com/ic/protocol/service/UpLoadDataPoints.java b/app/src/main/java/com/ic/protocol/service/UpLoadDataPoints.java index 296813e4..c6f1a95e 100644 --- a/app/src/main/java/com/ic/protocol/service/UpLoadDataPoints.java +++ b/app/src/main/java/com/ic/protocol/service/UpLoadDataPoints.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.os.Handler; import android.os.Message; +import com.ic.protocol.bean.ICLocation; import com.ic.protocol.bean.Locations; import com.ic.protocol.bean.Runtime; import com.ic.protocol.service.base.AbstractInvokeHandlerService; @@ -18,7 +19,7 @@ import org.json.JSONObject; import java.util.List; public class UpLoadDataPoints extends AbstractInvokeHandlerService { - private final String REGISTER_CODE = "FIZOF5Rcp0nuWPqf"; + private final String TAG = UpLoadDataPoints.class.getSimpleName(); private int alarmClock; @@ -26,57 +27,7 @@ public class UpLoadDataPoints extends AbstractInvokeHandlerService { private Runnable mRegisterDeviceTask = new Runnable() { public void run() { -// JSONObject jSONObject = new JSONObject(); -// try { -// jSONObject.put("sn", UpLoadDataPoints.this.mRuntime.getCid()); -// jSONObject.put("title", "EQC_G5_Device"); -// } catch (JSONException jSONException) { -// jSONException.printStackTrace(); -// } -// OneNetApiCallback oneNetApiCallback = new OneNetApiCallback() { -// public void onFailed(Exception param2Exception) { Logger.i(param2Exception.getMessage()); } -// -// public void onSuccess(String param2String) { -// try { -// StringBuilder stringBuilder1 = new JSONObject(param2String); -// int i = stringBuilder1.optInt("errno"); -// if (i != 0) { -// stringBuilder1 = new StringBuilder(); -// stringBuilder1.append("error : "); -// stringBuilder1.append(i); -// Logger.i(stringBuilder1.toString()); -// return; -// } -// JSONObject jSONObject = stringBuilder1.optJSONObject("data"); -// if (jSONObject == null) { -// Logger.i("data is null"); -// return; -// } -// String str1 = jSONObject.optString("device_id"); -// String str2 = jSONObject.optString("key", null); -// StringBuilder stringBuilder2 = new StringBuilder(); -// stringBuilder2.append("device_id="); -// stringBuilder2.append(str1); -// stringBuilder2.append("DeviceApiKey="); -// stringBuilder2.append(str2); -// Logger.i(stringBuilder2.toString()); -// UpLoadDataPoints.this.mRuntime.setDevice_id(str1); -// UpLoadDataPoints.this.mRuntime.setDevice_key(str2); -// SharPreferenceUtil.setPrefString((this.this$1.this$0.mRuntime.getContextProxy()).context, "key_device_id", str1); -// SharPreferenceUtil.setPrefString((this.this$1.this$0.mRuntime.getContextProxy()).context, "key_device_key", str2); -// if (str2 == null) { -// Logger.i("DeviceApiKey is null"); -// return; -// } -// OneNetApi.setAppKey(str2); -// return; -// } catch (JSONException param2String) { -// param2String.printStackTrace(); -// return; -// } -// } -// }; -// OneNetApi.registerDevice("FIZOF5Rcp0nuWPqf", jSONObject.toString(), oneNetApiCallback); + } }; @@ -127,157 +78,53 @@ public class UpLoadDataPoints extends AbstractInvokeHandlerService { public void onDetach(Connection paramConnection, Runtime paramRuntime) {} - public boolean onUserRequest(Intent paramIntent, Connection paramConnection, Runtime paramRuntime) { return false; } + public boolean onUserRequest(Intent paramIntent, Connection paramConnection, Runtime paramRuntime) { + return false; + } - public boolean onUserRequest(Message paramMessage, Connection paramConnection, Runtime paramRuntime) { return false; } + public boolean onUserRequest(Message paramMessage, Connection paramConnection, Runtime paramRuntime) { + return false; + } public void uploadCurrentLocation() { String str1 = this.mRuntime.getDevice_id(); String str2 = this.mRuntime.getDevice_key(); if (str1 != null && str2 != null) { -// OneNetApi.setAppKey(str2); -// this.mHandler.post(new UploadCurrentLocationTask(new Locations(this.mRuntime.getLongitude(), this.mRuntime.getLatitude()), str1)); + this.mHandler.post(new UploadCurrentLocationTask(this.mRuntime.getLocationInstance().getLocation(), str1)); return; } // this.mHandler.post(this.mRegisterDeviceTask); } private class UploadCurrentLocationTask implements Runnable { - private Locations mCurrentLocation; + private ICLocation.GPS_LocationPoint mCurrentLocation; private String mDeviceID; - UploadCurrentLocationTask(Locations param1Locations, String param1String) { + UploadCurrentLocationTask(ICLocation.GPS_LocationPoint param1Locations, String param1String) { this.mCurrentLocation = param1Locations; this.mDeviceID = param1String; } public void run() { -// JSONObject jSONObject1 = new JSONObject(); -// JSONObject jSONObject2 = new JSONObject(); -// try { -// jSONObject2.put("lon", this.mCurrentLocation.getLon()); -// jSONObject2.put("lat", this.mCurrentLocation.getLat()); -// jSONObject1.put("locations", jSONObject2); -// } catch (JSONException jSONObject2) { -// jSONObject2.printStackTrace(); -// UpLoadDataPoints.access$002(UpLoadDataPoints.this, false); -// UpLoadDataPoints.access$102(UpLoadDataPoints.this, 0); -// } -// OneNetApiCallback oneNetApiCallback = new OneNetApiCallback() { -// public void onFailed(Exception param2Exception) { -// UpLoadDataPoints.access$002(UpLoadDataPoints.UploadCurrentLocationTask.this.this$0, false); -// UpLoadDataPoints.access$102(UpLoadDataPoints.UploadCurrentLocationTask.this.this$0, 0); -// } -// -// public void onSuccess(String param2String) { -// try { -// int i = (new JSONObject(param2String)).optInt("errno"); -// if (i != 0) { -// StringBuilder stringBuilder = new StringBuilder(); -// stringBuilder.append("error : "); -// stringBuilder.append(i); -// Logger.i(stringBuilder.toString()); -// UpLoadDataPoints.access$002(UpLoadDataPoints.UploadCurrentLocationTask.this.this$0, false); -// return; -// } -// UpLoadDataPoints.access$002(UpLoadDataPoints.UploadCurrentLocationTask.this.this$0, true); -// return; -// } catch (JSONException param2String) { -// param2String.printStackTrace(); -// UpLoadDataPoints.access$002(UpLoadDataPoints.UploadCurrentLocationTask.this.this$0, false); -// return; -// } -// } -// }; -// OneNetApi.addDataPoints(this.mDeviceID, "3", jSONObject1.toString(), oneNetApiCallback); + } } - -// class null implements OneNetApiCallback { -// null() {} -// -// public void onFailed(Exception param1Exception) { -// UpLoadDataPoints.access$002(this.this$1.this$0, false); -// UpLoadDataPoints.access$102(this.this$1.this$0, 0); -// } -// -// public void onSuccess(String param1String) { -// try { -// int i = (new JSONObject(param1String)).optInt("errno"); -// if (i != 0) { -// StringBuilder stringBuilder = new StringBuilder(); -// stringBuilder.append("error : "); -// stringBuilder.append(i); -// Logger.i(stringBuilder.toString()); -// UpLoadDataPoints.access$002(this.this$1.this$0, false); -// return; -// } -// UpLoadDataPoints.access$002(this.this$1.this$0, true); -// return; -// } catch (JSONException param1String) { -// param1String.printStackTrace(); -// UpLoadDataPoints.access$002(this.this$1.this$0, false); -// return; -// } -// } -// } + private static class UploadLocationsTask implements Runnable { private String mDeviceID; - private List mLocations; + private List mLocations; - UploadLocationsTask(List param1List, String param1String) { + UploadLocationsTask(List param1List, String param1String) { this.mLocations = param1List; this.mDeviceID = param1String; } public void run() { -// JSONObject jSONObject1 = new JSONObject(); -// JSONArray jSONArray1 = new JSONArray(); -// JSONObject jSONObject2 = new JSONObject(); -// JSONArray jSONArray2 = new JSONArray(); -// try { -// for (Locations locations : this.mLocations) { -// JSONObject jSONObject3 = new JSONObject(); -// jSONObject3.put("lon", locations.getLon()); -// jSONObject3.put("lat", locations.getLat()); -// JSONObject jSONObject4 = new JSONObject(); -// jSONObject4.put("at", locations.getTime()); -// jSONObject4.put("value", jSONObject3); -// jSONArray2.put(jSONObject4); -// } -// jSONObject2.put("id", "locations"); -// jSONObject2.put("datapoints", jSONArray2); -// jSONArray1.put(jSONObject2); -// jSONObject1.put("datastreams", jSONArray1); -// } catch (JSONException e) { -// e.printStackTrace(); -// } -// OneNetApiCallback oneNetApiCallback = new OneNetApiCallback() { -// public void onFailed(Exception param2Exception) { Logger.i(param2Exception.getMessage()); } -// -// public void onSuccess(String param2String) { -// StringBuilder stringBuilder = new StringBuilder(); -// stringBuilder.append("upload location response : "); -// stringBuilder.append(param2String); -// Logger.i(stringBuilder.toString()); -// try { -// int i = (new JSONObject(param2String)).optInt("errno"); -// if (i != 0) { -// StringBuilder stringBuilder1 = new StringBuilder(); -// stringBuilder1.append("error : "); -// stringBuilder1.append(i); -// Logger.i(stringBuilder1.toString()); -// return; -// } -// } catch (JSONException param2String) { -// param2String.printStackTrace(); -// } -// } -// }; -// OneNetApi.addDataPoints(this.mDeviceID, jSONObject1.toString(), oneNetApiCallback); + + } } diff --git a/app/src/main/java/com/ic/protocol/service/protocolMainServer.java b/app/src/main/java/com/ic/protocol/service/protocolMainServer.java index 945724e6..8686e7ed 100644 --- a/app/src/main/java/com/ic/protocol/service/protocolMainServer.java +++ b/app/src/main/java/com/ic/protocol/service/protocolMainServer.java @@ -26,6 +26,7 @@ import com.ic.protocol.adapter.LBSHelper; import com.ic.protocol.adapter.protocolAPIHelper; import com.ic.protocol.bean.Runtime; import com.ic.protocol.bean.StringMessage; +import com.ic.protocol.bean.heartRateStatus; import com.ic.protocol.service.base.AbstractConnectionService; import com.ic.protocol.service.base.AbstractInvokeHandlerService; import com.ic.protocol.utils.AlarmHelper; @@ -60,6 +61,7 @@ import java.util.TimerTask; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; import static com.ic.protocol.Constants.ACTION_ALARM_ADD_DATAPOINTS; import static com.ic.protocol.Constants.ACTION_EQC_ALARM; +import static com.ic.protocol.Constants.ACTION_HEATR_RATE_START; import static com.ic.protocol.Constants.ACTION_LOCATION_ALARM; import static com.ic.protocol.Constants.HEART_ALARM; import static com.ic.protocol.Constants.SLEEP_ALARM; @@ -122,21 +124,19 @@ public class protocolMainServer extends Service { stringBuilder1.append(Integer.valueOf(str, 16)); stringBuilder1.append(",CELLID="); stringBuilder1.append(Integer.valueOf(str1, 16)); - FileOutputUtil.fileOutput(context, "cellInfoTest", stringBuilder1.toString()); + FileOutputUtil.fileOutput(runtime.getCacheDir(), "cellInfoTest", stringBuilder1.toString()); } } } } }; - private String actionName = "com.cmcm.interface"; - private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { public void onReceive(Context param1Context, Intent param1Intent) { StringBuilder stringBuilder2 = new StringBuilder(); stringBuilder2.append("broadcastReceiver alarmCycle action=="); stringBuilder2.append(param1Intent.getAction()); - FileOutputUtil.fileOutput(param1Context, "alarmCycle", stringBuilder2.toString()); + FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder2.toString()); StringBuilder stringBuilder1 = new StringBuilder(); stringBuilder1.append("时间变化"); stringBuilder1.append(param1Intent.getAction()); @@ -144,6 +144,7 @@ public class protocolMainServer extends Service { protocolMainServer.this.setSleepAlarm(); protocolMainServer.this.setWakeAlarm(); protocolMainServer.this.setHeartAlarm(); + protocolMainServer.this.setHeartRateDetectAlarm(3); protocolMainServer.this.setWeatherAlarm(); protocolMainServer.this.setLocationAlarm(runtime.getLocationInstance().getWorkingMod()); if (protocolMainServer.this.cmcm_call_eiot_into_powersave_mode() == 0) @@ -207,7 +208,6 @@ public class protocolMainServer extends Service { final Messenger mMessenger = new Messenger(new RequestHandler(this)); -// private SendPairMessage mSendPairMessage; private SimSignalUtil mSignalUtil; @@ -224,8 +224,7 @@ public class protocolMainServer extends Service { stringBuilder.append(is_wifi_network_ok); Logger.i(stringBuilder.toString()); if (is_in_sleep_mode) { -// CoreService.access$402(false); -// CoreService.access$502(0); + /*屏幕亮起时,如果在sleep模式,则唤醒各个进程*/ protocolMainServer.is_in_sleep_mode=false; protocolMainServer.is_allowed_in_sleep_mode=0; @@ -234,13 +233,13 @@ public class protocolMainServer extends Service { protocolMainServer.this.wakeUpFromSleep(); } if (is_wifi_network_ok) { -// CoreService.access$302(false); + /*屏幕亮起时,如果wifi开启,则开启wifi*/ protocolMainServer.is_in_sleep_mode=false; Util.turnOnWifiForConnect((protocolMainServer.this.runtime.getContextProxy()).context, protocolMainServer.this.runtime); } } else if ("android.intent.action.SCREEN_OFF".equals(param1Intent.getAction()) && Util.isWifiIsOpen((protocolMainServer.this.runtime.getContextProxy()).context, protocolMainServer.this.runtime)) { -// CoreService.access$302(true); + protocolMainServer.is_in_sleep_mode=true; Util.turnOffWifiForSleep((protocolMainServer.this.runtime.getContextProxy()).context, protocolMainServer.this.runtime); } @@ -251,24 +250,15 @@ public class protocolMainServer extends Service { UpLoadDataPoints upLoadDataPoints; - static { - - } private AbstractConnectionService getConnectionServiceChain() { -// DNS dNS = new DNS(); -// SynchronousTime synchronousTime = new SynchronousTime(); -// new ProcessEncryptionService(); Initialize initialize = new Initialize(); CheckSIM checkSIM = new CheckSIM(); this.mKeepAlive = new KeepAlive(); this.mDeliver = new Deliver(); -// dNS.setNext(synchronousTime); -// initialize.setNext(synchronousTime); initialize.setNext(checkSIM); checkSIM.setNext(this.mKeepAlive); this.mKeepAlive.setNext(this.mDeliver); - return initialize; } @@ -280,14 +270,12 @@ public class protocolMainServer extends Service { } private AbstractInvokeHandlerService getInvokeHandlerServiceChain() { + Logger.i("getInvokeHandlerServiceChain"); SendChatMessage sendChatMessage = new SendChatMessage(); -// this.mSendPairMessage = new SendPairMessage(); -// OtherBusiness otherBusiness = new OtherBusiness(); -// SendOssMessage sendOssMessage = new SendOssMessage(); + HeartRateManager heartRateManager= new HeartRateManager(this.runtime,this.connection); SilentManager silentManager = new SilentManager(); - Logger.i("BuildConfig.upLoadData=false"); -// this.justTalkLogin = new JustTalkLogin(); - sendChatMessage.setNext(silentManager); + sendChatMessage.setNext(heartRateManager); + heartRateManager.setNext(silentManager); return sendChatMessage; } @@ -362,35 +350,6 @@ public class protocolMainServer extends Service { public int cmcm_call_eiot_into_powersave_mode() { return 0; } - public void deliverDataToCmApp(int paramInt, String paramString) { -// if (paramInt != 500) -// try { -// Intent intent = new Intent(this.actionName); -// intent.putExtra("comjson", paramString); -// intent.putExtra("cmdId", paramInt); -// (this.runtime.getContextProxy()).context.startService(intent); -// return; -// } catch (Exception e) { -// e.printStackTrace(); -// return; -// } -// try { -// StringBuilder stringBuilder = new StringBuilder(); -// stringBuilder.append("deliver 1 cmd="); -// stringBuilder.append(paramInt); -// stringBuilder.append("---data="); -// stringBuilder.append(paramString); -// Logger.i(stringBuilder.toString()); -// Intent intent = new Intent(this.actionName); -// intent.putExtra("comjson", paramString); -// intent.putExtra("cmdId", 999); -// (this.runtime.getContextProxy()).context.startService(intent); -// return; -// } catch (Exception e) { -// e.printStackTrace(); -// return; -// } - } public PowerManager.WakeLock getWakeLock(int paramInt) { PowerManager.WakeLock wakeLock = ((PowerManager)(this.runtime.getContextProxy()).context.getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag"); @@ -399,7 +358,11 @@ public class protocolMainServer extends Service { return wakeLock; } - public IBinder onBind(Intent paramIntent) { return this.mMessenger.getBinder(); } + public IBinder onBind(Intent paramIntent) { + return this.mMessenger.getBinder(); + } + + public Runtime getRuntime(){ return runtime; @@ -418,6 +381,7 @@ public class protocolMainServer extends Service { this.runtime.setContextProxy(new ContextProxy(this)); this.runtime.setLbsHelper(new LBSHelper(this,this.runtime.getContextProxy().getWifiManager(), this.runtime)); this.runtime.setImeiAndCid(PhoneUtils.getIMEI(this),""); + this.runtime.setHRS(new heartRateStatus()); this.connectionServiceChain = getConnectionServiceChain(); this.invokeHandlerServiceChain = getInvokeHandlerServiceChain(); if (cmcm_call_eiot_into_powersave_mode() == 1) { @@ -427,7 +391,7 @@ public class protocolMainServer extends Service { this.connectionServiceChain.processAttach(this.connection, this.runtime); this.invokeHandlerServiceChain.processAttach(this.connection, this.runtime); setAlarm(alarmCycle); - FileOutputUtil.fileOutput(this, "alarmCycle", "设置闹钟服务 alarmCycle"); + 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()); @@ -484,6 +448,9 @@ public class protocolMainServer extends Service { //网络协议心跳时间 setHeartAlarm(); + //设置心率检测频率 + setHeartRateDetectAlarm(3); //3分钟一次 + //获取天气时间 setWeatherAlarm(); @@ -527,7 +494,7 @@ public class protocolMainServer extends Service { Util.turnOffWifiForSleep((this.runtime.getContextProxy()).context, this.runtime); } setAlarm(alarmCycle); - FileOutputUtil.fileOutput(this, "alarmCycle", "ALARM alarmCycle"); + FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "ALARM alarmCycle"); //发送心跳间隔广播给其他应用 this.runtime.getContextProxy().sendBroadcast(ACTION_EQC_ALARM, this.runtime); @@ -544,7 +511,7 @@ public class protocolMainServer extends Service { if (Constants.SLEEP_ALARM.equals(paramIntent.getAction())) { Logger.i("SLEEP_ALARM"); is_allowed_in_sleep_mode = 1; - FileOutputUtil.fileOutput(this, "alarmCycle", "SLEEP_ALARM alarmCycle"); + FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "SLEEP_ALARM alarmCycle"); setSleepAlarm(); boolean bool = ((PowerManager)getSystemService(POWER_SERVICE)).isScreenOn(); stringBuilder1 = new StringBuilder(); @@ -562,7 +529,7 @@ public class protocolMainServer extends Service { if (Constants.WAKE_ALARM.equals(paramIntent.getAction())) { if (is_in_sleep_mode) { is_in_sleep_mode = false; - FileOutputUtil.fileOutput(this, "alarmCycle", "WAKE_ALARM alarmCycle"); + FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "WAKE_ALARM alarmCycle"); if (this.mKeepAlive != null) this.mKeepAlive.setSleepMode(false); wakeUpFromSleep(); @@ -575,7 +542,7 @@ public class protocolMainServer extends Service { if (this.mKeepAlive != null) { this.mKeepAlive.onHeartAlarm(this.connection, this.runtime); setHeartAlarm(); - FileOutputUtil.fileOutput(this, "alarmCycle", "HEART_ALARM alarmCycle " ); + FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "HEART_ALARM alarmCycle " ); return Service.START_STICKY; } } else { @@ -601,7 +568,7 @@ public class protocolMainServer extends Service { stringBuilder1 = new StringBuilder(); stringBuilder1.append("STWORKMODE_ALARM alarmCycle="); stringBuilder1.append(alarmCycle); - FileOutputUtil.fileOutput(this, "alarmCycle", stringBuilder1.toString()); + FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder1.toString()); return Service.START_STICKY; } if (ACTION_LOCATION_ALARM.equals(paramIntent.getAction())){ @@ -609,41 +576,14 @@ public class protocolMainServer extends Service { stringBuilder1 = new StringBuilder(); stringBuilder1.append("LOCATION_ALARM work mod="); stringBuilder1.append(runtime.getLocationInstance().getWorkingMod()); - FileOutputUtil.fileOutput(this, "alarmCycle", stringBuilder1.toString()); + FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder1.toString()); this.locationClient.triggerLocationProcess(); return Service.START_STICKY; } - -// if (Constants.ACTION_PASS_DATA_TO_CM_SERVICES.equals(paramIntent.getAction())) { -// deliverDataToCmApp(paramIntent.getIntExtra("cmdId", 0), paramIntent.getStringExtra("cmdJsonData")); -// return Service.START_STICKY; -// } -// if ("com.enqualcomm.support.MONITOR_EXIT".equals(paramIntent.getAction())) { -// deliverDataToCmApp(203, null); -// return Service.START_STICKY; -// } -// if ("cmcm.call.eiot.into.powersave".equals(paramIntent.getAction())) { -// if (cmcm_call_eiot_into_powersave_mode() == 1) { -// Logger.i("3 into powersave return"); -// return Service.START_STICKY; -// } -// if (cmcm_call_eiot_into_powersave_mode() == 2) { -// Logger.i("1 out powersave"); -// wakeUpFromSleep(); -// return Service.START_STICKY; -// } -// } else { -// if (cmcm_call_eiot_into_powersave_mode() == 1) { -// Logger.i("4 into powersave return"); -// return Service.START_STICKY; -// } -// if (cmcm_call_eiot_into_powersave_mode() == 2) { -// Logger.i("2 out powersave"); -// wakeUpFromSleep(); -// } -// this.invokeHandlerServiceChain.processUserRequest(paramIntent, this.connection, this.runtime); -// } + if(ACTION_HEATR_RATE_START.equals(paramIntent.getAction())){ + this.invokeHandlerServiceChain.processUserRequest(paramIntent, this.connection, this.runtime); + } } } } @@ -678,6 +618,9 @@ public class protocolMainServer extends Service { AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,paramInt,ACTION_ALARM); } + public void setHeartRateDetectAlarm(int heartRateDetectAlarmCycle){ + AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,heartRateDetectAlarmCycle,ACTION_HEATR_RATE_START); + } public void setLocationAlarm(int mod) { // int mod=runtime.getLocationInstance().getWorkingMod(); StringBuilder sb=new StringBuilder(); @@ -700,7 +643,7 @@ public class protocolMainServer extends Service { locationClient.triggerLocationProcess(); Logger.i(sb.toString()); - FileOutputUtil.fileOutput(runtime.getContextProxy().context,"LocationAlarm",sb.toString()); + FileOutputUtil.fileOutput(runtime.getCacheDir(),"LocationAlarm",sb.toString()); } public void setHeartAlarm(){ @@ -724,7 +667,7 @@ public class protocolMainServer extends Service { // locationClient.triggerLocationProcess(); Logger.i(sb.toString()); - FileOutputUtil.fileOutput(runtime.getContextProxy().context,"HeartAlarm",sb.toString()); + FileOutputUtil.fileOutput(runtime.getCacheDir(),"HeartAlarm",sb.toString()); // AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,1, HEART_ALARM); } @@ -758,7 +701,9 @@ public class protocolMainServer extends Service { private static class RequestHandler extends Handler { private final WeakReference mReference; - RequestHandler(protocolMainServer param1CoreService) { this.mReference = new WeakReference(param1CoreService); } + RequestHandler(protocolMainServer param1CoreService) { + this.mReference = new WeakReference(param1CoreService); + } public void handleMessage(Message param1Message) { protocolMainServer coreService = (protocolMainServer)this.mReference.get(); diff --git a/app/src/main/java/com/ic/protocol/utils/AlarmWakeUp.java b/app/src/main/java/com/ic/protocol/utils/AlarmWakeUp.java index 56b8713b..40c45525 100644 --- a/app/src/main/java/com/ic/protocol/utils/AlarmWakeUp.java +++ b/app/src/main/java/com/ic/protocol/utils/AlarmWakeUp.java @@ -20,14 +20,14 @@ public class AlarmWakeUp { ComponentName componentName = new ComponentName("com.ic.protocol", "com.ic.protocol.service.protocolMainServer"); Intent intent = (new Intent(protocolMainServer.ACTION_ALARM)).setComponent(componentName); (dev.getContextProxy()).context.startService(intent); - Context context = (dev.getContextProxy()).context; + StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("currentTimeMillis="); stringBuilder.append(l); stringBuilder.append("---lastAlarmTime="); stringBuilder.append(lastAlarmTime); Logger.i("AlarmWakeUp "+ stringBuilder.toString()); - FileOutputUtil.fileOutput(context, "alarmWakeUp", stringBuilder.toString()); + FileOutputUtil.fileOutput(dev.getCacheDir(), "alarmWakeUp", stringBuilder.toString()); } } diff --git a/app/src/main/java/com/ic/protocol/utils/BatteryUtil.java b/app/src/main/java/com/ic/protocol/utils/BatteryUtil.java index baf63a3a..2ec22681 100644 --- a/app/src/main/java/com/ic/protocol/utils/BatteryUtil.java +++ b/app/src/main/java/com/ic/protocol/utils/BatteryUtil.java @@ -20,7 +20,7 @@ public class BatteryUtil { } int i = param1Intent.getIntExtra("level", 0) * 100 / param1Intent.getIntExtra("scale", 100); - FileOutputUtil.fileOutput(param1Context,"Battery","BatteryLevel "+i); + 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/ic/protocol/utils/CellInfoUtil.java b/app/src/main/java/com/ic/protocol/utils/CellInfoUtil.java index 17023170..2843cb5c 100644 --- a/app/src/main/java/com/ic/protocol/utils/CellInfoUtil.java +++ b/app/src/main/java/com/ic/protocol/utils/CellInfoUtil.java @@ -106,7 +106,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.getContextProxy()).context, "onCellLocationChanged", mCellInfo); + FileOutputUtil.fileOutput(mRuntime.getCacheDir(),"onCellLocationChanged", mCellInfo); CellInfoUtil.releaseWakeLock(mWakeLock); Logger.i(" setCurrentAttachCellInfo " + mCellInfo); @@ -132,7 +132,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.getContextProxy()).context, "onCellLocationChanged", mRuntime.cellinfo); + FileOutputUtil.fileOutput(mRuntime.getCacheDir(), "onCellLocationChanged", mRuntime.cellinfo); CellInfoUtil.releaseWakeLock(mWakeLock); Logger.i(" setCurrentAttachCellInfo " + mCellInfo); diff --git a/app/src/main/java/com/ic/protocol/utils/FileOutputUtil.java b/app/src/main/java/com/ic/protocol/utils/FileOutputUtil.java index 052302ce..7830f1a3 100644 --- a/app/src/main/java/com/ic/protocol/utils/FileOutputUtil.java +++ b/app/src/main/java/com/ic/protocol/utils/FileOutputUtil.java @@ -6,67 +6,97 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.InputStream; import java.io.PrintStream; public class FileOutputUtil { - public static void copyFolder(String dirsrc, String dirdst) { + + + /** + * 复制单个文件 + * @param oldPath String 原文件路径 如:c:/fqf.txt + * @param newPath String 复制后路径 如:f:/fqf.txt + * @return boolean + */ + public static void copyFile(String oldPath, String newPath) { try { - (new File(dirdst)).mkdirs(); - String[] arrayOfString = (new File(dirsrc)).list(); - for (byte b = 0; b < arrayOfString.length; b++) { - File file; - if (dirsrc.endsWith(File.separator)) { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(dirsrc); - stringBuilder.append(arrayOfString[b]); - file = new File(stringBuilder.toString()); - } else { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(dirsrc); - stringBuilder.append(File.separator); - stringBuilder.append(arrayOfString[b]); - file = new File(stringBuilder.toString()); - } - if (file.isFile()) { - FileInputStream fileInputStream = new FileInputStream(file); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(dirdst); - stringBuilder.append("/"); - stringBuilder.append(file.getName().toString()); - FileOutputStream fileOutputStream = new FileOutputStream(stringBuilder.toString()); - byte[] arrayOfByte = new byte[5120]; - while (true) { - int i = fileInputStream.read(arrayOfByte); - if (i != -1) { - fileOutputStream.write(arrayOfByte, 0, i); - continue; - } - break; - } - fileOutputStream.flush(); - fileOutputStream.close(); - fileInputStream.close(); - } - if (file.isDirectory()) { - StringBuilder stringBuilder1 = new StringBuilder(); - stringBuilder1.append(dirsrc); - stringBuilder1.append("/"); - stringBuilder1.append(arrayOfString[b]); - String str = stringBuilder1.toString(); - StringBuilder stringBuilder2 = new StringBuilder(); - stringBuilder2.append(dirdst); - stringBuilder2.append("/"); - stringBuilder2.append(arrayOfString[b]); - copyFolder(str, stringBuilder2.toString()); - } - } - } catch (Exception e) { + int bytesum = 0; + int byteread = 0; + File oldfile = new File(oldPath); + if (oldfile.exists()) { //文件存在时 + InputStream inStream = new FileInputStream(oldPath); //读入原文件 + FileOutputStream fs = new FileOutputStream(newPath); + byte[] buffer = new byte[1444]; + int length; + while ( (byteread = inStream.read(buffer)) != -1) { + bytesum += byteread; //字节数 文件大小 + System.out.println(bytesum); + fs.write(buffer, 0, byteread); + } + inStream.close(); + } + } + catch (Exception e) { + System.out.println("复制单个文件操作出错"); + e.printStackTrace(); + + } + + } + + /** + * 复制整个文件夹内容 + * @param oldPath String 原文件路径 如:c:/fqf + * @param newPath String 复制后路径 如:f:/fqf/ff + * @return boolean + */ + public static void copyFolder(String oldPath, String newPath) { + + try { + File dstdir=new File(newPath); + if (!dstdir.exists()) { + dstdir.mkdirs();//如果文件夹不存在 则建立新文件夹 + } + File a=new File(oldPath); + String[] file=a.list(); + File temp=null; + for (int i = 0; i < file.length; i++) { + if(oldPath.endsWith(File.separator)){ + temp=new File(oldPath+file[i]); + } + else{ + temp=new File(oldPath+File.separator+file[i]); + } + + if(temp.isFile()){ + FileInputStream input = new FileInputStream(temp); + FileOutputStream output = new FileOutputStream(newPath + "/" + + (temp.getName()).toString()); + byte[] b = new byte[1024 * 5]; + int len; + while ( (len = input.read(b)) != -1) { + output.write(b, 0, len); + } + output.flush(); + output.close(); + input.close(); + } + if(temp.isDirectory()){//如果是子文件夹 + copyFolder(oldPath+"/"+file[i],newPath+"/"+file[i]); + } + } + } + catch (Exception e) { System.out.println("复制整个文件夹内容操作出错"); e.printStackTrace(); - } + + } + } - public static void deleteDir(Context paramContext) { deleteDirWihtFile(new File(String.valueOf(paramContext.getExternalCacheDir()))); } + public static void deleteDir(Context paramContext) { + deleteDirWihtFile(new File(String.valueOf(paramContext.getExternalCacheDir()))); + } private static void deleteDirWihtFile(File paramFile) { if (paramFile != null) @@ -89,9 +119,9 @@ public class FileOutputUtil { } } - public static void fileOutput(Context paramContext, String filename, String msg) { + public static void fileOutput(File dir, String filename, String msg) { String str = TimeUtil.getSystemTime(); - File dir = paramContext.getExternalCacheDir(); + StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(filename); stringBuilder.append(".txt"); diff --git a/app/src/main/java/com/ic/protocol/utils/Logger.java b/app/src/main/java/com/ic/protocol/utils/Logger.java index fa62e72a..934036b8 100644 --- a/app/src/main/java/com/ic/protocol/utils/Logger.java +++ b/app/src/main/java/com/ic/protocol/utils/Logger.java @@ -69,7 +69,7 @@ public class Logger { if (DEBUG) { Log.e(TAG, msg); if (protocolMainServer.getInstance()!=null) - FileOutputUtil.fileOutput(protocolMainServer.getInstance().getApplicationContext(),"log",TAG + " "+ msg); + FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(),"log",TAG + " "+ msg); } @@ -79,7 +79,7 @@ public class Logger { if (DEBUG) { Log.e(TAG, "[" + funcName + "]" + msg); if (protocolMainServer.getInstance()!=null) - FileOutputUtil.fileOutput(protocolMainServer.getInstance().getApplicationContext(),"log",TAG + " "+ "[" + funcName + "]" + msg); + FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(),"log",TAG + " "+ "[" + funcName + "]" + msg); } } } diff --git a/app/src/main/java/com/ic/protocol/utils/NettyConnection.java b/app/src/main/java/com/ic/protocol/utils/NettyConnection.java index 7c8fed9f..1d44fc0f 100644 --- a/app/src/main/java/com/ic/protocol/utils/NettyConnection.java +++ b/app/src/main/java/com/ic/protocol/utils/NettyConnection.java @@ -10,6 +10,7 @@ import android.os.SystemClock; import com.ic.protocol.LocationClient; import com.ic.protocol.adapter.protocolAPIHelper; import com.ic.protocol.bean.StringMessage; +import com.ic.protocol.service.HeartRateManager; import com.ic.protocol.service.protocolMainServer; import java.io.UnsupportedEncodingException; @@ -45,10 +46,11 @@ public class NettyConnection implements Connection { @Override public boolean handleCmd(protocolAPIHelper.CMD_TYPE type, String cmd) { + //普通非二进制命令用此函数处理 Runtime runtime=protocolMainServer.getInstance().getRuntime(); boolean ret=true; Logger.i("handleCmd "+type.name() + " strLen="+cmd.length()); - FileOutputUtil.fileOutput(protocolMainServer.getInstance().getApplicationContext(),"APILog", " recv " + cmd); + FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(),"APILog", " recv " + cmd); switch (type){ case BP00: API.handleBP00(cmd); @@ -65,12 +67,6 @@ public class NettyConnection implements Connection { DeliverCMDMessageToSystem("BP03",cmd);//通知下面线程状态变化 break; -// case BP28: -// API.handleBP28(NettyConnection.this ,cmd); -// Logger.i("服务器收到语音BP28"); -// DeliverCMDMessageToSystem("BP28",cmd);//通知下面线程状态变化 -// -// break; case BPTM: // API.handleBPTM(cmd); Logger.i("服务器收到校时命令APTM"); @@ -130,6 +126,21 @@ public class NettyConnection implements Connection { Logger.i("收到服务器关机命令BP31"); DeliverCMDMessageToSystem("poweroff",cmd);//通知下面线程状态变化 break; + + case BPXL: + API.handleBPXL(cmd,NettyConnection.this); + Logger.i("收到服务器心率检测命令"); + HeartRateManager.triggerPPGtest(); + break; + case BPXY: + API.handleBPXY(cmd,NettyConnection.this); + Logger.i("收到服务器血压检测命令"); + HeartRateManager.triggerPPGtest(); + break; + case BPJZ: + API.handleBPJZ(cmd,NettyConnection.this,runtime); + Logger.i("收到服务器血压校准命令"); + } return ret; @@ -139,9 +150,10 @@ public class NettyConnection implements Connection { @Override public boolean handleCmd(protocolAPIHelper.CMD_TYPE type, String cmd, byte[] bytes) { + //只有需要传递二级制数据的才需要这个函数,目前只有BP28需要 boolean ret=true; Logger.i("handleCmd "+type.name() + " "+cmd+" bytelen="+bytes.length ); - FileOutputUtil.fileOutput(protocolMainServer.getInstance().getApplicationContext(),"APILog", " recv " +new String(bytes)); + FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(),"APILog", " recv " +new String(bytes)); switch (type) { case BP28: API.handleBP28(NettyConnection.this,cmd, bytes); @@ -255,7 +267,7 @@ public class NettyConnection implements Connection { if (!isServerConnected()){ log("skiped"+cmd); - FileOutputUtil.fileOutput(protocolMainServer.getInstance().getApplicationContext(),"APILog"," skiped " + cmd); + FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(),"APILog"," skiped " + cmd); return false; }else{ log("send "+cmd); @@ -276,7 +288,7 @@ public class NettyConnection implements Connection { } ); - FileOutputUtil.fileOutput(protocolMainServer.getInstance().getApplicationContext(),"APILog"," sent " + cmd); + FileOutputUtil.fileOutput(protocolMainServer.getInstance().getRuntime().getCacheDir(),"APILog"," sent " + cmd); } diff --git a/app/src/main/java/com/ic/protocol/utils/ProcessReceiver.java b/app/src/main/java/com/ic/protocol/utils/ProcessReceiver.java index b9a614be..e2c09037 100644 --- a/app/src/main/java/com/ic/protocol/utils/ProcessReceiver.java +++ b/app/src/main/java/com/ic/protocol/utils/ProcessReceiver.java @@ -20,6 +20,7 @@ import android.view.View; import com.ic.protocol.R; import com.ic.protocol.bean.Contact; import com.ic.protocol.service.AudioService; +import com.ic.protocol.service.HeartRateManager; import java.util.concurrent.TimeUnit; @@ -30,6 +31,7 @@ import rx.schedulers.Schedulers; import static android.os.PowerManager.ACQUIRE_CAUSES_WAKEUP; import static android.os.PowerManager.SCREEN_DIM_WAKE_LOCK; +import static com.ic.protocol.Constants.ACTION_HEATR_RATE_START; public class ProcessReceiver extends BroadcastReceiver { private static final int MICRO_CHAT = 2; @@ -319,7 +321,8 @@ public class ProcessReceiver extends BroadcastReceiver { this.mNotificationManager = (NotificationManager)paramContext.getSystemService(Context.NOTIFICATION_SERVICE); this.mNotificationManager.notify(1, notification); } - + + @Override public void onReceive(Context paramContext, Intent paramIntent) { Contact contact; String str = paramIntent.getAction(); @@ -336,18 +339,11 @@ public class ProcessReceiver extends BroadcastReceiver { SharPreferenceUtil.setPrefBoolean(paramContext, "key_is_resume", paramIntent.getBooleanExtra("is_resume", false)); return; } - if ("com.enqualcomm.support.DIALOG".equals(str)) { - contact = (Contact)paramIntent.getParcelableExtra("contact"); - SharPreferenceUtil.getPrefBoolean(paramContext, "key_is_resume", false); - boolean bool = SharPreferenceUtil.getPrefBoolean(paramContext, "KEY_ISSILENCE", false); -// if (contact != null && !bool) { -// if (!DeviceInfoUtil.isTopActivity(paramContext)) { -// initMyDialog(paramContext, contact, 1); -// playNotificationVoice(paramContext); -// } -// screenOn(paramContext); -// return; -// } + if (ACTION_HEATR_RATE_START.equals(str)) { +// contact = (Contact)paramIntent.getParcelableExtra("contact"); +// SharPreferenceUtil.getPrefBoolean(paramContext, "key_is_resume", false); + + } else if ("com.enqualcomm.imessage.SOS_ACTION".equals(str)) { if (paramIntent.getIntExtra("sos_end", 0) == 0) { // EqcAlgorithmNative.native_EqcAlgorithmMethod3(8); @@ -361,24 +357,8 @@ public class ProcessReceiver extends BroadcastReceiver { (new CameraUtil(paramContext)).getPictur(str1); return; } - if ("com.enqualcomm.support.CloseUnreadMsg".equals(paramIntent.getAction()) || "android.intent.action.BATTERY_LOW".equals(paramIntent.getAction())) { -// if (mCustomDialog != null && mCustomDialog.isShowing()) -// mCustomDialog.dismiss(); -// if (this.mCustomNotification != null && this.mCustomNotification.isShowing()) -// this.mCustomNotification.dismiss(); - return; - } - if ("com.enqualcomm.support.ACTION_MISSED_CALL_GET".equals(str)) { - Contact contact1 = (Contact)paramIntent.getParcelableExtra("contact"); - contact1.extra = paramIntent.getStringExtra("date"); - boolean bool = SharPreferenceUtil.getPrefBoolean(paramContext, "KEY_ISSILENCE", false); -// if (contact1 != null && !bool) { -// initMyDialog(paramContext, contact1, 2); -// playNotificationVoice(paramContext); -// screenOn(paramContext); -// return; -// } - } + + } }