release V376
authorsnickersun <scy@incartech.cn>
Sat, 14 Mar 2020 09:55:05 +0000 (17:55 +0800)
committersnickersun <scy@incartech.cn>
Sat, 14 Mar 2020 09:55:05 +0000 (17:55 +0800)
1、修复定位检测 定时器不准造成的长时间无法继续定位(增加时间的判断,而不是只有计数)
2、优化定位精度,HDOP定位精度由原来的50米以内改为10米以内 , 原来需要定位5次,改为定位3次即可。
3、去掉多余的定位代码
4、增加更多的日志,方便分析问题。

app/release/ICSer_V375_2003131757_release.apk [deleted file]
app/release/ICSer_V376_2003141723_release.apk [new file with mode: 0644]
app/src/main/java/com/enqualcomm/support/CoreService.java
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/utils/TimeUtil.java
app/version_code.properties

diff --git a/app/release/ICSer_V375_2003131757_release.apk b/app/release/ICSer_V375_2003131757_release.apk
deleted file mode 100644 (file)
index bc65c8c..0000000
Binary files a/app/release/ICSer_V375_2003131757_release.apk and /dev/null differ
diff --git a/app/release/ICSer_V376_2003141723_release.apk b/app/release/ICSer_V376_2003141723_release.apk
new file mode 100644 (file)
index 0000000..7e0558e
Binary files /dev/null and b/app/release/ICSer_V376_2003141723_release.apk differ
index e4d590e..1437020 100644 (file)
@@ -657,7 +657,7 @@ public class CoreService extends Service {
                 stringBuilder1.append("LOCATION_ALARM  work mod=");\r
                 stringBuilder1.append(runtime.getLocationInstance().getWorkingMod());\r
                 if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", stringBuilder1.toString());\r
-                this.locationClient.triggerLocationProcess();\r
+//                this.locationClient.triggerLocationProcess();\r
 \r
             } else {\r
                 StringBuilder stringBuilder1;\r
index edfb7f1..f503f06 100644 (file)
@@ -1,5 +1,6 @@
 package com.enqualcomm.support;\r
 \r
+import android.app.AlarmManager;\r
 import android.content.BroadcastReceiver;\r
 import android.content.Context;\r
 import android.content.Intent;\r
@@ -10,6 +11,7 @@ import android.os.PowerManager;
 import android.os.SystemClock;\r
 import android.provider.Settings;\r
 \r
+import com.enqualcomm.support.utils.AlarmHelper;\r
 import com.ic.jni.ICJniUtils;\r
 import com.enqualcomm.support.adapter.LBSHelper;\r
 import com.enqualcomm.support.adapter.protocolAPIHelper;\r
@@ -49,7 +51,7 @@ import static com.enqualcomm.support.Constants.HEART_ALARM;
 public class LocationClient {\r
   private static final String TAG = LocationClient.class.getSimpleName();\r
   private static final long CHANGENETMODETIME = 43200000L;\r
-  \r
+  private static long startCheckTime=0L;\r
   private static final int CLOSE_AIRMODE = 0;\r
   \r
   private static final int IS_GPS = 0;\r
@@ -118,7 +120,7 @@ public class LocationClient {
 //  private BroadcastReceiver screenOnReceiver = new BroadcastReceiver() {\r
 //      public void onReceive(Context param1Context, Intent param1Intent) {\r
 //        if ("android.intent.action.SCREEN_ON".equals(param1Intent.getAction())) {\r
-//          LocationClient.this.mSignalUtil.setAirMode("CloseAirplane");\r
+//          mSignalUtil.setAirMode("CloseAirplane");\r
 //        }\r
 //      }\r
 //    };\r
@@ -178,7 +180,6 @@ public class LocationClient {
 \r
   }\r
 \r
-\r
   private void performAlarm(PowerManager.WakeLock paramWakeLock) {\r
     if (!runtime.isAirMode) {\r
       updateStepCount();//update StepCount\r
@@ -187,11 +188,11 @@ public class LocationClient {
     }\r
   }\r
   public void triggerLocationProcess(){\r
-    mhandler.sendEmptyMessage(0);\r
+    mhandler.sendEmptyMessage(msgWhat_StartLocationProcess);\r
   }\r
 \r
   public void triggerSOSLocationProcess(){\r
-    mhandler.sendEmptyMessage(2);\r
+    mhandler.sendEmptyMessage(msgWhat_StartSOSLocationProcess);\r
   }\r
 \r
   private static int checktimes=0;\r
@@ -225,7 +226,7 @@ public class LocationClient {
           Settings.Secure.setLocationProviderEnabled(runtime.getContextProxy().getResolver(), GPS_PROVIDER, true);\r
           Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
             public void call(Object param1Object) {\r
-              LocationClient.this.nmeaListener.startListen();\r
+              nmeaListener.startListen();\r
             }\r
           });\r
         }\r
@@ -243,35 +244,41 @@ public class LocationClient {
   public void startCheckResult(){\r
       checktimes=0;\r
       timeout=false;\r
+      startCheckTime= System.currentTimeMillis();\r
       //延时2秒执行发送“读取定位”消息\r
       if (mTimer==null) mTimer=new Timer();\r
       mTimer.schedule(new MyTimerTask(), 1000L,1000L);\r
+//    AlarmManager alarmManager=(AlarmManager)runtime.getContextProxy().context.getSystemService(Context.ALARM_SERVICE);\r
+//    AlarmHelper.setAlarm(alarmManager,0,1,);\r
   }\r
   class MyTimerTask extends TimerTask {\r
     public void run() {\r
       //发送读取计步消息\r
-      LocationClient.this.mhandler.sendEmptyMessage(100);\r
+      mhandler.sendEmptyMessage(msgWhat_WaitAndSendLocation);\r
     }\r
   };\r
+\r
+\r
+\r
+  private final static int msgWhat_WaitAndSendLocation=100;\r
+  private final static int msgWhat_StartLocationProcess=0;\r
+  private final static int msgWhat_StartSOSLocationProcess=2;\r
   Handler mhandler=new Handler(){\r
 \r
         public void handleMessage(Message msg) {\r
           super.handleMessage(msg);\r
-          if (msg.what == 100){\r
+          if (msg.what == msgWhat_WaitAndSendLocation){\r
             Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
-              public void call(Object param1Object) { LocationClient.this.waitAndSendLocation(); }\r
+              public void call(Object param1Object) { waitAndSendLocation(); }\r
             });\r
-          }else if (msg.what == 0){\r
+          }else if (msg.what == msgWhat_StartLocationProcess){\r
             startLocationProcess(runtime.getLocationInstance().getWorkingMod());\r
-          }else if (msg.what == 2){\r
+          }else if (msg.what == msgWhat_StartSOSLocationProcess){\r
             startSOSLocation=true;//启动SOS定位,为了快速响应,只要wifi定位即可。\r
             forceLocation=1;\r
             startLocationProcess(ICLocation.NORMAL_MOD);\r
           }\r
-\r
-\r
         }\r
-\r
   };\r
 \r
 \r
@@ -296,7 +303,7 @@ public class LocationClient {
             && runtime.getLocationInstance().getGSMStationCID() ==0\r
             &&  runtime.getLocationInstance().getLAC()==0)) ?false:true;\r
 //        ICLogger.i("getMNC "+runtime.getLocationInstance().getMNC()+" getMCC "+runtime.getLocationInstance().getMCC()+" getGSMStationCID " + runtime.getLocationInstance().getGSMStationCID()+ " getLAC "+runtime.getLocationInstance().getLAC()+" changed "+runtime.getLocationInstance().isDataChanged());\r
-        ICLogger.i("waitAndSendLocation lbs="+lbs_ok+", wifi="+ wifi_ok+ ", gps="+gps_ok + ", mode="+mode);\r
+        ICLogger.i("waitAndSendLocation "+checktimes+", lbs="+lbs_ok+", wifi="+ wifi_ok+ ", gps="+gps_ok + ", mode="+mode);\r
 \r
         switch(mode){\r
           case ICLocation.CUSTOM_MOD:\r
@@ -305,57 +312,65 @@ public class LocationClient {
 \r
 \r
             //GPS 优先的话多给些时间(10秒)\r
-            if (checktimes> 50) timeout=true;\r
-\r
-            if ((lbs_ok && timeout==true) ||( gps_ok )||(lbs_ok &&  gps_ok  )||(lbs_ok && ( gps_ok || startSOSLocation==true ) && wifi_ok )||(lbs_ok&&gps_nosignal&&wifi_ok)){\r
-\r
-\r
+            if (checktimes> 50 ||\r
+                    ((startCheckTime!=0L)&&(System.currentTimeMillis()-startCheckTime > 50*1000L)) //有时timer计数不准,则根据实际时间计算\r
+            ) timeout=true;\r
+\r
+            // lbs only +timeout, lbs+wifi+gpsNosignal, libs+ , lbs+gps+wifi, Timeout can override wifi and gps\r
+            if ((lbs_ok && timeout==true)\r
+                    ||( gps_ok )\r
+                    ||(lbs_ok &&  ( gps_ok || startSOSLocation==true )  )\r
+                    ||(lbs_ok && ( gps_ok || startSOSLocation==true ) && wifi_ok )\r
+                    ||(lbs_ok&&gps_nosignal&&wifi_ok)\r
+            ){\r
               if (startSOSLocation==true){\r
-\r
                 String AP10_CMD = protocolAPIHelper.AP10(runtime);\r
                 Deliver.sendLocationMSG(AP10_CMD);\r
                 startSOSLocation=false;\r
-\r
               }else {\r
                 String AP01_CMD = protocolAPIHelper.AP01(runtime);\r
                 Deliver.sendLocationMSG(AP01_CMD);\r
               }\r
 \r
 \r
-              if (mTimer!=null){\r
-                mTimer.cancel();\r
-                mTimer=null;\r
-              }\r
-              isLocating = false;\r
+              stopCheckLocationResult();\r
+\r
               String locationtype="LBS";\r
               if (gps_ok ){\r
                   locationtype="GPS";\r
               }else if (wifi_ok){\r
                   locationtype="WiFi";\r
               }\r
+\r
               runtime.getLocationInstance().setLocationType(locationtype);\r
               runtime.getLocationInstance().setLocationTime(TimeUtil.getSystemTime3());\r
+\r
+              String msg="Location Fixed Type "+runtime.getLocationInstance().getLocationType()+" at "+runtime.getLocationInstance().getLocationTime();\r
+              ICLogger.i(msg);\r
+\r
+              if (Config.LOG_TOFILE)\r
+                FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",msg);\r
+\r
+\r
             }else if (timeout==true){\r
+              //timeout + noLBS +noGPS\r
               ICLogger.i("timeout no location  ");\r
-              isLocating = false;\r
-              if (mTimer!=null){\r
-                mTimer.cancel();\r
-                mTimer=null;\r
-              }\r
+              stopCheckLocationResult();\r
+              if (Config.LOG_TOFILE)\r
+                FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS","timeout no location ");\r
             }\r
             break;\r
+\r
+          case ICLocation.NORMAL_MOD:\r
+          case ICLocation.LOWPOWER_MOD:\r
           default:\r
             //wifi优先的话给20秒时间\r
-            if (checktimes> 20) timeout=true;\r
+            if (checktimes> 20 ||\r
+                    ((startCheckTime!=0L)&&(System.currentTimeMillis()-startCheckTime > 20*1000L)) //有时timer计数不准,则根据实际时间计算\r
+            ) timeout=true;\r
 \r
             if ((lbs_ok && timeout==true) ||(lbs_ok && wifi_ok )){\r
 \r
-              String locationtype="LBS";\r
-              if (wifi_ok){\r
-                locationtype="WiFi";\r
-              }\r
-              runtime.getLocationInstance().setLocationType(locationtype);\r
-              runtime.getLocationInstance().setLocationTime(TimeUtil.getSystemTime3());\r
 \r
               if (startSOSLocation==true){\r
                 String AP10_CMD = protocolAPIHelper.AP10(runtime);\r
@@ -367,33 +382,50 @@ public class LocationClient {
                 Deliver.sendLocationMSG(AP01_CMD);\r
               }\r
 \r
-              if (mTimer!=null){\r
-                mTimer.cancel();\r
-                mTimer=null;\r
+              stopCheckLocationResult();\r
+\r
+              String locationtype="LBS";\r
+              if (wifi_ok){\r
+                locationtype="WiFi";\r
               }\r
-              isLocating = false;\r
+              runtime.getLocationInstance().setLocationType(locationtype);\r
+              runtime.getLocationInstance().setLocationTime(TimeUtil.getSystemTime3());\r
+\r
+              String msg="Location Fixed Type "+runtime.getLocationInstance().getLocationType()+" at "+runtime.getLocationInstance().getLocationTime();\r
+              ICLogger.i(msg);\r
 \r
+              if (Config.LOG_TOFILE)\r
+                FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",msg);\r
 \r
 \r
             }else if (timeout==true){\r
               ICLogger.i("timeout no location  ");\r
-              isLocating = false;\r
-              if (mTimer!=null){\r
-                mTimer.cancel();\r
-                mTimer=null;\r
-              }\r
+              stopCheckLocationResult();\r
+              if (Config.LOG_TOFILE)\r
+                FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS","timeout no location ");\r
             }\r
             break;\r
         }\r
 \r
   }\r
 \r
+  public void stopCheckLocationResult(){\r
+    ICLogger.i("stopCheckLocationResult!");\r
+    if (mTimer!=null){\r
+      mTimer.cancel();\r
+      mTimer=null;\r
+    }\r
+    isLocating = false;\r
+    startCheckTime=0L;\r
+  }\r
+\r
 //  public void EqcAlgorithmInterfaceMethod3() {\r
   public void stopGpsLocate() {\r
 //    if (Deliver.is_active_location) {\r
 //      Deliver.is_active_location = false;\r
 //      getLocationWakeLock();\r
 //    }\r
+    ICLogger.i("stopGpsLocate");\r
 \r
     //防止与工厂测试冲突\r
     if (!DeviceInfoUtil.isFactoryTestTopActivity(runtime.getContextProxy().context)) {\r
@@ -401,7 +433,7 @@ public class LocationClient {
       Settings.Secure.setLocationProviderEnabled(runtime.getContextProxy().getResolver(), GPS_PROVIDER, false);\r
       Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
         public void call(Object param1Object) {\r
-          LocationClient.this.nmeaListener.stopListen();\r
+          nmeaListener.stopListen();\r
         }\r
       });\r
     }\r
@@ -461,7 +493,7 @@ public void updateCellInfo() {
 \r
     runtime.setLastStepCount(runtime.getTotalStepCount());\r
     updateCellInfo();\r
-      startWifiScan();\r
+    startWifiScan();\r
     switch(mod){\r
       case ICLocation.CUSTOM_MOD:\r
         if(runtime.getLocationInstance().getLocation_cycle()<60){\r
@@ -543,6 +575,7 @@ public void updateCellInfo() {
   \r
   public void deinit() {\r
 \r
+    ICLogger.i("GPS deinit!");\r
 //    (runtime.getContextProxy()).context.unregisterReceiver(this.screenOnReceiver);\r
 //    mLbsHelper.unRegisterWiFiBroadReceiver();\r
 //    this.executor.execute(new Runnable() {\r
@@ -560,7 +593,7 @@ public void updateCellInfo() {
   private void notifiSetAirModeMethod() { (new Thread(new Runnable() {\r
     public void run() {\r
       SystemClock.sleep(3000L);\r
-      boolean bool = LocationClient.this.mSignalUtil.IsAirModeOn();\r
+      boolean bool = mSignalUtil.IsAirModeOn();\r
       byte b = 1;\r
       if (bool != true)\r
         b = 0;\r
index 5178d87..cd4ccd7 100644 (file)
@@ -60,7 +60,7 @@ public class NMEAListener implements NmeaListener, LocationListener {
   int numberOfSatellites;\r
   Runtime runtime;\r
 \r
-  private static int MaxFixedTimes=5;\r
+  private static int MaxFixedTimes=3;\r
 \r
   private static int locationFixedCount=0;\r
 \r
@@ -68,6 +68,7 @@ public class NMEAListener implements NmeaListener, LocationListener {
 \r
   public void setNoStop(boolean nostop){\r
     noStop=nostop;\r
+    ICLogger.i("setNoStop"+nostop);\r
     if (noStop==false){\r
       stopListen();\r
     }\r
@@ -228,6 +229,7 @@ public class NMEAListener implements NmeaListener, LocationListener {
             stop(MSG_WHAT_GPS_NOSTAR);\r
           }\r
         }\r
+        ICLogger.i( sb2.toString());\r
         if (Config.LOG_TOFILE)\r
           FileOutputUtil.fileOutput(this.runtime.getCacheDir(),"GPS",sb2.toString());\r
 \r
@@ -282,6 +284,31 @@ public class NMEAListener implements NmeaListener, LocationListener {
                 只有当前GPS已经定位,且location不为空才给 runtime赋值GPS坐标。\r
                 延迟MaxFixedTimes秒后才设置runtime的定位标志,以便稳定坐标值。\r
               */\r
+\r
+            //log msg变量\r
+            StringBuffer sb2 = new StringBuffer();\r
+            sb2.append(" gps lat=").append(Lat).append(", gps lon=").append(lon);\r
+\r
+            latitude=Double.valueOf(Lat);\r
+            longitude=Double.valueOf(lon);\r
+            // 转换单位,从分转换到度\r
+\r
+            double intdu= (int)(longitude /100f); //小数转换到分为单位\r
+            double du=(longitude - intdu*100)/60f;\r
+            double last= intdu+du;\r
+            longitude =last;\r
+            intdu= (int)(latitude /100f); //小数转换到分为单位\r
+            du=(latitude - intdu*100)/60f;\r
+            last= intdu+du;\r
+            latitude=last;\r
+\r
+            // 经纬度 保留4位小数点\r
+            DecimalFormat df = new DecimalFormat("#.000000");\r
+            String strLatitude = df.format(latitude);\r
+            String strLongitude = df.format(longitude);\r
+            sb2.append(" real lat=").append(strLatitude).append(" lon=").append(strLongitude);\r
+            ICLogger.i(sb2.toString());\r
+\r
             runtime.getLocationInstance().setLocation(Lat,lon);\r
             runtime.getLocationInstance().setUsedStarts(Integer.valueOf(usedStarts.trim()));\r
             runtime.getLocationInstance().setHod(Float.valueOf(hdop.trim()));\r
@@ -395,7 +422,9 @@ public class NMEAListener implements NmeaListener, LocationListener {
       }\r
 \r
       if (!noStop){\r
-        NMEAListener.this.stopListen();\r
+        ICLogger.i("handleMessage MSG_WHAT_GPS_TIMEOUT/ MSG_WHAT_GPS_NOSTAR/ MSG_WHAT_GPS_FIXED "+message.what);\r
+\r
+        stopListen();\r
       }\r
       return true;\r
     }\r
@@ -437,17 +466,7 @@ public class NMEAListener implements NmeaListener, LocationListener {
 //\r
 //    ICLogger.i("Location " +runtime.getLocationInstance().getLocationStat().name());\r
     //发送停止消息\r
-    NMEAListener.this.temHandler.sendEmptyMessage(id);\r
-  }\r
-  private void delaystop(){\r
-\r
-    /*\r
-        只有当前GPS已经定位,且location不为空才给 runtime赋值GPS坐标。\r
-        延迟三秒后才设置runtime的定位标志,以便稳定坐标值。\r
-         */\r
-      //发送停止消息\r
-      NMEAListener.this.temHandler.sendEmptyMessageDelayed(MSG_WHAT_GPS_FIXED, 3000L);\r
-\r
+    temHandler.sendEmptyMessage(id);\r
   }\r
   boolean isFrist = true;\r
 \r
@@ -479,6 +498,8 @@ public class NMEAListener implements NmeaListener, LocationListener {
       //做个热启动\r
       return true;//gpsHotStart();\r
     }else{\r
+      ICLogger.i(" location listening, skip !");\r
+\r
       return true;\r
     }\r
   }\r
@@ -488,6 +509,7 @@ public class NMEAListener implements NmeaListener, LocationListener {
     this.locationManager.removeNmeaListener(this);\r
     this.locationManager.removeUpdates(this);\r
     this.listening = false;\r
+    ICLogger.i("stopListen 定位 ");\r
   }\r
 \r
   public enum  GPS_CURRENT_STATUS {\r
index 25cb8e3..d707df6 100644 (file)
@@ -42,7 +42,7 @@ public class ICLocation {
     private int mworkingMod;\r
     private int location_cycle;\r
 \r
-    public static final float MAX_HDOP=50.0f;\r
+    public static final float MAX_HDOP=10.0f;\r
     public static final int MAX_GPS_NOSIGNAL_COUNT=10;\r
     public static final int MAX_GPS_SEARCH_TIMEOUT=120;\r
     public void setWorkingMod(int wkmod){ mworkingMod=wkmod;}\r
index 5c6afb1..c2c3b27 100644 (file)
@@ -16,7 +16,7 @@ public class TimeUtil {
 \r
   public static String getSystemTime() { return getSystemTime(System.currentTimeMillis()); }\r
   \r
-  public static String getSystemTime(long paramLong) { return (new SimpleDateFormat("yyyy-MM-dd;HH:mm:ss")).format(new Date(paramLong)); }\r
+  public static String getSystemTime(long paramLong) { return (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date(paramLong)); }\r
   \r
   public static String getSystemTime2() { return getSystemTime2(System.currentTimeMillis()); }\r
   \r
index fc5c50e..439698b 100644 (file)
@@ -1,2 +1,2 @@
-#Fri Mar 13 17:57:22 CST 2020\r
-VERSION_CODE=375\r
+#Sat Mar 14 17:23:03 CST 2020\r
+VERSION_CODE=376\r