package kotlinx.coroutines.flow.internal;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes3.dex */
@kotlin.Metadata(d1 = {"\u0000P\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0010\u0000\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u000b\n\u0002\u0010\b\n\u0002\b\u000e\b\u0000\u0018\u0000*\u0004\b\u0000\u0010\u00012\b\u0012\u0004\u0012\u00028\u00000\u00022\u00020\u00032\u00020\u0004B\u001d\u0012\f\u0010\u0005\u001a\b\u0012\u0004\u0012\u00028\u00000\u0002\u0012\u0006\u0010\u0007\u001a\u00020\u0006¢\u0006\u0004\b\b\u0010\tJ'\u0010\u000f\u001a\u0004\u0018\u00010\u000e2\f\u0010\f\u001a\b\u0012\u0004\u0012\u00020\u000b0\n2\u0006\u0010\r\u001a\u00028\u0000H\u0002¢\u0006\u0004\b\u000f\u0010\u0010J)\u0010\u0013\u001a\u00020\u000b2\u0006\u0010\u0011\u001a\u00020\u00062\b\u0010\u0012\u001a\u0004\u0018\u00010\u00062\u0006\u0010\r\u001a\u00028\u0000H\u0002¢\u0006\u0004\b\u0013\u0010\u0014J!\u0010\u0017\u001a\u00020\u000b2\u0006\u0010\u0016\u001a\u00020\u00152\b\u0010\r\u001a\u0004\u0018\u00010\u000eH\u0002¢\u0006\u0004\b\u0017\u0010\u0018J\u0011\u0010\u001a\u001a\u0004\u0018\u00010\u0019H\u0016¢\u0006\u0004\b\u001a\u0010\u001bJ\u001f\u0010\u001e\u001a\u00020\u000e2\u000e\u0010\u001d\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u000e0\u001cH\u0014¢\u0006\u0004\b\u001e\u0010\u001fJ\u000f\u0010 \u001a\u00020\u000bH\u0016¢\u0006\u0004\b \u0010!J\u0018\u0010\"\u001a\u00020\u000b2\u0006\u0010\r\u001a\u00028\u0000H\u0096@¢\u0006\u0004\b\"\u0010#R\u001a\u0010\u0005\u001a\b\u0012\u0004\u0012\u00028\u00000\u00028\u0000X\u0081\u0004¢\u0006\u0006\n\u0004\b$\u0010%R\u0014\u0010\u0007\u001a\u00020\u00068\u0000X\u0081\u0004¢\u0006\u0006\n\u0004\b&\u0010'R\u0014\u0010+\u001a\u00020(8\u0000X\u0081\u0004¢\u0006\u0006\n\u0004\b)\u0010*R\u0018\u0010,\u001a\u0004\u0018\u00010\u00068\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0017\u0010'R\u001e\u0010/\u001a\n\u0012\u0004\u0012\u00020\u000b\u0018\u00010\n8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b-\u0010.R\u0016\u00102\u001a\u0004\u0018\u00010\u00048VX\u0096\u0004¢\u0006\u0006\u001a\u0004\b0\u00101R\u0014\u00105\u001a\u00020\u00068VX\u0096\u0004¢\u0006\u0006\u001a\u0004\b3\u00104¨\u00066"}, d2 = {"Lkotlinx/coroutines/flow/internal/SafeCollector;", "T", "Lkotlinx/coroutines/flow/FlowCollector;", "Lkotlin/coroutines/jvm/internal/ContinuationImpl;", "Lkotlin/coroutines/jvm/internal/CoroutineStackFrame;", "collector", "Lkotlin/coroutines/CoroutineContext;", "collectContext", "<init>", "(Lkotlinx/coroutines/flow/FlowCollector;Lkotlin/coroutines/CoroutineContext;)V", "Lkotlin/coroutines/Continuation;", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "uCont", "value", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "l", "(Lkotlin/coroutines/Continuation;Ljava/lang/Object;)Ljava/lang/Object;", "currentContext", "previousContext", "j", "(Lkotlin/coroutines/CoroutineContext;Lkotlin/coroutines/CoroutineContext;Ljava/lang/Object;)V", "Lkotlinx/coroutines/flow/internal/DownstreamExceptionContext;", "exception", "q", "(Lkotlinx/coroutines/flow/internal/DownstreamExceptionContext;Ljava/lang/Object;)V", "Ljava/lang/StackTraceElement;", "getStackTraceElement", "()Ljava/lang/StackTraceElement;", "Lkotlin/Result;", "result", "invokeSuspend", "(Ljava/lang/Object;)Ljava/lang/Object;", "releaseIntercepted", "()V", "emit", "(Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "n", "Lkotlinx/coroutines/flow/FlowCollector;", "o", "Lkotlin/coroutines/CoroutineContext;", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "p", "I", "collectContextSize", "lastEmissionContext", "r", "Lkotlin/coroutines/Continuation;", "completion_", "getCallerFrame", "()Lkotlin/coroutines/jvm/internal/CoroutineStackFrame;", "callerFrame", "getContext", "()Lkotlin/coroutines/CoroutineContext;", "context", "kotlinx-coroutines-core"}, k = 1, mv = {2, 1, 0}, xi = 48)
@kotlin.jvm.internal.SourceDebugExtension
public final class SafeCollector<T> extends kotlin.coroutines.jvm.internal.ContinuationImpl implements kotlinx.coroutines.flow.FlowCollector<T>, kotlin.coroutines.jvm.internal.CoroutineStackFrame {

    /* JADX INFO: renamed from: n, reason: from kotlin metadata */
    public final kotlinx.coroutines.flow.FlowCollector collector;

    /* JADX INFO: renamed from: o, reason: from kotlin metadata */
    public final kotlin.coroutines.CoroutineContext collectContext;

    /* JADX INFO: renamed from: p, reason: from kotlin metadata */
    public final int collectContextSize;

    /* JADX INFO: renamed from: q, reason: from kotlin metadata */
    private kotlin.coroutines.CoroutineContext lastEmissionContext;

    /* JADX INFO: renamed from: r, reason: from kotlin metadata */
    private kotlin.coroutines.Continuation completion_;

    public SafeCollector(kotlinx.coroutines.flow.FlowCollector flowCollector, kotlin.coroutines.CoroutineContext coroutineContext) {
        super(kotlinx.coroutines.flow.internal.NoOpContinuation.a, kotlin.coroutines.EmptyCoroutineContext.a);
        this.collector = flowCollector;
        this.collectContext = coroutineContext;
        this.collectContextSize = ((java.lang.Number) coroutineContext.u(0, new kotlin.jvm.functions.Function2() { // from class: kotlinx.coroutines.flow.internal.a
            public final java.lang.Object invoke(java.lang.Object obj, java.lang.Object obj2) {
                return java.lang.Integer.valueOf(kotlinx.coroutines.flow.internal.SafeCollector.k(((java.lang.Integer) obj).intValue(), (kotlin.coroutines.CoroutineContext.Element) obj2));
            }
        })).intValue();
    }

    private final void j(kotlin.coroutines.CoroutineContext currentContext, kotlin.coroutines.CoroutineContext previousContext, java.lang.Object value) {
        if (previousContext instanceof kotlinx.coroutines.flow.internal.DownstreamExceptionContext) {
            q((kotlinx.coroutines.flow.internal.DownstreamExceptionContext) previousContext, value);
        }
        kotlinx.coroutines.flow.internal.SafeCollector_commonKt.b(this, currentContext);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final int k(int i, kotlin.coroutines.CoroutineContext.Element element) {
        return i + 1;
    }

    private final java.lang.Object l(kotlin.coroutines.Continuation uCont, java.lang.Object value) {
        kotlin.coroutines.CoroutineContext context = uCont.getContext();
        kotlinx.coroutines.JobKt.k(context);
        kotlin.coroutines.CoroutineContext coroutineContext = this.lastEmissionContext;
        if (coroutineContext != context) {
            j(context, coroutineContext, value);
            this.lastEmissionContext = context;
        }
        this.completion_ = uCont;
        kotlin.jvm.functions.Function3 function3 = kotlinx.coroutines.flow.internal.SafeCollectorKt.a;
        kotlinx.coroutines.flow.FlowCollector flowCollector = this.collector;
        kotlin.jvm.internal.Intrinsics.j(flowCollector, "null cannot be cast to non-null type kotlinx.coroutines.flow.FlowCollector<kotlin.Any?>");
        kotlin.jvm.internal.Intrinsics.j(this, "null cannot be cast to non-null type kotlin.coroutines.Continuation<kotlin.Unit>");
        java.lang.Object objInvoke = function3.invoke(flowCollector, value, this);
        if (!kotlin.jvm.internal.Intrinsics.g(objInvoke, kotlin.coroutines.intrinsics.IntrinsicsKt.g())) {
            this.completion_ = null;
        }
        return objInvoke;
    }

    private final void q(kotlinx.coroutines.flow.internal.DownstreamExceptionContext exception, java.lang.Object value) {
        throw new java.lang.IllegalStateException(kotlin.text.StringsKt.n("\n            Flow exception transparency is violated:\n                Previous 'emit' call has thrown exception " + exception.e + ", but then emission attempt of value '" + value + "' has been detected.\n                Emissions from 'catch' blocks are prohibited in order to avoid unspecified behaviour, 'Flow.catch' operator can be used instead.\n                For a more detailed explanation, please refer to Flow documentation.\n            ").toString());
    }

    @Override // kotlinx.coroutines.flow.FlowCollector
    public java.lang.Object emit(java.lang.Object obj, kotlin.coroutines.Continuation continuation) {
        try {
            java.lang.Object objL = l(continuation, obj);
            if (objL == kotlin.coroutines.intrinsics.IntrinsicsKt.g()) {
                kotlin.coroutines.jvm.internal.DebugProbesKt.c(continuation);
            }
            return objL == kotlin.coroutines.intrinsics.IntrinsicsKt.g() ? objL : kotlin.Unit.a;
        } catch (java.lang.Throwable th) {
            this.lastEmissionContext = new kotlinx.coroutines.flow.internal.DownstreamExceptionContext(th, continuation.getContext());
            throw th;
        }
    }

    public kotlin.coroutines.jvm.internal.CoroutineStackFrame getCallerFrame() {
        kotlin.coroutines.jvm.internal.CoroutineStackFrame coroutineStackFrame = this.completion_;
        if (coroutineStackFrame instanceof kotlin.coroutines.jvm.internal.CoroutineStackFrame) {
            return coroutineStackFrame;
        }
        return null;
    }

    public kotlin.coroutines.CoroutineContext getContext() {
        kotlin.coroutines.CoroutineContext coroutineContext = this.lastEmissionContext;
        return coroutineContext == null ? kotlin.coroutines.EmptyCoroutineContext.a : coroutineContext;
    }

    public java.lang.StackTraceElement getStackTraceElement() {
        return null;
    }

    protected java.lang.Object invokeSuspend(java.lang.Object result) {
        java.lang.Throwable thE = kotlin.Result.e(result);
        if (thE != null) {
            this.lastEmissionContext = new kotlinx.coroutines.flow.internal.DownstreamExceptionContext(thE, getContext());
        }
        kotlin.coroutines.Continuation continuation = this.completion_;
        if (continuation != null) {
            continuation.resumeWith(result);
        }
        return kotlin.coroutines.intrinsics.IntrinsicsKt.g();
    }

    public void releaseIntercepted() {
        super.releaseIntercepted();
    }
}
