summaryrefslogtreecommitdiff
path: root/tools/aapt2/format/binary/TableFlattener_test.cpp
AgeCommit message (Collapse)Author
2021-04-21Aapt2 ValueTransformerRyan Mitchell
For future macro support, aapt2 must be able to convert Reference values into other Value types. Currently a DescendingValueVisitor is used to visit all of the References in a ResourceTable or a compiled XML file to set their resource ids during the link phase. This was fine since we were only mutating the resource id of the visited Reference. A macro may reference a String, BinaryPrimitive, or any other Item type. During the link phase, we will need to transform references to macros into the values of the macros. The only parameter in the methods of the ValueVisitor interface is a raw pointer to the type being visited. The visitor interface does not support reassigning the visited type to a different type. ValueTransformer is a new interface for consuming a Value type and transforming it into a compatible Value type. This change refactors Value::Clone to use this interface. Bug: 175616308 Test: aapt2_tests Change-Id: Ic1b9d718b932c208764114cd9c74d880e189ccb0
2021-03-29Refactor aapt2 tests ResourceTable changesRyan Mitchell
This changes refactors tests to use the NewResourceBuilder class that makes it easier to construct resource entries. Bug: 183102797 Test: aapt2_tests Change-Id: I851f9fb99a003769f8df8c1876997eee0864822a
2020-11-17Revert^2 "libandroidfw hardening for IncFs"Ryan Mitchell
55ef6167a2c235bd88c7216238b2001b46795b79 Change-Id: I02d4890d181655dfd0a14c188468db512559d27b
2020-11-13Revert "libandroidfw hardening for IncFs"Ryan Mitchell
Revert "Move map_ptr to incfs namspace" Revert submission 12787270 Reason for revert: b/173250495 Reverted Changes: I5cd1bc8a2:libandroidfw hardening for IncFs Ice5dbcfb2:Move map_ptr to incfs namspace I29ccdc8ed:Do not cache bag parent stack until requested I1e9e9acaa:Cache resolved theme values Change-Id: Ib90ef68339710086df41e9abe0833a542d03a74f
2020-11-12libandroidfw hardening for IncFsRyan Mitchell
Migrate libandroifw to using incfs::util::map_ptr to prevent processes from crashing when parsing the resources.arsc, parsing compiled xml, files, and retrieving resource values. This change propagates incremental failures to the JNI level where they are raised as ResourcesNotFoundException. Performance of ResourcesPerfWorkloads without change (time in nanoseconds): [1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.883s) youtube_ns_median: 93812805 youtube_ns_standardDeviation: 4387062 youtube_ns_mean: 94455597 [2/3] com.android.resources.perf.PerfTest#maps: PASSED (11.265s) maps_ns_standardDeviation: 2997543 maps_ns_mean: 83480371 maps_ns_median: 82210941 [3/3] com.android.resources.perf.PerfTest#gmail: PASSED (24.963s) gmail_ns_median: 266141091 gmail_ns_standardDeviation: 3492043 gmail_ns_mean: 267472765 With change and verification forcibly enabled for all apks (including the framework-res.apk): [1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.646s) youtube_ns_median: 101999396 youtube_ns_standardDeviation: 4625782 youtube_ns_mean: 102631770 [2/3] com.android.resources.perf.PerfTest#maps: PASSED (11.286s) maps_ns_standardDeviation: 2692088 maps_ns_mean: 91326538 maps_ns_median: 90519884 [3/3] com.android.resources.perf.PerfTest#gmail: PASSED (24.694s) gmail_ns_median: 290284442 gmail_ns_standardDeviation: 5764632 gmail_ns_mean: 291660464 With change and verification disabled: [1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.748s) youtube_ns_median: 95490747 youtube_ns_standardDeviation: 7282249 youtube_ns_mean: 98442515 [2/3] com.android.resources.perf.PerfTest#maps: PASSED (10.862s) maps_ns_standardDeviation: 4484213 maps_ns_mean: 87912988 maps_ns_median: 86325549 [3/3] com.android.resources.perf.PerfTest#gmail: PASSED (24.034s) gmail_ns_median: 282175838 gmail_ns_standardDeviation: 6560876 gmail_ns_mean: 282869146 These tests were done on a Pixel 3 and with cpu settings configured by libs/hwui/tests/scripts/prep_generic.sh: Locked CPUs 4,5,6,7 to 1459200 / 2803200 KHz Disabled CPUs 0,1,2,3 Bug: 160635104 Bug: 169423204 Test: boot device && atest ResourcesPerfWorkloads Change-Id: I5cd1bc8a2257bffaba6ca4a1c96f4e6640106866
2020-07-28OMS: Add config_signature policy handlingZoran Jovanovic
Alongside SIGNATURE and ACTOR_SIGNATURE policies, add CONFIG_SIGNATURE policy to overlayable that overlay fulfills if it is signed with the same certificate as the reference package whose package name is declared in 'config-signature' tag of SystemConfig and is vetted by OMS that it's a system pre-installed package. BUG: 158726924 TEST: regular aapt2, idmap2, OMS tests Change-Id: I645ee72271496008742886274be0d63a2985201b
2020-02-26Actor signature overlayable policyWinson
There are cases where an app can ship overlays for itself, but the "signature" policy as described would open up a vulnerability by allowing the system actor to create and sign any arbitrary overlay that will apply to the target. To prevent this, redefine "signature" as target package only, and introduce "actor" for checking against the actor signature. Any app that wishes to use both can include both policies. Bug: 130563563 Test: m aapt2_tests idmapt2_tests and run from host test output Test: atest libandroidfw_tests Change-Id: I1c583a5b37f4abbeb18fc6a35c502377d8977a41
2020-02-26Refactor overlayable policyWinson
To make it easier to add the actor policy in a follow up CL, move most of the policy handling to a central location. The strings and transformation between strings and flags is now handled in libidmap2policies, with libandroidfw containing the single source of policy flags. This also extracts all the test resource IDs into an R.h so they can be swapped without having to edit a dozen files each time. Bug: 130563563 Test: m aapt2_tests idmapt2_tests and run from host test output Test: atest libandroidfw_tests Change-Id: Ie533c9cebf938215df7586f00c38763ae467e606
2020-01-16Reorder style items in shared librariesClark DuVall
AssetManager2.cpp expects style attribute IDs to be in sorted order when applying a style (see AssetManager2::GetBag). Shared libraries have a package ID of 0x00, which will mean any attribute defined in a shared library will be put before all other attributes. Once the attribute ID is looked up in the dynamic ref table, the package ID is no longer 0x00, which means this ID is no longer in sorted order. This messes up the logic in AssetManager2::GetBag, and results in some style attributes getting dropped from shared libraries. This change modifies how aapt2 sorts the style entries, sorting entries with dynamic IDs after entries with the android framework ID. This means the entries will still be in sorted order when the IDs are looked up. Bug: 147674078 Test: TableFlattenerTest.FlattenSharedLibraryWithStyle Change-Id: Ic4f4004b6d9cecde9325dcdb37f71138857f8236
2019-09-16Improve how we exempt resources from getting their names collapsed.Brian Chang
Removed the --whitelist-path flag, which is poorly named and we can already specify these resources with --resources-config-path. Renamed TableFlattenerOptions.whitelisted_resources to keep_resources. It holds ResourceName instead of std::string. This lets us include type when specifying what gets exempted, for correctness. Bug: 111115201 Test: make aapt2_tests Change-Id: Ifa5df924b5e2265c32cdcf8ca7dfa4a3992a0468
2019-04-17Add odm and oem policiesRyan Mitchell
This change adds parsing, encoding, and validating of odm and oem overlayable policies to aapt2, libandroidfw, and idmap2. Bug: 121033532 Test: aapt2_tests, idmap2_tests Change-Id: Ifc0d4b6c9f9c37e06b2988abade69dbb277c50c2
2019-02-14Signature policy for overlayable itemsWinson
Add encoding/decoding of new policy for overlays. Signature enforces that an overlay package is signed with the same key as the actor of the target resource, so that an overlay can be installed by the user as a normal app but restricted to those built by the author of the actor (which can be the same as the target). This also enforces that a valid policy is specified. This doesn't implement the actors nor the signature check. Bug: 119402606 Test: ResourceParserTest ParseOverlayablePolicy Test: ProtoSerializerTest SerializeAndDeserializeOverlayable Test: aapt2_tests Change-Id: I8495ad790c2ebd51759bc6eba81149680c209475
2019-01-16Remove RRO policy product_servicesRyan Mitchell
Since Q will no longer have a product_services partition, remove instances of the product_services policy across aapt2, androidfw, and idmap2. Bug:122745343 Test: aapt2_tests and libandroidfw_tests Change-Id: I97c223a0bf5a2eab95811e5f738b44af6335e0ea
2019-01-11Add encoding of name and actor overlayable fieldsRyan Mitchell
Encode the actor and name attributes of <overlayable> elements in the overlayable chunks. Two chunks cannot have the same name. Bug: 110869880 Bug: 119390855 Test: aapt2_tests and libandroidfw_tests Change-Id: I0ed95efef640b3927046b6155d1840f0d96030dd
2018-12-13Add actor and name parsing for overlayableRyan Mitchell
Add parsing of two overlayable attributes: name : The unnique identifying name of the overlayable set of resources actor: The component responsible for enabling and disabling overlays targeting the specified set of resources Bug: 110869880 Bug: 119390855 Test: m -j aapt2_tests Change-Id: Id42463e2b92b69034fb39cd29bc8606affb61ba7
2018-12-11Refactor policy parsingRyan Mitchell
This change removes the ability for an overlayable resource to be defined in multiple policy blocks within the same overlayable. This change also changes aapt2 to use a bit mask to keep track of the parsed policies. Bug: 110869880 Bug: 120298168 Test: aapt2_tests Change-Id: Ie26cd913f94a16c0b312f222bccfa48f62feceaa
2018-12-04Encoding of <overlayable> and <policy>Ryan Mitchell
This change defines two new chunks for encoding overlayable information. RES_TABLE_OVERLAYABLE_POLICY_TYPE contains flags that represent restrictions enforced on overlays that try to overlay a specific set of resource ids. The chunk header is followed by ResTable_ref for each id that belongs to the policy type. A policy chunk will be created for every unique combination of policies that are defined in overlayable declarations. RES_TABLE_OVERLAYABLE_TYPE holds policy blocks. Since <overlayable> does not currently have any attributes, only one overlayable block is encoded in an APK. This change also removes the SPEC_OVERLAYABLE flag because the runtime does not use the flag, and the overlayable chunk encoding renders it obsolete. Bug: 110869880 Bug: 117545186 Test: libandroidfw_tests and aapt2_tests Change-Id: I45ae9bf4176699f14c85e2b7a2e8560185d8a0b8
2018-11-06RRO: Added partition policies for overlaysRyan Mitchell
<overlayable> tags can now have policy elements that indicate which partition the overlay apk must reside on in order to be allowed to overlay a resource. This change only adds parsing of <policy> and encoding of policy in the proto ResourceTable. A later change will add the encoding of policy and overlayable in the binary APK. <overlayable> <policy type="system|vendor|product|product_services|public" > <item type="string" name="oof" /> </policy> </overlayable> Bug: 110869880 Test: make aapt2_tests Change-Id: I8d4ed7b0e01f981149c6e3190af1681073b79b03
2018-08-17AAPT2: Set array element keysRyan Mitchell
Many google3 apps using lemon resource filtering had difficulty converting to aapt2. AAPT2 never set the name of the ResTable_map name value mapping. Bug: 78472540 Test: blaze build java/com/google/android/apps/gmail:Gmail_go_release and checking that all array resources are present Change-Id: I3d253a4c52c6100085e4c1083f4c36a943f11c76
2018-01-11AAPT2: Allow compatible duplicate AttributesAdam Lesinski
If a resource XML file defines two compatible Attributes, they should be merged without throwing an error. Ex: <declare-styleable> <attr name="conflict" format="string" /> </declare-styleable> <declare-styleable> <attr name="conflict" format="string|reference" /> </declare-styleable> In this case, string|reference and string are the same, so these should merge correctly. Bug: 65699599 Test: make aapt2_tests Test: make AaptBasicTest Change-Id: I7b0f956d2332f7f0b458acd59ca0a606b2cfdf95
2017-12-18AAPT2: Propagate SPEC_OVERLAYABLE flag to final APKAdam Lesinski
Resources can be marked as overlayable, which means they can be overlaid by runtime resource overlays. This change propagates this state to the final resource table that is installed on device. Future work: - Have the idmap tool respect the overlayable state and ignore entries that overlay anything else. Bug: 64980941 Test: make aapt2_tests Change-Id: Id45b1e141a281be2ee32a4ac3096fcf1114d523b
2017-12-04Enable obfuscation of resource names, with whitelisting support.Luke Nicholson
Test: Built aapt2, ran optimize on gmail apk with sample whitelist config file, and flags enabled. Added two unit tests to TableFlattener covering obfuscation logic. Change-Id: Iad6329d75ff440121bf1a2cdf09c5f4bf4199d9d
2017-11-01AAPT2: Add convert commandAdam Lesinski
This command allows a developer to convert their proto APK (generated from the link phase using --proto-format) into a binary APK suitable for use on device. aapt2 convert -o output.apk input.apk Test: manual + make aapt2_tests Change-Id: I10a7c33bb4b57006d01fe00a8bf92f78e04e7e50
2017-10-04AAPT2: Move format related files under same directoryAdam Lesinski
Test: make aapt2_tests Change-Id: Id72cdfc12ba3add294048e60c55f2461344464bf