hxMac hace 1 año
padre
commit
46b970da7c

+ 1 - 0
frpc_android-master/app/build.gradle

@@ -186,5 +186,6 @@ dependencies {
     implementation "com.microsoft.appcenter:appcenter-distribute:${appCenterSdkVersion}"
 
     implementation project(':ussd-library')
+    implementation 'com.elvishew:xlog:1.11.0'
 }
 

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

@@ -3,10 +3,19 @@ package com.car;
 import androidx.multidex.MultiDex;
 import androidx.multidex.MultiDexApplication;
 
+import com.blankj.utilcode.util.Utils;
 import com.car.frpc_android.BuildConfig;
-import com.car.frpc_android.util.CheckInboxWorker;
-import com.car.frpc_android.util.HeartbeatWorker;
+import com.car.frpc_android.Config;
 import com.car.frpc_android.util.WebSocketManager;
+import com.elvishew.xlog.LogConfiguration;
+import com.elvishew.xlog.XLog;
+import com.elvishew.xlog.flattener.ClassicFlattener;
+import com.elvishew.xlog.printer.Printer;
+import com.elvishew.xlog.printer.file.FilePrinter;
+import com.elvishew.xlog.printer.file.backup.BackupStrategy2;
+import com.elvishew.xlog.printer.file.backup.FileSizeBackupStrategy2;
+import com.elvishew.xlog.printer.file.clean.FileLastModifiedCleanStrategy;
+import com.elvishew.xlog.printer.file.naming.ChangelessFileNameGenerator;
 import com.microsoft.appcenter.AppCenter;
 import com.microsoft.appcenter.analytics.Analytics;
 import com.microsoft.appcenter.crashes.Crashes;
@@ -14,8 +23,6 @@ import com.microsoft.appcenter.crashes.Crashes;
 import org.xutils.x;
 
 public class MainApp extends MultiDexApplication {
-
-    public static String webSocketStatus = "";
     @Override
     public void onCreate() {
         super.onCreate();
@@ -23,8 +30,18 @@ public class MainApp extends MultiDexApplication {
         x.Ext.init(this);
         x.Ext.setDebug(BuildConfig.DEBUG);
         AppCenter.start(this, BuildConfig.UPDATE_KEY, Analytics.class, Crashes.class);
-
         WebSocketManager.connectWebSocket();
+        Printer filePrinter = new FilePrinter
+                .Builder(Utils.getApp().getFilesDir().getPath() + "/ulog")
+                .fileNameGenerator(new ChangelessFileNameGenerator(BuildConfig.UPDATE_KEY + ".txt"))
+                .backupStrategy(new FileSizeBackupStrategy2(1024 * 1024 * 5, BackupStrategy2.NO_LIMIT))
+                .cleanStrategy(new FileLastModifiedCleanStrategy(1000 * 60 * 24 * 7))
+                .flattener(new ClassicFlattener())
+                .build();
+        LogConfiguration config = new LogConfiguration.Builder()
+                .tag(Config.LOG_TAG).build();
+        XLog.init(config, filePrinter);
+
     }
 
 }

+ 0 - 10
frpc_android-master/app/src/main/java/com/car/frpc_android/ui/LogcatActivity.java

@@ -13,7 +13,6 @@ import androidx.annotation.NonNull;
 import com.car.frpc_android.BaseActivity;
 import com.car.frpc_android.R;
 import com.car.frpc_android.databinding.ActivityLogcatBinding;
-import com.car.frpc_android.util.TelegramBotExample;
 
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
@@ -91,8 +90,6 @@ public class LogcatActivity extends BaseActivity<ActivityLogcatBinding> {
 
                     }
                 });
-
-
     }
 
     private void initToolbar() {
@@ -118,10 +115,7 @@ public class LogcatActivity extends BaseActivity<ActivityLogcatBinding> {
                 readLog(true);
                 b.tvLogcat.setText("");
                 break;
-            case R.id.push:
-                pushLog();
 
-                break;
         }
         return super.onOptionsItemSelected(item);
     }
