use of android.net.wifi.WifiConfiguration in project android_frameworks_base by DirtyUnicorns.
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 android_frameworks_base by DirtyUnicorns.
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 android_frameworks_base by DirtyUnicorns.
the class AccessPoint method generateOpenNetworkConfig.
/**
* Generate and save a default wifiConfiguration with common values.
* Can only be called for unsecured networks.
*/
public void generateOpenNetworkConfig() {
if (security != SECURITY_NONE)
throw new IllegalStateException();
if (mConfig != null)
return;
mConfig = new WifiConfiguration();
mConfig.SSID = AccessPoint.convertToQuotedString(ssid);
mConfig.allowedKeyManagement.set(KeyMgmt.NONE);
}
use of android.net.wifi.WifiConfiguration in project android_frameworks_base by DirtyUnicorns.
the class WifiTracker method updateNetworkInfo.
private void updateNetworkInfo(NetworkInfo networkInfo) {
/* sticky broadcasts can call this when wifi is disabled */
if (!mWifiManager.isWifiEnabled()) {
mMainHandler.sendEmptyMessage(MainHandler.MSG_PAUSE_SCANNING);
return;
}
if (networkInfo != null && networkInfo.getDetailedState() == DetailedState.OBTAINING_IPADDR) {
mMainHandler.sendEmptyMessage(MainHandler.MSG_PAUSE_SCANNING);
} else {
mMainHandler.sendEmptyMessage(MainHandler.MSG_RESUME_SCANNING);
}
if (networkInfo != null) {
mLastNetworkInfo = networkInfo;
}
WifiConfiguration connectionConfig = null;
mLastInfo = mWifiManager.getConnectionInfo();
if (mLastInfo != null) {
connectionConfig = getWifiConfigurationForNetworkId(mLastInfo.getNetworkId());
}
boolean reorder = false;
for (int i = mAccessPoints.size() - 1; i >= 0; --i) {
if (mAccessPoints.get(i).update(connectionConfig, mLastInfo, mLastNetworkInfo)) {
reorder = true;
}
}
if (reorder) {
synchronized (mAccessPoints) {
Collections.sort(mAccessPoints);
}
mMainHandler.sendEmptyMessage(MainHandler.MSG_ACCESS_POINT_CHANGED);
}
}
use of android.net.wifi.WifiConfiguration in project android_frameworks_base by DirtyUnicorns.
the class WifiTrackerTest method addConfig.
private int addConfig(List<WifiConfiguration> configs, String ssid) {
WifiConfiguration config = new WifiConfiguration();
config.networkId = configs.size();
config.SSID = '"' + ssid + '"';
configs.add(config);
return config.networkId;
}
Aggregations