package androidx.activity; import io.sentry.protocol.SentryStackFrame; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.Executor; import kotlin.Metadata; import kotlin.Unit; import kotlin.jvm.functions.Function0; import kotlin.jvm.internal.Intrinsics; /* compiled from: FullyDrawnReporter.kt */ @Metadata(d1 = {"\u0000<\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0010!\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\b\u0018\u00002\u00020\u0001B\u001b\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\f\u0010\u0004\u001a\b\u0012\u0004\u0012\u00020\u00060\u0005¢\u0006\u0002\u0010\u0007J\u0014\u0010\u0014\u001a\u00020\u00062\f\u0010\u0015\u001a\b\u0012\u0004\u0012\u00020\u00060\u0005J\u0006\u0010\u0016\u001a\u00020\u0006J\b\u0010\u0017\u001a\u00020\u0006H\u0007J\b\u0010\u0018\u001a\u00020\u0006H\u0002J\u0014\u0010\u0019\u001a\u00020\u00062\f\u0010\u0015\u001a\b\u0012\u0004\u0012\u00020\u00060\u0005J\u0006\u0010\u001a\u001a\u00020\u0006R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u0011\u0010\b\u001a\u00020\t8F¢\u0006\u0006\u001a\u0004\b\b\u0010\nR\u000e\u0010\u000b\u001a\u00020\u0001X\u0082\u0004¢\u0006\u0002\n\u0000R\u001c\u0010\f\u001a\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00060\u00050\r8\u0002X\u0083\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u0004\u001a\b\u0012\u0004\u0012\u00020\u00060\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u0012\u0010\u000e\u001a\u00020\t8\u0002@\u0002X\u0083\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u000f\u001a\u00020\u0010X\u0082\u0004¢\u0006\u0002\n\u0000R\u0012\u0010\u0011\u001a\u00020\t8\u0002@\u0002X\u0083\u000e¢\u0006\u0002\n\u0000R\u0012\u0010\u0012\u001a\u00020\u00138\u0002@\u0002X\u0083\u000e¢\u0006\u0002\n\u0000¨\u0006\u001b"}, d2 = {"Landroidx/activity/FullyDrawnReporter;", "", "executor", "Ljava/util/concurrent/Executor;", "reportFullyDrawn", "Lkotlin/Function0;", "", "(Ljava/util/concurrent/Executor;Lkotlin/jvm/functions/Function0;)V", "isFullyDrawnReported", "", "()Z", SentryStackFrame.JsonKeys.LOCK, "onReportCallbacks", "", "reportPosted", "reportRunnable", "Ljava/lang/Runnable;", "reportedFullyDrawn", "reporterCount", "", "addOnReportDrawnListener", "callback", "addReporter", "fullyDrawnReported", "postWhenReportersAreDone", "removeOnReportDrawnListener", "removeReporter", "activity_release"}, k = 1, mv = {1, 8, 0}, xi = 48) /* loaded from: classes.dex */ public final class FullyDrawnReporter { private final Executor executor; private final Object lock; private final List> onReportCallbacks; private final Function0 reportFullyDrawn; private boolean reportPosted; private final Runnable reportRunnable; private boolean reportedFullyDrawn; private int reporterCount; public FullyDrawnReporter(Executor executor, Function0 reportFullyDrawn) { Intrinsics.checkNotNullParameter(executor, "executor"); Intrinsics.checkNotNullParameter(reportFullyDrawn, "reportFullyDrawn"); this.executor = executor; this.reportFullyDrawn = reportFullyDrawn; this.lock = new Object(); this.onReportCallbacks = new ArrayList(); this.reportRunnable = new Runnable() { // from class: androidx.activity.FullyDrawnReporter$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { FullyDrawnReporter.reportRunnable$lambda$2(FullyDrawnReporter.this); } }; } public final boolean isFullyDrawnReported() { boolean z; synchronized (this.lock) { z = this.reportedFullyDrawn; } return z; } /* JADX INFO: Access modifiers changed from: private */ public static final void reportRunnable$lambda$2(FullyDrawnReporter this$0) { Intrinsics.checkNotNullParameter(this$0, "this$0"); synchronized (this$0.lock) { this$0.reportPosted = false; if (this$0.reporterCount == 0 && !this$0.reportedFullyDrawn) { this$0.reportFullyDrawn.invoke(); this$0.fullyDrawnReported(); } Unit unit = Unit.INSTANCE; } } public final void addReporter() { synchronized (this.lock) { if (!this.reportedFullyDrawn) { this.reporterCount++; } Unit unit = Unit.INSTANCE; } } public final void removeReporter() { int i; synchronized (this.lock) { if (!this.reportedFullyDrawn && (i = this.reporterCount) > 0) { this.reporterCount = i - 1; postWhenReportersAreDone(); } Unit unit = Unit.INSTANCE; } } public final void addOnReportDrawnListener(Function0 callback) { boolean z; Intrinsics.checkNotNullParameter(callback, "callback"); synchronized (this.lock) { if (this.reportedFullyDrawn) { z = true; } else { this.onReportCallbacks.add(callback); z = false; } } if (z) { callback.invoke(); } } public final void removeOnReportDrawnListener(Function0 callback) { Intrinsics.checkNotNullParameter(callback, "callback"); synchronized (this.lock) { this.onReportCallbacks.remove(callback); Unit unit = Unit.INSTANCE; } } public final void fullyDrawnReported() { synchronized (this.lock) { this.reportedFullyDrawn = true; Iterator it = this.onReportCallbacks.iterator(); while (it.hasNext()) { ((Function0) it.next()).invoke(); } this.onReportCallbacks.clear(); Unit unit = Unit.INSTANCE; } } private final void postWhenReportersAreDone() { if (this.reportPosted || this.reporterCount != 0) { return; } this.reportPosted = true; this.executor.execute(this.reportRunnable); } }