package a.b.a.j;

import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Build;
import java.lang.reflect.Method;

public class a {
    private static final String b = "WifiApConfig";
    private static final int c = 2;
    private static final int d = 1;
    private static final int e = 4;

    /* renamed from: a  reason: collision with root package name */
    private final Object f42a;

    public static class b {

        /* renamed from: a  reason: collision with root package name */
        private WifiManager f43a;
        private Object b;
        private Object c;
        private Method d;
        private Method e;
        private Method f;
        private Method g;

        public b() {
            try {
                int i = Build.VERSION.SDK_INT;
                if (i >= 28 && i < 30) {
                    this.b = Class.forName("android.net.wifi.WifiConfiguration").newInstance();
                } else if (i >= 30) {
                    Class<?> cls = Class.forName("android.net.wifi.SoftApConfiguration$Builder");
                    this.d = cls.getMethod("setSsid", String.class);
                    Class<?> cls2 = Integer.TYPE;
                    this.e = cls.getMethod("setPassphrase", String.class, cls2);
                    this.f = cls.getMethod("setChannel", cls2, cls2);
                    this.g = cls.getMethod("setBand", cls2);
                    this.c = cls.newInstance();
                } else {
                    throw new IllegalArgumentException("the version less than Android P don't support");
                }
            } catch (Exception e2) {
                a.a.a.b.b(a.b, "WifiApConfig constructor method error: ", e2);
            }
        }

        public b(WifiManager wifiManager) {
            Object obj;
            this.f43a = wifiManager;
            try {
                int i = Build.VERSION.SDK_INT;
                if (i >= 28 && i < 30) {
                    obj = WifiManager.class.getMethod("getWifiApConfiguration", new Class[0]).invoke(this.f43a, new Object[0]);
                } else if (i >= 30) {
                    obj = WifiManager.class.getMethod("getSoftApConfiguration", new Class[0]).invoke(this.f43a, new Object[0]);
                } else {
                    throw new IllegalArgumentException("the version less than Android P don't support");
                }
                this.b = obj;
            } catch (Exception e2) {
                a.a.a.b.b(a.b, "WifiApConfig constructor method error: ", e2);
            }
        }

        public b a(int i) {
            try {
                int i2 = Build.VERSION.SDK_INT;
                if (i2 < 28 || i2 >= 30) {
                    if (i2 >= 30) {
                        this.g.invoke(this.c, Integer.valueOf(i));
                    }
                    return this;
                }
                Object obj = this.b;
                if (obj != null) {
                    WifiConfiguration wifiConfiguration = (WifiConfiguration) obj;
                    wifiConfiguration.getClass().getDeclaredField("apBand").set(wifiConfiguration, Integer.valueOf(i));
                }
                return this;
            } catch (Exception e2) {
                a.a.a.b.b(a.b, "setSsid error: ", e2);
            }
        }

        public b a(String str) {
            int i = Build.VERSION.SDK_INT;
            if (i >= 28 && i < 30) {
                Object obj = this.b;
                if (obj != null) {
                    WifiConfiguration wifiConfiguration = (WifiConfiguration) obj;
                    wifiConfiguration.preSharedKey = str;
                    wifiConfiguration.allowedKeyManagement.set(4);
                }
            } else if (i >= 30) {
                try {
                    this.e.invoke(this.c, str, 1);
                } catch (Exception e2) {
                    a.a.a.b.b(a.b, "setSsid error: ", e2);
                }
            }
            return this;
        }

