diff options
12 files changed, 226 insertions, 210 deletions
diff --git a/api/current.txt b/api/current.txt index cc57576849a8..afdfc3190487 100644 --- a/api/current.txt +++ b/api/current.txt @@ -15947,28 +15947,25 @@ package android.net { method public deprecated int getNetworkPreference(); method public static android.net.Network getProcessDefaultNetwork(); method public boolean isActiveNetworkMetered(); - method public boolean isNetworkActive(); + method public boolean isDefaultNetworkActive(); method public static boolean isNetworkTypeValid(int); - method public android.net.NetworkRequest listenForNetwork(android.net.NetworkCapabilities, android.net.ConnectivityManager.NetworkCallbackListener); - method public void registerNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener); - method public void releaseNetworkRequest(android.net.NetworkRequest); + method public void registerDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener); + method public void registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback); method public void reportBadNetwork(android.net.Network); - method public android.net.NetworkRequest requestNetwork(android.net.NetworkCapabilities, android.net.ConnectivityManager.NetworkCallbackListener); - method public android.net.NetworkRequest requestNetwork(android.net.NetworkCapabilities, android.app.PendingIntent); + method public void requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback); method public deprecated boolean requestRouteToHost(int, int); method public deprecated void setNetworkPreference(int); method public static boolean setProcessDefaultNetwork(android.net.Network); method public deprecated int startUsingNetworkFeature(int, java.lang.String); method public deprecated int stopUsingNetworkFeature(int, java.lang.String); - method public void unregisterNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener); + method public void unregisterDefaultNetworkActiveListener(android.net.ConnectivityManager.OnNetworkActiveListener); + method public void unregisterNetworkCallback(android.net.ConnectivityManager.NetworkCallback); field public static final deprecated java.lang.String ACTION_BACKGROUND_DATA_SETTING_CHANGED = "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED"; field public static final java.lang.String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE"; field public static final deprecated int DEFAULT_NETWORK_PREFERENCE = 1; // 0x1 field public static final java.lang.String EXTRA_EXTRA_INFO = "extraInfo"; field public static final java.lang.String EXTRA_IS_FAILOVER = "isFailover"; field public static final deprecated java.lang.String EXTRA_NETWORK_INFO = "networkInfo"; - field public static final java.lang.String EXTRA_NETWORK_REQUEST_NETWORK = "networkRequestNetwork"; - field public static final java.lang.String EXTRA_NETWORK_REQUEST_NETWORK_CAPABILITIES = "networkRequestNetworkCapabilities"; field public static final java.lang.String EXTRA_NETWORK_TYPE = "networkType"; field public static final java.lang.String EXTRA_NO_CONNECTIVITY = "noConnectivity"; field public static final java.lang.String EXTRA_OTHER_NETWORK_INFO = "otherNetwork"; @@ -15985,14 +15982,13 @@ package android.net { field public static final int TYPE_WIMAX = 6; // 0x6 } - public static class ConnectivityManager.NetworkCallbackListener { - ctor public ConnectivityManager.NetworkCallbackListener(); - method public void onAvailable(android.net.NetworkRequest, android.net.Network); - method public void onLinkPropertiesChanged(android.net.NetworkRequest, android.net.Network, android.net.LinkProperties); - method public void onLosing(android.net.NetworkRequest, android.net.Network, int); - method public void onLost(android.net.NetworkRequest, android.net.Network); - method public void onNetworkCapabilitiesChanged(android.net.NetworkRequest, android.net.Network, android.net.NetworkCapabilities); - method public void onReleased(android.net.NetworkRequest); + public static class ConnectivityManager.NetworkCallback { + ctor public ConnectivityManager.NetworkCallback(); + method public void onAvailable(android.net.Network); + method public void onCapabilitiesChanged(android.net.Network, android.net.NetworkCapabilities); + method public void onLinkPropertiesChanged(android.net.Network, android.net.LinkProperties); + method public void onLosing(android.net.Network, int); + method public void onLost(android.net.Network); } public static abstract interface ConnectivityManager.OnNetworkActiveListener { diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 65d47261e658..7faf8ef046c3 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -868,10 +868,10 @@ public class ConnectivityManager { return -1; } - NetworkRequest request = removeRequestForFeature(netCap); - if (request != null) { + NetworkCallback networkCallback = removeRequestForFeature(netCap); + if (networkCallback != null) { Log.d(TAG, "stopUsingNetworkFeature for " + networkType + ", " + feature); - releaseNetworkRequest(request); + unregisterNetworkCallback(networkCallback); } return 1; } @@ -981,15 +981,15 @@ public class ConnectivityManager { int expireSequenceNumber; Network currentNetwork; int delay = -1; - NetworkCallbackListener networkCallbackListener = new NetworkCallbackListener() { + NetworkCallback networkCallback = new NetworkCallback() { @Override - public void onAvailable(NetworkRequest request, Network network) { + public void onAvailable(Network network) { currentNetwork = network; Log.d(TAG, "startUsingNetworkFeature got Network:" + network); setProcessDefaultNetworkForHostResolution(network); } @Override - public void onLost(NetworkRequest request, Network network) { + public void onLost(Network network) { if (network.equals(currentNetwork)) { currentNetwork = null; setProcessDefaultNetworkForHostResolution(null); @@ -1023,7 +1023,7 @@ public class ConnectivityManager { if (l == null) return; ourSeqNum = l.expireSequenceNumber; if (l.expireSequenceNumber == sequenceNum) { - releaseNetworkRequest(l.networkRequest); + unregisterNetworkCallback(l.networkCallback); sLegacyRequests.remove(netCap); } } @@ -1040,7 +1040,7 @@ public class ConnectivityManager { l.networkCapabilities = netCap; l.delay = delay; l.expireSequenceNumber = 0; - l.networkRequest = sendRequestForNetwork(netCap, l.networkCallbackListener, 0, + l.networkRequest = sendRequestForNetwork(netCap, l.networkCallback, 0, REQUEST, type); if (l.networkRequest == null) return null; sLegacyRequests.put(netCap, l); @@ -1056,11 +1056,11 @@ public class ConnectivityManager { } } - private NetworkRequest removeRequestForFeature(NetworkCapabilities netCap) { + private NetworkCallback removeRequestForFeature(NetworkCapabilities netCap) { synchronized (sLegacyRequests) { LegacyRequest l = sLegacyRequests.remove(netCap); if (l == null) return null; - return l.networkRequest; + return l.networkCallback; } } @@ -1183,8 +1183,8 @@ public class ConnectivityManager { } /** - * Callback for use with {@link ConnectivityManager#registerNetworkActiveListener} to - * find out when the current network has gone in to a high power state. + * Callback for use with {@link ConnectivityManager#registerDefaultNetworkActiveListener} + * to find out when the system default network has gone in to a high power state. */ public interface OnNetworkActiveListener { /** @@ -1193,7 +1193,7 @@ public class ConnectivityManager { * operations. Note that this listener only tells you when the network becomes * active; if at any other time you want to know whether it is active (and thus okay * to initiate network traffic), you can retrieve its instantaneous state with - * {@link ConnectivityManager#isNetworkActive}. + * {@link ConnectivityManager#isDefaultNetworkActive}. */ public void onNetworkActive(); } @@ -1214,13 +1214,18 @@ public class ConnectivityManager { = new ArrayMap<OnNetworkActiveListener, INetworkActivityListener>(); /** - * Start listening to reports when the data network is active, meaning it is - * a good time to perform network traffic. Use {@link #isNetworkActive()} - * to determine the current state of the network after registering the listener. + * Start listening to reports when the system's default data network is active, meaning it is + * a good time to perform network traffic. Use {@link #isDefaultNetworkActive()} + * to determine the current state of the system's default network after registering the + * listener. + * <p> + * If the process default network has been set with + * {@link ConnectivityManager#setProcessDefaultNetwork} this function will not + * reflect the process's default, but the system default. * * @param l The listener to be told when the network is active. */ - public void registerNetworkActiveListener(final OnNetworkActiveListener l) { + public void registerDefaultNetworkActiveListener(final OnNetworkActiveListener l) { INetworkActivityListener rl = new INetworkActivityListener.Stub() { @Override public void onNetworkActive() throws RemoteException { @@ -1237,11 +1242,11 @@ public class ConnectivityManager { /** * Remove network active listener previously registered with - * {@link #registerNetworkActiveListener}. + * {@link #registerDefaultNetworkActiveListener}. * * @param l Previously registered listener. */ - public void unregisterNetworkActiveListener(OnNetworkActiveListener l) { + public void unregisterDefaultNetworkActiveListener(OnNetworkActiveListener l) { INetworkActivityListener rl = mNetworkActivityListeners.get(l); if (rl == null) { throw new IllegalArgumentException("Listener not registered: " + l); @@ -1260,7 +1265,7 @@ public class ConnectivityManager { * this state. This method tells you whether right now is currently a good time to * initiate network traffic, as the network is already active. */ - public boolean isNetworkActive() { + public boolean isDefaultNetworkActive() { try { return getNetworkManagementService().isNetworkActive(); } catch (RemoteException e) { @@ -1892,7 +1897,7 @@ public class ConnectivityManager { * Base class for NetworkRequest callbacks. Used for notifications about network * changes. Should be extended by applications wanting notifications. */ - public static class NetworkCallbackListener { + public static class NetworkCallback { /** @hide */ public static final int PRECHECK = 1; /** @hide */ @@ -1915,78 +1920,68 @@ public class ConnectivityManager { * Called whenever the framework connects to a network that it may use to * satisfy this request */ - public void onPreCheck(NetworkRequest networkRequest, Network network) {} + public void onPreCheck(Network network) {} /** * Called when the framework connects and has declared new network ready for use. + * This callback may be called more than once if the {@link Network} that is + * satisfying the request changes. * - * @param networkRequest The {@link NetworkRequest} used to initiate the request. * @param network The {@link Network} of the satisfying network. */ - public void onAvailable(NetworkRequest networkRequest, Network network) {} + public void onAvailable(Network network) {} /** * Called when the network is about to be disconnected. Often paired with an - * {@link NetworkCallbackListener#onAvailable} call with the new replacement network + * {@link NetworkCallback#onAvailable} call with the new replacement network * for graceful handover. This may not be called if we have a hard loss * (loss without warning). This may be followed by either a - * {@link NetworkCallbackListener#onLost} call or a - * {@link NetworkCallbackListener#onAvailable} call for this network depending + * {@link NetworkCallback#onLost} call or a + * {@link NetworkCallback#onAvailable} call for this network depending * on whether we lose or regain it. * - * @param networkRequest The {@link NetworkRequest} used to initiate the request. - * @param network The {@link Network} of the failing network. - * @param maxSecToLive The time in seconds the framework will attempt to keep the - * network connected. Note that the network may suffers a + * @param network The {@link Network} that is about to be disconnected. + * @param maxMsToLive The time in ms the framework will attempt to keep the + * network connected. Note that the network may suffer a * hard loss at any time. */ - public void onLosing(NetworkRequest networkRequest, Network network, int maxSecToLive) {} + public void onLosing(Network network, int maxMsToLive) {} /** * Called when the framework has a hard loss of the network or when the * graceful failure ends. * - * @param networkRequest The {@link NetworkRequest} used to initiate the request. * @param network The {@link Network} lost. */ - public void onLost(NetworkRequest networkRequest, Network network) {} + public void onLost(Network network) {} /** * Called if no network is found in the given timeout time. If no timeout is given, * this will not be called. * @hide */ - public void onUnavailable(NetworkRequest networkRequest) {} + public void onUnavailable() {} /** * Called when the network the framework connected to for this request * changes capabilities but still satisfies the stated need. * - * @param networkRequest The {@link NetworkRequest} used to initiate the request. * @param network The {@link Network} whose capabilities have changed. * @param networkCapabilities The new {@link NetworkCapabilities} for this network. */ - public void onNetworkCapabilitiesChanged(NetworkRequest networkRequest, Network network, + public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) {} /** * Called when the network the framework connected to for this request * changes {@link LinkProperties}. * - * @param networkRequest The {@link NetworkRequest} used to initiate the request. * @param network The {@link Network} whose link properties have changed. * @param linkProperties The new {@link LinkProperties} for this network. */ - public void onLinkPropertiesChanged(NetworkRequest networkRequest, Network network, - LinkProperties linkProperties) {} + public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {} - /** - * Called when a {@link #releaseNetworkRequest} call concludes and the registered - * callbacks will no longer be used. - * - * @param networkRequest The {@link NetworkRequest} used to initiate the request. - */ - public void onReleased(NetworkRequest networkRequest) {} + private NetworkRequest networkRequest; } private static final int BASE = Protocol.BASE_CONNECTIVITY_MANAGER; @@ -2012,12 +2007,12 @@ public class ConnectivityManager { private static final int EXPIRE_LEGACY_REQUEST = BASE + 10; private class CallbackHandler extends Handler { - private final HashMap<NetworkRequest, NetworkCallbackListener>mCallbackMap; + private final HashMap<NetworkRequest, NetworkCallback>mCallbackMap; private final AtomicInteger mRefCount; private static final String TAG = "ConnectivityManager.CallbackHandler"; private final ConnectivityManager mCm; - CallbackHandler(Looper looper, HashMap<NetworkRequest, NetworkCallbackListener>callbackMap, + CallbackHandler(Looper looper, HashMap<NetworkRequest, NetworkCallback>callbackMap, AtomicInteger refCount, ConnectivityManager cm) { super(looper); mCallbackMap = callbackMap; @@ -2031,9 +2026,9 @@ public class ConnectivityManager { switch (message.what) { case CALLBACK_PRECHECK: { NetworkRequest request = getNetworkRequest(message); - NetworkCallbackListener callbacks = getCallbacks(request); + NetworkCallback callbacks = getCallbacks(request); if (callbacks != null) { - callbacks.onPreCheck(request, getNetwork(message)); + callbacks.onPreCheck(getNetwork(message)); } else { Log.e(TAG, "callback not found for PRECHECK message"); } @@ -2041,9 +2036,9 @@ public class ConnectivityManager { } case CALLBACK_AVAILABLE: { NetworkRequest request = getNetworkRequest(message); - NetworkCallbackListener callbacks = getCallbacks(request); + NetworkCallback callbacks = getCallbacks(request); if (callbacks != null) { - callbacks.onAvailable(request, getNetwork(message)); + callbacks.onAvailable(getNetwork(message)); } else { Log.e(TAG, "callback not found for AVAILABLE message"); } @@ -2051,9 +2046,9 @@ public class ConnectivityManager { } case CALLBACK_LOSING: { NetworkRequest request = getNetworkRequest(message); - NetworkCallbackListener callbacks = getCallbacks(request); + NetworkCallback callbacks = getCallbacks(request); if (callbacks != null) { - callbacks.onLosing(request, getNetwork(message), message.arg1); + callbacks.onLosing(getNetwork(message), message.arg1); } else { Log.e(TAG, "callback not found for LOSING message"); } @@ -2061,9 +2056,9 @@ public class ConnectivityManager { } case CALLBACK_LOST: { NetworkRequest request = getNetworkRequest(message); - NetworkCallbackListener callbacks = getCallbacks(request); + NetworkCallback callbacks = getCallbacks(request); if (callbacks != null) { - callbacks.onLost(request, getNetwork(message)); + callbacks.onLost(getNetwork(message)); } else { Log.e(TAG, "callback not found for LOST message"); } @@ -2071,12 +2066,12 @@ public class ConnectivityManager { } case CALLBACK_UNAVAIL: { NetworkRequest req = (NetworkRequest)message.obj; - NetworkCallbackListener callbacks = null; + NetworkCallback callbacks = null; synchronized(mCallbackMap) { callbacks = mCallbackMap.get(req); } if (callbacks != null) { - callbacks.onUnavailable(req); + callbacks.onUnavailable(); } else { Log.e(TAG, "callback not found for UNAVAIL message"); } @@ -2084,12 +2079,12 @@ public class ConnectivityManager { } case CALLBACK_CAP_CHANGED: { NetworkRequest request = getNetworkRequest(message); - NetworkCallbackListener callbacks = getCallbacks(request); + NetworkCallback callbacks = getCallbacks(request); if (callbacks != null) { Network network = getNetwork(message); NetworkCapabilities cap = mCm.getNetworkCapabilities(network); - callbacks.onNetworkCapabilitiesChanged(request, network, cap); + callbacks.onCapabilitiesChanged(network, cap); } else { Log.e(TAG, "callback not found for CHANGED message"); } @@ -2097,12 +2092,12 @@ public class ConnectivityManager { } case CALLBACK_IP_CHANGED: { NetworkRequest request = getNetworkRequest(message); - NetworkCallbackListener callbacks = getCallbacks(request); + NetworkCallback callbacks = getCallbacks(request); if (callbacks != null) { Network network = getNetwork(message); LinkProperties lp = mCm.getLinkProperties(network); - callbacks.onLinkPropertiesChanged(request, network, lp); + callbacks.onLinkPropertiesChanged(network, lp); } else { Log.e(TAG, "callback not found for CHANGED message"); } @@ -2110,20 +2105,19 @@ public class ConnectivityManager { } case CALLBACK_RELEASED: { NetworkRequest req = (NetworkRequest)message.obj; - NetworkCallbackListener callbacks = null; + NetworkCallback callbacks = null; synchronized(mCallbackMap) { callbacks = mCallbackMap.remove(req); } if (callbacks != null) { - callbacks.onReleased(req); + synchronized(mRefCount) { + if (mRefCount.decrementAndGet() == 0) { + getLooper().quit(); + } + } } else { Log.e(TAG, "callback not found for CANCELED message"); } - synchronized(mRefCount) { - if (mRefCount.decrementAndGet() == 0) { - getLooper().quit(); - } - } break; } case CALLBACK_EXIT: { @@ -2141,7 +2135,7 @@ public class ConnectivityManager { private NetworkRequest getNetworkRequest(Message msg) { return (NetworkRequest)(msg.obj); } - private NetworkCallbackListener getCallbacks(NetworkRequest req) { + private NetworkCallback getCallbacks(NetworkRequest req) { synchronized(mCallbackMap) { return mCallbackMap.get(req); } @@ -2149,7 +2143,7 @@ public class ConnectivityManager { private Network getNetwork(Message msg) { return new Network(msg.arg2); } - private NetworkCallbackListener removeCallbacks(Message msg) { + private NetworkCallback removeCallbacks(Message msg) { NetworkRequest req = (NetworkRequest)msg.obj; synchronized(mCallbackMap) { return mCallbackMap.remove(req); @@ -2157,19 +2151,19 @@ public class ConnectivityManager { } } - private void addCallbackListener() { + private void incCallbackHandlerRefCount() { synchronized(sCallbackRefCount) { if (sCallbackRefCount.incrementAndGet() == 1) { // TODO - switch this over to a ManagerThread or expire it when done HandlerThread callbackThread = new HandlerThread("ConnectivityManager"); callbackThread.start(); sCallbackHandler = new CallbackHandler(callbackThread.getLooper(), - sNetworkCallbackListener, sCallbackRefCount, this); + sNetworkCallback, sCallbackRefCount, this); } } } - private void removeCallbackListener() { + private void decCallbackHandlerRefCount() { synchronized(sCallbackRefCount) { if (sCallbackRefCount.decrementAndGet() == 0) { sCallbackHandler.obtainMessage(CALLBACK_EXIT).sendToTarget(); @@ -2178,8 +2172,8 @@ public class ConnectivityManager { } } - static final HashMap<NetworkRequest, NetworkCallbackListener> sNetworkCallbackListener = - new HashMap<NetworkRequest, NetworkCallbackListener>(); + static final HashMap<NetworkRequest, NetworkCallback> sNetworkCallback = + new HashMap<NetworkRequest, NetworkCallback>(); static final AtomicInteger sCallbackRefCount = new AtomicInteger(0); static CallbackHandler sCallbackHandler = null; @@ -2187,51 +2181,48 @@ public class ConnectivityManager { private final static int REQUEST = 2; private NetworkRequest sendRequestForNetwork(NetworkCapabilities need, - NetworkCallbackListener networkCallbackListener, int timeoutSec, int action, + NetworkCallback networkCallback, int timeoutSec, int action, int legacyType) { - NetworkRequest networkRequest = null; - if (networkCallbackListener == null) { - throw new IllegalArgumentException("null NetworkCallbackListener"); + if (networkCallback == null) { + throw new IllegalArgumentException("null NetworkCallback"); } if (need == null) throw new IllegalArgumentException("null NetworkCapabilities"); try { - addCallbackListener(); + incCallbackHandlerRefCount(); if (action == LISTEN) { - networkRequest = mService.listenForNetwork(need, new Messenger(sCallbackHandler), - new Binder()); + networkCallback.networkRequest = mService.listenForNetwork(need, + new Messenger(sCallbackHandler), new Binder()); } else { - networkRequest = mService.requestNetwork(need, new Messenger(sCallbackHandler), - timeoutSec, new Binder(), legacyType); + networkCallback.networkRequest = mService.requestNetwork(need, + new Messenger(sCallbackHandler), timeoutSec, new Binder(), legacyType); } - if (networkRequest != null) { - synchronized(sNetworkCallbackListener) { - sNetworkCallbackListener.put(networkRequest, networkCallbackListener); + if (networkCallback.networkRequest != null) { + synchronized(sNetworkCallback) { + sNetworkCallback.put(networkCallback.networkRequest, networkCallback); } } } catch (RemoteException e) {} - if (networkRequest == null) removeCallbackListener(); - return networkRequest; + if (networkCallback.networkRequest == null) decCallbackHandlerRefCount(); + return networkCallback.networkRequest; } /** * Request a network to satisfy a set of {@link NetworkCapabilities}. * * This {@link NetworkRequest} will live until released via - * {@link #releaseNetworkRequest} or the calling application exits. + * {@link #unregisterNetworkCallback} or the calling application exits. * Status of the request can be followed by listening to the various - * callbacks described in {@link NetworkCallbackListener}. The {@link Network} + * callbacks described in {@link NetworkCallback}. The {@link Network} * can be used to direct traffic to the network. * - * @param need {@link NetworkCapabilities} required by this request. - * @param networkCallbackListener The {@link NetworkCallbackListener} to be utilized for this - * request. Note the callbacks can be shared by multiple - * requests and the NetworkRequest token utilized to - * determine to which request the callback relates. - * @return A {@link NetworkRequest} object identifying the request. + * @param request {@link NetworkRequest} describing this request. + * @param networkCallback The {@link NetworkCallback} to be utilized for this + * request. Note the callback must not be shared - they + * uniquely specify this request. */ - public NetworkRequest requestNetwork(NetworkCapabilities need, - NetworkCallbackListener networkCallbackListener) { - return sendRequestForNetwork(need, networkCallbackListener, 0, REQUEST, TYPE_NONE); + public void requestNetwork(NetworkRequest request, NetworkCallback networkCallback) { + sendRequestForNetwork(request.networkCapabilities, networkCallback, 0, + REQUEST, TYPE_NONE); } /** @@ -2239,53 +2230,53 @@ public class ConnectivityManager { * by a timeout. * * This function behaves identically to the non-timedout version, but if a suitable - * network is not found within the given time (in Seconds) the - * {@link NetworkCallbackListener#unavailable} callback is called. The request must + * network is not found within the given time (in milliseconds) the + * {@link NetworkCallback#unavailable} callback is called. The request must * still be released normally by calling {@link releaseNetworkRequest}. - * @param need {@link NetworkCapabilities} required by this request. - * @param networkCallbackListener The callbacks to be utilized for this request. Note - * the callbacks can be shared by multiple requests and - * the NetworkRequest token utilized to determine to which - * request the callback relates. - * @param timeoutSec The time in seconds to attempt looking for a suitable network - * before {@link NetworkCallbackListener#unavailable} is called. - * @return A {@link NetworkRequest} object identifying the request. + * @param request {@link NetworkRequest} describing this request. + * @param networkCallback The callbacks to be utilized for this request. Note + * the callbacks must not be shared - they uniquely specify + * this request. + * @param timeoutMs The time in milliseconds to attempt looking for a suitable network + * before {@link NetworkCallback#unavailable} is called. * @hide */ - public NetworkRequest requestNetwork(NetworkCapabilities need, - NetworkCallbackListener networkCallbackListener, int timeoutSec) { - return sendRequestForNetwork(need, networkCallbackListener, timeoutSec, REQUEST, - TYPE_NONE); + public void requestNetwork(NetworkRequest request, NetworkCallback networkCallback, + int timeoutMs) { + sendRequestForNetwork(request.networkCapabilities, networkCallback, timeoutMs, + REQUEST, TYPE_NONE); } /** - * The maximum number of seconds the framework will look for a suitable network + * The maximum number of milliseconds the framework will look for a suitable network * during a timeout-equiped call to {@link requestNetwork}. * {@hide} */ - public final static int MAX_NETWORK_REQUEST_TIMEOUT_SEC = 100 * 60; + public final static int MAX_NETWORK_REQUEST_TIMEOUT_MS = 100 * 60 * 1000; /** * The lookup key for a {@link Network} object included with the intent after * succesfully finding a network for the applications request. Retrieve it with * {@link android.content.Intent#getParcelableExtra(String)}. + * @hide */ public static final String EXTRA_NETWORK_REQUEST_NETWORK = "networkRequestNetwork"; /** - * The lookup key for a {@link NetworkCapabilities} object included with the intent after + * The lookup key for a {@link NetworkRequest} object included with the intent after * succesfully finding a network for the applications request. Retrieve it with * {@link android.content.Intent#getParcelableExtra(String)}. + * @hide */ - public static final String EXTRA_NETWORK_REQUEST_NETWORK_CAPABILITIES = - "networkRequestNetworkCapabilities"; + public static final String EXTRA_NETWORK_REQUEST_NETWORK_REQUEST = + "networkRequestNetworkRequest"; /** * Request a network to satisfy a set of {@link NetworkCapabilities}. * - * This function behavies identically to the callback-equiped version, but instead - * of {@link NetworkCallbackListener} a {@link PendingIntent} is used. This means + * This function behavies identically to the version that takes a NetworkCallback, but instead + * of {@link NetworkCallback} a {@link PendingIntent} is used. This means * the request may outlive the calling application and get called back when a suitable * network is found. * <p> @@ -2294,10 +2285,10 @@ public class ConnectivityManager { * <receiver> tag in an AndroidManifest.xml file * <p> * The operation Intent is delivered with two extras, a {@link Network} typed - * extra called {@link #EXTRA_NETWORK_REQUEST_NETWORK} and a {@link NetworkCapabilities} - * typed extra called {@link #EXTRA_NETWORK_REQUEST_NETWORK_CAPABILITIES} containing + * extra called {@link #EXTRA_NETWORK_REQUEST_NETWORK} and a {@link NetworkRequest} + * typed extra called {@link #EXTRA_NETWORK_REQUEST_NETWORK_REQUEST} containing * the original requests parameters. It is important to create a new, - * {@link NetworkCallbackListener} based request before completing the processing of the + * {@link NetworkCallback} based request before completing the processing of the * Intent to reserve the network or it will be released shortly after the Intent * is processed. * <p> @@ -2305,51 +2296,49 @@ public class ConnectivityManager { * two Intents defined by {@link Intent#filterEquals}), then it will be removed and * replaced by this one, effectively releasing the previous {@link NetworkRequest}. * <p> - * The request may be released normally by calling {@link #releaseNetworkRequest}. + * The request may be released normally by calling {@link #unregisterNetworkCallback}. * - * @param need {@link NetworkCapabilities} required by this request. + * @param request {@link NetworkRequest} describing this request. * @param operation Action to perform when the network is available (corresponds - * to the {@link NetworkCallbackListener#onAvailable} call. Typically + * to the {@link NetworkCallback#onAvailable} call. Typically * comes from {@link PendingIntent#getBroadcast}. - * @return A {@link NetworkRequest} object identifying the request. + * @hide */ - public NetworkRequest requestNetwork(NetworkCapabilities need, PendingIntent operation) { + public void requestNetwork(NetworkRequest request, PendingIntent operation) { try { - return mService.pendingRequestForNetwork(need, operation); + mService.pendingRequestForNetwork(request.networkCapabilities, operation); } catch (RemoteException e) {} - return null; } /** * Registers to receive notifications about all networks which satisfy the given - * {@link NetworkCapabilities}. The callbacks will continue to be called until - * either the application exits or the request is released using - * {@link #releaseNetworkRequest}. + * {@link NetworkRequest}. The callbacks will continue to be called until + * either the application exits or {@link #unregisterNetworkCallback} is called * - * @param need {@link NetworkCapabilities} required by this request. - * @param networkCallbackListener The {@link NetworkCallbackListener} to be called as suitable - * networks change state. - * @return A {@link NetworkRequest} object identifying the request. + * @param request {@link NetworkRequest} describing this request. + * @param networkCallback The {@link NetworkCallback} that the system will call as suitable + * networks change state. */ - public NetworkRequest listenForNetwork(NetworkCapabilities need, - NetworkCallbackListener networkCallbackListener) { - return sendRequestForNetwork(need, networkCallbackListener, 0, LISTEN, TYPE_NONE); + public void registerNetworkCallback(NetworkRequest request, NetworkCallback networkCallback) { + sendRequestForNetwork(request.networkCapabilities, networkCallback, 0, LISTEN, TYPE_NONE); } /** - * Releases a {@link NetworkRequest} generated either through a {@link #requestNetwork} - * or a {@link #listenForNetwork} call. The {@link NetworkCallbackListener} given in the - * earlier call may continue receiving calls until the - * {@link NetworkCallbackListener#onReleased} function is called, signifying the end - * of the request. + * Unregisters callbacks about and possibly releases networks originating from + * {@link #requestNetwork} and {@link #registerNetworkCallback} calls. If the + * given {@code NetworkCallback} had previosuly been used with {@code #requestNetwork}, + * any networks that had been connected to only to satisfy that request will be + * disconnected. * - * @param networkRequest The {@link NetworkRequest} generated by an earlier call to - * {@link #requestNetwork} or {@link #listenForNetwork}. + * @param networkCallback The {@link NetworkCallback} used when making the request. */ - public void releaseNetworkRequest(NetworkRequest networkRequest) { - if (networkRequest == null) throw new IllegalArgumentException("null NetworkRequest"); + public void unregisterNetworkCallback(NetworkCallback networkCallback) { + if (networkCallback == null || networkCallback.networkRequest == null || + networkCallback.networkRequest.requestId == REQUEST_ID_UNSET) { + throw new IllegalArgumentException("Invalid NetworkCallback"); + } try { - mService.releaseNetworkRequest(networkRequest); + mService.releaseNetworkRequest(networkCallback.networkRequest); } catch (RemoteException e) {} } diff --git a/core/java/android/net/Network.java b/core/java/android/net/Network.java index d933f26c782f..318aabe76a77 100644 --- a/core/java/android/net/Network.java +++ b/core/java/android/net/Network.java @@ -29,8 +29,9 @@ import javax.net.SocketFactory; /** * Identifies a {@code Network}. This is supplied to applications via - * {@link ConnectivityManager.NetworkCallbackListener} in response to - * {@link ConnectivityManager#requestNetwork} or {@link ConnectivityManager#listenForNetwork}. + * {@link ConnectivityManager.NetworkCallback} in response to the active + * {@link ConnectivityManager#requestNetwork} or passive + * {@link ConnectivityManager#registerNetworkCallback} calls. * It is used to direct traffic to the given {@code Network}, either on a {@link Socket} basis * through a targeted {@link SocketFactory} or process-wide via * {@link ConnectivityManager#setProcessDefaultNetwork}. diff --git a/core/java/android/net/NetworkRequest.java b/core/java/android/net/NetworkRequest.java index 7911c729d338..36dc57398148 100644 --- a/core/java/android/net/NetworkRequest.java +++ b/core/java/android/net/NetworkRequest.java @@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger; /** * Defines a request for a network, made through {@link NetworkRequest.Builder} and used * to request a network via {@link ConnectivityManager#requestNetwork} or listen for changes - * via {@link ConnectivityManager#listenForNetwork}. + * via {@link ConnectivityManager#registerNetworkCallback}. */ public class NetworkRequest implements Parcelable { /** diff --git a/libs/hwui/TessellationCache.cpp b/libs/hwui/TessellationCache.cpp index e6bc873041cd..37d53479e16b 100644 --- a/libs/hwui/TessellationCache.cpp +++ b/libs/hwui/TessellationCache.cpp @@ -39,6 +39,7 @@ namespace uirenderer { TessellationCache::Description::Description() : type(kNone) + , aa(false) , cap(SkPaint::kDefault_Cap) , style(SkPaint::kFill_Style) , strokeWidth(1.0f) { @@ -47,6 +48,7 @@ TessellationCache::Description::Description() TessellationCache::Description::Description(Type type) : type(type) + , aa(false) , cap(SkPaint::kDefault_Cap) , style(SkPaint::kFill_Style) , strokeWidth(1.0f) { @@ -55,6 +57,7 @@ TessellationCache::Description::Description(Type type) TessellationCache::Description::Description(Type type, const SkPaint* paint) : type(type) + , aa(paint->isAntiAlias()) , cap(paint->getStrokeCap()) , style(paint->getStyle()) , strokeWidth(paint->getStrokeWidth()) { @@ -63,6 +66,7 @@ TessellationCache::Description::Description(Type type, const SkPaint* paint) hash_t TessellationCache::Description::hash() const { uint32_t hash = JenkinsHashMix(0, type); + hash = JenkinsHashMix(hash, aa); hash = JenkinsHashMix(hash, cap); hash = JenkinsHashMix(hash, style); hash = JenkinsHashMix(hash, android::hash_type(strokeWidth)); diff --git a/libs/hwui/TessellationCache.h b/libs/hwui/TessellationCache.h index 8f37230d7eaf..d4ff9434cee8 100644 --- a/libs/hwui/TessellationCache.h +++ b/libs/hwui/TessellationCache.h @@ -55,6 +55,7 @@ public: }; Type type; + bool aa; SkPaint::Cap cap; SkPaint::Style style; float strokeWidth; diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java index 3fa8b99afafe..e8f3745af5e7 100644 --- a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java +++ b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java @@ -34,7 +34,6 @@ import android.os.Handler; import android.os.SystemClock; import android.os.UserHandle; import android.provider.Settings; -import android.util.Log; import android.util.Slog; import android.view.ContextThemeWrapper; import android.view.View; @@ -126,25 +125,16 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { updateNotification(); } - private void cancelOther(int showing) { - if (mShowing != SHOWING_NOTHING && mShowing != showing) { - mNoMan.cancel(TAG_NOTIFICATION, ID_NOTIFICATION); // workaround no HUN on updates - } - } - private void updateNotification() { Slog.d(TAG, "updateNotification mWarning=" + mWarning + " mSaver=" + mSaver + " mInvalidCharger=" + mInvalidCharger); if (mInvalidCharger) { - cancelOther(SHOWING_INVALID_CHARGER); showInvalidChargerNotification(); mShowing = SHOWING_INVALID_CHARGER; } else if (mWarning) { - cancelOther(SHOWING_WARNING); showWarningNotification(); mShowing = SHOWING_WARNING; } else if (mSaver) { - cancelOther(SHOWING_SAVER); showSaverNotification(); mShowing = SHOWING_SAVER; } else { @@ -312,6 +302,12 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { @Override public void dismissInvalidChargerWarning() { + dismissInvalidChargerNotification(); + mFallbackDialogs.dismissInvalidChargerWarning(); + } + + private void dismissInvalidChargerNotification() { + Slog.i(TAG, "dismissing invalid charger notification"); mInvalidCharger = false; updateNotification(); } @@ -355,10 +351,12 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); - Log.d(TAG, "got " + action); + Slog.i(TAG, "Received " + action); if (action.equals(ACTION_SHOW_FALLBACK_WARNING)) { + dismissLowBatteryNotification(); mFallbackDialogs.showLowBatteryWarning(false /*playSound*/); } else if (action.equals(ACTION_SHOW_FALLBACK_CHARGER)) { + dismissInvalidChargerNotification(); mFallbackDialogs.showInvalidChargerWarning(); } else if (action.equals(ACTION_SHOW_BATTERY_SETTINGS)) { dismissLowBatteryNotification(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index 7196b62ec5e1..97123fac6143 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -132,7 +132,6 @@ public abstract class BaseStatusBar extends SystemUI implements // for heads up notifications protected HeadsUpNotificationView mHeadsUpNotificationView; protected int mHeadsUpNotificationDecay; - protected long mInterruptingNotificationTime; // used to notify status bar for suppressing notification LED protected boolean mPanelSlightlyVisible; @@ -1413,6 +1412,9 @@ public abstract class BaseStatusBar extends SystemUI implements && !TextUtils.equals(notification.getNotification().tickerText, oldEntry.notification.getNotification().tickerText); + final boolean shouldInterrupt = shouldInterrupt(notification); + final boolean alertAgain = alertAgain(oldEntry); + boolean updateSuccessful = false; if (contentsUnchanged && bigContentsUnchanged && headsUpContentsUnchanged && publicUnchanged) { if (DEBUG) Log.d(TAG, "reusing notification for key: " + key); @@ -1432,8 +1434,6 @@ public abstract class BaseStatusBar extends SystemUI implements } } - final boolean shouldInterrupt = shouldInterrupt(notification); - final boolean alertAgain = alertAgain(oldEntry); if (wasHeadsUp) { if (shouldInterrupt) { updateHeadsUpViews(oldEntry, notification); @@ -1455,24 +1455,52 @@ public abstract class BaseStatusBar extends SystemUI implements } mNotificationData.updateRanking(ranking); updateNotifications(); + updateSuccessful = true; } catch (RuntimeException e) { // It failed to add cleanly. Log, and remove the view from the panel. Log.w(TAG, "Couldn't reapply views for package " + contentView.getPackage(), e); - removeNotificationViews(key, ranking); - addNotificationViews(notification, ranking); } - } else { + } + if (!updateSuccessful) { if (DEBUG) Log.d(TAG, "not reusing notification for key: " + key); - if (DEBUG) Log.d(TAG, "contents was " + (contentsUnchanged ? "unchanged" : "changed")); - removeNotificationViews(key, ranking); - addNotificationViews(notification, ranking); - final NotificationData.Entry newEntry = mNotificationData.findByKey(key); - final boolean userChangedExpansion = oldEntry.row.hasUserChangedExpansion(); - if (userChangedExpansion) { - boolean userExpanded = oldEntry.row.isUserExpanded(); - newEntry.row.setUserExpanded(userExpanded); - newEntry.row.notifyHeightChanged(); + if (wasHeadsUp) { + if (shouldInterrupt) { + if (DEBUG) Log.d(TAG, "rebuilding heads up for key: " + key); + Entry newEntry = new Entry(notification, null); + ViewGroup holder = mHeadsUpNotificationView.getHolder(); + if (inflateViewsForHeadsUp(newEntry, holder)) { + mHeadsUpNotificationView.showNotification(newEntry); + if (alertAgain) { + resetHeadsUpDecayTimer(); + } + } else { + Log.w(TAG, "Couldn't create new updated headsup for package " + + contentView.getPackage()); + } + } else { + if (DEBUG) Log.d(TAG, "releasing heads up for key: " + key); + oldEntry.notification = notification; + mHeadsUpNotificationView.releaseAndClose(); + return; + } + } else { + if (shouldInterrupt && alertAgain) { + if (DEBUG) Log.d(TAG, "reposting to invoke heads up for key: " + key); + removeNotificationViews(key, ranking); + addNotificationInternal(notification, ranking); //this will pop the headsup + } else { + if (DEBUG) Log.d(TAG, "rebuilding update in place for key: " + key); + removeNotificationViews(key, ranking); + addNotificationViews(notification, ranking); + final NotificationData.Entry newEntry = mNotificationData.findByKey(key); + final boolean userChangedExpansion = oldEntry.row.hasUserChangedExpansion(); + if (userChangedExpansion) { + boolean userExpanded = oldEntry.row.isUserExpanded(); + newEntry.row.setUserExpanded(userExpanded); + newEntry.row.notifyHeightChanged(); + } + } } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index d413f63297b5..8a57ce66d7c3 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -1081,8 +1081,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, Entry interruptionCandidate = new Entry(notification, null); ViewGroup holder = mHeadsUpNotificationView.getHolder(); if (inflateViewsForHeadsUp(interruptionCandidate, holder)) { - mInterruptingNotificationTime = System.currentTimeMillis(); - // 1. Populate mHeadsUpNotificationView mHeadsUpNotificationView.showNotification(interruptionCandidate); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpNotificationView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpNotificationView.java index 0f6c4b254231..0a48e34b16cf 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpNotificationView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpNotificationView.java @@ -78,8 +78,10 @@ public class HeadsUpNotificationView extends FrameLayout implements SwipeHelper. } public boolean showNotification(NotificationData.Entry headsUp) { - // bump any previous heads up back to the shade - release(); + if (mHeadsUp != null && headsUp != null && !mHeadsUp.key.equals(headsUp.key)) { + // bump any previous heads up back to the shade + release(); + } mHeadsUp = headsUp; if (mContentHolder != null) { diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index f66f7acea7e6..e39e0774564a 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -20,7 +20,6 @@ import static android.Manifest.permission.MANAGE_NETWORK_POLICY; import static android.Manifest.permission.RECEIVE_DATA_ACTIVITY_CHANGE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE; -import static android.net.ConnectivityManager.NetworkCallbackListener; import static android.net.ConnectivityManager.TYPE_BLUETOOTH; import static android.net.ConnectivityManager.TYPE_DUMMY; import static android.net.ConnectivityManager.TYPE_MOBILE; @@ -5401,7 +5400,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { @Override public NetworkRequest requestNetwork(NetworkCapabilities networkCapabilities, - Messenger messenger, int timeoutSec, IBinder binder, int legacyType) { + Messenger messenger, int timeoutMs, IBinder binder, int legacyType) { if (networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) == false) { enforceConnectivityInternalPermission(); @@ -5409,7 +5408,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { enforceChangePermission(); } - if (timeoutSec < 0 || timeoutSec > ConnectivityManager.MAX_NETWORK_REQUEST_TIMEOUT_SEC) { + if (timeoutMs < 0 || timeoutMs > ConnectivityManager.MAX_NETWORK_REQUEST_TIMEOUT_MS) { throw new IllegalArgumentException("Bad timeout specified"); } NetworkRequest networkRequest = new NetworkRequest(new NetworkCapabilities( @@ -5419,9 +5418,9 @@ public class ConnectivityService extends IConnectivityManager.Stub { NetworkRequestInfo.REQUEST); mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_REQUEST, nri)); - if (timeoutSec > 0) { + if (timeoutMs > 0) { mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_TIMEOUT_NETWORK_REQUEST, - nri), timeoutSec * 1000); + nri), timeoutMs); } return networkRequest; } @@ -5685,7 +5684,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { int a2 = 0; switch (notificationType) { case ConnectivityManager.CALLBACK_LOSING: - a1 = 30; // TODO - read this from NetworkMonitor + a1 = 30 * 1000; // TODO - read this from NetworkMonitor // fall through case ConnectivityManager.CALLBACK_PRECHECK: case ConnectivityManager.CALLBACK_AVAILABLE: diff --git a/services/core/java/com/android/server/job/controllers/ConnectivityController.java b/services/core/java/com/android/server/job/controllers/ConnectivityController.java index 7e79ff7b3e77..daba0d9c36d3 100644 --- a/services/core/java/com/android/server/job/controllers/ConnectivityController.java +++ b/services/core/java/com/android/server/job/controllers/ConnectivityController.java @@ -197,4 +197,4 @@ public class ConnectivityController extends StateController implements + ", UM=" + js.hasUnmeteredConstraint()); } } -}
\ No newline at end of file +} |