324 Commits

Author SHA1 Message Date
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
TreeHugger Robot
024d22fdb7 Merge "AAPT2: Fix pseudolocalization to respect <xliff:g>" 2017-02-09 16:17:18 +00:00
Adam Lesinski
7542162cb1 AAPT2: Fix pseudolocalization to respect <xliff:g>
The XLIFF 'g' tag specifies content that should NOT be translated.
AAPT2's pseudolocalization process should respect it.

Bug:34064599
Test: make libandroidfw_tests
Change-Id: Ice437d7f0ff246730ee04896fd035e2d846148fb
2017-02-08 06:23:45 -08:00
Adam Lesinski
929d6517df AssetManager2: Add GetResourceId
Add ability to lookup a resource by name.

Test: make libandroidfw_tests
Change-Id: I262ba5ce4c9892458226fbdb44cf21f9877fb92d
2017-02-08 06:04:52 -08:00
Pierre Lecesne
0355dccc85 Merge "Only compress files that were already compressed in the original APK." 2017-02-04 03:54:43 +00:00
Adam Lesinski
558a63056e Merge "AAPT2: Support CtsContentTestCases build" 2017-02-04 03:44:25 +00:00
Pierre Lecesne
fa131d5312 Only compress files that were already compressed in the original APK.
Also fix a log message.

Test: Manually. Unit tests pass.

Change-Id: Iea236bbcfbe1a0a0894ce1bfce09c19208c5a0bc
2017-02-03 19:49:37 +00:00
Pierre Lecesne
2968cbf4aa Strip the resources from the APK using the TableSplitter.
Test: Unit tests pass.

Change-Id: I1dd71581113fb9a6feeefa9c794cc282529c3754
2017-02-03 18:57:09 +00:00
Pierre Lecesne
fc866baa33 Merge "Iterate over the zip entries in order." 2017-02-03 18:51:42 +00:00
Pierre Lecesne
265066c51d Merge "Expose whether a file was compressed before being loaded in memory." 2017-02-03 18:50:16 +00:00
Pierre Lecesne
970732dc45 Expose whether a file was compressed before being loaded in memory.
This is useful when we want to write an APK and keep the same
compression parameters as the original APK.

Test: Unit tests pass.

Change-Id: I3afcae1c8727e429b08c9ac7359cf0789ff4abfc
2017-02-02 23:39:24 +00:00
Pierre Lecesne
880d65b4fd Iterate over the zip entries in order.
Test: Unit tests pass.

Change-Id: I0501fad51a87c6cc91f2fc22358cd356616e1a2e
2017-02-02 22:52:44 +00:00
Pierre Lecesne
2599aa4dfd Add a method LoadedApk::WriteToArchive.
Test: Manually.

Change-Id: I61717204e58ca2bbfba9a52c7aecf27882a853f8
2017-02-02 21:35:21 +00:00
Adam Lesinski
86d67df8d5 AAPT2: Support CtsContentTestCases build
- Add <feature-group> to ManifestFixer.
- Support <meta-data> in <instrumentation>
- Add support for <bag> and type="configVarying". Some CTS tests use this
  old notation, we need to support it (even though configVarying isn't
  anything supported by the framework convention).

Change-Id: I6946fa633ce513ea8437c1496db883cf27dcf6de
Test: make aapt2_tests
2017-02-01 15:28:23 -08:00
Pierre Lecesne
8a7b4cb992 Backbone of the new aapt2 strip command.
The strip command takes an APK as argument and a --target-densities flag which
contains the list of screen densities for which to optimize the APK. All
the resources that would be unused for a device having the given
densities are stripped from the APK leaving only the ones actually being
used.

Test: Manual.

Change-Id: I68368b00876a18ccdbbfc0a8dd265bd361117933
2017-02-01 18:49:19 +00:00
Pierre Lecesne
ff759e6a6e Moving the LoadedApk class to its own file.
Test: Unit tests pass.

Change-Id: Id706f9ad1f3406bb73a60a33139a04745d5d72c0
2017-02-01 00:31:55 +00:00
TreeHugger Robot
e84ad491c8 Merge "Add color mode to activity/window" 2017-01-25 01:20:28 +00:00