修复首页周星榜svga会消失的问题

修复Firebase可能没uid的问题
新增其他事件统计
This commit is contained in:
zlzw 2022-10-27 15:28:43 +08:00
parent 2e2e5c7ec0
commit 6efcb75c31
6 changed files with 97 additions and 12 deletions

View File

@ -36,6 +36,7 @@ import com.yunbao.common.BuildConfig;
import com.yunbao.common.CommonAppConfig; import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext; import com.yunbao.common.CommonAppContext;
import com.yunbao.common.Constants; import com.yunbao.common.Constants;
import com.yunbao.common.bean.CrashSaveBean;
import com.yunbao.common.http.CommonHttpUtil; import com.yunbao.common.http.CommonHttpUtil;
import com.yunbao.common.http.HttpCallback; import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.manager.imrongcloud.InstructorSendReward; import com.yunbao.common.manager.imrongcloud.InstructorSendReward;
@ -132,6 +133,7 @@ public class AppContext extends CommonAppContext {
if (!isMainProcess()) { if (!isMainProcess()) {
return; return;
} }
CrashSaveBean.getInstance().setStartTime(System.currentTimeMillis());
registerError(); registerError();
registerFirebaseCrash(); registerFirebaseCrash();
sInstance = this; sInstance = this;
@ -315,6 +317,7 @@ public class AppContext extends CommonAppContext {
} }
/* Process.killProcess(Process.myPid()); /* Process.killProcess(Process.myPid());
System.exit(0);*/ System.exit(0);*/
setFirebaseCrashData();
new Handler(Looper.getMainLooper()).postDelayed(() -> { new Handler(Looper.getMainLooper()).postDelayed(() -> {
throw new RuntimeException(e); throw new RuntimeException(e);
}, 100); }, 100);
@ -332,6 +335,13 @@ public class AppContext extends CommonAppContext {
} }
FirebaseAnalytics.getInstance(this); FirebaseAnalytics.getInstance(this);
FirebaseApp.initializeApp(this); FirebaseApp.initializeApp(this);
}
private void setFirebaseCrashData(){
if (!CommonAppConfig.IS_UPLOAD_ERROR_LOG) {
return;
}
String uid = CommonAppConfig.getInstance().getUid(); String uid = CommonAppConfig.getInstance().getUid();
FirebaseCrashlytics.getInstance().setUserId(CommonAppConfig.getInstance().getUid()); FirebaseCrashlytics.getInstance().setUserId(CommonAppConfig.getInstance().getUid());
if (uid != null && !uid.isEmpty()) { if (uid != null && !uid.isEmpty()) {
@ -344,5 +354,9 @@ public class AppContext extends CommonAppContext {
FirebaseCrashlytics.getInstance().setCustomKey("PhoneName", Build.BRAND); FirebaseCrashlytics.getInstance().setCustomKey("PhoneName", Build.BRAND);
FirebaseCrashlytics.getInstance().setCustomKey("Phone", Build.MODEL); FirebaseCrashlytics.getInstance().setCustomKey("Phone", Build.MODEL);
FirebaseCrashlytics.getInstance().setCustomKey("CPU", Arrays.toString(Build.SUPPORTED_ABIS)); 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());
} }
} }

View File

