Methods Summary |
---|
private android.net.wifi.WifiConfiguration | addConfiguration(AccessPointState state, int flags)
// Create and add
WifiConfiguration config = new WifiConfiguration();
state.updateWifiConfiguration(config);
final int networkId = mWifiManager.addNetwork(config);
if (networkId == -1) {
return null;
}
state.setNetworkId(networkId);
state.setConfigured(true);
// If we should, then enable it, since it comes disabled by default
if ((flags & ADD_CONFIGURATION_ENABLE) != 0
&& !managerEnableNetwork(state, false)) {
return null;
}
// If we should, then save it
if ((flags & ADD_CONFIGURATION_SAVE) != 0 && !managerSaveConfiguration()) {
return null;
}
if (mCallback != null) {
mCallback.onAccessPointSetChanged(state, true);
}
return config;
|
private void | attemptReenableAllAps()
if (mReenableApsOnNetworkStateChange) {
mReenableApsOnNetworkStateChange = false;
enableAllAps();
}
|
public void | attemptScan()Attempts to scan networks. This has a retry mechanism.
// Remove any future scans since we're scanning right now
removeFutureScans();
if (!mWifiManager.isWifiEnabled()) return;
if (!mWifiManager.startScan()) {
postAttemptScan();
} else {
mScanRetryCount = 0;
}
|
private void | checkForExcessOpenNetworks()Checks if there are too many open networks, and removes the excess ones.
synchronized(this) {
ArrayList<AccessPointState> allAps = getApsSortedByPriorityLocked();
// Walk from highest to lowest priority
int openConfiguredCount = 0;
for (int i = allAps.size() - 1; i >= 0; i--) {
AccessPointState state = allAps.get(i);
if (state.configured && !state.hasSecurity()) {
openConfiguredCount++;
if (openConfiguredCount > WIFI_NUM_OPEN_NETWORKS_KEPT) {
// Remove this network
forgetNetwork(state);
}
}
}
}
|
private void | checkNextHighestPriority(int priority)Makes sure the next highest priority is larger than the given priority.
if (priority > HIGHEST_PRIORITY_MAX_VALUE || priority < 0) {
// This is a priority that we aren't managing
return;
}
if (mNextHighestPriority <= priority) {
mNextHighestPriority = priority + 1;
}
|
private void | clearApLists()
List<AccessPointState> accessPoints = new ArrayList<AccessPointState>();
synchronized(this) {
// Clear the logic's list of access points
accessPoints.addAll(mApScanList);
accessPoints.addAll(mApOtherList);
mApScanList.clear();
mApOtherList.clear();
}
for (int i = accessPoints.size() - 1; i >= 0; i--) {
removeApFromUi(accessPoints.get(i));
}
|
public boolean | connectToNetwork(AccessPointState state)Connects to the network, and creates the Wi-Fi API config if necessary.
if (LOGV) {
Log.v(TAG, "Connecting to " + state);
}
// Need WifiConfiguration for the AP
WifiConfiguration config = findConfiguredNetwork(state);
if (LOGV) {
Log.v(TAG, " Found configured network " + config);
}
if (config == null) {
/*
* Connecting for the first time, need to create it. We will enable
* and save it below (when we set priority).
*/
config = addConfiguration(state, 0);
if (config == null) {
Log.e(TAG, "Config is still null, even after attempting to add it.");
error(R.string.error_connecting);
return false;
}
/*
* We could reload the configured networks, but instead just
* shortcut and add this state to our list in memory.
*/
ensureTrackingState(state);
} else {
// Make sure the configuration has the latest from the state
state.updateWifiConfiguration(config);
}
// Enable this network before we save to storage
if (!managerEnableNetwork(state, false)) {
Log.e(TAG, "Could not enable network ID " + state.networkId);
error(R.string.error_connecting);
return false;
}
/*
* Give it highest priority, this could cause a network ID change, so do
* it after any modifications to the network we're connecting to
*/
setHighestPriorityStateAndSave(state, config);
/*
* We force supplicant to connect to this network by disabling the
* others. We do this AFTER we save above so this disabled flag isn't
* persisted.
*/
mReenableApsOnNetworkStateChange = true;
if (!managerEnableNetwork(state, true)) {
Log.e(TAG, "Could not enable network ID " + state.networkId);
error(R.string.error_connecting);
return false;
}
if (LOGV) {
Log.v(TAG, " Enabled network " + state.networkId);
}
if (mCurrentSupplicantState == SupplicantState.DISCONNECTED ||
mCurrentSupplicantState == SupplicantState.SCANNING) {
mWifiManager.reconnect();
}
// Check for too many configured open networks
if (!state.hasSecurity()) {
checkForExcessOpenNetworks();
}
return true;
|
private void | enableAllAps()
synchronized(this) {
if (LOGV) {
Log.v(TAG, " Enabling all APs");
}
enableApsLocked(mApOtherList);
enableApsLocked(mApScanList);
}
|
private void | enableApsLocked(java.util.List apList)
for (int i = apList.size() - 1; i >= 0; i--) {
AccessPointState state = apList.get(i);
int networkId = state.networkId;
if (networkId != AccessPointState.NETWORK_ID_NOT_SET &&
networkId != AccessPointState.NETWORK_ID_ANY) {
managerEnableNetwork(state, false);
}
}
|
private void | ensureTrackingState(AccessPointState state)This ensures this class is tracking the given state. This means it is in
our list of access points, either in the scanned list or in the
remembered list.
synchronized (this) {
if (hasApInstanceLocked(state)) {
return;
}
mApOtherList.add(state);
}
|
public void | error(int messageResId)
Log.e(TAG, mContext.getResources().getString(messageResId));
if (mCallback != null) {
mCallback.onError(messageResId);
}
|
private static AccessPointState | findApLocked(java.util.List list, int networkId, java.lang.String bssid, java.lang.String ssid, java.lang.String security)Must call while holding the lock for the list, which is usually the
WifiLayer instance.
AccessPointState ap;
for (int i = list.size() - 1; i >= 0; i--) {
ap = list.get(i);
if (ap.matches(networkId, bssid, ssid, security) >= AccessPointState.MATCH_WEAK) {
return ap;
}
}
return null;
|
private AccessPointState | findApLocked(int networkId, java.lang.String bssid, java.lang.String ssid, java.lang.String security)Must call while holding the lock for the lists, which is usually this
WifiLayer instance.
AccessPointState ap = findApLocked(mApScanList, networkId, bssid, ssid, security);
if (ap == null) {
ap = findApLocked(mApOtherList, networkId, bssid, ssid, security);
}
return ap;
|
private android.net.wifi.WifiConfiguration | findConfiguredNetwork(AccessPointState state)
final List<WifiConfiguration> wifiConfigs = getConfiguredNetworks();
for (int i = wifiConfigs.size() - 1; i >= 0; i--) {
final WifiConfiguration wifiConfig = wifiConfigs.get(i);
if (state.matchesWifiConfiguration(wifiConfig) >= AccessPointState.MATCH_WEAK) {
return wifiConfig;
}
}
return null;
|
public boolean | forgetNetwork(AccessPointState state)Forgets a network.
if (!state.configured) {
Log.w(TAG, "Inconsistent state: Forgetting a network that is not configured.");
return true;
}
int oldNetworkId = state.networkId;
state.forget();
if (!state.seen) {
// If it is not seen, it should be removed from the UI
removeApFromUi(state);
}
synchronized (this) {
mApOtherList.remove(state);
// It should not be removed from the scan list, since if it was
// there that means it's still seen
}
if (!mWifiManager.removeNetwork(oldNetworkId)) {
Log.e(TAG, "Removing network " + state.ssid + " (network ID " + oldNetworkId +
") failed.");
return false;
}
if (!managerSaveConfiguration()) {
error(R.string.error_saving);
return false;
}
return true;
|
private java.util.ArrayList | getApsSortedByPriorityLocked()
// Get all of the access points we have
ArrayList<AccessPointState> allAps = new ArrayList<AccessPointState>(mApScanList.size()
+ mApOtherList.size());
allAps.addAll(mApScanList);
allAps.addAll(mApOtherList);
// Sort them based on priority
Collections.sort(allAps, new Comparator<AccessPointState>() {
public int compare(AccessPointState object1, AccessPointState object2) {
return object1.priority - object2.priority;
}
});
return allAps;
|
private java.util.List | getConfiguredNetworks()
final List<WifiConfiguration> wifiConfigs = mWifiManager.getConfiguredNetworks();
return wifiConfigs;
|
private AccessPointState | getCurrentAp()
final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
String ssid = wifiInfo.getSSID();
if (ssid != null) {
/*
* We pass null for security since we have a network ID (i.e., it's
* not a wildcard), and rely on it matching.
*/
return findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), ssid, null);
} else {
return null;
}
|
private int | getNextHighestPriority()Gets the next highest priority. If this value is larger than the max,
shift all the priorities so the lowest starts at 0.
Only
{@link #setHighestPriorityStateAndSave(AccessPointState, WifiConfiguration)}
should call this.
if (mNextHighestPriority > HIGHEST_PRIORITY_MAX_VALUE) {
shiftPriorities();
}
return mNextHighestPriority++;
|
public AccessPointState | getWifiLayerApInstance(AccessPointState state)Returns an AccessPointState instance (that we track locally in WifiLayer)
for the given state. First, we check if we track the given instance. If
not, we find an equal AccessPointState instance that we track.
synchronized (this) {
if (hasApInstanceLocked(state)) {
return state;
}
return findApLocked(state.networkId, state.bssid, state.ssid, state.security);
}
|
private void | handleDisablingScanWhileObtainingAddress(android.net.NetworkInfo.DetailedState detailedState)
if (detailedState == DetailedState.OBTAINING_IPADDR) {
mIsObtainingAddress = true;
// We will not scan while obtaining an IP address
removeFutureScans();
} else {
mIsObtainingAddress = false;
// Start continuous scan
queueContinuousScan();
}
|
private void | handleNetworkIdsChanged()
synchronized (this) {
final List<WifiConfiguration> configs = getConfiguredNetworks();
for (int i = configs.size() - 1; i >= 0; i--) {
final WifiConfiguration config = configs.get(i);
AccessPointState ap;
// Since network IDs have changed, we can't use it to find our previous AP state
ap = findApLocked(AccessPointState.NETWORK_ID_ANY, config.BSSID, config.SSID,
AccessPointState.getWifiConfigurationSecurity(config));
if (ap == null) {
continue;
}
ap.setNetworkId(config.networkId);
}
}
|
private void | handleNetworkStateChanged(android.net.NetworkInfo info, java.lang.String bssid)
final AccessPointState ap = getCurrentAp();
NetworkInfo.DetailedState detailedState = info.getDetailedState();
if (LOGV) {
Log.v(TAG, "State change received " + info.toString() + ", or "
+ detailedState + " on " + bssid + " matched to " + ap);
}
handleDisablingScanWhileObtainingAddress(detailedState);
// This will update the AP with its new info
refreshStatus(ap, detailedState);
boolean isDisconnected = info.getState().equals(State.DISCONNECTED);
if (ap != null && info.isConnectedOrConnecting()) {
setPrimaryAp(ap);
if (LOGV) {
Log.v(TAG, " Updated " + ap + " to be primary");
}
} else if (isDisconnected) {
/*
* When we drop off a network (for example, the router is powered
* down when we were connected), we received a DISCONNECT event
* without a BSSID. We should not have a primary AP anymore.
*/
setPrimaryAp(null);
if (LOGV) {
Log.v(TAG, " Cleared primary");
}
} else if (detailedState.equals(DetailedState.FAILED)) {
/*
* Doh, failed for whatever reason. Unset the primary AP, but set
* failed status on the AP that failed.
*/
setPrimaryAp(null);
ap.setStatus(DetailedState.FAILED);
// Bring up error dialog
error(R.string.wifi_generic_connection_error);
} else if (LOGV) {
Log.v(TAG, " Did not update any AP to primary, could have updated "
+ ap + " but we aren't connected or connecting");
}
if ((ap != null) && (info.isConnected()
|| (detailedState == DetailedState.OBTAINING_IPADDR))) {
/*
* Sometimes the scan results do not contain the AP even though it's
* clearly connected. This may be because we do passive background
* scanning that isn't as 'strong' as active scanning, so even
* though a network is nearby, it won't be seen by the passive
* scanning. If we are connected (or obtaining IP) then we know it
* is seen.
*/
ap.setSeen(true);
}
attemptReenableAllAps();
|
private void | handleScanResultsAvailable()
synchronized(this) {
// In the end, we'll moved the ones no longer seen into the mApOtherList
List<AccessPointState> oldScanList = mApScanList;
List<AccessPointState> newScanList =
new ArrayList<AccessPointState>(oldScanList.size());
List<ScanResult> list = mWifiManager.getScanResults();
if (list != null) {
for (int i = list.size() - 1; i >= 0; i--) {
final ScanResult scanResult = list.get(i);
if (LOGV) {
// Log.v(TAG, " " + scanResult);
}
if (scanResult == null) {
continue;
}
/*
* Ignore adhoc, enterprise-secured, or hidden networks.
* Hidden networks show up with empty SSID.
*/
if (AccessPointState.isAdhoc(scanResult)
|| AccessPointState.isEnterprise(scanResult)
|| TextUtils.isEmpty(scanResult.SSID)) {
continue;
}
final String ssid = AccessPointState.convertToQuotedString(scanResult.SSID);
String security = AccessPointState.getScanResultSecurity(scanResult);
// See if this AP is part of a group of APs (e.g., any large
// wifi network has many APs, we'll only show one) that we've
// seen in this scan
AccessPointState ap = findApLocked(newScanList, AccessPointState.NETWORK_ID_ANY,
AccessPointState.BSSID_ANY, ssid, security);
// Yup, we've seen this network.
if (ap != null) {
// Use the better signal
if (WifiManager.compareSignalLevel(scanResult.level, ap.signal) > 0) {
ap.setSignal(scanResult.level);
}
if (LOGV) {
// Log.v(TAG, " Already seen, continuing..");
}
continue;
}
// Find the AP in either our old scan list, or our non-seen
// configured networks list
ap = findApLocked(AccessPointState.NETWORK_ID_ANY, AccessPointState.BSSID_ANY,
ssid, security);
if (ap != null) {
// Remove the AP from both (no harm if one doesn't contain it)
oldScanList.remove(ap);
mApOtherList.remove(ap);
} else {
ap = new AccessPointState(mContext);
// if (LOGV) Log.v(TAG, "Created " + ap);
}
// Give it the latest state
ap.updateFromScanResult(scanResult);
if (mCallback != null) {
mCallback.onAccessPointSetChanged(ap, true);
}
newScanList.add(ap);
}
}
// oldScanList contains the ones no longer seen
List<AccessPointState> otherList = mApOtherList;
for (int i = oldScanList.size() - 1; i >= 0; i--) {
final AccessPointState ap = oldScanList.get(i);
if (ap.configured) {
// Keep it around, since it is configured
ap.setSeen(false);
otherList.add(ap);
} else {
// Remove it since it is not configured and not seen
removeApFromUi(ap);
}
}
mApScanList = newScanList;
}
onScanningEnded();
|
private void | handleSignalChanged(int rssi)
if (mCurrentPrimaryAp != null) {
mCurrentPrimaryAp.setSignal(rssi);
}
|
private void | handleSupplicantConnectionChanged(boolean connected)
if (mCallback != null) {
mCallback.onAccessPointsStateChanged(connected);
}
if (connected) {
refreshAll(true);
}
|
private void | handleSupplicantStateChanged(android.net.wifi.SupplicantState state, boolean hasError, int error)
mCurrentSupplicantState = state;
if (SupplicantState.FOUR_WAY_HANDSHAKE.equals(state)) {
mLastAuthenticatingAp = getCurrentAp();
}
if (hasError) {
handleSupplicantStateError(error);
}
|
private void | handleSupplicantStateError(int supplicantError)
if (supplicantError == WifiManager.ERROR_AUTHENTICATING) {
if (mCallback != null) {
if (mLastAuthenticatingAp != null) {
mCallback.onRetryPassword(mLastAuthenticatingAp);
}
}
}
|
private void | handleWifiStateChanged(int wifiState)
if (wifiState == WIFI_STATE_ENABLED) {
loadConfiguredAccessPoints();
attemptScan();
} else if (wifiState == WIFI_STATE_DISABLED) {
removeFutureScans();
if (LOGV) Log.v(TAG, "Clearing AP lists because wifi is disabled");
clearApLists();
}
if (mCallback != null) {
mCallback.onAccessPointsStateChanged(wifiState == WIFI_STATE_ENABLED);
}
|
private boolean | hasApInstanceLocked(AccessPointState state)Returns whether we have the exact instance of the access point state
given. This is useful in cases where an AccessPointState has been
parceled by the client and the client is attempting to use it to
connect/forget/save.
Must call while holding the lock for the lists, which is usually this
WifiLayer instance.
for (int i = mApScanList.size() - 1; i >= 0; i--) {
if (mApScanList.get(i) == state) {
return true;
}
}
for (int i = mApOtherList.size() - 1; i >= 0; i--) {
if (mApOtherList.get(i) == state) {
return true;
}
}
return false;
|
private boolean | isConsideredForHighestPriority(AccessPointState state)
return state.configured && state.networkId != AccessPointState.NETWORK_ID_ANY &&
state.networkId != AccessPointState.NETWORK_ID_NOT_SET;
|
public boolean | isWifiEnabled()
return mWifiManager.isWifiEnabled();
|
private void | loadConfiguredAccessPoints()
final List<WifiConfiguration> configs = getConfiguredNetworks();
for (int i = configs.size() - 1; i >= 0; i--) {
final WifiConfiguration config = configs.get(i);
AccessPointState ap;
synchronized(this) {
ap = findApLocked(config.networkId, config.BSSID, config.SSID,
AccessPointState.getWifiConfigurationSecurity(config));
if (ap != null) {
// We already know about this one
continue;
}
ap = new AccessPointState(mContext);
ap.updateFromWifiConfiguration(config);
if (LOGV) Log.v(TAG, "Created " + ap + " in loadConfiguredAccessPoints");
mApOtherList.add(ap);
}
// Make sure our next highest priority is greater than this
checkNextHighestPriority(ap.priority);
if (mCallback != null) {
mCallback.onAccessPointSetChanged(ap, true);
}
}
|
private boolean | managerEnableNetwork(AccessPointState state, boolean disableOthers)
if (!mWifiManager.enableNetwork(state.networkId, disableOthers)) {
return false;
}
// Enabling was successful, make sure the state is not disabled
state.setDisabled(false);
return true;
|
private boolean | managerSaveConfiguration()
boolean retValue = mWifiManager.saveConfiguration();
/*
* We need to assume the network IDs have changed, so handle this. Note:
* we also have a receiver on the broadcast intent in case another wifi
* framework client caused the change. In this case, we will handle the
* possible network ID change twice (but it's not too costly).
*/
handleNetworkIdsChanged();
return retValue;
|
public void | onCreate()The client MUST call this.
This shouldn't have any dependency on the callback.
mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
mIntentFilter = new IntentFilter();
mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
mIntentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
mIntentFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);
mIntentFilter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION);
WIFI_NUM_OPEN_NETWORKS_KEPT = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.WIFI_NUM_OPEN_NETWORKS_KEPT, 10);
|
public void | onCreatedCallback()The client MUST call this.
Callback is ready, this can do whatever it wants with it.
if (isWifiEnabled()) {
refreshAll(false);
}
|
public void | onPause()The client MUST call this.
mContext.unregisterReceiver(mReceiver);
attemptReenableAllAps();
removeFutureScans();
|
public void | onResume()The client MUST call this.
mContext.registerReceiver(mReceiver, mIntentFilter);
if (isWifiEnabled()) {
// Kick start the continual scan
queueContinuousScan();
}
|
private void | onScanningEnded()
queueContinuousScan();
if (mCallback != null) {
mCallback.onScanningStatusChanged(false);
}
|
private void | onScanningStarted()
if (mCallback != null) {
mCallback.onScanningStatusChanged(true);
}
|
private void | postAttemptScan()
onScanningStarted();
if (++mScanRetryCount < SCAN_MAX_RETRY) {
// Just in case, remove previous ones first
removeFutureScans();
mHandler.sendEmptyMessageDelayed(MESSAGE_ATTEMPT_SCAN, SCAN_RETRY_DELAY_MS);
} else {
// Show an error once we run out of attempts
error(R.string.error_scanning);
onScanningEnded();
}
|
private void | queueContinuousScan()
mHandler.removeMessages(MESSAGE_ATTEMPT_SCAN);
if (!mIsObtainingAddress) {
// Don't do continuous scan while in obtaining IP state
mHandler.sendEmptyMessageDelayed(MESSAGE_ATTEMPT_SCAN, CONTINUOUS_SCAN_DELAY_MS);
}
|
private void | refreshAll(boolean attemptScan)
loadConfiguredAccessPoints();
refreshStatus();
if (attemptScan) {
attemptScan();
}
|
private void | refreshStatus()
refreshStatus(null, null);
|
private void | refreshStatus(AccessPointState ap, android.net.NetworkInfo.DetailedState detailedState)
final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
if (detailedState == null) {
detailedState = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
}
if (ap == null && WifiStatus.isLiveConnection(detailedState)) {
/*
* We pass null for security since we have a network ID (i.e., it's
* not a wildcard), and rely on it matching.
*/
ap = findApLocked(wifiInfo.getNetworkId(), wifiInfo.getBSSID(), wifiInfo
.getSSID(), null);
}
if (ap != null) {
ap.blockRefresh();
// Let the AP get the latest info from the WifiInfo
ap.updateFromWifiInfo(wifiInfo, detailedState);
// The detailed state from the Intent has more states than the WifiInfo's detailed
// state can have (for example, DHCP completion). Set the status using
// the Intent's detailed state.
ap.setStatus(detailedState);
ap.unblockRefresh();
}
|
private void | removeApFromUi(AccessPointState ap)
if (mCallback != null) {
mCallback.onAccessPointSetChanged(ap, false);
}
|
private void | removeFutureScans()
mHandler.removeMessages(MESSAGE_ATTEMPT_SCAN);
|
public boolean | saveNetwork(AccessPointState state)Saves a network, and creates the Wi-Fi API config if necessary.
WifiConfiguration config = findConfiguredNetwork(state);
if (config == null) {
// if the user is adding a new network, assume that it is hidden
state.setHiddenSsid(true);
config = addConfiguration(state, ADD_CONFIGURATION_ENABLE);
if (config == null) {
Log.e(TAG, "Could not save configuration, call to addConfiguration failed.");
error(R.string.error_saving);
return false;
}
} else {
state.updateWifiConfiguration(config);
if (mWifiManager.updateNetwork(config) == -1) {
Log.e(TAG, "Could not update configuration, call to WifiManager failed.");
error(R.string.error_saving);
return false;
}
}
// Successfully added network, go ahead and persist
if (!managerSaveConfiguration()) {
Log.e(TAG, "Could not save configuration, call to WifiManager failed.");
error(R.string.error_saving);
return false;
}
/*
* We could reload the configured networks, but instead just shortcut
* and add this state to our list in memory
*/
ensureTrackingState(state);
return true;
|
private boolean | setHighestPriorityStateAndSave(AccessPointState state, android.net.wifi.WifiConfiguration reusableConfiguration)Sets the access point state to the highest priority.
If you have a list of configured networks from WifiManager, you probably
shouldn't call this until you're done traversing the list.
if (!isConsideredForHighestPriority(state)) {
Log.e(TAG,
"Could not set highest priority on state because state is not being considered.");
return false;
}
if (reusableConfiguration == null) {
reusableConfiguration = new WifiConfiguration();
}
int oldPriority = reusableConfiguration.priority;
reusableConfiguration.priority = getNextHighestPriority();
reusableConfiguration.networkId = state.networkId;
if (mWifiManager.updateNetwork(reusableConfiguration) == -1) {
// Rollback priority
reusableConfiguration.priority = oldPriority;
Log.e(TAG,
"Could not set highest priority on state because updating the supplicant network failed.");
return false;
}
if (!managerSaveConfiguration()) {
reusableConfiguration.priority = oldPriority;
Log.e(TAG,
"Could not set highest priority on state because saving config failed.");
return false;
}
state.priority = reusableConfiguration.priority;
if (LOGV) {
Log.v(TAG, " Set highest priority to "
+ state.priority + " from " + oldPriority);
}
return true;
|
private void | setPrimaryAp(AccessPointState ap)
synchronized (this) {
// Unset other
if (mCurrentPrimaryAp != null) {
mCurrentPrimaryAp.setPrimary(false);
}
mCurrentPrimaryAp = ap;
}
if (ap != null) {
ap.setPrimary(true);
}
|
private boolean | shiftPriorities()Shift all the priorities so the lowest starts at 0.
synchronized(this) {
ArrayList<AccessPointState> allAps = getApsSortedByPriorityLocked();
// Re-usable WifiConfiguration for setting priority
WifiConfiguration updatePriorityConfig = new WifiConfiguration();
// Set new priorities
mNextHighestPriority = 0;
int size = allAps.size();
for (int i = 0; i < size; i++) {
AccessPointState state = allAps.get(i);
if (!isConsideredForHighestPriority(state)) {
continue;
}
if (!setHighestPriorityStateAndSave(state, updatePriorityConfig)) {
Log.e(TAG,
"Could not shift priorities because setting the new priority failed.");
return false;
}
}
return true;
}
|