From 92071eea46235709d875cb7fe22c647cf9a2650e Mon Sep 17 00:00:00 2001 From: Xiang Wang Date: Mon, 25 Nov 2024 03:03:13 +0000 Subject: [PATCH] Fix CtsNetTestCases for secondary_user_on_secondary_display secondary_user_on_secondary_display is for background users that have access to UI on assigned displays (a.k.a. visible background users) on devices that have config_multiuserVisibleBackgroundUsers enabled. The main use case is Automotive's multi-display configuration where passengers (modeled as visible background users) can interact with the display in front of them concurrently with the driver (modeled as the the current user) interacting with the driver's display. The fix is to pass in the user id to appops commands so that appops permissions can be properly granted or denied to a visible background user (non current user). Bug: 374210153 Flag: EXEMPT test fix Test: Tested on Automotive reference hardware with Multi Display Test: atest android.net.cts.IpSecManagerTunnelTest Test: atest --user-type secondary_user_on_secondary_display android.net.cts.IpSecManagerTunnelTest Test: atest android.net.cts.Ikev2VpnTest Test: atest --user-type secondary_user_on_secondary_display android.net.cts.Ikev2VpnTest Test: atest android.net.cts.NetworkStatsManagerTest Test: atest --user-type secondary_user_on_secondary_display android.net.cts.NetworkStatsManagerTest (cherry picked from https://android-review.googlesource.com/q/commit:116a3a7bd0d1e80adf3258850180f60dc90a3a94) Merged-In: I02ae287a926e0bce69ed11fa7e0ef78b288b6b76 Change-Id: I02ae287a926e0bce69ed11fa7e0ef78b288b6b76 --- .../src/android/net/cts/NetworkStatsManagerTest.java | 11 +++++++---- .../util/java/android/net/cts/util/CtsNetUtils.java | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java b/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java index 2315940833..bc1a15447d 100644 --- a/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java +++ b/tests/cts/net/src/android/net/cts/NetworkStatsManagerTest.java @@ -62,6 +62,7 @@ import android.os.HandlerThread; import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; +import android.os.UserHandle; import android.platform.test.annotations.AppModeFull; import android.telephony.TelephonyManager; import android.text.TextUtils; @@ -103,8 +104,8 @@ public class NetworkStatsManagerTest { public final DevSdkIgnoreRule ignoreRule = new DevSdkIgnoreRule(Build.VERSION_CODES.Q); private static final String LOG_TAG = "NetworkStatsManagerTest"; - private static final String APPOPS_SET_SHELL_COMMAND = "appops set {0} {1} {2}"; - private static final String APPOPS_GET_SHELL_COMMAND = "appops get {0} {1}"; + private static final String APPOPS_SET_SHELL_COMMAND = "appops set --user {0} {1} {2} {3}"; + private static final String APPOPS_GET_SHELL_COMMAND = "appops get --user {0} {1} {2}"; private static final long MINUTE = 1000 * 60; private static final int TIMEOUT_MILLIS = 15000; @@ -290,12 +291,14 @@ public class NetworkStatsManagerTest { } private void setAppOpsMode(String appop, String mode) throws Exception { - final String command = MessageFormat.format(APPOPS_SET_SHELL_COMMAND, mPkg, appop, mode); + final String command = MessageFormat.format(APPOPS_SET_SHELL_COMMAND, + UserHandle.myUserId(), mPkg, appop, mode); SystemUtil.runShellCommand(mInstrumentation, command); } private String getAppOpsMode(String appop) throws Exception { - final String command = MessageFormat.format(APPOPS_GET_SHELL_COMMAND, mPkg, appop); + final String command = MessageFormat.format(APPOPS_GET_SHELL_COMMAND, + UserHandle.myUserId(), mPkg, appop); String result = SystemUtil.runShellCommand(mInstrumentation, command); if (result == null) { Log.w(LOG_TAG, "App op " + appop + " could not be read."); diff --git a/tests/cts/net/util/java/android/net/cts/util/CtsNetUtils.java b/tests/cts/net/util/java/android/net/cts/util/CtsNetUtils.java index 0dd2a23440..173d13f6d5 100644 --- a/tests/cts/net/util/java/android/net/cts/util/CtsNetUtils.java +++ b/tests/cts/net/util/java/android/net/cts/util/CtsNetUtils.java @@ -53,6 +53,7 @@ import android.os.Binder; import android.os.Build; import android.os.ConditionVariable; import android.os.IBinder; +import android.os.UserHandle; import android.system.Os; import android.system.OsConstants; import android.telephony.SubscriptionManager; @@ -145,7 +146,8 @@ public final class CtsNetUtils { for (final String pkg : new String[] {"com.android.shell", mContext.getPackageName()}) { final String cmd = String.format( - "appops set %s %s %s", + "appops set --user %d %s %s %s", + UserHandle.myUserId(), // user id pkg, // Package name opName, // Appop (allow ? "allow" : "deny")); // Action