@ -8,6 +8,7 @@ import android.os.Looper;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import com.yunbao.common.bean.CrashSaveBean;
import com.yunbao.common.utils.FileUtil; import com.yunbao.common.utils.FileUtil;
import com.yunbao.common.utils.SpUtil; import com.yunbao.common.utils.SpUtil;
@ -86,6 +87,7 @@ public class NeverCrashUtils {
/** /**
* 完成监听异常的注册 * 完成监听异常的注册
*
* @param application application * @param application application
*/ */
public void register(Application application) { public void register(Application application) {
@ -128,6 +130,7 @@ public class NeverCrashUtils {
public interface UncaughtCrashHandler { public interface UncaughtCrashHandler {
void uncaughtException(Thread t, Throwable e); void uncaughtException(Thread t, Throwable e);
} }
private static String throwableToString(Throwable e) { private static String throwableToString(Throwable e) {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
writer.write("time=" + System.currentTimeMillis() + "\n"); writer.write("time=" + System.currentTimeMillis() + "\n");
@ -136,6 +139,10 @@ public class NeverCrashUtils {
writer.write("PhoneName=" + Build.BRAND + "\n"); writer.write("PhoneName=" + Build.BRAND + "\n");
writer.write("Phone=" + Build.MODEL + "\n"); writer.write("Phone=" + Build.MODEL + "\n");
writer.write("CPU=" + Arrays.toString(Build.SUPPORTED_ABIS) + "\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("UserData=" + SpUtil.getInstance().getStringValue(SpUtil.USER_INFO) + "\n");
writer.write("[ERROR]"); writer.write("[ERROR]");
PrintWriter printWriter = new PrintWriter(writer); PrintWriter printWriter = new PrintWriter(writer);

View File

@ -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++;
}
}

View File

@ -4,6 +4,7 @@ import android.animation.ValueAnimator;
import com.opensource.svgaplayer.SVGACallback; import com.opensource.svgaplayer.SVGACallback;
import com.opensource.svgaplayer.SVGAImageView; import com.opensource.svgaplayer.SVGAImageView;
import com.yunbao.common.bean.CrashSaveBean;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
@ -18,6 +19,7 @@ public class SVGAViewUtils {
SVGA_CACHE.add(svga); SVGA_CACHE.add(svga);
} }
} }
CrashSaveBean.getInstance().addPlaySvga();
svga.setCallback(new SVGACallback() { svga.setCallback(new SVGACallback() {
@Override @Override
public void onPause() { public void onPause() {
@ -58,6 +60,10 @@ public class SVGAViewUtils {
for (SVGAImageView view : SVGA_CACHE) { for (SVGAImageView view : SVGA_CACHE) {
try { try {
if (view != null) { if (view != null) {
Object tag = view.getTag();
if(tag!=null&&tag.toString().equals("save")){
continue;
}
view.clear(); view.clear();
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -40,6 +40,7 @@ import com.yunbao.common.HtmlConfig;
import com.yunbao.common.activity.WebViewActivity; import com.yunbao.common.activity.WebViewActivity;
import com.yunbao.common.bean.AnchorRecommendItemModel; import com.yunbao.common.bean.AnchorRecommendItemModel;
import com.yunbao.common.bean.AnchorRecommendModel; import com.yunbao.common.bean.AnchorRecommendModel;
import com.yunbao.common.bean.CrashSaveBean;
import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.bean.LiveBean; import com.yunbao.common.bean.LiveBean;
import com.yunbao.common.bean.LiveGiftBean; import com.yunbao.common.bean.LiveGiftBean;
@ -158,7 +159,7 @@ public class LiveAudienceActivity extends LiveActivity {
Bus.getOn(this); Bus.getOn(this);
super.main(); super.main();
liveAudienceActivity = this; liveAudienceActivity = this;
CrashSaveBean.getInstance().addEnterRoom();
mProcessResultUtil = new ProcessResultUtil(this); mProcessResultUtil = new ProcessResultUtil(this);
Intent intent = getIntent(); Intent intent = getIntent();
mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY); mLiveSDK = intent.getIntExtra(Constants.LIVE_SDK, Constants.LIVE_SDK_KSY);
@ -255,7 +256,7 @@ public class LiveAudienceActivity extends LiveActivity {
public void onPageSelected(int position) { public void onPageSelected(int position) {
super.onPageSelected(position); super.onPageSelected(position);
mCurrentPage = position; mCurrentPage = position;
CrashSaveBean.getInstance().addSlidingRoom();
} }
}); });
verticalViewPager.setPageTransformer(false, new ViewPager.PageTransformer() { verticalViewPager.setPageTransformer(false, new ViewPager.PageTransformer() {

View File

@ -67,6 +67,7 @@ public class MainHomeLiveWeekItemViewHolder<T> extends RecyclerView.ViewHolder {
public void onComplete(SVGAVideoEntity videoItem) { public void onComplete(SVGAVideoEntity videoItem) {
SVGADrawable drawable = new SVGADrawable(videoItem); SVGADrawable drawable = new SVGADrawable(videoItem);
weekSvga.setImageDrawable(drawable); weekSvga.setImageDrawable(drawable);
weekSvga.setTag("save");
SVGAViewUtils.playEndClear(weekSvga,false); SVGAViewUtils.playEndClear(weekSvga,false);
weekSvga.setClearsAfterStop(false); weekSvga.setClearsAfterStop(false);
} }