package com.strmr.ps.data.update;

import android.content.Context;
import android.util.Log;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.upstream.CmcdData;
import com.strmr.ps.data.model.UpdateCheckResult;
import com.strmr.ps.data.repository.UpdateRepository;
import com.strmr.ps.data.update.b;
import dagger.hilt.android.qualifiers.ApplicationContext;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.i49;
import defpackage.ig6;
import defpackage.io6;
import defpackage.k63;
import defpackage.kp6;
import defpackage.n41;
import defpackage.o29;
import defpackage.s38;
import defpackage.t87;
import javax.inject.Inject;
import javax.inject.Singleton;
import kotlin.Metadata;
import kotlin.coroutines.jvm.internal.ContinuationImpl;

/* JADX INFO: loaded from: classes3.dex */
@Singleton
@Metadata(d1 = {"\u0000\u001c\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\b\u0007\u0018\u00002\u00020\u0001:\u0001\nB#\b\u0007\u0012\b\b\u0001\u0010\u0003\u001a\u00020\u0002\u0012\u0006\u0010\u0005\u001a\u00020\u0004\u0012\u0006\u0010\u0007\u001a\u00020\u0006¢\u0006\u0004\b\b\u0010\t¨\u0006\u000b"}, d2 = {"Lcom/strmr/ps/data/update/UpdateManager;", "", "Landroid/content/Context;", "context", "Lcom/strmr/ps/data/repository/UpdateRepository;", "updateRepository", "Lt87;", "playStoreUpdateChecker", "<init>", "(Landroid/content/Context;Lcom/strmr/ps/data/repository/UpdateRepository;Lt87;)V", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
public final class UpdateManager {
    public final UpdateRepository a;
    public final t87 b;
    public final ig6 c;
    public final o29 d;

    @Metadata(d1 = {"\u0000\u0010\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u000e\n\u0002\b\u0003\b\u0086\u0003\u0018\u00002\u00020\u0001R\u0014\u0010\u0003\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0003\u0010\u0004¨\u0006\u0005"}, d2 = {"Lcom/strmr/ps/data/update/UpdateManager$a;", "", "", "TAG", "Ljava/lang/String;", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class a {
    }

    @Inject
    public UpdateManager(@ApplicationContext @kp6 Context context, @kp6 UpdateRepository updateRepository, @kp6 t87 t87Var) {
        cr4.g(context, "context");
        cr4.g(updateRepository, "updateRepository");
        cr4.g(t87Var, "playStoreUpdateChecker");
        this.a = updateRepository;
        this.b = t87Var;
        ig6 ig6VarA = i49.a(b.e.a);
        this.c = ig6VarA;
        this.d = k63.b(ig6VarA);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:31:0x005d A[Catch: Exception -> 0x002c, TryCatch #0 {Exception -> 0x002c, blocks: (B:14:0x0028, B:28:0x0057, B:29:0x0059, B:31:0x005d, B:33:0x0066, B:35:0x0078, B:37:0x008a, B:39:0x008e, B:41:0x0096, B:43:0x009a, B:45:0x00ac, B:46:0x00b1, B:21:0x0039), top: B:51:0x001f }] */
    /* JADX WARN: Removed duplicated region for block: B:37:0x008a A[Catch: Exception -> 0x002c, TryCatch #0 {Exception -> 0x002c, blocks: (B:14:0x0028, B:28:0x0057, B:29:0x0059, B:31:0x005d, B:33:0x0066, B:35:0x0078, B:37:0x008a, B:39:0x008e, B:41:0x0096, B:43:0x009a, B:45:0x00ac, B:46:0x00b1, B:21:0x0039), top: B:51:0x001f }] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /* JADX WARN: Type inference failed for: r0v14 */
    /* JADX WARN: Type inference failed for: r0v15 */
    /* JADX WARN: Type inference failed for: r0v2, types: [com.strmr.ps.data.update.a, kotlin.coroutines.Continuation] */
    /* JADX WARN: Type inference failed for: r0v5 */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object a(ContinuationImpl continuationImpl) {
        UpdateManager aVar;
        UpdateManager updateManager;
        UpdateCheckResult updateCheckResult;
        if (continuationImpl instanceof com.strmr.ps.data.update.a) {
            com.strmr.ps.data.update.a aVar2 = (com.strmr.ps.data.update.a) continuationImpl;
            int i = aVar2.d;
            if ((i & Integer.MIN_VALUE) != 0) {
                aVar2.d = i - Integer.MIN_VALUE;
                aVar = aVar2;
            } else {
                aVar = new com.strmr.ps.data.update.a(this, continuationImpl);
            }
        }
        Object objCheckForUpdate = aVar.b;
        ck1 ck1Var = ck1.a;
        int i2 = aVar.d;
        try {
            if (i2 == 0) {
                s38.b(objCheckForUpdate);
                this.c.setValue(b.a.a);
                try {
                    UpdateRepository updateRepository = this.a;
                    aVar.a = this;
                    aVar.d = 2;
                    objCheckForUpdate = updateRepository.checkForUpdate(aVar);
                    if (objCheckForUpdate == ck1Var) {
                        return ck1Var;
                    }
                    updateManager = this;
                } catch (Exception e) {
                    e = e;
                    aVar = this;
                    Log.e("UpdateManager", "Update check failed", e);
                    UpdateCheckResult.Error error = new UpdateCheckResult.Error(n41.n("Update check failed: ", e.getMessage()), e);
                    aVar.c.setValue(new b.c(error.getMessage()));
                    return error;
                }
            } else {
                if (i2 == 1) {
                    updateManager = aVar.a;
                    s38.b(objCheckForUpdate);
                    updateCheckResult = (UpdateCheckResult) objCheckForUpdate;
                    if (!(updateCheckResult instanceof UpdateCheckResult.UpdateAvailable)) {
                        if (((UpdateCheckResult.UpdateAvailable) updateCheckResult).isForced()) {
                            updateManager.c.setValue(new b.d(((UpdateCheckResult.UpdateAvailable) updateCheckResult).getUpdateInfo()));
                            return updateCheckResult;
                        }
                        updateManager.c.setValue(new b.h(((UpdateCheckResult.UpdateAvailable) updateCheckResult).getUpdateInfo()));
                        return updateCheckResult;
                    }
                    if (updateCheckResult instanceof UpdateCheckResult.NoUpdateAvailable) {
                        updateManager.c.setValue(b.g.a);
                        return updateCheckResult;
                    }
                    if (!(updateCheckResult instanceof UpdateCheckResult.Error)) {
                        throw new io6();
                    }
                    updateManager.c.setValue(new b.c(((UpdateCheckResult.Error) updateCheckResult).getMessage()));
                    return updateCheckResult;
                }
                if (i2 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                updateManager = aVar.a;
                s38.b(objCheckForUpdate);
            }
            updateCheckResult = (UpdateCheckResult) objCheckForUpdate;
            if (!(updateCheckResult instanceof UpdateCheckResult.UpdateAvailable)) {
            }
        } catch (Exception e2) {
            e = e2;
        }
    }
}
