package com.seewo.ota.util;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/* JADX INFO: compiled from: NetworkCenter.java */
/* JADX INFO: loaded from: classes.dex */
public class n {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static volatile n f2336d;
    private Context a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final BroadcastReceiver f2337b = new a();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final Map<String, b> f2338c = new HashMap();

    /* JADX INFO: compiled from: NetworkCenter.java */
    class a extends BroadcastReceiver {
        a() {
        }

        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
            if (activeNetworkInfo == null || !activeNetworkInfo.isAvailable()) {
                Log.d("NetworkCenter", "Network is not available, pause all check");
                Iterator it = n.this.f2338c.values().iterator();
                while (it.hasNext()) {
                    ((b) it.next()).f(false);
                }
                return;
            }
            Log.d("NetworkCenter", "Network is available, can load data");
            Iterator it2 = n.this.f2338c.values().iterator();
            while (it2.hasNext()) {
                ((b) it2.next()).f(true);
            }
        }
    }

    /* JADX INFO: compiled from: NetworkCenter.java */
    public interface b {
        void f(boolean z);
    }

    private n() {
    }

    public static n b() {
        if (f2336d == null) {
            synchronized (n.class) {
                if (f2336d == null) {
                    f2336d = new n();
                }
            }
        }
        return f2336d;
    }

    public void c(Context context) {
        Context applicationContext = context.getApplicationContext();
        this.a = applicationContext;
        applicationContext.registerReceiver(this.f2337b, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));
    }

    public boolean d() {
        NetworkInfo activeNetworkInfo = ((ConnectivityManager) this.a.getSystemService("connectivity")).getActiveNetworkInfo();
        return activeNetworkInfo != null && activeNetworkInfo.isAvailable();
    }

    public void e(String str, b bVar) {
        this.f2338c.put(str, bVar);
    }

    public void f(String str) {
        this.f2338c.remove(str);
    }
}
