1、修复GPS 状态窗口Wakelock crash问题
authorsnickersun <scy@incartech.cn>
Tue, 17 Mar 2020 04:47:02 +0000 (12:47 +0800)
committersnickersun <scy@incartech.cn>
Tue, 17 Mar 2020 04:47:02 +0000 (12:47 +0800)
2、把所有log文件指向 /sdcard/Android/ic
3、把所有GPS相关操作都移到 NMEAListener中,解决偶尔有GPS unregister listener ,下次开启GPS 失灵的问题。

app/src/main/java/com/enqualcomm/support/CoreService.java
app/src/main/java/com/enqualcomm/support/CrashHandler.java
app/src/main/java/com/enqualcomm/support/GPSActivity.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/utils/WakeLockUtil.java
app/src/main/res/layout/activity_main.xml
app/src/main/res/layout/activity_tool.xml
local.properties

index 1a03a9f..a7d77c7 100644 (file)
@@ -21,6 +21,7 @@ import android.widget.Toast;
 import com.enqualcomm.support.bean.ICLocation;\r
 import com.enqualcomm.support.utils.DeviceInfoUtil;\r
 import com.enqualcomm.support.utils.ServiceUtil;\r
+import com.enqualcomm.support.utils.StorageUtils;\r
 import com.ic.jni.ICJniUtils;\r
 import com.enqualcomm.support.Constants;\r
 import com.enqualcomm.support.GSensorListener;\r
@@ -53,6 +54,7 @@ import com.enqualcomm.support.utils.SharPreferenceUtil;
 import com.enqualcomm.support.utils.SimSignalUtil;\r
 import com.enqualcomm.support.utils.TimeUtil;\r
 import com.enqualcomm.support.utils.Util;\r
+import com.sina.util.dnscache.log.FileUtil;\r
 \r
 import java.lang.ref.WeakReference;\r
 import chestnut.ui.Toastc;\r
@@ -351,7 +353,7 @@ public class CoreService extends Service {
 \r
     private void getDBFile() {\r
         StringBuilder stringBuilder = new StringBuilder();\r
-        stringBuilder.append(getExternalCacheDir());\r
+        stringBuilder.append(StorageUtils.getExternalStorageLogDir());\r
         stringBuilder.append("/contacts.db");\r
         FileOutputUtil.copyFolder("/data/data/com.enqualcomm.support/databases", stringBuilder.toString());\r
     }\r
index 260ac33..87517b7 100644 (file)
@@ -10,6 +10,7 @@ import android.util.Log;
 import android.widget.Toast;\r
 \r
 import com.enqualcomm.support.R;\r
+import com.enqualcomm.support.utils.StorageUtils;\r
 \r
 import java.io.File;\r
 import java.io.FileOutputStream;\r
@@ -199,7 +200,7 @@ public class CrashHandler implements Thread.UncaughtExceptionHandler {
 //            if (Environment.getExternalStorageState().equals(\r
 //                    Environment.MEDIA_MOUNTED)) {\r
 //                File dir = new File(mContext.getExternalCacheDir(), "crash");\r
-                File dir=mContext.getExternalCacheDir();\r
+                File dir= new File(StorageUtils.getExternalStorageLogDir());\r
                 String path = dir.getPath();\r
                 if (!dir.exists()) {\r
                     dir.mkdirs();\r
index 57ae3dc..5c35dab 100644 (file)
@@ -147,7 +147,8 @@ public class GPSActivity extends AppCompatActivity implements location_callback
 //        timer.schedule(tmt,0,2000);\r
 //        showmessage=true;\r
         NMEAListener.set_callback(this);\r
-        screenOnWakelock = WakeLockUtil.getScreenOnWakeLock(this,GPSActivity.class.getSimpleName());\r
+        if (screenOnWakelock==null)\r
+            screenOnWakelock = WakeLockUtil.getScreenOnWakeLock(this,GPSActivity.class.getSimpleName());\r
     }\r
 \r
     @Override\r
@@ -159,7 +160,12 @@ public class GPSActivity extends AppCompatActivity implements location_callback
 //            timer = null;\r
 //        }\r
         showmessage=false;\r
-        screenOnWakelock.release();\r
+        if(screenOnWakelock!=null) {\r
+            if (screenOnWakelock.isHeld()) {\r
+                screenOnWakelock.release();\r
+            }\r
+            screenOnWakelock=null;\r
+        }\r
 \r
     }\r
 }\r
