Check if ANGLE is installed before running tests

Normally, a device indicates that ANGLE is present with the RO property
ro.gfx.angle.supported. However, GSI overwrites the system.img that
contains the ANGLE libraries, without also overwriting the RO property.
This leads the CTS tests CtsAngleIntegrationHostTestCases to believe
ANGLE is installed, and then the tests fail since ANGLE is not actually
on the device and can't be loaded.

We had a few goals when writing the CTS tests to validate ANGLE on
devices with the libraries versus being skipped on devices without
ANGLE:
1. We didn't want to enforce the APK package name, in case other
   vendors wanted to include their own builds of ANGLE.
2. We aren't sure the ANGLE libraries will always be packaged in an
APK/APEX.

Neither of these are technical requirements. For the Android S QPR1,
ANGLE is only being shipped with P21 devices, not with any other
vendors, so restricting the package name is fine. Additionally, the
libraries will be packaged in an APK for the forseeable future.

To solve the GSI issue, the tests will be updated to check if the ANGLE
package com.android.angle is installed on the device before running.

If checking the package name in the future is too restrictive, we can
improve the checking once we have more concrete requirements.

Bug: b/198390495
Test: atest CtsAngleIntegrationHostTestCases
Change-Id: I5e2e10fcf7a1f3b2f4e2a7f957f1527fba956175
(cherry picked from commit f858b6eb5e00f683018e0da6d45443e8dd5a9fcd)
diff --git a/hostsidetests/angle/src/android/angle/cts/CtsAngleCommon.java b/hostsidetests/angle/src/android/angle/cts/CtsAngleCommon.java
index 3fb5c6c..e35e270 100644
--- a/hostsidetests/angle/src/android/angle/cts/CtsAngleCommon.java
+++ b/hostsidetests/angle/src/android/angle/cts/CtsAngleCommon.java
@@ -16,6 +16,7 @@
 package android.angle.cts;
 
 import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.device.PackageInfo;
 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
 
 import java.util.HashMap;
@@ -34,7 +35,6 @@
     static final String SETTINGS_GLOBAL_ANGLE_IN_USE_DIALOG_BOX = "show_angle_in_use_dialog_box";
 
     // System Properties
-    static final String PROPERTY_GFX_ANGLE_SUPPORTED = "ro.gfx.angle.supported";
     static final String PROPERTY_TEMP_RULES_FILE = "debug.angle.rules";
 
     // Rules File
@@ -43,6 +43,7 @@
     static final String DEVICE_TEMP_RULES_FILE_PATH = DEVICE_TEMP_RULES_FILE_DIRECTORY + "/" + DEVICE_TEMP_RULES_FILE_FILENAME;
 
     // ANGLE
+    static final String ANGLE_PACKAGE_NAME = "com.android.angle";
     static final String ANGLE_DRIVER_TEST_PKG = "com.android.angleIntegrationTest.driverTest";
     static final String ANGLE_DRIVER_TEST_SEC_PKG = "com.android.angleIntegrationTest.driverTestSecondary";
     static final String ANGLE_DRIVER_TEST_CLASS = "AngleDriverTestActivity";
@@ -103,10 +104,10 @@
         setProperty(device, PROPERTY_TEMP_RULES_FILE, "\"\"");
     }
 
