alexandroid/decompiled/jadx/sources/androidx/tracing/Trace.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

122 lines
4.5 KiB
Java

package androidx.tracing;
import android.os.Build;
import androidx.annotation.NonNull;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import okio.Buffer$$ExternalSyntheticBUOutline0;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes14.dex */
public final class Trace {
static final int MAX_TRACE_LABEL_LENGTH = 127;
static final String TAG = "Trace";
private static Method sAsyncTraceBeginMethod;
private static Method sAsyncTraceEndMethod;
private static boolean sHasAppTracingEnabled;
private static Method sIsTagEnabledMethod;
private static Method sTraceCounterMethod;
private static long sTraceTagApp;
private Trace() {
}
public static void beginAsyncSection(@NonNull String str, int i) {
TraceApi29Impl.beginAsyncSection(truncatedTraceSectionLabel(str), i);
}
private static void beginAsyncSectionFallback(@NonNull String str, int i) {
try {
if (sAsyncTraceBeginMethod == null) {
sAsyncTraceBeginMethod = android.os.Trace.class.getMethod("asyncTraceBegin", Long.TYPE, String.class, Integer.TYPE);
}
sAsyncTraceBeginMethod.invoke(null, Long.valueOf(sTraceTagApp), str, Integer.valueOf(i));
} catch (Exception e) {
handleException("asyncTraceBegin", e);
}
}
public static void beginSection(@NonNull String str) {
TraceApi18Impl.beginSection(truncatedTraceSectionLabel(str));
}
public static void endAsyncSection(@NonNull String str, int i) {
TraceApi29Impl.endAsyncSection(truncatedTraceSectionLabel(str), i);
}
private static void endAsyncSectionFallback(@NonNull String str, int i) {
try {
if (sAsyncTraceEndMethod == null) {
sAsyncTraceEndMethod = android.os.Trace.class.getMethod("asyncTraceEnd", Long.TYPE, String.class, Integer.TYPE);
}
sAsyncTraceEndMethod.invoke(null, Long.valueOf(sTraceTagApp), str, Integer.valueOf(i));
} catch (Exception e) {
handleException("asyncTraceEnd", e);
}
}
public static void endSection() {
TraceApi18Impl.endSection();
}
public static void forceEnableAppTracing() {
if (Build.VERSION.SDK_INT < 31) {
try {
if (sHasAppTracingEnabled) {
return;
}
sHasAppTracingEnabled = true;
android.os.Trace.class.getMethod("setAppTracingAllowed", Boolean.TYPE).invoke(null, Boolean.TRUE);
} catch (Exception e) {
handleException("setAppTracingAllowed", e);
}
}
}
private static void handleException(@NonNull String str, @NonNull Exception exc) {
if (exc instanceof InvocationTargetException) {
Throwable cause = exc.getCause();
if (cause instanceof RuntimeException) {
throw ((RuntimeException) cause);
}
Buffer$$ExternalSyntheticBUOutline0.m(cause);
}
}
public static boolean isEnabled() {
return TraceApi29Impl.isEnabled();
}
private static boolean isEnabledFallback() {
try {
if (sIsTagEnabledMethod == null) {
sTraceTagApp = android.os.Trace.class.getField("TRACE_TAG_APP").getLong(null);
sIsTagEnabledMethod = android.os.Trace.class.getMethod("isTagEnabled", Long.TYPE);
}
return ((Boolean) sIsTagEnabledMethod.invoke(null, Long.valueOf(sTraceTagApp))).booleanValue();
} catch (Exception e) {
handleException("isTagEnabled", e);
return false;
}
}
public static void setCounter(@NonNull String str, int i) {
TraceApi29Impl.setCounter(truncatedTraceSectionLabel(str), i);
}
private static void setCounterFallback(@NonNull String str, int i) {
try {
if (sTraceCounterMethod == null) {
sTraceCounterMethod = android.os.Trace.class.getMethod("traceCounter", Long.TYPE, String.class, Integer.TYPE);
}
sTraceCounterMethod.invoke(null, Long.valueOf(sTraceTagApp), str, Integer.valueOf(i));
} catch (Exception e) {
handleException("traceCounter", e);
}
}
@NonNull
private static String truncatedTraceSectionLabel(@NonNull String str) {
return str.length() <= 127 ? str : str.substring(0, 127);
}
}