290 Commits

Author SHA1 Message Date
TreeHugger Robot
7cf8ca95aa Merge "AAPT2: Fix typo in manifest validation expectation" into oc-dev 2017-04-30 14:31:17 +00:00
TreeHugger Robot
557a0c50a0 Merge "AAPT2: binary parser should be more lenient with files" into oc-dev 2017-04-29 21:39:29 +00:00
TreeHugger Robot
f6bc1402ed Merge "AAPT2: Fix string escaping" into oc-dev 2017-04-29 21:04:38 +00:00
TreeHugger Robot
53c9898e79 Merge changes I446fb6ab,Ife3bbd29 into oc-dev
* changes:
  Valid resource IDs may be negative
  AAPT2: Workaround for findViewById with package ID > 0x7f
2017-04-29 20:38:20 +00:00
Adam Lesinski
742888f0fd AAPT2: binary parser should be more lenient with files
Some APKs have file references that reference files that don't exist.

For now, just be lenient and ignore the files themselves.

Keep the actual reference until such a time as general resource
stripping is implemented.

Bug: 37749644
Test: manual
Change-Id: I773685acf41212405b71b064d64045fb4556dcfc
2017-04-28 15:34:52 -07:00
Adam Lesinski
c10c0d0db2 AAPT2: Fix typo in manifest validation expectation
Change expected tag from grant-uri-permissions -> grant-uri-permission

Bug: 37714102
Test: manual
Change-Id: Ic0178b83fff8de961cb3fdfe38023eaf111237ee
2017-04-28 12:54:08 -07:00
Adam Lesinski
48448e8a31 AAPT2: Fix string escaping
We were processing escaped strings too early, before
parsing of values into types. Now the escaped strings get
processed when they are being flattened.

Bug: 37715376
Test: make aapt2_tests
Change-Id: Ic59aa2e3a20c40756c219752ff74b2a4f8a602ba
2017-04-28 12:51:23 -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
Chris Warrington
820d72adc0 AAPT2: Error reporting through JNI.
Rather than relying on stderr being wired correctly.

Test: Tests for JNI integration in studio-master-dev.
Change-Id: I1c7e7130bc4e56d61de259a9596bee3a6b3520fb
2017-04-28 10:06:38 +01:00
TreeHugger Robot
e7172ff9fb Merge "AAPT2: Add workaround for non-standard package IDs" into oc-dev 2017-04-27 23:45:44 +00:00
Adam Lesinski
4ca56978a9 AAPT2: Add workaround for non-standard package IDs
The dynamic ref table used to map build-time IDs to runtime IDs
is mainly used for shared resource libraries and has a few built-in
mappings (app 0x7f and framework 0x01).

Using a non-standard package ID like 0x80 causes a failure in package ID
lookup. The solution is to ship the dynamic_ref_table with an identity mapping
with any resource table that uses a non-standard package ID.

Adds some tests to ensure this works correctly.

Bug: 37498913
Test: make libandroidfw_tests
Test: make aapt2_tests
Change-Id: Ic3f67942384d34e7fdcbc94ded360e940e3ebc8a
2017-04-26 21:55:31 -07:00
TreeHugger Robot
b9dbee430d Merge "AAPT2: Add better error message when processing invalid files" into oc-dev 2017-04-25 15:26:24 +00:00
TreeHugger Robot
7beb895d75 Merge "AAPT2: Allow <path-permission> tag in <provider>" into oc-dev 2017-04-25 15:26:01 +00:00
Adam Lesinski
776aa959c7 AAPT2: Add better error message when processing invalid files
Instead of showing a failed mmap error, show a better error when a file
being compiled is a directory or other unsupported file type.

Bug: 37626838
Test: manual
Change-Id: Ib9acf5f48ab5da37e79411c6a9f37c51f00f925f
2017-04-24 22:19:53 +00:00
Adam Lesinski
25783cab0b AAPT2: Allow <path-permission> tag in <provider>
Fix a typo where the wrong tag name was expected under <provider>
in AndroidManifest.xml.

Bug: 37627250
Test: manual
Change-Id: I45afd09b4ff25feb320f7991e16c4172e20dd417
2017-04-24 22:18:48 +00:00
Adam Lesinski
b522f04bc2 AAPT2: Allow truncating of package names
ResTable_package header only allows 127 UTF-16 characters, so AAPT
would truncate the real package name to fit. AAPT2 would error-out
on any package name longer than 127 UTF-16 characters. This strictness
is not required except when building shared libraries, which use the
full package name as a way of identifying the runtime assigned
package ID to package name mapping.

Bug: 36940145
Test: make aapt2_tests
Change-Id: I7d2b7e50c7ab30c6a6c4f15d310e711f68e35091
2017-04-21 17:02:09 -07:00
Adam Lesinski
9431c476f3 AAPT2: Make BinaryResourceParser more lenient
Trailing data after the main RES_TABLE_TYPE should be logged but not
cause an error.

