package com.google.android.gms.analytics; import android.content.Context; import com.huawei.hms.android.SystemUtils; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.TreeSet; /* loaded from: classes.dex */ public class StandardExceptionParser implements ExceptionParser { private final TreeSet zzta = new TreeSet<>(); public StandardExceptionParser(Context context, Collection collection) { setIncludedPackages(context, collection); } public void setIncludedPackages(Context context, Collection collection) { this.zzta.clear(); HashSet hashSet = new HashSet(); if (collection != null) { hashSet.addAll(collection); } if (context != null) { hashSet.add(context.getApplicationContext().getPackageName()); } for (String str : hashSet) { Iterator it = this.zzta.iterator(); boolean z = true; while (true) { if (!it.hasNext()) { break; } String next = it.next(); if (str.startsWith(next)) { z = false; } else if (next.startsWith(str)) { this.zzta.remove(next); } } if (z) { this.zzta.add(str); } } } protected Throwable getCause(Throwable th) { while (th.getCause() != null) { th = th.getCause(); } return th; } protected StackTraceElement getBestStackTraceElement(Throwable th) { StackTraceElement[] stackTrace = th.getStackTrace(); if (stackTrace == null || stackTrace.length == 0) { return null; } for (StackTraceElement stackTraceElement : stackTrace) { String className = stackTraceElement.getClassName(); Iterator it = this.zzta.iterator(); while (it.hasNext()) { if (className.startsWith(it.next())) { return stackTraceElement; } } } return stackTrace[0]; } protected String getDescription(Throwable th, StackTraceElement stackTraceElement, String str) { StringBuilder sb = new StringBuilder(); sb.append(th.getClass().getSimpleName()); if (stackTraceElement != null) { String[] split = stackTraceElement.getClassName().split("\\."); sb.append(String.format(" (@%s:%s:%s)", (split == null || split.length <= 0) ? SystemUtils.UNKNOWN : split[split.length - 1], stackTraceElement.getMethodName(), Integer.valueOf(stackTraceElement.getLineNumber()))); } if (str != null) { sb.append(String.format(" {%s}", str)); } return sb.toString(); } @Override // com.google.android.gms.analytics.ExceptionParser public String getDescription(String str, Throwable th) { return getDescription(getCause(th), getBestStackTraceElement(getCause(th)), str); } }