package com.seewo.vcommons.helper;

import a.b.c.a.a;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;
import com.seewo.vcommons.cutomer.CustomerUtils;
import com.seewo.vcommons.utils.BoardTypeUtils;
import com.seewo.vcommons.utils.ShellCommandUtils;
import com.seewo.vcommons.utils.reflect.ContextInsider;
import com.seewo.vcommons.utils.reflect.UserHandleInsider;
import com.seewo.vcommons.utils.reflect.WifiManagerInsider;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Random;
import java.util.UUID;

/* JADX INFO: loaded from: classes.dex */
public class NetShareHelper {
    private static final int INTERVAL = 15000;
    private static final String TAG = "NetShareHelper";
    private static volatile NetShareHelper sInstance;
    private ApManagerHandler mApManagerHandler;
    private Context mContext;
    private DHCPConfig mEthDHCPConfig;
    private HotspotConfig mHotspotConfig;
    private DHCPConfig mHotspotDHCPConfig;
    private HotspotDebugConfig mHotspotDebugConfig;

    public class ApManagerHandler extends Handler {
        private static final int MSG_RESTART_AP = 2;
        private static final int MSG_START_AP = 0;
        private static final int MSG_STOP_AP = 1;

        public ApManagerHandler(Looper looper) {
            super(looper);
        }

        @Override // android.os.Handler
        public void handleMessage(Message message) {
            int i2 = message.what;
            if (i2 == 0) {
                NetShareHelper.this.waitWifiApDisableIfNecessary();
                if (NetShareHelper.isHostapdServiceRunning()) {
                    return;
                }
                if (NetShareHelper.isUseApProtocolV2() && 1 == message.arg1) {
                    SystemProperties.set("persist.sys.usbAp.insterted", "1");
                }
            } else if (i2 == 1) {
                NetShareHelper.this.stopAPService();
                return;
            } else {
                if (i2 != 2) {
                    return;
                }
                if (BoardTypeUtils.is810Machine()) {
                    NetShareHelper.startService("restartap_service");
                    return;
                }
                NetShareHelper.this.stopAPService();
            }
            NetShareHelper.this.loadCFGDriver();
            NetShareHelper.this.startAPService();
        }
    }

