From dda2d35b0c8443f380ce836eb32e3504813e63a4 Mon Sep 17 00:00:00 2001 From: Motomu Utsumi Date: Fri, 7 Jun 2024 14:50:25 +0900 Subject: [PATCH] Update VpnTest#testDefault to use otherUid that has internet permission Bug: 342557183 Test: VpnTest Change-Id: If4a256df9ef96285c65dd285c7d37696dbd82298 --- .../app/src/com/android/cts/net/hostside/VpnTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java index e88c10594e..e186c6bb05 100755 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/VpnTest.java @@ -971,8 +971,12 @@ public class VpnTest { final TestableNetworkCallback otherUidCallback = new TestableNetworkCallback(); final TestableNetworkCallback myUidCallback = new TestableNetworkCallback(); if (SdkLevel.isAtLeastS()) { - final int otherUid = - UserHandle.of(5 /* userId */).getUid(Process.FIRST_APPLICATION_UID); + // Using the same appId with the test to make sure otherUid has the internet permission. + // This works because the UID permission map only stores the app ID and not the whole + // UID. If the otherUid does not have the internet permission, network access from + // otherUid could be considered blocked on V+. + final int appId = UserHandle.getAppId(Process.myUid()); + final int otherUid = UserHandle.of(5 /* userId */).getUid(appId); final Handler h = new Handler(Looper.getMainLooper()); runWithShellPermissionIdentity(() -> { registerSystemDefaultNetworkCallback(systemDefaultCallback, h);