package com.seewo.libsvendors.utils;

import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.util.Log;
import com.seewo.libsvendors.utils.reflect.ContextInsider;
import com.seewo.libsvendors.utils.reflect.UserHandleInsider;

/* JADX INFO: loaded from: classes.dex */
public class NetShareHelper {
    private static final int INTERVAL = 15000;
    private static final Object LOCK = new Object();
    private static final String TAG = "NetShareHelper";
    private static NetShareHelper sInstance;
    private Context mContext;

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

    public static NetShareHelper getInstance() {
        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 SystemProperties.get("init.svc." + str, "").equals("running");
    }

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

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

    public static void startService(String str) {
        SystemProperties.set("ctl.start", str);
    }

    public static void stopService(String str) {
        SystemProperties.set("ctl.stop", str);
    }

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

    /* JADX WARN: Type inference failed for: r0v0, types: [com.seewo.libsvendors.utils.NetShareHelper$1] */
    public void startHotspot() {
        loadCFGDriver();
        new Thread() { // from class: com.seewo.libsvendors.utils.NetShareHelper.1
            @Override // java.lang.Thread, java.lang.Runnable
            public void run() {
                synchronized (NetShareHelper.LOCK) {
                    NetShareHelper.this.startAPService();
                }
            }
        }.start();
    }

    private void loadCFGDriver() {
        if (isUseApProtocolV2()) {
            return;
        }
        startService("load_cfgdriver");
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void 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) {
                startService("startap_service");
            } else {
                startService("hostapd_init");
            }
            long jUptimeMillis = SystemClock.uptimeMillis();
            int i2 = 0;
            while (!isHostapdServiceRunning() && i2 <= INTERVAL) {
                try {
                    Thread.sleep(100L);
                } catch (InterruptedException e2) {
                    Log.e(TAG, e2.getMessage(), e2);
                }
                i2 += 100;
            }
            if (i2 <= INTERVAL) {
                Log.d(TAG, "start hostapd cost:" + (SystemClock.uptimeMillis() - jUptimeMillis));
                break;
            } else if (i <= 0) {
                break;
            }
        }
        if (isHostapdServiceRunning()) {
            sendBroadcast("com.seewo.ap.STARTED");
        } else {
            sendBroadcast("com.seewo.ap.FAILED");
        }
    }

    /* JADX WARN: Type inference failed for: r0v0, types: [com.seewo.libsvendors.utils.NetShareHelper$2] */
    public void stopHotspot() {
        new Thread() { // from class: com.seewo.libsvendors.utils.NetShareHelper.2
            @Override // java.lang.Thread, java.lang.Runnable
            public void run() {
                synchronized (NetShareHelper.LOCK) {
                    NetShareHelper.this.stopAPService();
                }
            }
        }.start();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void 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);
        }
        sendBroadcast("com.seewo.ap.STOPPED");
    }

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

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

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

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

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

        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 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 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 CTL_START = "ctl.start";
        public static final String CTL_STOP = "ctl.stop";
        public static final String DEFAULT_AP_PASSWD = "12345678";
        public static final String PERSIST_AP_PASSWD = "persist.sys.ap.passwd";
        public static final String PERSIST_AP_SSID = "persist.sys.ap.ssid";
        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_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_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() {
        }
    }
}
