package com.seewo.vcommons.helper;

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.constants.SeewoConstants;
import com.seewo.vcommons.cutomer.CustomerUtils;
import com.seewo.vcommons.data.PreferencesUtils;
import com.seewo.vcommons.data.PropertiesUtils;
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 SYSTEM_PERSIST_SSID_PREFIX = "persist.sys.ap.ssid_prefix";
    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 void resetNetShareConfigs() {
    }

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

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

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

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

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

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

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

    private void initHotspotConfig() {
        String property = PropertiesUtils.getProperty("persist.sys.ap.ssid");
        Log.i(TAG, "initHotspotConfig: ssid" + property);
        if (TextUtils.isEmpty(property)) {
            PropertiesUtils.setProperty("persist.sys.ap.ssid", getDefaultSSID());
        }
        this.mHotspotConfig = new HotspotConfig(PropertiesUtils.getProperty("persist.sys.ap.ssid"), PropertiesUtils.getProperty("persist.sys.ap.passwd", "12345678"), PropertiesUtils.getProperty(Constants.PERSIST_AP_BAND, "5g"), PropertiesUtils.getProperty(Constants.PERSIST_AP_COUNTRY, ""), PropertiesUtils.getProperty(Constants.PERSIST_AP_BSSID, ""), PropertiesUtils.getProperty(Constants.PERSIST_AP_HIDE, false));
        Log.d(TAG, "persist.sys.ap_ssid.hide init false ");
        Log.i(TAG, "initHotspotConfig: " + this.mHotspotConfig.toString());
    }

    private String getDefaultSSID() {
        if (CustomerUtils.isMaxhubCustomized() || CustomerUtils.isMaxhubMsaCustomized()) {
            Log.i(TAG, "getDefaultSSID: maxhub" + SystemProperties.get(SYSTEM_PERSIST_SSID_PREFIX));
            return "MAXHUB-" + getStringRandom(3);
        }
        if (!TextUtils.isEmpty(SystemProperties.get(SYSTEM_PERSIST_SSID_PREFIX))) {
            Log.i(TAG, "getDefaultSSID: SYSTEM_PERSIST_SSID_PREFIX" + SystemProperties.get(SYSTEM_PERSIST_SSID_PREFIX));
            return SystemProperties.get(SYSTEM_PERSIST_SSID_PREFIX) + "-" + getStringRandom(3);
        }
        Log.i(TAG, "getDefaultSSID: AP" + SystemProperties.get(SYSTEM_PERSIST_SSID_PREFIX));
        return "AP-" + UUID.randomUUID().toString().substring(0, 16);
    }

    private static String getStringRandom(int i) {
        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        for (int i2 = 0; i2 < i; i2++) {
            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 saveHotspotConfig() {
        if (this.mHotspotConfig == null) {
            return;
        }
        Log.d(TAG, "saveHotspotConfig" + this.mHotspotConfig.toString());
        PropertiesUtils.setProperty("persist.sys.ap.ssid", this.mHotspotConfig.getSsid());
        PropertiesUtils.setProperty("persist.sys.ap.passwd", this.mHotspotConfig.getPasswd());
        PropertiesUtils.setProperty(Constants.PERSIST_AP_BAND, this.mHotspotConfig.getBand());
        Log.d(TAG, "persist.sys.ap_ssid.hide " + this.mHotspotConfig.isHidden());
        PropertiesUtils.setProperty(Constants.PERSIST_AP_HIDE, this.mHotspotConfig.isHidden() ? "1" : "0");
        PropertiesUtils.setProperty(Constants.PERSIST_AP_COUNTRY, this.mHotspotConfig.getCountry());
    }

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

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

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

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

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

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

    public void resetHotspotConfig() {
        Log.i(TAG, "resetHotspotConfig: ");
        PropertiesUtils.setProperty("persist.sys.ap.ssid", getDefaultSSID());
        PropertiesUtils.setProperty("persist.sys.ap.passwd", "12345678");
        PropertiesUtils.setProperty(Constants.PERSIST_AP_BAND, "5g");
        Log.d(TAG, "persist.sys.ap_ssid.hide false");
        PropertiesUtils.setProperty(Constants.PERSIST_AP_HIDE, "");
        PropertiesUtils.setProperty(Constants.PERSIST_AP_COUNTRY, "");
        initHotspotConfig();
        restartHotspot();
    }

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

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

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

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

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

    private void initNetShareConfig() {
        if (TextUtils.isEmpty(PropertiesUtils.getProperty("persist.sys.ap.ssid"))) {
            PropertiesUtils.setProperty("persist.sys.ap.ssid", getDefaultSSID());
        }
    }

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

    public static boolean isHostapdServiceRunning() {
        return isUseApProtocolV2() ? isApServiceRunningV2() : isServiceRunning("hostapd_service");
    }

    public static boolean isServiceRunning(String str) {
        return PropertiesUtils.getProperty("init.svc." + str, "").equals("running");
    }

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

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

    public static void startService(String str) {
        Log.d(TAG, "startService bengin...");
        PropertiesUtils.setProperty("ctl.start", str);
        Log.d(TAG, "startService end...");
    }

    public static void stopService(String str) {
        Log.d(TAG, "stopService begin...");
        PropertiesUtils.setProperty("ctl.stop", str);
        Log.d(TAG, "stopService end...");
    }

    /* 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) {
            String str = commandResultExecuteCommand.successMsg;
            if (str.contains(":")) {
                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 e) {
                                e = e;
                                bufferedReader = bufferedReader2;
                                bufferedReader2 = bufferedReader3;
                                Log.e(TAG, e.getMessage(), e);
                                if (bufferedReader2 != null) {
                                    try {
                                        bufferedReader2.close();
                                    } catch (IOException e2) {
                                        Log.e(TAG, e2.getMessage(), e2);
                                    }
                                }
                                bufferedReader2 = bufferedReader;
                            } catch (Throwable th) {
                                th = th;
                                bufferedReader2 = bufferedReader3;
                                if (bufferedReader2 != null) {
                                    try {
                                        bufferedReader2.close();
                                    } catch (IOException e3) {
                                        Log.e(TAG, e3.getMessage(), e3);
                                    }
                                }
                                throw th;
                            }
                        }
                        bufferedReader3.close();
                        try {
                            bufferedReader3.close();
                        } catch (IOException e4) {
                            Log.e(TAG, e4.getMessage(), e4);
                        }
                    } catch (IOException e5) {
                        e = e5;
                        bufferedReader = null;
                    }
                    return new String[]{strSubstring, bufferedReader2};
                } catch (Throwable th2) {
                    th = th2;
                }
            } else {
                return new String[0];
            }
        } else {
            return new String[0];
        }
    }

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

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

    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();
    }

    /* 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 e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }

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

    /* JADX INFO: Access modifiers changed from: private */
    public void startAPService() {
        Log.i(TAG, "startAPService");
        boolean zIsUseApProtocolV2 = isUseApProtocolV2();
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            Log.e(TAG, e.getMessage(), e);
        }
        int i = 5;
        while (true) {
            i--;
            if (zIsUseApProtocolV2) {
                if (PropertiesUtils.getProperty("init.ap_service.success").equals(SeewoConstants.KEY_FIRST_BUTTON_IN_PC)) {
                    startService("stopap_service");
                }
                if (!PropertiesUtils.getProperty("init.ap_service.success").equals(SeewoConstants.KEY_THIRD_BUTTON)) {
                    startService("startap_service");
                }
            } else {
                startService("hostapd_init");
            }
            long jUptimeMillis = SystemClock.uptimeMillis();
            int i2 = 0;
            while (PreferencesUtils.getApStatus(this.mContext) && !isHostapdServiceRunning() && i2 <= INTERVAL) {
                try {
                    Thread.sleep(100L);
                } catch (InterruptedException e2) {
                    Log.e(TAG, e2.getMessage(), e2);
                }
                i2 += 100;
            }
            Log.d(TAG, "time:" + i2 + "---isHostapdServiceRunning():" + isHostapdServiceRunning());
            if (i2 <= INTERVAL && isHostapdServiceRunning()) {
                Log.d(TAG, "start hostapd cost:" + (SystemClock.uptimeMillis() - jUptimeMillis));
                break;
            } else if (i <= 0 || !PreferencesUtils.getApStatus(this.mContext)) {
                break;
            }
        }
        if (isHostapdServiceRunning()) {
            if (zIsUseApProtocolV2) {
                return;
            }
            sendBroadcast("com.seewo.ap.STARTED");
        } else {
            if (zIsUseApProtocolV2) {
                return;
            }
            sendBroadcast("com.seewo.ap.FAILED");
        }
    }

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

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

    public class HotspotConfig {
        private String band;
        private String bssid;
        private String country;
        private boolean isHidden;
        private String password;
        private String ssid;

        public HotspotConfig() {
        }

        public HotspotConfig(String str, String str2, String str3, String str4, String str5, boolean z) {
            this.ssid = str;
            this.password = str2;
            this.band = str3;
            this.country = str4;
            this.isHidden = z;
            this.bssid = str5;
        }

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

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

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

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

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

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

        public boolean isHidden() {
            return this.isHidden;
        }

        public void setHidden(boolean z) {
            this.isHidden = z;
        }

        public String getCountry() {
            return this.country;
        }

        public void setCountry(String str) {
            this.country = str;
        }

        public String getBssid() {
            return this.bssid;
        }

        public String toString() {
            return "HotspotConfig{ssid='" + this.ssid + "', passwd='" + this.password + "', band='" + this.band + "', isHidden=" + this.isHidden + ", country='" + this.country + "', bssid='" + this.bssid + "'}";
        }
    }

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

        public HotspotDebugConfig() {
        }

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

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

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

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

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

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

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

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

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

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

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

        public String toString() {
            return "HotspotDebugConfig{hwMode='" + this.hwMode + "', maxNumSta='" + this.maxNumSta + "', channel='" + this.channel + "', htCapab='" + this.htCapab + "'}";
        }
    }

    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 boolean validate() {
            return false;
        }

        public DHCPConfig() {
        }

        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 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 String getRange() {
            return this.startIp + "," + this.endIp + "," + this.netMask + "," + this.lease;
        }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        public String toString() {
            return "DHCPConfig{startIp='" + this.startIp + "', endIp='" + this.endIp + "', netMask='" + this.netMask + "', lease='" + this.lease + "', gateway='" + this.gateway + "', dns1='" + this.dns1 + "', dns2='" + this.dns2 + "'}";
        }
    }

    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_BSSID = "persist.sys.ap.bssid";
        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() {
        }
    }

    private 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;

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

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