package a.b.a.k;

import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import androidx.collection.ArrayMap;
import java.io.Closeable;
import java.util.Map;

public class e {

    /* renamed from: a  reason: collision with root package name */
    private static final String f47a = "WifiUtils";
    public static final int b = 1;
    public static final int c = 14;
    public static final int d = 36;
    public static final int e = 165;
    private static final ArrayMap<Integer, Integer> f = new a();
    private static final ArrayMap<Integer, Integer> g = new b();

    public class a extends ArrayMap<Integer, Integer> {
        public a() {
            put(1, 2412);
            put(2, 2417);
            put(3, 2422);
            put(4, 2427);
            put(5, 2432);
            put(6, 2437);
            put(7, 2442);
            put(8, 2447);
            put(9, 2452);
            put(10, 2457);
            put(11, 2462);
            put(12, 2467);
            put(13, 2472);
            put(14, 2484);
            put(36, 5180);
            put(40, 5200);
            put(44, 5220);
            put(48, 5240);
            put(52, 5260);
            put(56, 5280);
            put(60, 5300);
            put(64, 5320);
            put(100, 5500);
            put(104, 5520);
            put(108, 5540);
            put(112, 5560);
            put(116, 5580);
            put(120, 5600);
            put(124, 5620);
            put(128, 5640);
            put(132, 5660);
            put(136, 5680);
            put(140, 5700);
            put(149, 5745);
            put(153, 5765);
            put(157, 5785);
            put(161, 5805);
            put(Integer.valueOf((int) e.e), 5825);
        }
    }

    public class b extends ArrayMap<Integer, Integer> {
        public b() {
            put(1, 2412);
            put(36, 5180);
        }
    }

    public static int a(int i) {
        for (Map.Entry<Integer, Integer> entry : g.entrySet()) {
            if (entry.getValue().intValue() == i) {
                return entry.getKey().intValue();
            }
        }
        return 0;
    }

    public static int a(int i, int i2, WifiManager wifiManager, boolean z) {
        StringBuilder sb;
        String str;
        int a2;
        if ((i2 >= 36 || i == 0) && g.containsKey(Integer.valueOf(i2))) {
            sb = new StringBuilder();
            str = "Selected wifi phone channel: ";
        } else {
            i2 = 0;
            if (z && (a2 = a(wifiManager)) != -1 && ((a2 > 5000 && i == 1) || (a2 < 5000 && i == 0))) {
                i2 = a(a2);
            }
            if (i2 > 0) {
                sb = new StringBuilder();
                str = "Selected wifi sta channel: ";
            } else {
                i2 = 14;
                int i3 = e;
                for (Integer num : g.keySet()) {
                    int intValue = num.intValue();
                    if (intValue >= 36) {
                        i3 = Math.min(intValue, i3);
                    } else if (intValue >= 1) {
                        i2 = Math.min(intValue, i2);
                    }
                }
                if (i == 1) {
                    i2 = i3;
                }
                sb = new StringBuilder();
                str = "Selected wifi min channel: ";
            }
        }
        a.a.a.b.c(f47a, sb.append(str).append(i2).toString());
        return i2;
    }

    public static int a(WifiManager wifiManager) {
        WifiInfo connectionInfo = wifiManager.getConnectionInfo();
        int i = -1;
        if (connectionInfo != null) {
            if (Build.VERSION.SDK_INT >= 21) {
                i = connectionInfo.getFrequency();
            } else {
                for (ScanResult scanResult : wifiManager.getScanResults()) {
                    if (scanResult.BSSID.equalsIgnoreCase(connectionInfo.getBSSID())) {
                        i = scanResult.frequency;
                    }
                }
            }
        }
        a.a.a.b.c(f47a, "Current AP frequency: " + i);
        return i;
    }

    public static void a(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (Exception unused) {
            }
        }
    }

    public static void a(int[] iArr) {
        g.clear();
        boolean z = false;
        boolean z2 = false;
        for (int i : iArr) {
            ArrayMap<Integer, Integer> arrayMap = f;
            if (arrayMap.containsKey(Integer.valueOf(i))) {
                g.put(Integer.valueOf(i), arrayMap.get(Integer.valueOf(i)));
            }
            if (i >= 36) {
                z2 = true;
            } else {
                z = true;
            }
        }
        if (!z) {
            g.put(1, 2412);
        }
        if (!z2) {
            g.put(36, 5180);
        }
        a.a.a.b.c(f47a, "updateWifiChannelMaps: " + g.toString());
    }

    public static int b(int i) {
        ArrayMap<Integer, Integer> arrayMap = f;
        if (arrayMap.containsKey(Integer.valueOf(i))) {
            return arrayMap.get(Integer.valueOf(i)).intValue();
        }
        return 0;
    }

    private static boolean b(WifiManager wifiManager) {
        boolean is5GHzBandSupported = wifiManager.is5GHzBandSupported();
        a.a.a.b.c(f47a, "System 5GHz supported=" + is5GHzBandSupported);
        return is5GHzBandSupported;
    }

    private static boolean c(int i) {
        ArrayMap<Integer, Integer> arrayMap = f;
        if (arrayMap.containsKey(Integer.valueOf(i))) {
            return arrayMap.get(Integer.valueOf(i)).intValue() >= 5000;
        }
        a.a.a.b.e(f47a, "Channel: " + i + " isn't recognized channel, returning false.");
        return false;
    }

    public static boolean c(WifiManager wifiManager) {
        return b(wifiManager);
    }
}
