Fix: AnnotationTest is failing for P-launching devices

AnnotationTest is failing for P-launching devices that do not have
Android Auto APIs. This is a regression caused by f838cc917d364faa4a346f4587fadc5b2be52003
that added Android Auto APIs to the expected APIs set.

AbstractApiChecker that the test is inheriting from ensures that all
documented APIs are found in the device under test. That behavior is
required for other signature tests such as
CtsCurrentApiSignatureTestCases, but is not required for this test.
The primary goal of this test is to make sure that the set of APIs (such
as ones annotated with @SystemApi) is not greater than the documented
API set. It is not an error that the former is smaller than the latter.

Fixing the issue by adding a new overridable method 'checkMissingClass'
that can be used for each test to handle the missing class case
differently.

Bug: 122276795
Test: run CtsSystemApiAnnotationTestCases on Pixel 3

Change-Id: Ifd58b10b2c496eb495f5286bf8413302a6c8895f
diff --git a/tests/signature/src/android/signature/cts/AbstractApiChecker.java b/tests/signature/src/android/signature/cts/AbstractApiChecker.java
index 3ea16e1..546b921 100644
--- a/tests/signature/src/android/signature/cts/AbstractApiChecker.java
+++ b/tests/signature/src/android/signature/cts/AbstractApiChecker.java
@@ -62,12 +62,14 @@
                     .findRequiredClass(classDescription, classProvider);
 
             if (runtimeClass == null) {
-                // No class found, notify the observer according to the class type
-                resultObserver.notifyFailure(FailureType.missing(classDescription),
-                        classDescription.getAbsoluteClassName(),
-                        "Classloader is unable to find " + classDescription
-                                .getAbsoluteClassName());
-
+                // No class found, notify the observer according to the class type,
+                // if missing a class isn't acceptable.
+                if (!allowMissingClass(classDescription)) {
+                    resultObserver.notifyFailure(FailureType.missing(classDescription),
+                            classDescription.getAbsoluteClassName(),
+                            "Classloader is unable to find " + classDescription
+                                    .getAbsoluteClassName());
+                }
                 return null;
             }
 
@@ -106,6 +108,17 @@
 
 
     /**
+     * Checks that a class that exists in the API xml file but that does not exist
+     * in the runtime is allowed or not.
+     *
+     * @param classDescription the class description that is missing.
+     * @return true if missing the class is acceptable.
+     */
+    protected boolean allowMissingClass(JDiffClassDescription classDescription) {
+        return false;
+    }
+
+    /**
      * Checks all fields in test class for compliance with the API xml.
      *
      * @param classDescription a description of a class in an API.
diff --git a/tests/signature/src/android/signature/cts/AnnotationChecker.java b/tests/signature/src/android/signature/cts/AnnotationChecker.java
index 9419df1..ab111a4 100644
--- a/tests/signature/src/android/signature/cts/AnnotationChecker.java
+++ b/tests/signature/src/android/signature/cts/AnnotationChecker.java
@@ -95,6 +95,17 @@
     }
 
     @Override
+    protected boolean allowMissingClass(JDiffClassDescription classDescription) {
+        // A class that exist in the API document is not found in the runtime.
+        // This can happen for classes that are optional (e.g. classes for
+        // Android Auto). This, however, should not be considered as a test
+        // failure, because the purpose of this test is to ensure that every
+        // runtime classes found in the device have more annotations than
+        // the documented.
+        return true;
+    }
+
+    @Override
     protected boolean checkClass(JDiffClassDescription classDescription, Class<?> runtimeClass) {
         // remove the class from the set if found
         annotatedClassesMap.remove(runtimeClass.getName());