From: snickersun Date: Thu, 9 Jan 2020 15:20:22 +0000 (+0800) Subject: 更新定位协议,根据模式决定是否采用GPS优先 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=231726502faaf33cb6de66e176734dba165f584f;p=icsupport.git 更新定位协议,根据模式决定是否采用GPS优先 --- diff --git a/.gradle/5.4.1/executionHistory/executionHistory.bin b/.gradle/5.4.1/executionHistory/executionHistory.bin index cbf75be0..82e76a21 100644 Binary files a/.gradle/5.4.1/executionHistory/executionHistory.bin and b/.gradle/5.4.1/executionHistory/executionHistory.bin differ diff --git a/.gradle/5.4.1/executionHistory/executionHistory.lock b/.gradle/5.4.1/executionHistory/executionHistory.lock index 06770aac..d924b88d 100644 Binary files a/.gradle/5.4.1/executionHistory/executionHistory.lock and b/.gradle/5.4.1/executionHistory/executionHistory.lock differ diff --git a/.gradle/5.4.1/fileHashes/fileHashes.bin b/.gradle/5.4.1/fileHashes/fileHashes.bin index b3b20a9c..f6ca5039 100644 Binary files a/.gradle/5.4.1/fileHashes/fileHashes.bin and b/.gradle/5.4.1/fileHashes/fileHashes.bin differ diff --git a/.gradle/5.4.1/fileHashes/fileHashes.lock b/.gradle/5.4.1/fileHashes/fileHashes.lock index 31040f21..453d317d 100644 Binary files a/.gradle/5.4.1/fileHashes/fileHashes.lock and b/.gradle/5.4.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/5.4.1/fileHashes/resourceHashesCache.bin b/.gradle/5.4.1/fileHashes/resourceHashesCache.bin index 4e069773..6544497d 100644 Binary files a/.gradle/5.4.1/fileHashes/resourceHashesCache.bin and b/.gradle/5.4.1/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/5.4.1/javaCompile/classAnalysis.bin b/.gradle/5.4.1/javaCompile/classAnalysis.bin index e9caf051..2087f741 100644 Binary files a/.gradle/5.4.1/javaCompile/classAnalysis.bin and b/.gradle/5.4.1/javaCompile/classAnalysis.bin differ diff --git a/.gradle/5.4.1/javaCompile/javaCompile.lock b/.gradle/5.4.1/javaCompile/javaCompile.lock index 539ba533..afd4fc79 100644 Binary files a/.gradle/5.4.1/javaCompile/javaCompile.lock and b/.gradle/5.4.1/javaCompile/javaCompile.lock differ diff --git a/.gradle/5.4.1/javaCompile/taskHistory.bin b/.gradle/5.4.1/javaCompile/taskHistory.bin index 228a51ef..8c3a7f51 100644 Binary files a/.gradle/5.4.1/javaCompile/taskHistory.bin and b/.gradle/5.4.1/javaCompile/taskHistory.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index e1036d60..57222f8a 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index e57da57b..54f9a0e6 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index ef7cb6a1..d5b2fbf1 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/caches/gradle_models.ser b/.idea/caches/gradle_models.ser index 66c73d91..221b03f0 100644 Binary files a/.idea/caches/gradle_models.ser and b/.idea/caches/gradle_models.ser differ diff --git a/.idea/misc.xml b/.idea/misc.xml index 6f32454d..6fd9e2bb 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6752a982..a2d0e8fe 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -17,20 +17,35 @@ + + + + + - + + + - + + + + + + - + + + + - + + + + + + + true + + + + + + + @@ -454,31 +591,31 @@ - - + - - - - - + + + + + - - + + - - - + + + - - + + - + + - + @@ -514,7 +651,7 @@ file://$PROJECT_DIR$/app/src/main/java/com/ic/protocol/LocationClient.java - 350 + 346 @@ -524,30 +661,22 @@ - - - - - - - - - - - - - - - - - - - + + paramStringMessage.cmd() + JAVA + EXPRESSION + arrayOfString1[5] JAVA @@ -593,173 +722,150 @@ JAVA EXPRESSION - - CellInfoUtil.getLAC() - JAVA - EXPRESSION - - - - - - - - - + - - + + - + - - + + - + - - - - - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + + + + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - - - - + + - + - - + + - + - - + + - - - - - + - - - - - - + + @@ -770,230 +876,269 @@ - - - - + + + + + - + - - + + - + - - + + - + - - + + + + + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + + + + + - + - - + + - - + + - - - + - - - - - - + + - + - - - - - - + + - + - - + + - + - - + + - + - - + + + + + + + - + + - - + + - + - - + + - + - - - - - - + + - - + + + + + + - - + + - - - - + - + - - + + + + + + + + + + + + + + + + - - + + - - + + + + + + + + + + + + + - + + + + + + + + - - + + - + + + + - - + + + + diff --git a/app/app.iml b/app/app.iml index 95ac0dd5..f9ea079a 100644 --- a/app/app.iml +++ b/app/app.iml @@ -103,8 +103,8 @@ - - + + diff --git a/app/debug/output.json b/app/debug/output.json deleted file mode 100644 index 4a5be37e..00000000 --- a/app/debug/output.json +++ /dev/null @@ -1 +0,0 @@ -[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":320,"versionName":"202001082349","enabled":true,"outputFile":"ICSer_V320_202001082349_debug.apk","fullName":"debug","baseName":"debug"},"path":"ICSer_V320_202001082349_debug.apk","properties":{}}] \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 07c8168a..69406a15 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -128,6 +128,7 @@ + diff --git a/app/src/main/java/com/ic/protocol/Constants.java b/app/src/main/java/com/ic/protocol/Constants.java index 69c786de..08ad4bd6 100644 --- a/app/src/main/java/com/ic/protocol/Constants.java +++ b/app/src/main/java/com/ic/protocol/Constants.java @@ -26,7 +26,9 @@ public interface Constants { public static final String ACTION_CM_POWERSAVE_MODE = "cmcm.call.eiot.into.powersave"; public static final String ACTION_EQC_ALARM = "com.enqualcomm.support.ACTION_EQC_ALARM"; - + + public static final String ACTION_LOCATION_ALARM = "com.enqualcomm.support.ACTION_LOCATION_ALARM"; + public static final String ACTION_EXIT_MONITOR_MODE = "com.enqualcomm.support.MONITOR_EXIT"; public static final String ACTION_HEART_RATE_RESULT = "com.eqc.heartrate.action.RESULT"; diff --git a/app/src/main/java/com/ic/protocol/LocationClient.java b/app/src/main/java/com/ic/protocol/LocationClient.java index 3f7c44a7..76b204db 100644 --- a/app/src/main/java/com/ic/protocol/LocationClient.java +++ b/app/src/main/java/com/ic/protocol/LocationClient.java @@ -48,6 +48,9 @@ import rx.android.schedulers.AndroidSchedulers; import rx.functions.Action1; import static android.location.LocationManager.GPS_PROVIDER; +import static com.ic.protocol.Constants.ACTION_LOCATION_ALARM; +import static com.ic.protocol.Constants.HEART_ALARM; +import static com.ic.protocol.bean.ICLocation.NORMAL_MOD; public class LocationClient { private static final String TAG = LocationClient.class.getSimpleName(); @@ -248,12 +251,7 @@ public class LocationClient { private void performAlarm(PowerManager.WakeLock paramWakeLock) { if (!runtime.isAirMode) { - CellInfoUtil.setCurrentAttachCellInfo(runtime, paramWakeLock); - runtime.getLocationInstance().setMNC(String.valueOf(CellInfoUtil.getMNC())); - runtime.getLocationInstance().setCID(CellInfoUtil.getCELL_ID()); - runtime.getLocationInstance().setMCC(String.valueOf(CellInfoUtil.getMCC())); - runtime.getLocationInstance().setLAC(CellInfoUtil.getLAC()); - runtime.preCellInfo = CellInfoUtil.getCellInfo(); + CellInfoUtil.triggerUpdateCellinfo(); sendBatteryNotification(); // startLocationProcess(); } @@ -323,8 +321,8 @@ public class LocationClient { // stringMessage = stringMessage1; // } } - if (stringMessage != null) - ServiceUtil.offerQueue(stringMessage); +// if (stringMessage != null) +// ServiceUtil.offerQueue(stringMessage); } // public static void AP16Queue() { @@ -371,6 +369,9 @@ public class LocationClient { } } + public void triggerLocationProcess(){ + mhandler.sendEmptyMessage(0); + } public void EqcAlgorithmInterfaceMethod1(final int cycle_location_flag, int paramInt2, final int delay_flag, final double latitude, final double longitude, final double altitude, final float speed, final float bearing, final int sv_no, final float accuracy, final long timestamp_cur, final long timestamp_last_location, final double latitude_last_location, final double longitude_last_location, final int mode, long paramLong3, final int status_cur_location) { // StringBuilder stringBuilder1 = new StringBuilder(); @@ -509,15 +510,10 @@ public class LocationClient { private static int checktimes=0; private static boolean timeout=false; -// public void EqcAlgorithmInterfaceMethod2() { - public void startGpsLocate() { + private static boolean isLocating=false; - - Settings.Secure.setLocationProviderEnabled(runtime.getContextProxy().getResolver(), GPS_PROVIDER, true); - Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1() { - public void call(Object param1Object) { LocationClient.this.nmeaListener.startListen(); } - }); - Logger.i("开启GPS开启wifi扫描"); + public void startWifiScan(){ + Logger.i("开启wifi扫描"); runtime.currentWifiInfo = ""; mHasWifiResult = false; this.mLbsHelper.registerBroadReceiver(); @@ -525,23 +521,33 @@ public class LocationClient { this.mLbsHelper.setOnWiFiInfoListener(new LBSHelper.OnWiFiInfoListener() { public void getWifiInfoCallBack(String param1String) { // LocationClient.access$002(true); - Logger.i("get wifi scan Callback " + param1String); - LocationClient.mHasWifiResult=true; - runtime.currentWifiInfo = param1String; - runtime.setWifiinfo(param1String); + Logger.i("get wifi scan Callback " + param1String); + LocationClient.mHasWifiResult=true; + runtime.currentWifiInfo = param1String; + runtime.setWifiinfo(param1String); } + }); + } +// public void EqcAlgorithmInterfaceMethod2() { + public void startGpsLocate() { + Logger.i("开启GPS扫描"); + Settings.Secure.setLocationProviderEnabled(runtime.getContextProxy().getResolver(), GPS_PROVIDER, true); + Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1() { + public void call(Object param1Object) { LocationClient.this.nmeaListener.startListen(); } }); - Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1() { - public void call(Object param1Object) { LocationClient.this.waitAndSendLocation(); } - }); +// Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1() { +// public void call(Object param1Object) { LocationClient.this.waitAndSendLocation(); } +// }); + + } + public void startCheckResult(){ checktimes=0; timeout=false; //延时2秒执行发送“读取定位”消息 if (mTimer==null) mTimer=new Timer(); mTimer.schedule(new MyTimerTask(), 0,1000L); - } class MyTimerTask extends TimerTask { public void run() { @@ -553,9 +559,13 @@ public class LocationClient { public void handleMessage(Message msg) { super.handleMessage(msg); - if (msg.what != 100) - return; - waitAndSendLocation(); + if (msg.what == 100){ + waitAndSendLocation(); + }else if (msg.what == 0){ + startLocationProcess(WorkingMod); + } + + } }; @@ -569,6 +579,8 @@ public class LocationClient { gps_ok=false; lbs_ok=false; gps_nosignal=false; + + int mode=runtime.getLocationInstance().getWorkingMod(); if (runtime.currentWifiInfo.length()>0 ) wifi_ok =true; if (runtime.getLocationInstance().getLocationStat() == ICLocation.LOCATION_STAT.LOCATION_FIXED) gps_ok=true; if (runtime.getLocationInstance().getLocationStat() == ICLocation.LOCATION_STAT.LOCATION_GPS_TIEMOUT) gps_nosignal=true; @@ -578,24 +590,58 @@ public class LocationClient { && 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("lbs_ok "+lbs_ok+" waitAndSendLocation wifi_ok " + wifi_ok+ " gps_ok "+gps_ok); - if ((lbs_ok && timeout==true) ||(lbs_ok && gps_ok && wifi_ok )||(lbs_ok&&gps_nosignal&&wifi_ok)){ - - Logger.i("offerQueue "+protocolAPIHelper.AP01(runtime)); - ServiceUtil.offerQueue(protocolAPIHelper.genStringMessage("AP01", protocolAPIHelper.AP01(runtime))); - triggerSendThread(); - if (mTimer!=null){ - mTimer.cancel(); - mTimer=null; - } - }else if (timeout==true){ - Logger.i("timeout no location "); - - if (mTimer!=null){ - mTimer.cancel(); - mTimer=null; - } + Logger.i("lbs_ok "+lbs_ok+" waitAndSendLocation wifi_ok " + wifi_ok+ " gps_ok "+gps_ok + " mode "+mode); + + switch(mode){ + case ICLocation.EMERGNECY_MOD: + case ICLocation.REALTIME_MOD: + 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))); +// triggerSendThread(); + if (mTimer!=null){ + mTimer.cancel(); + mTimer=null; + } + isLocating = false; + }else if (timeout==true){ + Logger.i("timeout no location "); + isLocating = false; + if (mTimer!=null){ + mTimer.cancel(); + mTimer=null; + } + } + break; + default: + if ((lbs_ok && timeout==true) ||(lbs_ok && wifi_ok )){ + + if (connection.isServerConnected() && KeepAlive.isConnected) + { + Logger.i("send "+protocolAPIHelper.AP01(runtime)); + connection.send(protocolAPIHelper.genStringMessage("AP01", protocolAPIHelper.AP01(runtime))); + }else{ + Logger.i("offline skip "+protocolAPIHelper.AP01(runtime)); + + } +// triggerSendThread(); + if (mTimer!=null){ + mTimer.cancel(); + mTimer=null; + } + isLocating = false; + }else if (timeout==true){ + Logger.i("timeout no location "); + isLocating = false; + if (mTimer!=null){ + mTimer.cancel(); + mTimer=null; + } + } + break; } + } // public void EqcAlgorithmInterfaceMethod3() { @@ -612,8 +658,9 @@ public class LocationClient { // public void EqcAlgorithmInterfaceMethod4() { public void updateCellInfo() { - this.mLbsHelper.getAttchCellInfo(runtime.getContextProxy().getTelephonyManager()); - + this.mLbsHelper.getAttchCellInfo(runtime.getContextProxy().getTelephonyManager()); +// CellInfoUtil.triggerUpdateCellinfo(); + CellInfoUtil.setCurrentAttachCellInfo(runtime, getLocationWakeLock()); } // public void EqcAlgorithmInterfaceMethod5(int paramInt) { @@ -671,103 +718,85 @@ public void updateCellInfo() { this.gSensorListener.startListen(paramWakeLock); performAlarm(paramWakeLock); } - public void startLocationProcess(){ - updateCellInfo(); + public void startLocationProcess(int mod){ + + if (isLocating ) return; + isLocating=true; updateSimSignalInfo(); - startGpsLocate(); + + updateCellInfo(); + startWifiScan(); + switch(mod){ + case ICLocation.EMERGNECY_MOD: + case ICLocation.REALTIME_MOD: + startGpsLocate(); + break; + } + + startCheckResult(); } + + private static int WorkingMod=1; public void onReceive(StringMessage paramStringMessage) { - Logger.i("LocationClient onReceive " +paramStringMessage.cmd() ); + Logger.i("LocationClient onReceive " +paramStringMessage.cmd()+" linkOK "+linkOK ); if ("Sport:OK".equals(paramStringMessage.cmd())) this.mPedometer2 = this.H12StepCount; + + +// if (linkOK) +// return; +// if (paramStringMessage.cmd().startsWith("AP") || paramStringMessage.cmd().startsWith("BP")) { +// //如果Link:OK 则触发(激活)等待信号的发送线程 +//// triggerSendThread(); +// } //响应定位指令 if ("StartLocate".equals(paramStringMessage.cmd()) ){ // triggerSendThread(); -// this.startLocationProcess(); + this.startLocationProcess(WorkingMod); } - if ("ResartHeartAlarm".equals(paramStringMessage.cmd()) ){ + if ("ResartHeartAlarm".equals(paramStringMessage.cmd())) { // triggerSendThread(); -// this.startLocationProcess(); -// protocolMainServer.getInstance().setHeartAlarm(); + 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, LACATION_MODE, mod); + runtime.getLocationInstance().setWorkingMod(mod); +// runtime.getLocationInstance().setLocation_cycle(3); + Logger.i("ResartHeartAlarm 1 mod "+mod); + protocolMainServer.getInstance().setHeartAlarm(mod); + Logger.i("ResartHeartAlarm 2"); + runtime.getContextProxy().sendBroadcast(HEART_ALARM,runtime); + this.startLocationProcess(mod); + WorkingMod=mod; + Logger.i("ResartHeartAlarm 3 WorkingMod " +WorkingMod); + + } -// if (linkOK) -// return; - if (paramStringMessage.cmd().startsWith("AP") || paramStringMessage.cmd().startsWith("BP")) { - //如果Link:OK 则触发(激活)等待信号的发送线程 - triggerSendThread(); - } + } public void triggerSendThread(){ -// this.mLock.lock(); -// try { -// linkOK = true; -//// this.mCondition.signal(); -// return; -// } finally { -// this.mLock.unlock(); -// } - } - public void resolveResult(int paramInt1, int paramInt2, int paramInt3, double paramDouble1, double paramDouble2, double paramDouble3, float paramFloat1, float paramFloat2, int paramInt4, float paramFloat3, long paramLong1, long paramLong2, double paramDouble4, double paramDouble5, int paramInt5, long paramLong3, int paramInt6) { - int i = SharPreferenceUtil.getPrefInt((runtime.getContextProxy()).context, LACATION_CYCLE, 3); - String str1 = runtime.getLatitude(); - String str2 = runtime.getLongitude(); - paramLong2 = runtime.getTimestamp(); - isLocationCallBack = false; - if ((paramInt2 & 0x1) == 1) { - Logger.i("开机定位"); - performExecute(paramInt1, i, 0, paramInt3, paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2, paramInt4, paramFloat3, paramLong1, paramLong2, str1, str2, paramInt5, paramLong3, paramInt6); - } - if ((paramInt2 & 0x2) >> 1 == 1) { - Logger.i("周期定位"); - performExecute(paramInt1, i, 1, paramInt3, paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2, paramInt4, paramFloat3, paramLong1, paramLong2, str1, str2, paramInt5, paramLong3, paramInt6); - } - if ((paramInt2 & 0x4) >> 2 == 1) { - Logger.i("主动定位"); - performExecute(paramInt1, i, 2, paramInt3, paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2, paramInt4, paramFloat3, paramLong1, paramLong2, str1, str2, paramInt5, paramLong3, paramInt6); - } - if ((paramInt2 & 0x8) >> 3 == 1) { - Logger.i("SOS定位"); - performExecute(paramInt1, i, 3, paramInt3, paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2, paramInt4, paramFloat3, paramLong1, paramLong2, str1, str2, paramInt5, paramLong3, paramInt6); - } - if ((paramInt2 & 0x10) >> 4 == 1) { - Logger.i("获取位置信息"); - performExecute(paramInt1, i, 4, paramInt3, paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2, paramInt4, paramFloat3, paramLong1, paramLong2, str1, str2, paramInt5, paramLong3, paramInt6); - } - if ((paramInt2 & 0x20) >> 5 == 1) { - Logger.i("定时定位"); - performExecute(paramInt1, i, 5, paramInt3, paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2, paramInt4, paramFloat3, paramLong1, paramLong2, str1, str2, paramInt5, paramLong3, paramInt6); - } - if ((paramInt2 & 0x40) >> 6 == 1) { - Logger.i("实时定位"); - performExecute(paramInt1, i, 6, paramInt3, paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2, paramInt4, paramFloat3, paramLong1, paramLong2, str1, str2, paramInt5, paramLong3, paramInt6); - } - if ((paramInt2 & 0x80) >> 7 == 1) { - Logger.i("摇一摇"); - Runtime runtime1 = runtime; - LocationClient locationClient = this; -// ServiceUtil.offerQueue(API.H15(runtime1, locationClient.mWifiInfo, locationClient.mCellInfo, 7)); - } - if ((paramInt2 & 0x100) >> 8 == 1) { - Logger.i("脱落报警"); - performExecute(paramInt1, i, 8, paramInt3, paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2, paramInt4, paramFloat3, paramLong1, paramLong2, str1, str2, paramInt5, paramLong3, paramInt6); - } - if ((paramInt2 & 0x200) >> 9 == 1) { - Logger.i("照相定位"); - performExecute(paramInt1, i, 9, paramInt3, paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2, paramInt4, paramFloat3, paramLong1, paramLong2, str1, str2, paramInt5, paramLong3, paramInt6); - } - if ((paramInt2 & 0x400) >> 10 == 1) { - Logger.i("获取经纬度"); - performExecute(paramInt1, i, 10, paramInt3, paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2, paramInt4, paramFloat3, paramLong1, paramLong2, str1, str2, paramInt5, paramLong3, paramInt6); - } - if ((paramInt2 & 0x800) >> 11 == 1) { - Logger.i("获取天气"); - performExecute(paramInt1, i, 11, paramInt3, paramDouble1, paramDouble2, paramDouble3, paramFloat1, paramFloat2, paramInt4, paramFloat3, paramLong1, paramLong2, str1, str2, paramInt5, paramLong3, paramInt6); + this.mLock.lock(); + try { + linkOK = true; + this.mCondition.signal(); + + } finally { + this.mLock.unlock(); } } + MyThread2 mythread2=null; public void start() { + + this.mSignalUtil = SimSignalUtil.getInstance((runtime.getContextProxy()).context); // 开启计步 // EqcAlgorithmNative.EqcAlgorithmNativeSetInterface(this); @@ -781,20 +810,21 @@ public void updateCellInfo() { 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, LACATION_MODE, ICLocation.NORMAL_MOD)); - runtime.getLocationInstance().setLocation_cycle(SharPreferenceUtil.getPrefInt((runtime.getContextProxy()).context, LACATION_CYCLE, 15)); +// runtime.getLocationInstance().setLocation_cycle(SharPreferenceUtil.getPrefInt((runtime.getContextProxy()).context, LACATION_CYCLE, 3)); +// runtime.getLocationInstance().setLocation_cycle(15); } else { //否则设置一个默认值 SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, "value_setting_ver", Config.value_setting); SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, LACATION_MODE, ICLocation.NORMAL_MOD); - SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, LACATION_CYCLE, 15); +// SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, LACATION_CYCLE, 3); runtime.getLocationInstance().setWorkingMod(ICLocation.NORMAL_MOD); - runtime.getLocationInstance().setLocation_cycle(15); +// 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("LACATION_MODE="); - stringBuilder.append(SharPreferenceUtil.getPrefInt((runtime.getContextProxy()).context, LACATION_MODE, 2)); + stringBuilder.append(SharPreferenceUtil.getPrefInt((runtime.getContextProxy()).context, LACATION_MODE, 1)); stringBuilder.append("LACATION_CYCLE="); stringBuilder.append(SharPreferenceUtil.getPrefInt((runtime.getContextProxy()).context, LACATION_CYCLE, 3)); Logger.i(stringBuilder.toString()); @@ -806,37 +836,46 @@ public void updateCellInfo() { (runtime.getContextProxy()).context.registerReceiver(this.screenOnReceiver, intentFilter); /*启动 阻塞队列buffer 发送县城,随时准备发送buffer的message*/ - (new MyThread2(this.mCondition, this.mLock)).start(); - +// if (mythread2 == null) +// mythread2 = new MyThread2(this.mCondition, this.mLock); +// mythread2.exitthread=false; +// mythread2.start(); this.haveChanegTo4GTime = SystemClock.elapsedRealtime(); } public void stop() { +// mythread2.exitthread=true; +// if (mythread2 != null){ +//// triggerSendThread(); +//// mythread2.stop(); +// mythread2=null; +// } (runtime.getContextProxy()).context.unregisterReceiver(this.screenOnReceiver); // this.executor.execute(new Runnable() { // public void run() { LocationClient.AP16Queue(); } // }); this.gSensorListener.stopListen(); + mLbsHelper.unRegisterBroadReceiver(); stopGpsLocate(); } static class MyThread2 extends Thread { -// Condition condition; -// -// boolean isResent = false; -// -// ReentrantLock lock; + Condition condition; + + boolean isResent = false; + public boolean exitthread=false; + ReentrantLock lock; public MyThread2(Condition param1Condition, ReentrantLock param1ReentrantLock) { -// this.condition = param1Condition; -// this.lock = param1ReentrantLock; + this.condition = param1Condition; + this.lock = param1ReentrantLock; } public void run() { StringMessage stringMessage = null; - while (true) { + while (!exitthread) { //循环发送queue 中的数据 @@ -849,47 +888,59 @@ public void updateCellInfo() { if (runtime.getSignalStrength() + 110 < LocationClient.getMinSignalStrength(SimSignalUtil.getInstance((runtime.getContextProxy()).context).getNetworkType())) { Logger.i("Skip Send for SignalStrengh "+(runtime.getSignalStrength() + 110 )+" < "+LocationClient.getMinSignalStrength(SimSignalUtil.getInstance((runtime.getContextProxy()).context).getNetworkType())); //如果信号不好,把msg放回去 + LocationClient.queue.putFirst(stringMessage1); } else { - stringMessage=stringMessage1; - - Context context = (runtime.getContextProxy()).context; - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("send="); - stringBuilder.append(stringMessage.cmd()); - stringBuilder.append(", "); - stringBuilder.append(stringMessage.isFromCache()); - FileOutputUtil.fileOutput(context, "MessageInfo", stringBuilder.toString()); - Logger.i(stringBuilder.toString()); - - connection.send(stringMessage); - -// this.lock.lock(); -// LocationClient.linkOK=false; -// try { -// if (KeepAlive.isConnected) { -// //如果 服务器连接状态,等30秒 -// Logger.i("KeepAlive.isConnected "+KeepAlive.isConnected+" delay 30000ms"); -// this.condition.await(30000L, TimeUnit.MILLISECONDS); -// } else { -// //如果服务器断开,等5秒 以便连接后尽快响应 - Logger.i("KeepAlive.isConnected "+KeepAlive.isConnected+ " , connection isconnected "+connection.isServerConnected()+" delay 1000ms"); - Thread.sleep(1000); -// this.condition.await(1000L, TimeUnit.MILLISECONDS); -// } -// if (linkOK) { -// if (stringMessage.all() != null && stringMessage.all()[0].equals("AP16")) { -// this.isResent = false; -// Logger.i( " AP16 need wait for wifi scan list"); -// Deliver.releaseWakeLockForGetWifiList(); -// } - -// -// } finally { -// this.lock.unlock(); -// } + stringMessage=stringMessage1; + + Context context = (runtime.getContextProxy()).context; + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("send="); + stringBuilder.append(stringMessage.cmd()); + stringBuilder.append(", "); + stringBuilder.append(stringMessage.isFromCache()); + FileOutputUtil.fileOutput(context, "MessageInfo", stringBuilder.toString()); + Logger.i(stringBuilder.toString()); + if( connection.isServerConnected() ==false && !KeepAlive.isConnected ) { + + Logger.i("Skip Send for connection and KeepAlive both false "); + //发现连接断开则重试连接 + protocolMainServer.getInstance().startConnectionRetryTimer(); + //连接断开就把msg放回队列,以便重发 + LocationClient.queue.putFirst(stringMessage1); + }else{ + //连接状态都正常才发送包 + connection.send(stringMessage); + } + + + this.lock.lock(); + LocationClient.linkOK=false; + try { + if (KeepAlive.isConnected) { + //如果 服务器连接状态,等30秒 + Logger.i("KeepAlive.isConnected "+KeepAlive.isConnected+" delay 30000ms"); + this.condition.await(30000L, TimeUnit.MILLISECONDS); + } else { + //如果服务器断开,等5秒 以便连接后尽快响应 + Logger.i("KeepAlive.isConnected "+KeepAlive.isConnected+ " , connection isconnected "+connection.isServerConnected()+" delay 5000ms"); + + this.condition.await(5000L, TimeUnit.MILLISECONDS); + } + if (linkOK) { + if (stringMessage.all() != null && stringMessage.all()[0].equals("AP16")) { + this.isResent = false; + Logger.i( " AP16 need wait for wifi scan list"); + Deliver.releaseWakeLockForGetWifiList(); + } + } + } catch (InterruptedException e) { + e.printStackTrace(); + }finally{ + this.lock.unlock(); + } } } catch (Exception e) { e.printStackTrace(); diff --git a/app/src/main/java/com/ic/protocol/MainActivity.java b/app/src/main/java/com/ic/protocol/MainActivity.java index 66256efa..a9e924e7 100644 --- a/app/src/main/java/com/ic/protocol/MainActivity.java +++ b/app/src/main/java/com/ic/protocol/MainActivity.java @@ -1,6 +1,9 @@ package com.ic.protocol; +import android.content.Context; import android.content.Intent; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; @@ -60,9 +63,32 @@ public class MainActivity extends AppCompatActivity { }; new Timer().schedule(tmt,0,2000); + TextView tv_version=(TextView)findViewById(R.id.textViewVersion); + tv_version.setText( getVersionName(this)); } + /** + * 得到当前应用版本名称的方法 + * + * @param context + * :上下文 + * @throws Exception + */ + public static String getVersionName(Context context) { + // 获取packagemanager的实例 + PackageManager packageManager = context.getPackageManager(); + // getPackageName()是你当前类的包名 + PackageInfo packInfo = null; + String version="V001"; + try { + packInfo = packageManager.getPackageInfo(context.getPackageName(), 0); + version = packInfo.versionName; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + return version; + } private View.OnClickListener clickListener = new View.OnClickListener() { 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 882e61b3..a8662907 100644 --- a/app/src/main/java/com/ic/protocol/adapter/LBSHelper.java +++ b/app/src/main/java/com/ic/protocol/adapter/LBSHelper.java @@ -218,7 +218,7 @@ public class LBSHelper { }, 10000L); } - private void unRegisterBroadReceiver() { + public void unRegisterBroadReceiver() { this.context.unregisterReceiver(this.wifiChangedReceiver); } 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 ae3be19f..9076835d 100644 --- a/app/src/main/java/com/ic/protocol/adapter/protocolAPIHelper.java +++ b/app/src/main/java/com/ic/protocol/adapter/protocolAPIHelper.java @@ -8,7 +8,6 @@ import com.ic.protocol.bean.Runtime; import com.ic.protocol.bean.StringMessage; import com.ic.protocol.utils.Connection; import com.ic.protocol.utils.Logger; -import com.ic.protocol.utils.ServiceUtil; import com.ic.protocol.utils.SharPreferenceUtil; import java.util.HashMap; @@ -358,7 +357,7 @@ public class protocolAPIHelper { String replacement=new StringBuilder("IWBP85,").append(imei).append(",").toString(); String replycmd = cmd.replace(replacement,""); Logger.i("gen reply "+replacement+" "+replycmd); - ServiceUtil.offerQueue(genStringMessage("AP85",AP85(runtime,replycmd))); + connection.send(genStringMessage("AP85",AP85(runtime,replycmd))); } @@ -397,17 +396,20 @@ public class protocolAPIHelper { Cycle=60; break; case ICLocation.EMERGNECY_MOD: + case ICLocation.REALTIME_MOD: Cycle=1; break; + } String msg=AP33(cmdlist[2],mod); //设定当前工作模式及循环频率 - ServiceUtil.offerQueue(genStringMessage("AP33",msg)); + connection.send(genStringMessage("AP33",msg)); log("reply msg "+msg); + log("LACATION_MODE "+LACATION_MODE+" mod "+ mod); SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, "value_setting_ver", Config.value_setting); SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, LACATION_MODE, mod); - SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, LACATION_CYCLE, Cycle); +// SharPreferenceUtil.setPrefInt((runtime.getContextProxy()).context, LACATION_CYCLE, Cycle); runtime.getLocationInstance().setWorkingMod(mod); runtime.getLocationInstance().setLocation_cycle(Cycle); @@ -446,7 +448,7 @@ public class protocolAPIHelper { if(cmdlist.length==3){ log("imei "+cmdlist[1]+", cmdindex "+cmdlist[2]); - ServiceUtil.offerQueue(genStringMessage("AP16",AP16(cmdlist[2]))); + connection.send(genStringMessage("AP16",AP16(cmdlist[2]))); }else{ log("error BP16 format"); } diff --git a/app/src/main/java/com/ic/protocol/bean/Config.java b/app/src/main/java/com/ic/protocol/bean/Config.java deleted file mode 100644 index ee394142..00000000 --- a/app/src/main/java/com/ic/protocol/bean/Config.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.ic.protocol.bean; - -public class Config { - private String ServerIP="118.178.155.223"; - private int ServerPort=8090; - private String ServerHostname="watch.jiai.pro"; - - - public String getServerIP(){ - return ServerIP; - } - public int getServerPort(){ - return ServerPort; - } - public String getServerHostname(){ - return ServerHostname; - } - -} diff --git a/app/src/main/java/com/ic/protocol/bean/ICLocation.java b/app/src/main/java/com/ic/protocol/bean/ICLocation.java index ef9f8587..46d487dd 100644 --- a/app/src/main/java/com/ic/protocol/bean/ICLocation.java +++ b/app/src/main/java/com/ic/protocol/bean/ICLocation.java @@ -32,6 +32,7 @@ public class ICLocation { public static final int NORMAL_MOD=1; //location rate 1 time per 15 minutes public static final int LOWPOWER_MOD=2; // location rate 1 time per hour public static final int EMERGNECY_MOD=3; //location rate 1 time per minutes + public static final int REALTIME_MOD=4; //location rate 1 time per minutes private int mworkingMod; diff --git a/app/src/main/java/com/ic/protocol/service/CheckSIM.java b/app/src/main/java/com/ic/protocol/service/CheckSIM.java index 3742c753..ba14d439 100644 --- a/app/src/main/java/com/ic/protocol/service/CheckSIM.java +++ b/app/src/main/java/com/ic/protocol/service/CheckSIM.java @@ -96,7 +96,10 @@ public class CheckSIM extends AbstractConnectionService { public boolean onConnectionOpen(Connection paramConnection, Runtime paramRuntime) { return false; } - public void onDetach(Connection paramConnection, Runtime paramRuntime) {} + public void onDetach(Connection paramConnection, Runtime paramRuntime) { + + (paramRuntime.getContextProxy()).context.unregisterReceiver(this.SimStateReceive); + } public boolean onReceive(StringMessage paramStringMessage, Connection paramConnection, Runtime paramRuntime) { return false; } } 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 bf4540ba..cbcc6f75 100644 --- a/app/src/main/java/com/ic/protocol/service/KeepAlive.java +++ b/app/src/main/java/com/ic/protocol/service/KeepAlive.java @@ -244,6 +244,7 @@ public class KeepAlive extends AbstractConnectionService { } public boolean onConnectionClose(Connection paramConnection, Runtime paramRuntime) { + if (isConnected) protocolMainServer.getInstance().startConnectionRetryTimer(); connectionError = true; isConnected = false; paramRuntime.getContextProxy().sendBroadcast(isConnected); @@ -265,8 +266,8 @@ public class KeepAlive extends AbstractConnectionService { Logger.i(stringBuilder.toString()); // if (!connectionError) { connectionError = false; - ServiceUtil.offerQueue(protocolAPIHelper.genStringMessage("AP00",protocolAPIHelper.AP00(paramRuntime)),true); - ServiceUtil.offerQueue(protocolAPIHelper.genStringMessage("heart",protocolAPIHelper.AP03(paramRuntime))); + 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; @@ -293,8 +294,8 @@ public class KeepAlive extends AbstractConnectionService { Logger.i("onHeartAlarm"); // UpdateHeartBeatTimeout(); // if (this.reCycleTimes == 0 && this.currentReConnectInterval != 11){ - ServiceUtil.offerQueue(protocolAPIHelper.genStringMessage("AP00",protocolAPIHelper.AP00(paramRuntime)),true); - ServiceUtil.offerQueue(protocolAPIHelper.genStringMessage("heart",protocolAPIHelper.AP03(paramRuntime))); + paramNettyConnection.send(protocolAPIHelper.genStringMessage("AP00",protocolAPIHelper.AP00(paramRuntime))); + paramNettyConnection.send(protocolAPIHelper.genStringMessage("heart",protocolAPIHelper.AP03(paramRuntime))); // } } diff --git a/app/src/main/java/com/ic/protocol/service/connectionServer.java b/app/src/main/java/com/ic/protocol/service/connectionServer.java deleted file mode 100644 index d32a705d..00000000 --- a/app/src/main/java/com/ic/protocol/service/connectionServer.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.ic.protocol.service; - -import com.ic.protocol.bean.StringMessage; -import com.ic.protocol.utils.Connection; - -public class connectionServer implements Connection { - @Override - public void close() { - - } - - @Override - public void connect(String paramString, int paramInt) { - - } - - @Override - public void disconnect() { - - } - - @Override - public int getTimeout() { - return 0; - } - - @Override - public void open() { - - } - - @Override - public void send(StringMessage paramStringMessage) { - - } - - @Override - public boolean sendBlocking(StringMessage paramStringMessage) { - return false; - } - - @Override - public void setTimeout(int paramInt) { - - } -} 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 921d3e09..4b5ac7b5 100644 --- a/app/src/main/java/com/ic/protocol/service/protocolMainServer.java +++ b/app/src/main/java/com/ic/protocol/service/protocolMainServer.java @@ -22,8 +22,6 @@ import com.ic.protocol.Constants; import com.ic.protocol.LocationClient; import com.ic.protocol.adapter.LBSHelper; import com.ic.protocol.adapter.protocolAPIHelper; -import com.ic.protocol.bean.Config; -import com.ic.protocol.bean.ICLocation; import com.ic.protocol.bean.Runtime; import com.ic.protocol.bean.StringMessage; import com.ic.protocol.service.base.AbstractConnectionService; @@ -37,7 +35,6 @@ import com.ic.protocol.utils.DBHelper; import com.ic.protocol.utils.FileOutputUtil; import com.ic.protocol.utils.Logger; import com.ic.protocol.utils.NettyConnection; -import com.ic.protocol.utils.ServiceUtil; import com.ic.protocol.utils.SharPreferenceUtil; import com.ic.protocol.utils.SimSignalUtil; import com.ic.protocol.utils.Util; @@ -60,6 +57,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_LOCATION_ALARM; import static com.ic.protocol.Constants.HEART_ALARM; import static com.ic.protocol.Constants.SLEEP_ALARM; import static com.ic.protocol.Constants.WAKE_ALARM; @@ -95,7 +93,7 @@ public class protocolMainServer extends Service { public String getServerAlive(){ return new StringBuilder().append("Connecttion status is ").append(this.connection.isServerConnected()) .append("\n KeepAlive ").append(KeepAlive.isConnected) - .append( "\n cmd Queue size ").append(LocationClient.queue.size()) + .append( "\n Working Mode ").append(runtime.getLocationInstance().getWorkingMod()).append(" queue size ").append(LocationClient.queue.size()) .append("\n AP01 = ").append(protocolAPIHelper.AP01(runtime)) .toString(); } @@ -140,8 +138,9 @@ public class protocolMainServer extends Service { Logger.i(stringBuilder1.toString()); protocolMainServer.this.setSleepAlarm(); protocolMainServer.this.setWakeAlarm(); - protocolMainServer.this.setHeartAlarm(); + protocolMainServer.this.setHeartAlarm(runtime.getLocationInstance().getWorkingMod()); protocolMainServer.this.setWeatherAlarm(); + protocolMainServer.this.setLocationAlarm(); if (protocolMainServer.this.cmcm_call_eiot_into_powersave_mode() == 0) AlarmWakeUp.isNeedWakeUpAlarm(protocolMainServer.this.runtime); } @@ -156,7 +155,9 @@ public class protocolMainServer extends Service { protocolMainServer coreService = (protocolMainServer)this.mReference.get(); if (coreService == null) return; - Logger.i("onConnectionClose++"); + Logger.i("onConnectionClose++ retry to connect again!"); + +// startConnectionRetryTimer(); String ip=Util.parseHostGetIPAddress(coreService.runtime.getHost()); if ( ip !=null && ! ip.equals(coreService.runtime.getSrvIP())){ Logger.i("HostName "+coreService.runtime.getHost()+ " IP changed from "+coreService.runtime.getSrvIP()+" to "+ip); @@ -174,8 +175,9 @@ public class protocolMainServer extends Service { } public void onReceive(StringMessage param1StringMessage) { - Logger.i("onReceive " +param1StringMessage.cmd()); + protocolMainServer coreService = (protocolMainServer)this.mReference.get(); + Logger.i("onReceive " +param1StringMessage.cmd() +" coreService " + coreService ); if (coreService == null) return; coreService.connectionServiceChain.processServerResponse(param1StringMessage, coreService.connection, coreService.runtime); @@ -386,8 +388,12 @@ public class protocolMainServer extends Service { public IBinder onBind(Intent paramIntent) { return this.mMessenger.getBinder(); } - public void onCreateCore() { + @Override + public void onCreate() { Logger.i("CoreService--onCreate002"); + log("开始监听网络协议状态"); + mProtocolServer=this; + this.runtime = new Runtime(); this.runtime.setFileDir(getFilesDir()); this.runtime.setCacheDir(getExternalCacheDir()); @@ -428,8 +434,9 @@ public class protocolMainServer extends Service { setCleanStepCountAlarm(); setSleepAlarm(); setWakeAlarm(); - setHeartAlarm(); + setHeartAlarm(runtime.getLocationInstance().getWorkingMod()); setWeatherAlarm(); + setLocationAlarm(); getDBFile(); } @@ -460,6 +467,7 @@ public class protocolMainServer extends Service { if (!screenon) { send_at_to_update_lbs(); } + //这里就是为了省电,如果wifi开启,且屏幕关闭,则wifi也关闭 if (Util.isConnectWifi((this.runtime.getContextProxy()).context) && !screenon) { is_wifi_network_ok = true; Util.turnOffWifiForSleep((this.runtime.getContextProxy()).context, this.runtime); @@ -512,8 +520,8 @@ public class protocolMainServer extends Service { if (HEART_ALARM.equals(paramIntent.getAction())) { if (this.mKeepAlive != null) { this.mKeepAlive.onHeartAlarm(this.connection, this.runtime); - setHeartAlarm(); - FileOutputUtil.fileOutput(this, "alarmCycle", "HEART_ALARM alarmCycle"); + setHeartAlarm(runtime.getLocationInstance().getWorkingMod()); + FileOutputUtil.fileOutput(this, "alarmCycle", "HEART_ALARM alarmCycle " +runtime.getLocationInstance().getWorkingMod()); return Service.START_STICKY; } } else { @@ -542,6 +550,16 @@ public class protocolMainServer extends Service { FileOutputUtil.fileOutput(this, "alarmCycle", stringBuilder1.toString()); return Service.START_STICKY; } + if (ACTION_LOCATION_ALARM.equals(paramIntent.getAction())){ + setLocationAlarm(); + stringBuilder1 = new StringBuilder(); + stringBuilder1.append("LOCATION_ALARM alarmCycle="); + stringBuilder1.append(alarmCycle); + FileOutputUtil.fileOutput(this, "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")); @@ -591,23 +609,57 @@ public class protocolMainServer extends Service { //每一分钟设置一次 public void setAlarm(int paramInt) { - AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,1,ACTION_ALARM); + AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,paramInt,ACTION_ALARM); + } + + public void setLocationAlarm() { + int mod=runtime.getLocationInstance().getWorkingMod(); + StringBuilder sb=new StringBuilder(); + switch(mod){ + case EMERGNECY_MOD: + case REALTIME_MOD: + AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,1, ACTION_LOCATION_ALARM); + sb.append(" setLocationAlarm "+ACTION_LOCATION_ALARM+" Mode "+mod+", cycle 1"); + break; + case NORMAL_MOD: + AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,15, ACTION_LOCATION_ALARM); + sb.append(" setLocationAlarm "+ACTION_LOCATION_ALARM+" Mode "+mod+", cycle 15"); + + break; + case LOWPOWER_MOD: + AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,60, ACTION_LOCATION_ALARM); + sb.append(" setLocationAlarm "+ACTION_LOCATION_ALARM+" Mode "+mod+", cycle 60"); + break; + } + locationClient.triggerLocationProcess(); + Logger.i(sb.toString()); + FileOutputUtil.fileOutput(runtime.getContextProxy().context,"LocationAlarm",sb.toString()); } - public void setHeartAlarm() { - switch(runtime.getLocationInstance().getWorkingMod()){ + public void setHeartAlarm(int mod){ +// int mod=runtime.getLocationInstance().getWorkingMod(); + StringBuilder sb=new StringBuilder(); + int cycle=1; + switch(mod){ case EMERGNECY_MOD: - AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,1, HEART_ALARM); + case REALTIME_MOD: + cycle=1; break; case NORMAL_MOD: - AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,15, HEART_ALARM); + cycle=15; break; case LOWPOWER_MOD: - AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,60, HEART_ALARM); + cycle=60; break; } + AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,cycle, HEART_ALARM); + sb.append(" setHeartAlarm "+HEART_ALARM+" mod "+mod+", cycle "+cycle); + locationClient.triggerLocationProcess(); + Logger.i(sb.toString()); + FileOutputUtil.fileOutput(runtime.getContextProxy().context,"HeartAlarm",sb.toString()); +// AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context,1, HEART_ALARM); } public void setUpLocationDataAlarm(long paramLong) { @@ -659,9 +711,9 @@ public class protocolMainServer extends Service { private static boolean mLowPowerMode = false; private static boolean mCallStateIsIdle = true; // 非通话活动 private TelephonyManager telManager; - private Timer mTimer_keepalive=null; + private Timer mTimer_retry_connect=null; private WifiManager mWifiManager=null; - private Config mConfig=null; + private static Runtime mDevStat=null; // private protocolAPIHelper mProtocolAPI=null; @@ -675,132 +727,86 @@ public class protocolMainServer extends Service { } - @Override - public void onCreate() { - - log("开始监听网络协议状态"); - -// IntentFilter intentFilter = new IntentFilter(); -// intentFilter.addAction(Intent.ACTION_BATTERY_LOW); // 低电量提示 -// intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); // 低电量变化 -// intentFilter.addAction(Intent.ACTION_MANAGE_NETWORK_USAGE); -// try { -//// registerReceiver(mIntentReceiver, intentFilter); -// } catch (Exception ignored) { -// } - - -// telManager = (TelephonyManager) getApplicationContext().getSystemService(Service.TELEPHONY_SERVICE); -// assert telManager != null; -// telManager.listen(mCallStateListener, PhoneStateListener.LISTEN_CALL_STATE); - - -// init_protocols(); - -// startTimer(); - mProtocolServer=this; - - onCreateCore(); - super.onCreate(); - } +// @Override +// public void onCreate() { +// +// log("开始监听网络协议状态"); +// +//// IntentFilter intentFilter = new IntentFilter(); +//// intentFilter.addAction(Intent.ACTION_BATTERY_LOW); // 低电量提示 +//// intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED); // 低电量变化 +//// intentFilter.addAction(Intent.ACTION_MANAGE_NETWORK_USAGE); +//// try { +////// registerReceiver(mIntentReceiver, intentFilter); +//// } catch (Exception ignored) { +//// } +// +// +//// telManager = (TelephonyManager) getApplicationContext().getSystemService(Service.TELEPHONY_SERVICE); +//// assert telManager != null; +//// telManager.listen(mCallStateListener, PhoneStateListener.LISTEN_CALL_STATE); +// +// +//// init_protocols(); +// +//// startTimer(); +// mProtocolServer=this; +// +// onCreateCore(); +// super.onCreate(); +// } public static protocolMainServer getInstance(){ return mProtocolServer; } - private void init_protocols(){ +// private void init_protocols(){ +// +// if (mDevStat == null) { +// mDevStat =new Runtime(); +// log("new mDevStat"); +// } +//// if (mProtocolAPI == null) mProtocolAPI = new protocolAPIHelper(); +// if (mWifiManager == null) mWifiManager = (WifiManager)this.getApplicationContext().getSystemService(Context.WIFI_SERVICE); +// if (lbshelper==null) lbshelper = new LBSHelper(this,mWifiManager,mDevStat); +// +// toast = new Toastc(this, Toast.LENGTH_SHORT); +// +// } - if (mConfig == null) mConfig = new Config(); - if (mDevStat == null) { - mDevStat =new Runtime(); - log("new mDevStat"); + public void startConnectionRetryTimer(){ + if (mTimer_retry_connect == null) { + mTimer_retry_connect = new Timer(); } -// if (mProtocolAPI == null) mProtocolAPI = new protocolAPIHelper(); - if (mWifiManager == null) mWifiManager = (WifiManager)this.getApplicationContext().getSystemService(Context.WIFI_SERVICE); - if (lbshelper==null) lbshelper = new LBSHelper(this,mWifiManager,mDevStat); - - toast = new Toastc(this, Toast.LENGTH_SHORT); - - } - private void startTimer(){ - if (mTimer_keepalive == null) { - mTimer_keepalive = new Timer(); - } + //如果开始进行连接重试,证明网络断开的,那么KeepAlive也需要重连(心跳包) - if (mTimer_keepalive !=null){ - mTimer_keepalive.schedule(new TimerTask() { + KeepAlive.isConnected=false; + if (mTimer_retry_connect !=null){ + mTimer_retry_connect.schedule(new TimerTask() { @Override public void run() { do_timer_task(); } - },0,20000); + },0,5000); //每5秒重试一次 } } - public class WifiInfolistener implements LBSHelper.OnWiFiInfoListener { - - @Override - public void getWifiInfoCallBack(String aplist) { - - if (aplist !=null && aplist!="null") { - log("getWifiInfoCallBack " + aplist); - mDevStat.setWifiinfo(aplist); -// String[] list = var1.split("\\+"); -// for (String p : list){ -// String[] lp=p.split("@"); -// if (lp.length>=2) -// { -// mDevStat.getLocationInstance().append_wifiap(lp[0].replace(":","-"),Integer.valueOf(lp[1])); -// }else{ -// log("error format"); -// } -// } - } - else { - log("getWifiInfoCallBack wifi end"); - mDevStat.setWifiinfo(""); - } - } - } public void do_timer_task(){ -// boolean needlogin=true; -// if(!isServerConnected()) { -// connectServer(); -// needlogin=true; -// } -// if( needlogin){ -// log("do_timer_task send cmd "+ mProtocolAPI.AP00(mDevStat)); -//// Handler callbackHandler=new Handler(); -// String serverip = parseHostGetIPAddress(mConfig.getServerHostname()); -// log("getip "+mConfig.getServerHostname()+" "+serverip); -//// mConfig.setServerIP(serverip); -//// mConfig.setServerPort(8090); -// sendMsg(mProtocolAPI.AP00(mDevStat)); -// -// -// } -// log("do_timer_task send cmd "+ mProtocolAPI.AP03(mDevStat)); -// sendMsg(mProtocolAPI.AP03(mDevStat)); -// -// lbshelper.setOnWiFiInfoListener(new WifiInfolistener()); -// lbshelper.getWifiInfo(); -// lbshelper.getCellInfo(this.telManager); -// -// log("do_timer_task send cmd "+ mProtocolAPI.AP01(mDevStat)); -// -// sendMsg(mProtocolAPI.AP01(mDevStat)); - } + this.connection.connect(this.runtime.getSrvIP(), this.runtime.getPort()); - public void testGpsData(){ -// mProtocolAPI.AP01(mDevStat); -// log( mProtocolAPI.AP01(mDevStat)); + //里面如果连接成功 connectionOpen 会先发送 AP00 登录包 和发送AP03 心跳包 ,都成功则停止重试 + if (connection.isServerConnected() && KeepAlive.isConnected) + { + stopConnectionRetryTimer(); + } } - private void stopTimer(){ - if (mTimer_keepalive !=null){ - mTimer_keepalive.cancel(); - mTimer_keepalive = null; + + public void stopConnectionRetryTimer(){ + if (mTimer_retry_connect !=null){ + mTimer_retry_connect.cancel(); + mTimer_retry_connect = null; } } @@ -824,6 +830,8 @@ public class protocolMainServer extends Service { unregisterReceiver(this.broadcastReceiver); unregisterReceiver(this.screenOnReceiver); unregisterReceiver(this.AtCallbackBroadcastReceiver); + batteryUtil.unregisterBroadReceiver(); + } private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { diff --git a/app/src/main/java/com/ic/protocol/utils/AlarmHelper.java b/app/src/main/java/com/ic/protocol/utils/AlarmHelper.java index 9b7ac59a..5067a6f1 100644 --- a/app/src/main/java/com/ic/protocol/utils/AlarmHelper.java +++ b/app/src/main/java/com/ic/protocol/utils/AlarmHelper.java @@ -48,6 +48,7 @@ public class AlarmHelper { public static void setAlarm(AlarmManager paramAlarmManager, long paramLong, PendingIntent paramPendingIntent) { setAlarm(paramAlarmManager, paramLong, 604800000L, paramPendingIntent); +// setAlarm(paramAlarmManager, paramLong, 0, paramPendingIntent); } public static void setCleanStepCountAlarm(Context context, int hour, int minutes, String paramString) { 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 b1019c3a..17023170 100644 --- a/app/src/main/java/com/ic/protocol/utils/CellInfoUtil.java +++ b/app/src/main/java/com/ic/protocol/utils/CellInfoUtil.java @@ -37,11 +37,17 @@ public class CellInfoUtil { if (param1Message.what != 100) return; Logger.i("延时获取基站信息"); -// CellInfoUtil.access$010(); + CellInfoUtil.setCurrentAttachCellInfo(mRuntime, mWakeLock); + + } }; - + + + public static void triggerUpdateCellinfo(){ + mHandler.sendEmptyMessageDelayed(100,2000); + } private static Runtime mRuntime; private static PowerManager.WakeLock mWakeLock; @@ -70,63 +76,73 @@ public class CellInfoUtil { mRuntime = dev; (new Thread(new Runnable() { public void run() { - CellInfoUtil.mCellInfo=mRuntime.getLbsHelper().getAttchCellInfo(mRuntime.getContextProxy().getTelephonyManager()); - if (mCellInfo != null) { - String str1 = mRuntime.getCdmaInfo(); - String str2 = mRuntime.getMccAndMnc(); - if (str1 != null) { - String[] arrayOfString2 = str2.split("@"); - String[] arrayOfString1 = str1.split(","); - CellInfoUtil.MCC = Integer.parseInt(arrayOfString2[0]); - CellInfoUtil.MNC = Integer.parseInt(arrayOfString2[1]); - int i = Integer.parseInt(arrayOfString1[0]); - int j = Integer.parseInt(arrayOfString1[1]); - int k = Integer.parseInt(arrayOfString1[2]); - CellInfoUtil.BSSS = Integer.parseInt(arrayOfString1[5]); + + if (mRuntime !=null) { + CellInfoUtil.mCellInfo = mRuntime.getLbsHelper().getAttchCellInfo(mRuntime.getContextProxy().getTelephonyManager()); + + if (mCellInfo != null) { + String str1 = mRuntime.getCdmaInfo(); + String str2 = mRuntime.getMccAndMnc(); + if (str1 != null) { + String[] arrayOfString2 = str2.split("@"); + String[] arrayOfString1 = str1.split(","); + CellInfoUtil.MCC = Integer.parseInt(arrayOfString2[0]); + CellInfoUtil.MNC = Integer.parseInt(arrayOfString2[1]); + int i = Integer.parseInt(arrayOfString1[0]); + int j = Integer.parseInt(arrayOfString1[1]); + int k = Integer.parseInt(arrayOfString1[2]); + CellInfoUtil.BSSS = Integer.parseInt(arrayOfString1[5]); // EqcAlgorithmNative.native_EqcAlgorithmMethod4(3, j, CellInfoUtil.BSSS, CellInfoUtil.MCC, CellInfoUtil.MNC, i, k); - CellInfoUtil.releaseWakeLock(mWakeLock); - } else { - String[] arrayOfString = mCellInfo.split("\\+")[0].split("@"); - CellInfoUtil.MCC = Integer.parseInt(arrayOfString[0]); - CellInfoUtil.MNC = Integer.parseInt(arrayOfString[1]); - CellInfoUtil.LAC = Integer.parseInt(arrayOfString[2]); - CellInfoUtil.CELL_ID = Integer.parseInt(arrayOfString[3]); - CellInfoUtil.BSSS = Integer.parseInt(arrayOfString[4]); + CellInfoUtil.releaseWakeLock(mWakeLock); + } else { + String[] arrayOfString = mCellInfo.split("\\+")[0].split("@"); + CellInfoUtil.MCC = Integer.parseInt(arrayOfString[0]); + CellInfoUtil.MNC = Integer.parseInt(arrayOfString[1]); + CellInfoUtil.LAC = Integer.parseInt(arrayOfString[2]); + CellInfoUtil.CELL_ID = Integer.parseInt(arrayOfString[3]); + CellInfoUtil.BSSS = Integer.parseInt(arrayOfString[4]); // CellInfoUtil.access$002(2); - CellInfoUtil.IS2SECOND=2; + CellInfoUtil.IS2SECOND = 2; // 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); - CellInfoUtil.releaseWakeLock(mWakeLock); - return; - } - if (IS2SECOND <= 0) { - CellInfoUtil.MCC = 0; - CellInfoUtil.MNC = 0; - CellInfoUtil.LAC = 0; - CellInfoUtil.CELL_ID = -1; - CellInfoUtil.BSSS = 0; + mRuntime.cellinfo = mCellInfo; + } + FileOutputUtil.fileOutput((mRuntime.getContextProxy()).context, "onCellLocationChanged", mCellInfo); + CellInfoUtil.releaseWakeLock(mWakeLock); + Logger.i(" setCurrentAttachCellInfo " + mCellInfo); + + } + if (IS2SECOND <= 0) { + CellInfoUtil.MCC = 0; + CellInfoUtil.MNC = 0; + CellInfoUtil.LAC = 0; + CellInfoUtil.CELL_ID = -1; + CellInfoUtil.BSSS = 0; // CellInfoUtil.access$002(2); - CellInfoUtil.IS2SECOND=2; - Runtime runtime = mRuntime; - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(CellInfoUtil.MCC); - stringBuilder.append("@"); - stringBuilder.append(CellInfoUtil.MNC); - stringBuilder.append("@"); - stringBuilder.append(CellInfoUtil.LAC); - stringBuilder.append("@"); - stringBuilder.append(CellInfoUtil.CELL_ID); - stringBuilder.append("@"); - stringBuilder.append(CellInfoUtil.BSSS); - runtime.cellinfo = stringBuilder.toString(); + CellInfoUtil.IS2SECOND = 2; + Runtime runtime = mRuntime; + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(CellInfoUtil.MCC); + stringBuilder.append("@"); + stringBuilder.append(CellInfoUtil.MNC); + stringBuilder.append("@"); + stringBuilder.append(CellInfoUtil.LAC); + stringBuilder.append("@"); + stringBuilder.append(CellInfoUtil.CELL_ID); + stringBuilder.append("@"); + 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); - CellInfoUtil.releaseWakeLock(mWakeLock); - return; - } - CellInfoUtil.mHandler.sendEmptyMessageDelayed(100, 2000L); + FileOutputUtil.fileOutput((mRuntime.getContextProxy()).context, "onCellLocationChanged", mRuntime.cellinfo); + CellInfoUtil.releaseWakeLock(mWakeLock); + Logger.i(" setCurrentAttachCellInfo " + mCellInfo); + + } + mRuntime.getLocationInstance().setMNC(String.valueOf(CellInfoUtil.getMNC())); + mRuntime.getLocationInstance().setCID(CellInfoUtil.getCELL_ID()); + mRuntime.getLocationInstance().setMCC(String.valueOf(CellInfoUtil.getMCC())); + mRuntime.getLocationInstance().setLAC(CellInfoUtil.getLAC()); + mRuntime.preCellInfo = CellInfoUtil.getCellInfo(); + } } })).start(); } 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 7b140af2..51cc5d5c 100644 --- a/app/src/main/java/com/ic/protocol/utils/NettyConnection.java +++ b/app/src/main/java/com/ic/protocol/utils/NettyConnection.java @@ -1,8 +1,10 @@ package com.ic.protocol.utils; +import android.content.Intent; import android.os.SystemClock; +import com.ic.protocol.LocationClient; import com.ic.protocol.adapter.protocolAPIHelper; import com.ic.protocol.bean.StringMessage; @@ -39,7 +41,7 @@ public class NettyConnection implements Connection { public boolean handleCmd(protocolAPIHelper.CMD_TYPE type, String cmd) { boolean ret=true; - + Logger.i("handleCmd "+type.name() +" , cmd "+cmd); switch (type){ case BP00: API.handleBP00(cmd); @@ -73,9 +75,9 @@ public class NettyConnection implements Connection { break; case BP33: //设置工作模式 - API.handleBP33(NettyConnection.this,null,cmd); - DeliverCMDMessageToSystem("AP33",cmd);//通知下面线程状态变化 DeliverCMDMessageToSystem("ResartHeartAlarm",cmd);//通知下面线程状态变化 + DeliverCMDMessageToSystem("AP33",cmd);//通知下面线程状态变化 + API.handleBP33(NettyConnection.this,null,cmd); break; case BP16: @@ -97,7 +99,7 @@ public class NettyConnection implements Connection { } public void close() { - listener =null; +// listener =null; // RxSocket.getInstance().setConnectionListener(null); } @@ -107,7 +109,7 @@ public class NettyConnection implements Connection { return; realtime_old = l; Logger.i("connect1 "+host+":"+port); - disconnect(); +// disconnect(); this.executorService.execute(new Runnable() { public void run() { NettyConnection.this.connectImpl(host, port); @@ -228,7 +230,9 @@ public class NettyConnection implements Connection { }, throwable -> { - log("get Msg throwable"); + log("get Msg throwable " +throwable); + //出现错误恢复读取线程。 + NettyConnection.this.open(); }, ()->{ log("get Msg ()"); diff --git a/app/src/main/java/com/ic/protocol/utils/RxSocket.java b/app/src/main/java/com/ic/protocol/utils/RxSocket.java index 3bade991..b10ef68c 100644 --- a/app/src/main/java/com/ic/protocol/utils/RxSocket.java +++ b/app/src/main/java/com/ic/protocol/utils/RxSocket.java @@ -38,7 +38,7 @@ public class RxSocket { /* 常量 * */ private String TAG = "RxSocket"; - private boolean OpenLog = false; + private boolean OpenLog = true; private long WRITE_TIME_OUT = 3000; private long CONNECT_TIME_OUT = 3000; diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 61aa82cb..cc5f8d7d 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -15,20 +15,36 @@ android:layout_height="match_parent" android:orientation="vertical"> -