        public a a() {
            if (this.b == null && Build.VERSION.SDK_INT >= 30) {
                try {
                    this.b = Class.forName("android.net.wifi.SoftApConfiguration$Builder").getMethod("build", new Class[0]).invoke(this.c, new Object[0]);
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }
            return new a(this);
        }

        public b b(int i) {
            try {
                int i2 = Build.VERSION.SDK_INT;
                if (i2 < 28 || i2 >= 30) {
                    if (i2 >= 30) {
                        this.f.invoke(this.c, Integer.valueOf(i), 2);
                    }
                    return this;
                }
                Object obj = this.b;
                if (obj != null) {
                    WifiConfiguration wifiConfiguration = (WifiConfiguration) obj;
                    wifiConfiguration.getClass().getDeclaredField("apChannel").set(wifiConfiguration, Integer.valueOf(i));
                }
                return this;
            } catch (Exception e2) {
                a.a.a.b.b(a.b, "setSsid error: ", e2);
            }
        }

        public b b(String str) {
            int i = Build.VERSION.SDK_INT;
            if (i >= 28 && i < 30) {
                Object obj = this.b;
                if (obj != null) {
                    ((WifiConfiguration) obj).SSID = str;
                }
            } else if (i >= 30) {
                try {
                    this.d.invoke(this.c, str);
                } catch (Exception e2) {
                    a.a.a.b.b(a.b, "setSsid error: ", e2);
                }
            }
            return this;
        }
    }

    private a(b bVar) {
        this.f42a = bVar.b;
    }

    public int a() {
        int i = Build.VERSION.SDK_INT;
        if (i < 28 || i >= 30) {
            if (i < 30) {
                a.a.a.b.b(b, "the version less than Android P don't support");
            } else if (this.f42a instanceof SoftApConfiguration) {
                return ((Integer) SoftApConfiguration.class.getDeclaredMethod("getBand", new Class[0]).invoke(this.f42a, new Object[0])).intValue();
            }
        } else if (this.f42a instanceof WifiConfiguration) {
            try {
                return ((Integer) WifiConfiguration.class.getDeclaredField("apBand").get(this.f42a)).intValue();
            } catch (Exception e2) {
                a.a.a.b.b(b, "apBand filed error: ", e2);
            }
        }
        return 0;
    }

    public int b() {
        int i = Build.VERSION.SDK_INT;
        if (i < 28 || i >= 30) {
            if (i < 30) {
                a.a.a.b.b(b, "the version less than Android P don't support");
            } else if (this.f42a instanceof SoftApConfiguration) {
                return ((Integer) SoftApConfiguration.class.getDeclaredMethod("getChannel", new Class[0]).invoke(this.f42a, new Object[0])).intValue();
            }
        } else if (this.f42a instanceof WifiConfiguration) {
            try {
                return ((Integer) WifiConfiguration.class.getDeclaredField("apChannel").get(this.f42a)).intValue();
            } catch (Exception e2) {
                a.a.a.b.b(b, "apChannel filed error: ", e2);
            }
        }
        return 0;
    }

    public Object c() {
        return this.f42a;
    }

    public String d() {
        int i = Build.VERSION.SDK_INT;
        if (i >= 28 && i < 30) {
            Object obj = this.f42a;
            if (obj instanceof WifiConfiguration) {
                return ((WifiConfiguration) obj).preSharedKey;
            }
            return null;
        } else if (i >= 30) {
            Object obj2 = this.f42a;
            if (obj2 instanceof SoftApConfiguration) {
                return ((SoftApConfiguration) obj2).getPassphrase();
            }
            return null;
        } else {
            a.a.a.b.b(b, "the version less than Android P don't support");
            return null;
        }
    }

    public String e() {
        int i = Build.VERSION.SDK_INT;
        if (i >= 28 && i < 30) {
            Object obj = this.f42a;
            if (obj instanceof WifiConfiguration) {
                return ((WifiConfiguration) obj).SSID;
            }
            return null;
        } else if (i >= 30) {
            Object obj2 = this.f42a;
            if (obj2 instanceof SoftApConfiguration) {
                return ((SoftApConfiguration) obj2).getSsid();
            }
            return null;
        } else {
            a.a.a.b.b(b, "the version less than Android P don't support");
            return null;
        }
    }

    public String toString() {
        return this.f42a.toString();
    }
}
