Merge "Don't override maxTargetSdk for trackingBug=170729553."
diff --git a/java/com/android/class2nonsdklist/UnsupportedAppUsageAnnotationHandler.java b/java/com/android/class2nonsdklist/UnsupportedAppUsageAnnotationHandler.java
index a213d51..dda63d7 100644
--- a/java/com/android/class2nonsdklist/UnsupportedAppUsageAnnotationHandler.java
+++ b/java/com/android/class2nonsdklist/UnsupportedAppUsageAnnotationHandler.java
@@ -34,7 +34,7 @@
     private static final String IMPLICIT_MEMBER_PROPERTY = "implicitMember";
     private static final String PUBLIC_ALTERNATIVES_PROPERTY = "publicAlternatives";
     private static final String TRACKING_BUG_PROPERTY = "trackingBug";
-    // we are temporarilly treating this bug id as if it is specified with maxTargetSdk=0
+    // APIs with this tracking bug are exempted from public alternatives requirements
     private static final Long RESTRICT_UNUSED_APIS_BUG = 170729553L;
     private static final Integer SDK_VERSION_R = 30;
 
@@ -157,11 +157,9 @@
             }
         }
 
+        // Is this API exempted from the public alternatives enforcement?
         boolean isSpecialTrackingBug = RESTRICT_UNUSED_APIS_BUG.equals(trackingBug) &&
                 SDK_VERSION_R.equals(maxTargetSdk);
-        if (isSpecialTrackingBug) {
-            maxTargetSdk = 0;
-        }
 
         if (context instanceof AnnotatedClassContext && implicitMemberSignature == null) {
             context.reportError(
@@ -188,19 +186,17 @@
         } catch (JavadocLinkSyntaxError | AlternativeNotFoundError e) {
             context.reportError(e.toString());
         } catch (RequiredAlternativeNotSpecifiedError e) {
-            context.reportError("Signature %s moved to %s without specifying public "
-                            + "alternatives; Refer to go/unsupportedappusage-public-alternatives "
-                            + "for details.",
-                    signature, mSdkVersionToFlagMap.get(maxTargetSdk));
+            if (!isSpecialTrackingBug) {
+                context.reportError(
+                        "Signature %s moved to %s without specifying public alternatives; "
+                        + "Refer to go/unsupportedappusage-public-alternatives for details.",
+                        signature, mSdkVersionToFlagMap.get(maxTargetSdk));
+            }
         }
 
         // Consume this annotation if it matches the predicate.
         if (mClassMemberFilter.test(new ClassMember(signature, isBridgeMethod))) {
-            Map<String, String> annotationProperties = stringifyAnnotationProperties(annotation);
-            if (isSpecialTrackingBug) {
-                annotationProperties.put(MAX_TARGET_SDK_PROPERTY, "0");
-            }
-            mAnnotationConsumer.consume(signature, annotationProperties,
+            mAnnotationConsumer.consume(signature, stringifyAnnotationProperties(annotation),
                     ImmutableSet.of(mSdkVersionToFlagMap.get(maxTargetSdk)));
         }
     }
diff --git a/javatest/com/android/class2nonsdklist/UnsupportedAppUsageAnnotationHandlerTest.java b/javatest/com/android/class2nonsdklist/UnsupportedAppUsageAnnotationHandlerTest.java
index 7e7d22c..818688e 100644
--- a/javatest/com/android/class2nonsdklist/UnsupportedAppUsageAnnotationHandlerTest.java
+++ b/javatest/com/android/class2nonsdklist/UnsupportedAppUsageAnnotationHandlerTest.java
@@ -601,14 +601,15 @@
         mJavac.compile();
         new AnnotationVisitor(mJavac.getCompiledClass("a.b.Class"), mStatus,
                 ImmutableMap.of("Lannotation/Anno2;", createGreylistHandler(x -> true,
-                        ImmutableMap.of(0, "flag0")))
+                        ImmutableMap.of(30, "flag30")))
         ).visit();
 
+        // The absence of a publicAlternatives value should *not* be an error
         assertNoErrors();
         ArgumentCaptor<Map<String, String>> properties = ArgumentCaptor.forClass(Map.class);
         verify(mConsumer, times(1)).consume(any(), properties.capture(), any());
         assertThat(properties.getValue()).containsExactly(
-                "maxTargetSdk", "0",
+                "maxTargetSdk", "30",
                 "trackingBug", "170729553");
     }
 }