Commit Graph

76 Commits

Author SHA1 Message Date
Donald Chai
44fa342eb9 [aapt2] Fix infinite loop in proguard::CollectLocations
std::set only works correctly when the < comparator is a strict weak
ordering, while UsageLocation::operator< was actually implementing !=.

Bug: 134190468
Change-Id: Icb9407e9c8451f9fcb4eb9b2cea310e3bcaf159e
Tested: aapt2_tests, and b/134190468#comment1
2019-06-03 11:28:45 -07:00
Martijn Coenen
6c83e0c5c9 Make sure Proguard keeps zygote preload class.
Bug: 127262679
Test: atest ProguardRulesTest
Change-Id: Ib082404e08d98b25fcecbf680afb4af37fe2786b
2019-03-06 15:06:17 +01:00
Chih-Hung Hsieh
3b3be3f10f Merge "Fix/suppress aapt/aapt2 google-explicit-constructor warnings" am: cdf6be573f am: d42fe48c93
am: 0bf62f1309

Change-Id: Iffb7e4a145b172a35dd58b9450d4a5184d8b07f7
2019-01-04 12:20:01 -08:00
Chih-Hung Hsieh
1fc78e1814 Fix/suppress aapt/aapt2 google-explicit-constructor warnings
* Add explicit to conversion constructors/operators
* Use NOLINT or NOLINTNEXTLINE to suppress warnings on intended converters

Bug: 28341362
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,google-explicit-constructor
Change-Id: Ie02101ea7c422e8add535c111a30a2f21ead0ace
2019-01-04 17:38:13 +00:00
Chih-Hung Hsieh
2491af24a8 Merge "Fix performance-for-range-copy warnings" am: bc29242288 am: 7adb73f332
am: 2296036a40

Change-Id: Ia99ea6c9633986e68340bc88983d06baa7a1c597
2018-12-17 14:31:14 -08:00
Chih-Hung Hsieh
a1b644e88c Fix performance-for-range-copy warnings
Bug: 30413223
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,performance*
Change-Id: Ie481e88025a7a1f3abde8ff63420d5ccd8577e52
2018-12-17 20:00:55 +00:00
Ryan Mitchell
be8607dcd5 Add @hide support for styleable attributes
AAPT2 generates documentation for styleables. The documentation contains
references to the attributes of the styleable. If the attributes are
marked @hide, remove the references to the attributes in the generated
coments.

Bug: 120262117
Test: m -j offline-sdk-docs
Change-Id: I541002077b17771d89caead04df2f4ae66c623f0
2018-12-03 12:01:24 -08:00
Mårten Kongstad
5c541f6e36 libandroidfw: move ConfigDescription from aapt2 to libandroidfw
This is to allow idmap2 to access ConfigDescription.

Test: libandroidfw_tests
Test: aapt2_tests
Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5
Merged-In: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-10-08 09:56:09 -07:00
Mårten Kongstad
24c9aa6541 libandroidfw: move ConfigDescription from aapt2 to libandroidfw
This is to allow idmap2 to access ConfigDescription.

Test: libandroidfw_tests
Test: aapt2_tests
Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-10-08 06:50:22 -07:00
Ryan Mitchell
8b7e1a8803 Merge "Restore Proguard behavior and add minimal flag" 2018-10-03 20:54:14 +00:00
Pirama Arumuga Nainar
c691c0528e Merge "Do not use StringPiece in ExtractJavaIdentifier" am: 20ecc6397b am: 206ccf1f61
am: 7472303ff4

Change-Id: Idd910ad9fb743093f8e43ddcdf5770722b4393e6
2018-10-01 18:00:49 -07:00
Ryan Mitchell
7e5236dc56 Restore Proguard behavior and add minimal flag
We previously changed AAPT2 to correctly only generate keep rules for
the constructors required to inflate the different views. This cause
projects that did not have keep rules for the other constructors that
were accessed through reflection to have runtime crashes. This change
adds a flag to the link stage (--proguard-minimal-keep-rules) that
allows AAPT2 to only keep the constructors required for layout
inflation. If the flag is not present, then AAPT2 will generate less
specific keep rules than keep all constructors.

Bug: 116201243
Test: aapt2_tests
Change-Id: I8bb5cdf8446518ab153ea988e1243ca9494258c7
2018-09-25 15:20:59 -07:00
Pirama Arumuga Nainar
9ba5cb4796 Do not use StringPiece in ExtractJavaIdentifier
Bug: http://b/91353691

After assigning the result of TransformToFieldName to 'result', the
underlying storage is destroyed after the 'if' statement of the function
call.  'result' ends up with garbage if the identifier has a '-'.

