package a6;

import Z6.InterfaceC0382w;
import android.app.Application;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import c7.K;
import com.google.android.gms.internal.measurement.C1;
import com.martsnew.domain.model.LatestVersion;
import com.martsnew.tv.R;
import java.io.File;
import y5.C1763h;

/* JADX INFO: loaded from: classes.dex */
public final class s extends G6.i implements O6.p {

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public Object f7653u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public int f7654v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final /* synthetic */ u f7655w;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public s(u uVar, E6.d dVar) {
        super(2, dVar);
        this.f7655w = uVar;
    }

    @Override // O6.p
    public final Object k(Object obj, Object obj2) {
        return ((s) m((E6.d) obj2, (InterfaceC0382w) obj)).p(A6.n.f457a);
    }

    @Override // G6.a
    public final E6.d m(E6.d dVar, Object obj) {
        return new s(this.f7655w, dVar);
    }

    /* JADX WARN: Removed duplicated region for block: B:21:0x00b3  */
    /* JADX WARN: Removed duplicated region for block: B:28:0x00db  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x013d  */
    /* JADX WARN: Removed duplicated region for block: B:45:0x0174  */
    @Override // G6.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object p(Object obj) throws Throwable {
        Object objA;
        Object objB;
        Object obj2;
        Object obj3;
        F6.a aVar = F6.a.f2580q;
        int i = this.f7654v;
        p pVar = p.f7649a;
        u uVar = this.f7655w;
        if (i == 0) {
            C1.N(obj);
            if (Build.VERSION.SDK_INT >= 30) {
                uVar.h();
                Application application = uVar.f7658d;
                ContentResolver contentResolver = application.getContentResolver();
                ContentValues contentValues = new ContentValues();
                contentValues.put("_display_name", application.getString(R.string.app_name) + ".apk");
                contentValues.put("mime_type", "application/vnd.android.package-archive");
                contentValues.put("relative_path", Environment.DIRECTORY_DOWNLOADS);
                uVar.f7663j = contentResolver.insert(MediaStore.Files.getContentUri("external"), contentValues);
                String str = ((LatestVersion) uVar.f7662h.e()).f11054t;
                Uri uri = uVar.f7663j;
                r rVar = new r(uVar, 0);
                this.f7654v = 1;
                objB = uVar.f7659e.b(str, uri, rVar, this);
                if (objB != aVar) {
                    if (A6.j.a(objB) != null) {
                    }
                    if (!(objB instanceof A6.i)) {
                    }
                }
            } else {
                uVar.f7664k = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/" + uVar.f7658d.getString(R.string.app_name) + ".apk";
                String str2 = ((LatestVersion) uVar.f7662h.e()).f11054t;
                String str3 = uVar.f7664k;
                r rVar2 = new r(uVar, 1);
                this.f7654v = 3;
                objA = uVar.f7659e.a(str2, str3, rVar2, this);
                if (objA != aVar) {
                    if (A6.j.a(objA) != null) {
                    }
                    if (!(objA instanceof A6.i)) {
                    }
                }
            }
            return aVar;
        }
        if (i == 1) {
            C1.N(obj);
            objB = ((A6.j) obj).f449q;
            if (A6.j.a(objB) != null) {
                uVar.h();
                C1763h c1763h = new C1763h(pVar);
                K k8 = uVar.f7661g;
                k8.getClass();
                k8.g(null, c1763h);
                y5.n nVar = new y5.n(R.string.msg_unknown_error);
                this.f7653u = objB;
                this.f7654v = 2;
                if (uVar.g(nVar, this) != aVar) {
                    obj2 = objB;
                    objB = obj2;
                }
                return aVar;
            }
            if (!(objB instanceof A6.i)) {
            }
        } else if (i == 2) {
            obj2 = this.f7653u;
            C1.N(obj);
            objB = obj2;
            if (!(objB instanceof A6.i)) {
                K k9 = uVar.f7661g;
                C1763h c1763h2 = new C1763h(new C0421o((Uri) objB));
                k9.getClass();
                k9.g(null, c1763h2);
            }
        } else if (i == 3) {
            C1.N(obj);
            objA = ((A6.j) obj).f449q;
            if (A6.j.a(objA) != null) {
                uVar.getClass();
                try {
                    File file = new File(uVar.f7664k);
                    if (file.exists()) {
                        file.delete();
                    }
                } catch (Exception unused) {
                }
                C1763h c1763h3 = new C1763h(pVar);
                K k10 = uVar.f7661g;
                k10.getClass();
                k10.g(null, c1763h3);
                y5.n nVar2 = new y5.n(R.string.msg_unknown_error);
                this.f7653u = objA;
                this.f7654v = 4;
                if (uVar.g(nVar2, this) != aVar) {
                    obj3 = objA;
                    objA = obj3;
                }
                return aVar;
            }
            if (!(objA instanceof A6.i)) {
            }
        } else {
            if (i != 4) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            obj3 = this.f7653u;
            C1.N(obj);
            objA = obj3;
            if (!(objA instanceof A6.i)) {
                K k11 = uVar.f7661g;
                C1763h c1763h4 = new C1763h(new C0420n((File) objA));
                k11.getClass();
                k11.g(null, c1763h4);
            }
        }
        return A6.n.f457a;
    }
}
