ソースを参照

1,调整日志结构
2,将日志初始化放到els后面
3,日志文件上传后,删除

lyn 4 年 前
コミット
27f092b1ec

+ 13 - 51
app/src/main/java/com/haochuan/hciptvbasic/BaseWebActivity.java

@@ -34,6 +34,7 @@ import com.haochuan.core.http.bean.ApkSettingBean;
 import com.haochuan.core.http.bean.ResponseBean;
 import com.haochuan.core.util.ELS;
 import com.haochuan.core.util.HandlerUtil;
+import com.haochuan.hciptvbasic.util.ELSUtil;
 import com.haochuan.hciptvbasic.util.VRUtil;
 import com.haochuan.hciptvbasic.webview.PayToJS;
 import com.haochuan.hciptvbasic.webview.PlayerToJS;
@@ -69,57 +70,6 @@ public abstract class BaseWebActivity extends AppCompatActivity {
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        els = ELS.getInstance(this);
-        String uid = "";
-        //访问接口确定是否需要上传日志
-        if (!TextUtils.isEmpty(uid)) {
-            RequestServer.getInstance().getApkSetting(uid, new ResponseListener<ApkSettingBean>() {
-                @Override
-                public void onSuccess(ApkSettingBean response) {
-                    Logger.d("getApkSetting:" + response.toString());
-                    List<ApkSettingBean.DataBean> dataList = response.getData();
-                    for (ApkSettingBean.DataBean data : dataList) {
-                        //遍历寻找对应配置
-                        if ("open_apk_log_status".equals(data.getSetting_name())) {
-                            if ("1".equals(data.getSetting_value())) {
-                                Logger.setLogNeedWriteToFile(true);
-                                els.saveBoolData(ELS.LAST_LOG_SWITCH, true);
-                            } else {
-                                els.saveBoolData(ELS.LAST_LOG_SWITCH, false);
-                            }
-                        }
-                    }
-                }
-
-                @Override
-                public void onFailure(String code, String message) {
-                    els.saveBoolData(ELS.LAST_LOG_SWITCH, false);
-                }
-            });
-        }
-
-        //每次启动应用时,检查一下上一次使用是否要上传日志,
-        // 因为在应用关闭时上传文件可能导致内存内泄漏或上传失败,所以放在应用启动时上传
-        if (els.getBoolData(ELS.LAST_LOG_SWITCH)) {
-            String lasLogFileName = els.getStringData(ELS.LOG_FILE_NAME);
-            Logger.d("uploadLogFile lasLogFileName:" + lasLogFileName);
-            if (!TextUtils.isEmpty(lasLogFileName)) {
-                RequestServer.getInstance().uploadLogFile(lasLogFileName,
-                        new ResponseListener<ResponseBean>() {
-                            @Override
-                            public void onSuccess(ResponseBean response) {
-                                Logger.d("uploadLogFile:" + response.toString());
-                            }
-
-                            @Override
-                            public void onFailure(String code, String message) {
-                            }
-                        });
-            }
-        }
-
-        //初始化日志
-        Logger.init(this,getWebView());
 
         webView = new WebView(this);
         webView.setBackgroundColor(ContextCompat.getColor(this, android.R.color.transparent));
@@ -130,6 +80,18 @@ public abstract class BaseWebActivity extends AppCompatActivity {
         //初始化播放器和vr
         initPlayerAndVr();
 
+        //初始化els日志记录系统
+        els = ELS.getInstance(this);
+        String uid = "12398658";
+        if(utilToJS != null){
+            uid = utilToJS.getUserName();
+        }
+        Logger.d("uid:" + uid);
+        ELSUtil.Init(this,els,uid);
+
+        //初始化日志
+        Logger.init(this,getWebView());
+
         runH5();
     }
 

+ 70 - 0
app/src/main/java/com/haochuan/hciptvbasic/util/ELSUtil.java

@@ -0,0 +1,70 @@
+package com.haochuan.hciptvbasic.util;
+
+import android.content.Context;
+import android.text.TextUtils;
+
+import com.haochuan.core.Logger;
+import com.haochuan.core.http.RequestServer;
+import com.haochuan.core.http.ResponseListener;
+import com.haochuan.core.http.bean.ApkSettingBean;
+import com.haochuan.core.http.bean.ResponseBean;
+import com.haochuan.core.util.ELS;
+
+import java.util.List;
+
+/**
+ * @author: xulin
+ * @projectName:HcIPTVBasic
+ * @createTime:2020/7/22 18:32
+ */
+public class ELSUtil {
+    public static void Init(Context context, final ELS els, String uid){
+        //访问接口确定是否需要上传日志
+        if (!TextUtils.isEmpty(uid)) {
+            RequestServer.getInstance().getApkSetting(uid, new ResponseListener<ApkSettingBean>() {
+                @Override
+                public void onSuccess(ApkSettingBean response) {
+                    Logger.d("getApkSetting:" + response.toString());
+                    List<ApkSettingBean.DataBean> dataList = response.getData();
+                    for (ApkSettingBean.DataBean data : dataList) {
+                        //遍历寻找对应配置
+                        if ("open_apk_log_status".equals(data.getSetting_name())) {
+                            if ("1".equals(data.getSetting_value())) {
+                                Logger.setLogNeedWriteToFile(true);
+                                els.saveBoolData(ELS.LAST_LOG_SWITCH, true);
+                            } else {
+                                els.saveBoolData(ELS.LAST_LOG_SWITCH, false);
+                            }
+                        }
+                    }
+                }
+
+                @Override
+                public void onFailure(String code, String message) {
+                    els.saveBoolData(ELS.LAST_LOG_SWITCH, false);
+                }
+            });
+        }
+
+        //每次启动应用时,检查一下上一次使用是否要上传日志,
+        // 因为在应用关闭时上传文件可能导致内存内泄漏或上传失败,所以放在应用启动时上传
+        if (els.getBoolData(ELS.LAST_LOG_SWITCH)) {
+            String lasLogFileName = els.getStringData(ELS.LOG_FILE_NAME);
+            Logger.d("uploadLogFile lasLogFileName:" + lasLogFileName);
+            if (!TextUtils.isEmpty(lasLogFileName)) {
+                RequestServer.getInstance().uploadLogFile(lasLogFileName,
+                        new ResponseListener<ResponseBean>() {
+                            @Override
+                            public void onSuccess(ResponseBean response) {
+                                Logger.d("uploadLogFile:" + response.toString());
+                            }
+
+                            @Override
+                            public void onFailure(String code, String message) {
+                                Logger.d("uploadLogFile fail:" + message);
+                            }
+                        });
+            }
+        }
+    }
+}

+ 1 - 1
app/src/main/java/com/haochuan/hciptvbasic/webview/UtilToJS.java

@@ -218,7 +218,7 @@ public class UtilToJS {
      * 返回用户名
      * @return
      */
-    private String getUserName(){
+    public String getUserName(){
         String userName = getUserNameFromSTB();
         if(TextUtils.isEmpty(userName)){
             return MacUtil.getMac(context);

+ 3 - 0
core/src/main/java/com/haochuan/core/http/RequestServer.java

@@ -209,6 +209,9 @@ public class RequestServer {
                     } else {
                         listener.onFailure(OTHER_MESSAGE_CODE, OTHER_MESSAGE);
                     }
+
+                    //上传成功后,删除文件
+                    file.delete();
                 }
 
                 @Override