Skip to content

Commit

Permalink
Make security showing up correctly on Android 6 (see #35)
Browse files Browse the repository at this point in the history
  • Loading branch information
hypery2k committed May 27, 2016
1 parent 0fdd969 commit b4f98f6
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/android/com/mady/wifi/api/WifiHotSpots.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.util.Log;

import java.io.*;
Expand Down Expand Up @@ -440,7 +441,7 @@ public boolean setHotSpot(String SSID, String mode, String passWord) {
/*
* Before setting the HotSpot with specific Id delete the default AP Name.
*/

String BACKSLASH = "\"";
List<WifiConfiguration> list = mWifiManager.getConfiguredNetworks();
if (list != null) {
for (WifiConfiguration i : list) {
Expand Down Expand Up @@ -484,28 +485,30 @@ public boolean setHotSpot(String SSID, String mode, String passWord) {
netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
} else {
if (passWord == "" && mode.equalsIgnoreCase("WPA")) {
netConfig.SSID = SSID;
netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
netConfig.SSID = SSID;
netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
netConfig.SSID = SSID;
netConfig.preSharedKey = passWord;
netConfig.hiddenSSID = false;
netConfig.status = WifiConfiguration.Status.ENABLED;
netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP + 1) {
netConfig.allowedKeyManagement.set(4); // WPA2_PSK on Android 6!
} else {
netConfig.SSID = SSID;
netConfig.preSharedKey = passWord;
netConfig.hiddenSSID = false;
netConfig.status = WifiConfiguration.Status.ENABLED;
netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
netConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
}
netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
netConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);

}
try {
mMethod.invoke(mWifiManager, netConfig, true);
mWifiManager.disconnect();
mWifiManager.reconnect();
mWifiManager.saveConfiguration();
Log.v(LOG_TAG, "Successfully created hotspot");
return true;
Expand Down

0 comments on commit b4f98f6

Please sign in to comment.