Fix HarmfulAppWarningTest for secondary users.

Use cmd pm list packages instead of getAppPackageInfo to check if the app was actually
uninstalled for the current user. getAppPackageInfo uses dumpsys packages to list packages.
If two or more users exist on the device, the package still appears in the list, causing the
test to fail. Using cmd package list packages with the --user parameter will show only packages
installed for the current user.

For background on running CTS on secondary users, see go/aae-cts-on-u10

bug: 124493566
Test: cts-tradefed run cts-dev -a arm64-v8a -m CtsHarmfulAppWarningHostTestCases
On a prod pi phone, with both one and two users.

Change-Id: Id6cf0bd49615ab85df1dc565dd75f8297fc7d446
diff --git a/hostsidetests/harmfulappwarning/src/android/harmfulappwarning/cts/HarmfulAppWarningTest.java b/hostsidetests/harmfulappwarning/src/android/harmfulappwarning/cts/HarmfulAppWarningTest.java
index c93404d..4fc88fa 100644
--- a/hostsidetests/harmfulappwarning/src/android/harmfulappwarning/cts/HarmfulAppWarningTest.java
+++ b/hostsidetests/harmfulappwarning/src/android/harmfulappwarning/cts/HarmfulAppWarningTest.java
@@ -71,6 +71,9 @@
     private static final String GET_HARMFUL_APP_WARNING_COMMAND = String.format(
             "cmd package get-harmful-app-warning %s", TEST_APP_PACKAGE_NAME);
 
+    private static final String LIST_PACKAGES_COMMAND =
+            "cmd package list packages --user %d " + TEST_APP_PACKAGE_NAME;
+
     private ITestDevice mDevice;
 
     @Before
@@ -104,13 +107,15 @@
     }
 
     private void verifySampleAppUninstalled() throws DeviceNotAvailableException {
-        PackageInfo info = getDevice().getAppPackageInfo(TEST_APP_PACKAGE_NAME);
-        Assert.assertNull("Harmful application was not uninstalled", info);
+        String installedPackage = getDevice().executeShellCommand(
+                String.format(LIST_PACKAGES_COMMAND, getDevice().getCurrentUser()));
+        Assert.assertTrue("Harmful application was not uninstalled", installedPackage.isEmpty());
     }
 
     private void verifySampleAppInstalled() throws DeviceNotAvailableException {
-        PackageInfo info = getDevice().getAppPackageInfo(TEST_APP_PACKAGE_NAME);
-        Assert.assertNotNull("Harmful application was uninstalled", info);
+        String installedPackage = getDevice().executeShellCommand(
+                String.format(LIST_PACKAGES_COMMAND, getDevice().getCurrentUser()));
+        Assert.assertFalse("Harmful application was uninstalled", installedPackage.isEmpty());
     }
 
     /**