package com.seewo.remote.g;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.DhcpInfo;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;
import com.seewo.remote.g.j;
import e.c.e.f.b;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.snmp4j.agent.mo.snmp.DisplayString;

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static k f278e;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private WifiManager f279c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private BroadcastReceiver f280d = new a();
    private List<b> a = new LinkedList();
    private l b = l.b();

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

        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            e.c.d.y.e.a("NetworkCenter", "receive action: " + action);
            if (!action.equals("android.net.ethernet.ETHERNET_STATE_CHANGE")) {
                if (action.equals(com.seewo.libsvendors.utils.b.a)) {
                    k.this.f(intent.getIntExtra(com.seewo.libsvendors.utils.b.f3c, com.seewo.libsvendors.utils.b.f5e));
                    return;
                } else {
                    if (action.equals("android.net.wifi.STATE_CHANGE")) {
                        k.this.g(((NetworkInfo) intent.getParcelableExtra("networkInfo")).getState());
                        return;
                    }
                    return;
                }
            }
            int intExtra = intent.getIntExtra("ethernet_state", 0);
            if (intExtra == 10 || intExtra == 14) {
                k.this.f(com.seewo.libsvendors.utils.b.f8h);
            } else if (intExtra == 12 || intExtra == 16) {
                k.this.f(com.seewo.libsvendors.utils.b.f9i);
            }
        }
    }

    /* JADX INFO: compiled from: NetworkCenter.java */
    public interface b {
        void a();

        void stop();
    }

    private k() {
    }

    private String c() {
        int ipAddress = this.f279c.getConnectionInfo().getIpAddress();
        StringBuilder sb = new StringBuilder();
        sb.append(String.valueOf(ipAddress & DisplayString.MAX_SIZE));
        sb.append('.');
        int i2 = ipAddress >>> 8;
        sb.append(i2 & DisplayString.MAX_SIZE);
        sb.append('.');
        int i3 = i2 >>> 8;
        sb.append(i3 & DisplayString.MAX_SIZE);
        sb.append('.');
        sb.append((i3 >>> 8) & DisplayString.MAX_SIZE);
        return sb.toString();
    }

    public static k d() {
        if (f278e == null) {
            f278e = new k();
        }
        return f278e;
    }

    private String e(WifiInfo wifiInfo) {
        if (Build.VERSION.SDK_INT <= 19) {
            return f.b(wifiInfo.getIpAddress());
        }
        String str = SystemProperties.get("dhcp.wlan0.ipaddress");
        return TextUtils.isEmpty(str) ? c() : str;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void f(int i2) {
        e.c.d.y.e.a("NetworkCenter", "Ethernet state changed, state = " + i2);
        if (i2 == com.seewo.libsvendors.utils.b.f8h) {
            h();
            k();
        } else if (i2 == com.seewo.libsvendors.utils.b.f9i) {
            l();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void g(NetworkInfo.State state) {
        e.c.d.y.e.a("NetworkCenter", "handleWifiStateChanged: " + state);
        if (state == NetworkInfo.State.CONNECTED) {
            h();
            k();
        } else if (state == NetworkInfo.State.DISCONNECTED) {
            l();
        }
    }

    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    public void h() {
        j.a aVarF;
        boolean z = false;
        if (!i.a.i()) {
            WifiInfo connectionInfo = this.f279c.getConnectionInfo();
            DhcpInfo dhcpInfo = this.f279c.getDhcpInfo();
            if (connectionInfo != null && dhcpInfo != null && this.f279c.isWifiEnabled()) {
                z = true;
            }
            if (z) {
                this.b.l((byte) 1);
                this.b.j(f.a(e(connectionInfo)));
                this.b.m(f.c(connectionInfo.getMacAddress()));
                String strG = Build.VERSION.SDK_INT >= 33 ? i.a.g() : f.b(dhcpInfo.netmask);
                Log.d("NetworkCenter", "getWifiSubNetmask: " + strG);
                this.b.q(f.a(strG));
                this.b.i(f.a(f.b(dhcpInfo.gateway)));
                this.b.o(f.a(f.b(dhcpInfo.dns1)));
                this.b.p(f.a(f.b(dhcpInfo.dns2)));
                this.b.k(e(connectionInfo));
                this.b.n(connectionInfo.getMacAddress());
                e.c.d.y.e.a("NetworkCenter", "Wifi local ip: " + e(connectionInfo) + " mac:" + connectionInfo.getMacAddress());
                return;
            }
            return;
        }
        if (e.c.e.f.b.a() == b.a.MT8195) {
            aVarF = j.f();
            aVarF.g(i.a.h());
            Log.v("NetworkCenter", "GET IP 2");
        } else {
            try {
                e.c.c.b.b bVarB = e.c.c.c.e.a.c.a(com.seewo.remote.d.b.b().a()).b();
                boolean zEquals = "dhcp".equals(bVarB.h());
                j.a aVar = new j.a();
                aVar.g(zEquals);
                aVar.j(bVarB.e());
                aVar.h(bVarB.b());
                aVar.i(bVarB.f());
                aVar.l(bVarB.c());
                aVar.k(bVarB.d());
                Log.v("NetworkCenter", "GET IP 1");
                aVarF = aVar;
            } catch (Exception e2) {
                Log.v("NetworkCenter", "GET IP ERROR: " + e2.getMessage(), e2);
                aVarF = j.f();
                aVarF.g(false);
            }
        }
        this.b.l(aVarF.f() ? (byte) 1 : (byte) 0);
        this.b.j(f.a(aVarF.c()));
        this.b.m(f.c(e.c.d.k.a.e()));
        this.b.q(f.a(aVarF.d()));
        this.b.i(f.a(aVarF.e()));
        this.b.o(f.a(aVarF.a()));
        this.b.p(f.a(aVarF.b()));
        this.b.k(aVarF.c());
        this.b.n(e.c.d.k.a.e());
        e.c.d.y.e.a("NetworkCenter", "ipMsg:" + aVarF);
        e.c.d.y.e.a("NetworkCenter", "Eth local ip: " + aVarF.c() + " mac:" + e.c.d.k.a.e());
    }

    public void i(Context context) {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(com.seewo.libsvendors.utils.b.a);
        intentFilter.addAction("android.net.ethernet.ETHERNET_STATE_CHANGE");
        intentFilter.addAction("android.net.wifi.STATE_CHANGE");
        com.seewo.hiddenapi.b.b(context, this.f280d, com.seewo.hiddenapi.c.b, intentFilter, null, null);
    }

    public void j(Context context) {
        this.f279c = (WifiManager) context.getApplicationContext().getSystemService("wifi");
        h();
    }

    public void k() {
        Iterator<b> it = this.a.iterator();
        while (it.hasNext()) {
            it.next().a();
        }
    }

    public void l() {
        Iterator<b> it = this.a.iterator();
        while (it.hasNext()) {
            it.next().stop();
        }
    }

    public void m(Context context) {
        context.unregisterReceiver(this.f280d);
    }
}
