package com.google.android.gms.internal.measurement;

import android.content.Context;
import android.os.Binder;
import android.os.Parcel;
import android.os.Process;
import android.os.UserManager;
import android.util.Log;
import h0.ComponentCallbacksC1023x;
import java.util.ArrayDeque;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static B1 f9557d;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public boolean f9558a;

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

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

    public B1(int i) {
        switch (i) {
            case 5:
                this.f9559b = new Object();
                break;
            default:
                this.f9558a = false;
                this.f9559b = null;
                this.f9560c = null;
                break;
        }
    }

    public static B1 i(Context context) {
        B1 b12;
        B1 b13;
        synchronized (B1.class) {
            try {
                if (f9557d == null) {
                    if (s7.l.d(context, "com.google.android.providers.gsf.permission.READ_GSERVICES") == 0) {
                        b13 = new B1();
                        b13.f9558a = false;
                        b13.f9559b = context;
                        b13.f9560c = new A1(null);
                    } else {
                        b13 = new B1(0);
                    }
                    f9557d = b13;
                }
                B1 b14 = f9557d;
                if (b14 != null && ((A1) b14.f9560c) != null && !b14.f9558a) {
                    try {
                        context.getContentResolver().registerContentObserver(AbstractC0702t1.f9966a, true, (A1) f9557d.f9560c);
                        B1 b15 = f9557d;
                        b15.getClass();
                        b15.f9558a = true;
                    } catch (SecurityException e8) {
                        Log.e("GservicesLoader", "Unable to register Gservices content observer", e8);
                    }
                }
                b12 = f9557d;
                b12.getClass();
            } catch (Throwable th) {
                throw th;
            }
        }
        return b12;
    }

    public static synchronized void m() {
        Context context;
        try {
            B1 b12 = f9557d;
            if (b12 != null && (context = (Context) b12.f9559b) != null && ((A1) b12.f9560c) != null && b12.f9558a) {
                context.getContentResolver().unregisterContentObserver((A1) f9557d.f9560c);
            }
            f9557d = null;
        } catch (Throwable th) {
            throw th;
        }
    }

    public void a(N2.a aVar, g3.h hVar) {
        P.g gVar = (P.g) ((K4.c) this.f9560c).f3604r;
        gVar.getClass();
        R2.a aVar2 = (R2.a) ((R2.d) aVar).u();
        Parcel parcelObtain = Parcel.obtain();
        parcelObtain.writeInterfaceToken(aVar2.f6046f);
        int i = Y2.b.f7310a;
        P2.m mVar = (P2.m) gVar.f5246r;
        if (mVar == null) {
            parcelObtain.writeInt(0);
        } else {
            parcelObtain.writeInt(1);
            mVar.writeToParcel(parcelObtain, 0);
        }
        try {
            aVar2.f6045e.transact(1, parcelObtain, null, 1);
            parcelObtain.recycle();
            hVar.f12923a.l(null);
        } catch (Throwable th) {
            parcelObtain.recycle();
            throw th;
        }
    }

    public boolean b() {
        return false;
    }

    public void j(g3.n nVar) {
        synchronized (this.f9559b) {
            try {
                if (((ArrayDeque) this.f9560c) == null) {
                    this.f9560c = new ArrayDeque();
                }
                ((ArrayDeque) this.f9560c).add(nVar);
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public void k(g3.o oVar) {
        g3.n nVar;
        synchronized (this.f9559b) {
            if (((ArrayDeque) this.f9560c) != null && !this.f9558a) {
                this.f9558a = true;
                while (true) {
                    synchronized (this.f9559b) {
                        try {
                            nVar = (g3.n) ((ArrayDeque) this.f9560c).poll();
                            if (nVar == null) {
                                this.f9558a = false;
                                return;
                            }
                        } finally {
                        }
                    }
                    nVar.a(oVar);
                }
            }
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:30:0x0047, code lost:
    
        r6 = true;
     */
    /* JADX WARN: Removed duplicated region for block: B:69:0x0065 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public String l(String str) {
        Object objB;
        int i;
        boolean z8;
        Context context = (Context) this.f9559b;
        if (context != null) {
            if (AbstractC0717w1.a()) {
                boolean z9 = true;
                if (!AbstractC0717w1.f10060b) {
                    synchronized (AbstractC0717w1.class) {
                        try {
                            if (!AbstractC0717w1.f10060b) {
                                i = 1;
                                while (true) {
                                    z8 = false;
                                    if (i <= 2) {
                                        if (AbstractC0717w1.f10059a == null) {
                                            AbstractC0717w1.f10059a = (UserManager) context.getSystemService(UserManager.class);
                                        }
                                        UserManager userManager = AbstractC0717w1.f10059a;
                                        if (userManager != null) {
                                            if (userManager.isUserUnlocked()) {
                                                break;
                                            }
                                            if (!userManager.isUserRunning(Process.myUserHandle())) {
                                                break;
                                            }
                                        } else {
                                            z8 = true;
                                            break;
                                        }
                                    } else {
                                        break;
                                    }
                                }
                                if (z8) {
                                    AbstractC0717w1.f10059a = null;
                                }
                                if (z8) {
                                    AbstractC0717w1.f10060b = true;
                                }
                                z9 = z8;
                            }
                        } catch (NullPointerException e8) {
                            Log.w("DirectBootUtils", "Failed to check if user is unlocked.", e8);
                            AbstractC0717w1.f10059a = null;
                            i++;
                        } finally {
                        }
                    }
                }
                if (z9) {
                    try {
                        try {
                            C0700t c0700t = new C0700t(this, str);
                            try {
                                objB = c0700t.b();
                            } catch (SecurityException unused) {
                                long jClearCallingIdentity = Binder.clearCallingIdentity();
                                try {
                                    objB = c0700t.b();
                                } finally {
                                    Binder.restoreCallingIdentity(jClearCallingIdentity);
                                }
                            }
                            return (String) objB;
                        } catch (SecurityException e9) {
                            e = e9;
                            Log.e("GservicesLoader", "Unable to read GServices for: ".concat(str), e);
                            return null;
                        }
                    } catch (IllegalStateException e10) {
                        e = e10;
                        Log.e("GservicesLoader", "Unable to read GServices for: ".concat(str), e);
                        return null;
                    } catch (NullPointerException e11) {
                        e = e11;
                        Log.e("GservicesLoader", "Unable to read GServices for: ".concat(str), e);
                        return null;
                    }
                }
            }
        }
        return null;
    }

    public B1(ComponentCallbacksC1023x componentCallbacksC1023x) {
        this.f9559b = componentCallbacksC1023x;
    }

    public void c() {
    }

    public void d() {
    }

    public void e() {
    }

    public void f(int i) {
    }

    public void g(boolean z8) {
    }

    public void h(boolean z8) {
    }
}
