/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  android.content.Context
 *  android.net.DhcpInfo
 *  android.net.wifi.ScanResult
 *  android.net.wifi.WifiConfiguration
 *  android.net.wifi.WifiInfo
 *  android.net.wifi.WifiManager
 *  android.text.format.Formatter
 *  java.lang.Exception
 *  java.lang.Object
 *  java.lang.String
 *  java.util.Iterator
 *  java.util.List
 */
package com.xinli.portalclient;

import android.content.Context;
import android.net.DhcpInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.text.format.Formatter;
import com.google.code.microlog4android.Logger;
import java.util.Iterator;
import java.util.List;

public class WifiManagerUtil {
    private static final String TAG = "wifi";
    Logger logger;
    Context mContext;
    int mNetworkID;
    String mSSID;
    WifiConfiguration mTargetWifiCfg;
    List<WifiConfiguration> mWifiHotSpotLists;
    WifiInfo mWifiInfo;
    WifiManager mWifiManager;
    List<ScanResult> mWifiScanResultLists;

    public WifiManagerUtil(Context context, Logger logger) {
        this.mContext = context;
        this.logger = logger;
        this.logger.debug(" Construct...");
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    public void closeWifi() {
        if (!this.mWifiManager.isWifiEnabled()) return;
        if (this.mWifiManager.setWifiEnabled(false)) {
            this.logger.debug(" disableWifiEnabled...success");
            return;
        }
        this.logger.debug(" disableWifiEnabled...failure");
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    public void connectToTargetWifi(String string2, String string3, int n) {
        void var10_4 = this;
        synchronized (var10_4) {
            try {
                this.mSSID = string2;
                if (!this.isScanTargetWifi()) {
                    this.logger.debug(" connectToTargetWifi fail=======");
                    do {
                        return;
                        break;
                    } while (true);
                }
                this.logger.debug(" connectToTargetWifi success=======");
                this.logger.debug(" connectToTargetWifi step5=====password==" + string3 + "==ssid==" + string2);
                this.mTargetWifiCfg = this.createWifiCfg(string2, string3, n);
                this.logger.debug(" connectToTargetWifi step6=====");
                this.mNetworkID = this.mWifiManager.addNetwork(this.mTargetWifiCfg);
                this.logger.debug("connectToTargetWifi==addNetwork:mTargetWifiCfg->" + (Object)this.mTargetWifiCfg);
                this.logger.debug("connectToTargetWifi==addNetwork:mNetworkID->" + this.mNetworkID);
                this.mWifiManager.enableNetwork(this.mNetworkID, true);
                this.logger.debug(" connectToTargetWifi step7=====");
                this.mWifiManager.reassociate();
                this.logger.debug(" connectToTargetWifi step8=====");
                this.mWifiManager.reconnect();
                this.logger.debug(" connectToTargetWifi step9=====");
                DhcpInfo dhcpInfo = this.mWifiManager.getDhcpInfo();
                this.logger.debug(" connectToTargetWifi step9===dhcpinfo.ipAddress==" + Formatter.formatIpAddress((int)dhcpInfo.ipAddress));
                return;
            }
            catch (Exception var5_6) {
                var5_6.printStackTrace();
                this.logger.debug("connectToTargetWifi Exception:" + var5_6.toString());
                return;
            }
            finally {
            }
        }
    }

    /*
     * Exception decompiling
     */
    public WifiConfiguration createWifiCfg(String var1, String var2_3, int var3_2) {
        // This method has failed to decompile.  When submitting a bug report, please provide this stack trace, and (if you hold appropriate legal rights) the relevant class file.
        // org.benf.cfr.reader.util.ConfusedCFRException: First case is not immediately after switch.
        // org.benf.cfr.reader.bytecode.analysis.opgraph.op3rewriters.SwitchReplacer.examineSwitchContiguity(SwitchReplacer.java:366)
        // org.benf.cfr.reader.bytecode.analysis.opgraph.op3rewriters.SwitchReplacer.replaceRawSwitches(SwitchReplacer.java:65)
        // org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisInner(CodeAnalyser.java:422)
        // org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisOrWrapFail(CodeAnalyser.java:220)
        // org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysis(CodeAnalyser.java:165)
        // org.benf.cfr.reader.entities.attributes.AttributeCode.analyse(AttributeCode.java:91)
        // org.benf.cfr.reader.entities.Method.analyse(Method.java:354)
        // org.benf.cfr.reader.entities.ClassFile.analyseMid(ClassFile.java:751)
        // org.benf.cfr.reader.entities.ClassFile.analyseTop(ClassFile.java:683)
        // org.benf.cfr.reader.Main.doJar(Main.java:128)
        // com.njlabs.showjava.processor.JavaExtractor$1.run(JavaExtractor.java:84)
        // java.lang.Thread.run(Thread.java:818)
        throw new IllegalStateException("Decompilation failed");
    }

    public List<WifiConfiguration> getWifiAllHotSpot() {
        List list = this.mWifiManager.getConfiguredNetworks();
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            WifiConfiguration wifiConfiguration = (WifiConfiguration)iterator.next();
            this.logger.debug(" wifiConfiguration.SSID(hotSpot):" + wifiConfiguration.SSID);
        }
        return list;
    }

    public WifiInfo getWifiInfo() {
        if (this.mWifiManager == null) {
            this.mWifiManager = (WifiManager)this.mContext.getSystemService("wifi");
        }
        return this.mWifiManager.getConnectionInfo();
    }

    public List<ScanResult> getWifiScanResult() {
        this.logger.debug(" connectToTargetWifi step2=======");
        List list = this.mWifiManager.getScanResults();
        this.logger.debug(" connectToTargetWifi step3=======");
        return list;
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public boolean isConfigHotSpot() {
        try {
            this.logger.debug(" connectToTargetWifi step4=======");
            this.mWifiHotSpotLists = this.getWifiAllHotSpot();
            Iterator iterator = this.mWifiHotSpotLists.iterator();
            do {
                if (!iterator.hasNext()) {
                    return false;
                }
                WifiConfiguration wifiConfiguration = (WifiConfiguration)iterator.next();
                this.logger.debug(" connectToTargetWifi wifiConfiguration.SSID=======" + wifiConfiguration.SSID + "==mSSID==" + this.mSSID);
            } while (!wifiConfiguration.SSID.equals((Object)("\"" + this.mSSID + "\"")));
            this.logger.debug("before have cfg this hotspot:" + wifiConfiguration.SSID);
            return true;
        }
        catch (Exception var1_3) {
            var1_3.printStackTrace();
            this.logger.debug("isConfigHotSpot Exception:" + var1_3.toString());
            return false;
        }
    }

    public WifiConfiguration isExistWifiConfiguration(String string2) {
        WifiConfiguration wifiConfiguration;
        this.mWifiHotSpotLists = this.getWifiAllHotSpot();
        Iterator iterator = this.mWifiHotSpotLists.iterator();
        do {
            if (!iterator.hasNext()) {
                return null;
            }
            wifiConfiguration = (WifiConfiguration)iterator.next();
            this.logger.debug(" connectToTargetWifi===wifiConfiguration.SSID:" + wifiConfiguration.SSID + "==ssid==" + string2);
        } while (!wifiConfiguration.SSID.equals((Object)("\"" + string2 + "\"")));
        return wifiConfiguration;
    }

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public boolean isScanTargetWifi() {
        try {
            this.logger.debug(" connectToTargetWifi step1=======");
            this.mWifiScanResultLists = this.getWifiScanResult();
            if (this.mWifiScanResultLists == null) return false;
            {
                boolean bl;
                Iterator iterator = this.mWifiScanResultLists.iterator();
                do {
                    if (!iterator.hasNext()) {
                        return false;
                    }
                    ScanResult scanResult = (ScanResult)iterator.next();
                    this.logger.debug(" connectToTargetWifi====wifiScanResultList.SSID:" + scanResult.SSID + "==mSSID==" + this.mSSID);
                } while (!(bl = scanResult.SSID.equals((Object)this.mSSID)));
                return true;
            }
        }
        catch (Exception var1_4) {
            var1_4.printStackTrace();
            this.logger.debug("isScanTargetWifi Exception:" + var1_4.toString());
        }
        return false;
    }

    public void openWifi() {
        this.mWifiManager = (WifiManager)this.mContext.getSystemService("wifi");
        if (!this.mWifiManager.isWifiEnabled()) {
            if (this.mWifiManager.setWifiEnabled(true)) {
                this.logger.debug(" setWifiEnabled...success");
                return;
            }
            this.logger.debug(" setWifiEnabled...failure");
            return;
        }
        this.logger.debug("before have setWifiEnabled ...");
    }
}

