Bind to TestNetworkStackService as user 0 in IpClientRootTest

By default, context.bindService() will try to bind to the service as the
current user. On a multi-user device with another user (not user 0) as
the current user, this intent will in turn starts another test service
as the current user, which is unexpected in this test.

This patch change this call to bindServiceAsUser() with the SYSTEM user
to always bind to the network stack service running as user 0. Also
gives INTERACT_ACROSS_USERS_FULL permission for sending the intent (note
that INTERACT_ACROSS_USERS is not enough).

Bug: b/353415286
Test: `atest NetworkStackRootTests` on a multi-user device.
Change-Id: Ia3f795fd2bedcfea3d6b9a008189235fdad8a6d8
diff --git a/tests/integration/common/android/net/networkstack/TestNetworkStackServiceClient.kt b/tests/integration/common/android/net/networkstack/TestNetworkStackServiceClient.kt
index 3bba529..ac78b7a 100644
--- a/tests/integration/common/android/net/networkstack/TestNetworkStackServiceClient.kt
+++ b/tests/integration/common/android/net/networkstack/TestNetworkStackServiceClient.kt
@@ -23,6 +23,7 @@
 import android.content.pm.PackageManager.MATCH_SYSTEM_ONLY
 import android.net.INetworkStackConnector
 import android.os.IBinder
+import android.os.UserHandle
 import android.util.Log
 import androidx.test.platform.app.InstrumentationRegistry
 import kotlin.test.fail
@@ -82,7 +83,15 @@
     private fun init() {
         val bindIntent = Intent(testNetworkStackServiceAction)
         bindIntent.component = getNetworkStackComponent(bindIntent.action)
-        context.bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE)
+        // Use UserHandle.SYSTEM to bind to the test network stack service as user 0. Otherwise on a
+        // multi-user device where current user is not user 0, this intent will start another test
+        // service for the current user which is not expected.
+        context.bindServiceAsUser(
+            bindIntent,
+            serviceConnection,
+            Context.BIND_AUTO_CREATE,
+            UserHandle.SYSTEM
+        )
     }
 
     fun disconnect() {
diff --git a/tests/integration/root/android/net/ip/IpClientRootTest.kt b/tests/integration/root/android/net/ip/IpClientRootTest.kt
index 715e27d..2c7ce17 100644
--- a/tests/integration/root/android/net/ip/IpClientRootTest.kt
+++ b/tests/integration/root/android/net/ip/IpClientRootTest.kt
@@ -16,6 +16,7 @@
 
 package android.net.ip
 
+import android.Manifest.permission.INTERACT_ACROSS_USERS_FULL
 import android.Manifest.permission.NETWORK_SETTINGS
 import android.Manifest.permission.READ_DEVICE_CONFIG
 import android.Manifest.permission.WRITE_DEVICE_CONFIG
@@ -83,7 +84,7 @@
             // Connect to the NetworkStack only once, as it is relatively expensive (~50ms plus any
             // polling time waiting for the test UID to be allowed), and there should be minimal
             // side-effects between tests compared to reconnecting every time.
-            automation.adoptShellPermissionIdentity(NETWORK_SETTINGS)
+            automation.adoptShellPermissionIdentity(NETWORK_SETTINGS, INTERACT_ACROSS_USERS_FULL)
             try {
                 automation.executeShellCommand("su root service call network_stack " +
                         "$ALLOW_TEST_UID_INDEX i32 " + Process.myUid())