package u2;

import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import d3.E;
import f2.C0920j;
import java.lang.ref.WeakReference;
import n2.C1269c;
import o2.InterfaceC1339e;

/* JADX INFO: loaded from: classes.dex */
public final class l implements ComponentCallbacks2 {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final WeakReference f17458q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public Context f17459r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public InterfaceC1339e f17460s;

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

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public boolean f17462u = true;

    public l(C0920j c0920j) {
        this.f17458q = new WeakReference(c0920j);
    }

    public final synchronized void a() {
        InterfaceC1339e e8;
        try {
            C0920j c0920j = (C0920j) this.f17458q.get();
            if (c0920j == null) {
                b();
            } else if (this.f17460s == null) {
                if (c0920j.f12698d.f17452b) {
                    Context context = c0920j.f12695a;
                    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(ConnectivityManager.class);
                    if (connectivityManager == null || s7.d.h(context, "android.permission.ACCESS_NETWORK_STATE") != 0) {
                        e8 = new E(11);
                    } else {
                        try {
                            e8 = new com.google.android.material.datepicker.c(connectivityManager, this);
                        } catch (Exception unused) {
                            e8 = new E(11);
                        }
                    }
                } else {
                    e8 = new E(11);
                }
                this.f17460s = e8;
                this.f17462u = e8.g();
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized void b() {
        try {
            if (this.f17461t) {
                return;
            }
            this.f17461t = true;
            Context context = this.f17459r;
            if (context != null) {
                context.unregisterComponentCallbacks(this);
            }
            InterfaceC1339e interfaceC1339e = this.f17460s;
            if (interfaceC1339e != null) {
                interfaceC1339e.shutdown();
            }
            this.f17458q.clear();
        } catch (Throwable th) {
            throw th;
        }
    }

    @Override // android.content.ComponentCallbacks
    public final synchronized void onConfigurationChanged(Configuration configuration) {
        if (((C0920j) this.f17458q.get()) == null) {
            b();
        }
    }

    @Override // android.content.ComponentCallbacks
    public final synchronized void onLowMemory() {
        onTrimMemory(80);
    }

    @Override // android.content.ComponentCallbacks2
    public final synchronized void onTrimMemory(int i) {
        C0920j c0920j = (C0920j) this.f17458q.get();
        if (c0920j != null) {
            C1269c c1269c = (C1269c) c0920j.f12697c.getValue();
            if (c1269c != null) {
                c1269c.f15128a.h(i);
                c1269c.f15129b.t(i);
            }
        } else {
            b();
        }
    }
}