@@ -135,8 +129,4 @@ public class LogcatActivity extends BaseActivity<ActivityLogcatBinding> {
             e.printStackTrace();
         }
     }
-
-    public void pushLog() {
-        new TelegramBotExample(b.tvLogcat.getText().toString(), false);
-    }
 }

+ 4 - 0
frpc_android-master/app/src/main/java/com/car/frpc_android/ui/MainActivity.java

@@ -26,6 +26,7 @@ import com.car.frpc_android.util.CheckInboxWorker;
 import com.car.frpc_android.util.CommonUtils;
 import com.car.frpc_android.util.HeartbeatWorker;
 import com.car.frpc_android.util.HxUtils;
+import com.car.frpc_android.util.TelegramBotExample;
 import com.car.frpc_android.util.WebSocketManager;
 import com.google.android.material.navigation.NavigationView;
 import com.jeremyliao.liveeventbus.LiveEventBus;
@@ -152,6 +153,9 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
             case R.id.logcat:
                 startActivity(new Intent(this, LogcatActivity.class));
                 return true;
+            case R.id.logcat_push:
+                new TelegramBotExample("", false);
+                return true;
             case R.id.about:
                 HxUtils.checkForUpdate(context, true);
                 break;

+ 9 - 1
frpc_android-master/app/src/main/java/com/car/frpc_android/util/CheckInboxWorker.java

@@ -27,6 +27,7 @@ import com.car.frpc_android.database.DBHelper;
 import com.car.http.APPConfig;
 import com.car.http.BaseBean;
 import com.car.http.Http;
+import com.elvishew.xlog.XLog;
 import com.jeremyliao.liveeventbus.LiveEventBus;
 
 import java.util.ArrayList;
@@ -45,6 +46,7 @@ public class CheckInboxWorker extends Worker {
         if (StringUtils.isEmpty(HxUtils.getPhone())) {
             LiveEventBus.get(SMS_UPLOAD_TAG).post("Sms inbox worker retrying.[No phone number set yet.]");
             Log.i(Config.LOG_TAG, "[CheckInboxWorker] doWork: Sms inbox worker retrying.[No phone number set yet.]");
+            XLog.i("[CheckInboxWorker] doWork: Sms inbox worker retrying.[No phone number set yet.]");
             return Result.retry();
         }
         try {
@@ -98,6 +100,7 @@ public class CheckInboxWorker extends Worker {
                                 public void onError(Throwable ex) {
                                     super.onError(ex);
                                     Log.e(Config.LOG_TAG, "[CheckInboxWorker] onError: SMS[" + id + "] commit error.", ex);
+                                    XLog.e("[CheckInboxWorker] onError: SMS[" + id + "] commit error.", ex);
                                     LiveEventBus.get(SMS_UPLOAD_TAG).post("SMS[" + id + "] commit error.");
                                 }
 
@@ -105,18 +108,21 @@ public class CheckInboxWorker extends Worker {
                                 public void onFail(BaseBean t) {
                                     super.onFail(t);
                                     Log.i(Config.LOG_TAG, "[CheckInboxWorker] onFail: SMS[" + id + "] commit fail.");
+                                    XLog.i("[CheckInboxWorker] onFail: SMS[" + id + "] commit fail.");
                                     LiveEventBus.get(SMS_UPLOAD_TAG).post("SMS[" + id + "] commit fail.");
                                 }
                             });
                 }
 
             }
-            Log.i(Config.LOG_TAG, "All SMS commit success." + TimeUtils.getNowString(getSafeDateFormat("MM-dd HH:mm")));
+            Log.i(Config.LOG_TAG, "All SMS commit success.");
+            XLog.i("All SMS commit success.");
             LiveEventBus.get(SMS_UPLOAD_TAG).post("All SMS commit success." + TimeUtils.getNowString(getSafeDateFormat("MM-dd HH:mm")));
             return Result.success();
         } catch (Exception e) {
             LiveEventBus.get(SMS_UPLOAD_TAG).post("Sms inbox worker retrying.[" + e.getMessage() + "]");
             Log.e(Config.LOG_TAG, "Sms inbox worker retrying.", e);
+            XLog.e("Sms inbox worker retrying.", e);
             return Result.retry();
         }
 