    public final class Constants {
        public static final String ACTION_AP_FAILED = "com.seewo.ap.FAILED";
        public static final String ACTION_AP_PLUGIN = "com.seewo.ap.PLUGIN";
        public static final String ACTION_AP_PLUGOUT = "com.seewo.ap.PLUGOUT";
        public static final String ACTION_AP_STARTED = "com.seewo.ap.STARTED";
        public static final String ACTION_AP_STARTING = "com.seewo.ap.STARTING";
        public static final String ACTION_AP_STOPPED = "com.seewo.ap.STOPPED";
        public static final String AP_BAND_2G4 = "2g4";
        public static final String AP_BAND_5G = "5g";
        public static final int AP_FAILED = 10;
        public static final int AP_PLUGIN = 9;
        public static final int AP_PLUGOUT = 8;
        public static final int AP_RESTARTED = 12;
        public static final int AP_RESTARTING = 11;
        public static final int AP_STARTED = 1;
        public static final int AP_STARTING = 2;
        public static final int AP_START_FAILED = 3;
        private static final String AP_STATE_ENABLING = "3";
        private static final String AP_STATE_FAILED = "5";
        public static final int AP_STOPPED = 4;
        public static final int AP_STOPPING = 5;
        public static final int AP_STOP_FAILED = 6;
        public static final int AP_UNKNOWN = 7;
        public static final String CTL_START = "ctl.start";
        public static final String CTL_STOP = "ctl.stop";
        public static final String DEFAULT_AP_BAND = "5g";
        public static final String DEFAULT_AP_DEBUG = "a,8,36,[SHORT-GI-20][SHORT-GI-40][HT40+]";
        public static final String DEFAULT_AP_PASSWD = "12345678";
        public static final String DEFAULT_DHCP_OPTION0 = "192.168.53.1,8.8.8.8,8.8.4.4";
        public static final String DEFAULT_DHCP_OPTION1 = "192.168.54.1,8.8.8.8,8.8.4.4";
        public static final String DEFAULT_DHCP_RANGE0 = "192.168.53.100,192.168.53.200,255.255.255.0,12h";
        public static final String DEFAULT_DHCP_RANGE1 = "192.168.54.100,192.168.54.200,255.255.255.0,12h";
        public static final String DNS_LEASES_FILE = "/data/misc/wifi/dns_netshare.leases";
        private static final String KEY_USB_AP_INSERTED = "persist.sys.usbAp.insterted";
        public static final String PERSIST_AP_BAND = "persist.sys.ap.band";
        public static final String PERSIST_AP_COUNTRY = "persist.sys.country";
        public static final String PERSIST_AP_DEBUG = "persist.sys.ap.debug";
        public static final String PERSIST_AP_HIDE = "persist.sys.ap_ssid.hide";
        public static final String PERSIST_AP_PASSWD = "persist.sys.ap.passwd";
        public static final String PERSIST_AP_SSID = "persist.sys.ap.ssid";
        public static final String PERSIST_AP_STATUS = "persist.sys.ap.status";
        public static final String PERSIST_DHCP_OPTION0 = "persist.sys.dhcp_option0";
        public static final String PERSIST_DHCP_OPTION1 = "persist.sys.dhcp_option1";
        public static final String PERSIST_DHCP_RANGE0 = "persist.sys.dhcp_range0";
        public static final String PERSIST_DHCP_RANGE1 = "persist.sys.dhcp_range1";
        private static final String SERVICE_AP_RESTART_V2 = "restartap_service";
        private static final String SERVICE_AP_START_V2 = "startap_service";
        private static final String SERVICE_AP_STOP_V2 = "stopap_service";
        public static final String SERVICE_DNSMASQ_INIT = "dnsmasq_init";
        public static final String SERVICE_DNSMASQ_SERVICE = "dnsmasq_service";
        public static final String SERVICE_HOSTAPD_INIT = "hostapd_init";
        public static final String SERVICE_HOSTAPD_SERVICE = "hostapd_service";
        public static final String SERVICE_LOAD_APDRIVERS = "load_apdrivers";
        public static final String SERVICE_LOAD_CFGDRIVER = "load_cfgdriver";
        public static final String SERVICE_PRIFIX = "init.svc.";
        public static final String SERVICE_RUNNING = "running";
        private static final String SERVICE_RUNNING_V2 = "1";
        private static final String SERVICE_STATE_V2 = "init.ap_service.success";
        public static final String SERVICE_UNLOAD_APDRIVERS = "unload_apdrivers";

        private Constants() {
        }
    }

    public class DHCPConfig {
        private String dns1;
        private String dns2;
        private String endIp;
        private String gateway;
        private String lease;
        private String netMask;
        private String startIp;

        public DHCPConfig() {
        }

        public DHCPConfig(String str, String str2, String str3, String str4, String str5, String str6, String str7) {
            this.startIp = str;
            this.endIp = str2;
            this.netMask = str3;
            this.lease = str4;
            this.gateway = str5;
            this.dns1 = str6;
            this.dns2 = str7;
        }

        public DHCPConfig(String[] strArr, String[] strArr2) {
            this.startIp = strArr[0];
            this.endIp = strArr[1];
            this.netMask = strArr[2];
            this.lease = strArr[3];
            this.gateway = strArr2[0];
            this.dns1 = strArr2[1];
            this.dns2 = strArr2[2];
        }

        public String getDns1() {
            return this.dns1;
        }

        public String getDns2() {
            return this.dns2;
        }

        public String getEndIp() {
            return this.endIp;
        }

        public String getGateway() {
            return this.gateway;
        }

        public String getLease() {
            return this.lease;
        }

        public String getNetMask() {
            return this.netMask;
        }

        public String getOption() {
            return this.gateway + "," + this.dns1 + "," + this.dns2;
        }

        public String getRange() {
            return this.startIp + "," + this.endIp + "," + this.netMask + "," + this.lease;
        }

        public String getStartIp() {
            return this.startIp;
        }

        public void setDns1(String str) {
            this.dns1 = str;
        }

