Add decompiled APK source code (JADX)

- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-18 14:52:23 -08:00
parent cc210a65ea
commit f9d20bb3fc
26991 changed files with 2541449 additions and 0 deletions

View File

@@ -0,0 +1,323 @@
package com.google.firebase.perf.application;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import com.google.firebase.perf.config.ConfigResolver;
import com.google.firebase.perf.logging.AndroidLogger;
import com.google.firebase.perf.metrics.FrameMetricsCalculator;
import com.google.firebase.perf.metrics.Trace;
import com.google.firebase.perf.session.SessionManager;
import com.google.firebase.perf.transport.TransportManager;
import com.google.firebase.perf.util.Clock;
import com.google.firebase.perf.util.Constants$CounterNames;
import com.google.firebase.perf.util.Constants$TraceNames;
import com.google.firebase.perf.util.Optional;
import com.google.firebase.perf.util.ScreenTraceUtil;
import com.google.firebase.perf.util.Timer;
import com.google.firebase.perf.v1.ApplicationProcessState;
import com.google.firebase.perf.v1.TraceMetric;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicInteger;
/* loaded from: classes3.dex */
public class AppStateMonitor implements Application.ActivityLifecycleCallbacks {
public static volatile AppStateMonitor instance;
public static final AndroidLogger logger = AndroidLogger.getInstance();
public final WeakHashMap activityToFragmentStateMonitorMap;
public final WeakHashMap activityToRecorderMap;
public final WeakHashMap activityToResumedMap;
public final WeakHashMap activityToScreenTraceMap;
public Set appColdStartSubscribers;
public final Set appStateSubscribers;
public final Clock clock;
public final ConfigResolver configResolver;
public ApplicationProcessState currentAppState;
public boolean isColdStart;
public boolean isRegisteredForLifecycleCallbacks;
public final Map metricToCountMap;
public Timer resumeTime;
public final boolean screenPerformanceRecordingSupported;
public Timer stopTime;
public final TransportManager transportManager;
public final AtomicInteger tsnsCount;
public interface AppColdStartCallback {
void onAppColdStart();
}
public interface AppStateCallback {
void onUpdateAppState(ApplicationProcessState applicationProcessState);
}
public ApplicationProcessState getAppState() {
return this.currentAppState;
}
public boolean isColdStart() {
return this.isColdStart;
}
public boolean isScreenTraceSupported() {
return this.screenPerformanceRecordingSupported;
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityPaused(Activity activity) {
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
}
public static AppStateMonitor getInstance() {
if (instance == null) {
synchronized (AppStateMonitor.class) {
try {
if (instance == null) {
instance = new AppStateMonitor(TransportManager.getInstance(), new Clock());
}
} finally {
}
}
}
return instance;
}
public AppStateMonitor(TransportManager transportManager, Clock clock) {
this(transportManager, clock, ConfigResolver.getInstance(), isScreenPerformanceRecordingSupported());
}
public AppStateMonitor(TransportManager transportManager, Clock clock, ConfigResolver configResolver, boolean z) {
this.activityToResumedMap = new WeakHashMap();
this.activityToRecorderMap = new WeakHashMap();
this.activityToFragmentStateMonitorMap = new WeakHashMap();
this.activityToScreenTraceMap = new WeakHashMap();
this.metricToCountMap = new HashMap();
this.appStateSubscribers = new HashSet();
this.appColdStartSubscribers = new HashSet();
this.tsnsCount = new AtomicInteger(0);
this.currentAppState = ApplicationProcessState.BACKGROUND;
this.isRegisteredForLifecycleCallbacks = false;
this.isColdStart = true;
this.transportManager = transportManager;
this.clock = clock;
this.configResolver = configResolver;
this.screenPerformanceRecordingSupported = z;
}
public synchronized void registerActivityLifecycleCallbacks(Context context) {
if (this.isRegisteredForLifecycleCallbacks) {
return;
}
Context applicationContext = context.getApplicationContext();
if (applicationContext instanceof Application) {
((Application) applicationContext).registerActivityLifecycleCallbacks(this);
this.isRegisteredForLifecycleCallbacks = true;
}
}
public void incrementCount(String str, long j) {
synchronized (this.metricToCountMap) {
try {
Long l = (Long) this.metricToCountMap.get(str);
if (l == null) {
this.metricToCountMap.put(str, Long.valueOf(j));
} else {
this.metricToCountMap.put(str, Long.valueOf(l.longValue() + j));
}
} catch (Throwable th) {
throw th;
}
}
}
public void incrementTsnsCount(int i) {
this.tsnsCount.addAndGet(i);
}
public final void startFrameMonitoring(Activity activity) {
if (isScreenTraceSupported() && this.configResolver.isPerformanceMonitoringEnabled()) {
FrameMetricsRecorder frameMetricsRecorder = new FrameMetricsRecorder(activity);
this.activityToRecorderMap.put(activity, frameMetricsRecorder);
if (activity instanceof FragmentActivity) {
FragmentStateMonitor fragmentStateMonitor = new FragmentStateMonitor(this.clock, this.transportManager, this, frameMetricsRecorder);
this.activityToFragmentStateMonitorMap.put(activity, fragmentStateMonitor);
((FragmentActivity) activity).getSupportFragmentManager().registerFragmentLifecycleCallbacks(fragmentStateMonitor, true);
}
}
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityCreated(Activity activity, Bundle bundle) {
startFrameMonitoring(activity);
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public void onActivityDestroyed(Activity activity) {
this.activityToRecorderMap.remove(activity);
if (this.activityToFragmentStateMonitorMap.containsKey(activity)) {
((FragmentActivity) activity).getSupportFragmentManager().unregisterFragmentLifecycleCallbacks((FragmentManager.FragmentLifecycleCallbacks) this.activityToFragmentStateMonitorMap.remove(activity));
}
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public synchronized void onActivityStarted(Activity activity) {
try {
if (isScreenTraceSupported() && this.configResolver.isPerformanceMonitoringEnabled()) {
if (!this.activityToRecorderMap.containsKey(activity)) {
startFrameMonitoring(activity);
}
((FrameMetricsRecorder) this.activityToRecorderMap.get(activity)).start();
Trace trace = new Trace(getScreenTraceName(activity), this.transportManager, this.clock, this);
trace.start();
this.activityToScreenTraceMap.put(activity, trace);
}
} catch (Throwable th) {
throw th;
}
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public synchronized void onActivityStopped(Activity activity) {
try {
if (isScreenTraceSupported()) {
sendScreenTrace(activity);
}
if (this.activityToResumedMap.containsKey(activity)) {
this.activityToResumedMap.remove(activity);
if (this.activityToResumedMap.isEmpty()) {
this.stopTime = this.clock.getTime();
sendSessionLog(Constants$TraceNames.FOREGROUND_TRACE_NAME.toString(), this.resumeTime, this.stopTime);
updateAppState(ApplicationProcessState.BACKGROUND);
}
}
} catch (Throwable th) {
throw th;
}
}
@Override // android.app.Application.ActivityLifecycleCallbacks
public synchronized void onActivityResumed(Activity activity) {
try {
if (this.activityToResumedMap.isEmpty()) {
this.resumeTime = this.clock.getTime();
this.activityToResumedMap.put(activity, Boolean.TRUE);
if (this.isColdStart) {
updateAppState(ApplicationProcessState.FOREGROUND);
sendAppColdStartUpdate();
this.isColdStart = false;
} else {
sendSessionLog(Constants$TraceNames.BACKGROUND_TRACE_NAME.toString(), this.stopTime, this.resumeTime);
updateAppState(ApplicationProcessState.FOREGROUND);
}
} else {
this.activityToResumedMap.put(activity, Boolean.TRUE);
}
} catch (Throwable th) {
throw th;
}
}
public void registerForAppState(WeakReference weakReference) {
synchronized (this.appStateSubscribers) {
this.appStateSubscribers.add(weakReference);
}
}
public void unregisterForAppState(WeakReference weakReference) {
synchronized (this.appStateSubscribers) {
this.appStateSubscribers.remove(weakReference);
}
}
public void registerForAppColdStart(AppColdStartCallback appColdStartCallback) {
synchronized (this.appColdStartSubscribers) {
this.appColdStartSubscribers.add(appColdStartCallback);
}
}
public final void updateAppState(ApplicationProcessState applicationProcessState) {
this.currentAppState = applicationProcessState;
synchronized (this.appStateSubscribers) {
try {
Iterator it = this.appStateSubscribers.iterator();
while (it.hasNext()) {
AppStateCallback appStateCallback = (AppStateCallback) ((WeakReference) it.next()).get();
if (appStateCallback != null) {
appStateCallback.onUpdateAppState(this.currentAppState);
} else {
it.remove();
}
}
} catch (Throwable th) {
throw th;
}
}
}
public final void sendAppColdStartUpdate() {
synchronized (this.appColdStartSubscribers) {
try {
for (AppColdStartCallback appColdStartCallback : this.appColdStartSubscribers) {
if (appColdStartCallback != null) {
appColdStartCallback.onAppColdStart();
}
}
} catch (Throwable th) {
throw th;
}
}
}
public final void sendScreenTrace(Activity activity) {
Trace trace = (Trace) this.activityToScreenTraceMap.get(activity);
if (trace == null) {
return;
}
this.activityToScreenTraceMap.remove(activity);
Optional stop = ((FrameMetricsRecorder) this.activityToRecorderMap.get(activity)).stop();
if (!stop.isAvailable()) {
logger.warn("Failed to record frame data for %s.", activity.getClass().getSimpleName());
} else {
ScreenTraceUtil.addFrameCounters(trace, (FrameMetricsCalculator.PerfFrameMetrics) stop.get());
trace.stop();
}
}
public final void sendSessionLog(String str, Timer timer, Timer timer2) {
if (this.configResolver.isPerformanceMonitoringEnabled()) {
TraceMetric.Builder addPerfSessions = TraceMetric.newBuilder().setName(str).setClientStartTimeUs(timer.getMicros()).setDurationUs(timer.getDurationMicros(timer2)).addPerfSessions(SessionManager.getInstance().perfSession().build());
int andSet = this.tsnsCount.getAndSet(0);
synchronized (this.metricToCountMap) {
try {
addPerfSessions.putAllCounters(this.metricToCountMap);
if (andSet != 0) {
addPerfSessions.putCounters(Constants$CounterNames.TRACE_STARTED_NOT_STOPPED.toString(), andSet);
}
this.metricToCountMap.clear();
} catch (Throwable th) {
throw th;
}
}
this.transportManager.log((TraceMetric) addPerfSessions.build(), ApplicationProcessState.FOREGROUND_BACKGROUND);
}
}
public static boolean isScreenPerformanceRecordingSupported() {
return FrameMetricsRecorder.isFrameMetricsRecordingSupported();
}
public static String getScreenTraceName(Activity activity) {
return "_st_" + activity.getClass().getSimpleName();
}
}

View File

@@ -0,0 +1,68 @@
package com.google.firebase.perf.application;
import androidx.annotation.VisibleForTesting;
import com.google.firebase.perf.application.AppStateMonitor;
import com.google.firebase.perf.v1.ApplicationProcessState;
import java.lang.ref.WeakReference;
/* loaded from: classes3.dex */
public abstract class AppStateUpdateHandler implements AppStateMonitor.AppStateCallback {
private final WeakReference<AppStateMonitor.AppStateCallback> appStateCallback;
private final AppStateMonitor appStateMonitor;
private ApplicationProcessState currentAppState;
private boolean isRegisteredForAppState;
public ApplicationProcessState getAppState() {
return this.currentAppState;
}
@VisibleForTesting
public WeakReference<AppStateMonitor.AppStateCallback> getAppStateCallback() {
return this.appStateCallback;
}
public AppStateUpdateHandler() {
this(AppStateMonitor.getInstance());
}
public AppStateUpdateHandler(AppStateMonitor appStateMonitor) {
this.isRegisteredForAppState = false;
this.currentAppState = ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN;
this.appStateMonitor = appStateMonitor;
this.appStateCallback = new WeakReference<>(this);
}
public void registerForAppState() {
if (this.isRegisteredForAppState) {
return;
}
this.currentAppState = this.appStateMonitor.getAppState();
this.appStateMonitor.registerForAppState(this.appStateCallback);
this.isRegisteredForAppState = true;
}
public void unregisterForAppState() {
if (this.isRegisteredForAppState) {
this.appStateMonitor.unregisterForAppState(this.appStateCallback);
this.isRegisteredForAppState = false;
}
}
public void incrementTsnsCount(int i) {
this.appStateMonitor.incrementTsnsCount(i);
}
@Override // com.google.firebase.perf.application.AppStateMonitor.AppStateCallback
public void onUpdateAppState(ApplicationProcessState applicationProcessState) {
ApplicationProcessState applicationProcessState2 = this.currentAppState;
ApplicationProcessState applicationProcessState3 = ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN;
if (applicationProcessState2 == applicationProcessState3) {
this.currentAppState = applicationProcessState;
} else {
if (applicationProcessState2 == applicationProcessState || applicationProcessState == applicationProcessState3) {
return;
}
this.currentAppState = ApplicationProcessState.FOREGROUND_BACKGROUND;
}
}
}

View File

@@ -0,0 +1,74 @@
package com.google.firebase.perf.application;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import com.google.firebase.perf.logging.AndroidLogger;
import com.google.firebase.perf.metrics.FrameMetricsCalculator;
import com.google.firebase.perf.metrics.Trace;
import com.google.firebase.perf.transport.TransportManager;
import com.google.firebase.perf.util.Clock;
import com.google.firebase.perf.util.Optional;
import com.google.firebase.perf.util.ScreenTraceUtil;
import java.util.WeakHashMap;
/* loaded from: classes3.dex */
public class FragmentStateMonitor extends FragmentManager.FragmentLifecycleCallbacks {
private static final AndroidLogger logger = AndroidLogger.getInstance();
private final FrameMetricsRecorder activityFramesRecorder;
private final AppStateMonitor appStateMonitor;
private final Clock clock;
private final WeakHashMap<Fragment, Trace> fragmentToTraceMap = new WeakHashMap<>();
private final TransportManager transportManager;
@VisibleForTesting
public WeakHashMap<Fragment, Trace> getFragmentToTraceMap() {
return this.fragmentToTraceMap;
}
public FragmentStateMonitor(Clock clock, TransportManager transportManager, AppStateMonitor appStateMonitor, FrameMetricsRecorder frameMetricsRecorder) {
this.clock = clock;
this.transportManager = transportManager;
this.appStateMonitor = appStateMonitor;
this.activityFramesRecorder = frameMetricsRecorder;
}
public String getFragmentScreenTraceName(Fragment fragment) {
return "_st_" + fragment.getClass().getSimpleName();
}
@Override // androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks
public void onFragmentResumed(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
super.onFragmentResumed(fragmentManager, fragment);
logger.debug("FragmentMonitor %s.onFragmentResumed", fragment.getClass().getSimpleName());
Trace trace = new Trace(getFragmentScreenTraceName(fragment), this.transportManager, this.clock, this.appStateMonitor);
trace.start();
trace.putAttribute("Parent_fragment", fragment.getParentFragment() == null ? "No parent" : fragment.getParentFragment().getClass().getSimpleName());
if (fragment.getActivity() != null) {
trace.putAttribute("Hosting_activity", fragment.getActivity().getClass().getSimpleName());
}
this.fragmentToTraceMap.put(fragment, trace);
this.activityFramesRecorder.startFragment(fragment);
}
@Override // androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks
public void onFragmentPaused(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
super.onFragmentPaused(fragmentManager, fragment);
AndroidLogger androidLogger = logger;
androidLogger.debug("FragmentMonitor %s.onFragmentPaused ", fragment.getClass().getSimpleName());
if (!this.fragmentToTraceMap.containsKey(fragment)) {
androidLogger.warn("FragmentMonitor: missed a fragment trace from %s", fragment.getClass().getSimpleName());
return;
}
Trace trace = this.fragmentToTraceMap.get(fragment);
this.fragmentToTraceMap.remove(fragment);
Optional stopFragment = this.activityFramesRecorder.stopFragment(fragment);
if (!stopFragment.isAvailable()) {
androidLogger.warn("onFragmentPaused: recorder failed to trace %s", fragment.getClass().getSimpleName());
} else {
ScreenTraceUtil.addFrameCounters(trace, (FrameMetricsCalculator.PerfFrameMetrics) stopFragment.get());
trace.stop();
}
}
}

View File

@@ -0,0 +1,121 @@
package com.google.firebase.perf.application;
import android.app.Activity;
import android.os.Build;
import android.util.SparseIntArray;
import androidx.core.app.FrameMetricsAggregator;
import androidx.fragment.app.Fragment;
import com.google.firebase.perf.logging.AndroidLogger;
import com.google.firebase.perf.metrics.FrameMetricsCalculator;
import com.google.firebase.perf.util.Optional;
import java.util.HashMap;
import java.util.Map;
/* loaded from: classes3.dex */
public class FrameMetricsRecorder {
public static final AndroidLogger logger = AndroidLogger.getInstance();
public final Activity activity;
public final Map fragmentSnapshotMap;
public final FrameMetricsAggregator frameMetricsAggregator;
public boolean isRecording;
public static boolean isFrameMetricsRecordingSupported() {
return true;
}
public FrameMetricsRecorder(Activity activity) {
this(activity, new FrameMetricsAggregator(), new HashMap());
}
public FrameMetricsRecorder(Activity activity, FrameMetricsAggregator frameMetricsAggregator, Map map) {
this.isRecording = false;
this.activity = activity;
this.frameMetricsAggregator = frameMetricsAggregator;
this.fragmentSnapshotMap = map;
}
public void start() {
if (this.isRecording) {
logger.debug("FrameMetricsAggregator is already recording %s", this.activity.getClass().getSimpleName());
} else {
this.frameMetricsAggregator.add(this.activity);
this.isRecording = true;
}
}
public Optional stop() {
if (!this.isRecording) {
logger.debug("Cannot stop because no recording was started");
return Optional.absent();
}
if (!this.fragmentSnapshotMap.isEmpty()) {
logger.debug("Sub-recordings are still ongoing! Sub-recordings should be stopped first before stopping Activity screen trace.");
this.fragmentSnapshotMap.clear();
}
Optional snapshot = snapshot();
try {
this.frameMetricsAggregator.remove(this.activity);
} catch (IllegalArgumentException | NullPointerException e) {
if ((e instanceof NullPointerException) && Build.VERSION.SDK_INT > 28) {
throw e;
}
logger.warn("View not hardware accelerated. Unable to collect FrameMetrics. %s", e.toString());
snapshot = Optional.absent();
}
this.frameMetricsAggregator.reset();
this.isRecording = false;
return snapshot;
}
public void startFragment(Fragment fragment) {
if (!this.isRecording) {
logger.debug("Cannot start sub-recording because FrameMetricsAggregator is not recording");
return;
}
if (this.fragmentSnapshotMap.containsKey(fragment)) {
logger.debug("Cannot start sub-recording because one is already ongoing with the key %s", fragment.getClass().getSimpleName());
return;
}
Optional snapshot = snapshot();
if (!snapshot.isAvailable()) {
logger.debug("startFragment(%s): snapshot() failed", fragment.getClass().getSimpleName());
} else {
this.fragmentSnapshotMap.put(fragment, (FrameMetricsCalculator.PerfFrameMetrics) snapshot.get());
}
}
public Optional stopFragment(Fragment fragment) {
if (!this.isRecording) {
logger.debug("Cannot stop sub-recording because FrameMetricsAggregator is not recording");
return Optional.absent();
}
if (!this.fragmentSnapshotMap.containsKey(fragment)) {
logger.debug("Sub-recording associated with key %s was not started or does not exist", fragment.getClass().getSimpleName());
return Optional.absent();
}
FrameMetricsCalculator.PerfFrameMetrics perfFrameMetrics = (FrameMetricsCalculator.PerfFrameMetrics) this.fragmentSnapshotMap.remove(fragment);
Optional snapshot = snapshot();
if (!snapshot.isAvailable()) {
logger.debug("stopFragment(%s): snapshot() failed", fragment.getClass().getSimpleName());
return Optional.absent();
}
return Optional.of(((FrameMetricsCalculator.PerfFrameMetrics) snapshot.get()).deltaFrameMetricsFromSnapshot(perfFrameMetrics));
}
public final Optional snapshot() {
if (!this.isRecording) {
logger.debug("No recording has been started.");
return Optional.absent();
}
SparseIntArray[] metrics = this.frameMetricsAggregator.getMetrics();
if (metrics == null) {
logger.debug("FrameMetricsAggregator.mMetrics is uninitialized.");
return Optional.absent();
}
if (metrics[0] == null) {
logger.debug("FrameMetricsAggregator.mMetrics[TOTAL_INDEX] is uninitialized.");
return Optional.absent();
}
return Optional.of(FrameMetricsCalculator.calculateFrameMetrics(metrics));
}
}