DO NOT MERGE: Support timeouts for requestNetwork() invocations.

(cherry-pick of 0b7a74842b)
(cherry picked from commit 155a59aa63)

Bug: 21414325
Change-Id: I1a58823a372154589f972b98c4c428eab0e0523e
This commit is contained in:
Erik Kline 2015-11-25 12:49:38 +09:00 • committed by Lorenzo Colitti
commit 5791c5f681

View file

@ -2592,7 +2592,8 @@ public class ConnectivityManager {
/**
* Called if no network is found in the given timeout time. If no timeout is given,
* this will not be called.
* this will not be called. The associated {@link NetworkRequest} will have already
* been removed and released, as if {@link #unregisterNetworkCallback} had been called.
* @hide
*/
public void onUnavailable() {}
@ -2665,6 +2666,26 @@ public class ConnectivityManager {
/** @hide */
public static final int CALLBACK_RESUMED = BASE + 12;
/** @hide */
public static String getCallbackName(int whichCallback) {
switch (whichCallback) {
case CALLBACK_PRECHECK: return "CALLBACK_PRECHECK";
case CALLBACK_AVAILABLE: return "CALLBACK_AVAILABLE";
case CALLBACK_LOSING: return "CALLBACK_LOSING";
case CALLBACK_LOST: return "CALLBACK_LOST";
case CALLBACK_UNAVAIL: return "CALLBACK_UNAVAIL";
case CALLBACK_CAP_CHANGED: return "CALLBACK_CAP_CHANGED";
case CALLBACK_IP_CHANGED: return "CALLBACK_IP_CHANGED";
case CALLBACK_RELEASED: return "CALLBACK_RELEASED";
case CALLBACK_EXIT: return "CALLBACK_EXIT";
case EXPIRE_LEGACY_REQUEST: return "EXPIRE_LEGACY_REQUEST";
case CALLBACK_SUSPENDED: return "CALLBACK_SUSPENDED";
case CALLBACK_RESUMED: return "CALLBACK_RESUMED";
default:
return Integer.toString(whichCallback);
}
}
private class CallbackHandler extends Handler {
private final HashMap<NetworkRequest, NetworkCallback>mCallbackMap;
private final AtomicInteger mRefCount;
@ -2831,7 +2852,7 @@ public class ConnectivityManager {
private final static int REQUEST = 2;
private NetworkRequest sendRequestForNetwork(NetworkCapabilities need,
NetworkCallback networkCallback, int timeoutSec, int action,
NetworkCallback networkCallback, int timeoutMs, int action,
int legacyType) {
if (networkCallback == null) {
throw new IllegalArgumentException("null NetworkCallback");
@ -2847,7 +2868,7 @@ public class ConnectivityManager {
new Messenger(sCallbackHandler), new Binder());
} else {
networkCallback.networkRequest = mService.requestNetwork(need,
new Messenger(sCallbackHandler), timeoutSec, new Binder(), legacyType);
new Messenger(sCallbackHandler), timeoutMs, new Binder(), legacyType);
}
if (networkCallback.networkRequest != null) {
sNetworkCallback.put(networkCallback.networkRequest, networkCallback);