Ver Fonte

1.3.14 optimize:优化拉取日志,修改websocket新的访问地址。

xwh há 3 meses atrás
pai
commit
c34c1406d8

+ 2 - 1
app/build.gradle

@@ -44,7 +44,8 @@ android {
             // 服务器地址
             // 通用
             buildConfigField("String", "BASE_URL", "\"https://hhomc.hz-hanghui.com:8096/\"")
-            buildConfigField("String", "BASE_URL_WEBSOCKET", "\"wss://hhomc.hz-hanghui.com:18096/\"")
+          //  buildConfigField("String", "BASE_URL_WEBSOCKET", "\"wss://hhomc.hz-hanghui.com:18096/\"")
+            buildConfigField("String", "BASE_URL_WEBSOCKET", "\"ws://115.227.34.58:18096/\"")
 
             // 故宫
 //            buildConfigField("String", "BASE_URL", "\"https://aiotota.dpm.org.cn/\"")

+ 17 - 2
app/src/main/java/com/hh/hhomc/bean/ServerActionBean.java

@@ -1,5 +1,6 @@
 package com.hh.hhomc.bean;
 
+import java.util.ArrayList;
 import java.util.List;
 
 public class ServerActionBean {
@@ -55,6 +56,13 @@ public class ServerActionBean {
     }
 
     public List<String> getPaths() {
+        if(paths==null){
+            synchronized (ServerActionBean.class){
+                if(paths==null){
+                    paths=new ArrayList<>();
+                }
+            }
+        }
         return paths;
     }
 
@@ -103,6 +111,13 @@ public class ServerActionBean {
     }
 
     public List<LogsDTO> getLogs() {
+        if(logs==null){
+            synchronized (ServerActionBean.class){
+                if(logs==null){
+                    logs=new ArrayList<>();
+                }
+            }
+        }
         return logs;
     }
 
@@ -157,8 +172,8 @@ public class ServerActionBean {
                 ", op='" + op + '\'' +
                 ", msg='" + msg + '\'' +
                 ", logType='" + logType + '\'' +
-                ", logs=" + logs +
-                ", paths=" + paths +
+                ", logs=" + (logs == null ? "" : getLogs()) +
+                ", paths=" + (paths == null ? "" : getPaths()) +
                 ", logDirPath='" + logDirPath + '\'' +
                 ", appOnline=" + appOnline +
                 ", packageName='" + packageName + '\'' +

+ 10 - 3
app/src/main/java/com/hh/hhomc/services/BackgroundService.java

@@ -633,6 +633,9 @@ public class BackgroundService extends Service {
                     mWebSocketClient = new WebSocketClient(uri) {
                         @Override
                         public void onOpen(ServerHandshake serverHandshake) {
+                            sendTime=0;
+                            getmHandler().removeMessages(WHAT_HEART);
+                            getmHandler().sendEmptyMessageDelayed(WHAT_HEART, 100);//开启心跳检测
                             AppLogUtils.e("onOpen: ");
                             isWebsocketConnect = true;
 
@@ -721,6 +724,8 @@ public class BackgroundService extends Service {
                             // 检查在OTA平台设备列表是否已经添加设备
                             AppLogUtils.e("onClose: ");
                             isWebsocketConnect = false;
+                            getmHandler().removeMessages(WHAT_HEART);
+                            getmHandler().sendEmptyMessageDelayed(WHAT_HEART, 100);//开启心跳检测
                         }
 
                         @Override
@@ -728,6 +733,8 @@ public class BackgroundService extends Service {
                             AppLogUtils.e("onError--e = " + e.toString());
                             // java.net.UnknownHostException: hhomc.hz-hanghui.com
                             isWebsocketConnect = false;
+                            getmHandler().removeMessages(WHAT_HEART);
+                            getmHandler().sendEmptyMessageDelayed(WHAT_HEART, 100);//开启心跳检测
                         }
                     };
                 }
@@ -738,8 +745,8 @@ public class BackgroundService extends Service {
 //            if (heartBeatRunnable != null) {
 //                mHandler.removeCallbacks(heartBeatRunnable);
 //            }
-            getmHandler().removeMessages(WHAT_HEART);
-            getmHandler().sendEmptyMessageDelayed(WHAT_HEART,5 * 1000);//开启心跳检测
+
+
 
 
 //            mHandler.post(new Runnable() {
@@ -1102,7 +1109,7 @@ public class BackgroundService extends Service {
     }
 
 
-    private long sendTime = 0L;
+    private volatile long sendTime = 0L;
     // 定时任务,发送心跳包
     private Handler mHandler;
 

+ 2 - 2
config.gradle

@@ -7,8 +7,8 @@ ext {
 //            minSdkVersion    : 24,
             minSdkVersion    : 21,
             targetSdkVersion : 30,
-            versionCode      : 20,
-            versionName      : "1.3.13"
+            versionCode      : 21,
+            versionName      : "1.3.14"
     ]
     //依赖 配置
     dependencies = [