summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorRobert Greenwalt <rgreenwalt@google.com>2015-07-09 17:09:15 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-07-09 17:09:17 +0000
commitb091695bd9b9a87fc637751cfa2b52c8b72ce487 (patch)
tree82ed3962d9a91578729a6cbd050e3ded3aaf1ac8 /services
parentee4a534b7bbe95fa913473e3288787fcd1050c49 (diff)
parent8d48252b80cdb261cd2fa7372a01e6197f95efa6 (diff)
downloadframeworks_base-b091695bd9b9a87fc637751cfa2b52c8b72ce487.zip
frameworks_base-b091695bd9b9a87fc637751cfa2b52c8b72ce487.tar.gz
frameworks_base-b091695bd9b9a87fc637751cfa2b52c8b72ce487.tar.bz2
Merge "Revive NetworkInfo's SUSPENDED state." into mnc-dev
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/ConnectivityService.java56
1 files changed, 42 insertions, 14 deletions
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 7f124dc..8ca075f 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -493,10 +493,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
}
- private void maybeLogBroadcast(NetworkAgentInfo nai, boolean connected, int type,
+ private void maybeLogBroadcast(NetworkAgentInfo nai, DetailedState state, int type,
boolean isDefaultNetwork) {
if (DBG) {
- log("Sending " + (connected ? "connected" : "disconnected") +
+ log("Sending " + state +
" broadcast for type " + type + " " + nai.name() +
" isDefaultNetwork=" + isDefaultNetwork);
}
@@ -520,8 +520,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
// Send a broadcast if this is the first network of its type or if it's the default.
final boolean isDefaultNetwork = isDefaultNetwork(nai);
if (list.size() == 1 || isDefaultNetwork) {
- maybeLogBroadcast(nai, true, type, isDefaultNetwork);
- sendLegacyNetworkBroadcast(nai, true, type);
+ maybeLogBroadcast(nai, DetailedState.CONNECTED, type, isDefaultNetwork);
+ sendLegacyNetworkBroadcast(nai, DetailedState.CONNECTED, type);
}
}
@@ -538,17 +538,19 @@ public class ConnectivityService extends IConnectivityManager.Stub
return;
}
+ final DetailedState state = DetailedState.DISCONNECTED;
+
if (wasFirstNetwork || wasDefault) {
- maybeLogBroadcast(nai, false, type, wasDefault);
- sendLegacyNetworkBroadcast(nai, false, type);
+ maybeLogBroadcast(nai, state, type, wasDefault);
+ sendLegacyNetworkBroadcast(nai, state, type);
}
if (!list.isEmpty() && wasFirstNetwork) {
if (DBG) log("Other network available for type " + type +
", sending connected broadcast");
final NetworkAgentInfo replacement = list.get(0);
- maybeLogBroadcast(replacement, false, type, isDefaultNetwork(replacement));
- sendLegacyNetworkBroadcast(replacement, false, type);
+ maybeLogBroadcast(replacement, state, type, isDefaultNetwork(replacement));
+ sendLegacyNetworkBroadcast(replacement, state, type);
}
}
@@ -560,6 +562,21 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
}
+ // send out another legacy broadcast - currently only used for suspend/unsuspend
+ // toggle
+ public void update(NetworkAgentInfo nai) {
+ final boolean isDefault = isDefaultNetwork(nai);
+ final DetailedState state = nai.networkInfo.getDetailedState();
+ for (int type = 0; type < mTypeLists.length; type++) {
+ final ArrayList<NetworkAgentInfo> list = mTypeLists[type];
+ final boolean isFirst = (list != null && list.size() > 0 && nai == list.get(0));
+ if (isFirst || isDefault) {
+ maybeLogBroadcast(nai, state, type, isDefault);
+ sendLegacyNetworkBroadcast(nai, state, type);
+ }
+ }
+ }
+
private String naiToString(NetworkAgentInfo nai) {
String name = (nai != null) ? nai.name() : "null";
String state = (nai.networkInfo != null) ?
@@ -4502,6 +4519,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
private void updateNetworkInfo(NetworkAgentInfo networkAgent, NetworkInfo newInfo) {
NetworkInfo.State state = newInfo.getState();
NetworkInfo oldInfo = null;
+ final int oldScore = networkAgent.getCurrentScore();
synchronized (networkAgent) {
oldInfo = networkAgent.networkInfo;
networkAgent.networkInfo = newInfo;
@@ -4560,8 +4578,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
// This has to happen after matching the requests, because callbacks are just requests.
notifyNetworkCallbacks(networkAgent, ConnectivityManager.CALLBACK_PRECHECK);
- } else if (state == NetworkInfo.State.DISCONNECTED ||
- state == NetworkInfo.State.SUSPENDED) {
+ } else if (state == NetworkInfo.State.DISCONNECTED) {
networkAgent.asyncChannel.disconnect();
if (networkAgent.isVPN()) {
synchronized (mProxyLock) {
@@ -4573,6 +4590,17 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
}
}
+ } else if ((oldInfo != null && oldInfo.getState() == NetworkInfo.State.SUSPENDED) ||
+ state == NetworkInfo.State.SUSPENDED) {
+ // going into or coming out of SUSPEND: rescore and notify
+ if (networkAgent.getCurrentScore() != oldScore) {
+ rematchAllNetworksAndRequests(networkAgent, oldScore,
+ NascentState.NOT_JUST_VALIDATED);
+ }
+ notifyNetworkCallbacks(networkAgent, (state == NetworkInfo.State.SUSPENDED ?
+ ConnectivityManager.CALLBACK_SUSPENDED :
+ ConnectivityManager.CALLBACK_RESUMED));
+ mLegacyTypeTracker.update(networkAgent);
}
}
@@ -4608,7 +4636,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
}
- private void sendLegacyNetworkBroadcast(NetworkAgentInfo nai, boolean connected, int type) {
+ private void sendLegacyNetworkBroadcast(NetworkAgentInfo nai, DetailedState state, int type) {
// The NetworkInfo we actually send out has no bearing on the real
// state of affairs. For example, if the default connection is mobile,
// and a request for HIPRI has just gone away, we need to pretend that
@@ -4617,11 +4645,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
// and is still connected.
NetworkInfo info = new NetworkInfo(nai.networkInfo);
info.setType(type);
- if (connected) {
- info.setDetailedState(DetailedState.CONNECTED, null, info.getExtraInfo());
+ if (state != DetailedState.DISCONNECTED) {
+ info.setDetailedState(state, null, info.getExtraInfo());
sendConnectedBroadcast(info);
} else {
- info.setDetailedState(DetailedState.DISCONNECTED, info.getReason(), info.getExtraInfo());
+ info.setDetailedState(state, info.getReason(), info.getExtraInfo());
Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, info);
intent.putExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, info.getType());