package com.facebook.internal.instrument; import androidx.annotation.RestrictTo; import androidx.annotation.VisibleForTesting; import com.facebook.FacebookSdk; import com.facebook.GraphRequest; import com.facebook.GraphRequestBatch; import com.facebook.GraphResponse; import com.facebook.internal.FeatureManager; import com.facebook.internal.Utility; import com.facebook.internal.instrument.InstrumentData; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import kotlin.jvm.internal.Intrinsics; import kotlin.jvm.internal.StringCompanionObject; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP}) /* loaded from: classes2.dex */ public final class ExceptionAnalyzer { public static final ExceptionAnalyzer INSTANCE = new ExceptionAnalyzer(); private static boolean enabled; @VisibleForTesting(otherwise = 2) public static final boolean isDebug$facebook_core_release() { return false; } private ExceptionAnalyzer() { } public static final void enable() { enabled = true; if (FacebookSdk.getAutoLogAppEventsEnabled()) { INSTANCE.sendExceptionAnalysisReports$facebook_core_release(); } } public static final void execute(Throwable th) { if (!enabled || isDebug$facebook_core_release() || th == null) { return; } HashSet hashSet = new HashSet(); StackTraceElement[] stackTrace = th.getStackTrace(); Intrinsics.checkNotNullExpressionValue(stackTrace, "e.stackTrace"); for (StackTraceElement stackTraceElement : stackTrace) { FeatureManager featureManager = FeatureManager.INSTANCE; String className = stackTraceElement.getClassName(); Intrinsics.checkNotNullExpressionValue(className, "it.className"); FeatureManager.Feature feature = FeatureManager.getFeature(className); if (feature != FeatureManager.Feature.Unknown) { FeatureManager.disableFeature(feature); hashSet.add(feature.toString()); } } if (FacebookSdk.getAutoLogAppEventsEnabled() && (!hashSet.isEmpty())) { InstrumentData.Builder builder = InstrumentData.Builder.INSTANCE; InstrumentData.Builder.build(new JSONArray((Collection) hashSet)).save(); } } @VisibleForTesting(otherwise = 2) public final void sendExceptionAnalysisReports$facebook_core_release() { if (Utility.isDataProcessingRestricted()) { return; } File[] listExceptionAnalysisReportFiles = InstrumentUtility.listExceptionAnalysisReportFiles(); ArrayList arrayList = new ArrayList(); int length = listExceptionAnalysisReportFiles.length; int i = 0; while (i < length) { File file = listExceptionAnalysisReportFiles[i]; i++; final InstrumentData load = InstrumentData.Builder.load(file); if (load.isValid()) { JSONObject jSONObject = new JSONObject(); try { jSONObject.put("crash_shield", load.toString()); GraphRequest.Companion companion = GraphRequest.Companion; StringCompanionObject stringCompanionObject = StringCompanionObject.INSTANCE; String format = String.format("%s/instruments", Arrays.copyOf(new Object[]{FacebookSdk.getApplicationId()}, 1)); Intrinsics.checkNotNullExpressionValue(format, "java.lang.String.format(format, *args)"); arrayList.add(companion.newPostRequest(null, format, jSONObject, new GraphRequest.Callback() { // from class: com.facebook.internal.instrument.ExceptionAnalyzer$$ExternalSyntheticLambda0 @Override // com.facebook.GraphRequest.Callback public final void onCompleted(GraphResponse graphResponse) { ExceptionAnalyzer.m590sendExceptionAnalysisReports$lambda1(InstrumentData.this, graphResponse); } })); } catch (JSONException unused) { } } } if (arrayList.isEmpty()) { return; } new GraphRequestBatch(arrayList).executeAsync(); } /* JADX INFO: Access modifiers changed from: private */ /* renamed from: sendExceptionAnalysisReports$lambda-1, reason: not valid java name */ public static final void m590sendExceptionAnalysisReports$lambda1(InstrumentData instrumentData, GraphResponse response) { Intrinsics.checkNotNullParameter(instrumentData, "$instrumentData"); Intrinsics.checkNotNullParameter(response, "response"); try { if (response.getError() == null) { JSONObject jsonObject = response.getJsonObject(); if (Intrinsics.areEqual(jsonObject == null ? null : Boolean.valueOf(jsonObject.getBoolean("success")), Boolean.TRUE)) { instrumentData.clear(); } } } catch (JSONException unused) { } } }