index f503f06..0add009 100644 (file)
@@ -215,23 +215,25 @@ public class LocationClient {
   }\r
 //  public void EqcAlgorithmInterfaceMethod2() {\r
     public void startGpsLocate() {\r
-      ICLogger.i("开启GPS扫描");\r
-\r
-      if(!nmeaListener.isListening()) {\r
-        runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_OPEN); //此处为了检测是否定位时可以正确识别状态,以防一直处于GPS定位成功状态\r
-\r
-        //防止与工厂测试冲突\r
-        if (!DeviceInfoUtil.isFactoryTestTopActivity(runtime.getContextProxy().context)) {\r
-\r
-          Settings.Secure.setLocationProviderEnabled(runtime.getContextProxy().getResolver(), GPS_PROVIDER, true);\r
+       //防止与工厂测试冲突\r
+      if (!DeviceInfoUtil.isFactoryTestTopActivity(runtime.getContextProxy().context)) {\r
+        ICLogger.i("开启GPS扫描!");\r
+        if(Config.LOG_TOFILE) ICLogger.logToFile("GPS","开启GPS扫描!");\r
+        if (!nmeaListener.isListening()) {\r
+          runtime.getLocationInstance().setLocationStat(ICLocation.LOCATION_STAT.LOCATION_OPEN); //此处为了检测是否定位时可以正确识别状态,以防一直处于GPS定位成功状态\r
           Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
             public void call(Object param1Object) {\r
               nmeaListener.startListen();\r
             }\r
           });\r
+\r
+        } else {\r
+          ICLogger.i("GPS is still listening, skip open it!");\r
+          if (Config.LOG_TOFILE) ICLogger.logToFile("GPS", "GPS is still listening, skip open it!");\r
         }\r
       }else{\r
-        ICLogger.i("GPS is still listening, skip open it!");\r
+        ICLogger.i("工厂模式,skip 开启GPS扫描!");\r
+        if(Config.LOG_TOFILE) ICLogger.logToFile("GPS","工厂模式,skip 开启GPS扫描!");\r
       }\r
   }\r
 \r
@@ -425,17 +427,18 @@ public class LocationClient {
 //      Deliver.is_active_location = false;\r
 //      getLocationWakeLock();\r
 //    }\r
-    ICLogger.i("stopGpsLocate");\r
-\r
     //防止与工厂测试冲突\r
     if (!DeviceInfoUtil.isFactoryTestTopActivity(runtime.getContextProxy().context)) {\r
-\r
-      Settings.Secure.setLocationProviderEnabled(runtime.getContextProxy().getResolver(), GPS_PROVIDER, false);\r
+      ICLogger.i("stopGpsLocate");\r
+      if(Config.LOG_TOFILE) ICLogger.logToFile("GPS","stopGpsLocate");\r
       Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
         public void call(Object param1Object) {\r
           nmeaListener.stopListen();\r
         }\r
       });\r
+    }else{\r
+      ICLogger.i("工厂模式 skip stopGpsLocate");\r
+      if(Config.LOG_TOFILE) ICLogger.logToFile("GPS","工厂模式 skip stopGpsLocate");\r
     }\r
   }\r
   \r
index 4adfe4e..1f4480c 100644 (file)
@@ -12,6 +12,8 @@ import android.location.LocationManager;
 import android.os.Bundle;\r
 import android.os.Handler;\r
 import android.os.Message;\r
+import android.provider.Settings;\r
+\r
 import com.enqualcomm.support.bean.ICLocation;\r
 import com.enqualcomm.support.bean.Runtime;\r
 import com.enqualcomm.support.utils.FileOutputUtil;\r
@@ -23,8 +25,14 @@ import java.util.ArrayList;
 import java.util.Iterator;\r
 import java.util.List;\r
 \r
