diff --git a/tools/aapt2/Android.bp b/tools/aapt2/Android.bp index 0849600b0606c..cee3e5ca5da7b 100644 --- a/tools/aapt2/Android.bp +++ b/tools/aapt2/Android.bp @@ -24,6 +24,7 @@ package { } toolSources = [ + "cmd/ApkInfo.cpp", "cmd/Command.cpp", "cmd/Compile.cpp", "cmd/Convert.cpp", @@ -159,6 +160,7 @@ cc_library_host_static { "xml/XmlDom.cpp", "xml/XmlPullParser.cpp", "xml/XmlUtil.cpp", + "ApkInfo.proto", "Configuration.proto", "Resources.proto", "ResourcesInternal.proto", @@ -191,6 +193,7 @@ cc_test_host { "integration-tests/CompileTest/**/*", "integration-tests/CommandTests/**/*", "integration-tests/ConvertTest/**/*", + "integration-tests/DumpTest/**/*", ], } diff --git a/tools/aapt2/ApkInfo.proto b/tools/aapt2/ApkInfo.proto new file mode 100644 index 0000000000000..80bdccbc4dd23 --- /dev/null +++ b/tools/aapt2/ApkInfo.proto @@ -0,0 +1,338 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +syntax = "proto3"; + +import "frameworks/base/tools/aapt2/Resources.proto"; + +package aapt.pb; + +option java_package = "com.android.aapt"; + +// Top level message representing data extracted from the APK for 'apkinfo' +// command. +message ApkInfo { + message XmlFile { + string path = 1; + XmlNode root = 2; + } + + Badging badging = 1; + ResourceTable resource_table = 2; + repeated XmlFile xml_files = 3; +} + +// Data extracted from the manifest of the APK. +message Badging { + PackageInfo package = 1; + Application application = 2; + UsesSdk uses_sdk = 3; + UsesConfiguration uses_configuration = 4; + SupportsScreen supports_screen = 5; + SupportsInput supports_input = 6; + LaunchableActivity launchable_activity = 7; + LeanbackLaunchableActivity leanback_launchable_activity = 8; + StaticLibrary static_library = 9; + SdkLibrary sdk_library = 10; + Overlay overlay = 11; + PackageVerifier package_verifier = 12; + CompatibleScreens compatible_screens = 13; + Architectures architectures = 14; + SupportsGlTexture supports_gl_texture = 15; + Components components = 16; + + repeated string locales = 17; + repeated int32 densities = 18; + + repeated FeatureGroup feature_groups = 53; + repeated UsesPermission uses_permissions = 54; + repeated Permission permissions = 55; + repeated UsesLibrary uses_libraries = 56; + repeated UsesStaticLibrary uses_static_libraries = 57; + repeated UsesSdkLibrary uses_sdk_libraries = 58; + repeated UsesNativeLibrary uses_native_libraries = 59; + repeated UsesPackage uses_packages = 51; + + repeated Metadata metadata = 62; + repeated Property properties = 63; +} + +// Information extracted about package from and +// tags. +message PackageInfo { + enum InstallLocation { + DEFAULT_INSTALL_LOCATION = 0; + AUTO = 1; + INTERNAL_ONLY = 2; + PREFER_EXTERNAL = 3; + } + + string package = 1; + int32 version_code = 2; + string version_name = 3; + + string split = 4; + + string platform_version_name = 5; + string platform_version_code = 6; + + int32 compile_sdk_version = 7; + string compile_sdk_version_codename = 8; + + InstallLocation install_location = 9; + + string original_package = 10; +} + +// Information extracted from element. +message Application { + string label = 1; + string icon = 2; + string banner = 3; + + bool test_only = 4; + bool game = 5; + bool debuggable = 6; + + map locale_labels = 8; + map density_icons = 9; +} + +// Components defined in the APK. +message Components { + bool main = 1; + bool other_activities = 2; + bool other_receivers = 3; + bool other_services = 4; + + repeated string provided_components = 5; +} + +// Application's min and target SDKs. +message UsesSdk { + oneof min_sdk { + int32 min_sdk_version = 2; + string min_sdk_version_name = 3; + } + int32 max_sdk_version = 4; + oneof target_sdk { + int32 target_sdk_version = 5; + string target_sdk_version_name = 6; + } +} + +message UsesConfiguration { + int32 req_touch_screen = 1; + int32 req_keyboard_type = 2; + int32 req_hard_keyboard = 3; + int32 req_navigation = 4; + int32 req_five_way_nav = 5; +} + +// Screens supported by this application. +message SupportsScreen { + enum ScreenType { + UNSPECIFIED_SCREEN_TYPE = 0; + SMALL = 1; + NORMAL = 2; + LARGE = 3; + XLARGE = 4; + } + repeated ScreenType screens = 1; + bool supports_any_densities = 2; + int32 requires_smallest_width_dp = 3; + int32 compatible_width_limit_dp = 4; + int32 largest_width_limit_dp = 5; +} + +// Inputs supported by this application. +message SupportsInput { + repeated string inputs = 1; +} + +// Information about used features which is extracted from +// elements or implied from permissions. +message Feature { + message ImpliedData { + bool from_sdk_23_permission = 1; + repeated string reasons = 2; + } + + string name = 1; + bool required = 2; + int32 version = 3; + + ImpliedData implied_data = 4; +} + +message FeatureGroup { + string label = 1; + int32 open_gles_version = 2; + repeated Feature features = 3; +} + +// Information about permission requested by the application. +message UsesPermission { + message PermissionFlags { + bool never_for_location = 1; + } + + string name = 1; + int32 max_sdk_version = 2; + bool required = 3; + bool implied = 4; + bool sdk23_and_above = 5; + + repeated string required_features = 6; + repeated string required_not_features = 7; + + PermissionFlags permission_flags = 8; +} + +// Permission defined by the application. +message Permission { + string name = 1; +} + +// Data extracted about launchable activity. Launchable activity is an entry +// point on phone and tablet devices. +message LaunchableActivity { + string name = 1; + string icon = 2; + string label = 3; +} + +// Data extracted about leanback launchable activity. Leanback launchable +// activity is an entry point on TV devices. +message LeanbackLaunchableActivity { + string name = 1; + string icon = 2; + string label = 3; + string banner = 4; +} + +// Library used by the application. +message UsesLibrary { + string name = 1; + bool required = 2; +} + +// Static library this APK declares. +message StaticLibrary { + string name = 1; + int32 version = 2; + int32 version_major = 3; +} + +// Static library used by the application. +message UsesStaticLibrary { + string name = 1; + int32 version = 2; + int32 version_major = 3; + repeated string certificates = 4; +} + +// SDK library this APK declares. +message SdkLibrary { + string name = 1; + int32 version_major = 2; +} + +// SDK library used by the application. +message UsesSdkLibrary { + string name = 1; + int32 version_major = 2; + repeated string certificates = 3; +} + +// Native library used by the application. +message UsesNativeLibrary { + string name = 1; + bool required = 2; +} + +// Information extracted from elements defined across +// AndroidManifest.xml. +message Metadata { + string name = 1; + oneof value { + string value_string = 2; + int32 value_int = 3; + } + oneof resource { + string resource_string = 4; + int32 resource_int = 5; + } +} + +// Information about overlay that is declared in the APK. +message Overlay { + string target_package = 1; + int32 priority = 2; + bool static = 3; + string required_property_name = 4; + string required_property_value = 5; +} + +// Data extracted from element. +message PackageVerifier { + string name = 1; + string public_key = 2; +} + +// External packages used by the application +message UsesPackage { + string name = 1; + string package_type = 2; + int32 version = 3; + int32 version_major = 4; + repeated string certificates = 5; +} + +// Open GL textures format supported by the current application. +message SupportsGlTexture { + repeated string name = 1; +} + +// Screens compatible with the application. +message CompatibleScreens { + message Screen { + int32 size = 1; + int32 density = 2; + } + + repeated Screen screens = 1; +} + +// Architectures supported by the application. +message Architectures { + repeated string architectures = 1; + repeated string alt_architectures = 2; +} + +// Information extracted from elements defined across +// AndroidManifest.xml. +message Property { + string name = 1; + oneof value { + string value_string = 2; + int32 value_int = 3; + } + oneof resource { + string resource_string = 4; + int32 resource_int = 5; + } +} \ No newline at end of file diff --git a/tools/aapt2/Main.cpp b/tools/aapt2/Main.cpp index b249c6c128e13..e47bd67c4b8d8 100644 --- a/tools/aapt2/Main.cpp +++ b/tools/aapt2/Main.cpp @@ -24,11 +24,11 @@ #include #include +#include "Diagnostics.h" #include "android-base/stringprintf.h" #include "android-base/utf8.h" #include "androidfw/StringPiece.h" - -#include "Diagnostics.h" +#include "cmd/ApkInfo.h" #include "cmd/Command.h" #include "cmd/Compile.h" #include "cmd/Convert.h" @@ -72,6 +72,7 @@ class MainCommand : public Command { AddOptionalSubcommand(util::make_unique()); AddOptionalSubcommand(util::make_unique()); AddOptionalSubcommand(util::make_unique()); + AddOptionalSubcommand(util::make_unique(diagnostics)); } int Action(const std::vector& args) override { diff --git a/tools/aapt2/cmd/ApkInfo.cpp b/tools/aapt2/cmd/ApkInfo.cpp new file mode 100644 index 0000000000000..7c9df4c64d958 --- /dev/null +++ b/tools/aapt2/cmd/ApkInfo.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ApkInfo.h" + +#include + +#include +#include + +#include "Diagnostics.h" +#include "LoadedApk.h" +#include "android-base/file.h" // for O_BINARY +#include "android-base/utf8.h" +#include "androidfw/StringPiece.h" +#include "dump/DumpManifest.h" +#include "format/proto/ProtoSerialize.h" + +using ::android::StringPiece; + +namespace aapt { + +int ExportApkInfo(LoadedApk* apk, bool include_resource_table, + const std::unordered_set& xml_resources, pb::ApkInfo* out_apk_info, + IDiagnostics* diag) { + auto result = DumpBadgingProto(apk, out_apk_info->mutable_badging(), diag); + if (result != 0) { + return result; + } + + if (include_resource_table) { + SerializeTableToPb(*apk->GetResourceTable(), out_apk_info->mutable_resource_table(), diag); + } + + for (auto& xml_resource : xml_resources) { + auto xml = apk->LoadXml(xml_resource, diag); + if (xml) { + auto out_xml = out_apk_info->add_xml_files(); + out_xml->set_path(xml_resource); + SerializeXmlResourceToPb(*xml, out_xml->mutable_root(), + {/* remove_empty_text_nodes= */ true}); + } + } + + return 0; +} + +int ApkInfoCommand::Action(const std::vector& args) { + if (args.size() != 1) { + std::cerr << "must supply a single APK\n"; + Usage(&std::cerr); + return 1; + } + const StringPiece& path = args[0]; + std::unique_ptr apk = LoadedApk::LoadApkFromPath(path, diag_); + if (!apk) { + return 1; + } + + pb::ApkInfo out_apk_info; + int result = + ExportApkInfo(apk.get(), include_resource_table_, xml_resources_, &out_apk_info, diag_); + if (result != 0) { + diag_->Error(DiagMessage() << "Failed to serialize ApkInfo into proto."); + return result; + } + + int mode = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY; + int outfd = ::android::base::utf8::open(output_path_.c_str(), mode, 0666); + if (outfd == -1) { + diag_->Error(DiagMessage() << "Failed to open output file."); + return 1; + } + + bool is_serialized = out_apk_info.SerializeToFileDescriptor(outfd); + close(outfd); + + return is_serialized ? 0 : 1; +} + +} // namespace aapt \ No newline at end of file diff --git a/tools/aapt2/cmd/ApkInfo.h b/tools/aapt2/cmd/ApkInfo.h new file mode 100644 index 0000000000000..d682678ffe8a5 --- /dev/null +++ b/tools/aapt2/cmd/ApkInfo.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AAPT2_APKINFO_H +#define AAPT2_APKINFO_H + +#include "Command.h" +#include "Diagnostics.h" + +namespace aapt { + +class ApkInfoCommand : public Command { + public: + explicit ApkInfoCommand(IDiagnostics* diag) : Command("apkinfo"), diag_(diag) { + SetDescription("Dump information about an APK in binary proto format."); + AddRequiredFlag("-o", "Output path", &output_path_, Command::kPath); + AddOptionalSwitch("--include-resource-table", "Include the resource table data into output.", + &include_resource_table_); + AddOptionalFlagList("--include-xml", + "Include an XML file content into output. Multiple XML files might be " + "requested during single invocation.", + &xml_resources_); + } + + int Action(const std::vector& args) override; + + private: + IDiagnostics* diag_; + std::string output_path_; + bool include_resource_table_ = false; + std::unordered_set xml_resources_; +}; + +} // namespace aapt + +#endif // AAPT2_APKINFO_H diff --git a/tools/aapt2/cmd/ApkInfo_test.cpp b/tools/aapt2/cmd/ApkInfo_test.cpp new file mode 100644 index 0000000000000..70539c08d67b2 --- /dev/null +++ b/tools/aapt2/cmd/ApkInfo_test.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ApkInfo.h" + +#include "ApkInfo.pb.h" +#include "LoadedApk.h" +#include "android-base/unique_fd.h" +#include "io/StringStream.h" +#include "test/Test.h" + +using testing::Eq; +using testing::Ne; + +namespace aapt { + +using ApkInfoTest = CommandTestFixture; + +void AssertProducedAndExpectedInfo(const std::string& produced_path, + const std::string& expected_path) { + android::base::unique_fd fd(open(produced_path.c_str(), O_RDONLY)); + ASSERT_NE(fd.get(), -1); + + pb::ApkInfo produced_apk_info; + produced_apk_info.ParseFromFileDescriptor(fd.get()); + + std::string expected; + ::android::base::ReadFileToString(expected_path, &expected); + + EXPECT_EQ(produced_apk_info.DebugString(), expected); +} + +class NoopDiagnostics : public IDiagnostics { + public: + void Log(Level level, DiagMessageActual& actualMsg) override { + } +}; +static NoopDiagnostics noop_diag; + +TEST_F(ApkInfoTest, ApkInfoWithBadging) { + auto apk_path = file::BuildPath( + {android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", "components.apk"}); + auto out_info_path = GetTestPath("apk_info.pb"); + + ApkInfoCommand command(&noop_diag); + command.Execute({"-o", out_info_path, apk_path}, &std::cerr); + + auto expected_path = + file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", + "components_expected_proto.txt"}); + AssertProducedAndExpectedInfo(out_info_path, expected_path); +} + +TEST_F(ApkInfoTest, FullApkInfo) { + auto apk_path = file::BuildPath( + {android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", "components.apk"}); + auto out_info_path = GetTestPath("apk_info.pb"); + + ApkInfoCommand command(&noop_diag); + command.Execute({"-o", out_info_path, "--include-resource-table", "--include-xml", + "AndroidManifest.xml", "--include-xml", "res/oy.xml", apk_path}, + &std::cerr); + + auto expected_path = + file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", + "components_full_proto.txt"}); + AssertProducedAndExpectedInfo(out_info_path, expected_path); +} + +} // namespace aapt \ No newline at end of file diff --git a/tools/aapt2/cmd/Dump.h b/tools/aapt2/cmd/Dump.h index ec320ecd2a324..c7a35672dc903 100644 --- a/tools/aapt2/cmd/Dump.h +++ b/tools/aapt2/cmd/Dump.h @@ -131,6 +131,14 @@ class DumpBadgingCommand : public DumpApkCommand { &options_.include_meta_data); } + void SetIncludeMetaData(bool value) { + options_.include_meta_data = value; + } + + void SetOnlyPermissions(bool value) { + options_.only_permissions = value; + } + int Dump(LoadedApk* apk) override { return DumpManifest(apk, options_, GetPrinter(), GetDiagnostics()); } diff --git a/tools/aapt2/cmd/Dump_test.cpp b/tools/aapt2/cmd/Dump_test.cpp new file mode 100644 index 0000000000000..d018882fad9cf --- /dev/null +++ b/tools/aapt2/cmd/Dump_test.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Dump.h" + +#include "LoadedApk.h" +#include "io/StringStream.h" +#include "test/Test.h" +#include "text/Printer.h" + +using ::aapt::io::StringOutputStream; +using ::aapt::text::Printer; +using testing::Eq; +using testing::Ne; + +namespace aapt { + +using DumpTest = CommandTestFixture; + +class NoopDiagnostics : public IDiagnostics { + public: + void Log(Level level, DiagMessageActual& actualMsg) override { + } +}; +static NoopDiagnostics noop_diag; + +void DumpBadgingToString(LoadedApk* loaded_apk, std::string* output, bool include_meta_data = false, + bool only_permissions = false) { + StringOutputStream output_stream(output); + Printer printer(&output_stream); + + DumpBadgingCommand command(&printer, &noop_diag); + command.SetIncludeMetaData(include_meta_data); + command.SetOnlyPermissions(only_permissions); + ASSERT_EQ(command.Dump(loaded_apk), 0); + output_stream.Flush(); +} + +TEST_F(DumpTest, DumpBadging) { + auto apk_path = file::BuildPath( + {android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", "minimal.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", "minimal_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"}); + auto loaded_apk = LoadedApk::LoadApkFromPath(apk_path, &noop_diag); + + std::string output; + DumpBadgingToString(loaded_apk.get(), &output, /* include_meta_data= */ true); + + std::string expected; + auto expected_path = + file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", + "components_expected.txt"}); + ::android::base::ReadFileToString(expected_path, &expected); + ASSERT_EQ(output, expected); +} + +TEST_F(DumpTest, DumpBadgingPermissionsOnly) { + auto apk_path = file::BuildPath( + {android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", "components.apk"}); + auto loaded_apk = LoadedApk::LoadApkFromPath(apk_path, &noop_diag); + + std::string output; + DumpBadgingToString(loaded_apk.get(), &output, /* include_meta_data= */ false, + /* only_permissions= */ true); + + std::string expected; + auto expected_path = + file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests", "DumpTest", + "components_permissions_expected.txt"}); + ::android::base::ReadFileToString(expected_path, &expected); + ASSERT_EQ(output, expected); +} + +} // namespace aapt \ No newline at end of file diff --git a/tools/aapt2/dump/DumpManifest.cpp b/tools/aapt2/dump/DumpManifest.cpp index 9828b97982ed7..e36112d6126c2 100644 --- a/tools/aapt2/dump/DumpManifest.cpp +++ b/tools/aapt2/dump/DumpManifest.cpp @@ -17,17 +17,21 @@ #include "DumpManifest.h" #include +#include +#include +#include +#include +#include #include "LoadedApk.h" #include "SdkConstants.h" #include "ValueVisitor.h" +#include "androidfw/ConfigDescription.h" #include "io/File.h" #include "io/FileStream.h" #include "process/IResourceTableConsumer.h" #include "xml/XmlDom.h" -#include "androidfw/ConfigDescription.h" - using ::android::base::StringPrintf; using ::android::ConfigDescription; @@ -112,7 +116,101 @@ static xml::Attribute* FindAttribute(xml::Element *el, const std::string &packag return el->FindAttribute(package, name); } +class Architectures { + public: + std::set architectures; + std::set alt_architectures; + + void Print(text::Printer* printer) { + if (!architectures.empty()) { + printer->Print("native-code:"); + for (auto& arch : architectures) { + printer->Print(StringPrintf(" '%s'", arch.data())); + } + printer->Print("\n"); + } + if (!alt_architectures.empty()) { + printer->Print("alt-native-code:"); + for (auto& arch : alt_architectures) { + printer->Print(StringPrintf(" '%s'", arch.data())); + } + printer->Print("\n"); + } + } + + void ToProto(pb::Badging* out_badging) { + auto out_architectures = out_badging->mutable_architectures(); + for (auto& arch : architectures) { + out_architectures->add_architectures(arch); + } + for (auto& arch : alt_architectures) { + out_architectures->add_alt_architectures(arch); + } + } +}; + +const static std::array printable_components{"app-widget", + "device-admin", + "ime", + "wallpaper", + "accessibility", + "print-service", + "payment", + "search", + "document-provider", + "launcher", + "notification-listener", + "dream", + "camera", + "camera-secure"}; + +class Components { + public: + std::set> discovered_components; + bool other_activities = false; + bool other_receivers = false; + bool other_services = false; + + void Print(text::Printer* printer) { + for (auto& component : printable_components) { + if (discovered_components.find(component) != discovered_components.end()) { + printer->Print(StringPrintf("provides-component:'%s'\n", component.data())); + } + } + // Print presence of main activity + if (discovered_components.find("main") != discovered_components.end()) { + printer->Print("main\n"); + } + + if (other_activities) { + printer->Print("other-activities\n"); + } + if (other_receivers) { + printer->Print("other-receivers\n"); + } + if (other_services) { + printer->Print("other-services\n"); + } + } + + void ToProto(pb::Badging* out_badging) { + auto out_components = out_badging->mutable_components(); + for (auto& component : printable_components) { + auto discovered = discovered_components.find(component); + if (discovered != discovered_components.end()) { + out_components->add_provided_components(*discovered); + } + } + out_components->set_main(discovered_components.find("main") != discovered_components.end()); + out_components->set_other_activities(other_activities); + out_components->set_other_receivers(other_receivers); + out_components->set_other_services(other_services); + } +}; + class CommonFeatureGroup; +class FeatureGroup; +class SupportsScreen; class ManifestExtractor { public: @@ -128,7 +226,12 @@ class ManifestExtractor { static std::unique_ptr Inflate(ManifestExtractor* extractor, xml::Element* el); /** Writes out the extracted contents of the element. */ - virtual void Print(text::Printer* printer) { } + virtual void Print(text::Printer* printer) { + } + + /** Saves extracted information into Badging proto. */ + virtual void ToProto(pb::Badging* out_badging) { + } /** Adds an element to the list of children of the element. */ void AddChild(std::unique_ptr& child) { children_.push_back(std::move(child)); } @@ -338,7 +441,9 @@ class ManifestExtractor { return config; } - bool Dump(text::Printer* printer, IDiagnostics* diag); + bool Extract(IDiagnostics* diag); + bool Dump(text::Printer* printer); + bool DumpProto(pb::Badging* out_badging); /** Recursively visit the xml element tree and return a processed badging element tree. */ std::unique_ptr Visit(xml::Element* element); @@ -354,7 +459,7 @@ class ManifestExtractor { * Retrieves the default feature group that features are added into when * are not in a element. **/ - CommonFeatureGroup* GetCommonFeatureGroup() { + CommonFeatureGroup* common_feature_group() { return commonFeatureGroup_.get(); } @@ -387,11 +492,19 @@ class ManifestExtractor { DumpManifestOptions& options_; private: + std::unique_ptr doc_; std::unique_ptr commonFeatureGroup_ = util::make_unique(); std::map locales_; std::map densities_; std::vector parent_stack_; int32_t target_sdk_ = 0; + + std::unique_ptr root_element_; + std::vector> implied_permissions_; + std::vector feature_groups_; + Components components_; + Architectures architectures_; + const SupportsScreen* supports_screen_; }; template T* ElementCast(ManifestExtractor::Element* element); @@ -427,6 +540,7 @@ static ManifestExtractor::Element* FindElement(ManifestExtractor::Element* root, class Manifest : public ManifestExtractor::Element { public: Manifest() = default; + bool only_package_name; std::string package; int32_t versionCode; std::string versionName; @@ -462,7 +576,54 @@ class Manifest : public ManifestExtractor::Element { installLocation = GetAttributeInteger(FindAttribute(manifest, INSTALL_LOCATION_ATTR)); } + void ToProto(pb::Badging* out_badging) override { + auto out_package = out_badging->mutable_package(); + out_package->set_package(package); + out_package->set_version_code(versionCode); + out_package->set_version_name(versionName); + if (compilesdkVersion) { + out_package->set_compile_sdk_version(*compilesdkVersion); + } + if (compilesdkVersionCodename) { + out_package->set_compile_sdk_version_codename(*compilesdkVersionCodename); + } + if (platformVersionName) { + out_package->set_platform_version_name(*platformVersionName); + } else if (platformVersionNameInt) { + out_package->set_platform_version_name(std::to_string(*platformVersionNameInt)); + } + if (platformVersionCode) { + out_package->set_platform_version_code(*platformVersionCode); + } else if (platformVersionCodeInt) { + out_package->set_platform_version_code(std::to_string(*platformVersionCodeInt)); + } + + if (installLocation) { + switch (*installLocation) { + case 0: + out_package->set_install_location(pb::PackageInfo_InstallLocation_AUTO); + break; + case 1: + out_package->set_install_location(pb::PackageInfo_InstallLocation_INTERNAL_ONLY); + break; + case 2: + out_package->set_install_location(pb::PackageInfo_InstallLocation_PREFER_EXTERNAL); + break; + default: + break; + } + } + } + void Print(text::Printer* printer) override { + if (only_package_name) { + printer->Println(StringPrintf("package: %s", package.data())); + } else { + PrintFull(printer); + } + } + + void PrintFull(text::Printer* printer) { printer->Print(StringPrintf("package: name='%s' ", package.data())); printer->Print(StringPrintf("versionCode='%s' ", (versionCode > 0) ? std::to_string(versionCode).data() : "")); @@ -598,6 +759,27 @@ class Application : public ManifestExtractor::Element { printer->Print("application-debuggable\n"); } } + + void ToProto(pb::Badging* out_badging) override { + auto application = out_badging->mutable_application(); + application->set_label(android::ResTable::normalizeForOutput(label.data())); + application->set_icon(icon); + application->set_banner(banner); + application->set_test_only(test_only != 0); + application->set_game(is_game != 0); + application->set_debuggable(debuggable != 0); + + auto out_locale_labels = application->mutable_locale_labels(); + for (auto& p : locale_labels) { + if (!p.first.empty()) { + (*out_locale_labels)[p.first] = p.second; + } + } + auto out_density_icons = application->mutable_density_icons(); + for (auto& p : density_icons) { + (*out_density_icons)[p.first] = p.second; + } + } }; /** Represents elements. **/ @@ -647,6 +829,23 @@ class UsesSdkBadging : public ManifestExtractor::Element { printer->Print(StringPrintf("targetSdkVersion:'%s'\n", target_sdk_name->data())); } } + + void ToProto(pb::Badging* out_badging) override { + auto out_sdks = out_badging->mutable_uses_sdk(); + if (min_sdk) { + out_sdks->set_min_sdk_version(*min_sdk); + } else if (min_sdk_name) { + out_sdks->set_min_sdk_version_name(*min_sdk_name); + } + if (max_sdk) { + out_sdks->set_max_sdk_version(*max_sdk); + } + if (target_sdk) { + out_sdks->set_target_sdk_version(*target_sdk); + } else if (target_sdk_name) { + out_sdks->set_target_sdk_version_name(*target_sdk_name); + } + } }; /** Represents elements. **/ @@ -691,6 +890,15 @@ class UsesConfiguarion : public ManifestExtractor::Element { } printer->Print("\n"); } + + void ToProto(pb::Badging* out_badging) override { + auto out_configuration = out_badging->mutable_uses_configuration(); + out_configuration->set_req_touch_screen(req_touch_screen); + out_configuration->set_req_keyboard_type(req_keyboard_type); + out_configuration->set_req_hard_keyboard(req_hard_keyboard); + out_configuration->set_req_navigation(req_navigation); + out_configuration->set_req_five_way_nav(req_five_way_nav); + } }; /** Represents elements. **/ @@ -733,54 +941,24 @@ class SupportsScreen : public ManifestExtractor::Element { } } - void PrintScreens(text::Printer* printer, int32_t target_sdk) { - int32_t small_screen_temp = small_screen; - int32_t normal_screen_temp = normal_screen; - int32_t large_screen_temp = large_screen; - int32_t xlarge_screen_temp = xlarge_screen; - int32_t any_density_temp = any_density; - - // Determine default values for any unspecified screen sizes, - // based on the target SDK of the package. As of 4 (donut) - // the screen size support was introduced, so all default to - // enabled. - if (small_screen_temp > 0) { - small_screen_temp = target_sdk >= SDK_DONUT ? -1 : 0; - } - if (normal_screen_temp > 0) { - normal_screen_temp = -1; - } - if (large_screen_temp > 0) { - large_screen_temp = target_sdk >= SDK_DONUT ? -1 : 0; - } - if (xlarge_screen_temp > 0) { - // Introduced in Gingerbread. - xlarge_screen_temp = target_sdk >= SDK_GINGERBREAD ? -1 : 0; - } - if (any_density_temp > 0) { - any_density_temp = (target_sdk >= SDK_DONUT || requires_smallest_width_dp > 0 || - compatible_width_limit_dp > 0) - ? -1 - : 0; - } - + void PrintScreens(text::Printer* printer, int32_t target_sdk) const { // Print the formatted screen info printer->Print("supports-screens:"); - if (small_screen_temp != 0) { + if (IsSmallScreenSupported(target_sdk)) { printer->Print(" 'small'"); } - if (normal_screen_temp != 0) { + if (normal_screen != 0) { printer->Print(" 'normal'"); } - if (large_screen_temp != 0) { + if (IsLargeScreenSupported(target_sdk)) { printer->Print(" 'large'"); } - if (xlarge_screen_temp != 0) { + if (IsXLargeScreenSupported(target_sdk)) { printer->Print(" 'xlarge'"); } printer->Print("\n"); printer->Print(StringPrintf("supports-any-density: '%s'\n", - (any_density_temp ) ? "true" : "false")); + (IsAnyDensitySupported(target_sdk)) ? "true" : "false")); if (requires_smallest_width_dp > 0) { printer->Print(StringPrintf("requires-smallest-width:'%d'\n", requires_smallest_width_dp)); } @@ -791,6 +969,60 @@ class SupportsScreen : public ManifestExtractor::Element { printer->Print(StringPrintf("largest-width-limit:'%d'\n", largest_width_limit_dp)); } } + + void ToProtoScreens(pb::Badging* out_badging, int32_t target_sdk) const { + auto supports_screen = out_badging->mutable_supports_screen(); + if (IsSmallScreenSupported(target_sdk)) { + supports_screen->add_screens(pb::SupportsScreen_ScreenType_SMALL); + } + if (normal_screen != 0) { + supports_screen->add_screens(pb::SupportsScreen_ScreenType_NORMAL); + } + if (IsLargeScreenSupported(target_sdk)) { + supports_screen->add_screens(pb::SupportsScreen_ScreenType_LARGE); + } + if (IsXLargeScreenSupported(target_sdk)) { + supports_screen->add_screens(pb::SupportsScreen_ScreenType_XLARGE); + } + supports_screen->set_supports_any_densities(IsAnyDensitySupported(target_sdk)); + supports_screen->set_requires_smallest_width_dp(requires_smallest_width_dp); + supports_screen->set_compatible_width_limit_dp(compatible_width_limit_dp); + supports_screen->set_largest_width_limit_dp(largest_width_limit_dp); + } + + private: + // Determine default values for any unspecified screen sizes, + // based on the target SDK of the package. As of 4 (donut) + // the screen size support was introduced, so all default to + // enabled. + bool IsSmallScreenSupported(int32_t target_sdk) const { + if (small_screen > 0) { + return target_sdk >= SDK_DONUT; + } + return small_screen != 0; + } + + bool IsLargeScreenSupported(int32_t target_sdk) const { + if (large_screen > 0) { + return target_sdk >= SDK_DONUT; + } + return large_screen != 0; + } + + bool IsXLargeScreenSupported(int32_t target_sdk) const { + if (xlarge_screen > 0) { + return target_sdk >= SDK_GINGERBREAD; + } + return xlarge_screen != 0; + } + + bool IsAnyDensitySupported(int32_t target_sdk) const { + if (any_density > 0) { + return target_sdk >= SDK_DONUT || requires_smallest_width_dp > 0 || + compatible_width_limit_dp > 0; + } + return any_density != 0; + } }; /** Represents elements. **/ @@ -821,6 +1053,18 @@ class FeatureGroup : public ManifestExtractor::Element { } } + virtual void GroupToProto(pb::Badging* out_badging) { + auto feature_group = out_badging->add_feature_groups(); + feature_group->set_label(label); + feature_group->set_open_gles_version(open_gles_version); + for (auto& feature : features_) { + auto out_feature = feature_group->add_features(); + out_feature->set_name(feature.first); + out_feature->set_required(feature.second.required); + out_feature->set_version(feature.second.version); + } + } + /** Adds a feature to the feature group. */ void AddFeature(const std::string& name, bool required = true, int32_t version = -1) { features_.insert(std::make_pair(name, Feature{ required, version })); @@ -910,6 +1154,23 @@ class CommonFeatureGroup : public FeatureGroup { } } + virtual void GroupToProto(pb::Badging* out_badging) override { + FeatureGroup::GroupToProto(out_badging); + auto feature_group = + out_badging->mutable_feature_groups(out_badging->feature_groups_size() - 1); + for (auto& feature : implied_features_) { + if (features_.find(feature.first) == features_.end()) { + auto out_feature = feature_group->add_features(); + out_feature->set_name(feature.first); + auto implied_data = out_feature->mutable_implied_data(); + implied_data->set_from_sdk_23_permission(feature.second.implied_from_sdk_k23); + for (auto& reason : feature.second.reasons) { + implied_data->add_reasons(reason); + } + } + } + } + /** Returns true if the feature group has the given feature. */ bool HasFeature(const std::string& name) override { return FeatureGroup::HasFeature(name) @@ -1050,7 +1311,7 @@ class UsesFeature : public ManifestExtractor::Element { // common feature group FeatureGroup* feature_group = ElementCast(extractor()->parent_stack()[0]); if (!feature_group) { - feature_group = extractor()->GetCommonFeatureGroup(); + feature_group = extractor()->common_feature_group(); } else { // All features in side of elements are required. required = true; @@ -1068,12 +1329,14 @@ class UsesFeature : public ManifestExtractor::Element { class UsesPermission : public ManifestExtractor::Element { public: UsesPermission() = default; + bool implied; std::string name; std::vector requiredFeatures; std::vector requiredNotFeatures; int32_t required = true; int32_t maxSdkVersion = -1; int32_t usesPermissionFlags = 0; + std::string impliedReason; void Extract(xml::Element* element) override { name = GetAttributeStringDefault(FindAttribute(element, NAME_ATTR), ""); @@ -1094,7 +1357,7 @@ class UsesPermission : public ManifestExtractor::Element { FindAttribute(element, USES_PERMISSION_FLAGS_ATTR), 0); if (!name.empty()) { - CommonFeatureGroup* common = extractor()->GetCommonFeatureGroup(); + CommonFeatureGroup* common = extractor()->common_feature_group(); common->addImpliedFeaturesForPermission(extractor()->target_sdk(), name, false); } } @@ -1126,17 +1389,37 @@ class UsesPermission : public ManifestExtractor::Element { printer->Print("\n"); } } + if (implied) { + printer->Print(StringPrintf("uses-implied-permission: name='%s'", name.data())); + if (maxSdkVersion >= 0) { + printer->Print(StringPrintf(" maxSdkVersion='%d'", maxSdkVersion)); + } + if ((usesPermissionFlags & kNeverForLocation) != 0) { + printer->Print(StringPrintf(" usesPermissionFlags='neverForLocation'")); + } + printer->Print(StringPrintf(" reason='%s'\n", impliedReason.data())); + } } - void PrintImplied(text::Printer* printer, const std::string& reason) { - printer->Print(StringPrintf("uses-implied-permission: name='%s'", name.data())); - if (maxSdkVersion >= 0) { - printer->Print(StringPrintf(" maxSdkVersion='%d'", maxSdkVersion)); + void ToProto(pb::Badging* out_badging) override { + if (!name.empty()) { + auto permission = out_badging->add_uses_permissions(); + permission->set_name(name); + if (maxSdkVersion > 0) { + permission->set_max_sdk_version(maxSdkVersion); + } + if ((usesPermissionFlags & kNeverForLocation) != 0) { + permission->mutable_permission_flags()->set_never_for_location(true); + } + for (auto& requiredFeature : requiredFeatures) { + permission->add_required_features(requiredFeature); + } + for (auto& requiredNotFeature : requiredNotFeatures) { + permission->add_required_not_features(requiredNotFeature); + } + permission->set_required(required != 0); + permission->set_implied(implied); } - if ((usesPermissionFlags & kNeverForLocation) != 0) { - printer->Print(StringPrintf(" usesPermissionFlags='neverForLocation'")); - } - printer->Print(StringPrintf(" reason='%s'\n", reason.data())); } }; @@ -1184,7 +1467,7 @@ class UsesPermissionSdk23 : public ManifestExtractor::Element { maxSdkVersion = GetAttributeInteger(FindAttribute(element, MAX_SDK_VERSION_ATTR)); if (name) { - CommonFeatureGroup* common = extractor()->GetCommonFeatureGroup(); + CommonFeatureGroup* common = extractor()->common_feature_group(); common->addImpliedFeaturesForPermission(extractor()->target_sdk(), *name, true); } } @@ -1198,6 +1481,17 @@ class UsesPermissionSdk23 : public ManifestExtractor::Element { printer->Print("\n"); } } + + void ToProto(pb::Badging* out_badging) override { + if (name) { + auto permission = out_badging->add_uses_permissions(); + permission->set_sdk23_and_above(true); + permission->set_name(*name); + if (maxSdkVersion) { + permission->set_max_sdk_version(*maxSdkVersion); + } + } + } }; /** Represents elements. These elements are only printing when dumping permissions. **/ @@ -1215,6 +1509,12 @@ class Permission : public ManifestExtractor::Element { printer->Print(StringPrintf("permission: %s\n", name.data())); } } + + void ToProto(pb::Badging* out_badging) override { + if (!name.empty()) { + out_badging->add_permissions()->set_name(name); + } + } }; /** Represents elements. **/ @@ -1256,7 +1556,7 @@ class Activity : public ManifestExtractor::Element { auto orientation = GetAttributeInteger(FindAttribute(element, SCREEN_ORIENTATION_ATTR)); if (orientation) { - CommonFeatureGroup* common = extractor()->GetCommonFeatureGroup(); + CommonFeatureGroup* common = extractor()->common_feature_group(); int orien = *orientation; if (orien == 0 || orien == 6 || orien == 8) { // Requests landscape, sensorLandscape, or reverseLandscape. @@ -1295,6 +1595,22 @@ class Activity : public ManifestExtractor::Element { icon.data(), banner.data())); } } + + void ToProto(pb::Badging* out_badging) override { + if (has_main_action && has_launcher_category) { + auto activity = out_badging->mutable_launchable_activity(); + activity->set_name(name); + activity->set_label(android::ResTable::normalizeForOutput(label.data())); + activity->set_icon(icon); + } + if (has_leanback_launcher_category) { + auto activity = out_badging->mutable_leanback_launchable_activity(); + activity->set_name(name); + activity->set_label(android::ResTable::normalizeForOutput(label.data())); + activity->set_icon(icon); + activity->set_banner(banner); + } + } }; /** Represents elements. */ @@ -1395,6 +1711,14 @@ class UsesLibrary : public ManifestExtractor::Element { (required == 0) ? "-not-required" : "", name.data())); } } + + void ToProto(pb::Badging* out_badging) override { + if (!name.empty()) { + auto uses_library = out_badging->add_uses_libraries(); + uses_library->set_name(name); + uses_library->set_required(required != 0); + } + } }; /** Represents elements. **/ @@ -1419,6 +1743,13 @@ class StaticLibrary : public ManifestExtractor::Element { "static-library: name='%s' version='%d' versionMajor='%d'\n", name.data(), version, versionMajor)); } + + void ToProto(pb::Badging* out_badging) override { + auto static_library = out_badging->mutable_static_library(); + static_library->set_name(name); + static_library->set_version(version); + static_library->set_version_major(versionMajor); + } }; /** Represents elements. **/ @@ -1459,6 +1790,16 @@ class UsesStaticLibrary : public ManifestExtractor::Element { } printer->Print("\n"); } + + void ToProto(pb::Badging* out_badging) override { + auto uses_static_library = out_badging->add_uses_static_libraries(); + uses_static_library->set_name(name); + uses_static_library->set_version(version); + uses_static_library->set_version_major(versionMajor); + for (auto& cert : certDigests) { + uses_static_library->add_certificates(cert); + } + } }; /** Represents elements. **/ @@ -1480,6 +1821,12 @@ class SdkLibrary : public ManifestExtractor::Element { printer->Print( StringPrintf("sdk-library: name='%s' versionMajor='%d'\n", name.data(), versionMajor)); } + + void ToProto(pb::Badging* out_badging) override { + auto sdk_library = out_badging->mutable_sdk_library(); + sdk_library->set_name(name); + sdk_library->set_version_major(versionMajor); + } }; /** Represents elements. **/ @@ -1517,6 +1864,15 @@ class UsesSdkLibrary : public ManifestExtractor::Element { } printer->Print("\n"); } + + void ToProto(pb::Badging* out_badging) override { + auto uses_sdk_library = out_badging->add_uses_sdk_libraries(); + uses_sdk_library->set_name(name); + uses_sdk_library->set_version_major(versionMajor); + for (auto& cert : certDigests) { + uses_sdk_library->add_certificates(cert); + } + } }; /** Represents elements. **/ @@ -1540,6 +1896,14 @@ class UsesNativeLibrary : public ManifestExtractor::Element { (required == 0) ? "-not-required" : "", name.data())); } } + + void ToProto(pb::Badging* out_badging) override { + if (!name.empty()) { + auto uses_native_library = out_badging->add_uses_native_libraries(); + uses_native_library->set_name(name); + uses_native_library->set_required(required != 0); + } + } }; /** @@ -1565,21 +1929,39 @@ class MetaData : public ManifestExtractor::Element { void Print(text::Printer* printer) override { if (extractor()->options_.include_meta_data && !name.empty()) { - printer->Print(StringPrintf("meta-data: name='%s' ", name.data())); + printer->Print(StringPrintf("meta-data: name='%s'", name.data())); if (!value.empty()) { - printer->Print(StringPrintf("value='%s' ", value.data())); + printer->Print(StringPrintf(" value='%s'", value.data())); } else if (value_int) { - printer->Print(StringPrintf("value='%d' ", *value_int)); + printer->Print(StringPrintf(" value='%d'", *value_int)); } else { if (!resource.empty()) { - printer->Print(StringPrintf("resource='%s' ", resource.data())); + printer->Print(StringPrintf(" resource='%s'", resource.data())); } else if (resource_int) { - printer->Print(StringPrintf("resource='%d' ", *resource_int)); + printer->Print(StringPrintf(" resource='%d'", *resource_int)); } } printer->Print("\n"); } } + + void ToProto(pb::Badging* out_badging) override { + if (!name.empty()) { + auto metadata = out_badging->add_metadata(); + metadata->set_name(name); + if (!value.empty()) { + metadata->set_value_string(value); + } else if (value_int) { + metadata->set_value_int(*value_int); + } else { + if (!resource.empty()) { + metadata->set_resource_string(resource); + } else if (resource_int) { + metadata->set_resource_int(*resource_int); + } + } + } + } }; /** @@ -1709,6 +2091,13 @@ class SupportsInput : public ManifestExtractor::Element { printer->Print("\n"); } } + + void ToProto(pb::Badging* out_badging) override { + auto supports_input = out_badging->mutable_supports_input(); + for (auto& input : inputs) { + supports_input->add_inputs(input); + } + } }; /** Represents elements. **/ @@ -1742,6 +2131,12 @@ class OriginalPackage : public ManifestExtractor::Element { printer->Print(StringPrintf("original-package:'%s'\n", name->data())); } } + + void ToProto(pb::Badging* out_badging) override { + if (name) { + out_badging->mutable_package()->set_original_package(*name); + } + } }; @@ -1780,6 +2175,21 @@ class Overlay : public ManifestExtractor::Element { } printer->Print("\n"); } + + void ToProto(pb::Badging* out_badging) override { + auto overlay = out_badging->mutable_overlay(); + if (target_package) { + overlay->set_target_package(*target_package); + } + overlay->set_priority(priority); + overlay->set_static_(is_static); + if (required_property_name) { + overlay->set_required_property_name(*required_property_name); + } + if (required_property_value) { + overlay->set_required_property_value(*required_property_value); + } + } }; /** * Represents elements. **/ @@ -1800,6 +2210,14 @@ class PackageVerifier : public ManifestExtractor::Element { name->data(), public_key->data())); } } + + void ToProto(pb::Badging* out_badging) override { + auto package_verifier = out_badging->mutable_package_verifier(); + if (name && public_key) { + package_verifier->set_name(*name); + package_verifier->set_public_key(*public_key); + } + } }; /** Represents elements. **/ @@ -1848,6 +2266,21 @@ class UsesPackage : public ManifestExtractor::Element { } } } + + void ToProto(pb::Badging* out_badging) override { + if (name) { + auto uses_package = out_badging->add_uses_packages(); + uses_package->set_name(*name); + if (packageType) { + uses_package->set_package_type(*packageType); + uses_package->set_version(version); + uses_package->set_version_major(versionMajor); + for (auto& cert : certDigests) { + uses_package->add_certificates(cert); + } + } + } + } }; /** Represents elements. **/ @@ -1880,6 +2313,14 @@ class Screen : public ManifestExtractor::Element { size = GetAttributeInteger(FindAttribute(element, SCREEN_SIZE_ATTR)); density = GetAttributeInteger(FindAttribute(element, SCREEN_DENSITY_ATTR)); } + + void ToProto(pb::Badging* out_badging) override { + if (size && density) { + auto screen = out_badging->mutable_compatible_screens()->add_screens(); + screen->set_density(*density); + screen->set_size(*size); + } + } }; /** @@ -1925,6 +2366,12 @@ class SupportsGlTexture : public ManifestExtractor::Element { printer->Print(StringPrintf("supports-gl-texture:'%s'\n", name->data())); } } + + void ToProto(pb::Badging* out_badging) override { + if (name) { + out_badging->mutable_supports_gl_texture()->add_name(*name); + } + } }; /** Represents elements. **/ @@ -1960,6 +2407,24 @@ class Property : public ManifestExtractor::Element { } printer->Print("\n"); } + + void ToProto(pb::Badging* out_badging) override { + if (!name.empty()) { + auto property = out_badging->add_properties(); + property->set_name(name); + if (!value.empty()) { + property->set_value_string(value); + } else if (value_int) { + property->set_value_int(*value_int); + } else { + if (!resource.empty()) { + property->set_resource_string(resource); + } else if (resource_int) { + property->set_resource_int(*resource_int); + } + } + } + } }; /** Recursively prints the extracted badging element. */ @@ -1970,15 +2435,23 @@ static void Print(ManifestExtractor::Element* el, text::Printer* printer) { } } -bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) { +/** Recursively serializes extracted badging elements to proto. */ +static void ToProto(ManifestExtractor::Element* el, pb::Badging* out_badging) { + el->ToProto(out_badging); + for (auto& child : el->children()) { + ToProto(child.get(), out_badging); + } +} + +bool ManifestExtractor::Extract(IDiagnostics* diag) { // Load the manifest - std::unique_ptr doc = apk_->LoadXml("AndroidManifest.xml", diag); - if (doc == nullptr) { + doc_ = apk_->LoadXml("AndroidManifest.xml", diag); + if (doc_ == nullptr) { diag->Error(DiagMessage() << "failed to find AndroidManifest.xml"); return false; } - xml::Element* element = doc->root.get(); + xml::Element* element = doc_->root.get(); if (element->name != "manifest") { diag->Error(DiagMessage() << "manifest does not start with tag"); return false; @@ -1987,10 +2460,11 @@ bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) { // Print only the , , and elements if // printing only permission elements is requested if (options_.only_permissions) { - std::unique_ptr manifest_element = - ManifestExtractor::Element::Inflate(this, element); + root_element_ = ManifestExtractor::Element::Inflate(this, element); + + if (auto manifest = ElementCast(root_element_.get())) { + manifest->only_package_name = true; - if (auto manifest = ElementCast(manifest_element.get())) { for (xml::Element* child : element->GetChildElements()) { if (child->name == "uses-permission" || child->name == "uses-permission-sdk-23" || child->name == "permission") { @@ -1999,15 +2473,8 @@ bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) { manifest->AddChild(permission_element); } } - - printer->Print(StringPrintf("package: %s\n", manifest->package.data())); - ForEachChild(manifest, [&printer](ManifestExtractor::Element* el) -> void { - el->Print(printer); - }); - return true; } - return false; } @@ -2041,27 +2508,24 @@ bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) { } // Extract badging information - auto root = Visit(element); + root_element_ = Visit(element); // Filter out all "uses-sdk" tags besides the very last tag. The android runtime only uses the // attribute values from the last defined tag. std::vector filtered_uses_sdk_tags; - for (const auto& child : root->children()) { + for (const auto& child : root_element_->children()) { if (auto uses_sdk = ElementCast(child.get())) { filtered_uses_sdk_tags.emplace_back(uses_sdk); } } if (filtered_uses_sdk_tags.size() >= 2U) { filtered_uses_sdk_tags.pop_back(); - root->Filter([&](const ManifestExtractor::Element* e) { + root_element_->Filter([&](const ManifestExtractor::Element* e) { return std::find(filtered_uses_sdk_tags.begin(), filtered_uses_sdk_tags.end(), e) != filtered_uses_sdk_tags.end(); }); } - // Print the elements in order seen - Print(root.get(), printer); - /** Recursively checks the extracted elements for the specified permission. **/ auto FindPermission = [&](ManifestExtractor::Element* root, const std::string& name) -> ManifestExtractor::Element* { @@ -2073,30 +2537,30 @@ bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) { }); }; - auto PrintPermission = [&printer](const std::string& name, const std::string& reason, - int32_t max_sdk_version) -> void { + auto AddImpliedPermission = [&](const std::string& name, const std::string& reason, + int32_t max_sdk_version) -> void { auto permission = util::make_unique(); permission->name = name; permission->maxSdkVersion = max_sdk_version; - permission->Print(printer); - permission->PrintImplied(printer, reason); + permission->implied = true; + permission->impliedReason = reason; + implied_permissions_.push_back(std::move(permission)); }; // Implied permissions // Pre-1.6 implicitly granted permission compatibility logic - CommonFeatureGroup* common_feature_group = GetCommonFeatureGroup(); bool insert_write_external = false; auto write_external_permission = ElementCast( - FindPermission(root.get(), "android.permission.WRITE_EXTERNAL_STORAGE")); + FindPermission(root_element_.get(), "android.permission.WRITE_EXTERNAL_STORAGE")); if (target_sdk() < SDK_DONUT) { if (!write_external_permission) { - PrintPermission("android.permission.WRITE_EXTERNAL_STORAGE", "targetSdkVersion < 4", -1); + AddImpliedPermission("android.permission.WRITE_EXTERNAL_STORAGE", "targetSdkVersion < 4", -1); insert_write_external = true; } - if (!FindPermission(root.get(), "android.permission.READ_PHONE_STATE")) { - PrintPermission("android.permission.READ_PHONE_STATE", "targetSdkVersion < 4", -1); + if (!FindPermission(root_element_.get(), "android.permission.READ_PHONE_STATE")) { + AddImpliedPermission("android.permission.READ_PHONE_STATE", "targetSdkVersion < 4", -1); } } @@ -2104,62 +2568,60 @@ bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) { // force them to always take READ_EXTERNAL_STORAGE as well. We always // do this (regardless of target API version) because we can't have // an app with write permission but not read permission. - auto read_external = FindPermission(root.get(), "android.permission.READ_EXTERNAL_STORAGE"); + auto read_external = + FindPermission(root_element_.get(), "android.permission.READ_EXTERNAL_STORAGE"); if (!read_external && (insert_write_external || write_external_permission)) { - PrintPermission("android.permission.READ_EXTERNAL_STORAGE", - "requested WRITE_EXTERNAL_STORAGE", - (write_external_permission) ? write_external_permission->maxSdkVersion : -1); + AddImpliedPermission( + "android.permission.READ_EXTERNAL_STORAGE", "requested WRITE_EXTERNAL_STORAGE", + (write_external_permission) ? write_external_permission->maxSdkVersion : -1); } // Pre-JellyBean call log permission compatibility. if (target_sdk() < SDK_JELLY_BEAN) { - if (!FindPermission(root.get(), "android.permission.READ_CALL_LOG") - && FindPermission(root.get(), "android.permission.READ_CONTACTS")) { - PrintPermission("android.permission.READ_CALL_LOG", - "targetSdkVersion < 16 and requested READ_CONTACTS", -1); + if (!FindPermission(root_element_.get(), "android.permission.READ_CALL_LOG") && + FindPermission(root_element_.get(), "android.permission.READ_CONTACTS")) { + AddImpliedPermission("android.permission.READ_CALL_LOG", + "targetSdkVersion < 16 and requested READ_CONTACTS", -1); } - if (!FindPermission(root.get(), "android.permission.WRITE_CALL_LOG") - && FindPermission(root.get(), "android.permission.WRITE_CONTACTS")) { - PrintPermission("android.permission.WRITE_CALL_LOG", - "targetSdkVersion < 16 and requested WRITE_CONTACTS", -1); + if (!FindPermission(root_element_.get(), "android.permission.WRITE_CALL_LOG") && + FindPermission(root_element_.get(), "android.permission.WRITE_CONTACTS")) { + AddImpliedPermission("android.permission.WRITE_CALL_LOG", + "targetSdkVersion < 16 and requested WRITE_CONTACTS", -1); } } // If the app hasn't declared the touchscreen as a feature requirement (either // directly or implied, required or not), then the faketouch feature is implied. - if (!common_feature_group->HasFeature("android.hardware.touchscreen")) { - common_feature_group->addImpliedFeature("android.hardware.faketouch", - "default feature for all apps", false); + if (!common_feature_group()->HasFeature("android.hardware.touchscreen")) { + common_feature_group()->addImpliedFeature("android.hardware.faketouch", + "default feature for all apps", false); } // Only print the common feature group if no feature group is defined std::vector feature_groups; - ForEachChild(root.get(), [&feature_groups](ManifestExtractor::Element* el) -> void { + ForEachChild(root_element_.get(), [&feature_groups](ManifestExtractor::Element* el) -> void { if (auto feature_group = ElementCast(el)) { feature_groups.push_back(feature_group); } }); if (feature_groups.empty()) { - common_feature_group->PrintGroup(printer); + feature_groups_.push_back(common_feature_group()); } else { // Merge the common feature group into the feature group for (auto& feature_group : feature_groups) { - feature_group->open_gles_version = std::max(feature_group->open_gles_version, - common_feature_group->open_gles_version); - feature_group->Merge(common_feature_group); - feature_group->PrintGroup(printer); + feature_group->Merge(common_feature_group()); + feature_groups_.push_back(feature_group); } }; // Collect the component types of the application - std::set components; - ForEachChild(root.get(), [&components](ManifestExtractor::Element* el) -> void { + ForEachChild(root_element_.get(), [&](ManifestExtractor::Element* el) -> void { if (ElementCast(el)) { auto action = ElementCast(el); if (!action->component.empty()) { - components.insert(action->component); + components_.discovered_components.insert(action->component); return; } } @@ -2167,15 +2629,14 @@ bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) { if (ElementCast(el)) { auto category = ElementCast(el); if (!category->component.empty()) { - components.insert(category->component); + components_.discovered_components.insert(category->component); return; } } }); // Check for the payment component - auto apk = apk_; - ForEachChild(root.get(), [&apk, &components, &diag](ManifestExtractor::Element* el) -> void { + ForEachChild(root_element_.get(), [this, &diag](ManifestExtractor::Element* el) -> void { if (auto service = ElementCast(el)) { auto host_apdu_action = ElementCast(FindElement(service, [&](ManifestExtractor::Element* el) -> bool { @@ -2193,140 +2654,87 @@ bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) { return false; })); - ForEachChild(service, [&apk, &components, &diag, &host_apdu_action, - &offhost_apdu_action](ManifestExtractor::Element* el) -> void { - if (auto meta_data = ElementCast(el)) { - if ((meta_data->name == "android.nfc.cardemulation.host_apdu_service" && host_apdu_action) - || (meta_data->name == "android.nfc.cardemulation.off_host_apdu_service" - && offhost_apdu_action)) { + ForEachChild(service, + [this, &diag, &host_apdu_action, + &offhost_apdu_action](ManifestExtractor::Element* el) -> void { + if (auto meta_data = ElementCast(el)) { + if ((meta_data->name == "android.nfc.cardemulation.host_apdu_service" && + host_apdu_action) || + (meta_data->name == "android.nfc.cardemulation.off_host_apdu_service" && + offhost_apdu_action)) { + // Attempt to load the resource file + if (!meta_data->resource.empty()) { + return; + } + auto resource = this->apk_->LoadXml(meta_data->resource, diag); + if (!resource) { + return; + } - // Attempt to load the resource file - if (!meta_data->resource.empty()) { - return; - } - auto resource = apk->LoadXml(meta_data->resource, diag); - if (!resource) { - return; - } - - // Look for the payment category on an element - auto& root = resource.get()->root; - if ((host_apdu_action && root->name == "host-apdu-service") - || (offhost_apdu_action && root->name == "offhost-apdu-service")) { - - for (auto& child : root->GetChildElements()) { - if (child->name == "aid-group") { - auto category = FindAttribute(child, CATEGORY_ATTR); - if (category && category->value == "payment") { - components.insert("payment"); - return; - } - } - } - } - } - } - }); + // Look for the payment category on an element + auto& root = resource.get()->root; + if ((host_apdu_action && root->name == "host-apdu-service") || + (offhost_apdu_action && root->name == "offhost-apdu-service")) { + for (auto& child : root->GetChildElements()) { + if (child->name == "aid-group") { + auto category = FindAttribute(child, CATEGORY_ATTR); + if (category && category->value == "payment") { + this->components_.discovered_components.insert("payment"); + return; + } + } + } + } + } + } + }); } }); - // Print the components types if they are present - auto PrintComponent = [&components, &printer](const std::string& component) -> void { - if (components.find(component) != components.end()) { - printer->Print(StringPrintf("provides-component:'%s'\n", component.data())); - } - }; - - PrintComponent("app-widget"); - PrintComponent("device-admin"); - PrintComponent("ime"); - PrintComponent("wallpaper"); - PrintComponent("accessibility"); - PrintComponent("print-service"); - PrintComponent("payment"); - PrintComponent("search"); - PrintComponent("document-provider"); - PrintComponent("launcher"); - PrintComponent("notification-listener"); - PrintComponent("dream"); - PrintComponent("camera"); - PrintComponent("camera-secure"); - - // Print presence of main activity - if (components.find("main") != components.end()) { - printer->Print("main\n"); - } - - // Print presence of activities, recivers, and services with no special components - FindElement(root.get(), [&printer](ManifestExtractor::Element* el) -> bool { + // Print presence of activities, receivers, and services with no special components + FindElement(root_element_.get(), [&](ManifestExtractor::Element* el) -> bool { if (auto activity = ElementCast(el)) { if (!activity->has_component_) { - printer->Print("other-activities\n"); + components_.other_activities = true; return true; } } return false; }); - FindElement(root.get(), [&printer](ManifestExtractor::Element* el) -> bool { + FindElement(root_element_.get(), [&](ManifestExtractor::Element* el) -> bool { if (auto receiver = ElementCast(el)) { if (!receiver->has_component) { - printer->Print("other-receivers\n"); + components_.other_receivers = true; return true; } } return false; }); - FindElement(root.get(), [&printer](ManifestExtractor::Element* el) -> bool { + FindElement(root_element_.get(), [&](ManifestExtractor::Element* el) -> bool { if (auto service = ElementCast(el)) { if (!service->has_component) { - printer->Print("other-services\n"); + components_.other_services = true; return true; } } return false; }); - // Print the supported screens - SupportsScreen* screen = ElementCast(FindElement(root.get(), - [&](ManifestExtractor::Element* el) -> bool { - return ElementCast(el) != nullptr; - })); + // Gather the supported screens + const static SupportsScreen default_screens{}; + SupportsScreen* screen = ElementCast( + FindElement(root_element_.get(), [&](ManifestExtractor::Element* el) -> bool { + return ElementCast(el) != nullptr; + })); + supports_screen_ = screen ? screen : &default_screens; - if (screen) { - screen->PrintScreens(printer, target_sdk_); - } else { - // Print the default supported screens - SupportsScreen default_screens; - default_screens.PrintScreens(printer, target_sdk_); - } - - // Print all the unique locales of the apk - printer->Print("locales:"); - for (auto& config : locales_) { - if (config.first.empty()) { - printer->Print(" '--_--'"); - } else { - printer->Print(StringPrintf(" '%s'", config.first.data())); - } - } - printer->Print("\n"); - - // Print all the densities locales of the apk - printer->Print("densities:"); - for (auto& config : densities_) { - printer->Print(StringPrintf(" '%d'", config.first)); - } - printer->Print("\n"); - - // Print the supported architectures of the app - std::set architectures; + // Gather the supported architectures_ of the app + std::set architectures_from_apk; auto it = apk_->GetFileCollection()->Iterator(); while (it->HasNext()) { auto file_path = it->Next()->GetSource().path; - - size_t pos = file_path.find("lib/"); if (pos != std::string::npos) { file_path = file_path.substr(pos + 4); @@ -2335,17 +2743,18 @@ bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) { file_path = file_path.substr(0, pos); } - architectures.insert(file_path); + architectures_from_apk.insert(file_path); } } // Determine if the application has multiArch supports - auto has_multi_arch = FindElement(root.get(), [&](ManifestExtractor::Element* el) -> bool { - if (auto application = ElementCast(el)) { - return application->has_multi_arch; - } - return false; - }); + auto has_multi_arch = + FindElement(root_element_.get(), [&](ManifestExtractor::Element* el) -> bool { + if (auto application = ElementCast(el)) { + return application->has_multi_arch; + } + return false; + }); bool output_alt_native_code = false; // A multiArch package is one that contains 64-bit and @@ -2366,29 +2775,85 @@ bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) { const std::string kIntel64 = "x86_64"; const std::string kArm64 = "arm64-v8a"; - auto arch = architectures.find(kIntel64); - if (arch == architectures.end()) { - arch = architectures.find(kArm64); + auto arch = architectures_from_apk.find(kIntel64); + if (arch == architectures_from_apk.end()) { + arch = architectures_from_apk.find(kArm64); } - if (arch != architectures.end()) { - printer->Print(StringPrintf("native-code: '%s'\n", arch->data())); - architectures.erase(arch); + if (arch != architectures_from_apk.end()) { + architectures_.architectures.insert(*arch); + architectures_from_apk.erase(arch); output_alt_native_code = true; } } - - if (architectures.size() > 0) { + for (auto& arch : architectures_from_apk) { if (output_alt_native_code) { - printer->Print("alt-"); + architectures_.alt_architectures.insert(arch); + } else { + architectures_.architectures.insert(arch); } - printer->Print("native-code:"); - for (auto& arch : architectures) { - printer->Print(StringPrintf(" '%s'", arch.data())); - } - printer->Print("\n"); + } + return true; +} + +bool ManifestExtractor::Dump(text::Printer* printer) { + Print(root_element_.get(), printer); + if (options_.only_permissions) { + return true; } + for (auto& implied_permission : implied_permissions_) { + implied_permission->Print(printer); + } + for (auto& feature_group : feature_groups_) { + feature_group->PrintGroup(printer); + } + components_.Print(printer); + supports_screen_->PrintScreens(printer, target_sdk_); + + // Print all the unique locales of the apk + printer->Print("locales:"); + for (auto& config : locales_) { + if (config.first.empty()) { + printer->Print(" '--_--'"); + } else { + printer->Print(StringPrintf(" '%s'", config.first.data())); + } + } + printer->Print("\n"); + + // Print all the densities locales of the apk + printer->Print("densities:"); + for (auto& config : densities_) { + printer->Print(StringPrintf(" '%d'", config.first)); + } + printer->Print("\n"); + + architectures_.Print(printer); + return true; +} + +bool ManifestExtractor::DumpProto(pb::Badging* out_badging) { + ToProto(root_element_.get(), out_badging); + for (auto& implied_permission : implied_permissions_) { + implied_permission->ToProto(out_badging); + } + for (auto& feature_group : feature_groups_) { + feature_group->GroupToProto(out_badging); + } + components_.ToProto(out_badging); + supports_screen_->ToProtoScreens(out_badging, target_sdk_); + + for (auto& config : locales_) { + if (!config.first.empty()) { + out_badging->add_locales(config.first); + } + } + for (auto& config : densities_) { + out_badging->add_densities(config.first); + } + + architectures_.ToProto(out_badging); return true; } @@ -2527,11 +2992,23 @@ std::unique_ptr ManifestExtractor::Visit(xml::Elemen return element; } - int DumpManifest(LoadedApk* apk, DumpManifestOptions& options, text::Printer* printer, IDiagnostics* diag) { ManifestExtractor extractor(apk, options); - return extractor.Dump(printer, diag) ? 0 : 1; + if (!extractor.Extract(diag)) { + return 1; + } + return extractor.Dump(printer) ? 0 : 1; +} + +int DumpBadgingProto(LoadedApk* apk, pb::Badging* out_badging, IDiagnostics* diag) { + DumpManifestOptions options{/* include_meta_data= */ true, + /* only_permissions= */ false}; + ManifestExtractor extractor(apk, options); + if (!extractor.Extract(diag)) { + return 1; + } + return extractor.DumpProto(out_badging) ? 0 : 1; } } // namespace aapt diff --git a/tools/aapt2/dump/DumpManifest.h b/tools/aapt2/dump/DumpManifest.h index daf22ed57a84d..72d1b464f1f5d 100644 --- a/tools/aapt2/dump/DumpManifest.h +++ b/tools/aapt2/dump/DumpManifest.h @@ -17,6 +17,7 @@ #ifndef AAPT2_DUMP_MANIFEST_H #define AAPT2_DUMP_MANIFEST_H +#include "ApkInfo.pb.h" #include "Diagnostics.h" #include "LoadedApk.h" #include "text/Printer.h" @@ -34,6 +35,9 @@ struct DumpManifestOptions { int DumpManifest(LoadedApk* apk, DumpManifestOptions& options, text::Printer* printer, IDiagnostics* diag); +/** Extracts badging data from the manifest of the APK and stores it in Badging proto. */ +int DumpBadgingProto(LoadedApk* apk, pb::Badging* out_badging, IDiagnostics* diag); + } // namespace aapt #endif // AAPT2_DUMP_MANIFEST_H \ No newline at end of file diff --git a/tools/aapt2/integration-tests/DumpTest/components.apk b/tools/aapt2/integration-tests/DumpTest/components.apk new file mode 100644 index 0000000000000..deb55ea6fda36 Binary files /dev/null and b/tools/aapt2/integration-tests/DumpTest/components.apk differ diff --git a/tools/aapt2/integration-tests/DumpTest/components_expected.txt b/tools/aapt2/integration-tests/DumpTest/components_expected.txt new file mode 100644 index 0000000000000..79b6706e4a9f4 --- /dev/null +++ b/tools/aapt2/integration-tests/DumpTest/components_expected.txt @@ -0,0 +1,56 @@ +package: name='com.example.bundletool.minimal' versionCode='1' versionName='1.0' platformBuildVersionName='12' platformBuildVersionCode='31' compileSdkVersion='31' compileSdkVersionCodename='12' +sdkVersion:'21' +targetSdkVersion:'31' +uses-configuration: reqTouchScreen='3' reqKeyboardType='2' reqHardKeyboard='-1' reqNavigation='3' reqFiveWayNav='-1' +supports-gl-texture:'GL_OES_compressed_paletted_texture' +uses-permission: name='android.permission.BIND_ACCESSIBILITY_SERVICE' maxSdkVersion='24' +uses-permission-sdk-23: name='android.permission.RECEIVE_SMS' +uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE' +compatible-screens:'500/240','400/160' +application-label:'minimal' +application-icon-160:'res/uF.xml' +application-icon-240:'res/uF.xml' +application-icon-320:'res/uF.xml' +application-icon-480:'res/uF.xml' +application-icon-640:'res/uF.xml' +application-icon-65534:'res/uF.xml' +application: label='minimal' icon='res/uF.xml' +uses-library:'mylib1' +uses-library-not-required:'my_optional_lib' +uses-native-library:'native1' +uses-native-library-not-required:'optional' +launchable-activity: name='com.example.bundletool.minimal.MainActivity' label='minimal' icon='' +meta-data: name='android.nfc.cardemulation.host_apdu_service' resource='res/dU.xml' +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.bluetooth' + uses-feature: name='android.hardware.camera' + uses-feature: name='android.hardware.faketouch' + uses-implied-feature: name='android.hardware.faketouch' reason='default feature for all apps' + uses-feature-sdk-23: name='android.hardware.telephony' + uses-implied-feature-sdk-23: name='android.hardware.telephony' reason='requested a telephony permission' +provides-component:'app-widget' +provides-component:'device-admin' +provides-component:'ime' +provides-component:'wallpaper' +provides-component:'accessibility' +provides-component:'print-service' +provides-component:'search' +provides-component:'document-provider' +provides-component:'notification-listener' +provides-component:'dream' +provides-component:'camera' +provides-component:'camera-secure' +main +other-receivers +other-services +supports-screens: 'normal' 'large' 'xlarge' +supports-any-density: 'true' +requires-smallest-width:'240' +compatible-width-limit:'360' +largest-width-limit:'480' +locales: '--_--' +densities: '160' '240' '320' '480' '640' '65534' +native-code: 'x86_64' +alt-native-code: 'x86' diff --git a/tools/aapt2/integration-tests/DumpTest/components_expected_proto.txt b/tools/aapt2/integration-tests/DumpTest/components_expected_proto.txt new file mode 100644 index 0000000000000..775641054c066 --- /dev/null +++ b/tools/aapt2/integration-tests/DumpTest/components_expected_proto.txt @@ -0,0 +1,165 @@ +badging { + package { + package: "com.example.bundletool.minimal" + version_code: 1 + version_name: "1.0" + platform_version_name: "12" + platform_version_code: "31" + compile_sdk_version: 31 + compile_sdk_version_codename: "12" + } + application { + label: "minimal" + icon: "res/uF.xml" + density_icons { + key: 160 + value: "res/uF.xml" + } + density_icons { + key: 240 + value: "res/uF.xml" + } + density_icons { + key: 320 + value: "res/uF.xml" + } + density_icons { + key: 480 + value: "res/uF.xml" + } + density_icons { + key: 640 + value: "res/uF.xml" + } + density_icons { + key: 65534 + value: "res/uF.xml" + } + } + uses_sdk { + min_sdk_version: 21 + target_sdk_version: 31 + } + uses_configuration { + req_touch_screen: 3 + req_keyboard_type: 2 + req_hard_keyboard: -1 + req_navigation: 3 + req_five_way_nav: -1 + } + supports_screen { + screens: NORMAL + screens: LARGE + screens: XLARGE + supports_any_densities: true + requires_smallest_width_dp: 240 + compatible_width_limit_dp: 360 + largest_width_limit_dp: 480 + } + launchable_activity { + name: "com.example.bundletool.minimal.MainActivity" + label: "minimal" + } + compatible_screens { + screens { + size: 500 + density: 240 + } + screens { + size: 400 + density: 160 + } + } + architectures { + architectures: "x86_64" + alt_architectures: "x86" + } + supports_gl_texture { + name: "GL_OES_compressed_paletted_texture" + } + components { + main: true + other_receivers: true + other_services: true + provided_components: "app-widget" + provided_components: "device-admin" + provided_components: "ime" + provided_components: "wallpaper" + provided_components: "accessibility" + provided_components: "print-service" + provided_components: "search" + provided_components: "document-provider" + provided_components: "notification-listener" + provided_components: "dream" + provided_components: "camera" + provided_components: "camera-secure" + } + densities: 160 + densities: 240 + densities: 320 + densities: 480 + densities: 640 + densities: 65534 + feature_groups { + features { + name: "android.hardware.bluetooth" + required: true + } + features { + name: "android.hardware.camera" + required: true + } + features { + name: "android.hardware.faketouch" + implied_data { + reasons: "default feature for all apps" + } + } + features { + name: "android.hardware.telephony" + implied_data { + from_sdk_23_permission: true + reasons: "requested a telephony permission" + } + } + } + uses_permissions { + name: "android.permission.BIND_ACCESSIBILITY_SERVICE" + max_sdk_version: 24 + required: true + } + uses_permissions { + name: "android.permission.RECEIVE_SMS" + sdk23_and_above: true + } + uses_permissions { + name: "android.permission.WRITE_EXTERNAL_STORAGE" + required: true + } + uses_permissions { + name: "android.permission.READ_EXTERNAL_STORAGE" + required: true + implied: true + } + permissions { + name: "minimal.FIRST_PERMISSION" + } + uses_libraries { + name: "mylib1" + required: true + } + uses_libraries { + name: "my_optional_lib" + } + uses_native_libraries { + name: "native1" + required: true + } + uses_native_libraries { + name: "optional" + } + metadata { + name: "android.nfc.cardemulation.host_apdu_service" + resource_string: "res/dU.xml" + } +} diff --git a/tools/aapt2/integration-tests/DumpTest/components_full_proto.txt b/tools/aapt2/integration-tests/DumpTest/components_full_proto.txt new file mode 100644 index 0000000000000..bd7673616ddc8 --- /dev/null +++ b/tools/aapt2/integration-tests/DumpTest/components_full_proto.txt @@ -0,0 +1,2310 @@ +badging { + package { + package: "com.example.bundletool.minimal" + version_code: 1 + version_name: "1.0" + platform_version_name: "12" + platform_version_code: "31" + compile_sdk_version: 31 + compile_sdk_version_codename: "12" + } + application { + label: "minimal" + icon: "res/uF.xml" + density_icons { + key: 160 + value: "res/uF.xml" + } + density_icons { + key: 240 + value: "res/uF.xml" + } + density_icons { + key: 320 + value: "res/uF.xml" + } + density_icons { + key: 480 + value: "res/uF.xml" + } + density_icons { + key: 640 + value: "res/uF.xml" + } + density_icons { + key: 65534 + value: "res/uF.xml" + } + } + uses_sdk { + min_sdk_version: 21 + target_sdk_version: 31 + } + uses_configuration { + req_touch_screen: 3 + req_keyboard_type: 2 + req_hard_keyboard: -1 + req_navigation: 3 + req_five_way_nav: -1 + } + supports_screen { + screens: NORMAL + screens: LARGE + screens: XLARGE + supports_any_densities: true + requires_smallest_width_dp: 240 + compatible_width_limit_dp: 360 + largest_width_limit_dp: 480 + } + launchable_activity { + name: "com.example.bundletool.minimal.MainActivity" + label: "minimal" + } + compatible_screens { + screens { + size: 500 + density: 240 + } + screens { + size: 400 + density: 160 + } + } + architectures { + architectures: "x86_64" + alt_architectures: "x86" + } + supports_gl_texture { + name: "GL_OES_compressed_paletted_texture" + } + components { + main: true + other_receivers: true + other_services: true + provided_components: "app-widget" + provided_components: "device-admin" + provided_components: "ime" + provided_components: "wallpaper" + provided_components: "accessibility" + provided_components: "print-service" + provided_components: "search" + provided_components: "document-provider" + provided_components: "notification-listener" + provided_components: "dream" + provided_components: "camera" + provided_components: "camera-secure" + } + densities: 160 + densities: 240 + densities: 320 + densities: 480 + densities: 640 + densities: 65534 + feature_groups { + features { + name: "android.hardware.bluetooth" + required: true + } + features { + name: "android.hardware.camera" + required: true + } + features { + name: "android.hardware.faketouch" + implied_data { + reasons: "default feature for all apps" + } + } + features { + name: "android.hardware.telephony" + implied_data { + from_sdk_23_permission: true + reasons: "requested a telephony permission" + } + } + } + uses_permissions { + name: "android.permission.BIND_ACCESSIBILITY_SERVICE" + max_sdk_version: 24 + required: true + } + uses_permissions { + name: "android.permission.RECEIVE_SMS" + sdk23_and_above: true + } + uses_permissions { + name: "android.permission.WRITE_EXTERNAL_STORAGE" + required: true + } + uses_permissions { + name: "android.permission.READ_EXTERNAL_STORAGE" + required: true + implied: true + } + permissions { + name: "minimal.FIRST_PERMISSION" + } + uses_libraries { + name: "mylib1" + required: true + } + uses_libraries { + name: "my_optional_lib" + } + uses_native_libraries { + name: "native1" + required: true + } + uses_native_libraries { + name: "optional" + } + metadata { + name: "android.nfc.cardemulation.host_apdu_service" + resource_string: "res/dU.xml" + } +} +resource_table { + source_pool { + data: "\001\000\034\000$\000\000\000\001\000\000\000\000\000\000\000\000\001\000\000 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" + } + package { + package_id { + id: 127 + } + package_name: "com.example.bundletool.minimal" + type { + type_id { + id: 1 + } + name: "color" + entry { + entry_id { + } + name: "black" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + prim { + color_argb8_value: 4278190080 + } + } + } + } + } + entry { + entry_id { + id: 1 + } + name: "purple_200" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + prim { + color_argb8_value: 4290479868 + } + } + } + } + } + entry { + entry_id { + id: 2 + } + name: "purple_500" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + prim { + color_argb8_value: 4284612846 + } + } + } + } + } + entry { + entry_id { + id: 3 + } + name: "purple_700" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + prim { + color_argb8_value: 4281794739 + } + } + } + } + } + entry { + entry_id { + id: 4 + } + name: "teal_200" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + prim { + color_argb8_value: 4278442693 + } + } + } + } + } + entry { + entry_id { + id: 5 + } + name: "teal_700" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + prim { + color_argb8_value: 4278290310 + } + } + } + } + } + entry { + entry_id { + id: 6 + } + name: "white" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + prim { + color_argb8_value: 4294967295 + } + } + } + } + } + } + type { + type_id { + id: 2 + } + name: "dimen" + entry { + entry_id { + } + name: "fab_margin" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + prim { + dimension_value: 4097 + } + } + } + } + } + } + type { + type_id { + id: 3 + } + name: "drawable" + entry { + entry_id { + } + name: "$ic_launcher_foreground__0" + visibility { + source { + } + } + config_value { + config { + density: 65534 + sdk_version: 24 + } + value { + source { + } + item { + file { + path: "res/Za.xml" + type: BINARY_XML + } + } + } + } + } + entry { + entry_id { + id: 1 + } + name: "ic_launcher_background" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + file { + path: "res/3N.xml" + type: BINARY_XML + } + } + } + } + } + entry { + entry_id { + id: 2 + } + name: "ic_launcher_foreground" + visibility { + source { + } + } + config_value { + config { + density: 65534 + sdk_version: 24 + } + value { + source { + } + item { + file { + path: "res/qm.xml" + type: BINARY_XML + } + } + } + } + } + } + type { + type_id { + id: 4 + } + name: "mipmap" + entry { + entry_id { + } + name: "ic_launcher" + visibility { + source { + } + } + config_value { + config { + density: 160 + } + value { + source { + } + item { + file { + path: "res/u3.png" + type: PNG + } + } + } + } + config_value { + config { + density: 240 + } + value { + source { + } + item { + file { + path: "res/SD.png" + type: PNG + } + } + } + } + config_value { + config { + density: 320 + } + value { + source { + } + item { + file { + path: "res/jy.png" + type: PNG + } + } + } + } + config_value { + config { + density: 480 + } + value { + source { + } + item { + file { + path: "res/D2.png" + type: PNG + } + } + } + } + config_value { + config { + density: 640 + } + value { + source { + } + item { + file { + path: "res/CG.png" + type: PNG + } + } + } + } + config_value { + config { + density: 65534 + sdk_version: 26 + } + value { + source { + } + item { + file { + path: "res/uF.xml" + type: BINARY_XML + } + } + } + } + } + entry { + entry_id { + id: 1 + } + name: "ic_launcher_round" + visibility { + source { + } + } + config_value { + config { + density: 160 + } + value { + source { + } + item { + file { + path: "res/7c.png" + type: PNG + } + } + } + } + config_value { + config { + density: 240 + } + value { + source { + } + item { + file { + path: "res/tf.png" + type: PNG + } + } + } + } + config_value { + config { + density: 320 + } + value { + source { + } + item { + file { + path: "res/1S.png" + type: PNG + } + } + } + } + config_value { + config { + density: 480 + } + value { + source { + } + item { + file { + path: "res/5Q.png" + type: PNG + } + } + } + } + config_value { + config { + density: 640 + } + value { + source { + } + item { + file { + path: "res/C9.png" + type: PNG + } + } + } + } + config_value { + config { + density: 65534 + sdk_version: 26 + } + value { + source { + } + item { + file { + path: "res/oy.xml" + type: BINARY_XML + } + } + } + } + } + } + type { + type_id { + id: 5 + } + name: "string" + entry { + entry_id { + } + name: "action_settings" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + str { + value: "Settings" + } + } + } + } + } + entry { + entry_id { + id: 1 + } + name: "app_name" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + str { + value: "minimal" + } + } + } + } + } + entry { + entry_id { + id: 2 + } + name: "first_fragment_label" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + str { + value: "First Fragment" + } + } + } + } + } + entry { + entry_id { + id: 3 + } + name: "hello_first_fragment" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + str { + value: "Hello first fragment" + } + } + } + } + } + entry { + entry_id { + id: 4 + } + name: "hello_second_fragment" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + str { + value: "Hello second fragment. Arg: %1$s" + } + } + } + } + } + entry { + entry_id { + id: 5 + } + name: "next" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + str { + value: "Next" + } + } + } + } + } + entry { + entry_id { + id: 6 + } + name: "previous" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + str { + value: "Previous" + } + } + } + } + } + entry { + entry_id { + id: 7 + } + name: "second_fragment_label" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + str { + value: "Second Fragment" + } + } + } + } + } + } + type { + type_id { + id: 6 + } + name: "xml" + entry { + entry_id { + } + name: "apduservice" + visibility { + source { + } + } + config_value { + config { + } + value { + source { + } + item { + file { + path: "res/dU.xml" + type: BINARY_XML + } + } + } + } + } + } + } + tool_fingerprint { + tool: "Android Asset Packaging Tool (aapt)" + version: "2.19-SOONG BUILD NUMBER PLACEHOLDER" + } +} +xml_files { + path: "res/oy.xml" + root { + element { + namespace_declaration { + prefix: "android" + uri: "http://schemas.android.com/apk/res/android" + source { + line_number: 2 + } + } + name: "adaptive-icon" + child { + element { + name: "background" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "drawable" + source { + } + resource_id: 16843161 + compiled_item { + ref { + id: 2130903041 + } + } + } + } + source { + line_number: 3 + } + } + child { + element { + name: "foreground" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "drawable" + source { + } + resource_id: 16843161 + compiled_item { + ref { + id: 2130903042 + } + } + } + } + source { + line_number: 4 + } + } + } + source { + line_number: 2 + } + } +} +xml_files { + path: "AndroidManifest.xml" + root { + element { + namespace_declaration { + prefix: "android" + uri: "http://schemas.android.com/apk/res/android" + source { + line_number: 2 + } + } + name: "manifest" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "versionCode" + source { + } + resource_id: 16843291 + compiled_item { + prim { + int_decimal_value: 1 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "versionName" + value: "1.0" + resource_id: 16843292 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "compileSdkVersion" + source { + } + resource_id: 16844146 + compiled_item { + prim { + int_decimal_value: 31 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "compileSdkVersionCodename" + value: "12" + resource_id: 16844147 + } + attribute { + name: "package" + value: "com.example.bundletool.minimal" + } + attribute { + name: "platformBuildVersionCode" + source { + } + compiled_item { + prim { + int_decimal_value: 31 + } + } + } + attribute { + name: "platformBuildVersionName" + source { + } + compiled_item { + prim { + int_decimal_value: 12 + } + } + } + child { + element { + name: "uses-sdk" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "minSdkVersion" + source { + } + resource_id: 16843276 + compiled_item { + prim { + int_decimal_value: 21 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "targetSdkVersion" + source { + } + resource_id: 16843376 + compiled_item { + prim { + int_decimal_value: 31 + } + } + } + } + source { + line_number: 7 + } + } + child { + element { + name: "supports-screens" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "anyDensity" + source { + } + resource_id: 16843372 + compiled_item { + prim { + boolean_value: true + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "smallScreens" + source { + } + resource_id: 16843396 + compiled_item { + prim { + boolean_value: false + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "normalScreens" + source { + } + resource_id: 16843397 + compiled_item { + prim { + boolean_value: true + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "largeScreens" + source { + } + resource_id: 16843398 + compiled_item { + prim { + boolean_value: true + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "requiresSmallestWidthDp" + source { + } + resource_id: 16843620 + compiled_item { + prim { + int_decimal_value: 240 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "compatibleWidthLimitDp" + source { + } + resource_id: 16843621 + compiled_item { + prim { + int_decimal_value: 360 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "largestWidthLimitDp" + source { + } + resource_id: 16843622 + compiled_item { + prim { + int_decimal_value: 480 + } + } + } + } + source { + line_number: 11 + } + } + child { + element { + name: "uses-configuration" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "reqTouchScreen" + source { + } + resource_id: 16843303 + compiled_item { + prim { + int_decimal_value: 3 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "reqKeyboardType" + source { + } + resource_id: 16843304 + compiled_item { + prim { + int_decimal_value: 2 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "reqHardKeyboard" + source { + } + resource_id: 16843305 + compiled_item { + prim { + boolean_value: true + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "reqNavigation" + source { + } + resource_id: 16843306 + compiled_item { + prim { + int_decimal_value: 3 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "reqFiveWayNav" + source { + } + resource_id: 16843314 + compiled_item { + prim { + boolean_value: true + } + } + } + } + source { + line_number: 20 + } + } + child { + element { + name: "supports-gl-texture" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "GL_OES_compressed_paletted_texture" + resource_id: 16842755 + } + } + source { + line_number: 27 + } + } + child { + element { + name: "permission" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "minimal.FIRST_PERMISSION" + resource_id: 16842755 + } + } + source { + line_number: 29 + } + } + child { + element { + name: "uses-feature" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.hardware.camera" + resource_id: 16842755 + } + } + source { + line_number: 31 + } + } + child { + element { + name: "uses-feature" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.hardware.bluetooth" + resource_id: 16842755 + } + } + source { + line_number: 32 + } + } + child { + element { + name: "uses-permission" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.permission.BIND_ACCESSIBILITY_SERVICE" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "maxSdkVersion" + source { + } + resource_id: 16843377 + compiled_item { + prim { + int_decimal_value: 24 + } + } + } + } + source { + line_number: 34 + } + } + child { + element { + name: "uses-permission-sdk-23" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.permission.RECEIVE_SMS" + resource_id: 16842755 + } + } + source { + line_number: 38 + } + } + child { + element { + name: "uses-permission" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.permission.WRITE_EXTERNAL_STORAGE" + resource_id: 16842755 + } + } + source { + line_number: 40 + } + } + child { + element { + name: "compatible-screens" + child { + element { + name: "screen" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "screenSize" + source { + } + resource_id: 16843466 + compiled_item { + prim { + int_decimal_value: 500 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "screenDensity" + source { + } + resource_id: 16843467 + compiled_item { + prim { + int_decimal_value: 240 + } + } + } + } + source { + line_number: 43 + } + } + child { + element { + name: "screen" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "screenSize" + source { + } + resource_id: 16843466 + compiled_item { + prim { + int_decimal_value: 400 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "screenDensity" + source { + } + resource_id: 16843467 + compiled_item { + prim { + int_decimal_value: 160 + } + } + } + } + source { + line_number: 46 + } + } + } + source { + line_number: 42 + } + } + child { + element { + name: "application" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "label" + source { + } + resource_id: 16842753 + compiled_item { + ref { + id: 2131034113 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "icon" + source { + } + resource_id: 16842754 + compiled_item { + ref { + id: 2130968576 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "allowBackup" + source { + } + resource_id: 16843392 + compiled_item { + prim { + boolean_value: true + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "supportsRtl" + source { + } + resource_id: 16843695 + compiled_item { + prim { + boolean_value: true + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "multiArch" + source { + } + resource_id: 16843918 + compiled_item { + prim { + boolean_value: true + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "roundIcon" + source { + } + resource_id: 16844076 + compiled_item { + ref { + id: 2130968577 + } + } + } + child { + element { + name: "uses-library" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "mylib1" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "required" + source { + } + resource_id: 16843406 + compiled_item { + prim { + boolean_value: true + } + } + } + } + source { + line_number: 58 + } + } + child { + element { + name: "uses-library" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "my_optional_lib" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "required" + source { + } + resource_id: 16843406 + compiled_item { + prim { + boolean_value: false + } + } + } + } + source { + line_number: 61 + } + } + child { + element { + name: "uses-native-library" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "native1" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "required" + source { + } + resource_id: 16843406 + compiled_item { + prim { + boolean_value: true + } + } + } + } + source { + line_number: 65 + } + } + child { + element { + name: "uses-native-library" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "optional" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "required" + source { + } + resource_id: 16843406 + compiled_item { + prim { + boolean_value: false + } + } + } + } + source { + line_number: 68 + } + } + child { + element { + name: "activity" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "label" + source { + } + resource_id: 16842753 + compiled_item { + ref { + id: 2131034113 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "com.example.bundletool.minimal.MainActivity" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "exported" + source { + } + resource_id: 16842768 + compiled_item { + prim { + boolean_value: false + } + } + } + child { + element { + name: "intent-filter" + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.intent.action.MAIN" + resource_id: 16842755 + } + } + source { + line_number: 77 + } + } + child { + element { + name: "category" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.intent.category.LAUNCHER" + resource_id: 16842755 + } + } + source { + line_number: 79 + } + } + } + source { + line_number: 76 + } + } + } + source { + line_number: 72 + } + } + child { + element { + name: "activity" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "label" + source { + } + resource_id: 16842753 + compiled_item { + ref { + id: 2131034113 + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "com.example.bundletool.minimal.AnotherActivity" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "exported" + source { + } + resource_id: 16842768 + compiled_item { + prim { + boolean_value: false + } + } + } + child { + element { + name: "intent-filter" + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.intent.action.VIDEO_CAMERA" + resource_id: 16842755 + } + } + source { + line_number: 87 + } + } + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.intent.action.STILL_IMAGE_CAMERA_SECURE" + resource_id: 16842755 + } + } + source { + line_number: 88 + } + } + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.intent.action.SEARCH" + resource_id: 16842755 + } + } + source { + line_number: 89 + } + } + } + source { + line_number: 86 + } + } + } + source { + line_number: 82 + } + } + child { + element { + name: "receiver" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "com.example.bundletool.minimal.OneReceiver" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "exported" + source { + } + resource_id: 16842768 + compiled_item { + prim { + boolean_value: false + } + } + } + child { + element { + name: "intent-filter" + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.appwidget.action.APPWIDGET_UPDATE" + resource_id: 16842755 + } + } + source { + line_number: 97 + } + } + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.app.action.DEVICE_ADMIN_ENABLED" + resource_id: 16842755 + } + } + source { + line_number: 98 + } + } + } + source { + line_number: 96 + } + } + } + source { + line_number: 93 + } + } + child { + element { + name: "receiver" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "com.example.bundletool.minimal.TwoReceiver" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "permission" + value: "android.permission.BIND_DEVICE_ADMIN" + resource_id: 16842758 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "exported" + source { + } + resource_id: 16842768 + compiled_item { + prim { + boolean_value: false + } + } + } + child { + element { + name: "intent-filter" + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.app.action.DEVICE_ADMIN_ENABLED" + resource_id: 16842755 + } + } + source { + line_number: 106 + } + } + } + source { + line_number: 105 + } + } + } + source { + line_number: 101 + } + } + child { + element { + name: "receiver" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "com.example.bundletool.minimal.ThreeReceiver" + resource_id: 16842755 + } + } + source { + line_number: 109 + } + } + child { + element { + name: "service" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "com.example.bundletool.minimal.OneService" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "exported" + source { + } + resource_id: 16842768 + compiled_item { + prim { + boolean_value: false + } + } + } + child { + element { + name: "intent-filter" + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.view.InputMethod" + resource_id: 16842755 + } + } + source { + line_number: 115 + } + } + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.service.wallpaper.WallpaperService" + resource_id: 16842755 + } + } + source { + line_number: 116 + } + } + } + source { + line_number: 114 + } + } + } + source { + line_number: 111 + } + } + child { + element { + name: "service" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "com.example.bundletool.minimal.Services$TwoService" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "permission" + value: "android.permission.BIND_ACCESSIBILITY_SERVICE" + resource_id: 16842758 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "exported" + source { + } + resource_id: 16842768 + compiled_item { + prim { + boolean_value: false + } + } + } + child { + element { + name: "intent-filter" + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.accessibilityservice.AccessibilityService" + resource_id: 16842755 + } + } + source { + line_number: 124 + } + } + } + source { + line_number: 123 + } + } + } + source { + line_number: 119 + } + } + child { + element { + name: "service" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "com.example.bundletool.minimal.Services$ThreeService" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "permission" + value: "android.permission.BIND_PRINT_SERVICE" + resource_id: 16842758 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "exported" + source { + } + resource_id: 16842768 + compiled_item { + prim { + boolean_value: false + } + } + } + child { + element { + name: "intent-filter" + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.printservice.PrintService" + resource_id: 16842755 + } + } + source { + line_number: 132 + } + } + } + source { + line_number: 131 + } + } + } + source { + line_number: 127 + } + } + child { + element { + name: "service" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "com.example.bundletool.minimal.Services$FourService" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "permission" + value: "android.permission.BIND_NFC_SERVICE" + resource_id: 16842758 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "exported" + source { + } + resource_id: 16842768 + compiled_item { + prim { + boolean_value: false + } + } + } + child { + element { + name: "intent-filter" + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.nfc.cardemulation.action.HOST_APDU_SERVICE" + resource_id: 16842755 + } + } + source { + line_number: 140 + } + } + } + source { + line_number: 139 + } + } + child { + element { + name: "meta-data" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.nfc.cardemulation.host_apdu_service" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "resource" + source { + } + resource_id: 16842789 + compiled_item { + ref { + id: 2131099648 + } + } + } + } + source { + line_number: 143 + } + } + } + source { + line_number: 135 + } + } + child { + element { + name: "service" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "com.example.bundletool.minimal.Services$FiveService" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "permission" + value: "android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" + resource_id: 16842758 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "exported" + source { + } + resource_id: 16842768 + compiled_item { + prim { + boolean_value: false + } + } + } + child { + element { + name: "intent-filter" + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.service.notification.NotificationListenerService" + resource_id: 16842755 + } + } + source { + line_number: 152 + } + } + } + source { + line_number: 151 + } + } + } + source { + line_number: 147 + } + } + child { + element { + name: "service" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "com.example.bundletool.minimal.Services$SixService" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "permission" + value: "android.permission.BIND_DREAM_SERVICE" + resource_id: 16842758 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "exported" + source { + } + resource_id: 16842768 + compiled_item { + prim { + boolean_value: false + } + } + } + child { + element { + name: "intent-filter" + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.service.dreams.DreamService" + resource_id: 16842755 + } + } + source { + line_number: 160 + } + } + } + source { + line_number: 159 + } + } + } + source { + line_number: 155 + } + } + child { + element { + name: "service" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "com.example.bundletool.minimal.Services$SevenService" + resource_id: 16842755 + } + } + source { + line_number: 163 + } + } + child { + element { + name: "provider" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "com.example.bundletool.minimal.OneProvider" + resource_id: 16842755 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "permission" + value: "android.permission.MANAGE_DOCUMENTS" + resource_id: 16842758 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "exported" + source { + } + resource_id: 16842768 + compiled_item { + prim { + boolean_value: true + } + } + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "authorities" + value: "A" + resource_id: 16842776 + } + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "grantUriPermissions" + source { + } + resource_id: 16842779 + compiled_item { + prim { + boolean_value: true + } + } + } + child { + element { + name: "intent-filter" + child { + element { + name: "action" + attribute { + namespace_uri: "http://schemas.android.com/apk/res/android" + name: "name" + value: "android.content.action.DOCUMENTS_PROVIDER" + resource_id: 16842755 + } + } + source { + line_number: 172 + } + } + } + source { + line_number: 171 + } + } + } + source { + line_number: 165 + } + } + } + source { + line_number: 51 + } + } + } + source { + line_number: 2 + } + } +} diff --git a/tools/aapt2/integration-tests/DumpTest/components_permissions_expected.txt b/tools/aapt2/integration-tests/DumpTest/components_permissions_expected.txt new file mode 100644 index 0000000000000..f79de5cba11d7 --- /dev/null +++ b/tools/aapt2/integration-tests/DumpTest/components_permissions_expected.txt @@ -0,0 +1,5 @@ +package: com.example.bundletool.minimal +permission: minimal.FIRST_PERMISSION +uses-permission: name='android.permission.BIND_ACCESSIBILITY_SERVICE' maxSdkVersion='24' +uses-permission-sdk-23: name='android.permission.RECEIVE_SMS' +uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE' diff --git a/tools/aapt2/integration-tests/DumpTest/minimal.apk b/tools/aapt2/integration-tests/DumpTest/minimal.apk new file mode 100644 index 0000000000000..a8415faca3902 Binary files /dev/null and b/tools/aapt2/integration-tests/DumpTest/minimal.apk differ diff --git a/tools/aapt2/integration-tests/DumpTest/minimal_expected.txt b/tools/aapt2/integration-tests/DumpTest/minimal_expected.txt new file mode 100644 index 0000000000000..85ab5d80cd390 --- /dev/null +++ b/tools/aapt2/integration-tests/DumpTest/minimal_expected.txt @@ -0,0 +1,92 @@ +package: name='com.lato.bubblegirl' versionCode='33' versionName='1.0.0' platformBuildVersionName='8.1.0' platformBuildVersionCode='27' +sdkVersion:'19' +targetSdkVersion:'26' +application-label:'Bubble Girl' +application-label-ar:'Bubble Girl' +application-label-az:'Bubble Girl' +application-label-be:'Bubble Girl' +application-label-bg:'Bubble Girl' +application-label-bn:'Bubble Girl' +application-label-bs:'Bubble Girl' +application-label-ca:'Bubble Girl' +application-label-cs:'Bubble Girl' +application-label-da:'Bubble Girl' +application-label-de:'Bubble Girl' +application-label-el:'Bubble Girl' +application-label-es:'Bubble Girl' +application-label-es-ES:'Bubble Girl' +application-label-et:'Bubble Girl' +application-label-eu:'Bubble Girl' +application-label-fa:'Bubble Girl' +application-label-fi:'Bubble Girl' +application-label-fr:'Bubble Girl' +application-label-fr-CA:'Bubble Girl' +application-label-gl:'Bubble Girl' +application-label-hi:'Bubble Girl' +application-label-hr:'Bubble Girl' +application-label-hu:'Bubble Girl' +application-label-hy:'Bubble Girl' +application-label-in:'Bubble Girl' +application-label-is:'Bubble Girl' +application-label-it:'Bubble Girl' +application-label-iw:'Bubble Girl' +application-label-ja:'Bubble Girl' +application-label-jv:'Bubble Girl' +application-label-ka:'Bubble Girl' +application-label-kk:'Bubble Girl' +application-label-kn:'Bubble Girl' +application-label-ko:'Bubble Girl' +application-label-lt:'Bubble Girl' +application-label-lv:'Bubble Girl' +application-label-mk:'Bubble Girl' +application-label-ml:'Bubble Girl' +application-label-mr:'Bubble Girl' +application-label-ms:'Bubble Girl' +application-label-nb:'Bubble Girl' +application-label-nl:'Bubble Girl' +application-label-pa:'Bubble Girl' +application-label-pl:'Bubble Girl' +application-label-pt-BR:'Bubble Girl' +application-label-pt-PT:'Bubble Girl' +application-label-ro:'Bubble Girl' +application-label-ru:'Bubble Girl' +application-label-sk:'Bubble Girl' +application-label-sl:'Bubble Girl' +application-label-sq:'Bubble Girl' +application-label-sr:'Bubble Girl' +application-label-su:'Bubble Girl' +application-label-sv:'Bubble Girl' +application-label-ta:'Bubble Girl' +application-label-te:'Bubble Girl' +application-label-th:'Bubble Girl' +application-label-tl:'Bubble Girl' +application-label-tr:'Bubble Girl' +application-label-tt:'Bubble Girl' +application-label-uk:'Bubble Girl' +application-label-vi:'Bubble Girl' +application-label-zh-CN:'Bubble Girl' +application-label-zh-HK:'Bubble Girl' +application-label-zh-TW:'Bubble Girl' +application-icon-160:'res/theme/1f.png' +application-icon-240:'res/theme/1f.png' +application-icon-320:'res/theme/1f.png' +application-icon-480:'res/theme/1f.png' +application-icon-640:'res/theme/1f.png' +application: label='Bubble Girl' icon='res/theme/1f.png' +launchable-activity: name='com.sonymobile.runtimeskinning.livewallpaperlib.configactivity.LauncherActivity' label='' icon='' +uses-library:'com.sony.device' +uses-permission: name='com.sonymobile.permission.RUNTIME_SKIN' +feature-group: label='' + uses-gl-es: '0x30000' + uses-feature: name='android.software.live_wallpaper' + uses-feature: name='android.hardware.faketouch' + uses-implied-feature: name='android.hardware.faketouch' reason='default feature for all apps' + uses-feature: name='android.hardware.screen.portrait' + uses-implied-feature: name='android.hardware.screen.portrait' reason='one or more activities have specified a portrait orientation' +provides-component:'wallpaper' +main +other-activities +supports-screens: 'small' 'normal' 'large' 'xlarge' +supports-any-density: 'true' +locales: '--_--' 'ar' 'az' 'be' 'bg' 'bn' 'bs' 'ca' 'cs' 'da' 'de' 'el' 'es' 'es-ES' 'et' 'eu' 'fa' 'fi' 'fr' 'fr-CA' 'gl' 'hi' 'hr' 'hu' 'hy' 'in' 'is' 'it' 'iw' 'ja' 'jv' 'ka' 'kk' 'kn' 'ko' 'lt' 'lv' 'mk' 'ml' 'mr' 'ms' 'nb' 'nl' 'pa' 'pl' 'pt-BR' 'pt-PT' 'ro' 'ru' 'sk' 'sl' 'sq' 'sr' 'su' 'sv' 'ta' 'te' 'th' 'tl' 'tr' 'tt' 'uk' 'vi' 'zh-CN' 'zh-HK' 'zh-TW' +densities: '160' '240' '320' '480' '640'