-    static boolean isAngleLoadable(ITestDevice device) throws Exception {
-        String angleSupported = device.getProperty(PROPERTY_GFX_ANGLE_SUPPORTED);
+    static boolean isAngleInstalled(ITestDevice device) throws Exception {
+        PackageInfo info = device.getAppPackageInfo(ANGLE_PACKAGE_NAME);
 
-        return (angleSupported != null) && (angleSupported.equals("true"));
+        return (info != null);
     }
 
     static boolean isNativeDriverAngle(ITestDevice device) throws Exception {
diff --git a/hostsidetests/angle/src/android/angle/cts/CtsAngleDeveloperOptionHostTest.java b/hostsidetests/angle/src/android/angle/cts/CtsAngleDeveloperOptionHostTest.java
index 12770b1..a78f953 100644
--- a/hostsidetests/angle/src/android/angle/cts/CtsAngleDeveloperOptionHostTest.java
+++ b/hostsidetests/angle/src/android/angle/cts/CtsAngleDeveloperOptionHostTest.java
@@ -99,7 +99,7 @@
      */
     @Test
     public void testEnableAngleForAll() throws Exception {
-        Assume.assumeTrue(isAngleLoadable(getDevice()));
+        Assume.assumeTrue(isAngleInstalled(getDevice()));
 
         installApp(ANGLE_DRIVER_TEST_APP);
         installApp(ANGLE_DRIVER_TEST_SEC_APP);
@@ -124,7 +124,7 @@
      */
     @Test
     public void testUseDefaultDriver() throws Exception {
-        Assume.assumeTrue(isAngleLoadable(getDevice()));
+        Assume.assumeTrue(isAngleInstalled(getDevice()));
         Assume.assumeFalse(isNativeDriverAngle(getDevice()));
 
         installApp(ANGLE_DRIVER_TEST_APP);
@@ -142,7 +142,7 @@
      */
     @Test
     public void testUseAngleDriver() throws Exception {
-        Assume.assumeTrue(isAngleLoadable(getDevice()));
+        Assume.assumeTrue(isAngleInstalled(getDevice()));
         Assume.assumeFalse(isNativeDriverAngle(getDevice()));
 
         installApp(ANGLE_DRIVER_TEST_APP);
@@ -160,7 +160,7 @@
      */
     @Test
     public void testUseNativeDriver() throws Exception {
-        Assume.assumeTrue(isAngleLoadable(getDevice()));
+        Assume.assumeTrue(isAngleInstalled(getDevice()));
         Assume.assumeFalse(isNativeDriverAngle(getDevice()));
 
         installApp(ANGLE_DRIVER_TEST_APP);
@@ -178,7 +178,7 @@
      */
     @Test
     public void testSettingsLengthMismatch() throws Exception {
-        Assume.assumeTrue(isAngleLoadable(getDevice()));
+        Assume.assumeTrue(isAngleInstalled(getDevice()));
         Assume.assumeFalse(isNativeDriverAngle(getDevice()));
 
         installApp(ANGLE_DRIVER_TEST_APP);
@@ -202,7 +202,7 @@
      */
     @Test
     public void testUseInvalidDriver() throws Exception {
-        Assume.assumeTrue(isAngleLoadable(getDevice()));
+        Assume.assumeTrue(isAngleInstalled(getDevice()));
         Assume.assumeFalse(isNativeDriverAngle(getDevice()));
 
         installApp(ANGLE_DRIVER_TEST_APP);
@@ -219,7 +219,7 @@
      */
     @Test
     public void testUpdateDriverValues() throws Exception {
-        Assume.assumeTrue(isAngleLoadable(getDevice()));
+        Assume.assumeTrue(isAngleInstalled(getDevice()));
         Assume.assumeFalse(isNativeDriverAngle(getDevice()));
 
         installApp(ANGLE_DRIVER_TEST_APP);
@@ -242,7 +242,7 @@
      */
     @Test
     public void testMultipleDevOptionsAngleNative() throws Exception {
-        Assume.assumeTrue(isAngleLoadable(getDevice()));
+        Assume.assumeTrue(isAngleInstalled(getDevice()));
         Assume.assumeFalse(isNativeDriverAngle(getDevice()));
 
         installApp(ANGLE_DRIVER_TEST_APP);
@@ -267,7 +267,7 @@
      */
     @Test
     public void testMultipleUpdateDriverValues() throws Exception {
-        Assume.assumeTrue(isAngleLoadable(getDevice()));
+        Assume.assumeTrue(isAngleInstalled(getDevice()));
         Assume.assumeFalse(isNativeDriverAngle(getDevice()));
 
         installApp(ANGLE_DRIVER_TEST_APP);
@@ -325,7 +325,7 @@
      */
     @Test
     public void testAngleInUseDialogBoxWithAngle() throws Exception {
-        Assume.assumeTrue(isAngleLoadable(getDevice()));
+        Assume.assumeTrue(isAngleInstalled(getDevice()));
         Assume.assumeFalse(isNativeDriverAngle(getDevice()));
 
         setGlobalSetting(getDevice(), SETTINGS_GLOBAL_ANGLE_IN_USE_DIALOG_BOX, "1");
@@ -341,7 +341,7 @@
      */
     @Test
     public void testAngleInUseDialogBoxWithNative() throws Exception {
-        Assume.assumeTrue(isAngleLoadable(getDevice()));
+        Assume.assumeTrue(isAngleInstalled(getDevice()));
         Assume.assumeFalse(isNativeDriverAngle(getDevice()));
 
         setGlobalSetting(getDevice(), SETTINGS_GLOBAL_ANGLE_IN_USE_DIALOG_BOX, "1");