Add TestNetworkStackService to NetworkStack am: 9e6aeea309 am: 6c47d693b0

Original change: https://android-review.googlesource.com/c/platform/packages/modules/NetworkStack/+/1355068

Change-Id: I451b5459ae43e80328068ad609a0f9d9fd5bb6aa
diff --git a/Android.bp b/Android.bp
index 51f139e..314def9 100644
--- a/Android.bp
+++ b/Android.bp
@@ -48,8 +48,7 @@
 
 java_defaults {
     name: "NetworkStackReleaseApiLevel",
-    // TODO: use system_30 once a prebuilt SDK is available for R
-    sdk_version: "system_current",
+    sdk_version: "system_30",
     min_sdk_version: "29",
     target_sdk_version: "30",
 }
@@ -130,7 +129,7 @@
     defaults: ["NetworkStackReleaseApiLevel"],
     srcs: [
         "src/**/*.java",
-        ":statslog-networkstack-java-gen-q",
+        ":statslog-networkstack-java-gen",
     ],
     // API stable uses a jarjared version of the shims
     static_libs: [
@@ -256,15 +255,6 @@
 }
 
 genrule {
-    name: "statslog-networkstack-java-gen-q",
-    tools: ["stats-log-api-gen"],
-    cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
-         " --javaPackage com.android.networkstack.metrics --javaClass NetworkStackStatsLog" +
-         " --compileQ",
-    out: ["com/android/networkstack/metrics/NetworkStackStatsLog.java"],
-}
-
-genrule {
     name: "statslog-networkstack-java-gen",
     tools: ["stats-log-api-gen"],
     cmd: "$(location stats-log-api-gen) --java $(out) --module network_stack" +
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 784838a..82e7047 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -19,7 +19,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.android.networkstack"
   android:sharedUserId="android.uid.networkstack"
-  android:versionCode="299900000"
+  android:versionCode="300000000"
   android:versionName="2019-09"
 >
     <!-- Permissions must be defined here, and not in the base manifest, as the network stack
diff --git a/common/networkstackclient/Android.bp b/common/networkstackclient/Android.bp
index 439f9fc..a8b8628 100644
--- a/common/networkstackclient/Android.bp
+++ b/common/networkstackclient/Android.bp
@@ -27,6 +27,7 @@
         java: {
             apex_available: [
                 "//apex_available:platform",
+                "com.android.wifi",
                 "com.android.bluetooth.updatable",
                 "com.android.tethering",
             ],
@@ -94,6 +95,7 @@
             apex_available: [
                 "//apex_available:platform",
                 "com.android.bluetooth.updatable",
+                "com.android.wifi",
                 "com.android.tethering",
             ],
             // this is part of updatable modules(NetworkStack) which targets 29(Q)
diff --git a/src/com/android/networkstack/NetworkStackNotifier.java b/src/com/android/networkstack/NetworkStackNotifier.java
index 872834a..dbb62b1 100644
--- a/src/com/android/networkstack/NetworkStackNotifier.java
+++ b/src/com/android/networkstack/NetworkStackNotifier.java
@@ -239,7 +239,7 @@
                     .setContentText(res.getString(R.string.tap_for_info))
                     .setContentIntent(mDependencies.getActivityPendingIntent(
                             getContextAsUser(mContext, UserHandle.CURRENT),
-                            infoIntent, PendingIntent.FLAG_UPDATE_CURRENT));
+                            infoIntent, PendingIntent.FLAG_IMMUTABLE));
 
             networkStatus.mShownNotification = NOTE_VENUE_INFO;
         } else if (showValidated) {
@@ -252,7 +252,7 @@
                     .setContentIntent(mDependencies.getActivityPendingIntent(
                             getContextAsUser(mContext, UserHandle.CURRENT),
                             new Intent(Settings.ACTION_WIFI_SETTINGS),
-                            PendingIntent.FLAG_UPDATE_CURRENT));
+                            PendingIntent.FLAG_IMMUTABLE));
 
             networkStatus.mShownNotification = NOTE_CONNECTED;
         } else {
diff --git a/src/com/android/networkstack/metrics/DataStallDetectionStats.java b/src/com/android/networkstack/metrics/DataStallDetectionStats.java
index 47f5805..131fb79 100644
--- a/src/com/android/networkstack/metrics/DataStallDetectionStats.java
+++ b/src/com/android/networkstack/metrics/DataStallDetectionStats.java
@@ -261,11 +261,13 @@
             if (info == null) return DataStallEventProto.AP_BAND_UNKNOWN;
 
             int freq = info.getFrequency();
-            // Refer to ScanResult.is5GHz() and ScanResult.is24GHz().
-            if (freq > 4900 && freq < 5900) {
+            // Refer to ScanResult.is5GHz(), ScanResult.is24GHz() and ScanResult.is6GHz().
+            if (freq >= 5160 && freq <= 5865) {
                 return DataStallEventProto.AP_BAND_5GHZ;
-            } else if (freq > 2400 && freq < 2500) {
+            } else if (freq >= 2412 && freq <= 2484) {
                 return DataStallEventProto.AP_BAND_2GHZ;
+            } else if (freq >= 5945 && freq <= 7105) {
+                return DataStallEventProto.AP_BAND_6GHZ;
             } else {
                 return DataStallEventProto.AP_BAND_UNKNOWN;
             }
diff --git a/tests/integration/src/android/net/ip/IpClientIntegrationTest.java b/tests/integration/src/android/net/ip/IpClientIntegrationTest.java
index 5868079..6ad99f8 100644
--- a/tests/integration/src/android/net/ip/IpClientIntegrationTest.java
+++ b/tests/integration/src/android/net/ip/IpClientIntegrationTest.java
@@ -149,7 +149,6 @@
 
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -1561,7 +1560,6 @@
 
     }
 
-    @Ignore  // AOSP kernels don't support the PREF64 option yet.
     @Test @IgnoreUpTo(Build.VERSION_CODES.Q)
     public void testPref64Option() throws Exception {
         assumeTrue(ConstantsShim.VERSION > Build.VERSION_CODES.Q);
diff --git a/tests/unit/src/com/android/networkstack/NetworkStackNotifierTest.kt b/tests/unit/src/com/android/networkstack/NetworkStackNotifierTest.kt
index b2607eb..348392d 100644
--- a/tests/unit/src/com/android/networkstack/NetworkStackNotifierTest.kt
+++ b/tests/unit/src/com/android/networkstack/NetworkStackNotifierTest.kt
@@ -22,7 +22,7 @@
 import android.app.NotificationManager.IMPORTANCE_DEFAULT
 import android.app.NotificationManager.IMPORTANCE_NONE
 import android.app.PendingIntent
-import android.app.PendingIntent.FLAG_UPDATE_CURRENT
+import android.app.PendingIntent.FLAG_IMMUTABLE
 import android.content.Context
 import android.content.Intent
 import android.content.res.Resources
@@ -57,6 +57,7 @@
 import org.mockito.ArgumentCaptor
 import org.mockito.ArgumentMatchers.anyInt
 import org.mockito.ArgumentMatchers.eq
+import org.mockito.ArgumentMatchers.intThat
 import org.mockito.Captor
 import org.mockito.Mock
 import org.mockito.Mockito.any
@@ -188,7 +189,8 @@
         assertEquals(CHANNEL_CONNECTED, note.channelId)
         assertEquals(timeout, note.timeoutAfter)
         verify(mDependencies).getActivityPendingIntent(
-                eq(mCurrentUserContext), mIntentCaptor.capture(), eq(FLAG_UPDATE_CURRENT))
+                eq(mCurrentUserContext), mIntentCaptor.capture(),
+                intThat { it or FLAG_IMMUTABLE != 0 })
     }
 
     private fun verifyCanceledNotificationAfterNetworkLost() {
@@ -279,7 +281,8 @@
 
         verify(mNm).notify(eq(TEST_NETWORK_TAG), mNoteIdCaptor.capture(), mNoteCaptor.capture())
         verify(mDependencies).getActivityPendingIntent(
-                eq(mCurrentUserContext), mIntentCaptor.capture(), eq(FLAG_UPDATE_CURRENT))
+                eq(mCurrentUserContext), mIntentCaptor.capture(),
+                intThat { it or FLAG_IMMUTABLE != 0 })
         verifyVenueInfoIntent(mIntentCaptor.value)
         verifyCanceledNotificationAfterDefaultNetworkLost()
     }