        public void setDns2(String str) {
            this.dns2 = str;
        }

        public void setEndIp(String str) {
            this.endIp = str;
        }

        public void setGateway(String str) {
            this.gateway = str;
        }

        public void setLease(String str) {
            this.lease = str;
        }

        public void setNetMask(String str) {
            this.netMask = str;
        }

        public void setStartIp(String str) {
            this.startIp = str;
        }

        public String toString() {
            StringBuilder sbC = a.C("DHCPConfig{startIp='");
            a.i0(sbC, this.startIp, '\'', ", endIp='");
            a.i0(sbC, this.endIp, '\'', ", netMask='");
            a.i0(sbC, this.netMask, '\'', ", lease='");
            a.i0(sbC, this.lease, '\'', ", gateway='");
            a.i0(sbC, this.gateway, '\'', ", dns1='");
            a.i0(sbC, this.dns1, '\'', ", dns2='");
            sbC.append(this.dns2);
            sbC.append('\'');
            sbC.append('}');
            return sbC.toString();
        }

        public boolean validate() {
            return false;
        }
    }

    public class HotspotConfig {
        private String band;
        private String passwd;
        private String ssid;

        public HotspotConfig() {
        }

        public HotspotConfig(String str, String str2, String str3) {
            this.ssid = str;
            this.passwd = str2;
            this.band = str3;
        }

        public String getBand() {
            return this.band;
        }

        public String getPasswd() {
            return this.passwd;
        }

        public String getSsid() {
            return this.ssid;
        }

        public void setBand(String str) {
            this.band = str;
        }

        public void setPasswd(String str) {
            this.passwd = str;
        }

        public void setSsid(String str) {
            this.ssid = str;
        }

        public String toString() {
            StringBuilder sbC = a.C("HotspotConfig{ssid='");
            a.i0(sbC, this.ssid, '\'', ", passwd='");
            a.i0(sbC, this.passwd, '\'', ", band='");
            sbC.append(this.band);
            sbC.append('\'');
            sbC.append('}');
            return sbC.toString();
        }
    }

    public class HotspotDebugConfig {
        private String channel;
        private String htCapab;
        private String hwMode;
        private String maxNumSta;

        public HotspotDebugConfig() {
        }

        public HotspotDebugConfig(String str, String str2, String str3, String str4) {
            this.hwMode = str;
            this.maxNumSta = str2;
            this.channel = str3;
            this.htCapab = str4;
        }

        public HotspotDebugConfig(String[] strArr) {
            this.hwMode = strArr[0];
            this.maxNumSta = strArr[1];
            this.channel = strArr[2];
            this.htCapab = strArr[3];
        }

        public String getChannel() {
            return this.channel;
        }

        public String getDebugConfig() {
            return this.hwMode + "," + this.maxNumSta + "," + this.channel + "," + this.htCapab;
        }

        public String getHtCapab() {
            return this.htCapab;
        }

        public String getHwMode() {
            return this.hwMode;
        }

        public String getMaxNumSta() {
            return this.maxNumSta;
        }

        public void setChannel(String str) {
            this.channel = str;
        }

        public void setHtCapab(String str) {
            this.htCapab = str;
        }

        public void setHwMode(String str) {
            this.hwMode = str;
        }

        public void setMaxNumSta(String str) {
            this.maxNumSta = str;
        }

        public String toString() {
            StringBuilder sbC = a.C("HotspotDebugConfig{hwMode='");
            a.i0(sbC, this.hwMode, '\'', ", maxNumSta='");
            a.i0(sbC, this.maxNumSta, '\'', ", channel='");
            a.i0(sbC, this.channel, '\'', ", htCapab='");
            sbC.append(this.htCapab);
            sbC.append('\'');
            sbC.append('}');
            return sbC.toString();
        }
    }

    private NetShareHelper() {
        initNetShareConfig();
        HandlerThread handlerThread = new HandlerThread("SeewoApManager");
        handlerThread.start();
        this.mApManagerHandler = new ApManagerHandler(handlerThread.getLooper());
    }

