添加了移动的判断,如果LBS变了,我们也认为位置改变了,不单纯地以脚步来做判断.
authorTrillGates <williamtrillgates@gmail.com>
Wed, 3 Nov 2021 03:01:15 +0000 (11:01 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Wed, 3 Nov 2021 03:01:15 +0000 (11:01 +0800)
app/src/main/java/com/enqualcomm/support/LocationClient.java
app/src/main/java/com/enqualcomm/support/NMEAListener.java
app/src/main/java/com/enqualcomm/support/bean/ICLocation.java
app/src/main/java/com/enqualcomm/support/bean/Runtime.java
app/src/main/java/com/enqualcomm/support/utils/CellInfoUtil.java

index 93ece6a..34ede47 100644 (file)
@@ -620,8 +620,6 @@ public class LocationClient {
             case ICLocation.CUSTOM_MOD8_GPS:
             case ICLocation.EMERGNECY_MOD:
             case ICLocation.REALTIME_MOD:
-
-
                 //GPS 优先的话多给些时间(10秒)
                 if (checktimes > GPSLocationTimeoutInSeconds) {
                     ICLogger.i("waitAndSendLocation " + checktimes + " timeout");
@@ -677,14 +675,9 @@ public class LocationClient {
                         }
 
                     }
-
-
                     stopCheckLocationResult();
-
-
                     String msg = "Location Fixed Type " + runtime.getLocationInstance().getLocationType() + " at " + runtime.getLocationInstance().getLocationTime() + " timeout " + timeout;
                     ICLogger.i(msg);
-
                     if (responseUrl != null) {
                         if (locationtype.equals("GPS")) {
                             responseUrl.replyCallBack(runtime.getLocationInstance().getLocation().latGPSStr + "," + runtime.getLocationInstance().getLocation().lonGPSStr);
@@ -711,7 +704,6 @@ public class LocationClient {
             case ICLocation.CUSTOM_MOD8_WIFI:
             default:
                 //wifi优先的话给20秒时间
-
                 if (checktimes > WiFiLocationTimeoutInSeconds) {
                     ICLogger.i("waitAndSendLocation " + checktimes + " timeout");
                     timeout = true;
@@ -722,10 +714,7 @@ public class LocationClient {
                     ICLogger.i("waitAndSendLocation " + timeCost + "> 20000ms timeout");
                     // timeout=true;
                 }
-
                 if ((lbs_ok && timeout == true) || (lbs_ok && wifi_ok)) {
-
-
                     String locationtype = "LBS";
                     if (wifi_ok) {
                         locationtype = "WiFi";
@@ -744,20 +733,14 @@ public class LocationClient {
                         StringMessage AP02_CMD = protocolAPIHelper.getLBSLocationMSG(runtime);
                         DeliverMessage(AP02_CMD);
                     }
-
                     stopCheckLocationResult();
-
-
                     String msg = "Location Fixed Type " + runtime.getLocationInstance().getLocationType() + " at " + runtime.getLocationInstance().getLocationTime() + " timeout " + timeout;
                     ICLogger.i(msg);
-
                     if (responseUrl != null) {
                         responseUrl.replyCallBack("Location Fixed Type " + locationtype);
                     }
                     if (Config.LOG_TOFILE)
                         ICLogger.logToFile("GPS", msg);
-
-
                 } else if (timeout == true) {
                     ICLogger.i("timeout no location  ");
                     stopCheckLocationResult();
@@ -911,6 +894,7 @@ public class LocationClient {
      * else return false
      */
     private boolean checkNoMoveTimeoutForBT() {
+
         noMove = ((runtime.getTotalStepCount() - runtime.getLastStepCountForBT()) <= 0);
         runtime.updateFZDDevStatusMoving(!noMove); //设置当前运动状态
         ICLogger.i("BT checkNoMoveTimeout last_noMoveForBT " + last_noMoveForBT + " noMove " + noMove + " lastStepCountForBT " + runtime.getLastStepCountForBT() + " StepCount " + runtime.getTotalStepCount());
@@ -931,11 +915,49 @@ public class LocationClient {
 
     }
 
+    private String lastMCC = "";
+    private String lastMnc = "";
+    private long lastLAC = 0l;
+    private long lastCID = 0l;
+
+    private boolean checkLBS() {
+        //获取LBS上一次的数据,与当前的数据进行对比即可
+        //只要有一个是变化的,那么我们就认为是变化了
+        ICLocation locationInstance = runtime.getLocationInstance();
+        String mcc = locationInstance.getMCC();
+        ICLogger.d("mcc==> " + mcc);
+        String mnc = locationInstance.getMNC();
+        ICLogger.d("mnc==> " + mnc);
+        long lac = locationInstance.getLAC();
+        ICLogger.d("lac==> " + lac);
+        long gsmStationCID = locationInstance.getGSMStationCID();
+        ICLogger.d("gsmStationCID==> " + gsmStationCID);
+        //判断跟上一次的是否一样,如果一样的话就没有变化
+        //如果变了,那么就返回true
+        ICLogger.d("last ==> lastMCC " + lastMCC + " lastMnc ==> " +
+                lastMnc + " lastLAC ==> " + lastLAC + " lastCID " + lastCID);
+        boolean result = false;
+        if (!lastMCC.equals(mcc) || !lastMnc.equals(mnc) || lastCID != gsmStationCID || lastLAC != lac) {
+            result = true;
+        }
+        //更新值
+        lastMnc = mnc;
+        lastMCC = mcc;
+        lastLAC = lac;
+        lastCID = gsmStationCID;
+        return result;
+    }
+
     /***
      *noMove and timeout return true
      * else return false
      */
     private boolean checkNoMoveTimeout() {
+        //如果LBS变化了,我们就认为位置改变了
+        if (checkLBS()) {
+            ICLogger.d("ON LBS CHANGE...");
+            return true;
+        }
         noMove = (runtime.getTotalStepCount() - runtime.getLastStepCount() <= 0);
         runtime.updateFZDDevStatusMoving(!noMove); //设置当前运动状态
         ICLogger.i("checkNoMoveTimeout last_noMove " + last_noMove + " noMove " + noMove + " lastStepCount " + runtime.getLastStepCount() + " StepCount " + runtime.getTotalStepCount());
@@ -946,14 +968,13 @@ public class LocationClient {
         }
         last_noMove = noMove;
         //属于 判断是否 不动的状态超时
-        if (noMove == true && first_NoMove_timestamp > 0.01 && System.currentTimeMillis() - first_NoMove_timestamp > MaxNoMoveTimeout) {
+        if (noMove && first_NoMove_timestamp > 0.01 && System.currentTimeMillis() - first_NoMove_timestamp > MaxNoMoveTimeout) {
             ICLogger.i(" checkNoMoveTimeout true ");
             return true;
         } else {
             ICLogger.i("checkNoMoveTimeout false");
             return false;
         }
-
     }
 
     private boolean needLocationForBT() {
@@ -989,7 +1010,6 @@ public class LocationClient {
         // 不强制定位 且 (WorkingMod 不是紧急模式 或者 强制进行移动检测),且 没有移动过
         if ((forceLocation != 1) && NoMoveTimeout) {
             ICLogger.i("No Move ,skip BT location2!");
-
             return false;
         }
         //只做正常定位前是否运动的判断,给定位前蓝牙扫描专用的。和 NeedlocationFotBT 还不同。
@@ -1023,7 +1043,7 @@ public class LocationClient {
         }
 
         if (NoMoveTimeout) {
-// 记录gps 无信号或者timeout的次数,超过5 就会停止使用gps定位,只要有一次 移动,或者设置为wifi定位,则清零。
+            //记录gps 无信号或者timeout的次数,超过5 就会停止使用gps定位,只要有一次 移动,或者设置为wifi定位,则清零。
             if (gpsTimeoutCountOnNoMove >= MaxGpsTimeoutCountOnNoMove) {
                 NoMoveAndNoGPSsignalSkipGpsFlag = true;
             } else {
@@ -1059,15 +1079,13 @@ public class LocationClient {
             case ICLocation.EMERGNECY_MOD:
             case ICLocation.REALTIME_MOD:
 
-
                 if (NoMoveAndNoGPSsignalSkipGpsFlag == false) {
                     nmeaListener.setNoStop(true);
-//        nmeaListener.setNoStop(false);//保证从Custom切换回来的时候不至于不关闭gps
+                    //nmeaListener.setNoStop(false);//保证从Custom切换回来的时候不至于不关闭gps
                     startGpsLocate();
                 } else {
                     clearGPSlocateStat(); //确保gps关闭,防止切换回来gps状态错误,尤其是不NoStop模式下的gps切换回来有此风险。
                 }
-
                 break;
             case ICLocation.LOWPOWER_MOD:
             case ICLocation.NORMAL_MOD:
index c242bbe..8ee1250 100644 (file)
@@ -189,49 +189,49 @@ public class NMEAListener implements NmeaListener, LocationListener {
         }
         if (nmeastr.startsWith("$GPGLL,") || nmeastr.startsWith("$GNGLL,")) {
             String tmplist[] = nmeastr.split(",");
-//      GPGLL编辑
-//(地理定位信息)
-//      例:$GPGLL,4250.5589,S,14718.5084,E,092204.999,A*2D
-//      字段0:$GPGLL,语句ID,表明该语句为Geographic Position(GLL)地理定位信息
-//      字段1:纬度ddmm.mmmm,度分格式(前导位数不足则补0)
-//      字段2:纬度N(北纬)或S(南纬)
-//      字段3:经度dddmm.mmmm,度分格式(前导位数不足则补0)
-//      字段4:经度E(东经)或W(西经)
-//      字段5:UTC时间,hhmmss.sss格式
-//      字段6:状态,A=定位,V=未定位
-//      字段7:校验值($与*之间的数异或后的值)
+            //      GPGLL编辑
+            //(地理定位信息)
+            //      例:$GPGLL,4250.5589,S,14718.5084,E,092204.999,A*2D
+            //      字段0:$GPGLL,语句ID,表明该语句为Geographic Position(GLL)地理定位信息
+            //      字段1:纬度ddmm.mmmm,度分格式(前导位数不足则补0)
+            //      字段2:纬度N(北纬)或S(南纬)
+            //      字段3:经度dddmm.mmmm,度分格式(前导位数不足则补0)
+            //      字段4:经度E(东经)或W(西经)
+            //      字段5:UTC时间,hhmmss.sss格式
+            //      字段6:状态,A=定位,V=未定位
+            //      字段7:校验值($与*之间的数异或后的值)
             String Lat = tmplist[1];
             String lon = tmplist[3];
             String fixed = tmplist[6];
-//      ICLogger.i("GPGLL Lat="+Lat+",Lon="+lon+",fixed="+fixed);
+            //      ICLogger.i("GPGLL Lat="+Lat+",Lon="+lon+",fixed="+fixed);
 
         } else if (nmeastr.startsWith("$GPRMC,") || nmeastr.startsWith("$GNRMC,")) {
-//      GPRMC编辑
-//(推荐定位信息数据格式)
-//      例:$GPRMC,024813.640,A,3158.4608,N,11848.3737,E,10.05,324.27,150706,,,A*50
-//      字段0:$GPRMC,语句ID,表明该语句为Recommended Minimum Specific GPS/TRANSIT Data(RMC)推荐最小定位信息
-//      字段1:UTC时间,hhmmss.sss格式
-//      字段2:状态,A=定位,V=未定位
-//      字段3:纬度ddmm.mmmm,度分格式(前导位数不足则补0)
-//      字段4:纬度N(北纬)或S(南纬)
-//      字段5:经度dddmm.mmmm,度分格式(前导位数不足则补0)
-//      字段6:经度E(东经)或W(西经)
-//      字段7:速度,节,Knots
-//      字段8:方位角,度
-//      字段9:UTC日期,DDMMYY格式
-//      字段10:磁偏角,(000 - 180)度(前导位数不足则补0)
-//      字段11:磁偏角方向,E=东W=西
-//      字段12:模式,A=自动,D=差分,E=估测,N=数据无效(3.0协议内容)
-//      字段13:校验值($与*之间的数异或后的值)
+            //      GPRMC编辑
+            //(推荐定位信息数据格式)
+            //      例:$GPRMC,024813.640,A,3158.4608,N,11848.3737,E,10.05,324.27,150706,,,A*50
+            //      字段0:$GPRMC,语句ID,表明该语句为Recommended Minimum Specific GPS/TRANSIT Data(RMC)推荐最小定位信息
+            //      字段1:UTC时间,hhmmss.sss格式
+            //      字段2:状态,A=定位,V=未定位
+            //      字段3:纬度ddmm.mmmm,度分格式(前导位数不足则补0)
+            //      字段4:纬度N(北纬)或S(南纬)
+            //      字段5:经度dddmm.mmmm,度分格式(前导位数不足则补0)
+            //      字段6:经度E(东经)或W(西经)
+            //      字段7:速度,节,Knots
+            //      字段8:方位角,度
+            //      字段9:UTC日期,DDMMYY格式
+            //      字段10:磁偏角,(000 - 180)度(前导位数不足则补0)
+            //      字段11:磁偏角方向,E=东W=西
+            //      字段12:模式,A=自动,D=差分,E=估测,N=数据无效(3.0协议内容)
+            //      字段13:校验值($与*之间的数异或后的值)
             String tmplist[] = nmeastr.split(",");
             String utctime = tmplist[1];
             String Lat = tmplist[3];
             String lon = tmplist[5];
             String fixed = tmplist[2];
             String speed = tmplist[7];
-//      ICLogger.i("GPRMC GPSTime="+utctime+",Lat="+Lat+",Lon="+lon+",fixed="+fixed+",speed="+speed);
-//      if (Config.LOG_TOFILE)
-//        FileOutputUtil.fileOutput(this.runtime.getCacheDir(), "GPS", "GPRMC GPSTime="+utctime+",Lat="+Lat+",Lon="+lon+",fixed="+fixed+",speed="+speed);
+            //      ICLogger.i("GPRMC GPSTime="+utctime+",Lat="+Lat+",Lon="+lon+",fixed="+fixed+",speed="+speed);
+            //      if (Config.LOG_TOFILE)
+            //        FileOutputUtil.fileOutput(this.runtime.getCacheDir(), "GPS", "GPRMC GPSTime="+utctime+",Lat="+Lat+",Lon="+lon+",fixed="+fixed+",speed="+speed);
             if (fixed.trim().equals("A")) {
                 if (speed.trim().isEmpty()) speed = "0.0";
                 runtime.getLocationInstance().setSpeed(Float.valueOf(speed));
@@ -240,26 +240,26 @@ public class NMEAListener implements NmeaListener, LocationListener {
 
         } else if (nmeastr.startsWith("$GPGSV,") || nmeastr.startsWith("$GLGSV,") || nmeastr.startsWith("$GAGSV,") || nmeastr.startsWith("$GBGSV,") || nmeastr.startsWith("$BDGSV,")) {
 
-//    GPGSV编辑
-//            (可见卫星信息)
-//    例:$GPGSV,3,1,10,20,78,331,45,01,59,235,47,22,41,069,,13,32,252,45*70
-//    字段0:$GPGSV,语句ID,表明该语句为GPS Satellites in View(GSV)可见卫星信息
-//    字段1:本次GSV语句的总数目(1 - 3)
-//    字段2:本条GSV语句是本次GSV语句的第几条(1 - 3)
-//    字段3:当前可见卫星总数(00 - 12)(前导位数不足则补0)
-//    字段4:PRN 码(伪随机噪声码)(01 - 32)(前导位数不足则补0)
-//    字段5:卫星仰角(00 - 90)度(前导位数不足则补0)
-//    字段6:卫星方位角(00 - 359)度(前导位数不足则补0)
-//    字段7:信噪比(00-99)dbHz
-//    字段8:PRN 码(伪随机噪声码)(01 - 32)(前导位数不足则补0)
-//    字段9:卫星仰角(00 - 90)度(前导位数不足则补0)
-//    字段10:卫星方位角(00 - 359)度(前导位数不足则补0)
-//    字段11:信噪比(00-99)dbHz
-//    字段12:PRN 码(伪随机噪声码)(01 - 32)(前导位数不足则补0)
-//    字段13:卫星仰角(00 - 90)度(前导位数不足则补0)
-////    字段14:卫星方位角(00 - 359)度(前导位数不足则补0)
-////    字段15:信噪比(00-99)dbHz
-//    字段16:校验值($与*之间的数异或后的值)
+            //    GPGSV编辑
+            //            (可见卫星信息)
+            //    例:$GPGSV,3,1,10,20,78,331,45,01,59,235,47,22,41,069,,13,32,252,45*70
+            //    字段0:$GPGSV,语句ID,表明该语句为GPS Satellites in View(GSV)可见卫星信息
+            //    字段1:本次GSV语句的总数目(1 - 3)
+            //    字段2:本条GSV语句是本次GSV语句的第几条(1 - 3)
+            //    字段3:当前可见卫星总数(00 - 12)(前导位数不足则补0)
+            //    字段4:PRN 码(伪随机噪声码)(01 - 32)(前导位数不足则补0)
+            //    字段5:卫星仰角(00 - 90)度(前导位数不足则补0)
+            //    字段6:卫星方位角(00 - 359)度(前导位数不足则补0)
+            //    字段7:信噪比(00-99)dbHz
+            //    字段8:PRN 码(伪随机噪声码)(01 - 32)(前导位数不足则补0)
+            //    字段9:卫星仰角(00 - 90)度(前导位数不足则补0)
+            //    字段10:卫星方位角(00 - 359)度(前导位数不足则补0)
+            //    字段11:信噪比(00-99)dbHz
+            //    字段12:PRN 码(伪随机噪声码)(01 - 32)(前导位数不足则补0)
+            //    字段13:卫星仰角(00 - 90)度(前导位数不足则补0)
+            ////    字段14:卫星方位角(00 - 359)度(前导位数不足则补0)
+            ////    字段15:信噪比(00-99)dbHz
+            //    字段16:校验值($与*之间的数异或后的值)
 
             String tmplist[] = nmeastr.split(",");
             int maxPageCount = 0;
index d4c4baa..e561134 100644 (file)
@@ -101,14 +101,15 @@ public class ICLocation {
     public static final int MAX_GPS_NOSIGNAL_COUNT = 15;\r
     public static final int MAX_GPS_SEARCH_TIMEOUT = 120;\r
 \r
-    public void setLastWorkingMode(int wkmod){\r
-        last_workmode=wkmod;\r
+    public void setLastWorkingMode(int wkmod) {\r
+        last_workmode = wkmod;\r
     }\r
+\r
     public void setWorkingMod(int wkmod) {\r
         mworkingMod = wkmod;\r
     }\r
 \r
-    public int getLastWorkingMode(){\r
+    public int getLastWorkingMode() {\r
         return last_workmode;\r
     }\r
 \r
@@ -116,7 +117,7 @@ public class ICLocation {
         location_cycle = _locatCycle;\r
     }\r
 \r
-    private static int last_workmode=NORMAL_MOD; //上一次工作模式,主要用来EMERGENCY_MODE 结束后返回 使用。\r
+    private static int last_workmode = NORMAL_MOD; //上一次工作模式,主要用来EMERGENCY_MODE 结束后返回 使用。\r
 \r
     public int getWorkingMod() {\r
         return mworkingMod;\r
@@ -288,36 +289,38 @@ public class ICLocation {
     private String MNC = "0";\r
     private int LAC = 0;\r
     private int CID = 0;\r
-    private int rxlevel = 0;\r
-    private boolean datachanged = false;\r
+    private int rxLevel = 0;\r
+    private boolean dataChanged = false;\r
 \r
     public void setMCC(String mcc) {\r
         MCC = mcc;\r
-        datachanged = true;\r
+        dataChanged = true;\r
     }\r
 \r
     public void setMNC(String mnc) {\r
         ICLogger.d("MNC==> " + mnc);\r
         MNC = mnc;\r
-        datachanged = true;\r
+        dataChanged = true;\r
     }\r
 \r
     public void setLAC(int lac) {\r
+        ICLogger.d("lac ==> " + lac);\r
         LAC = lac;\r
-        datachanged = true;\r
+        dataChanged = true;\r
     }\r
 \r
     public void setCID(int cid) {\r
+        ICLogger.d("cid===> " + cid);\r
         CID = cid;\r
-        datachanged = true;\r
+        dataChanged = true;\r
     }\r
 \r
-    public void setRxlevel(int level) {\r
-        rxlevel = level;\r
+    public void setRxLevel(int level) {\r
+        rxLevel = level;\r
     }\r
 \r
     public boolean isDataChanged() {\r
-        return datachanged;\r
+        return dataChanged;\r
     }\r
 \r
     public String getMCC() {\r
@@ -328,8 +331,8 @@ public class ICLocation {
         return MNC;\r
     }\r
 \r
-    public int getRxlevel() {\r
-        return rxlevel;\r
+    public int getRxLevel() {\r
+        return rxLevel;\r
     }\r
 \r
     public long getLAC() {\r
index fe2e51e..67114e4 100644 (file)
@@ -1296,7 +1296,7 @@ public class Runtime {
                 .append(String.format("%1$03d", mnc))
                 .append(String.format("%1$04X", gpsp.getLAC()))
                 .append(String.format("%1$07X", gpsp.getGSMStationCID()))
-                .append(String.format("%1$02X", gpsp.getRxlevel()));
+                .append(String.format("%1$02X", gpsp.getRxLevel()));
         return sb.toString();
     }
 
index f4bccbc..2529d9a 100644 (file)
@@ -1,14 +1,7 @@
 package com.enqualcomm.support.utils;
 
-import android.Manifest;
 import android.content.Context;
-import android.content.pm.PackageManager;
 import android.os.Build;
-import android.os.Handler;
-import android.os.Message;
-import android.os.PowerManager;
-import android.provider.ContactsContract;
-import android.support.v4.app.ActivityCompat;
 import android.telephony.CellInfo;
 import android.telephony.CellInfoCdma;
 import android.telephony.CellInfoGsm;
@@ -24,17 +17,12 @@ import android.telephony.TelephonyManager;
 import android.telephony.cdma.CdmaCellLocation;
 import android.telephony.gsm.GsmCellLocation;
 
-import com.android.internal.telephony.CallManager;
-import com.android.internal.telephony.CallStateException;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneFactory;
 import com.enqualcomm.support.Config;
-import com.enqualcomm.support.GSensorListener;
-import com.enqualcomm.support.adapter.LBSHelper;
 import com.enqualcomm.support.bean.Runtime;
 import com.sprd.internal.telephony.SprdCallManager;
 
-import java.lang.reflect.Method;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
@@ -250,7 +238,7 @@ public class CellInfoUtil {
           runtime.setCellinfo(gsmSb.toString());
           runtime.getLocationInstance().setCID(gsmCell.getCid());
           runtime.getLocationInstance().setLAC(gsmCell.getLac());
-          runtime.getLocationInstance().setRxlevel(150-Math.abs(getSignal(telephonyManager,runtime)));
+          runtime.getLocationInstance().setRxLevel(150-Math.abs(getSignal(telephonyManager,runtime)));
           ICLogger.i("LBS GsmCellLocation "+ gsmSb.toString());
           if (Config.LOG_TOFILE) ICLogger.logToFile("LBS", gsmSb.toString());