package com.google.android.gms.common.api.internal;

import android.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.provider.DocumentsContract;
import android.widget.ImageView;
import android.widget.ProgressBar;
import com.google.android.gms.common.api.GoogleApiActivity;
import com.google.android.gms.internal.atv_ads_framework.d1;
import com.google.android.gms.internal.atv_ads_framework.z1;
import com.google.android.gms.tasks.RuntimeExecutionException;
import java.util.ArrayList;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import kotlin.coroutines.EmptyCoroutineContext;
import pl.droidsonroids.gif.GifInfoHandle;
import pl.droidsonroids.gif.GifTextureView;

/* JADX INFO: loaded from: classes2.dex */
public final class v0 implements Runnable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f8294a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Object f8296c;

    public /* synthetic */ v0(Object obj, Object obj2, int i10) {
        this.f8294a = i10;
        this.f8296c = obj;
        this.f8295b = obj2;
    }

    @Override // java.lang.Runnable
    public final void run() {
        Throwable thA;
        Uri uri;
        com.mr.flutter.plugin.filepicker.a aVarE;
        int i10;
        int i11;
        int i12 = 0;
        switch (this.f8294a) {
            case 0:
                if (((w0) this.f8296c).f8299b) {
                    e8.b bVar = ((t0) this.f8295b).f8291b;
                    if (bVar.w()) {
                        w0 w0Var = (w0) this.f8296c;
                        i iVar = w0Var.f8251a;
                        Activity activityA = w0Var.a();
                        PendingIntent pendingIntent = (PendingIntent) com.google.android.gms.common.internal.w.checkNotNull(bVar.getResolution());
                        int i13 = ((t0) this.f8295b).f8290a;
                        int i14 = GoogleApiActivity.f8185b;
                        Intent intent = new Intent(activityA, (Class<?>) GoogleApiActivity.class);
                        intent.putExtra("pending_intent", pendingIntent);
                        intent.putExtra("failing_client_id", i13);
                        intent.putExtra("notify_manager", false);
                        iVar.startActivityForResult(intent, 1);
                        return;
                    }
                    w0 w0Var2 = (w0) this.f8296c;
                    if (w0Var2.f8302e.getErrorResolutionIntent(w0Var2.a(), bVar.f25514b, null) != null) {
                        w0 w0Var3 = (w0) this.f8296c;
                        w0Var3.f8302e.zag(w0Var3.a(), w0Var3.f8251a, bVar.f25514b, 2, (w0) this.f8296c);
                        return;
                    }
                    if (bVar.f25514b != 18) {
                        ((w0) this.f8296c).b(bVar, ((t0) this.f8295b).f8290a);
                        return;
                    }
                    w0 w0Var4 = (w0) this.f8296c;
                    e8.d dVar = w0Var4.f8302e;
                    Activity activityA2 = w0Var4.a();
                    dVar.getClass();
                    ProgressBar progressBar = new ProgressBar(activityA2, null, R.attr.progressBarStyleLarge);
                    progressBar.setIndeterminate(true);
                    progressBar.setVisibility(0);
                    AlertDialog.Builder builder = new AlertDialog.Builder(activityA2);
                    builder.setView(progressBar);
                    builder.setMessage(com.google.android.gms.common.internal.e0.b(activityA2, 18));
                    builder.setPositiveButton("", (DialogInterface.OnClickListener) null);
                    AlertDialog alertDialogCreate = builder.create();
                    dVar.zad(activityA2, alertDialogCreate, "GooglePlayServicesUpdatingDialog", w0Var4);
                    w0 w0Var5 = (w0) this.f8296c;
                    w0Var5.f8302e.zac(w0Var5.a().getApplicationContext(), new u0(this, alertDialogCreate));
                    return;
                }
                return;
            case 1:
                ((com.google.android.gms.internal.appset.a) this.f8295b).c((w8.i) this.f8296c);
                return;
            case 2:
                if (((w8.t) ((w8.h) this.f8295b)).f34253d) {
                    ((w8.o) this.f8296c).f34242d.l();
                    return;
                }
                try {
                    ((w8.o) this.f8296c).f34242d.zzb(((w8.o) this.f8296c).f34241c.then((w8.h) this.f8295b));
                    return;
                } catch (RuntimeExecutionException e10) {
                    if (e10.getCause() instanceof Exception) {
                        ((w8.o) this.f8296c).f34242d.k((Exception) e10.getCause());
                        return;
                    } else {
                        ((w8.o) this.f8296c).f34242d.k(e10);
                        return;
                    }
                } catch (Exception e11) {
                    ((w8.o) this.f8296c).f34242d.k(e11);
                    return;
                }
            case 3:
                Object obj = this.f8296c;
                try {
                    w8.h hVar = (w8.h) ((w8.o) obj).f34241c.then((w8.h) this.f8295b);
                    if (hVar == null) {
                        ((w8.o) obj).onFailure(new NullPointerException("Continuation returned null"));
                        return;
                    }
                    w8.o oVar = (w8.o) obj;
                    e.v vVar = w8.j.f34226b;
                    hVar.d(vVar, oVar);
                    hVar.c(vVar, oVar);
                    w8.t tVar = (w8.t) hVar;
                    tVar.f34251b.f(new w8.q(vVar, (w8.c) oVar));
                    tVar.m();
                    return;
                } catch (RuntimeExecutionException e12) {
                    if (e12.getCause() instanceof Exception) {
                        ((w8.o) obj).f34242d.k((Exception) e12.getCause());
                        return;
                    } else {
                        ((w8.o) obj).f34242d.k(e12);
                        return;
                    }
                } catch (Exception e13) {
                    ((w8.o) obj).f34242d.k(e13);
                    return;
                }
            case 4:
                synchronized (((w8.q) this.f8296c).f34247c) {
                    try {
                        Object obj2 = ((w8.q) this.f8296c).f34248d;
                        if (((w8.d) obj2) != null) {
                            ((w8.d) obj2).onComplete((w8.h) this.f8295b);
                        }
                    } finally {
                    }
                    break;
                }
                return;
            case 5:
                synchronized (((w8.q) this.f8296c).f34247c) {
                    try {
                        Object obj3 = ((w8.q) this.f8296c).f34248d;
                        if (((w8.e) obj3) != null) {
                            ((w8.e) obj3).onFailure((Exception) com.google.android.gms.common.internal.w.checkNotNull(((w8.h) this.f8295b).getException()));
                        }
                    } finally {
                    }
                    break;
                }
                return;
            case 6:
                synchronized (((w8.q) this.f8296c).f34247c) {
                    try {
                        Object obj4 = ((w8.q) this.f8296c).f34248d;
                        if (((w8.f) obj4) != null) {
                            ((w8.f) obj4).onSuccess(((w8.h) this.f8295b).g());
                        }
                    } finally {
                    }
                    break;
                }
                return;
            case 7:
                Object obj5 = this.f8296c;
                try {
                    w8.t tVarA = ((w8.g) ((w8.q) obj5).f34247c).a(((w8.h) this.f8295b).g());
                    if (tVarA == null) {
                        ((w8.q) obj5).onFailure(new NullPointerException("Continuation returned null"));
                        return;
                    }
                    w8.q qVar = (w8.q) obj5;
                    e.v vVar2 = w8.j.f34226b;
                    tVarA.d(vVar2, qVar);
                    tVarA.c(vVar2, qVar);
                    tVarA.f34251b.f(new w8.q(vVar2, (w8.c) qVar));
                    tVarA.m();
                    return;
                } catch (RuntimeExecutionException e14) {
                    if (e14.getCause() instanceof Exception) {
                        ((w8.q) obj5).onFailure((Exception) e14.getCause());
                        return;
                    } else {
                        ((w8.q) obj5).onFailure(e14);
                        return;
                    }
                } catch (CancellationException unused) {
                    ((w8.q) obj5).a();
                    return;
                } catch (Exception e15) {
                    ((w8.q) obj5).onFailure(e15);
                    return;
                }
            case 8:
                try {
                    ((w8.t) this.f8295b).zzb(((Callable) this.f8296c).call());
                    return;
                } catch (Exception e16) {
                    ((w8.t) this.f8295b).k(e16);
                    return;
                } catch (Throwable th) {
                    ((w8.t) this.f8295b).k(new RuntimeException(th));
                    return;
                }
            case 9:
                w8.i iVar2 = (w8.i) this.f8295b;
                Context context = (Context) this.f8296c;
                try {
                    iVar2.setResult(com.bumptech.glide.g.M(context));
                    return;
                } catch (RuntimeException e17) {
                    d1 d1VarS = d1.s(context);
                    z1 z1VarM = com.google.android.gms.internal.atv_ads_framework.a.m();
                    z1VarM.c();
                    com.google.android.gms.internal.atv_ads_framework.a.n((com.google.android.gms.internal.atv_ads_framework.a) z1VarM.f20005b);
                    com.google.android.gms.internal.atv_ads_framework.a aVar = (com.google.android.gms.internal.atv_ads_framework.a) z1VarM.a();
                    com.google.android.gms.internal.atv_ads_framework.b bVarK = com.bumptech.glide.g.K((Context) d1VarS.f19915c);
                    bVarK.c();
                    com.google.android.gms.internal.atv_ads_framework.c.o((com.google.android.gms.internal.atv_ads_framework.c) bVarK.f20005b, aVar);
                    d1VarS.v((com.google.android.gms.internal.atv_ads_framework.c) bVarK.a());
                    iVar2.a(e17);
                    return;
                }
            case 10:
                Object obj6 = (Future) this.f8295b;
                boolean z10 = obj6 instanceof ca.a;
                Object obj7 = this.f8296c;
                if (z10 && (thA = ((ca.a) obj6).a()) != null) {
                    ((com.google.common.util.concurrent.t) obj7).onFailure(thA);
                    return;
                }
                try {
                    ((com.google.common.util.concurrent.t) obj7).onSuccess(com.google.common.util.concurrent.c0.j((Future) this.f8295b));
                    return;
                } catch (ExecutionException e18) {
                    ((com.google.common.util.concurrent.t) obj7).onFailure(e18.getCause());
                    return;
                } catch (Throwable th2) {
                    ((com.google.common.util.concurrent.t) obj7).onFailure(th2);
                    return;
                }
            case 11:
                Intent intent2 = (Intent) this.f8295b;
                Object obj8 = this.f8296c;
                if (intent2 == null) {
                    int i15 = com.mr.flutter.plugin.filepicker.c.f24629k;
                    ((com.mr.flutter.plugin.filepicker.c) obj8).b("unknown_activity", "Unknown activity error, please fill an issue.");
                    return;
                }
                ArrayList arrayList = new ArrayList();
                if (((Intent) this.f8295b).getClipData() != null) {
                    int itemCount = ((Intent) this.f8295b).getClipData().getItemCount();
                    while (i12 < itemCount) {
                        Uri uri2 = ((Intent) this.f8295b).getClipData().getItemAt(i12).getUri();
                        com.mr.flutter.plugin.filepicker.c cVar = (com.mr.flutter.plugin.filepicker.c) obj8;
                        if (Objects.equals(cVar.f24635e, "image/*") && cVar.f24636f && (i11 = cVar.f24637g) > 0) {
                            uri2 = com.mr.flutter.plugin.filepicker.d.a(uri2, i11, cVar.f24631a.getApplicationContext());
                        }
                        com.mr.flutter.plugin.filepicker.a aVarE2 = com.mr.flutter.plugin.filepicker.d.e(cVar.f24631a, uri2, cVar.f24634d);
                        if (aVarE2 != null) {
                            arrayList.add(aVarE2);
                            uri2.getPath();
                        }
                        i12++;
                    }
                    int i16 = com.mr.flutter.plugin.filepicker.c.f24629k;
                    ((com.mr.flutter.plugin.filepicker.c) obj8).c(arrayList);
                    return;
                }
                if (((Intent) this.f8295b).getData() == null) {
                    if (((Intent) this.f8295b).getExtras() == null) {
                        int i17 = com.mr.flutter.plugin.filepicker.c.f24629k;
                        ((com.mr.flutter.plugin.filepicker.c) obj8).b("unknown_activity", "Unknown activity error, please fill an issue.");
                        return;
                    }
                    Bundle extras = ((Intent) this.f8295b).getExtras();
                    if (!extras.keySet().contains("selectedItems")) {
                        int i18 = com.mr.flutter.plugin.filepicker.c.f24629k;
                        ((com.mr.flutter.plugin.filepicker.c) obj8).b("unknown_path", "Failed to retrieve path from bundle.");
                        return;
                    }
                    com.mr.flutter.plugin.filepicker.c cVar2 = (com.mr.flutter.plugin.filepicker.c) obj8;
                    int i19 = com.mr.flutter.plugin.filepicker.c.f24629k;
                    cVar2.getClass();
                    ArrayList<Parcelable> parcelableArrayList = Build.VERSION.SDK_INT >= 33 ? extras.getParcelableArrayList("selectedItems", Parcelable.class) : extras.getParcelableArrayList("selectedItems");
                    if (parcelableArrayList != null) {
                        for (Parcelable parcelable : parcelableArrayList) {
                            if ((parcelable instanceof Uri) && (aVarE = com.mr.flutter.plugin.filepicker.d.e(cVar2.f24631a, (uri = (Uri) parcelable), cVar2.f24634d)) != null) {
                                arrayList.add(aVarE);
                                uri.getPath();
                            }
                        }
                    }
                    cVar2.c(arrayList);
                    return;
                }
                Uri data = ((Intent) this.f8295b).getData();
                com.mr.flutter.plugin.filepicker.c cVar3 = (com.mr.flutter.plugin.filepicker.c) obj8;
                if (Objects.equals(cVar3.f24635e, "image/*") && cVar3.f24636f && (i10 = cVar3.f24637g) > 0) {
                    data = com.mr.flutter.plugin.filepicker.d.a(data, i10, cVar3.f24631a.getApplicationContext());
                }
                if (cVar3.f24635e.equals("dir")) {
                    Uri uriBuildDocumentUriUsingTree = DocumentsContract.buildDocumentUriUsingTree(data, DocumentsContract.getTreeDocumentId(data));
                    uriBuildDocumentUriUsingTree.toString();
                    String fullPathFromTreeUri = com.mr.flutter.plugin.filepicker.d.getFullPathFromTreeUri(uriBuildDocumentUriUsingTree, cVar3.f24631a);
                    if (fullPathFromTreeUri != null) {
                        cVar3.c(fullPathFromTreeUri);
                        return;
                    } else {
                        cVar3.b("unknown_path", "Failed to retrieve directory path.");
                        return;
                    }
                }
                com.mr.flutter.plugin.filepicker.a aVarE3 = com.mr.flutter.plugin.filepicker.d.e(cVar3.f24631a, data, cVar3.f24634d);
                if (aVarE3 != null) {
                    arrayList.add(aVarE3);
                }
                if (arrayList.isEmpty()) {
                    cVar3.b("unknown_path", "Failed to retrieve path.");
                    return;
                } else {
                    arrayList.toString();
                    cVar3.c(arrayList);
                    return;
                }
            case 12:
                ((lc.a) this.f8296c).f30206b.success(this.f8295b);
                return;
            case 13:
                ((kotlinx.coroutines.g) this.f8296c).f((kotlinx.coroutines.t) this.f8295b);
                return;
            case 14:
                ((kotlinx.coroutines.g) this.f8295b).f((ae.d) this.f8296c);
                return;
            case 15:
                break;
            case 16:
                fe.i iVarM = ((d1) this.f8295b).m();
                if (iVarM == null) {
                    throw new IllegalStateException("No pending post available");
                }
                ((fe.d) this.f8296c).c(iVarM);
                return;
            default:
                GifTextureView gifTextureView = (GifTextureView) this.f8295b;
                GifInfoHandle gifInfoHandle = ((pl.droidsonroids.gif.h) this.f8296c).f32039b;
                ImageView.ScaleType[] scaleTypeArr = GifTextureView.f32013g;
                gifTextureView.c(gifInfoHandle);
                return;
        }
        while (true) {
            try {
                ((Runnable) this.f8295b).run();
            } catch (Throwable th3) {
                hb.a.g0(EmptyCoroutineContext.f29221a, th3);
            }
            kotlinx.coroutines.internal.h hVar2 = (kotlinx.coroutines.internal.h) this.f8296c;
            AtomicIntegerFieldUpdater atomicIntegerFieldUpdater = kotlinx.coroutines.internal.h.f29465h;
            Runnable runnableO = hVar2.O();
            if (runnableO == null) {
                return;
            }
            this.f8295b = runnableO;
            i12++;
            if (i12 >= 16 && hVar2.f29466c.M(hVar2)) {
                hVar2.f29466c.L(hVar2, this);
                return;
            }
        }
    }

    public final String toString() {
        switch (this.f8294a) {
            case 10:
                int i10 = 0;
                p7.i0 i0Var = new p7.i0(v0.class.getSimpleName(), i10);
                com.google.common.util.concurrent.t tVar = (com.google.common.util.concurrent.t) this.f8296c;
                xyz.stream.utils.t tVar2 = new xyz.stream.utils.t(18, i10);
                ((xyz.stream.utils.t) i0Var.f31699f).f36174d = tVar2;
                i0Var.f31699f = tVar2;
                tVar2.f36173c = tVar;
                return i0Var.toString();
            default:
                return super.toString();
        }
    }

    public /* synthetic */ v0(Object obj, Object obj2, int i10, int i11) {
        this.f8294a = i10;
        this.f8295b = obj;
        this.f8296c = obj2;
    }

    public v0(fe.d dVar) {
        this.f8294a = 16;
        this.f8296c = dVar;
        this.f8295b = new d1(20);
    }
}
