Browse Source

1.3.14 optimize:优化拉取日志.

xwh 2 months ago
parent
commit
eadfb4cbc0

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

@@ -90,6 +90,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Future;
 
 import io.reactivex.Observable;
 import io.reactivex.Observer;
@@ -909,7 +910,7 @@ public class BackgroundService extends Service {
             startDownloadApk(mBean);
         }
     }
-
+    private Future future;
     private void uploadLogFileList(ServerActionBean serverActionBean) {
         List<String> waitUploadLogPaths = serverActionBean.getPaths();
         if (waitUploadLogPaths == null || waitUploadLogPaths.size() == 0) {
@@ -924,10 +925,14 @@ public class BackgroundService extends Service {
 
         String logType = serverActionBean.getLogType();
         String sender = serverActionBean.getSender();
-        ThreadPoolManager.getInstance().executeIOTask(new Runnable() {
+        if (future != null && !future.isDone()) {
+            return;
+        }
+        future=  ThreadPoolManager.getInstance().sumbitIOTask(new Runnable() {
             @Override
             public void run() {
                 try {
+                    AppLogUtils.e("下载run"+waitUploadLogPaths);
                     synchronized (BackgroundService.class) {
                         String zipPath = ZipUtils.createZipFolder(MyApplication.getContext(), waitUploadLogPaths);
                         String downloadUrl = ChunkedUploadExample.uploadFile(MyApplication.getContext(), zipPath);
@@ -937,11 +942,11 @@ public class BackgroundService extends Service {
                         reportLogList(DOWNLOAD_LOG, downLoadUrls, logType, sender);
                     }
                 }catch (IOException e){
-
+                    AppLogUtils.e(e.toString());
                 }catch (OutOfMemoryError e2){
-
+                    AppLogUtils.e(e2.toString());
                 }catch (Exception e3){
-
+                    AppLogUtils.e(e3.toString());
                 }
 
             }

+ 17 - 1
app/src/main/java/com/hh/hhomc/utils/DeviceUtils.java

@@ -11,6 +11,10 @@ import android.util.Log;
 
 import com.common.lib_base.utils.log.AppLogUtils;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.lang.reflect.Method;
 import java.net.Inet4Address;
 import java.net.InetAddress;
@@ -53,7 +57,19 @@ public final class DeviceUtils {
             e.printStackTrace();
         }
 
-
+        if(TextUtils.isEmpty(serial)){
+            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
+                try {
+                    Runtime runtime = Runtime.getRuntime();
+                    Process proc = runtime.exec(new String[]{"getprop", "ro.serialno"});
+                    InputStream is = proc.getInputStream();
+                    BufferedReader br = new BufferedReader(new InputStreamReader(is), 8192);
+                    serial = br.readLine();
+                } catch (IOException ex) {
+                    Log.e("Serial Number", "The Serial could not be found");
+                }
+            }
+        }
         // 兼容版本11的紫鹏
         if (TextUtils.isEmpty(serial)) {
 //            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

+ 5 - 0
app/src/main/java/com/hh/hhomc/utils/ZipUtils.java

@@ -6,6 +6,7 @@ import android.util.Log;
 
 import com.blankj.utilcode.util.FileUtils;
 import com.blankj.utilcode.util.PathUtils;
+import com.common.lib_base.utils.log.AppLogUtils;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -39,6 +40,7 @@ public class ZipUtils {
 
 
     public static String createFileName() {
+        Log.i(TAG, "createFileName = "  );
         String fileName = "";
         String pattern = "yyyy-MM-dd";
         SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, Locale.CHINA);
@@ -93,8 +95,11 @@ public class ZipUtils {
                    int length;
                    while ((length = fis.read(buffer)) > 0) {
                        zipOut.write(buffer, 0, length);
+                       zipOut.flush();
+                       AppLogUtils.e("执行 读取中" );
                    }
                    fis.close();
+                   zipOut.close();
                }
            }
 

+ 7 - 0
lib_base/src/main/java/com/common/lib_base/common/async/ThreadPoolManager.java

@@ -2,6 +2,7 @@ package com.common.lib_base.common.async;
 
 import android.os.Process;
 
+import java.util.concurrent.Future;
 import java.util.concurrent.LinkedBlockingDeque;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.ThreadPoolExecutor;
@@ -86,6 +87,12 @@ public class ThreadPoolManager {
         }
         iOExecutor.execute(runnable);
     }
+    public  Future sumbitIOTask(Runnable runnable) {
+        if (runnable == null) {
+            return null;
+        }
+        return iOExecutor.submit(runnable);
+    }
 
     /**
      * 移除IO任务