diff options
| author | Robert Greenwalt <robdroid@android.com> | 2010-01-20 19:29:41 -0800 |
|---|---|---|
| committer | Robert Greenwalt <robdroid@android.com> | 2010-01-20 19:29:41 -0800 |
| commit | da03c4e4b3d47e6917fdcddecf68f2f52564e3a0 (patch) | |
| tree | a08480b57b97e4033f0c2e909bef9d358aa75eb1 /services/java/com/android/server/ConnectivityService.java | |
| parent | 48ef378d01b3ace349cbb6ba564276b854d872c9 (diff) | |
Try to switch to another default net on connection failure.
This shouldn't be required, but there seems to be something odd going on
in wifi and it doesn't hurt to try other available options. Makes a
connection failure case work like a disconnected case.
bug: 2378462
Diffstat (limited to 'services/java/com/android/server/ConnectivityService.java')
| -rw-r--r-- | services/java/com/android/server/ConnectivityService.java | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 08eceac4b37c..dfb6ff7a0251 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -811,6 +811,28 @@ public class ConnectivityService extends IConnectivityManager.Stub { info.getExtraInfo()); } + NetworkStateTracker newNet = tryFailover(prevNetType); + if (newNet != null) { + NetworkInfo switchTo = newNet.getNetworkInfo(); + intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo); + } else { + intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true); + } + // do this before we broadcast the change + handleConnectivityChange(); + + sendStickyBroadcast(intent); + /* + * If the failover network is already connected, then immediately send + * out a followup broadcast indicating successful failover + */ + if (newNet != null && newNet.getNetworkInfo().isConnected()) { + sendConnectedBroadcast(newNet.getNetworkInfo()); + } + } + + // returns -1 if no failover available + private NetworkStateTracker tryFailover(int prevNetType) { /* * If this is a default network, check if other defaults are available * or active @@ -823,8 +845,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { int newType = -1; int newPriority = -1; - for (int checkType=0; checkType <= - ConnectivityManager.MAX_NETWORK_TYPE; checkType++) { + for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) { if (checkType == prevNetType) { continue; } @@ -839,8 +860,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { if (mRadioAttributes[mNetAttributes[checkType].mRadio]. mPriority > newPriority) { newType = checkType; - newPriority = mRadioAttributes[mNetAttributes[newType]. - mRadio].mPriority; + newPriority = mRadioAttributes[mNetAttributes[newType].mRadio].mPriority; } } } @@ -870,29 +890,13 @@ public class ConnectivityService extends IConnectivityManager.Stub { switchTo.getTypeName()); } } - intent.putExtra(ConnectivityManager. - EXTRA_OTHER_NETWORK_INFO, switchTo); } else { - intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, - true); newNet.reconnect(); } - } else { - intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, - true); } } - // do this before we broadcast the change - handleConnectivityChange(); - - sendStickyBroadcast(intent); - /* - * If the failover network is already connected, then immediately send - * out a followup broadcast indicating successful failover - */ - if (newNet != null && newNet.getNetworkInfo().isConnected()) - sendConnectedBroadcast(newNet.getNetworkInfo()); + return newNet; } private void sendConnectedBroadcast(NetworkInfo info) { @@ -948,7 +952,25 @@ public class ConnectivityService extends IConnectivityManager.Stub { intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true); info.setFailover(false); } + + NetworkStateTracker newNet = tryFailover(info.getType()); + if (newNet != null) { + NetworkInfo switchTo = newNet.getNetworkInfo(); + intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo); + } else { + intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true); + } + // do this before we broadcast the change + handleConnectivityChange(); + sendStickyBroadcast(intent); + /* + * If the failover network is already connected, then immediately send + * out a followup broadcast indicating successful failover + */ + if (newNet != null && newNet.getNetworkInfo().isConnected()) { + sendConnectedBroadcast(newNet.getNetworkInfo()); + } } private void sendStickyBroadcast(Intent intent) { |
