1、UI界面不强制重启服务,查看状态不会影响服务启动情况检查。
authorsnicker <snickersun@163.com>
Mon, 13 Apr 2020 00:20:38 +0000 (08:20 +0800)
committersnicker <snickersun@163.com>
Mon, 13 Apr 2020 00:20:38 +0000 (08:20 +0800)
2、添加WiFi状态检查
3、强制每次搜索WiFi网络后必然关闭WiFi,暂时先确保功耗问题。亮屏使用WiFi的事情,后面有需要时在调试。

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/MainActivity.java
app/src/main/java/com/enqualcomm/support/adapter/LBSHelper.java
app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java

index 213626a..ad6766c 100644 (file)
@@ -333,7 +333,7 @@ public class CoreService extends Service {
                     Util.turnOnWifiForConnect(runtime.getContextProxy().context, runtime);\r
                 }\r
             } else if ("android.intent.action.SCREEN_OFF".equals(param1Intent.getAction()) && Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)) {\r
-                CoreService.is_wifi_network_ok = true;\r
+               // CoreService.is_wifi_network_ok = true;\r
                 if (!runtime.isNoTurnOffWifiOnScreenOff()) {\r
                     //不关闭wifi when ScreenOff\r
                     Util.turnOffWifiForSleep(runtime.getContextProxy().context, runtime);\r
index 8c91a44..6b39500 100644 (file)
@@ -491,7 +491,7 @@ public class LocationClient {
     needCheckAgain=false;\r
     isLocating = false;\r
     startCheckTime=0L;\r
-\r
+    isWifiScanning=false;\r
 //    ICLogger.i(" stopCheckLocationResult Done ");\r
   }\r
 \r
index e278641..a6feb66 100644 (file)
@@ -46,7 +46,8 @@ public class MainActivity extends AppCompatActivity {
             try {
 
                 if (showmessage) {
-                    sb.append(CoreService.getInstance().getServerAlive());
+                    if (CoreService.getInstance()!=null)
+                        sb.append(CoreService.getInstance().getServerAlive());
                     tv.setText(sb.toString());
                 }
 
@@ -91,7 +92,7 @@ public class MainActivity extends AppCompatActivity {
 //            }
 //        });
 
-        startService(new Intent(this,CoreService.class));// protocol service
+//        startService(new Intent(this,CoreService.class));// protocol service
 
 //        double longitude=113.878339f;
 //        double latitude=22.580827f;
@@ -153,18 +154,23 @@ public class MainActivity extends AppCompatActivity {
             switch (view.getId()) {
                 case R.id.btnConnect:
                     //进行连接Socket:这里使用的是,在本地上开启了一个服务器。
-                    Util.ShowToast(CoreService.getInstance().runtime,"Stop ProtocolService!");
-                    stopService(new Intent(MainActivity.this,CoreService.class));// protocol service
-
-                    //delay 5秒再重启
+                    if (CoreService.getInstance()!=null)
+                    Util.ShowToast(CoreService.getInstance().runtime,"Start ProtocolService!");
+                    startService(new Intent(MainActivity.this,CoreService.class));// protocol service
                     Observable.timer(5000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {
                         public void call(Long param1Long) {
-                            Util.ShowToast(CoreService.getInstance().runtime,"Start ProtocolService!");
+                            if (CoreService.getInstance()!=null) Util.ShowToast(CoreService.getInstance().runtime,"Stop ProtocolService!");
+                            stopService(new Intent(MainActivity.this,CoreService.class));// protocol service
+                        }
+                    });
+                    //delay 5秒再重启
+                    Observable.timer(10000L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {
+                        public void call(Long param1Long) {
+                            if (CoreService.getInstance()!=null) Util.ShowToast(CoreService.getInstance().runtime,"Start ProtocolService!");
                             startService(new Intent(MainActivity.this,CoreService.class));// protocol service
                         }
                     });
 
-
                     break;
 
             }
index 5208662..f20c175 100644 (file)
@@ -39,6 +39,8 @@ import java.util.List;
 import java.util.concurrent.TimeUnit;\r
 \r
 import rx.Observable;\r
+import rx.Single;\r
+import rx.android.schedulers.AndroidSchedulers;\r
 import rx.functions.Action1;\r
 \r
 import static android.net.wifi.WifiManager.WIFI_STATE_DISABLED;\r
@@ -133,25 +135,37 @@ public class LBSHelper {
         if (mMyWifiListener != null) {\r
             mMyWifiListener.getWifiInfoCallBack(wifiInfoResult);\r
 //            mMyWifiListener.getWifiInfoCallBack(null);\r
-            Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
+\r
+//            Single.just(null).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Object>() {\r
+//            public void call(Object param1Object) {\r
+\r
+            Observable.timer(500L, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Long>() {\r
                 public void call(Long param1Long) {\r
+\r
                     //由于wifi状态不好确认客户是如何设置的,干脆只有屏幕灭的时候才考虑关闭wifi ,防止在开启屏幕用来视频的时候被后台关掉\r
                     ICLogger.i("setWifiEnabled false");\r
-                    if(SimSignalUtil.isScreenON(runtime.getContextProxy().context)==false) {\r
+//                    if(SimSignalUtil.isScreenON(runtime.getContextProxy().context)==false) {\r
                         if (runtime.isNoTurnOffWifiOnScreenOff() || DeviceInfoUtil.isFactoryTestTopActivity(runtime.getContextProxy().context)) {\r
                             //如果 NoTurnOffWifiOnScreenOff 开关 开启,且是屏灭,或者是在工厂测试模式,则原来什么状态就什么状态。\r
+                            ICLogger.i("isNoTurnOffWifiOnScreenOff or In Factory Mode");\r
                             if (!IS_HASOPEN && IS_OPEN) {\r
-                                 wifiManager.setWifiEnabled(false);\r
+//                                wifiManager.setWifiEnabled(false);\r
                                 IS_OPEN = false;\r
                             }\r
-                        } else if (!runtime.isNoTurnOffWifiOnScreenOff()) {\r
+                        } else  {\r
                             //如果 NoTurnOffWifiOnScreenOff 开关 关闭,且是屏灭,则关闭wifi省电\r
+                            ICLogger.i("isTurnOffWifiOnScreenOff");\r
                             wifiManager.setWifiEnabled(false);\r
                             IS_OPEN = false;\r
                             IS_HASOPEN = false;\r
 \r
                         }\r
-                    }\r
+//                    }else{\r
+//                        ICLogger.i("isTurnOffWifiOnScreenOff");\r
+//                        wifiManager.setWifiEnabled(false);\r
+//                        IS_OPEN = false;\r
+//                        IS_HASOPEN = false;\r
+//                    }\r
                     ICLogger.i("setWifiEnabled done");\r
 \r
 \r
index 66ad5ba..cab7a3b 100644 (file)
@@ -244,6 +244,7 @@ public class DeviceInfoUtil {
             .append(" at ").append(runtime.getHRS().getTestTime())\r
             .append("\nrealimei:").append(PhoneUtils.getIMEI(runtime.getContextProxy().context))\r
             .append("\n").append(runtime.getLBSMultiStationData())\r
+            .append("\nWiFi Status ").append(Util.isWifiIsOpen(runtime.getContextProxy().context,runtime))\r
             .toString();\r
   }\r
   public static String getShortDeviceInfo(Runtime runtime){\r