Bug: 36945869
Test: (aapt2 dump apk/attached/in/bug.apk)
Change-Id: I784406a680b79630798fdb4b7ca81f9d1f2b96d1
2017-04-21 16:09:24 -07:00
TreeHugger Robot
b97d51a0d2 Merge "AAPT2: Allow the ';' separator on Windows for split args" into oc-dev 2017-04-14 00:58:08 +00:00
Adam Lesinski
db091577ff AAPT2: Allow the ';' separator on Windows for split args
Bug: 36870463
Test: manual (wine)
Change-Id: I8a38545a3cac9354b41858e1840b197b60925c03
2017-04-13 16:07:35 -07:00
Adam Lesinski
62b713ed73 Merge "AAPT2: Fix order-of-destruction crash" into oc-dev 2017-04-13 22:54:02 +00:00
Adam Lesinski
ea134e08d7 AAPT2: Fix order-of-destruction crash
Make sure that users of StringPool are destroyed before
the StringPool itself.

Test: valgrind aapt2 optimize -o opt.apk out/target/common/obj/APPS/framework-res_intermediates/package-export.apk
Change-Id: I140c2d32f8449028976795d5d6865d83e1409b53
2017-04-13 12:57:06 -07:00
TreeHugger Robot
d1a6e6740f Merge "AAPT2: Generate R.txt" into oc-dev 2017-04-13 06:54:21 +00: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
Chris Warrington
014d315653 AAPT2: expose return values through JNI.
Test: Tests for JNI in the studio-master-dev branch.
Change-Id: I709595aabf31c9c2fea659c7af20a5c50d1e3d34
2017-04-11 09:21:29 +00:00
Adam Lesinski
d0f492db03 AAPT2: Share split functionality between link and optimize
Generating splits should be possible to do from the optimize command.
This means that a lot of infrastructure around split APKs can be
shared by both the optimize and link phase.

Bug: 35925830
Change-Id: Ia88b9e4bff300a56353b2f7a4a2547c8eb43a299
Test: manual
2017-04-10 11:59:18 -07:00
Mihai Nita
f4dacf29cc AAPT2: fixing the -c flag being ignored
Bug: 36999175
Test: manual

Change-Id: Id9a4a00a3b37bc088d86df7c75bbe711536b980f
2017-04-07 09:27:03 -07:00
TreeHugger Robot
448727bdae Merge "AAPT2: Fix pseudolocalization (again)" into oc-dev 2017-04-05 20:43:23 +00:00
TreeHugger Robot
7a7e415967 Merge "AAPT2: Allow multiple -c flags" into oc-dev 2017-04-04 19:14:47 +00:00
Adam Lesinski
113ee09738 AAPT2: Allow multiple -c flags
AAPT allows multiple -c flags in addition to separating -c arguments
with commas.

Bug: 35671619
Test: manual
Change-Id: I90491968e8ea2b28e3cd6e9246bcdd62bd6d6a3c
2017-04-03 19:38:25 -07:00
Adam Lesinski
8049f3da71 AAPT2: Fix pseudolocalization (again)
Pseudolocalization didn't properly handle spans in
strings like "<small><small>Hello</small></small>".

The spans would be identical and when doing range checks
only one of them would be updated.

Switched to a more robust way of extracting the relevant
chunks of a styled string. This uses a stack, which is more
in line with the real representation in XML.

Bug: 34088357
Test: make aapt2_tests
Change-Id: Ia4e4501713e688c96a89e26e4e2b1384f4cd3889
2017-03-31 18:30:20 -07:00
Adam Lesinski
c26ace0754 Merge "AAPT2: Parse an ID encoded as a map" into oc-dev 2017-03-30 00:31:01 +00:00
Adam Lesinski
b1afa07745 AAPT2: Allow arbitrary entry names with aapt2 optimize
Presumably, the apps build fine for the developers, so just
feed the existing names through without validation. Validation
still exists when building an app from source.

Bug: 36051854
Change-Id: Idc64ee91b08dce67d3c28f3c5284a7afa1312df1
Test: run aapt2 optimize on the apks from b/36051854 and build aapt2_tests
2017-03-29 20:56:32 +00:00
Adam Lesinski
33af6c730f AAPT2: Parse an ID encoded as a map
ID types should not be encoded as a map. AAPT and AAPT2 emit
IDs as boolean types.

Some apps exist that for some reason have their ID types encoded
as empty maps. This is the case only for the auto generated IDs
from enum values in <attr> tags.

Allow IDs as maps and ignore their content when processing an APK
for optimizing.

Also fixes an issue with expected size of the ResTable_package struct.

Bug: 35861796
Test: tested against the APK in b/35861796
Change-Id: I29a19cd9777bb10bed6766cd42e35e50e098797b
2017-03-29 20:11:04 +00:00
TreeHugger Robot
27a01ef063 Merge "AAPT2: Fix up file IO" 2017-03-24 22:04:59 +00:00
Adam Lesinski
06460ef0d7 AAPT2: Fix up file IO
This also enables an AAPT behavior that CTS tests have
come to depend on.

Small files that compress negatively (get larger) are stored
uncompressed. Some CTS tests assume this and try to open these
files by mmapping them, which is only possible if they are
uncompressed.

