Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad44d814 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Android Git Automerger
Browse files

am 3dc08220: am b57f236e: Merge changes Icf7d67e2,Ia914ec88,I2490ad75,Ie79f2d28 into mnc-dev

* commit '3dc08220':
  Add a hidden method to clear NetworkCapabilities.
  Fix javadoc error for requestNetwork.
  Simplify network callback handling code.
  Document and unhide CALLBACK_PRECHECK.
parents 4816ebe8 3dc08220
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -18438,6 +18438,7 @@ package android.net {
    method public void onLinkPropertiesChanged(android.net.Network, android.net.LinkProperties);
    method public void onLinkPropertiesChanged(android.net.Network, android.net.LinkProperties);
    method public void onLosing(android.net.Network, int);
    method public void onLosing(android.net.Network, int);
    method public void onLost(android.net.Network);
    method public void onLost(android.net.Network);
    method public void onPreCheck(android.net.Network);
  }
  }
  public static abstract interface ConnectivityManager.OnNetworkActiveListener {
  public static abstract interface ConnectivityManager.OnNetworkActiveListener {
+1 −0
Original line number Original line Diff line number Diff line
@@ -19906,6 +19906,7 @@ package android.net {
    method public void onLinkPropertiesChanged(android.net.Network, android.net.LinkProperties);
    method public void onLinkPropertiesChanged(android.net.Network, android.net.LinkProperties);
    method public void onLosing(android.net.Network, int);
    method public void onLosing(android.net.Network, int);
    method public void onLost(android.net.Network);
    method public void onLost(android.net.Network);
    method public void onPreCheck(android.net.Network);
  }
  }
  public static abstract interface ConnectivityManager.OnNetworkActiveListener {
  public static abstract interface ConnectivityManager.OnNetworkActiveListener {
+65 −80
Original line number Original line Diff line number Diff line
@@ -341,7 +341,8 @@ public class ConnectivityManager {
     * one.  This is used by applications needing to talk to the carrier's
     * one.  This is used by applications needing to talk to the carrier's
     * Multimedia Messaging Service servers.
     * Multimedia Messaging Service servers.
     *
     *
     * @deprecated Applications should instead use {@link #requestNetwork} to request a network that
     * @deprecated Applications should instead use
     *         {@link #requestNetwork(NetworkRequest, NetworkCallback)} to request a network that
     *         provides the {@link NetworkCapabilities#NET_CAPABILITY_MMS} capability.
     *         provides the {@link NetworkCapabilities#NET_CAPABILITY_MMS} capability.
     */
     */
    public static final int TYPE_MOBILE_MMS  = 2;
    public static final int TYPE_MOBILE_MMS  = 2;
@@ -351,7 +352,8 @@ public class ConnectivityManager {
     * one.  This is used by applications needing to talk to the carrier's
     * one.  This is used by applications needing to talk to the carrier's
     * Secure User Plane Location servers for help locating the device.
     * Secure User Plane Location servers for help locating the device.
     *
     *
     * @deprecated Applications should instead use {@link #requestNetwork} to request a network that
     * @deprecated Applications should instead use
     *         {@link #requestNetwork(NetworkRequest, NetworkCallback)} to request a network that
     *         provides the {@link NetworkCapabilities#NET_CAPABILITY_SUPL} capability.
     *         provides the {@link NetworkCapabilities#NET_CAPABILITY_SUPL} capability.
     */
     */
    public static final int TYPE_MOBILE_SUPL = 3;
    public static final int TYPE_MOBILE_SUPL = 3;
@@ -367,7 +369,8 @@ public class ConnectivityManager {
     * same network interface as {@link #TYPE_MOBILE} but the routing setup
     * same network interface as {@link #TYPE_MOBILE} but the routing setup
     * is different.
     * is different.
     *
     *
     * @deprecated Applications should instead use {@link #requestNetwork} to request a network that
     * @deprecated Applications should instead use
     *         {@link #requestNetwork(NetworkRequest, NetworkCallback)} to request a network that
     *         uses the {@link NetworkCapabilities#TRANSPORT_CELLULAR} transport.
     *         uses the {@link NetworkCapabilities#TRANSPORT_CELLULAR} transport.
     */
     */
    public static final int TYPE_MOBILE_HIPRI = 5;
    public static final int TYPE_MOBILE_HIPRI = 5;
@@ -910,7 +913,8 @@ public class ConnectivityManager {
     * implementation+feature combination, except that the value {@code -1}
     * implementation+feature combination, except that the value {@code -1}
     * always indicates failure.
     * always indicates failure.
     *
     *
     * @deprecated Deprecated in favor of the cleaner {@link #requestNetwork} api.
     * @deprecated Deprecated in favor of the cleaner
     *             {@link #requestNetwork(NetworkRequest, NetworkCallback)} API.
     * @removed
     * @removed
     */
     */
    public int startUsingNetworkFeature(int networkType, String feature) {
    public int startUsingNetworkFeature(int networkType, String feature) {
@@ -958,7 +962,7 @@ public class ConnectivityManager {
     * implementation+feature combination, except that the value {@code -1}
     * implementation+feature combination, except that the value {@code -1}
     * always indicates failure.
     * always indicates failure.
     *
     *
     * @deprecated Deprecated in favor of the cleaner {@link #requestNetwork} api.
     * @deprecated Deprecated in favor of the cleaner {@link unregisterNetworkCallback} API.
     * @removed
     * @removed
     */
     */
    public int stopUsingNetworkFeature(int networkType, String feature) {
    public int stopUsingNetworkFeature(int networkType, String feature) {
@@ -1236,8 +1240,9 @@ public class ConnectivityManager {
     * @param hostAddress the IP address of the host to which the route is desired
     * @param hostAddress the IP address of the host to which the route is desired
     * @return {@code true} on success, {@code false} on failure
     * @return {@code true} on success, {@code false} on failure
     *
     *
     * @deprecated Deprecated in favor of the {@link #requestNetwork},
     * @deprecated Deprecated in favor of the
     *             {@link #bindProcessToNetwork} and {@link Network#getSocketFactory} api.
     *             {@link #requestNetwork(NetworkRequest, NetworkCallback)},
     *             {@link #bindProcessToNetwork} and {@link Network#getSocketFactory} API.
     * @removed
     * @removed
     */
     */
    public boolean requestRouteToHost(int networkType, int hostAddress) {
    public boolean requestRouteToHost(int networkType, int hostAddress) {
@@ -1256,7 +1261,7 @@ public class ConnectivityManager {
     * @return {@code true} on success, {@code false} on failure
     * @return {@code true} on success, {@code false} on failure
     * @hide
     * @hide
     * @deprecated Deprecated in favor of the {@link #requestNetwork} and
     * @deprecated Deprecated in favor of the {@link #requestNetwork} and
     *             {@link #bindProcessToNetwork} api.
     *             {@link #bindProcessToNetwork} API.
     * @removed
     * @removed
     */
     */
    public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) {
    public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) {
@@ -2144,14 +2149,22 @@ public class ConnectivityManager {
        public static final int CANCELED     = 8;
        public static final int CANCELED     = 8;


        /**
        /**
         * @hide
         * Called when the framework connects to a new network to evaluate whether it satisfies this
         * Called whenever the framework connects to a network that it may use to
         * request. If evaluation succeeds, this callback may be followed by an {@link #onAvailable}
         * satisfy this request
         * callback. There is no guarantee that this new network will satisfy any requests, or that
         * the network will stay connected for longer than the time necessary to evaluate it.
         * <p>
         * Most applications <b>should not</b> act on this callback, and should instead use
         * {@link #onAvailable}. This callback is intended for use by applications that can assist
         * the framework in properly evaluating the network &mdash; for example, an application that
         * can automatically log in to a captive portal without user intervention.
         *
         * @param network The {@link Network} of the network that is being evaluated.
         */
         */
        public void onPreCheck(Network network) {}
        public void onPreCheck(Network network) {}


        /**
        /**
         * Called when the framework connects and has declared new network ready for use.
         * Called when the framework connects and has declared a new network ready for use.
         * This callback may be called more than once if the {@link Network} that is
         * This callback may be called more than once if the {@link Network} that is
         * satisfying the request changes.
         * satisfying the request changes.
         *
         *
@@ -2251,116 +2264,82 @@ public class ConnectivityManager {
        @Override
        @Override
        public void handleMessage(Message message) {
        public void handleMessage(Message message) {
            Log.d(TAG, "CM callback handler got msg " + message.what);
            Log.d(TAG, "CM callback handler got msg " + message.what);
            NetworkRequest request = (NetworkRequest) getObject(message, NetworkRequest.class);
            Network network = (Network) getObject(message, Network.class);
            switch (message.what) {
            switch (message.what) {
                case CALLBACK_PRECHECK: {
                case CALLBACK_PRECHECK: {
                    NetworkRequest request = (NetworkRequest)getObject(message,
                    NetworkCallback callback = getCallback(request, "PRECHECK");
                            NetworkRequest.class);
                    if (callback != null) {
                    NetworkCallback callbacks = getCallbacks(request);
                        callback.onPreCheck(network);
                    if (callbacks != null) {
                        callbacks.onPreCheck((Network)getObject(message, Network.class));
                    } else {
                        Log.e(TAG, "callback not found for PRECHECK message");
                    }
                    }
                    break;
                    break;
                }
                }
                case CALLBACK_AVAILABLE: {
                case CALLBACK_AVAILABLE: {
                    NetworkRequest request = (NetworkRequest)getObject(message,
                    NetworkCallback callback = getCallback(request, "AVAILABLE");
                            NetworkRequest.class);
                    if (callback != null) {
                    NetworkCallback callbacks = getCallbacks(request);
                        callback.onAvailable(network);
                    if (callbacks != null) {
                        callbacks.onAvailable((Network)getObject(message, Network.class));
                    } else {
                        Log.e(TAG, "callback not found for AVAILABLE message");
                    }
                    }
                    break;
                    break;
                }
                }
                case CALLBACK_LOSING: {
                case CALLBACK_LOSING: {
                    NetworkRequest request = (NetworkRequest)getObject(message,
                    NetworkCallback callback = getCallback(request, "LOSING");
                            NetworkRequest.class);
                    if (callback != null) {
                    NetworkCallback callbacks = getCallbacks(request);
                        callback.onLosing(network, message.arg1);
                    if (callbacks != null) {
                        callbacks.onLosing((Network)getObject(message, Network.class),
                                message.arg1);
                    } else {
                        Log.e(TAG, "callback not found for LOSING message");
                    }
                    }
                    break;
                    break;
                }
                }
                case CALLBACK_LOST: {
                case CALLBACK_LOST: {
                    NetworkRequest request = (NetworkRequest)getObject(message,
                    NetworkCallback callback = getCallback(request, "LOST");
                            NetworkRequest.class);
                    if (callback != null) {

                        callback.onLost(network);
                    NetworkCallback callbacks = getCallbacks(request);
                    if (callbacks != null) {
                        callbacks.onLost((Network)getObject(message, Network.class));
                    } else {
                        Log.e(TAG, "callback not found for LOST message");
                    }
                    }
                    break;
                    break;
                }
                }
                case CALLBACK_UNAVAIL: {
                case CALLBACK_UNAVAIL: {
                    NetworkRequest request = (NetworkRequest)getObject(message,
                    NetworkCallback callback = getCallback(request, "UNAVAIL");
                            NetworkRequest.class);
                    if (callback != null) {
                    NetworkCallback callbacks = null;
                        callback.onUnavailable();
                    synchronized(mCallbackMap) {
                        callbacks = mCallbackMap.get(request);
                    }
                    if (callbacks != null) {
                        callbacks.onUnavailable();
                    } else {
                        Log.e(TAG, "callback not found for UNAVAIL message");
                    }
                    }
                    break;
                    break;
                }
                }
                case CALLBACK_CAP_CHANGED: {
                case CALLBACK_CAP_CHANGED: {
                    NetworkRequest request = (NetworkRequest)getObject(message,
                    NetworkCallback callback = getCallback(request, "CAP_CHANGED");
                            NetworkRequest.class);
                    if (callback != null) {
                    NetworkCallback callbacks = getCallbacks(request);
                    if (callbacks != null) {
                        Network network = (Network)getObject(message, Network.class);
                        NetworkCapabilities cap = (NetworkCapabilities)getObject(message,
                        NetworkCapabilities cap = (NetworkCapabilities)getObject(message,
                                NetworkCapabilities.class);
                                NetworkCapabilities.class);


                        callbacks.onCapabilitiesChanged(network, cap);
                        callback.onCapabilitiesChanged(network, cap);
                    } else {
                        Log.e(TAG, "callback not found for CAP_CHANGED message");
                    }
                    }
                    break;
                    break;
                }
                }
                case CALLBACK_IP_CHANGED: {
                case CALLBACK_IP_CHANGED: {
                    NetworkRequest request = (NetworkRequest)getObject(message,
                    NetworkCallback callback = getCallback(request, "IP_CHANGED");
                            NetworkRequest.class);
                    if (callback != null) {
                    NetworkCallback callbacks = getCallbacks(request);
                    if (callbacks != null) {
                        Network network = (Network)getObject(message, Network.class);
                        LinkProperties lp = (LinkProperties)getObject(message,
                        LinkProperties lp = (LinkProperties)getObject(message,
                                LinkProperties.class);
                                LinkProperties.class);


                        callbacks.onLinkPropertiesChanged(network, lp);
                        callback.onLinkPropertiesChanged(network, lp);
                    } else {
                        Log.e(TAG, "callback not found for IP_CHANGED message");
                    }
                    }
                    break;
                    break;
                }
                }
                case CALLBACK_RELEASED: {
                case CALLBACK_RELEASED: {
                    NetworkRequest req = (NetworkRequest)getObject(message, NetworkRequest.class);
                    NetworkCallback callback = null;
                    NetworkCallback callbacks = null;
                    synchronized(mCallbackMap) {
                    synchronized(mCallbackMap) {
                        callbacks = mCallbackMap.remove(req);
                        callback = mCallbackMap.remove(request);
                    }
                    }
                    if (callbacks != null) {
                    if (callback != null) {
                        synchronized(mRefCount) {
                        synchronized(mRefCount) {
                            if (mRefCount.decrementAndGet() == 0) {
                            if (mRefCount.decrementAndGet() == 0) {
                                getLooper().quit();
                                getLooper().quit();
                            }
                            }
                        }
                        }
                    } else {
                    } else {
                        Log.e(TAG, "callback not found for CANCELED message");
                        Log.e(TAG, "callback not found for RELEASED message");
                    }
                    }
                    break;
                    break;
                }
                }
                case CALLBACK_EXIT: {
                case CALLBACK_EXIT: {
                    Log.d(TAG, "Listener quiting");
                    Log.d(TAG, "Listener quitting");
                    getLooper().quit();
                    getLooper().quit();
                    break;
                    break;
                }
                }
@@ -2374,10 +2353,16 @@ public class ConnectivityManager {
        private Object getObject(Message msg, Class c) {
        private Object getObject(Message msg, Class c) {
            return msg.getData().getParcelable(c.getSimpleName());
            return msg.getData().getParcelable(c.getSimpleName());
        }
        }
        private NetworkCallback getCallbacks(NetworkRequest req) {

        private NetworkCallback getCallback(NetworkRequest req, String name) {
            NetworkCallback callback;
            synchronized(mCallbackMap) {
            synchronized(mCallbackMap) {
                return mCallbackMap.get(req);
                callback = mCallbackMap.get(req);
            }
            if (callback == null) {
                Log.e(TAG, "callback not found for " + name + " message");
            }
            }
            return callback;
        }
        }
    }
    }


@@ -2601,10 +2586,10 @@ public class ConnectivityManager {


    /**
    /**
     * Unregisters callbacks about and possibly releases networks originating from
     * Unregisters callbacks about and possibly releases networks originating from
     * {@link #requestNetwork} and {@link #registerNetworkCallback} calls.  If the
     * {@link #requestNetwork(NetworkRequest, NetworkCallback)} and {@link #registerNetworkCallback}
     * given {@code NetworkCallback} had previously been used with {@code #requestNetwork},
     * calls.  If the given {@code NetworkCallback} had previously been used with
     * any networks that had been connected to only to satisfy that request will be
     * {@code #requestNetwork}, any networks that had been connected to only to satisfy that request
     * disconnected.
     * will be disconnected.
     *
     *
     * @param networkCallback The {@link NetworkCallback} used when making the request.
     * @param networkCallback The {@link NetworkCallback} used when making the request.
     */
     */
+17 −2
Original line number Original line Diff line number Diff line
@@ -37,6 +37,11 @@ public final class NetworkCapabilities implements Parcelable {
     * @hide
     * @hide
     */
     */
    public NetworkCapabilities() {
    public NetworkCapabilities() {
        clearAll();
        mNetworkCapabilities =
                (1 << NET_CAPABILITY_NOT_RESTRICTED) |
                (1 << NET_CAPABILITY_TRUSTED) |
                (1 << NET_CAPABILITY_NOT_VPN);
    }
    }


    public NetworkCapabilities(NetworkCapabilities nc) {
    public NetworkCapabilities(NetworkCapabilities nc) {
@@ -49,12 +54,22 @@ public final class NetworkCapabilities implements Parcelable {
        }
        }
    }
    }


    /**
     * Completely clears the contents of this object, removing even the capabilities that are set
     * by default when the object is constructed.
     * @hide
     */
    public void clearAll() {
        mNetworkCapabilities = mTransportTypes = 0;
        mLinkUpBandwidthKbps = mLinkDownBandwidthKbps = 0;
        mNetworkSpecifier = null;
    }

    /**
    /**
     * Represents the network's capabilities.  If any are specified they will be satisfied
     * Represents the network's capabilities.  If any are specified they will be satisfied
     * by any Network that matches all of them.
     * by any Network that matches all of them.
     */
     */
    private long mNetworkCapabilities = (1 << NET_CAPABILITY_NOT_RESTRICTED) |
    private long mNetworkCapabilities;
            (1 << NET_CAPABILITY_TRUSTED) | (1 << NET_CAPABILITY_NOT_VPN);


    /**
    /**
     * Indicates this is a network that has the ability to reach the
     * Indicates this is a network that has the ability to reach the