package M4;

import android.util.Log;
import java.util.HashMap;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/* JADX INFO: loaded from: classes.dex */
public final class d {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final HashMap f4219d = new HashMap();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final K1.c f4220e = new K1.c(0);

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Executor f4221a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final p f4222b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public g3.o f4223c = null;

    public d(Executor executor, p pVar) {
        this.f4221a = executor;
        this.f4222b = pVar;
    }

    public static Object a(g3.o oVar) throws ExecutionException, TimeoutException {
        TimeUnit timeUnit = TimeUnit.SECONDS;
        c cVar = new c(0);
        Executor executor = f4220e;
        oVar.c(executor, cVar);
        oVar.b(executor, cVar);
        oVar.a(executor, cVar);
        if (!cVar.f4218r.await(5L, timeUnit)) {
            throw new TimeoutException("Task await timed out.");
        }
        if (oVar.i()) {
            return oVar.g();
        }
        throw new ExecutionException(oVar.f());
    }

    public static synchronized d d(Executor executor, p pVar) {
        String str;
        HashMap map;
        try {
            str = pVar.f4291b;
            map = f4219d;
            if (!map.containsKey(str)) {
                map.put(str, new d(executor, pVar));
            }
        } catch (Throwable th) {
            throw th;
        }
        return (d) map.get(str);
    }

    public final synchronized g3.o b() {
        try {
            g3.o oVar = this.f4223c;
            if (oVar == null || (oVar.h() && !this.f4223c.i())) {
                Executor executor = this.f4221a;
                p pVar = this.f4222b;
                Objects.requireNonNull(pVar);
                this.f4223c = W2.g.f(executor, new L4.i(1, pVar));
            }
        } catch (Throwable th) {
            throw th;
        }
        return this.f4223c;
    }

    public final f c() {
        synchronized (this) {
            try {
                g3.o oVar = this.f4223c;
                if (oVar != null && oVar.i()) {
                    return (f) this.f4223c.g();
                }
                try {
                    g3.o oVarB = b();
                    TimeUnit timeUnit = TimeUnit.SECONDS;
                    return (f) a(oVarB);
                } catch (InterruptedException | ExecutionException | TimeoutException e8) {
                    Log.d("FirebaseRemoteConfig", "Reading from storage file failed.", e8);
                    return null;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }
}