Bug: 35461578
Test: make aapt2_tests
Change-Id: Id622a6150fe72477ad65d67d1bad897a8ee2ffb9
2017-03-20 16:53:46 -07:00
Adam Lesinski
ed69ce84bd libandroidfw: Fix mass logspam of ResourceTypes warnings
An overlay was incorrectly leaking its own resources into the
framework resource package, which caused warnings for every app
that tried to access framework resources (all of them).

This change skips including any resources that are not overlaying
anything (not present in IDMAP).

Bug: 36256974
Test: make libandroidfw_tests
Change-Id: I8c710af6849bb848938825aacca02799ee96c003
2017-03-20 14:51:13 -07:00
Adam Lesinski
b0c47ef877 AAPT2: Finish support for feature splits
- Prefix the config split name generated from a feature split with the
  name of the feature split.
- Add the 'configForSplit' attribute to the <manifest> tag of a config
  split and give it the same name as the feature split it was generated
  from.
- Look for the featureSplit attribute in <manifest> and automatically
  convert it to 'split' and inject 'android:isFeatureSplit="true"'.

  Feature splits should be written like so:

  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.foo.example"
            featureSplit="feature_b">

        <uses-split android:name="feature_a" />

        ...
  </manifest>

Bug: 34703094
Test: manual
Change-Id: I01b5c4a9aa03a2d25ef1e87bc7874b57c9deede9
2017-03-16 15:45:16 -07:00
Adam Lesinski
b39ad7c9f6 AAPT2: Add -A (assets) support
Looks like the build system doesn't support assets/ for
resources, so we will re-introduce them in aapt2, even though
we're just copying them around and they would be better
suited for inclusion in the APK when classes.dex gets inserted.

Bug: 35461578
Test: CTS test android.content.res.cts.AssetManager#testAssetOperations should pass
Change-Id: I18361d7367d476806bcf7154ee76df3f0e83b565
2017-03-14 12:26:28 -07:00
Adam Lesinski
f34b6f4f2b AAPT2: Add --package-id flag for feature-split suppport
Bug: 35928935
Change-Id: Ia8496505e61cfcfdb8f9f62366d2f36e453db111
Test: make aapt2_tests
2017-03-07 11:06:16 -08:00
TreeHugger Robot
df2870df9a Merge "AAPT2: Fix parsing ResTable_type" 2017-03-06 20:01:17 +00:00
TreeHugger Robot
ae3c244944 Merge "AAPT2: Fix Plural::Equals() method" 2017-03-04 00:50:51 +00:00
Adam Lesinski
136fd0764f AAPT2: Fix parsing ResTable_type
ResTable_type's size changes due to it containing
ResTable_config. Make sure we check for the minimum size
required to read it.

Bug: 35861796
Test: Manual (don't have an integration test harness setup yet)
Change-Id: Ifb0cd1d732625f59835c8ed0449adb78129636de
2017-03-03 14:01:09 -08:00
Adam Lesinski
ac6edc501b AAPT2: Fix escaping sequence processing in XML parsing
Bug: 35483813
Test: make aapt2_tests
Change-Id: I68baba17ab3639c220b734a2a68d86aad0dedf8c
2017-03-02 19:32:32 -08:00
Adam Lesinski
8f7c550e20 AAPT2: Fix Plural::Equals() method
Test: make aapt2_tests
Bug: 35902437
Change-Id: I8797f89af58876f891f0b0c5cce85fd7781c4e24
2017-03-02 17:45:51 -08: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
Adam Lesinski
d48944a745 AAPT2: Rename strip phase to optimize
- Allow resource deduping, version collapsing, and sparse resource
  encoding.

Test: manual
Change-Id: Ia4aa892ab5b06ba1d5ea4a6efb51b00bc3a980c4
2017-02-22 11:41:55 -08:00
Adam Lesinski
ceb9b2f80f AAPT2: Shared library support
Test: make aapt2_tests
Change-Id: I98dddf1367e6c0ac425bb20be46e6ff05f4f2f45
2017-02-22 11:16:13 -08:00
Adam Lesinski
c8f71aa67e Add ResTable_sparseTypeEntry support
Benchmarks on bullhead-userdebug show that there is a negligent
performance impact when using sparse entries on a 30% loaded
sparse type of 1000 resources.

Benchmark                                             Time           CPU Iterations
-----------------------------------------------------------------------------------
BM_SparseEntryGetResourceSparseLarge                255 ns        254 ns    2751408
BM_SparseEntryGetResourceNotSparseLarge             254 ns        254 ns    2756534

Bug: 27381711
Test: make libandroidfw_tests aapt2_tests
Change-Id: I051ea22f2f6b2bc3696e446adc9e2a34be18009f
2017-02-15 12:40:02 -08:00
Pierre Lecesne
5b12734fb0 Merge "Allow for multiple preferred densities in the strip command." 2017-02-12 18:44:01 +00:00
Pierre Lecesne
672384b41e Allow for multiple preferred densities in the strip command.
Test: Unit tests pass.

Change-Id: I1f27ac8c36ff3489e4c8e4fce7f3d9cb31df6906
2017-02-12 15:57:41 +00:00