package o;

import android.content.Context;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.PowerManager;
import android.util.Log;
import java.io.IOException;
import java.util.Objects;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.fg0, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class RunnableC1213fg0 implements Runnable {
    public static final Object r = new Object();
    public static Boolean s;
    public static Boolean t;
    public final /* synthetic */ int l;
    public final long m;
    public final Object n;

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

    public /* synthetic */ RunnableC1213fg0(Object obj, String str, String str2, Object obj2, long j, int i) {
        this.l = i;
        this.n = str;
        this.f528o = str2;
        this.p = obj2;
        this.m = j;
        this.q = obj;
    }

    public static boolean a(Context context) {
        boolean zBooleanValue;
        synchronized (r) {
            try {
                Boolean bool = t;
                if (bool == null && bool == null) {
                    zBooleanValue = context.checkCallingOrSelfPermission("android.permission.ACCESS_NETWORK_STATE") == 0;
                    if (!zBooleanValue) {
                        Log.isLoggable("FirebaseMessaging", 3);
                    }
                } else {
                    zBooleanValue = bool.booleanValue();
                }
                t = Boolean.valueOf(zBooleanValue);
            } catch (Throwable th) {
                throw th;
            }
        }
        return zBooleanValue;
    }

    public static boolean b(Context context) {
        boolean zBooleanValue;
        synchronized (r) {
            try {
                Boolean bool = s;
                if (bool == null && bool == null) {
                    zBooleanValue = context.checkCallingOrSelfPermission("android.permission.WAKE_LOCK") == 0;
                    if (!zBooleanValue) {
                        Log.isLoggable("FirebaseMessaging", 3);
                    }
                } else {
                    zBooleanValue = bool.booleanValue();
                }
                s = Boolean.valueOf(zBooleanValue);
            } catch (Throwable th) {
                throw th;
            }
        }
        return zBooleanValue;
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0021  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public synchronized boolean c() {
        /*
            r2 = this;
            monitor-enter(r2)
            java.lang.Object r0 = r2.n     // Catch: java.lang.Throwable -> L14
            android.content.Context r0 = (android.content.Context) r0     // Catch: java.lang.Throwable -> L14
            java.lang.String r1 = "connectivity"
            java.lang.Object r0 = r0.getSystemService(r1)     // Catch: java.lang.Throwable -> L14
            android.net.ConnectivityManager r0 = (android.net.ConnectivityManager) r0     // Catch: java.lang.Throwable -> L14
            if (r0 == 0) goto L16
            android.net.NetworkInfo r0 = r0.getActiveNetworkInfo()     // Catch: java.lang.Throwable -> L14
            goto L17
        L14:
            r0 = move-exception
            goto L24
        L16:
            r0 = 0
        L17:
            if (r0 == 0) goto L21
            boolean r0 = r0.isConnected()     // Catch: java.lang.Throwable -> L14
            if (r0 == 0) goto L21
            r0 = 1
            goto L22
        L21:
            r0 = 0
        L22:
            monitor-exit(r2)
            return r0
        L24:
            monitor-exit(r2)     // Catch: java.lang.Throwable -> L14
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: o.RunnableC1213fg0.c():boolean");
    }

    @Override // java.lang.Runnable
    public final void run() {
        switch (this.l) {
            case 0:
                C1022dg0 c1022dg0 = (C1022dg0) this.q;
                PowerManager.WakeLock wakeLock = (PowerManager.WakeLock) this.p;
                Context context = (Context) this.n;
                if (b(context)) {
                    wakeLock.acquire(AbstractC2933xl.a);
                }
                try {
                    try {
                        c1022dg0.d(true);
                        if (!((C2805wP) this.f528o).d()) {
                            c1022dg0.d(false);
                            if (!b(context)) {
                                return;
                            }
                        } else if (!a(context) || c()) {
                            if (c1022dg0.e()) {
                                c1022dg0.d(false);
                            } else {
                                c1022dg0.f(this.m);
                            }
                            if (!b(context)) {
                                return;
                            }
                        } else {
                            C1117eg0 c1117eg0 = new C1117eg0();
                            c1117eg0.a = this;
                            Log.isLoggable("FirebaseMessaging", 3);
                            context.registerReceiver(c1117eg0, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
                            if (!b(context)) {
                                return;
                            }
                        }
                    } catch (Throwable th) {
                        if (b(context)) {
                            try {
                                wakeLock.release();
                            } catch (RuntimeException unused) {
                            }
                        }
                        throw th;
                    }
                } catch (IOException e) {
                    e.getMessage();
                    c1022dg0.d(false);
                    if (!b(context)) {
                        return;
                    }
                }
                try {
                    wakeLock.release();
                    return;
                } catch (RuntimeException unused2) {
                    return;
                }
            case 1:
                String str = (String) this.f528o;
                BinderC1237fs0 binderC1237fs0 = (BinderC1237fs0) this.q;
                String str2 = (String) this.n;
                if (str2 == null) {
                    C1051dv0 c1051dv0 = binderC1237fs0.d;
                    c1051dv0.c().r();
                    String str3 = c1051dv0.G;
                    if (str3 == null || str3.equals(str)) {
                        c1051dv0.G = str;
                        c1051dv0.F = null;
                        return;
                    }
                    return;
                }
                C1431ht0 c1431ht0 = new C1431ht0((String) this.p, str2, this.m);
                C1051dv0 c1051dv02 = binderC1237fs0.d;
                c1051dv02.c().r();
                String str4 = c1051dv02.G;
                if (str4 != null) {
                    str4.equals(str);
                }
                c1051dv02.G = str;
                c1051dv02.F = c1431ht0;
                return;
            case 2:
                Xs0 xs0 = (Xs0) this.q;
                String str5 = (String) this.n;
                String str6 = (String) this.f528o;
                xs0.D(this.m, this.p, str5, str6);
                return;
            default:
                C2191pt0 c2191pt0 = (C2191pt0) this.q;
                Bundle bundle = (Bundle) this.n;
                C1431ht0 c1431ht02 = (C1431ht0) this.f528o;
                C1431ht0 c1431ht03 = (C1431ht0) this.p;
                c2191pt0.getClass();
                bundle.remove("screen_name");
                bundle.remove("screen_class");
                C2574tv0 c2574tv0 = ((Kr0) c2191pt0.a).i;
                Kr0.j(c2574tv0);
                c2191pt0.C(c1431ht02, c1431ht03, this.m, true, c2574tv0.A("screen_view", bundle, null, false));
                return;
        }
    }

    public RunnableC1213fg0(C2191pt0 c2191pt0, Bundle bundle, C1431ht0 c1431ht0, C1431ht0 c1431ht02, long j) {
        this.l = 3;
        this.n = bundle;
        this.f528o = c1431ht0;
        this.p = c1431ht02;
        this.m = j;
        Objects.requireNonNull(c2191pt0);
        this.q = c2191pt0;
    }

    public RunnableC1213fg0(C1022dg0 c1022dg0, Context context, C2805wP c2805wP, long j) {
        this.l = 0;
        this.q = c1022dg0;
        this.n = context;
        this.m = j;
        this.f528o = c2805wP;
        this.p = ((PowerManager) context.getSystemService("power")).newWakeLock(1, "wake:com.google.firebase.messaging");
    }
}
