[SDK Index] Add issue description as note

... for messages from developers.

Recent versions of the SDK Index snapshot contain a description for the
critical issues (messages from developers). Now we can display that
infromation in Android Studio. This change adds that description in the
genererateBlockingCriticalMessage and generateCriticalMessage methods so
users can see those descriptions without needing to navigate into the
SDK Index.

Bug: 336568007
Test: GooglePlaySdkIndexTest
Change-Id: Ifccc22ffdd3a0bc0ef19b21050c55e37fe6e4b9b
diff --git a/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GooglePlaySdkIndex.kt b/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GooglePlaySdkIndex.kt
index 3d24b78..14c18d9 100644
--- a/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GooglePlaySdkIndex.kt
+++ b/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/GooglePlaySdkIndex.kt
@@ -400,12 +400,20 @@
   }
 
   /** Generate a message for a library that has blocking critical issues */
-  fun generateBlockingCriticalMessage(groupId: String, artifactId: String, versionString: String) =
-    "[Prevents app release in Google Play Console] $groupId:$artifactId version $versionString has been reported as problematic by its author and will block publishing of your app to Play Console"
+  fun generateBlockingCriticalMessage(
+    groupId: String,
+    artifactId: String,
+    versionString: String,
+  ): String {
+    val note = getNoteFromDeveloper(groupId, artifactId, versionString)
+    return "[Prevents app release in Google Play Console] $groupId:$artifactId version $versionString has been reported as problematic by its author and will block publishing of your app to Play Console$note"
+  }
 
   /** Generate a message for a library that has non-blocking critical issues */
-  fun generateCriticalMessage(groupId: String, artifactId: String, versionString: String) =
-    "$groupId:$artifactId version $versionString has an associated message from its author"
+  fun generateCriticalMessage(groupId: String, artifactId: String, versionString: String): String {
+    val note = getNoteFromDeveloper(groupId, artifactId, versionString)
+    return "$groupId:$artifactId version $versionString has an associated message from its author$note"
+  }
 
   /** Generate a message for a library that has blocking outdated issues */
   fun generateBlockingOutdatedMessage(groupId: String, artifactId: String, versionString: String) =
@@ -507,4 +515,16 @@
     }
     return result
   }
+
+  private fun getNoteFromDeveloper(
+    groupId: String,
+    artifactId: String,
+    versionString: String,
+  ): String {
+    val labels = getLabels(groupId, artifactId, versionString) ?: return ""
+    val criticalIssue = labels.criticalIssueInfo ?: return ""
+    val message = criticalIssue.description
+    if (message.isNullOrBlank()) return ""
+    return ". Note: $message"
+  }
 }
diff --git a/lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GooglePlaySdkIndexTest.kt b/lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GooglePlaySdkIndexTest.kt
index 7d73d54..2095407 100644
--- a/lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GooglePlaySdkIndexTest.kt
+++ b/lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/GooglePlaySdkIndexTest.kt
@@ -55,7 +55,7 @@
                 .addVersions(
                   LibraryVersion.newBuilder().setVersionString("1.2.17").setIsLatestVersion(false)
                 )
-                // Critical
+                // Critical (with description)
                 .addVersions(
                   LibraryVersion.newBuilder()
                     .setVersionString("1.2.16")
@@ -88,6 +88,16 @@
                         .setPolicyIssuesInfo(LibraryVersionLabels.PolicyIssuesInfo.newBuilder())
                     )
                 )
+                // Critical (without description)
+                .addVersions(
+                  LibraryVersion.newBuilder()
+                    .setVersionString("1.2.13")
+                    .setIsLatestVersion(false)
+                    .setVersionLabels(
+                      LibraryVersionLabels.newBuilder()
+                        .setCriticalIssueInfo(LibraryVersionLabels.CriticalIssueInfo.newBuilder())
+                    )
+                )
             )
         )
         .addSdks(
@@ -464,7 +474,7 @@
 
   @Test
   fun `critical issues shown`() {
-    assertThat(countCriticalIssues()).isEqualTo(2)
+    assertThat(countCriticalIssues()).isEqualTo(3)
   }
 
   @Test
@@ -599,6 +609,35 @@
     assertThat(lintLink).isNull()
   }
 
+  @Test
+  fun `There is a note if description is present in blocking critical`() {
+    val expectedMessage =
+      "[Prevents app release in Google Play Console] log4j:log4j version 1.2.16 has been reported as problematic by its author and will block publishing of your app to Play Console. Note: This is a custom message from sdk developer."
+    assertThat(index.generateBlockingCriticalMessage("log4j", "log4j", "1.2.16"))
+      .isEqualTo(expectedMessage)
+  }
+
+  @Test
+  fun `There is a note if description is present in non blocking critical`() {
+    val expectedMessage =
+      "log4j:log4j version 1.2.16 has an associated message from its author. Note: This is a custom message from sdk developer."
+    assertThat(index.generateCriticalMessage("log4j", "log4j", "1.2.16")).isEqualTo(expectedMessage)
+  }
+
+  @Test
+  fun `Note not present if description is not present in blocking critical`() {
+    val expectedMessage =
+      "[Prevents app release in Google Play Console] log4j:log4j version 1.2.13 has been reported as problematic by its author and will block publishing of your app to Play Console"
+    assertThat(index.generateBlockingCriticalMessage("log4j", "log4j", "1.2.13"))
+      .isEqualTo(expectedMessage)
+  }
+
+  @Test
+  fun `Note not present if description is not present in non blocking critical`() {
+    val expectedMessage = "log4j:log4j version 1.2.13 has an associated message from its author"
+    assertThat(index.generateCriticalMessage("log4j", "log4j", "1.2.13")).isEqualTo(expectedMessage)
+  }
+
   private fun countOutdatedIssues(): Int {
     var result = 0
     for (sdk in proto.sdksList) {