package com.ifpdos.udi.service.network;

import a.a.a.a.c.e1;
import a.a.a.a.c.r0;
import a.a.a.a.h.c0;
import a.a.a.a.h.e7.a;
import a.a.a.a.h.j3;
import a.a.a.a.h.m2;
import a.a.a.a.h.n2;
import a.a.a.a.h.y1;
import a.f.a.f;
import a.f.a.g;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.MacAddress;
import android.net.TetheringManager;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiManager;
import android.os.Build;
import androidx.annotation.Keep;
import com.cvte.vman.VmanMiddleWare;
import com.ifpdos.udi.service.network.HotspotHelper;
import com.seewo.libmcuservice.constant.IRemoteConstants;
import com.seewo.vcommons.constants.SeewoConstants;
import com.seewo.vcommons.executor.ButtonActionExecutor;
import com.seewo.vcommons.mstar.MKeyEvent;
import com.seewo.vcommons.system.onoffsetting.Task;
import com.seewo.vcommons.utils.LanguageUtils;
import d.a.j;
import d.a.s.e.c.b;
import d.a.u.a;
import e.s.c.i;
import e.s.c.q;
import e.w.h;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/* JADX INFO: loaded from: classes.dex */
public final class HotspotHelper implements j3, c0.a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final r0 f5527a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final r0 f5528b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final VmanMiddleWare f5530d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final ExecutorService f5531e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final c0 f5532f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final a f5533g;

    public static final class a extends BroadcastReceiver {
        public a() {
        }

        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            i.e(context, "context");
            i.e(intent, "intent");
            int intExtra = intent.getIntExtra("wifi_state", 0);
            if (intExtra == 11) {
                g gVar = f.f4591a;
                gVar.g("HotspotHelper");
                gVar.f(3, null, "wifi ap disabled", new Object[0]);
                HotspotHelper.c(HotspotHelper.this, false);
            }
            if (intExtra == 13) {
                g gVar2 = f.f4591a;
                gVar2.g("HotspotHelper");
                gVar2.f(3, null, "wifi ap enabled", new Object[0]);
                HotspotHelper.c(HotspotHelper.this, true);
            }
        }
    }

    static {
        r0.a aVar = r0.f1794a;
        f5527a = a.b.c.a.a.c("dongle hotspot service unavailable", aVar, MKeyEvent.KEYCODE_KONKA_THREEPOINT_COLLECT);
        f5528b = a.b.c.a.a.c("dongle hotspot not available now", aVar, ButtonActionExecutor.TIME_PAGE_CHANGED_DLEAYED);
    }

    public HotspotHelper(Context context) {
        i.e(context, "context");
        this.f5529c = context;
        this.f5530d = VmanMiddleWare.getInstance(context);
        this.f5531e = Executors.newCachedThreadPool();
        this.f5532f = new c0(context);
        this.f5533g = new a();
    }

    public static final void c(HotspotHelper hotspotHelper, boolean z) {
        WifiManager wifiManager;
        Object systemService;
        Context context = hotspotHelper.f5529c;
        i.e(context, "context");
        try {
            systemService = context.getApplicationContext().getSystemService("wifi");
        } catch (Exception e2) {
            g gVar = f.f4591a;
            gVar.g("NetworkUtils");
            gVar.b(i.j("fail to get wifi manager: ", e2), new Object[0]);
            wifiManager = null;
        }
        if (systemService == null) {
            throw new NullPointerException("null cannot be cast to non-null type android.net.wifi.WifiManager");
        }
        wifiManager = (WifiManager) systemService;
        if (wifiManager == null) {
            return;
        }
        boolean z2 = hotspotHelper.j(wifiManager) ? z : false;
        boolean z3 = hotspotHelper.h(wifiManager) ? z : false;
        List listF = e.o.f.f(Task.TaskColumns.ENABLED, "hidden", "bssid", IRemoteConstants.KEY_SSID, "password", "country");
        m2 m2VarE = hotspotHelper.e(z3, e.o.f.d(listF, ",", null, null, 0, null, null, 62));
        m2 m2VarE2 = hotspotHelper.e(z2, e.o.f.d(listF, ",", null, null, 0, null, null, 62));
        g gVar2 = f.f4591a;
        gVar2.g("HotspotHelper");
        gVar2.b("publish config notify, 24G: " + z3 + ", 5G: " + z2, new Object[0]);
        i.e(m2VarE, "notify");
        e1 e1Var = e1.f1627a;
        a.a.a.a.c.c0 c0Var = (a.a.a.a.c.c0) e1.a(q.a(a.a.a.a.c.c0.class));
        a.a.a.a.c.u1.i iVar = a.a.a.a.c.u1.i.f1877a;
        c.c.b.a.z(c0Var, "v1/network/dsu/hotspot/24g/config", a.a.a.a.c.u1.i.l(m2VarE), null, 4, null);
        c.c.b.a.z((a.a.a.a.c.c0) e1.a(q.a(a.a.a.a.c.c0.class)), "v1/network/dongle/hotspot/24g/config", a.a.a.a.c.u1.i.l(m2VarE), null, 4, null);
        i.e(m2VarE2, "notify");
        c.c.b.a.z((a.a.a.a.c.c0) e1.a(q.a(a.a.a.a.c.c0.class)), "v1/network/dsu/hotspot/5g/config", a.a.a.a.c.u1.i.l(m2VarE2), null, 4, null);
        c.c.b.a.z((a.a.a.a.c.c0) e1.a(q.a(a.a.a.a.c.c0.class)), "v1/network/dongle/hotspot/5g/config", a.a.a.a.c.u1.i.l(m2VarE2), null, 4, null);
        a.a.a.a.c.f fVar = new a.a.a.a.c.f(z);
        i.e(fVar, "notify");
        c.c.b.a.z((a.a.a.a.c.c0) e1.a(q.a(a.a.a.a.c.c0.class)), "v1/network/dsu/hotspot/enable", a.a.a.a.c.u1.i.l(fVar), null, 4, null);
        c.c.b.a.z((a.a.a.a.c.c0) e1.a(q.a(a.a.a.a.c.c0.class)), "v1/network/dongle/hotspot/enable", a.a.a.a.c.u1.i.l(fVar), null, 4, null);
    }

    public static final void q(final HotspotHelper hotspotHelper, final boolean z, final d.a.i iVar) {
        final WifiManager wifiManager;
        Object systemService;
        Object systemService2;
        i.e(hotspotHelper, "this$0");
        i.e(iVar, LanguageUtils.ITALIAN_NAME);
        Context context = hotspotHelper.f5529c;
        i.e(context, "context");
        WifiManager wifiManager2 = null;
        try {
            systemService2 = context.getApplicationContext().getSystemService("wifi");
        } catch (Exception e2) {
            g gVar = f.f4591a;
            gVar.g("NetworkUtils");
            gVar.b(i.j("fail to get wifi manager: ", e2), new Object[0]);
            wifiManager = null;
        }
        if (systemService2 == null) {
            throw new NullPointerException("null cannot be cast to non-null type android.net.wifi.WifiManager");
        }
        wifiManager = (WifiManager) systemService2;
        i.c(wifiManager);
        Context context2 = hotspotHelper.f5529c;
        i.e(context2, "context");
        try {
            systemService = context2.getApplicationContext().getSystemService("wifi");
        } catch (Exception e3) {
            g gVar2 = f.f4591a;
            gVar2.g("NetworkUtils");
            gVar2.b(i.j("fail to get wifi manager: ", e3), new Object[0]);
        }
        if (systemService == null) {
            throw new NullPointerException("null cannot be cast to non-null type android.net.wifi.WifiManager");
        }
        wifiManager2 = (WifiManager) systemService;
        i.c(wifiManager2);
        wifiManager2.registerSoftApCallback(hotspotHelper.f5531e, new WifiManager.SoftApCallback() { // from class: com.ifpdos.udi.service.network.HotspotHelper$stopTethering$1$1
            @Keep
            public void onStateChanged(int i2, int i3) {
                String strJ;
                switch (i2) {
                    case 10:
                    case 12:
                    case 13:
                        g gVar3 = f.f4591a;
                        gVar3.g("HotspotHelper");
                        HotspotHelper hotspotHelper2 = hotspotHelper;
                        r0 r0Var = HotspotHelper.f5527a;
                        Objects.requireNonNull(hotspotHelper2);
                        switch (i2) {
                            case 10:
                                strJ = "WIFI_AP_STATE_DISABLING";
                                break;
                            case 11:
                                strJ = "WIFI_AP_STATE_DISABLED";
                                break;
                            case 12:
                                strJ = "WIFI_AP_STATE_ENABLING";
                                break;
                            case 13:
                                strJ = "WIFI_AP_STATE_ENABLED";
                                break;
                            case 14:
                                strJ = "WIFI_AP_STATE_FAILED";
                                break;
                            default:
                                strJ = i.j("WIFI_AP_STATE_UNKNOWN_", Integer.valueOf(i2));
                                break;
                        }
                        gVar3.b(i.j("WIFI AP STATE CHANGED: ", strJ), new Object[0]);
                        break;
                    case 11:
                        wifiManager.unregisterSoftApCallback(this);
                        ((b.a) iVar).b(Boolean.TRUE);
                        if (z) {
                            HotspotHelper hotspotHelper3 = hotspotHelper;
                            r0 r0Var2 = HotspotHelper.f5527a;
                            hotspotHelper3.o();
                        }
                        break;
                    case 14:
                        wifiManager.unregisterSoftApCallback(this);
                        d.a.i<Boolean> iVar2 = iVar;
                        Exception exc = new Exception(String.valueOf(i3));
                        if (!((b.a) iVar2).c(exc)) {
                            a.v(exc);
                        }
                        break;
                }
            }
        });
        TetheringManager tetheringManagerF = hotspotHelper.f();
        i.c(tetheringManagerF);
        tetheringManagerF.stopTethering(0);
    }

    @Override // a.a.a.a.h.c0.a
    public void a() {
        a.a.a.a.c.f fVar = new a.a.a.a.c.f(false);
        i.e(fVar, "notify");
        e1 e1Var = e1.f1627a;
        a.a.a.a.c.c0 c0Var = (a.a.a.a.c.c0) e1.a(q.a(a.a.a.a.c.c0.class));
        a.a.a.a.c.u1.i iVar = a.a.a.a.c.u1.i.f1877a;
        c.c.b.a.z(c0Var, "v1/network/dsu/hotspot/available", a.a.a.a.c.u1.i.l(fVar), null, 4, null);
        c.c.b.a.z((a.a.a.a.c.c0) e1.a(q.a(a.a.a.a.c.c0.class)), "v1/network/dongle/hotspot/available", a.a.a.a.c.u1.i.l(fVar), null, 4, null);
    }

    @Override // a.a.a.a.h.c0.a
    public void b() {
        if (k()) {
            a.a.a.a.c.f fVar = new a.a.a.a.c.f(true);
            i.e(fVar, "notify");
            e1 e1Var = e1.f1627a;
            a.a.a.a.c.c0 c0Var = (a.a.a.a.c.c0) e1.a(q.a(a.a.a.a.c.c0.class));
            a.a.a.a.c.u1.i iVar = a.a.a.a.c.u1.i.f1877a;
            c.c.b.a.z(c0Var, "v1/network/dsu/hotspot/available", a.a.a.a.c.u1.i.l(fVar), null, 4, null);
            c.c.b.a.z((a.a.a.a.c.c0) e1.a(q.a(a.a.a.a.c.c0.class)), "v1/network/dongle/hotspot/available", a.a.a.a.c.u1.i.l(fVar), null, 4, null);
        }
    }

    public final String d(WifiManager wifiManager) {
        MacAddress bssid = wifiManager.getSoftApConfiguration().getBssid();
        if (bssid != null) {
            String string = bssid.toString();
            i.d(string, "bssidFromWifiManager.toString()");
            return string;
        }
        String macAddress = VmanMiddleWare.getInstance(this.f5529c).getNetworkCtrl().getMacAddress("wlan1");
        g gVar = f.f4591a;
        gVar.g("HotspotHelper");
        gVar.b(i.j("bssidFromWifiManager is null, get from vman : ", macAddress), new Object[0]);
        return macAddress == null ? SeewoConstants.BOARD_TYPE_NULL : macAddress;
    }

    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    @SuppressLint({"NewApi"})
    public final m2 e(boolean z, String str) {
        WifiManager wifiManager;
        List<String> listF;
        String str2;
        Object systemService;
        if (!k()) {
            Boolean bool = Boolean.FALSE;
            return new m2(null, bool, null, null, null, null, bool, null, null, null, 957);
        }
        Context context = this.f5529c;
        i.e(context, "context");
        try {
            systemService = context.getApplicationContext().getSystemService("wifi");
        } catch (Exception e2) {
            g gVar = f.f4591a;
            gVar.g("NetworkUtils");
            gVar.b(i.j("fail to get wifi manager: ", e2), new Object[0]);
            wifiManager = null;
        }
        if (systemService == null) {
            throw new NullPointerException("null cannot be cast to non-null type android.net.wifi.WifiManager");
        }
        wifiManager = (WifiManager) systemService;
        i.c(wifiManager);
        if (str == null || h.m(str)) {
            listF = e.o.f.f(Task.TaskColumns.ENABLED, "hidden", "bssid", IRemoteConstants.KEY_SSID, "password", "country", "channel", "nat");
        } else {
            List<String> listV = h.v(str, new String[]{","}, false, 0, 6);
            ArrayList arrayList = new ArrayList(d.a.u.a.g(listV, 10));
            for (String str3 : listV) {
                Objects.requireNonNull(str3, "null cannot be cast to non-null type kotlin.CharSequence");
                arrayList.add(h.A(str3).toString());
            }
            listF = arrayList;
        }
        String str4 = "context";
        m2 m2Var = new m2(null, Boolean.TRUE, null, null, null, null, null, null, null, null, 1021);
        for (String str5 : listF) {
            switch (str5.hashCode()) {
                case -1609594047:
                    str2 = str4;
                    if (str5.equals(Task.TaskColumns.ENABLED)) {
                        m2Var.e(Boolean.valueOf(z));
                        continue;
                    }
                    str4 = str2;
                    break;
                case -1217487446:
                    str2 = str4;
                    if (str5.equals("hidden")) {
                        m2Var.f(Boolean.valueOf(wifiManager.getSoftApConfiguration().isHiddenSsid()));
                        continue;
                    }
                    str4 = str2;
                    break;
                case 108833:
                    if (str5.equals("nat")) {
                        a.a.a.a.h.e7.a aVar = a.a.a.a.h.e7.a.f2062a;
                        Context context2 = this.f5529c;
                        str2 = str4;
                        i.e(context2, str2);
                        m2Var.g(Boolean.valueOf(((a.d) a.a.a.a.h.e7.a.f2063b.getValue()).b(context2)));
                    }
                    str4 = str2;
                    break;
                case 3539835:
                    if (str5.equals(IRemoteConstants.KEY_SSID)) {
                        m2Var.i(wifiManager.getSoftApConfiguration().getSsid());
                    }
                    break;
                case 94044893:
                    if (str5.equals("bssid")) {
                        m2Var.b(d(wifiManager));
                    }
                    break;
                case 738950403:
                    if (str5.equals("channel")) {
                        m2Var.c(Integer.valueOf(wifiManager.getSoftApConfiguration().getChannel()));
                    }
                    break;
                case 957831062:
                    if (str5.equals("country")) {
                        m2Var.d(wifiManager.getCountryCode());
                    }
                    break;
                case 1216985755:
                    if (str5.equals("password")) {
                        m2Var.h(wifiManager.getSoftApConfiguration().getPassphrase());
                    }
                    break;
            }
            str2 = str4;
            str4 = str2;
        }
        m2Var.a(g() ? y1.AP_BAND_24G : y1.AP_BAND_5G);
        return m2Var;
    }

    public final TetheringManager f() {
        try {
            Object systemService = this.f5529c.getApplicationContext().getSystemService("tethering");
            if (systemService != null) {
                return (TetheringManager) systemService;
            }
            throw new NullPointerException("null cannot be cast to non-null type android.net.TetheringManager");
        } catch (Exception e2) {
            g gVar = f.f4591a;
            gVar.g("HotspotHelper");
            gVar.b(i.j("fail to get tethering manager: ", e2), new Object[0]);
            return null;
        }
    }

    public final boolean g() {
        Object systemService;
        WifiManager wifiManager = null;
        if (!l()) {
            g gVar = f.f4591a;
            gVar.g("HotspotHelper");
            gVar.f(3, null, "2.4g dongle hotspot not enabled yet.", new Object[0]);
            return false;
        }
        Context context = this.f5529c;
        i.e(context, "context");
        try {
            systemService = context.getApplicationContext().getSystemService("wifi");
        } catch (Exception e2) {
            g gVar2 = f.f4591a;
            gVar2.g("NetworkUtils");
            gVar2.b(i.j("fail to get wifi manager: ", e2), new Object[0]);
        }
        if (systemService == null) {
            throw new NullPointerException("null cannot be cast to non-null type android.net.wifi.WifiManager");
        }
        wifiManager = (WifiManager) systemService;
        if (wifiManager == null) {
            return false;
        }
        boolean zH = h(wifiManager);
        g gVar3 = f.f4591a;
        gVar3.g("HotspotHelper");
        gVar3.b(i.j("current band is 2.4G: ", Boolean.valueOf(zH)), new Object[0]);
        return zH;
    }

    public final boolean h(WifiManager wifiManager) {
        return wifiManager.getSoftApConfiguration().getBand() == 1;
    }

    public final boolean i() {
        Object systemService;
        WifiManager wifiManager = null;
        if (!l()) {
            g gVar = f.f4591a;
            gVar.g("HotspotHelper");
            gVar.f(3, null, "5.0g dongle hotspot not enabled yet.", new Object[0]);
            return false;
        }
        Context context = this.f5529c;
        i.e(context, "context");
        try {
            systemService = context.getApplicationContext().getSystemService("wifi");
        } catch (Exception e2) {
            g gVar2 = f.f4591a;
            gVar2.g("NetworkUtils");
            gVar2.b(i.j("fail to get wifi manager: ", e2), new Object[0]);
        }
        if (systemService == null) {
            throw new NullPointerException("null cannot be cast to non-null type android.net.wifi.WifiManager");
        }
        wifiManager = (WifiManager) systemService;
        if (wifiManager == null) {
            return false;
        }
        boolean zJ = j(wifiManager);
        g gVar3 = f.f4591a;
        gVar3.g("HotspotHelper");
        gVar3.b(i.j("current band is 5G: ", Boolean.valueOf(zJ)), new Object[0]);
        return zJ;
    }

    @Override // a.a.a.a.h.j3
    public void init() {
        g gVar = f.f4591a;
        gVar.g("HotspotHelper");
        gVar.f(3, null, "init", new Object[0]);
        c0 c0Var = this.f5532f;
        Objects.requireNonNull(c0Var);
        i.e(this, "callback");
        c0Var.f2037b.add(this);
        IntentFilter intentFilter = new IntentFilter("android.net.conn.TETHER_STATE_CHANGED");
        intentFilter.addAction("android.net.wifi.WIFI_AP_STATE_CHANGED");
        this.f5529c.registerReceiver(this.f5533g, intentFilter);
    }

    public final boolean j(WifiManager wifiManager) {
        return (wifiManager.getSoftApConfiguration().getBand() & 2) != 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x003a  */
    /* JADX WARN: Removed duplicated region for block: B:32:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final boolean k() {
        /*
            r5 = this;
            a.a.a.a.h.c0 r0 = r5.f5532f
            boolean r0 = r0.a()
            r1 = 0
            r2 = 0
            if (r0 != 0) goto L42
            a.a.a.a.c.e1 r0 = a.a.a.a.c.e1.f1627a
            java.lang.Class<a.a.a.a.c.c0> r0 = a.a.a.a.c.c0.class
            e.u.b r0 = e.s.c.q.a(r0)
            java.lang.Object r0 = a.a.a.a.c.e1.a(r0)
            a.a.a.a.c.c0 r0 = (a.a.a.a.c.c0) r0
            r3 = 2
            java.lang.String r4 = "v1/device/wifi/pcie/available"
            a.a.a.a.c.c0$a r0 = c.c.b.a.h(r0, r4, r1, r3, r1)
            if (r0 != 0) goto L23
            r0 = r1
            goto L25
        L23:
            java.lang.String r0 = r0.f1608b
        L25:
            if (r0 != 0) goto L28
            goto L3a
        L28:
            a.a.a.a.c.u1.i r3 = a.a.a.a.c.u1.i.f1877a
            a.e.a.l r0 = a.a.a.a.c.u1.i.b(r0)
            if (r0 != 0) goto L32
            r0 = r1
            goto L38
        L32:
            java.lang.String r3 = "value"
            a.e.a.i r0 = r0.i(r3)
        L38:
            if (r0 != 0) goto L3c
        L3a:
            r0 = r2
            goto L40
        L3c:
            boolean r0 = r0.a()
        L40:
            if (r0 == 0) goto L7d
        L42:
            android.content.Context r0 = r5.f5529c
            java.lang.String r3 = "context"
            e.s.c.i.e(r0, r3)
            android.content.Context r0 = r0.getApplicationContext()     // Catch: java.lang.Exception -> L61
            java.lang.String r3 = "wifi"
            java.lang.Object r0 = r0.getSystemService(r3)     // Catch: java.lang.Exception -> L61
            if (r0 == 0) goto L59
            android.net.wifi.WifiManager r0 = (android.net.wifi.WifiManager) r0     // Catch: java.lang.Exception -> L61
            r1 = r0
            goto L74
        L59:
            java.lang.NullPointerException r0 = new java.lang.NullPointerException     // Catch: java.lang.Exception -> L61
            java.lang.String r3 = "null cannot be cast to non-null type android.net.wifi.WifiManager"
            r0.<init>(r3)     // Catch: java.lang.Exception -> L61
            throw r0     // Catch: java.lang.Exception -> L61
        L61:
            r0 = move-exception
            a.f.a.g r3 = a.f.a.f.f4591a
            java.lang.String r4 = "NetworkUtils"
            r3.g(r4)
            java.lang.String r4 = "fail to get wifi manager: "
            java.lang.String r0 = e.s.c.i.j(r4, r0)
            java.lang.Object[] r4 = new java.lang.Object[r2]
            r3.b(r0, r4)
        L74:
            if (r1 == 0) goto L7d
            android.net.TetheringManager r0 = r5.f()
            if (r0 == 0) goto L7d
            r2 = 1
        L7d:
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ifpdos.udi.service.network.HotspotHelper.k():boolean");
    }

    public final boolean l() {
        WifiManager wifiManager;
        Object systemService;
        Context context = this.f5529c;
        i.e(context, "context");
        try {
            systemService = context.getApplicationContext().getSystemService("wifi");
        } catch (Exception e2) {
            g gVar = f.f4591a;
            gVar.g("NetworkUtils");
            gVar.b(i.j("fail to get wifi manager: ", e2), new Object[0]);
            wifiManager = null;
        }
        if (systemService == null) {
            throw new NullPointerException("null cannot be cast to non-null type android.net.wifi.WifiManager");
        }
        wifiManager = (WifiManager) systemService;
        if (wifiManager != null) {
            return wifiManager.getWifiApState() == 13 || wifiManager.getWifiApState() == 12;
        }
        return false;
    }

    public final boolean m(n2 n2Var) {
        return (n2Var.c() == null && n2Var.d() == null && n2Var.f() == null && n2Var.g() == null && n2Var.a() == null && n2Var.e() == null) ? false : true;
    }

    @SuppressLint({"NewApi"})
    public final boolean n(int i2, n2 n2Var) {
        WifiManager wifiManager;
        String strF;
        int iIntValue;
        Object systemService;
        if (!k()) {
            g gVar = f.f4591a;
            gVar.g("HotspotHelper");
            gVar.f(3, null, "fail to set dongle hotspot config: not available now", new Object[0]);
            return false;
        }
        Boolean boolE = n2Var.e();
        if (boolE != null) {
            a.a.a.a.h.e7.a aVar = a.a.a.a.h.e7.a.f2062a;
            Context context = this.f5529c;
            boolean zBooleanValue = boolE.booleanValue();
            i.e(context, "context");
            ((a.d) a.a.a.a.h.e7.a.f2063b.getValue()).a(context, zBooleanValue);
            if (n2Var.e() != null && n2Var.a() == null && n2Var.c() == null && n2Var.d() == null && n2Var.g() == null && n2Var.f() == null) {
                m2 m2Var = new m2(null, null, null, null, null, null, null, null, null, boolE, MKeyEvent.KEYCODE_LIST);
                i.e(m2Var, "notify");
                e1 e1Var = e1.f1627a;
                a.a.a.a.c.c0 c0Var = (a.a.a.a.c.c0) e1.a(q.a(a.a.a.a.c.c0.class));
                a.a.a.a.c.u1.i iVar = a.a.a.a.c.u1.i.f1877a;
                c.c.b.a.z(c0Var, "v1/network/dsu/hotspot/5g/config", a.a.a.a.c.u1.i.l(m2Var), null, 4, null);
                c.c.b.a.z((a.a.a.a.c.c0) e1.a(q.a(a.a.a.a.c.c0.class)), "v1/network/dongle/hotspot/5g/config", a.a.a.a.c.u1.i.l(m2Var), null, 4, null);
                return true;
            }
        }
        Context context2 = this.f5529c;
        i.e(context2, "context");
        try {
            systemService = context2.getApplicationContext().getSystemService("wifi");
        } catch (Exception e2) {
            g gVar2 = f.f4591a;
            gVar2.g("NetworkUtils");
            gVar2.b(i.j("fail to get wifi manager: ", e2), new Object[0]);
            wifiManager = null;
        }
        if (systemService == null) {
            throw new NullPointerException("null cannot be cast to non-null type android.net.wifi.WifiManager");
        }
        wifiManager = (WifiManager) systemService;
        i.c(wifiManager);
        if (n2Var.a() != null) {
            if (Build.VERSION.SDK_INT >= 34) {
                VmanMiddleWare.getInstance().getSupplicantCtrl().setApVendorElements("wlan1", n2Var.a());
            } else {
                Object obj = a.a.a.a.c.s1.a.a.e(wifiManager).b("startWifiApBeacon", n2Var.a()).f1824b;
                Objects.requireNonNull(obj, "null cannot be cast to non-null type kotlin.Boolean");
                if (!((Boolean) obj).booleanValue()) {
                    g gVar3 = f.f4591a;
                    gVar3.g("HotspotHelper");
                    gVar3.f(6, null, "startWifiApBeacon fail", new Object[0]);
                    return false;
                }
            }
            if (n2Var.a() != null && n2Var.c() == null && n2Var.d() == null && n2Var.g() == null && n2Var.f() == null) {
                return true;
            }
        }
        if (i.a(n2Var.c(), Boolean.FALSE)) {
            p(false);
            return true;
        }
        SoftApConfiguration softApConfiguration = wifiManager.getSoftApConfiguration();
        i.d(softApConfiguration, "wifiManager.softApConfiguration");
        if (n2Var.f() == null) {
            strF = softApConfiguration.getPassphrase();
        } else {
            String strF2 = n2Var.f();
            Integer numValueOf = strF2 == null ? null : Integer.valueOf(strF2.length());
            strF = (numValueOf != null && numValueOf.intValue() == 0) ? null : n2Var.f();
        }
        int i3 = ((strF == null || strF.length() == 0) ? 1 : 0) ^ 1;
        SoftApConfiguration.Builder band = new SoftApConfiguration.Builder().setBand(i2);
        String strG = n2Var.g();
        if (strG == null) {
            strG = softApConfiguration.getSsid();
        }
        SoftApConfiguration.Builder ssid = band.setSsid(strG);
        Boolean boolD = n2Var.d();
        SoftApConfiguration.Builder passphrase = ssid.setHiddenSsid(boolD == null ? softApConfiguration.isHiddenSsid() : boolD.booleanValue()).setPassphrase(strF, i3);
        i.d(passphrase, "Builder()\n            .setBand(band)\n            .setSsid(config.ssid ?: original.ssid)\n            .setHiddenSsid(config.hidden ?: original.isHiddenSsid)\n            .setPassphrase(passphrase, security)");
        Integer numB = n2Var.b();
        if (numB != null && softApConfiguration.getChannel() != (iIntValue = numB.intValue())) {
            g gVar4 = f.f4591a;
            gVar4.g("HotspotHelper");
            gVar4.b(i.j("set hotspot channel: ", Integer.valueOf(iIntValue)), new Object[0]);
            passphrase.setChannel(iIntValue, i2);
        }
        SoftApConfiguration softApConfigurationBuild = passphrase.build();
        i.d(softApConfigurationBuild, "configurationBuilder.build()");
        g gVar5 = f.f4591a;
        gVar5.g("HotspotHelper");
        gVar5.b("set dongle hotspot param: " + n2Var + ", config: " + softApConfigurationBuild, new Object[0]);
        wifiManager.setSoftApConfiguration(softApConfigurationBuild);
        g gVar6 = f.f4591a;
        gVar6.g("HotspotHelper");
        gVar6.f(3, null, "enable hotspot", new Object[0]);
        if (l()) {
            g gVar7 = f.f4591a;
            gVar7.g("HotspotHelper");
            gVar7.f(3, null, "hotspot is enabled, disable it first.", new Object[0]);
            p(true);
        } else {
            o();
        }
        return true;
    }

    @SuppressLint({"CheckResult"})
    public final void o() {
        new b(new j() { // from class: a.a.a.a.h.e
            @Override // d.a.j
            public final void a(final d.a.i iVar) {
                HotspotHelper hotspotHelper = this.f2057a;
                e.s.c.i.e(hotspotHelper, "this$0");
                e.s.c.i.e(iVar, LanguageUtils.ITALIAN_NAME);
                TetheringManager tetheringManagerF = hotspotHelper.f();
                e.s.c.i.c(tetheringManagerF);
                tetheringManagerF.startTethering(0, hotspotHelper.f5531e, new TetheringManager.StartTetheringCallback() { // from class: com.ifpdos.udi.service.network.HotspotHelper$startTethering$1$1
                    @Keep
                    public void onTetheringFailed(int i2) {
                        g gVar = f.f4591a;
                        gVar.g("HotspotHelper");
                        gVar.b(i.j("onTetheringFailed: ", Integer.valueOf(i2)), new Object[0]);
                        d.a.i<Boolean> iVar2 = iVar;
                        Exception exc = new Exception(String.valueOf(i2));
                        if (((b.a) iVar2).c(exc)) {
                            return;
                        }
                        d.a.u.a.v(exc);
                    }

                    @Keep
                    public void onTetheringStarted() {
                        g gVar = f.f4591a;
                        gVar.g("HotspotHelper");
                        gVar.f(3, null, "onTetheringStarted", new Object[0]);
                        ((b.a) iVar).b(Boolean.TRUE);
                    }
                });
            }
        }).p(d.a.v.a.f5913c).n(new d.a.r.b() { // from class: a.a.a.a.h.a
            @Override // d.a.r.b
            public final void accept(Object obj) {
                a.a.a.a.c.r0 r0Var = HotspotHelper.f5527a;
                a.f.a.g gVar = a.f.a.f.f4591a;
                gVar.g("HotspotHelper");
                gVar.f(3, null, "hotspot enabled", new Object[0]);
            }
        }, new d.a.r.b() { // from class: a.a.a.a.h.c
            @Override // d.a.r.b
            public final void accept(Object obj) {
                a.a.a.a.c.r0 r0Var = HotspotHelper.f5527a;
                a.f.a.g gVar = a.f.a.f.f4591a;
                gVar.g("HotspotHelper");
                gVar.b(e.s.c.i.j("fail to enable hotspot: ", ((Throwable) obj).getMessage()), new Object[0]);
            }
        }, d.a.s.b.a.f5672b, d.a.s.b.a.f5673c);
    }

    @SuppressLint({"CheckResult"})
    public final void p(final boolean z) {
        g gVar = f.f4591a;
        gVar.g("HotspotHelper");
        gVar.f(3, null, "disable hotspot", new Object[0]);
        if (l()) {
            new b(new j() { // from class: a.a.a.a.h.d
                @Override // d.a.j
                public final void a(d.a.i iVar) {
                    HotspotHelper.q(this.f2047a, z, iVar);
                }
            }).p(d.a.v.a.f5913c).n(new d.a.r.b() { // from class: a.a.a.a.h.f
                @Override // d.a.r.b
                public final void accept(Object obj) {
                    a.a.a.a.c.r0 r0Var = HotspotHelper.f5527a;
                    a.f.a.g gVar2 = a.f.a.f.f4591a;
                    gVar2.g("HotspotHelper");
                    gVar2.f(3, null, "hotspot disabled", new Object[0]);
                }
            }, new d.a.r.b() { // from class: a.a.a.a.h.b
                @Override // d.a.r.b
                public final void accept(Object obj) {
                    a.a.a.a.c.r0 r0Var = HotspotHelper.f5527a;
                    a.f.a.g gVar2 = a.f.a.f.f4591a;
                    gVar2.g("HotspotHelper");
                    gVar2.b(e.s.c.i.j("fail to disable hotspot: ", ((Throwable) obj).getMessage()), new Object[0]);
                }
            }, d.a.s.b.a.f5672b, d.a.s.b.a.f5673c);
            return;
        }
        g gVar2 = f.f4591a;
        gVar2.g("HotspotHelper");
        gVar2.f(3, null, "hotspot not enabled yet", new Object[0]);
    }
}
