package com.ifpdos.autotest.n0;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemProperties;
import android.util.Log;
import com.ifpdos.autotest.model.EthernetConfig;
import com.ifpdos.autotest.n0.l;
import com.seewo.sdk.model.SDKEthernetConfig;
import com.seewo.sdk.model.SDKEthernetConnectionMode;
import d.g0;
import d.n;
import d.n0.c.s;
import d.n0.c.t;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Locale;
import okhttp3.Request;
import okhttp3.Response;

/* JADX INFO: compiled from: UdiEthernetHandler.kt */
/* JADX INFO: loaded from: classes.dex */
@n
public final class l implements i {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final a f2258b = new a(null);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final d.i f2259c = d.k.b(b.f2260d);

    /* JADX INFO: compiled from: UdiEthernetHandler.kt */
    @n
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(d.n0.c.l lVar) {
            this();
        }
    }

    /* JADX INFO: compiled from: UdiEthernetHandler.kt */
    @n
    static final class b extends t implements d.n0.b.a<Handler> {

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public static final b f2260d = new b();

        b() {
            super(0);
        }

        @Override // d.n0.b.a
        /* JADX INFO: renamed from: c, reason: merged with bridge method [inline-methods] */
        public final Handler a() {
            return new Handler(Looper.getMainLooper());
        }
    }

    /* JADX INFO: compiled from: UdiEthernetHandler.kt */
    @n
    public static final class c extends com.ifpdos.autotest.okhttp.f<String> {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ SDKEthernetConfig f2261b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        final /* synthetic */ Context f2262c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        final /* synthetic */ l f2263d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        final /* synthetic */ EthernetConfig f2264e;

        /* JADX INFO: compiled from: UdiEthernetHandler.kt */
        @n
        static final class a extends t implements d.n0.b.a<g0> {

            /* JADX INFO: renamed from: d, reason: collision with root package name */
            final /* synthetic */ l f2265d;

            /* JADX INFO: renamed from: e, reason: collision with root package name */
            final /* synthetic */ EthernetConfig f2266e;

            /* JADX INFO: renamed from: f, reason: collision with root package name */
            final /* synthetic */ Context f2267f;

            /* JADX INFO: renamed from: g, reason: collision with root package name */
            final /* synthetic */ SDKEthernetConfig f2268g;

            /* JADX INFO: renamed from: com.ifpdos.autotest.n0.l$c$a$a, reason: collision with other inner class name */
            /* JADX INFO: compiled from: UdiEthernetHandler.kt */
            @n
            static final class C0078a extends t implements d.n0.b.a<g0> {

                /* JADX INFO: renamed from: d, reason: collision with root package name */
                final /* synthetic */ EthernetConfig f2269d;

                /* JADX INFO: renamed from: e, reason: collision with root package name */
                final /* synthetic */ l f2270e;

                /* JADX INFO: renamed from: f, reason: collision with root package name */
                final /* synthetic */ Context f2271f;

                /* JADX INFO: renamed from: g, reason: collision with root package name */
                final /* synthetic */ SDKEthernetConfig f2272g;

                /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
                C0078a(EthernetConfig ethernetConfig, l lVar, Context context, SDKEthernetConfig sDKEthernetConfig) {
                    super(0);
                    this.f2269d = ethernetConfig;
                    this.f2270e = lVar;
                    this.f2271f = context;
                    this.f2272g = sDKEthernetConfig;
                }

                /* JADX INFO: Access modifiers changed from: private */
                public static final void f(Context context, SDKEthernetConfig sDKEthernetConfig) {
                    s.e(context, "$context");
                    com.ifpdos.autotest.o0.d.d(context, "Set static: " + sDKEthernetConfig.ip + ",  " + com.seewo.vcommons.data.c.b(context));
                }

                @Override // d.n0.b.a
                public /* bridge */ /* synthetic */ g0 a() {
                    c();
                    return g0.f2578a;
                }

                public final void c() {
                    b.c.c.f.f1451a.e(true);
                    if (this.f2269d == null) {
                        Handler handlerD = this.f2270e.d();
                        final Context context = this.f2271f;
                        final SDKEthernetConfig sDKEthernetConfig = this.f2272g;
                        handlerD.post(new Runnable() { // from class: com.ifpdos.autotest.n0.g
                            @Override // java.lang.Runnable
                            public final void run() {
                                l.c.a.C0078a.f(context, sDKEthernetConfig);
                            }
                        });
                    }
                }
            }

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            a(l lVar, EthernetConfig ethernetConfig, Context context, SDKEthernetConfig sDKEthernetConfig) {
                super(0);
                this.f2265d = lVar;
                this.f2266e = ethernetConfig;
                this.f2267f = context;
                this.f2268g = sDKEthernetConfig;
            }

            @Override // d.n0.b.a
            public /* bridge */ /* synthetic */ g0 a() {
                c();
                return g0.f2578a;
            }

            public final void c() {
                b.c.c.f.f1451a.e(false);
                com.ifpdos.autotest.o0.f.b(this.f2265d.d(), 2000L, new C0078a(this.f2266e, this.f2265d, this.f2267f, this.f2268g));
            }
        }

        c(SDKEthernetConfig sDKEthernetConfig, Context context, l lVar, EthernetConfig ethernetConfig) {
            this.f2261b = sDKEthernetConfig;
            this.f2262c = context;
            this.f2263d = lVar;
            this.f2264e = ethernetConfig;
        }

        @Override // com.ifpdos.autotest.okhttp.f, com.ifpdos.autotest.okhttp.c
        public void d(Request request, Exception exc) {
            Log.e("UdiEthernetHandler", "setStaticIPByOpenSDK failed");
            if (this.f2264e == null) {
                com.ifpdos.autotest.o0.d.d(this.f2262c, "Set static failed");
            }
        }

        @Override // com.ifpdos.autotest.okhttp.f, com.ifpdos.autotest.okhttp.c
        /* JADX INFO: renamed from: j, reason: merged with bridge method [inline-methods] */
        public void f(Response response, String str) {
            Log.d("UdiEthernetHandler", "setStaticIPBUdi");
            Log.d("UdiEthernetHandler", "ip=" + this.f2261b.ip);
            Log.d("UdiEthernetHandler", "mask=" + this.f2261b.mask);
            Log.d("UdiEthernetHandler", "gateway=" + this.f2261b.gateway);
            Log.d("UdiEthernetHandler", "dns1=" + this.f2261b.dns1);
            Log.d("UdiEthernetHandler", "dns2=" + this.f2261b.dns2);
            try {
                SystemProperties.set("dhcp.eth0.gateway", this.f2261b.gateway);
                SystemProperties.set("dhcp.eth0.dns1", this.f2261b.dns1);
                SystemProperties.set("dhcp.eth0.dns2", this.f2261b.dns2);
                com.seewo.vcommons.data.c.h(this.f2262c, this.f2261b.gateway);
            } catch (Throwable unused) {
            }
            com.ifpdos.autotest.o0.f.b(this.f2263d.d(), 1000L, new a(this.f2263d, this.f2264e, this.f2262c, this.f2261b));
        }
    }

    /* JADX INFO: compiled from: UdiEthernetHandler.kt */
    @n
    static final class d extends t implements d.n0.b.a<g0> {

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public static final d f2273d = new d();

        d() {
            super(0);
        }

        @Override // d.n0.b.a
        public /* bridge */ /* synthetic */ g0 a() {
            c();
            return g0.f2578a;
        }

        public final void c() {
            b.c.c.f.f1451a.e(true);
        }
    }

    /* JADX INFO: compiled from: UdiEthernetHandler.kt */
    @n
    static final class e extends t implements d.n0.b.a<g0> {

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        final /* synthetic */ Context f2275e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        final /* synthetic */ EthernetConfig f2276f;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        e(Context context, EthernetConfig ethernetConfig) {
            super(0);
            this.f2275e = context;
            this.f2276f = ethernetConfig;
        }

        @Override // d.n0.b.a
        public /* bridge */ /* synthetic */ g0 a() {
            c();
            return g0.f2578a;
        }

        public final void c() {
            Log.i("UdiEthernetHandler", "eth1 network is not mount, setStaticIp later");
            l.this.a(this.f2275e, this.f2276f);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Handler d() {
        return (Handler) this.f2259c.getValue();
    }

    private final boolean e() throws SocketException {
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            String name = networkInterfaces.nextElement().getName();
            s.d(name, "networkInterface.name");
            String lowerCase = name.toLowerCase(Locale.ROOT);
            s.d(lowerCase, "this as java.lang.String).toLowerCase(Locale.ROOT)");
            if (s.a(lowerCase, "eth1")) {
                return true;
            }
        }
        Log.e("UdiEthernetHandler", "ethInterface is not mount");
        return false;
    }

    private final void f(Context context, EthernetConfig ethernetConfig) {
        String ip;
        String mask;
        String gateway;
        SDKEthernetConnectionMode sDKEthernetConnectionModeF = com.ifpdos.autotest.okhttp.e.f();
        SDKEthernetConfig sDKEthernetConfigG = com.ifpdos.autotest.okhttp.e.g();
        h hVar = h.f2250a;
        if (!hVar.a().getInit()) {
            EthernetConfig ethernetConfig2 = new EthernetConfig(null, null, null, null, null, false, 63, null);
            String str = sDKEthernetConfigG.ip;
            String str2 = "";
            if (str == null) {
                str = "";
            } else {
                s.d(str, "config.ip ?: \"\"");
            }
            ethernetConfig2.setIp(str);
            String str3 = sDKEthernetConfigG.mask;
            if (str3 == null) {
                str3 = "";
            } else {
                s.d(str3, "config.mask ?: \"\"");
            }
            ethernetConfig2.setMask(str3);
            String str4 = sDKEthernetConfigG.gateway;
            if (str4 != null) {
                s.d(str4, "config.gateway ?: \"\"");
                str2 = str4;
            }
            ethernetConfig2.setGateway(str2);
            if (sDKEthernetConnectionModeF == null) {
                sDKEthernetConnectionModeF = SDKEthernetConnectionMode.DHCP;
            }
            ethernetConfig2.setOpenSdkConnectMode(sDKEthernetConnectionModeF);
            hVar.b(ethernetConfig2);
        }
        if (ethernetConfig == null || (ip = ethernetConfig.getIp()) == null) {
            ip = "192.168.1.11";
        }
        sDKEthernetConfigG.ip = ip;
        if (ethernetConfig == null || (mask = ethernetConfig.getMask()) == null) {
            mask = "255.255.0.0";
        }
        sDKEthernetConfigG.mask = mask;
        if (ethernetConfig == null || (gateway = ethernetConfig.getGateway()) == null) {
            gateway = "192.168.1.1";
        }
        sDKEthernetConfigG.gateway = gateway;
        com.ifpdos.autotest.okhttp.e.s(sDKEthernetConfigG.ip, sDKEthernetConfigG.mask, gateway, new c(sDKEthernetConfigG, context, this, ethernetConfig));
    }

    private final void g() {
        com.ifpdos.autotest.okhttp.e.r(SDKEthernetConnectionMode.DHCP);
        b.c.c.f.f1451a.e(false);
        com.ifpdos.autotest.o0.f.b(d(), 2000L, d.f2273d);
    }

    @Override // com.ifpdos.autotest.n0.i
    public void a(Context context, EthernetConfig ethernetConfig) {
        s.e(context, "context");
        if (!com.ifpdos.autotest.o0.e.f2286a.g()) {
            Log.e("UdiEthernetHandler", "setStaticIp: not in wb running, skip set static ip.");
        } else if (e()) {
            f(context, ethernetConfig);
        } else {
            com.ifpdos.autotest.o0.f.b(d(), 500L, new e(context, ethernetConfig));
        }
    }

    @Override // com.ifpdos.autotest.n0.i
    public void b(Context context) {
        s.e(context, "context");
        h hVar = h.f2250a;
        if (hVar.a().getInit()) {
            if (hVar.a().getOpenSdkConnectMode() == SDKEthernetConnectionMode.DHCP) {
                g();
            } else {
                f(context, hVar.a());
            }
        }
    }
}