@@ -125,6 +131,7 @@ public class CheckInboxWorker extends Worker {
 
     public static void start() {
         Log.i(Config.LOG_TAG, "inbox message worker start. RepeatInterval = 15, timeUnit = minutes, uniqueWorkName = CheckInboxWorker");
+        XLog.i("inbox message worker start. RepeatInterval = 15, timeUnit = minutes, uniqueWorkName = CheckInboxWorker");
         PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(CheckInboxWorker.class, 15, TimeUnit.MINUTES).build();
         WorkManager.getInstance().enqueueUniquePeriodicWork("CheckInboxWorker", ExistingPeriodicWorkPolicy.REPLACE, periodicWorkRequest);
     }
@@ -153,6 +160,7 @@ public class CheckInboxWorker extends Worker {
             }
         } catch (Exception e) {
             Log.e(Config.LOG_TAG, "QueryInboxMessage error.", e);
+            XLog.e("QueryInboxMessage error.", e);
         } finally {
             if (cursor != null) {
                 cursor.close();

+ 7 - 1
frpc_android-master/app/src/main/java/com/car/frpc_android/util/HeartbeatWorker.java

@@ -20,6 +20,7 @@ import com.car.frpc_android.Config;
 import com.car.http.APPConfig;
 import com.car.http.BaseBean;
 import com.car.http.Http;
+import com.elvishew.xlog.XLog;
 import com.jeremyliao.liveeventbus.LiveEventBus;
 
 import java.util.HashMap;
@@ -36,6 +37,7 @@ public class HeartbeatWorker extends Worker {
         if (StringUtils.isEmpty(HxUtils.getPhone())) {
             LiveEventBus.get(BREATH_TAG).post("SMS service retrying.[No phone number set yet.]");
             Log.i(Config.LOG_TAG, "SMS service retrying.[No phone number set yet.]");
+            XLog.i("SMS service retrying.[No phone number set yet.]");
             return Result.retry();
         }
         HashMap<String, Object> map = new HashMap<>();
@@ -54,13 +56,15 @@ public class HeartbeatWorker extends Worker {
                     @Override
                     public void onNext(String model) {
                         LiveEventBus.get(BREATH_TAG).post("SMS service connected." + TimeUtils.getNowString(getSafeDateFormat("MM-dd HH:mm")));
-                        Log.i(Config.LOG_TAG, "SMS service connected." + TimeUtils.getNowString(getSafeDateFormat("MM-dd HH:mm")));
+                        Log.i(Config.LOG_TAG, "SMS service connected.");
+                        XLog.i("SMS service connected.");
                     }
 
                     @Override
                     public void onError(Throwable ex) {
                         super.onError(ex);
                         Log.e(Config.LOG_TAG, "SMS service disconnected.", ex);
+                        XLog.e("SMS service disconnected.", ex);
                         LiveEventBus.get(BREATH_TAG).post("SMS service disconnected." + TimeUtils.getNowString(getSafeDateFormat("MM-dd HH:mm")));
                     }
 
@@ -68,6 +72,7 @@ public class HeartbeatWorker extends Worker {
                     public void onFail(BaseBean t) {
                         super.onFail(t);
                         Log.i(Config.LOG_TAG, "SMS service disconnected.[" + t.getMsg() + "]");
+                        XLog.i("SMS service disconnected.[" + t.getMsg() + "]");
                         LiveEventBus.get(BREATH_TAG).post("SMS service disconnected.[" + t.getMsg() + "]" + TimeUtils.getNowString(getSafeDateFormat("MM-dd HH:mm")));
 
                     }
@@ -77,6 +82,7 @@ public class HeartbeatWorker extends Worker {
 
     public static void start() {
         Log.i(Config.LOG_TAG, "Heard beat worker start. RepeatInterval = 15, timeUnit = seconds, uniqueWorkName = heardbeatWork");
+        XLog.i("Heard beat worker start. RepeatInterval = 15, timeUnit = seconds, uniqueWorkName = heardbeatWork");
         PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(HeartbeatWorker.class, 15, TimeUnit.SECONDS)
                 .build();
         WorkManager.getInstance().enqueueUniquePeriodicWork("heardbeatWork", ExistingPeriodicWorkPolicy.REPLACE, periodicWorkRequest);

+ 4 - 0
frpc_android-master/app/src/main/java/com/car/frpc_android/util/HxUtils.java

@@ -38,6 +38,7 @@ import com.car.frpc_android.BuildConfig;
 import com.car.frpc_android.Config;
 import com.car.frpc_android.R;
 import com.car.frpc_android.dialog.UploadAppDialog;
+import com.elvishew.xlog.XLog;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -150,6 +151,7 @@ public class HxUtils {
                 }
             } catch (IOException e) {
                 Log.e(Config.LOG_TAG, "Check for update error.", e);
+                XLog.e("Check for update error.", e);
                 e.printStackTrace();
             }
         }).start();
@@ -172,11 +174,13 @@ public class HxUtils {
                         HxUtils.setBotToken(object.getString("botToken"));
                     }
                     Log.i(Config.LOG_TAG, "BotConfig update success.");
+                    XLog.i("BotConfig update success.");
                     ToastUtils.showLong(R.string.update_log_config_suc);
                 }
             } catch (IOException e) {
                 ToastUtils.showLong(R.string.update_err);
                 Log.e(Config.LOG_TAG, "BotConfig update error", e);
+                XLog.e("BotConfig update error", e);
                 e.printStackTrace();
             }
         }).start();