ManifestClassGeneratorTest.NormalizePermissionNames is broken for this
reason in 32-bit Windows when using libc++ and 32-bit Linux.  ASAN also
reports this failure for both 32-bit and 64-bit linux.

Test: Run test on the cases mentioned above and ensure all of them pass.
Change-Id: I69163c423c1171b7ac7838f2abe06bdf8058df4c
2018-09-25 13:21:35 -07:00
TreeHugger Robot
24a464a9be Merge "Only keep necessary constructor for custom view nodes" 2018-07-20 17:14:35 +00:00
TreeHugger Robot
41dcc4eac5 Merge "Only keep methods with correct signature for more types" 2018-07-20 16:36:24 +00:00
Ryan Mitchell
848585e1a4 Merge "AAPT2: Fix R.java for styleable in different package" 2018-07-20 15:18:05 +00:00
Jake Wharton
cc65b8dba6 Only keep necessary constructor for custom view nodes
This expands the Context+AttributeSet constructor specificity from only work on <view class=> nodes to <my.Type> nodes.

Bug: 37123156
Test: make aapt2_tests
Change-Id: I8fb950731383f86bee225333bda27baf5a7a34c5
2018-07-20 10:44:11 -04:00
Jake Wharton
98100c3828 Only keep methods with correct signature for more types
- For transition and pathMotion attributes the method must have Context and AttributeSet parameters.
- For actionViewClass and actionProviderClass attributes the constructor must have a single Context parameter.
- For Fragment's class or name attributes the constructor must have zero parameters.

Bug: 37123156
Test: make aapt2_tests
Change-Id: I34017abd182867ba95172835051d114cb2f3b3ac
2018-07-20 10:44:11 -04:00
Jake Wharton
e4bd160284 Add rule emissions for appComponentFactory
This attribute was added in API 28 and is reflectively instantiated from a zero-argument constructor.

Test: make aapt2_tests
Change-Id: Ie9de0764165c6fe6c6fcda6cc38b0cc633f03bbd
2018-07-18 12:09:17 -04:00
Jake Wharton
cfbc767b61 Add Application name to manifest test case
Test: make aapt2_tests
Change-Id: I4df26375bdf480b7d09e9cf816b7a9feaa141115
2018-07-18 12:09:17 -04:00
Ryan Mitchell
23cc5d5dbe AAPT2: Fix R.java for styleable in different package
When generating the R.java file, attributes of styleables do not always
have package names on them. This caused a problem where when an apk
that was previously linked and that also contained a declare-styleable
is linked again to an AndroidManifest.xml with a different package name,
styleable attributes' resource symbols could not be looked up correctly.

This change does not rename the resources but makes sure that the java
generator finds the attribute symbols correctly.

Bug: 110877419
Test: Created a test in aapt2_tests and verified correct behavior of
repro example from bug

Change-Id: Ib99d84cbe44dadca86603bc610ad3f4e09e3fb11
2018-07-13 11:19:56 -07:00
Jake Wharton
3001f0311d Only keep methods with correct signature for view/menu click
For View's onClick attribute the method must have a single argument of type android.view.View. For a MenuItem's onClick attribute the method must have a single argument of type android.view.MenuItem. Since these rules match all types and any return type, matching by signature is the only available specificity that can be added.

Bug: 37123156
Test: make aapt2_tests
Change-Id: I4b82f5ef9e62a8ecffaab424e269df627825709e
2018-06-11 17:21:28 -04:00
Jake Wharton
420785e6d0 Improve tests for ProGuard rules, add transition tests
Test: make aapt2_tests
Change-Id: If3300a9f82ad90189b74aab03c0d7f649e74e3f3
2018-06-11 15:57:59 -04:00
Jake Wharton
ab660a7fde Only keep default constructor of manifest items
Reflection-based instantiation of manifest-declared types is only done on the default (aka no-argument) constructor. While these types are unlikely to have alternate constructors (unlike the others listed in the bug), there's no reason to generate overly keep-y rules for them.

Bug: 37123156
Test: make aapt2_tests
Change-Id: Ic83a2671a54ea5dd558bfcacf033a60e9568ab8c
2018-06-11 11:33:17 -04:00
Ryan Mitchell
9a2f6e60c6 AAPT2: Add Proguard rules for nav fragments
Adds generation of proguard rules for fragments in res/navigation. All
android:name attributes have keep rules generated for the classes they
reference.

Bug: 69929974
Test: aapt2_tests
Change-Id: I05a87484ab357ea5629b73caad8488182f474e1f
2018-05-24 09:58:27 -07:00
TreeHugger Robot
0315c8495d Merge "Don't dereference a null pointer" 2018-03-05 18:58:43 +00:00
Todd Kennedy
949b625377 Don't dereference a null pointer
If we don't specifiy an output for R.java, don't try to write
data to the class definition