    /* JADX WARN: Multi-variable type inference failed */
    public static String[] getAndroidSlotIpConfig() throws Throwable {
        BufferedReader bufferedReader;
        File file = new File(Constants.DNS_LEASES_FILE);
        if (!file.exists()) {
            return new String[0];
        }
        ShellCommandUtils.CommandResult commandResultExecuteCommand = ShellCommandUtils.executeCommand("adb shell getprop | busybox grep 'net.hostname'", true);
        if (commandResultExecuteCommand.result != 0) {
            return new String[0];
        }
        String str = commandResultExecuteCommand.successMsg;
        if (!str.contains(":")) {
            return new String[0];
        }
        String strTrim = str.split(":")[1].trim();
        String strSubstring = strTrim.substring(1, strTrim.length() - 1);
        BufferedReader bufferedReader2 = null;
        try {
            try {
                BufferedReader bufferedReader3 = new BufferedReader(new FileReader(file));
                while (true) {
                    try {
                        String line = bufferedReader3.readLine();
                        if (line == null) {
                            break;
                        }
                        String[] strArrSplit = line.split(" ");
                        if (strArrSplit[3].equals(strSubstring)) {
                            bufferedReader2 = strArrSplit[2];
                            break;
                        }
                    } catch (IOException e2) {
                        e = e2;
                        bufferedReader = bufferedReader2;
                        bufferedReader2 = bufferedReader3;
                        Log.e(TAG, e.getMessage(), e);
                        if (bufferedReader2 != null) {
                            try {
                                bufferedReader2.close();
                            } catch (IOException e3) {
                                Log.e(TAG, e3.getMessage(), e3);
                            }
                        }
                        bufferedReader2 = bufferedReader;
                    } catch (Throwable th) {
                        th = th;
                        bufferedReader2 = bufferedReader3;
                        if (bufferedReader2 != null) {
                            try {
                                bufferedReader2.close();
                            } catch (IOException e4) {
                                Log.e(TAG, e4.getMessage(), e4);
                            }
                        }
                        throw th;
                    }
                }
                bufferedReader3.close();
                try {
                    bufferedReader3.close();
                } catch (IOException e5) {
                    Log.e(TAG, e5.getMessage(), e5);
                }
            } catch (IOException e6) {
                e = e6;
                bufferedReader = null;
            }
            return new String[]{strSubstring, bufferedReader2};
        } catch (Throwable th2) {
            th = th2;
        }
    }

    private String getDefaultSSID() {
        StringBuilder sbC;
        String strSubstring;
        if (CustomerUtils.isMaxhubCustomized()) {
            sbC = a.C("MAXHUB-");
            strSubstring = getStringRandom(3);
        } else {
            sbC = a.C("AP-");
            strSubstring = UUID.randomUUID().toString().substring(0, 16);
        }
        sbC.append(strSubstring);
        return sbC.toString();
    }

    public static NetShareHelper getInstance() {
        if (sInstance == null) {
            synchronized (StorageHelper.class) {
                if (sInstance == null) {
                    sInstance = new NetShareHelper();
                }
            }
        }
        return sInstance;
    }

    private static String getStringRandom(int i2) {
        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        for (int i3 = 0; i3 < i2; i3++) {
            if ("char".equalsIgnoreCase(random.nextInt(2) % 2 == 0 ? "char" : "num")) {
                sb.append((char) (random.nextInt(26) + 65));
            } else {
                sb.append(random.nextInt(10));
            }
        }
        return sb.toString();
    }

    private void initEthDHCPConfig() {
        this.mEthDHCPConfig = new DHCPConfig(SystemProperties.get(Constants.PERSIST_DHCP_RANGE0, Constants.DEFAULT_DHCP_RANGE0).split(","), SystemProperties.get(Constants.PERSIST_DHCP_OPTION0, Constants.DEFAULT_DHCP_OPTION0).split(","));
    }

    private void initHotspotConfig() {
        if (TextUtils.isEmpty(SystemProperties.get(Constants.PERSIST_AP_SSID))) {
            SystemProperties.set(Constants.PERSIST_AP_SSID, getDefaultSSID());
        }
        this.mHotspotConfig = new HotspotConfig(SystemProperties.get(Constants.PERSIST_AP_SSID), SystemProperties.get(Constants.PERSIST_AP_PASSWD, Constants.DEFAULT_AP_PASSWD), SystemProperties.get(Constants.PERSIST_AP_BAND, "5g"));
    }

