Fix : recent Connectivity module with old NetworkStack module

The guarantees that the NetworkStack module will be as recent
as the Connectivity module are a little bit weak, so we should
make sure the rare configuration where Connectivity is more
recent should work.

In the absence of a satisfactory solution which :
- Doesn't cause log spew
- Is easy to manage process-wise
- Is scalable
This implements a simple solution where clients of the
network-stack-client lib only calls the new
notifyNetworkConnectedParcel method in T+. This is safe because
a T device can never revert to a version of the NetworkStack
that doesn't support this, and is in fact optimal since before
T the additional info is never useful (the one relevant field
in NetworkAgentConfig is always false, for lack of a public API
to make it true in S-).

Test: ConnectivityServiceTest
      NetworkMonitorTest
Change-Id: Ieaade098c55bc296d593c90e518de727b639d527
diff --git a/common/networkstackclient/Android.bp b/common/networkstackclient/Android.bp
index 1fbf525..6e44450 100644
--- a/common/networkstackclient/Android.bp
+++ b/common/networkstackclient/Android.bp
@@ -193,6 +193,7 @@
     ],
     static_libs: [
         "networkstack-aidl-latest",
+        "modules-utils-build",
     ],
     visibility: [
         "//frameworks/base/packages/Connectivity/service",
diff --git a/common/networkstackclient/src/android/net/NetworkMonitorManager.java b/common/networkstackclient/src/android/net/NetworkMonitorManager.java
index 2cfec17..98598a1 100644
--- a/common/networkstackclient/src/android/net/NetworkMonitorManager.java
+++ b/common/networkstackclient/src/android/net/NetworkMonitorManager.java
@@ -23,6 +23,8 @@
 import android.os.RemoteException;
 import android.util.Log;
 
+import com.android.modules.utils.build.SdkLevel;
+
 /**
  * A convenience wrapper for INetworkMonitor.
  *
@@ -151,7 +153,12 @@
     public boolean notifyNetworkConnected(NetworkMonitorParameters params) {
         final long token = Binder.clearCallingIdentity();
         try {
-            mNetworkMonitor.notifyNetworkConnectedParcel(params);
+            if (SdkLevel.isAtLeastT()) {
+                mNetworkMonitor.notifyNetworkConnectedParcel(params);
+            } else {
+                mNetworkMonitor.notifyNetworkConnected(params.linkProperties,
+                        params.networkCapabilities);
+            }
             return true;
         } catch (RemoteException e) {
             log("Error in notifyNetworkConnected", e);
diff --git a/src/com/android/server/connectivity/NetworkMonitor.java b/src/com/android/server/connectivity/NetworkMonitor.java
index 977f907..301462f 100755
--- a/src/com/android/server/connectivity/NetworkMonitor.java
+++ b/src/com/android/server/connectivity/NetworkMonitor.java
@@ -693,8 +693,7 @@
 
     /**
      * Send a notification to NetworkMonitor indicating that the network is now connected.
-     * @Deprecated use notifyNetworkConnectedParcel. This method is called on R-, or in
-     *             cases where the Connectivity module is old in S.
+     * @Deprecated use notifyNetworkConnectedParcel. This method is called on S-.
      */
     public void notifyNetworkConnected(LinkProperties lp, NetworkCapabilities nc) {
         final NetworkMonitorParameters params = new NetworkMonitorParameters();