Change-Id: I3ad471ec93dcb8baf13f221174065679cce311ad
Fixes: 72547268
Test: out/host/linux-x86/nativetest64/aapt2_tests/aapt2_tests
2018-03-02 14:19:45 -08:00
Izabela Orlowska
d31bc123a0 AAPT2: normalize Manifest java identifiers.
Currently AAPT2 does not allow permissions which last piece contains the
"-" symbol (since it is an illegal character for a java identifier).

AAPT1 would normalize the last piece, therefore creating a valid java
identifier.

This CL makes AAPT2 behave in a similar way to AAPT1, but instead of
modifying the original value of the permission string, modifies only the
java identifier part, leaving the permission string unchanged.

Fixes: 72980877
Test: updated
Change-Id: Ie44317e07407341ba3e91a84d9b06980547b3448
2018-02-13 14:09:00 +00:00
TreeHugger Robot
bd56951c5b Merge "aapt2: Fix issue with Manifest duplicate handling" 2018-01-17 20:20:29 +00:00
Adam Lesinski
a4fb17bbbb aapt2: Fix issue with Manifest duplicate handling
Fixed a memory-corruption issue that led to multiple duplicate
permission entries being generated for Manifest.java.

Bug: 71641288
Test: make aapt2_tests
Change-Id: I8cd37929c4883aaba2beebbf874c7ee3234d51d8
2018-01-16 17:06:33 -08:00
Adam Lesinski
73bff1e851 AAPT2: Allow compatible duplicate Attributes
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
2018-01-11 13:54:11 -08:00
Adam Lesinski
71be70507d AAPT2: Propagate SPEC_OVERLAYABLE flag to final APK
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-18 14:16:02 -08:00
Izabela Orlowska
23a6e1e390 AAPT2: allow to generate R.txt without R.java
Bug: 69956357
Test: manual
Change-Id: If2bc32bd4efb1ea17c6cba7a17f2b2300164ede0
2017-12-05 20:59:08 +00:00
Adam Koski
f85eec8403 Fix conditional keep rules for new semantics
New conditional syntax is a logical AND, not OR. This means if a
resource should be conditionally kept by multiple ids, we need to
generate a separate rule for each condition (which will be interpreted
as OR).

Test: unit tests
Bug: 69341430
Change-Id: I0786c65561d36fbf43d181a2dfd0c7eaf1d96b8c
2017-11-20 14:54:28 -08:00
Adam Lesinski
a693c4a32e AAPT2: Move all file output to FileOutputStream
FileOutputStream is safe to use on Windows, as it opens
files using our compatibility API.

Bug: 68262818
Test: make aapt2_tests
Change-Id: Ib0b27e93edd609b49b1327db7d9867a002198ebb
2017-11-16 12:06:17 -08:00
Adam Koski
09ef94e918 Change conditional keep rule syntax
Google's ProGuard fork is migrating to a new syntax that upstream
ProGuard 6.0 will also support.

Test: unit tests
Bug: 69162105
Change-Id: I3b6d7e82eb99c2e2af6c4d851a4f97ec3e471b55
2017-11-10 11:30:56 -08:00
Adam Lesinski
93190b79d1 AAPT2: Better debugging output
Test: make aapt2_tests
Change-Id: I7778b773201381538dc1f2e376abee4eb33e44c0
2017-11-07 11:21:10 -08:00
Adam Koski
dc21dea9b8 AAPT2: Produce Conditional Proguard Keep Rules
Add the option to produce keep rules that conditional keep based on
usage of R identifiers. This allows Proguard to potentially shrink more
code if resources are not used.

Currently only produces conditional rules for classes referenced in
layout resources because they are the most common and has the easiest
transitive usage chain to analyze.

Bug: 63628451
Test: make aapt2_tests and manual testing
Change-Id: I6c1af7affd64af40c80e004d8506a9463444b2c3
2017-10-20 16:25:18 -07:00
Adam Lesinski
761d4341fc AAPT2: Fix R.java styleable + indices ordering
Make sure that Styleables are directly followed by their indices.
If not, Robolectric breaks. This is not strictly incorrect to have
an arbitrary ordering in R.java, but its easier to just support
Robolectric in this case.

Bug: 65837293
Test: make aapt2_tests

(cherry picked from commit af85c4deb667843a227d62275fe6992005f4c38d)

Change-Id: Ia59ba58427ade386d075ca9fc9eb5b53e35beca0
2017-09-29 11:20:45 -07:00
Adam Lesinski
123a19bc3a Merge "AAPT2: Fixup namespace implementation" 2017-08-29 17:32:24 +00:00
Adam Lesinski
1ef0fa9d72 AAPT2: Fixup namespace implementation
A few pieces were missing in the namespace mangling implementation.
Namespace aware libraries now work, along with R class generation.

