package com.dowse.base.manager;

import android.content.Context;
import android.net.wifi.WifiInfo;
import com.dowse.base.data.DSWIFIAPInfo;
import com.dowse.base.data.DSWIFIInfo;
import com.dowse.base.log.DSLog;
import com.dowse.base.util.ContextUtil;
import com.dowse.base.util.WifiUtil;

/* loaded from: ds_base_2.0.9_23030112.aar:classes.jar:com/dowse/base/manager/DSWIFIManager.class */
public class DSWIFIManager {
    private static final String TAG = "DSWIFIManager";
    private Context mContext;

    public static DSWIFIManager getInstance() {
        return DSWIFIManagerHolder.instance;
    }

    /* loaded from: ds_base_2.0.9_23030112.aar:classes.jar:com/dowse/base/manager/DSWIFIManager$DSWIFIManagerHolder.class */
    private static class DSWIFIManagerHolder {
        public static final DSWIFIManager instance = new DSWIFIManager();

        private DSWIFIManagerHolder() {
        }
    }

    private DSWIFIManager() {
        this.mContext = null;
        this.mContext = ContextUtil.getApplication();
    }

    public DSWIFIInfo getWifiInfo() {
        DSWIFIInfo dswifiInfo = new DSWIFIInfo();
        dswifiInfo.setEnable(0);
        dswifiInfo.setIp("");
        dswifiInfo.setSsid("");
        dswifiInfo.setPassword("");
        if (this.mContext != null) {
            if (WifiUtil.isWifiOpen(this.mContext)) {
                dswifiInfo.setEnable(1);
                WifiInfo wifiInfo = WifiUtil.getWifInfo(this.mContext);
                if (wifiInfo != null) {
                    dswifiInfo.setSsid(wifiInfo.getSSID());
                    dswifiInfo.setIp(WifiUtil.intToIp(wifiInfo.getIpAddress()));
                }
            }
        } else {
            DSLog.e(TAG, "getWifiInfo mContext is null");
        }
        return dswifiInfo;
    }

    public boolean setWifiInfo(DSWIFIInfo dswifiInfo) {
        boolean result;
        DSLog.d(TAG, "setWifiInfo dswifiInfo=" + dswifiInfo.toString());
        if (this.mContext != null) {
            if (dswifiInfo.getEnable() == 1) {
                WifiUtil.connectWIFI(this.mContext, dswifiInfo.getSsid(), dswifiInfo.getPassword(), new WifiUtil.CallBack() { // from class: com.dowse.base.manager.DSWIFIManager.1
                    @Override // com.dowse.base.util.WifiUtil.CallBack
                    public void connnectResult(boolean isSuccess) {
                        DSLog.d(DSWIFIManager.TAG, "onConnectWiFi isSuccess=" + isSuccess);
                    }
                });
                result = true;
            } else {
                WifiUtil.disconnectWIFI(this.mContext);
                result = true;
            }
        } else {
            DSLog.e(TAG, "setWifiInfo mContext is null");
            result = false;
        }
        return result;
    }

    public DSWIFIAPInfo getWiFiAPInfo() {
        DSWIFIAPInfo dswifiapInfo = new DSWIFIAPInfo();
        dswifiapInfo.setEnable(0);
        dswifiapInfo.setStatus(0);
        dswifiapInfo.setSsid("");
        dswifiapInfo.setPassword("");
        if (this.mContext != null) {
            if (WifiUtil.isWifiApEnabled(this.mContext)) {
                dswifiapInfo.setEnable(1);
            }
            dswifiapInfo.setSsid(WifiUtil.getApSSID(this.mContext));
            dswifiapInfo.setStatus(WifiUtil.getWifiApState(this.mContext));
        } else {
            DSLog.e(TAG, "getWiFiAPInfo mContext is null");
        }
        return dswifiapInfo;
    }

    public boolean setWiFiAPInfo(DSWIFIAPInfo info) {
        boolean result;
        DSLog.d(TAG, "setWiFiAPInfo DSWIFIAPInfo info=" + info.toString());
        if (info.getEnable() == 1) {
            WifiUtil.disableAp(this.mContext);
            try {
                Thread.sleep(500L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            WifiUtil.enableAP(this.mContext, info.getSsid(), info.getPassword());
            result = true;
        } else {
            WifiUtil.disableAp(this.mContext);
            result = true;
        }
        return result;
    }
}