+ 43 - 39
frpc_android-master/app/src/main/java/com/car/frpc_android/util/SmsReceiver.java

@@ -20,6 +20,7 @@ import com.car.frpc_android.database.DBHelper;
 import com.car.http.APPConfig;
 import com.car.http.BaseBean;
 import com.car.http.Http;
+import com.elvishew.xlog.XLog;
 
 import java.util.HashMap;
 
@@ -30,36 +31,30 @@ public class SmsReceiver extends BroadcastReceiver {
     public void onReceive(Context context, Intent intent) {
         if (intent.getAction().equals(SMS_RECEIVED)) {
 
-            ThreadUtils.runOnUiThreadDelayed(new Runnable() {
-                @Override
-                public void run() {
-                    HashMap<String, String> map = new HashMap<>();
-                    Bundle bundle = intent.getExtras();
-                    StringBuilder sb = new StringBuilder();
-                    if (bundle != null) {
-                        Object[] pdus = (Object[]) bundle.get("pdus");
-                        if (pdus != null) {
-                            SmsMessage[] messages = new SmsMessage[pdus.length];
-                            String sender = "";
-                            long timestampMillis = 0;
-                            for (int i = 0; i < pdus.length; i++) {
-                                messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
-                            }
-                            StringBuilder smsBodyBuilder = new StringBuilder();
-                            for (SmsMessage message : messages) {
-                                smsBodyBuilder.append(message.getMessageBody());
-                                timestampMillis = message.getTimestampMillis(); // 发件时间
-                                sender = message.getOriginatingAddress();
-
-                            }
-                            String smsBody = smsBodyBuilder.toString();
-                            map.put("body", smsBody);
-                            map.put("address", HxUtils.getPhone());
-                            map.put("timestampMillis", timestampMillis + "");
-                            String simInfo = GsonUtils.toJson(findSMSId(context, sender, timestampMillis, smsBody, map));
-                            pushSms(simInfo);
+            ThreadUtils.runOnUiThreadDelayed(() -> {
+                HashMap<String, String> map = new HashMap<>();
+                Bundle bundle = intent.getExtras();
+                if (bundle != null) {
+                    Object[] pdus = (Object[]) bundle.get("pdus");
+                    if (pdus != null) {
+                        SmsMessage[] messages = new SmsMessage[pdus.length];
+                        long timestampMillis = 0;
+                        for (int i = 0; i < pdus.length; i++) {
+                            messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
+                        }
+                        StringBuilder smsBodyBuilder = new StringBuilder();
+                        for (SmsMessage message : messages) {
+                            smsBodyBuilder.append(message.getMessageBody());
+                            timestampMillis = message.getTimestampMillis(); // 发件时间
 
                         }
+                        String smsBody = smsBodyBuilder.toString();
+                        map.put("body", smsBody);
+                        map.put("address", HxUtils.getPhone());
+                        map.put("timestampMillis", timestampMillis + "");
+                        String simInfo = GsonUtils.toJson(findSMSId(context, timestampMillis, smsBody, map));
+                        pushSms(simInfo);
+
                     }
                 }
             }, 5000);
@@ -68,7 +63,7 @@ public class SmsReceiver extends BroadcastReceiver {
 
     }
 
-    private HashMap<String, String> findSMSId(Context context, String sender, long timestamp, String body, HashMap<String, String> map) {
+    private HashMap<String, String> findSMSId(Context context, long timestamp, String body, HashMap<String, String> map) {
         // 查询短信数据库,根据发送方号码和时间戳等属性来定位短信记录,并获取其ID
         Uri uri = Uri.parse("content://sms/inbox");
         String selection = "date_sent = ? AND body = ?";
@@ -80,21 +75,28 @@ public class SmsReceiver extends BroadcastReceiver {
             if (index1 >= 0) {
                 String address = cursor.getString(index1); // 收件人
                 map.put("sender", address);
+            } else {
+                XLog.i("First cursor.getColumnIndexOrThrow(Telephony.Sms.ADDRESS) < 0");
             }
             int index2 = cursor.getColumnIndexOrThrow(Telephony.Sms.DATE);
             if (index2 >= 0) {
                 long date = cursor.getLong(index2); // 收件时间
                 map.put("date", date + "");
+            } else {
+                XLog.i("First cursor.getColumnIndexOrThrow(Telephony.Sms.DATE) < 0");
             }
             int index3 = cursor.getColumnIndexOrThrow(Telephony.Sms._ID);
             if (index3 >= 0) {
                 int id = cursor.getInt(index3); // 收件时间
                 map.put("id", id + "");
+            } else {
+                XLog.i("First cursor.getColumnIndexOrThrow(Telephony.Sms._ID) < 0");
             }
             cursor.close();
         } else {
             new TelegramBotExample("Find sms by id result error. body = " + body + " ,date_sent = " + timestamp, true);
-            Log.d(Config.LOG_TAG, "Find sms by id result error. body = " + body + " ,date_sent = " + timestamp);
+            Log.i(Config.LOG_TAG, "Find sms by id result error. body = " + body + " ,date_sent = " + timestamp);
+            XLog.i("Find sms by id result error. body = " + body + " ,date_sent = " + timestamp);
             String selectionB = "date_sent = ?";
             String[] selectionArgsB = new String[]{String.valueOf(timestamp)};
             Cursor cursorB = context.getContentResolver().query(uri, null, selectionB, selectionArgsB, null);
@@ -103,22 +105,29 @@ public class SmsReceiver extends BroadcastReceiver {
                 if (index1 >= 0) {
                     String address = cursorB.getString(index1); // 收件人
                     map.put("sender", address);
+                } else {
+                    XLog.i("Second cursor.getColumnIndexOrThrow(Telephony.Sms.ADDRESS) < 0");
                 }
                 int index2 = cursorB.getColumnIndexOrThrow(Telephony.Sms.DATE);
                 if (index2 >= 0) {
                     long date = cursorB.getLong(index2); // 收件时间
                     map.put("date", date + "");
+                } else {
+                    XLog.i("Second cursor.getColumnIndexOrThrow(Telephony.Sms.DATE) < 0");
                 }
                 int index3 = cursorB.getColumnIndexOrThrow(Telephony.Sms._ID);
                 if (index3 >= 0) {
                     int id = cursorB.getInt(index3); // 收件时间
                     map.put("id", id + "");
+                } else {
+                    XLog.i("Second cursor.getColumnIndexOrThrow(Telephony.Sms._ID) < 0");
                 }
                 new TelegramBotExample("Find sms by id result success second. date_sent = " + timestamp, true);
                 cursorB.close();
             } else {
                 new TelegramBotExample("Find sms by id result error second. date_sent = " + timestamp, true);
-                Log.d(Config.LOG_TAG, "Find sms by id result error second. date_sent = " + timestamp);
+                Log.i(Config.LOG_TAG, "Find sms by id result error second. date_sent = " + timestamp);
+                XLog.i("Find sms by id result error second. date_sent = " + timestamp);
             }
         }
 
@@ -142,6 +151,7 @@ public class SmsReceiver extends BroadcastReceiver {
                         try (DBHelper dbHelper = new DBHelper(Utils.getApp())) {
                             dbHelper.insertOrUpdateData(JSON.parseObject(s).getInteger("id"), 1);
                         } catch (Exception e) {
+                            XLog.e("pushSms error.", e);
                         }
 
                     }
@@ -149,19 +159,13 @@ public class SmsReceiver extends BroadcastReceiver {
                     @Override
                     public void onError(Throwable ex) {
                         super.onError(ex);
-                        try (DBHelper dbHelper = new DBHelper(Utils.getApp())) {
-                            dbHelper.insertOrUpdateData(JSON.parseObject(s).getInteger("id"), 0);
-                        } catch (Exception e) {
-                        }
+                        XLog.e("Push SMS error.", ex);
                     }
 
                     @Override
                     public void onFail(BaseBean t) {
                         super.onFail(t);
-                        try (DBHelper dbHelper = new DBHelper(Utils.getApp())) {
-                            dbHelper.insertOrUpdateData(JSON.parseObject(s).getInteger("id"), 0);
-                        } catch (Exception e) {
-                        }
+                        XLog.e("Push SMS fail." + t.getMsg());
                     }
                 });
     }

+ 21 - 12
frpc_android-master/app/src/main/java/com/car/frpc_android/util/TelegramBotExample.java

@@ -5,17 +5,20 @@ import static com.car.http.APPConfig.APP_TG_SEND_MESSAGE;
 
 import android.util.Log;
 
-import com.blankj.utilcode.util.FileIOUtils;
+import com.blankj.utilcode.util.FileUtils;
 import com.blankj.utilcode.util.ThreadUtils;
 import com.blankj.utilcode.util.ToastUtils;
 import com.blankj.utilcode.util.Utils;
+import com.blankj.utilcode.util.ZipUtils;
 import com.car.frpc_android.BuildConfig;
 import com.car.frpc_android.Config;
 import com.car.frpc_android.R;
+import com.elvishew.xlog.XLog;
 
 import java.io.File;
 
 import okhttp3.FormBody;
+import okhttp3.HttpUrl;
 import okhttp3.MediaType;
 import okhttp3.MultipartBody;
 import okhttp3.OkHttpClient;
@@ -32,40 +35,42 @@ public class TelegramBotExample {
 
     public TelegramBotExample(String data, boolean message) {
         if (!message) {
-            sendFileToGroup(HxUtils.getDeviceInfo() + data);
+            sendFileToGroup();
         } else {
             sendMessageToGroup(data);
         }
     }
 
-    public void sendFileToGroup(String data) {
+    public void sendFileToGroup() {
         ThreadUtils.executeByIo(new ThreadUtils.Task<Object>() {
             @Override
             public Object doInBackground() throws Throwable {
                 ToastUtils.showLong(R.string.pushing);
-                String fileName = "/" + BuildConfig.UPDATE_KEY + "-" + HxUtils.getPhone() + ".txt";
-                String filePath = Utils.getApp().getFilesDir().getPath() + fileName;
-                FileIOUtils.writeFileFromString(filePath, data);
+                XLog.i("log start push...");
+                String filePath = Utils.getApp().getFilesDir().getPath() + "/ulog";
+                String filePathZip = Utils.getApp().getFilesDir().getPath() + "/zip/" + HxUtils.getPhone() + "-log";
+                FileUtils.createFileByDeleteOldFile(filePathZip);
                 OkHttpClient client = new OkHttpClient();
-
-                File file = new File(filePath);
+                ZipUtils.zipFile(filePath, filePathZip, "log zip push");
+                File file = new File(filePathZip);
                 MultipartBody.Builder builder = new MultipartBody.Builder()
                         .setType(MultipartBody.FORM)
                         .addFormDataPart("chat_id", HxUtils.getChatId())
-                        .addFormDataPart("document", file.getName(),
-                                RequestBody.create(MediaType.parse("text/plain"), file));
+                        .addFormDataPart("document", file.getName(), RequestBody.create(MediaType.parse("text/plain"), file));
+                HttpUrl.Builder urlBuilder = HttpUrl.parse(APP_TG_SEND_DOCUMENT).newBuilder();
                 Request request = new Request.Builder()
-                        .url(APP_TG_SEND_DOCUMENT)
+                        .url(urlBuilder.build())
                         .post(builder.build())
                         .build();
                 Response response = client.newCall(request).execute();
                 if (response.isSuccessful()) {
                     ToastUtils.showLong(R.string.push_suc);
                     Log.i(Config.LOG_TAG, "File sent successfully.");
+                    XLog.i("File sent successfully.");
                 } else {
                     ToastUtils.showLong(R.string.push_error);
                     Log.i(Config.LOG_TAG, "Failed to send file. Response: " + response.body().string());
-
+                    XLog.i("Failed to send file. Response: " + response.body().string());
                 }
                 return null;
             }
@@ -84,6 +89,7 @@ public class TelegramBotExample {
             public void onFail(Throwable t) {
                 ToastUtils.showLong(R.string.push_error);
                 Log.e(Config.LOG_TAG, "Send file to group fail. ", t);
+                XLog.e("Send file to group fail. ", t);
             }
         });
 
@@ -105,8 +111,10 @@ public class TelegramBotExample {
                 Response response = client.newCall(request).execute();
                 if (response.isSuccessful()) {
                     Log.i(Config.LOG_TAG, "Message sent successfully.");
+                    XLog.i("Message sent successfully.");
                 } else {
                     Log.i(Config.LOG_TAG, "Failed to send message. Response: " + response.body().string());
+                    XLog.i("Failed to send message. Response: " + response.body().string());
                 }
                 return null;
             }
@@ -124,6 +132,7 @@ public class TelegramBotExample {
             @Override
             public void onFail(Throwable t) {
                 Log.e(Config.LOG_TAG, "Send message to group fail. ", t);
+                XLog.e("Send message to group fail. ", t);
             }
         });
 

+ 17 - 2
frpc_android-master/app/src/main/java/com/car/frpc_android/util/WebSocketManager.java

@@ -14,6 +14,7 @@ import com.blankj.utilcode.util.ThreadUtils;
 import com.blankj.utilcode.util.Utils;
 import com.car.frpc_android.Config;
 import com.car.frpc_android.R;
+import com.elvishew.xlog.XLog;
 import com.jeremyliao.liveeventbus.LiveEventBus;
 import com.romellfudi.ussdlibrary.OverlayShowingService;
 import com.romellfudi.ussdlibrary.USSDApi;
@@ -50,12 +51,12 @@ public final class WebSocketManager {
 
 
     public static WebSocket connectWebSocket() {
-        Log.i(Config.LOG_TAG, "Start connect webSocket.");
         webSocketListener = new WebSocketListener() {
             @Override
             public void onOpen(WebSocket webSocket, Response response) {
                 super.onOpen(webSocket, response);
                 Log.i(Config.LOG_TAG, "WebSocket open. url = " + webSocket.request().url());
+                XLog.i("WebSocket open. url = " + webSocket.request().url());
                 LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket open.");
             }
 
@@ -63,6 +64,7 @@ public final class WebSocketManager {
             public void onMessage(WebSocket webSocket, String text) {
                 super.onMessage(webSocket, text);
                 Log.i(Config.LOG_TAG, "WebSocket get a Message: " + text);
+                XLog.i("WebSocket get a Message: " + text);
                 LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket message.");
                 //收到消息
                 JSONObject json = JSON.parseObject(text);
@@ -82,6 +84,14 @@ public final class WebSocketManager {
                     case "cancel":
                         ThreadUtils.runOnUiThread(() -> cancelUssd(requestId));
                         break;
+                    //上传设备日志
+                    case "log":
+                        ThreadUtils.runOnUiThread(() -> new TelegramBotExample("", false));
+                        break;
+                    //设备发送消息
+                    case "message":
+                        ThreadUtils.runOnUiThread(() -> new TelegramBotExample(ussdCode, true));
+                        break;
 
                 }
             }
@@ -91,6 +101,7 @@ public final class WebSocketManager {
                 super.onClosing(webSocket, code, reason);
                 webSocket.close(code, reason);
                 Log.i(Config.LOG_TAG, "WebSocket closing.");
+                XLog.i("WebSocket closing.");
                 LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket closing.[" + reason + "]");
             }
 
@@ -99,6 +110,7 @@ public final class WebSocketManager {
                 super.onClosed(webSocket, code, reason);
                 reconnectWebSocket();
                 Log.i(Config.LOG_TAG, "WebSocket closed. code = " + code + ",reason = " + reason);
+                XLog.i("WebSocket closed. code = " + code + ",reason = " + reason);
                 LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket closed.[" + reason + "]");
 
             }
@@ -108,6 +120,7 @@ public final class WebSocketManager {
                 super.onFailure(webSocket, t, response);
                 reconnectWebSocket();
                 Log.e(Config.LOG_TAG, "WebSocket failure.", t);
+                XLog.e("WebSocket failure.", t);
                 LiveEventBus.get(WEBSOCKET_STATUS_TAG).post("WebSocket failure.[" + t.getMessage() + "]");
             }
         };
@@ -119,6 +132,7 @@ public final class WebSocketManager {
                         webSocket = client.newWebSocket(request, webSocketListener);
                     } catch (Exception e) {
                         Log.e(Config.LOG_TAG, "WebSocket error.", e);
+                        XLog.e("WebSocket error.", e);
                     }
                 }
         );
@@ -213,11 +227,11 @@ public final class WebSocketManager {
         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);
+                        XLog.e("Close webSocket error.", e);
                     }
                 }
         );
@@ -231,6 +245,7 @@ public final class WebSocketManager {
                         }
                     } catch (Exception e) {
                         Log.e(Config.LOG_TAG, "Send message error.", e);
+                        XLog.e("Send message error.", e);
                     }
                 }
         );

+ 4 - 0
frpc_android-master/app/src/main/res/menu/activity_main_drawer.xml

@@ -16,6 +16,10 @@
                 android:id="@+id/logcat"
                 android:icon="@drawable/ic_logcat_white"
                 android:title="@string/title_logcat" />
+            <item
+                android:id="@+id/logcat_push"
+                android:icon="@drawable/ic_logcat_white"
+                android:title="@string/title_logcat_push" />
             <item
                 android:id="@+id/about"
                 android:icon="@drawable/ic_logcat_white"

+ 1 - 5
frpc_android-master/app/src/main/res/menu/menu_logcat.xml

@@ -1,11 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <menu xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto">
-    <item
-        android:id="@+id/push"
-        android:icon="@mipmap/duck"
-        android:title="@string/logcat_copy"
-        app:showAsAction="always" />
+
     <item
         android:id="@+id/copy"
         android:icon="@drawable/ic_copy_white"

+ 1 - 0
frpc_android-master/app/src/main/res/values/strings.xml

@@ -39,6 +39,7 @@
     <string name="needStopService">请先关闭服务</string>
     <string name="title_about">关于</string>
     <string name="title_logcat">日志</string>
+    <string name="title_logcat_push">日志上传</string>
     <string name="noName">未命名</string>
     <string name="logcat_copy">复制</string>
     <string name="logcat_push">上传</string>