package androidx.lifecycle;

import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.CoroutineSingletons;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.Ref$ObjectRef;
import kotlin.jvm.internal.SourceDebugExtension;
import org.jetbrains.annotations.NotNull;

/* JADX INFO: loaded from: classes.dex */
@Metadata(d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\u0010\u0007\u001a\u00020\u00042\u0006\u0010\u0001\u001a\u00020\u00002\u0006\u0010\u0003\u001a\u00020\u0002H\n¢\u0006\u0004\b\u0005\u0010\u0006"}, d2 = {"Landroidx/lifecycle/p;", "<anonymous parameter 0>", "Landroidx/lifecycle/Lifecycle$Event;", "event", "Lkd/e;", "onStateChanged", "(Landroidx/lifecycle/p;Landroidx/lifecycle/Lifecycle$Event;)V", "<anonymous>"}, k = 3, mv = {1, 8, 0})
final class RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1 implements LifecycleEventObserver {
    final /* synthetic */ kotlinx.coroutines.x $$this$coroutineScope;
    final /* synthetic */ Function2 $block;
    final /* synthetic */ Lifecycle$Event $cancelWorkEvent;
    final /* synthetic */ kotlinx.coroutines.g $cont;
    final /* synthetic */ Ref$ObjectRef<kotlinx.coroutines.y0> $launchedJob;
    final /* synthetic */ kotlinx.coroutines.sync.a $mutex;
    final /* synthetic */ Lifecycle$Event $startWorkEvent;

    /* JADX INFO: renamed from: androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1, reason: invalid class name */
    @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\u008a@"}, d2 = {"Lkotlinx/coroutines/x;", "Lkd/e;", "<anonymous>"}, k = 3, mv = {1, 8, 0})
    @DebugMetadata(c = "androidx.lifecycle.RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1", f = "RepeatOnLifecycle.kt", i = {0, 1}, l = {171, 110}, m = "invokeSuspend", n = {"$this$withLock_u24default$iv", "$this$withLock_u24default$iv"}, s = {"L$0", "L$0"})
    @SourceDebugExtension({"SMAP\nRepeatOnLifecycle.kt\nKotlin\n*S Kotlin\n*F\n+ 1 RepeatOnLifecycle.kt\nandroidx/lifecycle/RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1\n+ 2 Mutex.kt\nkotlinx/coroutines/sync/MutexKt\n*L\n1#1,165:1\n120#2,10:166\n*S KotlinDebug\n*F\n+ 1 RepeatOnLifecycle.kt\nandroidx/lifecycle/RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1\n*L\n109#1:166,10\n*E\n"})
    public static final class AnonymousClass1 extends SuspendLambda implements Function2 {
        final /* synthetic */ Function2 $block;
        final /* synthetic */ kotlinx.coroutines.sync.a $mutex;
        Object L$0;
        Object L$1;
        int label;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public AnonymousClass1(kotlinx.coroutines.sync.a aVar, Function2 function2, Continuation continuation) {
            super(2, continuation);
            this.$mutex = aVar;
            this.$block = function2;
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Continuation create(Object obj, Continuation continuation) {
            return new AnonymousClass1(this.$mutex, this.$block, continuation);
        }

        @Override // kotlin.jvm.functions.Function2
        public final Object invoke(Object obj, Object obj2) {
            return ((AnonymousClass1) create((kotlinx.coroutines.x) obj, (Continuation) obj2)).invokeSuspend(kd.e.f29109a);
        }

        @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
        public final Object invokeSuspend(Object obj) throws Throwable {
            kotlinx.coroutines.sync.a aVar;
            Function2 function2;
            kotlinx.coroutines.sync.a aVar2;
            Throwable th;
            CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
            int i10 = this.label;
            try {
                if (i10 == 0) {
                    kotlin.a.d(obj);
                    aVar = this.$mutex;
                    function2 = this.$block;
                    this.L$0 = aVar;
                    this.L$1 = function2;
                    this.label = 1;
                    if (aVar.e(this) == coroutineSingletons) {
                        return coroutineSingletons;
                    }
                } else {
                    if (i10 != 1) {
                        if (i10 != 2) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        aVar2 = (kotlinx.coroutines.sync.a) this.L$0;
                        try {
                            kotlin.a.d(obj);
                            aVar2.g(null);
                            return kd.e.f29109a;
                        } catch (Throwable th2) {
                            th = th2;
                            aVar2.g(null);
                            throw th;
                        }
                    }
                    function2 = (Function2) this.L$1;
                    kotlinx.coroutines.sync.a aVar3 = (kotlinx.coroutines.sync.a) this.L$0;
                    kotlin.a.d(obj);
                    aVar = aVar3;
                }
                RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1$1$1 repeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1$1$1 = new RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1$1$1(function2, null);
                this.L$0 = aVar;
                this.L$1 = null;
                this.label = 2;
                kotlinx.coroutines.internal.r rVar = new kotlinx.coroutines.internal.r(this, getContext());
                if (kotlinx.coroutines.y.c0(rVar, rVar, repeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1$1$1$1) == coroutineSingletons) {
                    return coroutineSingletons;
                }
                aVar2 = aVar;
                aVar2.g(null);
                return kd.e.f29109a;
            } catch (Throwable th3) {
                aVar2 = aVar;
                th = th3;
                aVar2.g(null);
                throw th;
            }
        }
    }

    public RepeatOnLifecycleKt$repeatOnLifecycle$3$1$1$1(Lifecycle$Event lifecycle$Event, Ref$ObjectRef<kotlinx.coroutines.y0> ref$ObjectRef, kotlinx.coroutines.x xVar, Lifecycle$Event lifecycle$Event2, kotlinx.coroutines.g gVar, kotlinx.coroutines.sync.a aVar, Function2 function2) {
        this.$startWorkEvent = lifecycle$Event;
        this.$launchedJob = ref$ObjectRef;
        this.$$this$coroutineScope = xVar;
        this.$cancelWorkEvent = lifecycle$Event2;
        this.$cont = gVar;
        this.$mutex = aVar;
        this.$block = function2;
    }

    /* JADX WARN: Type inference failed for: r6v3, types: [T, kotlinx.coroutines.n1] */
    @Override // androidx.lifecycle.LifecycleEventObserver
    public final void onStateChanged(@NotNull p pVar, @NotNull Lifecycle$Event lifecycle$Event) {
        nb.g.i(pVar, "<anonymous parameter 0>");
        nb.g.i(lifecycle$Event, "event");
        if (lifecycle$Event == this.$startWorkEvent) {
            this.$launchedJob.element = hb.a.k0(this.$$this$coroutineScope, null, new AnonymousClass1(this.$mutex, this.$block, null), 3);
            return;
        }
        if (lifecycle$Event == this.$cancelWorkEvent) {
            kotlinx.coroutines.y0 y0Var = this.$launchedJob.element;
            if (y0Var != null) {
                y0Var.e(null);
            }
            this.$launchedJob.element = null;
        }
        if (lifecycle$Event == Lifecycle$Event.ON_DESTROY) {
            this.$cont.resumeWith(kd.e.f29109a);
        }
    }
}
