Use the latest 'uses-sdk' tag to detect target SDK version.

At the moment aapt2 dumps information from the latest <uses-sdk> element
but uses all of them to detect target SDK which affects implied
permissions. Use only the latest one for detecting targetSdk as well.

Bug: b/243145989
Test: Dump_test
Change-Id: I70f828f1845ab070fa84c5297af12df24e7068dc
diff --git a/tools/aapt2/cmd/Dump_test.cpp b/tools/aapt2/cmd/Dump_test.cpp
index 03da364..b1c69cd 100644
--- a/tools/aapt2/cmd/Dump_test.cpp
+++ b/tools/aapt2/cmd/Dump_test.cpp
@@ -59,6 +59,22 @@
   ASSERT_EQ(output, expected);
 }
 
+TEST_F(DumpTest, DumpBadgingMultipleUsesSdkTakesLatest) {
+  auto apk_path = file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests",
+                                   "DumpTest", "multiple_uses_sdk.apk"});
+  auto loaded_apk = LoadedApk::LoadApkFromPath(apk_path, &noop_diag);
+
+  std::string output;
+  DumpBadgingToString(loaded_apk.get(), &output);
+
+  std::string expected;
+  auto expected_path =
+      file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests", "DumpTest",
+                       "multiple_uses_sdk_expected.txt"});
+  ::android::base::ReadFileToString(expected_path, &expected);
+  ASSERT_EQ(output, expected);
+}
+
 TEST_F(DumpTest, DumpBadgingAllComponents) {
   auto apk_path = file::BuildPath(
       {android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", "components.apk"});