package o;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.PowerManager;
import android.util.Log;
import com.google.android.gms.common.util.concurrent.NamedThreadFactory;
import com.google.firebase.messaging.FirebaseMessaging;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Zb0 implements Runnable {
    public final /* synthetic */ int l = 0;
    public final long m;
    public final Object n;

    /* renamed from: o, reason: collision with root package name */
    public final Object f437o;

    public Zb0(C2191pt0 c2191pt0, C1431ht0 c1431ht0, long j) {
        this.n = c1431ht0;
        this.m = j;
        Objects.requireNonNull(c2191pt0);
        this.f437o = c2191pt0;
    }

    public boolean a() {
        ConnectivityManager connectivityManager = (ConnectivityManager) ((FirebaseMessaging) this.f437o).b.getSystemService("connectivity");
        NetworkInfo activeNetworkInfo = connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null;
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    }

    public boolean b() throws IOException {
        try {
            if (((FirebaseMessaging) this.f437o).a() == null) {
                return false;
            }
            Log.isLoggable("FirebaseMessaging", 3);
            return true;
        } catch (IOException e) {
            String message = e.getMessage();
            if ("SERVICE_NOT_AVAILABLE".equals(message) || "INTERNAL_SERVER_ERROR".equals(message) || "InternalServerError".equals(message)) {
                e.getMessage();
                return false;
            }
            if (e.getMessage() == null) {
                return false;
            }
            throw e;
        } catch (SecurityException unused) {
            return false;
        }
    }

    @Override // java.lang.Runnable
    public final void run() {
        switch (this.l) {
            case 0:
                PowerManager.WakeLock wakeLock = (PowerManager.WakeLock) this.n;
                S60 s60H = S60.h();
                FirebaseMessaging firebaseMessaging = (FirebaseMessaging) this.f437o;
                if (s60H.n(firebaseMessaging.b)) {
                    wakeLock.acquire();
                }
                try {
                    try {
                        synchronized (firebaseMessaging) {
                            firebaseMessaging.j = true;
                        }
                        if (!firebaseMessaging.i.d()) {
                            synchronized (firebaseMessaging) {
                                firebaseMessaging.j = false;
                            }
                            if (!S60.h().n(firebaseMessaging.b)) {
                                return;
                            }
                        } else if (!S60.h().k(firebaseMessaging.b) || a()) {
                            if (b()) {
                                synchronized (firebaseMessaging) {
                                    firebaseMessaging.j = false;
                                }
                            } else {
                                firebaseMessaging.g(this.m);
                            }
                            if (!S60.h().n(firebaseMessaging.b)) {
                                return;
                            }
                        } else {
                            Yb0 yb0 = new Yb0();
                            yb0.a = this;
                            yb0.a();
                            if (!S60.h().n(firebaseMessaging.b)) {
                                return;
                            }
                        }
                    } catch (IOException e) {
                        e.getMessage();
                        synchronized (firebaseMessaging) {
                            firebaseMessaging.j = false;
                            if (!S60.h().n(firebaseMessaging.b)) {
                                return;
                            }
                        }
                    }
                    wakeLock.release();
                    return;
                } catch (Throwable th) {
                    if (S60.h().n(firebaseMessaging.b)) {
                        wakeLock.release();
                    }
                    throw th;
                }
            default:
                C2191pt0 c2191pt0 = (C2191pt0) this.f437o;
                c2191pt0.w((C1431ht0) this.n, false, this.m);
                c2191pt0.e = null;
                Vt0 vt0O = ((Kr0) c2191pt0.a).o();
                vt0O.r();
                vt0O.t();
                vt0O.G(new Js0(vt0O, (C1431ht0) null));
                return;
        }
    }

    public Zb0(FirebaseMessaging firebaseMessaging, long j) {
        new ThreadPoolExecutor(0, 1, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue(), new NamedThreadFactory("firebase-iid-executor"));
        this.f437o = firebaseMessaging;
        this.m = j;
        PowerManager.WakeLock wakeLockNewWakeLock = ((PowerManager) firebaseMessaging.b.getSystemService("power")).newWakeLock(1, "fiid-sync");
        this.n = wakeLockNewWakeLock;
        wakeLockNewWakeLock.setReferenceCounted(false);
    }
}