Bug: 64706588
Test: make AaptTestNamespace_App
Change-Id: I12f78d6aa909e782c0faf7ceaa36058f2e6c864a
2017-08-23 11:30:54 -07:00
Adam Lesinski
f852dd0eb8 AAPT2: Fix regression in Manifest.java permissions
Permissions defined with the same leaf name emit the same
string symbol, which causes collisions. AAPT would override
the symbol with the last one seen.

Do the same thing as AAPT, but emit a warning.

Bug: 64472942
Test: make aapt2_tests
Change-Id: I17b9dc7e8d8bd80db98869394c93695cb453bebd
2017-08-19 08:40:33 -07:00
Adam Lesinski
6b37299129 AAPT2: Change XmlDom to exclude Namespace as a node
In preparation for exporting an XML proto format for UAM to consume,
this change brings the XML DOM API more in line with other APIs that
do not make the Namespace a separate node.

Treating Namespace declarations as just properties of an Element
node makes the implementation of algorithms much simpler, as
the constraints that Namespace nodes have only one child
are now built in and traversing to find Element nodes
is much simpler.

Also made a bunch of quality of life improvements, like formatting and
comment style.

Test: make aapt2_tests
Change-Id: Ib97ff1c4252b7907e2cc1f13a448dc4ca3b809a4
2017-08-17 17:43:08 +00:00
Adam Lesinski
09f4d706d9 AAPT2: Forward @TestApi in resource comments to JavaDoc
Bug: 37894597
Test: make aapt2_tests
Change-Id: I357fb84941bfbb3892a8c46feb47f55b865b6649
2017-08-08 10:51:23 -07:00
Adam Lesinski
e967d3f6ac AAPT2: Fix JavaDoc first sentence extraction.
The old algorithm for detecting the first sentence of a JavaDoc comment
looked for the first occurence of '.'. This does not work when code or a
{@link android.R.styleable} link is encountered in the first sentence.

Switch to checking for whitespace characters after the '.' character.

Bug: 62900335
Test: make aapt2_tests
Change-Id: I8238f6a6304c9c2f92e2e576ca8962a59c2b20ea
2017-07-25 15:53:15 -07:00
Adam Lesinski
f762df2575 AAPT2: Emit more proguard keep rules for layouts and menus
<fragment> tags in layouts use the class attribute to determine which
Fragment subclass to load, and fallback on android:name if class is not
set.

AAPT2 only emitted a proguard rule for the class attribute for <fragment>,
when it should emit a proguard rule for the android:name attribute as
well.

AAPT2 didn't handle menu XML, so support for actionViewClass,
actionProviderClass and onClick is added.

Bug: 62216174
Test: make aapt2_tests
Change-Id: Ie8675c2bd899a5b51f3661eb0901ab8c9a16fd70
2017-06-28 11:01:59 -07:00
Adam Lesinski
0d81f70104 AAPT2: Honor --custom-package when writing Manifest.java
Bug: 62826426
Test: manual
Change-Id: I517ff5da2ef2a9147ddbfb13b074a1f60550f189
2017-06-27 18:46:58 -07:00
Adam Lesinski
1e4b0e54a3 AAPT2: Workaround for findViewById with package ID > 0x7f
The entire View code base checks IDs against View.NO_ID except
findViewById(), which checks to see if the ID is negative.

Any package ID > 0x7f is interpreted as a negative number in Java
(no unsigned ints), so this check prevents the use of IDs > 0x7f.

findViewById is final, so support library workarounds are not possible.

Instead, IDs (@id/foo) are just sentinels, their values don't matter.
If building for pre-O devices, rewrite any references to these IDs of
the for 0xPPTTEEEE, where PP > 7f, to 0x7fPPEEEE.

The symbol table will check for potential collisions against the base
APK, so this should be safe.

Bug: 37498913
Test: manual
Change-Id: Ife3bbd29db287757ef8a2ffd83053d97f1db2613
2017-04-28 12:47:48 -07:00
Adam Lesinski
418763ff54 AAPT2: Generate R.txt
In order to support a staged rollout of support for AAPT2,
libraries being built the old way (merged into a single resource
directory) still need to make use of the generated R.txt AAPT
emitted. Do the same as AAPT.

Test: manual
Change-Id: Iaac1e824ddbd67e4efbab7692cddc1e4aa052f5a
2017-04-11 17:40:02 -07:00
Adam Lesinski
b5dc4bd49a AAPT2: Few tweaks to get shared-libraries working
Test: manual (building shared support library demo)
Change-Id: I4730645aa92ba1893baf67ffe35fbd4aac0f8e46
2017-02-22 19:54:43 -08:00