use of android.net.wifi.WifiManager in project MDM-Android-Agent by wso2-attic.
the class WiFiConfig method removeWiFiConfigurationBySSID.
public boolean removeWiFiConfigurationBySSID(String ssid) {
WifiManager wifi = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
List<WifiConfiguration> item = wifi.getConfiguredNetworks();
for (int i = 0; i < item.size(); i++) {
WifiConfiguration config = item.get(0);
if (config.SSID.equals(ssid)) {
int networkId = config.networkId;
wifi.removeNetwork(networkId);
wifi.saveConfiguration();
}
}
return true;
}
use of android.net.wifi.WifiManager in project MDM-Android-Agent by wso2-attic.
the class WiFiConfig method readWEPConfig.
/**
* Read WEP Configuration Profile
*/
public boolean readWEPConfig(String ssid) {
WifiManager wifi = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
List<WifiConfiguration> item = wifi.getConfiguredNetworks();
int i = item.size();
Log.d("WifiPreference", "NO OF CONFIG " + i);
Iterator<WifiConfiguration> iter = item.iterator();
WifiConfiguration config = item.get(0);
Log.d("WifiPreference", "SSID" + config.SSID);
Log.d("WifiPreference", "PASSWORD" + config.preSharedKey);
Log.d("WifiPreference", "ALLOWED ALGORITHMS");
Log.d("WifiPreference", "LEAP" + config.allowedAuthAlgorithms.get(AuthAlgorithm.LEAP));
Log.d("WifiPreference", "OPEN" + config.allowedAuthAlgorithms.get(AuthAlgorithm.OPEN));
Log.d("WifiPreference", "SHARED" + config.allowedAuthAlgorithms.get(AuthAlgorithm.SHARED));
Log.d("WifiPreference", "GROUP CIPHERS");
Log.d("WifiPreference", "CCMP" + config.allowedGroupCiphers.get(GroupCipher.CCMP));
Log.d("WifiPreference", "TKIP" + config.allowedGroupCiphers.get(GroupCipher.TKIP));
Log.d("WifiPreference", "WEP104" + config.allowedGroupCiphers.get(GroupCipher.WEP104));
Log.d("WifiPreference", "WEP40" + config.allowedGroupCiphers.get(GroupCipher.WEP40));
Log.d("WifiPreference", "KEYMGMT");
Log.d("WifiPreference", "IEEE8021X" + config.allowedKeyManagement.get(KeyMgmt.IEEE8021X));
Log.d("WifiPreference", "NONE" + config.allowedKeyManagement.get(KeyMgmt.NONE));
Log.d("WifiPreference", "WPA_EAP" + config.allowedKeyManagement.get(KeyMgmt.WPA_EAP));
Log.d("WifiPreference", "WPA_PSK" + config.allowedKeyManagement.get(KeyMgmt.WPA_PSK));
Log.d("WifiPreference", "PairWiseCipher");
Log.d("WifiPreference", "CCMP" + config.allowedPairwiseCiphers.get(PairwiseCipher.CCMP));
Log.d("WifiPreference", "NONE" + config.allowedPairwiseCiphers.get(PairwiseCipher.NONE));
Log.d("WifiPreference", "TKIP" + config.allowedPairwiseCiphers.get(PairwiseCipher.TKIP));
Log.d("WifiPreference", "Protocols");
Log.d("WifiPreference", "RSN" + config.allowedProtocols.get(Protocol.RSN));
Log.d("WifiPreference", "WPA" + config.allowedProtocols.get(Protocol.WPA));
Log.d("WifiPreference", "WEP Key Strings");
String[] wepKeys = config.wepKeys;
Log.d("WifiPreference", "WEP KEY 0" + wepKeys[0]);
Log.d("WifiPreference", "WEP KEY 1" + wepKeys[1]);
Log.d("WifiPreference", "WEP KEY 2" + wepKeys[2]);
Log.d("WifiPreference", "WEP KEY 3" + wepKeys[3]);
if (config.SSID.equals(ssid)) {
return true;
} else {
return false;
}
}
use of android.net.wifi.WifiManager in project MDM-Android-Agent by wso2-attic.
the class WiFiConfig method saveWEPConfig.
/**
* Saves a WEP WIFI Configuration Profile
* @params SSID, PASSWORD
* - WiFi SSID and PASSWORD should be passed in.
*/
public boolean saveWEPConfig(String SSID, String PASSWORD) {
WifiManager wifi = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
WifiConfiguration wc = new WifiConfiguration();
// IMP! This should be in Quotes!!
wc.SSID = "\"" + SSID + "\"";
wc.hiddenSSID = true;
wc.status = WifiConfiguration.Status.DISABLED;
wc.priority = 40;
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
wc.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
wc.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
// This is the WEP Password
wc.wepKeys[0] = "\"" + PASSWORD + "\"";
wc.wepTxKeyIndex = 0;
WifiManager wifiManag = (WifiManager) this.context.getSystemService(this.context.WIFI_SERVICE);
boolean res1 = wifiManag.setWifiEnabled(true);
int res = wifi.addNetwork(wc);
Log.d("WifiPreference", "add Network returned " + res);
boolean saved = wifi.saveConfiguration();
Log.d("WifiPreference", "saveConfiguration returned " + saved);
boolean b = wifi.enableNetwork(res, true);
Log.d("WifiPreference", "enableNetwork returned " + b);
return saved;
}
use of android.net.wifi.WifiManager in project android_packages_apps_Settings by DirtyUnicorns.
the class WifiDialogActivity method onForget.
@Override
public void onForget(WifiDialog dialog) {
final WifiManager wifiManager = getSystemService(WifiManager.class);
final AccessPoint accessPoint = dialog.getController().getAccessPoint();
if (accessPoint != null) {
if (!accessPoint.isSaved()) {
if (accessPoint.getNetworkInfo() != null && accessPoint.getNetworkInfo().getState() != NetworkInfo.State.DISCONNECTED) {
// Network is active but has no network ID - must be ephemeral.
wifiManager.disableEphemeralNetwork(AccessPoint.convertToQuotedString(accessPoint.getSsidStr()));
} else {
// Should not happen, but a monkey seems to trigger it
Log.e(TAG, "Failed to forget invalid network " + accessPoint.getConfig());
}
} else {
wifiManager.forget(accessPoint.getConfig().networkId, null);
}
}
Intent resultData = new Intent();
if (accessPoint != null) {
Bundle accessPointState = new Bundle();
accessPoint.saveWifiState(accessPointState);
resultData.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
}
setResult(RESULT_FORGET);
finish();
}
use of android.net.wifi.WifiManager in project android_packages_apps_Settings by DirtyUnicorns.
the class Utils method getWifiIpAddresses.
/**
* Returns the WIFI IP Addresses, if any, taking into account IPv4 and IPv6 style addresses.
* @param context the application context
* @return the formatted and newline-separated IP addresses, or null if none.
*/
public static String getWifiIpAddresses(Context context) {
WifiManager wifiManager = context.getSystemService(WifiManager.class);
Network currentNetwork = wifiManager.getCurrentNetwork();
if (currentNetwork != null) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
LinkProperties prop = cm.getLinkProperties(currentNetwork);
return formatIpAddresses(prop);
}
return null;
}
Aggregations