Loading tools/aapt2/cmd/Dump_test.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,22 @@ TEST_F(DumpTest, DumpBadging) { 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"}); Loading tools/aapt2/dump/DumpManifest.cpp +10 −1 Original line number Diff line number Diff line Loading @@ -448,6 +448,11 @@ class ManifestExtractor { /** Recursively visit the xml element tree and return a processed badging element tree. */ std::unique_ptr<Element> Visit(xml::Element* element); /** Resets target SDK to 0. */ void ResetTargetSdk() { target_sdk_ = 0; } /** Raises the target sdk value if the min target is greater than the current target. */ void RaiseTargetSdk(int32_t min_target) { if (min_target > target_sdk_) { Loading Loading @@ -799,6 +804,10 @@ class UsesSdkBadging : public ManifestExtractor::Element { target_sdk = GetAttributeInteger(FindAttribute(element, TARGET_SDK_VERSION_ATTR)); target_sdk_name = GetAttributeString(FindAttribute(element, TARGET_SDK_VERSION_ATTR)); // Resets target SDK first. This is required if APK contains multiple <uses-sdk> elements, // we only need to take the latest values. extractor()->ResetTargetSdk(); // Detect the target sdk of the element if ((min_sdk_name && *min_sdk_name == "Donut") || (target_sdk_name && *target_sdk_name == "Donut")) { Loading tools/aapt2/integration-tests/DumpTest/multiple_uses_sdk.apk 0 → 100644 +33.7 KiB File added.No diff preview for this file type. View file tools/aapt2/integration-tests/DumpTest/multiple_uses_sdk_expected.txt 0 → 100644 +23 −0 Original line number Diff line number Diff line package: name='com.test.e17wmultiapknexus' versionCode='107' versionName='14' platformBuildVersionName='2.3.3' platformBuildVersionCode='10' sdkVersion:'1' application-label:'w45wmultiapknexus_10' application-icon-120:'res/drawable-ldpi-v4/icon.png' application-icon-160:'res/drawable-mdpi-v4/icon.png' application-icon-240:'res/drawable-hdpi-v4/icon.png' application: label='w45wmultiapknexus_10' icon='res/drawable-mdpi-v4/icon.png' launchable-activity: name='com.test.e17wmultiapknexus.TestActivity' label='' icon='' compatible-screens:'500/320' uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE' uses-implied-permission: name='android.permission.WRITE_EXTERNAL_STORAGE' reason='targetSdkVersion < 4' uses-permission: name='android.permission.READ_PHONE_STATE' uses-implied-permission: name='android.permission.READ_PHONE_STATE' reason='targetSdkVersion < 4' uses-permission: name='android.permission.READ_EXTERNAL_STORAGE' uses-implied-permission: name='android.permission.READ_EXTERNAL_STORAGE' reason='requested WRITE_EXTERNAL_STORAGE' feature-group: label='' uses-feature: name='android.hardware.faketouch' uses-implied-feature: name='android.hardware.faketouch' reason='default feature for all apps' main supports-screens: 'small' 'normal' 'large' 'xlarge' supports-any-density: 'true' locales: '--_--' densities: '120' '160' '240' Loading
tools/aapt2/cmd/Dump_test.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,22 @@ TEST_F(DumpTest, DumpBadging) { 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"}); Loading
tools/aapt2/dump/DumpManifest.cpp +10 −1 Original line number Diff line number Diff line Loading @@ -448,6 +448,11 @@ class ManifestExtractor { /** Recursively visit the xml element tree and return a processed badging element tree. */ std::unique_ptr<Element> Visit(xml::Element* element); /** Resets target SDK to 0. */ void ResetTargetSdk() { target_sdk_ = 0; } /** Raises the target sdk value if the min target is greater than the current target. */ void RaiseTargetSdk(int32_t min_target) { if (min_target > target_sdk_) { Loading Loading @@ -799,6 +804,10 @@ class UsesSdkBadging : public ManifestExtractor::Element { target_sdk = GetAttributeInteger(FindAttribute(element, TARGET_SDK_VERSION_ATTR)); target_sdk_name = GetAttributeString(FindAttribute(element, TARGET_SDK_VERSION_ATTR)); // Resets target SDK first. This is required if APK contains multiple <uses-sdk> elements, // we only need to take the latest values. extractor()->ResetTargetSdk(); // Detect the target sdk of the element if ((min_sdk_name && *min_sdk_name == "Donut") || (target_sdk_name && *target_sdk_name == "Donut")) { Loading
tools/aapt2/integration-tests/DumpTest/multiple_uses_sdk.apk 0 → 100644 +33.7 KiB File added.No diff preview for this file type. View file
tools/aapt2/integration-tests/DumpTest/multiple_uses_sdk_expected.txt 0 → 100644 +23 −0 Original line number Diff line number Diff line package: name='com.test.e17wmultiapknexus' versionCode='107' versionName='14' platformBuildVersionName='2.3.3' platformBuildVersionCode='10' sdkVersion:'1' application-label:'w45wmultiapknexus_10' application-icon-120:'res/drawable-ldpi-v4/icon.png' application-icon-160:'res/drawable-mdpi-v4/icon.png' application-icon-240:'res/drawable-hdpi-v4/icon.png' application: label='w45wmultiapknexus_10' icon='res/drawable-mdpi-v4/icon.png' launchable-activity: name='com.test.e17wmultiapknexus.TestActivity' label='' icon='' compatible-screens:'500/320' uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE' uses-implied-permission: name='android.permission.WRITE_EXTERNAL_STORAGE' reason='targetSdkVersion < 4' uses-permission: name='android.permission.READ_PHONE_STATE' uses-implied-permission: name='android.permission.READ_PHONE_STATE' reason='targetSdkVersion < 4' uses-permission: name='android.permission.READ_EXTERNAL_STORAGE' uses-implied-permission: name='android.permission.READ_EXTERNAL_STORAGE' reason='requested WRITE_EXTERNAL_STORAGE' feature-group: label='' uses-feature: name='android.hardware.faketouch' uses-implied-feature: name='android.hardware.faketouch' reason='default feature for all apps' main supports-screens: 'small' 'normal' 'large' 'xlarge' supports-any-density: 'true' locales: '--_--' densities: '120' '160' '240'