From 6efcb75c317422c6ded5bd6937437bd0d54e2f2c Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Thu, 27 Oct 2022 15:28:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A6=96=E9=A1=B5=E5=91=A8?= =?UTF-8?q?=E6=98=9F=E6=A6=9Csvga=E4=BC=9A=E6=B6=88=E5=A4=B1=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20=E4=BF=AE=E5=A4=8DFirebase=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E6=B2=A1uid=E7=9A=84=E9=97=AE=E9=A2=98=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=85=B6=E4=BB=96=E4=BA=8B=E4=BB=B6=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shayu/phonelive/AppContext.java | 14 +++++ .../com/shayu/phonelive/NeverCrashUtils.java | 27 +++++---- .../com/yunbao/common/bean/CrashSaveBean.java | 56 +++++++++++++++++++ .../yunbao/common/utils/SVGAViewUtils.java | 6 ++ .../live/activity/LiveAudienceActivity.java | 5 +- .../views/MainHomeLiveWeekItemViewHolder.java | 1 + 6 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/bean/CrashSaveBean.java diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index a8eb4e4c9..d8b08e0e9 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -36,6 +36,7 @@ import com.yunbao.common.BuildConfig; import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppContext; import com.yunbao.common.Constants; +import com.yunbao.common.bean.CrashSaveBean; import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.HttpCallback; import com.yunbao.common.manager.imrongcloud.InstructorSendReward; @@ -132,6 +133,7 @@ public class AppContext extends CommonAppContext { if (!isMainProcess()) { return; } + CrashSaveBean.getInstance().setStartTime(System.currentTimeMillis()); registerError(); registerFirebaseCrash(); sInstance = this; @@ -315,6 +317,7 @@ public class AppContext extends CommonAppContext { } /* Process.killProcess(Process.myPid()); System.exit(0);*/ + setFirebaseCrashData(); new Handler(Looper.getMainLooper()).postDelayed(() -> { throw new RuntimeException(e); }, 100); @@ -332,6 +335,13 @@ public class AppContext extends CommonAppContext { } FirebaseAnalytics.getInstance(this); FirebaseApp.initializeApp(this); + } + + + private void setFirebaseCrashData(){ + if (!CommonAppConfig.IS_UPLOAD_ERROR_LOG) { + return; + } String uid = CommonAppConfig.getInstance().getUid(); FirebaseCrashlytics.getInstance().setUserId(CommonAppConfig.getInstance().getUid()); if (uid != null && !uid.isEmpty()) { @@ -344,5 +354,9 @@ public class AppContext extends CommonAppContext { FirebaseCrashlytics.getInstance().setCustomKey("PhoneName", Build.BRAND); FirebaseCrashlytics.getInstance().setCustomKey("Phone", Build.MODEL); FirebaseCrashlytics.getInstance().setCustomKey("CPU", Arrays.toString(Build.SUPPORTED_ABIS)); + FirebaseCrashlytics.getInstance().setCustomKey("RunTime", (System.currentTimeMillis() - CrashSaveBean.getInstance().getStartTime())); + FirebaseCrashlytics.getInstance().setCustomKey("enterRoom", CrashSaveBean.getInstance().getEnterRoom()); + FirebaseCrashlytics.getInstance().setCustomKey("slidingRoom", CrashSaveBean.getInstance().getSlidingRoom()); + FirebaseCrashlytics.getInstance().setCustomKey("playSvga", CrashSaveBean.getInstance().getPlaySvga()); } } diff --git a/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java b/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java index 61e644127..78cf7245d 100644 --- a/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java +++ b/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java @@ -8,6 +8,7 @@ import android.os.Looper; import android.util.Log; import android.widget.Toast; +import com.yunbao.common.bean.CrashSaveBean; import com.yunbao.common.utils.FileUtil; import com.yunbao.common.utils.SpUtil; @@ -86,6 +87,7 @@ public class NeverCrashUtils { /** * 完成监听异常的注册 + * * @param application application */ public void register(Application application) { @@ -100,7 +102,7 @@ public class NeverCrashUtils { } e.printStackTrace(); Toast.makeText(application, "发生闪退", Toast.LENGTH_SHORT).show(); - FileUtil.saveStringToFile(new File(application.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()),throwableToString(e),"error.log"); + FileUtil.saveStringToFile(new File(application.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()), throwableToString(e), "error.log"); getMainCrashHandler().mainException(Looper.getMainLooper().getThread(), e); return; } @@ -128,17 +130,22 @@ public class NeverCrashUtils { public interface UncaughtCrashHandler { void uncaughtException(Thread t, Throwable e); } + private static String throwableToString(Throwable e) { - StringWriter writer=new StringWriter(); - writer.write("time="+System.currentTimeMillis()+"\n"); - writer.write("AndroidVersion="+ Build.VERSION.SDK_INT+"\n"); - writer.write("AndroidName="+ Build.VERSION.RELEASE+"\n"); - writer.write("PhoneName="+ Build.BRAND+"\n"); - writer.write("Phone="+ Build.MODEL+"\n"); - writer.write("CPU="+ Arrays.toString(Build.SUPPORTED_ABIS) +"\n"); - writer.write("UserData="+SpUtil.getInstance().getStringValue(SpUtil.USER_INFO)+"\n"); + StringWriter writer = new StringWriter(); + writer.write("time=" + System.currentTimeMillis() + "\n"); + writer.write("AndroidVersion=" + Build.VERSION.SDK_INT + "\n"); + writer.write("AndroidName=" + Build.VERSION.RELEASE + "\n"); + writer.write("PhoneName=" + Build.BRAND + "\n"); + writer.write("Phone=" + Build.MODEL + "\n"); + writer.write("CPU=" + Arrays.toString(Build.SUPPORTED_ABIS) + "\n"); + writer.write("runTime=" + (System.currentTimeMillis() - CrashSaveBean.getInstance().getStartTime())+ "\n"); + writer.write("enterRoom=" + CrashSaveBean.getInstance().getEnterRoom()+ "\n"); + writer.write("slidingRoom=" + CrashSaveBean.getInstance().getSlidingRoom()+ "\n"); + writer.write("playSvga=" + CrashSaveBean.getInstance().getPlaySvga()+ "\n"); + writer.write("UserData=" + SpUtil.getInstance().getStringValue(SpUtil.USER_INFO) + "\n"); writer.write("[ERROR]"); - PrintWriter printWriter=new PrintWriter(writer); + PrintWriter printWriter = new PrintWriter(writer); e.printStackTrace(printWriter); return writer.toString(); } diff --git a/common/src/main/java/com/yunbao/common/bean/CrashSaveBean.java b/common/src/main/java/com/yunbao/common/bean/CrashSaveBean.java new file mode 100644 index 000000000..6f7036836 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/CrashSaveBean.java @@ -0,0 +1,56 @@ +package com.yunbao.common.bean; + +/** + * 用于统计记录崩溃的数据 + */ +public class CrashSaveBean { + private static CrashSaveBean bean; + private long startTime;//应用启动时间 + private long enterRoom;//进入房间次数 + private long slidingRoom;//滑动直播间次数 + private long playSvga;//加载播放svga次数 + + private CrashSaveBean() { + + } + + public static CrashSaveBean getInstance() { + if (bean == null) { + bean = new CrashSaveBean(); + } + return bean; + } + + public long getStartTime() { + return startTime; + } + + public void setStartTime(long startTime) { + this.startTime = startTime; + } + + public long getEnterRoom() { + return enterRoom; + } + + public long getPlaySvga() { + return playSvga; + } + + public long getSlidingRoom() { + return slidingRoom; + } + + public void addEnterRoom() { + enterRoom++; + } + + public void addPlaySvga() { + playSvga++; + } + + public void addSlidingRoom() { + slidingRoom++; + } +} + diff --git a/common/src/main/java/com/yunbao/common/utils/SVGAViewUtils.java b/common/src/main/java/com/yunbao/common/utils/SVGAViewUtils.java index 9c76a4646..7cefb2e2f 100644 --- a/common/src/main/java/com/yunbao/common/utils/SVGAViewUtils.java +++ b/common/src/main/java/com/yunbao/common/utils/SVGAViewUtils.java @@ -4,6 +4,7 @@ import android.animation.ValueAnimator; import com.opensource.svgaplayer.SVGACallback; import com.opensource.svgaplayer.SVGAImageView; +import com.yunbao.common.bean.CrashSaveBean; import java.lang.reflect.Field; import java.util.ArrayList; @@ -18,6 +19,7 @@ public class SVGAViewUtils { SVGA_CACHE.add(svga); } } + CrashSaveBean.getInstance().addPlaySvga(); svga.setCallback(new SVGACallback() { @Override public void onPause() { @@ -58,6 +60,10 @@ public class SVGAViewUtils { for (SVGAImageView view : SVGA_CACHE) { try { if (view != null) { + Object tag = view.getTag(); + if(tag!=null&&tag.toString().equals("save")){ + continue; + } view.clear(); } } catch (Exception e) { diff --git a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java index 09e3ae30c..a6f66d293 100644 --- a/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java +++ b/live/src/main/java/com/yunbao/live/activity/LiveAudienceActivity.java @@ -40,6 +40,7 @@ import com.yunbao.common.HtmlConfig; import com.yunbao.common.activity.WebViewActivity; import com.yunbao.common.bean.AnchorRecommendItemModel; import com.yunbao.common.bean.AnchorRecommendModel; +import com.yunbao.common.bean.CrashSaveBean; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.LiveBean; import com.yunbao.common.bean.LiveGiftBean; @@ -158,7 +159,7 @@ public class LiveAudienceActivity extends LiveActivity { Bus.getOn(this); super.main(); liveAudienceActivity = this; - + CrashSaveBean.getInstance().addEnterRoom(); mProcessResultUtil = new ProcessResultUtil(this); Intent intent = getIntent(); mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY); @@ -255,7 +256,7 @@ public class LiveAudienceActivity extends LiveActivity { public void onPageSelected(int position) { super.onPageSelected(position); mCurrentPage = position; - + CrashSaveBean.getInstance().addSlidingRoom(); } }); verticalViewPager.setPageTransformer(false, new ViewPager.PageTransformer() { diff --git a/main/src/main/java/com/yunbao/main/views/MainHomeLiveWeekItemViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainHomeLiveWeekItemViewHolder.java index 1012b4dd5..7da0d137c 100644 --- a/main/src/main/java/com/yunbao/main/views/MainHomeLiveWeekItemViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainHomeLiveWeekItemViewHolder.java @@ -67,6 +67,7 @@ public class MainHomeLiveWeekItemViewHolder extends RecyclerView.ViewHolder { public void onComplete(SVGAVideoEntity videoItem) { SVGADrawable drawable = new SVGADrawable(videoItem); weekSvga.setImageDrawable(drawable); + weekSvga.setTag("save"); SVGAViewUtils.playEndClear(weekSvga,false); weekSvga.setClearsAfterStop(false); }