+import rx.Single;\r
+import rx.android.schedulers.AndroidSchedulers;\r
+import rx.functions.Action1;\r
+\r
+import static android.location.LocationManager.GPS_PROVIDER;\r
+\r
 public class NMEAListener implements NmeaListener, LocationListener {\r
-  private boolean listening=false;\r
+  private static boolean listening=false;\r
 \r
   public boolean isListening(){\r
     return listening;\r
@@ -507,6 +515,9 @@ public class NMEAListener implements NmeaListener, LocationListener {
   public boolean startListen() {\r
 \r
     if (this.listening == false) {\r
+      Settings.Secure.setLocationProviderEnabled(runtime.getContextProxy().getResolver(), GPS_PROVIDER, true);\r
+\r
+\r
       Criteria criteria = new Criteria();\r
       criteria.setAccuracy(Criteria.ACCURACY_FINE);// 设置为最大精度\r
       criteria.setAltitudeRequired(false);//不要求海拔信息\r
@@ -516,8 +527,13 @@ public class NMEAListener implements NmeaListener, LocationListener {
 \r
       String provider = locationManager.getBestProvider(criteria, true);\r
 \r
+\r
       ICLogger.i("GPS StartListen with Provider " + provider);\r
+\r
+      if( Config.LOG_TOFILE) ICLogger.logToFile("GPS","GPS StartListen with Provider " + provider);\r
+\r
       this.locationManager.requestLocationUpdates(provider, 0L, 0.0F, this);\r
+\r
       this.listening = true;\r
       noSignalCount = 0;\r
       longitude = 0;\r
@@ -532,6 +548,7 @@ public class NMEAListener implements NmeaListener, LocationListener {
       return true;//gpsHotStart();\r
     }else{\r
       ICLogger.i(" location listening, skip !");\r
+      if( Config.LOG_TOFILE)ICLogger.logToFile("GPS"," location listening, skip !");\r
 \r
       return true;\r
     }\r
@@ -543,6 +560,9 @@ public class NMEAListener implements NmeaListener, LocationListener {
     this.locationManager.removeUpdates(this);\r
     this.listening = false;\r
     ICLogger.i("stopListen 定位 ");\r
+    if( Config.LOG_TOFILE)ICLogger.logToFile("GPS","stopListen 定位 ");\r
+    Settings.Secure.setLocationProviderEnabled(runtime.getContextProxy().getResolver(), GPS_PROVIDER, false);\r
+\r
   }\r
 \r
   public enum  GPS_CURRENT_STATUS {\r
index 9db2654..374b227 100644 (file)
@@ -9,7 +9,8 @@ import java.util.Objects;
 public class WakeLockUtil {\r
   public static PowerManager.WakeLock getScreenOnWakeLock(Context context, String tag) {\r
     PowerManager.WakeLock wakeLock = ((PowerManager)(context.getSystemService(Context.POWER_SERVICE))).newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, tag);\r
-    wakeLock.acquire(900000L);\r
+//    wakeLock.acquire(900000L);\r
+    wakeLock.acquire();\r
     return wakeLock;\r
   }\r
 }\r
index 32a286a..070d23e 100644 (file)
                 android:layout_width="80dp"
                 android:layout_height="wrap_content"
                 android:layout_weight="1"
-                android:text="重启服务" />
+                android:text="重启服务"
+                android:textSize="18sp" />
 
             <Button
                 android:id="@+id/btn_tools"
                 android:layout_width="80dp"
                 android:layout_height="wrap_content"
                 android:layout_weight="1"
-                android:text="工具" />
+                android:text="工具"
+                android:textSize="18sp" />
         </LinearLayout>
 
         <HorizontalScrollView
index 92fb4cc..79dd4f3 100644 (file)
             android:layout_width="wrap_content"\r
             android:layout_height="wrap_content"\r
             android:layout_weight="1"\r
-            android:text="上传日志" />\r
+            android:text="上传日志"\r
+            android:textSize="18sp" />\r
 \r
         <Button\r
             android:id="@+id/btn_simReset"\r
             android:layout_width="wrap_content"\r
             android:layout_height="wrap_content"\r
             android:layout_weight="1"\r
-            android:text="重置SIM" />\r
+            android:text="重置SIM"\r
+            android:textSize="18sp" />\r
 \r
         <Button\r
             android:id="@+id/btn_sim2"\r
             android:layout_width="wrap_content"\r
             android:layout_height="wrap_content"\r
             android:layout_weight="1"\r
-            android:text="GPS状态" />\r
+            android:text="GPS状态"\r
+            android:textSize="18sp" />\r
     </LinearLayout>\r
 \r
     <LinearLayout\r
             android:layout_width="wrap_content"\r
             android:layout_height="wrap_content"\r
             android:layout_weight="1"\r
-            android:text="模式3" />\r
+            android:text="模式3"\r
+            android:textSize="18sp" />\r
 \r
         <Button\r
             android:id="@+id/btn_location530"\r
             android:layout_width="wrap_content"\r
             android:layout_height="wrap_content"\r
             android:layout_weight="1"\r
-            android:text="模式5.30" />\r
+            android:text="模式5.30"\r
+            android:textSize="18sp" />\r
 \r
         <Button\r
             android:id="@+id/btn_location1"\r
             android:layout_width="wrap_content"\r
             android:layout_height="wrap_content"\r
             android:layout_weight="1"\r
-            android:text="模式1" />\r
+            android:text="模式1"\r
+            android:textSize="18sp" />\r
     </LinearLayout>\r
 \r
 </LinearLayout>
\ No newline at end of file
index 2d9e691..1e8cdd3 100644 (file)
@@ -4,5 +4,5 @@
 # Location of the SDK. This is only used by Gradle.\r
 # For customization when using a Version Control System, please read the\r
 # header note.\r
-#Sun Mar 15 23:29:11 CST 2020\r
-sdk.dir=E\:\\Android\\sdk\r
+#Mon Mar 16 11:44:29 CST 2020\r
+sdk.dir=C\:\\Users\\incar\\AppData\\Local\\Android\\Sdk\r