    private void initHotspotDHCPConfig() {
        this.mHotspotDHCPConfig = new DHCPConfig(SystemProperties.get(Constants.PERSIST_DHCP_RANGE1, Constants.DEFAULT_DHCP_RANGE1).split(","), SystemProperties.get(Constants.PERSIST_DHCP_OPTION1, Constants.DEFAULT_DHCP_OPTION1).split(","));
    }

    private void initHotspotDebugConfig() {
        this.mHotspotDebugConfig = new HotspotDebugConfig(SystemProperties.get(Constants.PERSIST_AP_DEBUG, Constants.DEFAULT_AP_DEBUG).split(","));
    }

    private void initNetShareConfig() {
        if (TextUtils.isEmpty(SystemProperties.get(Constants.PERSIST_AP_SSID))) {
            SystemProperties.set(Constants.PERSIST_AP_SSID, getDefaultSSID());
        }
    }

    private static boolean isApServiceRunningV2() {
        return SystemProperties.get("init.ap_service.success").equals("1");
    }

    public static boolean isHostapdServiceRunning() {
        return isUseApProtocolV2() ? isApServiceRunningV2() : isServiceRunning(Constants.SERVICE_HOSTAPD_SERVICE);
    }

    public static boolean isServiceRunning(String str) {
        return SystemProperties.get(Constants.SERVICE_PRIFIX + str, "").equals(Constants.SERVICE_RUNNING);
    }

