discord-jadx/app/src/main/java/com/discord/app/AppLog.java

488 lines
20 KiB
Java

package com.discord.app;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import c.a.d.h;
import c.a.d.i;
import com.discord.utilities.analytics.AnalyticsTracker;
import com.discord.utilities.logging.Logger;
import com.discord.utilities.mg_recycler.MGRecyclerDataPayload;
import com.discord.utilities.rx.ObservableExtensionsKt;
import com.discord.utilities.systemlog.SystemLogUtils;
import com.google.firebase.crashlytics.FirebaseCrashlytics;
import d0.g0.w;
import d0.g0.y;
import d0.t.k;
import d0.t.u;
import d0.z.d.m;
import d0.z.d.o;
import j0.q.a;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
import org.webrtc.Logging;
import rx.subjects.SerializedSubject;
/* compiled from: AppLog.kt */
public final class AppLog extends Logger {
public static int a = 99;
public static boolean b;
/* renamed from: c reason: collision with root package name */
public static SharedPreferences f1588c;
public static final SerializedSubject<LoggedItem, LoggedItem> d = new SerializedSubject<>(new j0.q.a(new a.d(new a.c(5000))));
public static boolean e;
public static final String[] f = {"com.discord", "co.discord"};
public static final AppLog g = new AppLog();
/* compiled from: AppLog.kt */
public static final class LoggedItem implements MGRecyclerDataPayload {
public final String i;
public final int j;
public final String k;
public final Throwable l;
public LoggedItem(int i, String str, Throwable th) {
m.checkNotNullParameter(str, "message");
this.j = i;
this.k = str;
this.l = th;
String uuid = UUID.randomUUID().toString();
m.checkNotNullExpressionValue(uuid, "UUID.randomUUID().toString()");
this.i = uuid;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof LoggedItem)) {
return false;
}
LoggedItem loggedItem = (LoggedItem) obj;
return this.j == loggedItem.j && m.areEqual(this.k, loggedItem.k) && m.areEqual(this.l, loggedItem.l);
}
@Override // com.discord.utilities.mg_recycler.MGRecyclerDataPayload, com.discord.utilities.recycler.DiffKeyProvider
public String getKey() {
return this.i;
}
@Override // com.discord.utilities.mg_recycler.MGRecyclerDataPayload
public int getType() {
return 0;
}
public int hashCode() {
int i = this.j * 31;
String str = this.k;
int i2 = 0;
int hashCode = (i + (str != null ? str.hashCode() : 0)) * 31;
Throwable th = this.l;
if (th != null) {
i2 = th.hashCode();
}
return hashCode + i2;
}
public String toString() {
StringBuilder L = c.d.b.a.a.L("LoggedItem(priority=");
L.append(this.j);
L.append(", message=");
L.append(this.k);
L.append(", throwable=");
L.append(this.l);
L.append(")");
return L.toString();
}
}
/* compiled from: AppLog.kt */
public static final class a extends o implements Function1<String, Unit> {
public final /* synthetic */ Map $metadata;
public final /* synthetic */ int $priority;
public final /* synthetic */ Throwable $throwable;
/* compiled from: AppLog.kt */
/* renamed from: com.discord.app.AppLog$a$a reason: collision with other inner class name */
public static final class C0173a extends o implements Function2<String, Integer, Unit> {
public final /* synthetic */ a this$0;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public C0173a(a aVar) {
super(2);
this.this$0 = aVar;
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */
@Override // kotlin.jvm.functions.Function2
public /* bridge */ /* synthetic */ Unit invoke(String str, Integer num) {
invoke(str, num.intValue());
return Unit.a;
}
public final void invoke(String str, int i) {
m.checkNotNullParameter(str, "message");
for (String str2 : y.chunked(str, i)) {
Log.println(this.this$0.$priority, AppLog.g.getDefaultTag(), str2);
}
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public a(int i, Map map, Throwable th) {
super(1);
this.$priority = i;
this.$metadata = map;
this.$throwable = th;
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(String str) {
invoke(str);
return Unit.a;
}
public final void invoke(String str) {
Set entrySet;
String joinToString$default;
m.checkNotNullParameter(str, "message");
C0173a aVar = new C0173a(this);
aVar.invoke(str, 1000);
Map map = this.$metadata;
if (!(map == null || (entrySet = map.entrySet()) == null || (joinToString$default = u.joinToString$default(entrySet, "\n\t", null, null, 0, null, null, 62, null)) == null)) {
aVar.invoke("Metadata: " + joinToString$default, Integer.MAX_VALUE);
}
String stackTraceString = Log.getStackTraceString(this.$throwable);
m.checkNotNullExpressionValue(stackTraceString, "Log.getStackTraceString(throwable)");
aVar.invoke(stackTraceString, 1000);
}
}
/* compiled from: AppLog.kt */
public static final class b extends o implements Function1<String, Unit> {
public final /* synthetic */ Map $metadata;
public final /* synthetic */ Throwable $throwable;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public b(Throwable th, Map map) {
super(1);
this.$throwable = th;
this.$metadata = map;
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public /* bridge */ /* synthetic */ Unit invoke(String str) {
invoke(str);
return Unit.a;
}
public final void invoke(String str) {
Set<Map.Entry> entrySet;
m.checkNotNullParameter(str, "message");
try {
if (this.$throwable != null) {
AppLog appLog = AppLog.g;
appLog.recordBreadcrumb("Message " + str, "Error");
}
Map map = this.$metadata;
if (!(map == null || (entrySet = map.entrySet()) == null)) {
for (Map.Entry entry : entrySet) {
AppLog appLog2 = AppLog.g;
appLog2.recordBreadcrumb("Metadata: " + ((String) entry.getKey()) + ", " + ((String) entry.getValue()), "Error");
}
}
Exception exc = new Exception(str, this.$throwable);
AppLog appLog3 = AppLog.g;
StackTraceElement[] stackTrace = exc.getStackTrace();
m.checkNotNullExpressionValue(stackTrace, "e.stackTrace");
exc.setStackTrace(AppLog.a(appLog3, stackTrace, str));
Throwable cause = exc.getCause();
if (cause != null) {
StackTraceElement[] stackTrace2 = cause.getStackTrace();
m.checkNotNullExpressionValue(stackTrace2, "cause.stackTrace");
cause.setStackTrace(AppLog.a(appLog3, stackTrace2, str));
}
FirebaseCrashlytics.getInstance().recordException(exc);
} catch (Exception e) {
AppLog.g.w("Unable to notify error logging.", e);
}
if (this.$throwable != null) {
try {
AnalyticsTracker analyticsTracker = AnalyticsTracker.INSTANCE;
StringBuilder sb = new StringBuilder();
sb.append(this.$throwable.getClass().toString());
sb.append(":\n");
StackTraceElement[] stackTrace3 = this.$throwable.getStackTrace();
m.checkNotNullExpressionValue(stackTrace3, "throwable.stackTrace");
sb.append(k.joinToString$default(stackTrace3, "\n", (CharSequence) null, (CharSequence) null, 0, (CharSequence) null, (Function1) null, 62, (Object) null));
analyticsTracker.appExceptionThrown(sb.toString());
} catch (Exception e2) {
AppLog.g.w("Unable to report to analytics.", e2);
}
}
}
}
/* compiled from: AppLog.kt */
public static final /* synthetic */ class c extends d0.z.d.k implements Function2<String, Throwable, Unit> {
public c(AppLog appLog) {
super(2, appLog, AppLog.class, "v", "v(Ljava/lang/String;Ljava/lang/Throwable;)V", 0);
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */
@Override // kotlin.jvm.functions.Function2
public Unit invoke(String str, Throwable th) {
String str2 = str;
m.checkNotNullParameter(str2, "p1");
((AppLog) this.receiver).v(str2, th);
return Unit.a;
}
}
public AppLog() {
super("Discord");
}
/* JADX WARNING: Removed duplicated region for block: B:22:0x0085 A[LOOP:0: B:1:0x0006->B:22:0x0085, LOOP_END] */
/* JADX WARNING: Removed duplicated region for block: B:50:0x008a A[EDGE_INSN: B:50:0x008a->B:24:0x008a ?: BREAK , SYNTHETIC] */
public static final StackTraceElement[] a(AppLog appLog, StackTraceElement[] stackTraceElementArr, String str) {
StackTraceElement stackTraceElement;
int i;
boolean z2;
String className;
boolean z3;
Objects.requireNonNull(appLog);
int length = stackTraceElementArr.length;
int i2 = 0;
int i3 = 0;
while (true) {
stackTraceElement = null;
i = -1;
if (i3 >= length) {
i3 = -1;
break;
}
StackTraceElement stackTraceElement2 = stackTraceElementArr[i3];
String className2 = stackTraceElement2.getClassName();
m.checkNotNullExpressionValue(className2, "stackTraceElement.className");
boolean z4 = w.contains$default(className2, "MediaEngineLegacy", false, 2, null) && m.areEqual(stackTraceElement2.getMethodName(), "e");
String className3 = stackTraceElement2.getClassName();
m.checkNotNullExpressionValue(className3, "stackTraceElement.className");
String name = Logger.class.getName();
m.checkNotNullExpressionValue(name, "Logger::class.java.name");
if (!w.contains$default((CharSequence) className3, (CharSequence) name, false, 2, (Object) null)) {
String className4 = stackTraceElement2.getClassName();
m.checkNotNullExpressionValue(className4, "stackTraceElement.className");
String name2 = Logging.class.getName();
m.checkNotNullExpressionValue(name2, "Logging::class.java.name");
if (!w.contains$default((CharSequence) className4, (CharSequence) name2, false, 2, (Object) null)) {
String className5 = stackTraceElement2.getClassName();
m.checkNotNullExpressionValue(className5, "stackTraceElement.className");
String name3 = AppLog.class.getName();
m.checkNotNullExpressionValue(name3, "AppLog::class.java.name");
if (!w.contains$default((CharSequence) className5, (CharSequence) name3, false, 2, (Object) null)) {
z3 = false;
if (!(z3 && !z4)) {
break;
}
i3++;
}
}
}
z3 = true;
if (!(z3 && !z4)) {
}
}
int length2 = stackTraceElementArr.length - i3;
StackTraceElement[] stackTraceElementArr2 = new StackTraceElement[length2];
System.arraycopy(stackTraceElementArr, i3, stackTraceElementArr2, 0, length2);
int i4 = 0;
while (true) {
if (i4 >= length2) {
break;
}
StackTraceElement stackTraceElement3 = stackTraceElementArr2[i4];
String[] strArr = f;
int length3 = strArr.length;
int i5 = 0;
while (true) {
if (i5 >= length3) {
z2 = false;
break;
}
if ((stackTraceElement3 == null || (className = stackTraceElement3.getClassName()) == null || !w.contains$default(className, strArr[i5], false, 2, null)) ? false : true) {
z2 = true;
break;
}
i5++;
}
if (z2) {
i = i4;
break;
}
i4++;
}
if (i > 0) {
i2 = i;
}
StackTraceElement stackTraceElement4 = stackTraceElementArr2[i2];
if (stackTraceElement4 != null) {
stackTraceElement = new StackTraceElement(stackTraceElement4.getClassName(), stackTraceElement4.getMethodName(), c.d.b.a.a.v(stackTraceElement4.getFileName(), ", ", str), stackTraceElement4.getLineNumber());
}
stackTraceElementArr2[i2] = stackTraceElement;
return stackTraceElementArr2;
}
public static final void g(Long l, String str, String str2) {
String str3;
if (b) {
SharedPreferences sharedPreferences = f1588c;
if (sharedPreferences != null) {
SharedPreferences.Editor edit = sharedPreferences.edit();
m.checkExpressionValueIsNotNull(edit, "editor");
if (l != null) {
l.longValue();
edit.putString("LOG_CACHE_KEY_USER_ID", String.valueOf(l));
}
if (str != null) {
edit.putString("LOG_CACHE_KEY_USER_LOGIN", str);
}
if (str2 != null) {
edit.putString("LOG_CACHE_KEY_USER_NAME", str2);
}
edit.apply();
}
FirebaseCrashlytics instance = FirebaseCrashlytics.getInstance();
if (l == null || (str3 = String.valueOf(l.longValue())) == null) {
str3 = "";
}
instance.setUserId(str3);
if (str != null) {
FirebaseCrashlytics.getInstance().setCustomKey("userLogin", str);
}
if (str2 != null) {
FirebaseCrashlytics.getInstance().setCustomKey("userName", str2);
}
if (l != null && !e) {
e = true;
Objects.requireNonNull(g);
if (new Random().nextInt(10) == 1) {
ObservableExtensionsKt.appSubscribe$default(SystemLogUtils.INSTANCE.fetchLastTombstone(), AppLog.class, (Context) null, (Function1) null, h.i, (Function0) null, (Function0) null, i.i, 54, (Object) null);
}
}
}
}
public static final void i(String str) {
m.checkNotNullParameter(str, "message");
g.i(str, null);
}
public final void b(String str, int i, Throwable th, Map<String, String> map) {
if (i >= a) {
a aVar = new a(i, map, th);
d.j.onNext(new LoggedItem(i, str, th));
b bVar = new b(th, map);
if (i == 6) {
bVar.invoke(str);
}
aVar.invoke(str);
}
}
public final void c(String str, String str2, Throwable th, Function2<? super String, ? super Throwable, Unit> function2) {
m.checkNotNullParameter(str, "message");
m.checkNotNullParameter(str2, "category");
m.checkNotNullParameter(function2, "loggingFn");
if (b) {
String str3 = '[' + str2 + "]: " + str;
function2.invoke("Breadcrumb, " + str3, th);
FirebaseCrashlytics.getInstance().log(str3);
}
}
@Override // com.discord.utilities.logging.Logger
public void d(String str, String str2, Throwable th) {
m.checkNotNullParameter(str, "tag");
m.checkNotNullParameter(str2, "message");
d(str + " -> " + str2, th);
}
@Override // com.discord.utilities.logging.Logger
public void d(String str, Throwable th) {
m.checkNotNullParameter(str, "message");
b(str, 3, th, null);
}
@Override // com.discord.utilities.logging.Logger
public void e(String str, String str2, Throwable th, Map<String, String> map) {
m.checkNotNullParameter(str, "tag");
m.checkNotNullParameter(str2, "message");
e(str + " -> " + str2, th, map);
}
@Override // com.discord.utilities.logging.Logger
public void e(String str, Throwable th, Map<String, String> map) {
m.checkNotNullParameter(str, "message");
b(str, 6, th, map);
}
public final void f(String str, String str2) {
m.checkNotNullParameter(str, "from");
m.checkNotNullParameter(str2, "to");
recordBreadcrumb("Navigation [" + str + "] > [" + str2 + ']', "navigation");
}
@Override // com.discord.utilities.logging.Logger
public void i(String str, String str2, Throwable th) {
m.checkNotNullParameter(str, "tag");
m.checkNotNullParameter(str2, "message");
i(str + " -> " + str2, th);
}
@Override // com.discord.utilities.logging.Logger
public void i(String str, Throwable th) {
m.checkNotNullParameter(str, "message");
b(str, 4, th, null);
}
@Override // com.discord.utilities.logging.Logger
public void recordBreadcrumb(String str, String str2) {
m.checkNotNullParameter(str, "message");
m.checkNotNullParameter(str2, "category");
c(str, str2, null, new c(this));
}
@Override // com.discord.utilities.logging.Logger
public void v(String str, Throwable th) {
m.checkNotNullParameter(str, "message");
b(str, 2, th, null);
}
@Override // com.discord.utilities.logging.Logger
public void w(String str, String str2, Throwable th) {
m.checkNotNullParameter(str, "tag");
m.checkNotNullParameter(str2, "message");
w(str + " -> " + str2, th);
}
@Override // com.discord.utilities.logging.Logger
public void w(String str, Throwable th) {
m.checkNotNullParameter(str, "message");
b(str, 5, th, null);
}
}