Loading core/java/android/net/ConnectivityManager.java +4 −0 Original line number Original line Diff line number Diff line Loading @@ -1078,6 +1078,8 @@ public class ConnectivityManager { * registerNetworkCallback() are not specific to any particular Network so * registerNetworkCallback() are not specific to any particular Network so * do not cause any updates. * do not cause any updates. * * * TODO: Delete once callers are updated. * * @hide * @hide */ */ public void requestLinkProperties(NetworkCallback networkCallback) { public void requestLinkProperties(NetworkCallback networkCallback) { Loading Loading @@ -1115,6 +1117,8 @@ public class ConnectivityManager { * registerNetworkCallback() are not specific to any particular Network so * registerNetworkCallback() are not specific to any particular Network so * do not cause any updates. * do not cause any updates. * * * TODO: Delete once callers are updated. * * @hide * @hide */ */ public void requestNetworkCapabilities(NetworkCallback networkCallback) { public void requestNetworkCapabilities(NetworkCallback networkCallback) { Loading services/core/java/com/android/server/ConnectivityService.java +24 −10 Original line number Original line Diff line number Diff line Loading @@ -4351,6 +4351,7 @@ public class ConnectivityService extends IConnectivityManager.Stub mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_LISTENER, nri)); mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_LISTENER, nri)); } } // TODO: Delete once callers are updated. @Override @Override public void requestLinkProperties(NetworkRequest networkRequest) { public void requestLinkProperties(NetworkRequest networkRequest) { ensureNetworkRequestHasType(networkRequest); ensureNetworkRequestHasType(networkRequest); Loading @@ -4359,6 +4360,7 @@ public class ConnectivityService extends IConnectivityManager.Stub EVENT_REQUEST_LINKPROPERTIES, getCallingUid(), 0, networkRequest)); EVENT_REQUEST_LINKPROPERTIES, getCallingUid(), 0, networkRequest)); } } // TODO: Delete once callers are updated. @Override @Override public void requestNetworkCapabilities(NetworkRequest networkRequest) { public void requestNetworkCapabilities(NetworkRequest networkRequest) { ensureNetworkRequestHasType(networkRequest); ensureNetworkRequestHasType(networkRequest); Loading Loading @@ -4879,7 +4881,7 @@ public class ConnectivityService extends IConnectivityManager.Stub if (!nr.isListen()) continue; if (!nr.isListen()) continue; if (nai.satisfies(nr) && !nai.isSatisfyingRequest(nr.requestId)) { if (nai.satisfies(nr) && !nai.isSatisfyingRequest(nr.requestId)) { nai.addRequest(nr); nai.addRequest(nr); notifyNetworkCallback(nai, nri); notifyNetworkAvailable(nai, nri); } } } } } } Loading Loading @@ -5061,7 +5063,7 @@ public class ConnectivityService extends IConnectivityManager.Stub // do this after the default net is switched, but // do this after the default net is switched, but // before LegacyTypeTracker sends legacy broadcasts // before LegacyTypeTracker sends legacy broadcasts for (NetworkRequestInfo nri : addedRequests) notifyNetworkCallback(newNetwork, nri); for (NetworkRequestInfo nri : addedRequests) notifyNetworkAvailable(newNetwork, nri); // Linger any networks that are no longer needed. This should be done after sending the // Linger any networks that are no longer needed. This should be done after sending the // available callback for newNetwork. // available callback for newNetwork. Loading Loading @@ -5224,7 +5226,7 @@ public class ConnectivityService extends IConnectivityManager.Stub } } private void updateNetworkInfo(NetworkAgentInfo networkAgent, NetworkInfo newInfo) { private void updateNetworkInfo(NetworkAgentInfo networkAgent, NetworkInfo newInfo) { NetworkInfo.State state = newInfo.getState(); final NetworkInfo.State state = newInfo.getState(); NetworkInfo oldInfo = null; NetworkInfo oldInfo = null; final int oldScore = networkAgent.getCurrentScore(); final int oldScore = networkAgent.getCurrentScore(); synchronized (networkAgent) { synchronized (networkAgent) { Loading Loading @@ -5351,15 +5353,27 @@ public class ConnectivityService extends IConnectivityManager.Stub sendUpdatedScoreToFactories(nai); sendUpdatedScoreToFactories(nai); } } // notify only this one new request of the current state // Notify only this one new request of the current state. Transfer all the protected void notifyNetworkCallback(NetworkAgentInfo nai, NetworkRequestInfo nri) { // current state by calling NetworkCapabilities and LinkProperties callbacks int notifyType = ConnectivityManager.CALLBACK_AVAILABLE; // so that callers can be guaranteed to have as close to atomicity in state // transfer as can be supported by this current API. protected void notifyNetworkAvailable(NetworkAgentInfo nai, NetworkRequestInfo nri) { mHandler.removeMessages(EVENT_TIMEOUT_NETWORK_REQUEST, nri); mHandler.removeMessages(EVENT_TIMEOUT_NETWORK_REQUEST, nri); if (nri.mPendingIntent == null) { if (nri.mPendingIntent != null) { callCallbackForRequest(nri, nai, notifyType, 0); sendPendingIntentForRequest(nri, nai, ConnectivityManager.CALLBACK_AVAILABLE); } else { // Attempt no subsequent state pushes where intents are involved. sendPendingIntentForRequest(nri, nai, notifyType); return; } callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_AVAILABLE, 0); // Whether a network is currently suspended is also an important // element of state to be transferred (it would not otherwise be // delivered by any currently available mechanism). if (nai.networkInfo.getState() == NetworkInfo.State.SUSPENDED) { callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_SUSPENDED, 0); } } callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_CAP_CHANGED, 0); callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_IP_CHANGED, 0); } } private void sendLegacyNetworkBroadcast(NetworkAgentInfo nai, DetailedState state, int type) { private void sendLegacyNetworkBroadcast(NetworkAgentInfo nai, DetailedState state, int type) { Loading tests/net/java/com/android/server/ConnectivityServiceTest.java +5 −9 Original line number Original line Diff line number Diff line Loading @@ -1176,16 +1176,12 @@ public class ConnectivityServiceTest extends AndroidTestCase { void expectAvailableCallbacks(MockNetworkAgent agent, boolean expectSuspended, int timeoutMs) { void expectAvailableCallbacks(MockNetworkAgent agent, boolean expectSuspended, int timeoutMs) { expectCallback(CallbackState.AVAILABLE, agent, timeoutMs); expectCallback(CallbackState.AVAILABLE, agent, timeoutMs); final boolean HAS_DATASYNC_ON_AVAILABLE = false; if (HAS_DATASYNC_ON_AVAILABLE) { if (expectSuspended) { if (expectSuspended) { expectCallback(CallbackState.SUSPENDED, agent, timeoutMs); expectCallback(CallbackState.SUSPENDED, agent, timeoutMs); } } expectCallback(CallbackState.NETWORK_CAPABILITIES, agent, timeoutMs); expectCallback(CallbackState.NETWORK_CAPABILITIES, agent, timeoutMs); expectCallback(CallbackState.LINK_PROPERTIES, agent, timeoutMs); expectCallback(CallbackState.LINK_PROPERTIES, agent, timeoutMs); } } } void expectAvailableCallbacks(MockNetworkAgent agent) { void expectAvailableCallbacks(MockNetworkAgent agent) { expectAvailableCallbacks(agent, false, TIMEOUT_MS); expectAvailableCallbacks(agent, false, TIMEOUT_MS); Loading @@ -1196,7 +1192,7 @@ public class ConnectivityServiceTest extends AndroidTestCase { } } void expectAvailableAndValidatedCallbacks(MockNetworkAgent agent) { void expectAvailableAndValidatedCallbacks(MockNetworkAgent agent) { expectAvailableCallbacks(agent, true, TIMEOUT_MS); expectAvailableCallbacks(agent, false, TIMEOUT_MS); expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, agent); expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, agent); } } Loading Loading
core/java/android/net/ConnectivityManager.java +4 −0 Original line number Original line Diff line number Diff line Loading @@ -1078,6 +1078,8 @@ public class ConnectivityManager { * registerNetworkCallback() are not specific to any particular Network so * registerNetworkCallback() are not specific to any particular Network so * do not cause any updates. * do not cause any updates. * * * TODO: Delete once callers are updated. * * @hide * @hide */ */ public void requestLinkProperties(NetworkCallback networkCallback) { public void requestLinkProperties(NetworkCallback networkCallback) { Loading Loading @@ -1115,6 +1117,8 @@ public class ConnectivityManager { * registerNetworkCallback() are not specific to any particular Network so * registerNetworkCallback() are not specific to any particular Network so * do not cause any updates. * do not cause any updates. * * * TODO: Delete once callers are updated. * * @hide * @hide */ */ public void requestNetworkCapabilities(NetworkCallback networkCallback) { public void requestNetworkCapabilities(NetworkCallback networkCallback) { Loading
services/core/java/com/android/server/ConnectivityService.java +24 −10 Original line number Original line Diff line number Diff line Loading @@ -4351,6 +4351,7 @@ public class ConnectivityService extends IConnectivityManager.Stub mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_LISTENER, nri)); mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_LISTENER, nri)); } } // TODO: Delete once callers are updated. @Override @Override public void requestLinkProperties(NetworkRequest networkRequest) { public void requestLinkProperties(NetworkRequest networkRequest) { ensureNetworkRequestHasType(networkRequest); ensureNetworkRequestHasType(networkRequest); Loading @@ -4359,6 +4360,7 @@ public class ConnectivityService extends IConnectivityManager.Stub EVENT_REQUEST_LINKPROPERTIES, getCallingUid(), 0, networkRequest)); EVENT_REQUEST_LINKPROPERTIES, getCallingUid(), 0, networkRequest)); } } // TODO: Delete once callers are updated. @Override @Override public void requestNetworkCapabilities(NetworkRequest networkRequest) { public void requestNetworkCapabilities(NetworkRequest networkRequest) { ensureNetworkRequestHasType(networkRequest); ensureNetworkRequestHasType(networkRequest); Loading Loading @@ -4879,7 +4881,7 @@ public class ConnectivityService extends IConnectivityManager.Stub if (!nr.isListen()) continue; if (!nr.isListen()) continue; if (nai.satisfies(nr) && !nai.isSatisfyingRequest(nr.requestId)) { if (nai.satisfies(nr) && !nai.isSatisfyingRequest(nr.requestId)) { nai.addRequest(nr); nai.addRequest(nr); notifyNetworkCallback(nai, nri); notifyNetworkAvailable(nai, nri); } } } } } } Loading Loading @@ -5061,7 +5063,7 @@ public class ConnectivityService extends IConnectivityManager.Stub // do this after the default net is switched, but // do this after the default net is switched, but // before LegacyTypeTracker sends legacy broadcasts // before LegacyTypeTracker sends legacy broadcasts for (NetworkRequestInfo nri : addedRequests) notifyNetworkCallback(newNetwork, nri); for (NetworkRequestInfo nri : addedRequests) notifyNetworkAvailable(newNetwork, nri); // Linger any networks that are no longer needed. This should be done after sending the // Linger any networks that are no longer needed. This should be done after sending the // available callback for newNetwork. // available callback for newNetwork. Loading Loading @@ -5224,7 +5226,7 @@ public class ConnectivityService extends IConnectivityManager.Stub } } private void updateNetworkInfo(NetworkAgentInfo networkAgent, NetworkInfo newInfo) { private void updateNetworkInfo(NetworkAgentInfo networkAgent, NetworkInfo newInfo) { NetworkInfo.State state = newInfo.getState(); final NetworkInfo.State state = newInfo.getState(); NetworkInfo oldInfo = null; NetworkInfo oldInfo = null; final int oldScore = networkAgent.getCurrentScore(); final int oldScore = networkAgent.getCurrentScore(); synchronized (networkAgent) { synchronized (networkAgent) { Loading Loading @@ -5351,15 +5353,27 @@ public class ConnectivityService extends IConnectivityManager.Stub sendUpdatedScoreToFactories(nai); sendUpdatedScoreToFactories(nai); } } // notify only this one new request of the current state // Notify only this one new request of the current state. Transfer all the protected void notifyNetworkCallback(NetworkAgentInfo nai, NetworkRequestInfo nri) { // current state by calling NetworkCapabilities and LinkProperties callbacks int notifyType = ConnectivityManager.CALLBACK_AVAILABLE; // so that callers can be guaranteed to have as close to atomicity in state // transfer as can be supported by this current API. protected void notifyNetworkAvailable(NetworkAgentInfo nai, NetworkRequestInfo nri) { mHandler.removeMessages(EVENT_TIMEOUT_NETWORK_REQUEST, nri); mHandler.removeMessages(EVENT_TIMEOUT_NETWORK_REQUEST, nri); if (nri.mPendingIntent == null) { if (nri.mPendingIntent != null) { callCallbackForRequest(nri, nai, notifyType, 0); sendPendingIntentForRequest(nri, nai, ConnectivityManager.CALLBACK_AVAILABLE); } else { // Attempt no subsequent state pushes where intents are involved. sendPendingIntentForRequest(nri, nai, notifyType); return; } callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_AVAILABLE, 0); // Whether a network is currently suspended is also an important // element of state to be transferred (it would not otherwise be // delivered by any currently available mechanism). if (nai.networkInfo.getState() == NetworkInfo.State.SUSPENDED) { callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_SUSPENDED, 0); } } callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_CAP_CHANGED, 0); callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_IP_CHANGED, 0); } } private void sendLegacyNetworkBroadcast(NetworkAgentInfo nai, DetailedState state, int type) { private void sendLegacyNetworkBroadcast(NetworkAgentInfo nai, DetailedState state, int type) { Loading
tests/net/java/com/android/server/ConnectivityServiceTest.java +5 −9 Original line number Original line Diff line number Diff line Loading @@ -1176,16 +1176,12 @@ public class ConnectivityServiceTest extends AndroidTestCase { void expectAvailableCallbacks(MockNetworkAgent agent, boolean expectSuspended, int timeoutMs) { void expectAvailableCallbacks(MockNetworkAgent agent, boolean expectSuspended, int timeoutMs) { expectCallback(CallbackState.AVAILABLE, agent, timeoutMs); expectCallback(CallbackState.AVAILABLE, agent, timeoutMs); final boolean HAS_DATASYNC_ON_AVAILABLE = false; if (HAS_DATASYNC_ON_AVAILABLE) { if (expectSuspended) { if (expectSuspended) { expectCallback(CallbackState.SUSPENDED, agent, timeoutMs); expectCallback(CallbackState.SUSPENDED, agent, timeoutMs); } } expectCallback(CallbackState.NETWORK_CAPABILITIES, agent, timeoutMs); expectCallback(CallbackState.NETWORK_CAPABILITIES, agent, timeoutMs); expectCallback(CallbackState.LINK_PROPERTIES, agent, timeoutMs); expectCallback(CallbackState.LINK_PROPERTIES, agent, timeoutMs); } } } void expectAvailableCallbacks(MockNetworkAgent agent) { void expectAvailableCallbacks(MockNetworkAgent agent) { expectAvailableCallbacks(agent, false, TIMEOUT_MS); expectAvailableCallbacks(agent, false, TIMEOUT_MS); Loading @@ -1196,7 +1192,7 @@ public class ConnectivityServiceTest extends AndroidTestCase { } } void expectAvailableAndValidatedCallbacks(MockNetworkAgent agent) { void expectAvailableAndValidatedCallbacks(MockNetworkAgent agent) { expectAvailableCallbacks(agent, true, TIMEOUT_MS); expectAvailableCallbacks(agent, false, TIMEOUT_MS); expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, agent); expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, agent); } } Loading