use of android.net.wifi.WifiConfiguration in project routerkeygenAndroid by routerkeygen.
the class Wifi method getWifiConfiguration.
private static WifiConfiguration getWifiConfiguration(final WifiManager wifiMgr, final ScanResult hotspot, String hotspotSecurity) {
final String ssid = convertToQuotedString(hotspot.SSID);
if (ssid.length() == 0) {
return null;
}
final String bssid = hotspot.BSSID;
if (bssid == null) {
return null;
}
if (hotspotSecurity == null) {
hotspotSecurity = ConfigSec.getScanResultSecurity(hotspot);
}
final List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks();
if (configurations == null) {
return null;
}
for (final WifiConfiguration config : configurations) {
if (config.SSID == null || !ssid.equals(config.SSID)) {
continue;
}
if (config.BSSID == null || bssid.equals(config.BSSID)) {
final String configSecurity = ConfigSec.getWifiConfigurationSecurity(config);
if (hotspotSecurity.equals(configSecurity)) {
return config;
}
}
}
return null;
}
use of android.net.wifi.WifiConfiguration in project platform_frameworks_base by android.
the class NetworkPolicyManagerShellCommand method setMeteredWifiNetwork.
private int setMeteredWifiNetwork() throws RemoteException {
final PrintWriter pw = getOutPrintWriter();
final String id = getNextArg();
if (id == null) {
pw.println("Error: didn't specify ID");
return -1;
}
final String arg = getNextArg();
if (arg == null) {
pw.println("Error: didn't specify BOOLEAN");
return -1;
}
final boolean metered = Boolean.valueOf(arg);
final NetworkPolicy[] policies = mInterface.getNetworkPolicies(null);
boolean changed = false;
// First try to find a policy with such id
for (NetworkPolicy policy : policies) {
if (policy.template.isMatchRuleMobile() || policy.metered == metered) {
continue;
}
final String networkId = getNetworkId(policy);
if (id.equals(networkId)) {
Log.i(TAG, "Changing " + networkId + " metered status to " + metered);
policy.metered = metered;
changed = true;
}
}
if (changed) {
mInterface.setNetworkPolicies(policies);
return 0;
}
// Policy not found: check if there is a saved wi-fi with such id.
for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) {
final String ssid = removeDoubleQuotes(config.SSID);
if (id.equals(ssid)) {
final NetworkPolicy policy = newPolicy(ssid);
policy.metered = true;
Log.i(TAG, "Creating new policy for " + ssid + ": " + policy);
final NetworkPolicy[] newPolicies = new NetworkPolicy[policies.length + 1];
System.arraycopy(policies, 0, newPolicies, 0, policies.length);
newPolicies[newPolicies.length - 1] = policy;
mInterface.setNetworkPolicies(newPolicies);
}
}
return 0;
}
use of android.net.wifi.WifiConfiguration in project platform_frameworks_base by android.
the class NetworkPolicyManagerShellCommand method getWifiPolicies.
private List<NetworkPolicy> getWifiPolicies() throws RemoteException {
// First gets a list of saved wi-fi networks.
final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
final int size = configs != null ? configs.size() : 0;
final Set<String> ssids = new HashSet<>(size);
if (configs != null) {
for (WifiConfiguration config : configs) {
ssids.add(removeDoubleQuotes(config.SSID));
}
}
// Then gets the saved policies.
final NetworkPolicy[] policies = mInterface.getNetworkPolicies(null);
final List<NetworkPolicy> wifiPolicies = new ArrayList<NetworkPolicy>(policies.length);
for (NetworkPolicy policy : policies) {
if (!policy.template.isMatchRuleMobile()) {
wifiPolicies.add(policy);
final String netId = getNetworkId(policy);
ssids.remove(netId);
}
}
// Finally, creates new default policies for saved WI-FIs not policied yet.
for (String ssid : ssids) {
final NetworkPolicy policy = newPolicy(ssid);
wifiPolicies.add(policy);
}
return wifiPolicies;
}
use of android.net.wifi.WifiConfiguration in project platform_frameworks_base by android.
the class WifiConfigurationHelper method createGenericConfig.
/**
* Create a generic {@link WifiConfiguration} used by the other create methods.
*/
private static WifiConfiguration createGenericConfig(String ssid) {
WifiConfiguration config = new WifiConfiguration();
config.SSID = quotedString(ssid);
config.setIpAssignment(IpAssignment.DHCP);
config.setProxySettings(ProxySettings.NONE);
return config;
}
use of android.net.wifi.WifiConfiguration in project platform_frameworks_base by android.
the class WifiConfigurationHelper method createWepConfig.
/**
* Create a {@link WifiConfiguration} for a WEP secured network
*
* @param ssid The SSID of the wifi network
* @param password Either a 10, 26, or 58 character hex string or the plain text password
* @return The {@link WifiConfiguration}
*/
public static WifiConfiguration createWepConfig(String ssid, String password) {
WifiConfiguration config = createGenericConfig(ssid);
if (isHex(password, 10) || isHex(password, 26) || isHex(password, 58)) {
config.wepKeys[0] = password;
} else {
config.wepKeys[0] = quotedString(password);
}
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
return config;
}
Aggregations