    public static boolean isUseApProtocolV2() {
        return (BoardTypeUtils.is6369Machine() || BoardTypeUtils.is638Machine() || BoardTypeUtils.is510Machine()) ? false : true;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void loadCFGDriver() {
        if (isUseApProtocolV2()) {
            return;
        }
        Log.i(TAG, "loadCFGDriver");
        startService(Constants.SERVICE_LOAD_CFGDRIVER);
    }

    private void saveEthDHCPConfig() {
        DHCPConfig dHCPConfig = this.mEthDHCPConfig;
        if (dHCPConfig == null) {
            return;
        }
        SystemProperties.set(Constants.PERSIST_DHCP_RANGE0, dHCPConfig.getRange());
        SystemProperties.set(Constants.PERSIST_DHCP_OPTION0, this.mEthDHCPConfig.getOption());
    }

    private void saveHotspotConfig() {
        HotspotConfig hotspotConfig = this.mHotspotConfig;
        if (hotspotConfig == null) {
            return;
        }
        Log.d(TAG, hotspotConfig.toString());
        SystemProperties.set(Constants.PERSIST_AP_SSID, this.mHotspotConfig.getSsid());
        SystemProperties.set(Constants.PERSIST_AP_PASSWD, this.mHotspotConfig.getPasswd());
        SystemProperties.set(Constants.PERSIST_AP_BAND, this.mHotspotConfig.getBand());
    }

    private void saveHotspotDHCPConfig() {
        DHCPConfig dHCPConfig = this.mHotspotDHCPConfig;
        if (dHCPConfig == null) {
            return;
        }
        SystemProperties.set(Constants.PERSIST_DHCP_RANGE1, dHCPConfig.getRange());
        SystemProperties.set(Constants.PERSIST_DHCP_OPTION1, this.mHotspotDHCPConfig.getOption());
    }

    private void saveHotspotDebugConfig() {
        HotspotDebugConfig hotspotDebugConfig = this.mHotspotDebugConfig;
        if (hotspotDebugConfig == null) {
            return;
        }
        SystemProperties.set(Constants.PERSIST_AP_DEBUG, hotspotDebugConfig.getDebugConfig());
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:34:0x008b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void startAPService() {
        /*
            r8 = this;
            java.lang.String r0 = "NetShareHelper"
            java.lang.String r1 = "startAPService"
            android.util.Log.i(r0, r1)
            boolean r1 = isUseApProtocolV2()
            r2 = 1000(0x3e8, double:4.94E-321)
            java.lang.Thread.sleep(r2)     // Catch: java.lang.InterruptedException -> L11
            goto L19
        L11:
            r2 = move-exception
            java.lang.String r3 = r2.getMessage()
            android.util.Log.e(r0, r3, r2)
        L19:
            r2 = 5
        L1a:
            int r2 = r2 + (-1)
            if (r1 == 0) goto L40
            java.lang.String r3 = "init.ap_service.success"
            java.lang.String r4 = android.os.SystemProperties.get(r3)
            java.lang.String r5 = "5"
            boolean r4 = r4.equals(r5)
            if (r4 == 0) goto L31
            java.lang.String r4 = "stopap_service"
            startService(r4)
        L31:
            java.lang.String r3 = android.os.SystemProperties.get(r3)
            java.lang.String r4 = "3"
            boolean r3 = r3.equals(r4)
            if (r3 != 0) goto L45
            java.lang.String r3 = "startap_service"
            goto L42
        L40:
            java.lang.String r3 = "hostapd_init"
        L42:
            startService(r3)
        L45:
            long r3 = android.os.SystemClock.uptimeMillis()
            r5 = 0
        L4a:
            android.content.Context r6 = r8.mContext
            boolean r6 = com.seewo.vcommons.data.PreferencesUtils.getApStatus(r6)
            r7 = 15000(0x3a98, float:2.102E-41)
            if (r6 == 0) goto L6d
            boolean r6 = isHostapdServiceRunning()
            if (r6 != 0) goto L6d
            if (r5 > r7) goto L6d
            r6 = 100
            java.lang.Thread.sleep(r6)     // Catch: java.lang.InterruptedException -> L62
            goto L6a
        L62:
            r6 = move-exception
            java.lang.String r7 = r6.getMessage()
            android.util.Log.e(r0, r7, r6)
        L6a:
            int r5 = r5 + 100
            goto L4a
        L6d:
            if (r5 > r7) goto L8b
            boolean r5 = isHostapdServiceRunning()
            if (r5 == 0) goto L8b
            java.lang.String r2 = "start hostapd cost:"
            java.lang.StringBuilder r2 = a.b.c.a.a.C(r2)
            long r5 = android.os.SystemClock.uptimeMillis()
            long r5 = r5 - r3
            r2.append(r5)
            java.lang.String r2 = r2.toString()
            android.util.Log.d(r0, r2)
            goto L95
        L8b:
            if (r2 <= 0) goto L95
            android.content.Context r3 = r8.mContext
            boolean r3 = com.seewo.vcommons.data.PreferencesUtils.getApStatus(r3)
            if (r3 != 0) goto L1a
        L95:
            boolean r0 = isHostapdServiceRunning()
            if (r0 == 0) goto La0
            if (r1 != 0) goto La7
            java.lang.String r0 = "com.seewo.ap.STARTED"
            goto La4
        La0:
            if (r1 != 0) goto La7
            java.lang.String r0 = "com.seewo.ap.FAILED"
        La4:
            r8.sendBroadcast(r0)
        La7:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.seewo.vcommons.helper.NetShareHelper.startAPService():void");
    }

    public static void startService(String str) {
        SystemProperties.set(Constants.CTL_START, str);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void stopAPService() {
        String str;
        Log.i(TAG, "stopAPService");
        if (isUseApProtocolV2()) {
            str = "stopap_service";
        } else {
            stopService(Constants.SERVICE_HOSTAPD_SERVICE);
            stopService(Constants.SERVICE_DNSMASQ_SERVICE);
            str = Constants.SERVICE_UNLOAD_APDRIVERS;
        }
        startService(str);
        try {
            Thread.sleep(4000L);
        } catch (InterruptedException e2) {
            Log.e(TAG, e2.getMessage(), e2);
        }
        if (isUseApProtocolV2()) {
            return;
        }
        sendBroadcast("com.seewo.ap.STOPPED");
    }

    public static void stopService(String str) {
        SystemProperties.set(Constants.CTL_STOP, str);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void waitWifiApDisableIfNecessary() {
        WifiManager wifiManager = (WifiManager) this.mContext.getApplicationContext().getSystemService("wifi");
        if (wifiManager == null || WifiManagerInsider.getWifiApState(wifiManager) == WifiManagerInsider.WIFI_AP_STATE_DISABLED) {
            return;
        }
        try {
            long jUptimeMillis = SystemClock.uptimeMillis();
            while (WifiManagerInsider.getWifiApState(wifiManager) != WifiManagerInsider.WIFI_AP_STATE_DISABLED && SystemClock.uptimeMillis() - jUptimeMillis <= 15000) {
                Thread.sleep(100L);
            }
            Thread.sleep(300L);
        } catch (InterruptedException e2) {
            Log.e(TAG, e2.getMessage(), e2);
        }
    }

    public DHCPConfig getEthDHCPConfig() {
        if (this.mEthDHCPConfig == null) {
            initEthDHCPConfig();
        }
        return this.mEthDHCPConfig;
    }

    public HotspotConfig getHotspotConfig() {
        initHotspotConfig();
        return this.mHotspotConfig;
    }

    public DHCPConfig getHotspotDHCPConfig() {
        if (this.mHotspotDHCPConfig == null) {
            initHotspotDHCPConfig();
        }
        return this.mHotspotDHCPConfig;
    }

    public HotspotDebugConfig getHotspotDebugConfig() {
        if (this.mHotspotDebugConfig == null) {
            initHotspotDebugConfig();
        }
        return this.mHotspotDebugConfig;
    }

    public void init(Context context) {
        this.mContext = context.getApplicationContext();
    }

    public void resetAPConfig() {
        initEthDHCPConfig();
        saveEthDHCPConfig();
        initHotspotDHCPConfig();
        saveHotspotDHCPConfig();
        initHotspotConfig();
        saveHotspotConfig();
    }

    public void resetHotspotConfig() {
        SystemProperties.set(Constants.PERSIST_AP_SSID, getDefaultSSID());
        SystemProperties.set(Constants.PERSIST_AP_PASSWD, Constants.DEFAULT_AP_PASSWD);
        SystemProperties.set(Constants.PERSIST_AP_BAND, "5g");
        SystemProperties.set(Constants.PERSIST_AP_HIDE, "");
        SystemProperties.set(Constants.PERSIST_AP_COUNTRY, "");
        initHotspotConfig();
        restartHotspot();
    }

    public void resetNetShareConfigs() {
    }

    public void restartHotspot() {
        this.mApManagerHandler.removeCallbacksAndMessages(null);
        this.mApManagerHandler.sendEmptyMessage(2);
    }

    public void sendBroadcast(String str) {
        Intent intent = new Intent();
        intent.setAction(str);
        ContextInsider.sendBroadcastAsUser(this.mContext, intent, UserHandleInsider.ALL);
    }

    public void setEthDHCPConfig(DHCPConfig dHCPConfig) {
        this.mEthDHCPConfig = dHCPConfig;
    }

    public void setHotspotConfig(HotspotConfig hotspotConfig) {
        this.mHotspotConfig = hotspotConfig;
    }

    public void setHotspotDHCPConfig(DHCPConfig dHCPConfig) {
        this.mHotspotDHCPConfig = dHCPConfig;
    }

    public void setHotspotDebugConfig(HotspotDebugConfig hotspotDebugConfig) {
        this.mHotspotDebugConfig = hotspotDebugConfig;
    }

    public void startHotspot() {
        startHotspot(false);
    }

    public void startHotspot(boolean z) {
        this.mApManagerHandler.removeCallbacksAndMessages(null);
        Message message = new Message();
        message.what = 0;
        message.arg1 = z ? 1 : 0;
        this.mApManagerHandler.sendMessage(message);
    }

    @Deprecated
    public void startHotspotAfterWifiApDisabled() {
        startHotspot();
    }

    public void stopHotspot() {
        this.mApManagerHandler.removeCallbacksAndMessages(null);
        this.mApManagerHandler.sendEmptyMessage(1);
    }

    public void syncNetShareConfigs() {
        saveEthDHCPConfig();
        saveHotspotConfig();
        saveHotspotDHCPConfig();
        saveHotspotDebugConfig();
    }
}
