156 Commits

Author SHA1 Message Date
Mårten Kongstad
c92c4dd6c6 Surface <overlayable> info in Java AssetManager
Add a new, hidden method to AssetManager to extract a mapping
overlayable name -> overlayable actor for all <overlayable> blocks in a
package. [This will eventually be used to check if the caller of the OMS
AIDL API is the registered actor for a given overlay.]

Also, teach AssetManager2 to not accept packages that re-use the same
overlayable name. [Such packages have always been ill-formed.]

Bug: 123894537
Test: make libandroidfw_tests
Change-Id: I1117fd3503f04fe4c73eb7114901e022508f4d9e
2019-02-07 14:32:16 -08:00
Ryan Mitchell
741e96ff07 Fix GetResourceName for shared libraries
GetResourceName used GetPAckageById which only works when the compile
time package id is eqal to the runtime package id. This change resolves
resource names correctly using the ruuntime package id.

Bug: 79666085
Test: libandroidfw_tests
Change-Id: Ic60cb2416329c5cb34e925991cd689ca7574b483
2019-01-24 15:45:43 -08:00
Ryan Mitchell
02d9c1e931 Remove RRO policy product_services
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-16 11:47:33 -08:00
Mårten Kongstad
d10d06d0b0 Add enforcement of idmap policies
Teaches idmap2 to recognize policy restrictions put on overlayable
resources. If overlayable enforcement is turned on for an overlay, then
any resources defined within the overlayable api of the target will have
policy restrictions imposed on them. All resources without overlayable
definitions will continue to be overlayable without policy restrictions.

Bug: 119390857
Test: atest idmap2 and booting

Co-authored-by: Ryan Mitchell <rtmitchell@google.com>
Change-Id: I7e435648eb6e4a87b0b90a7b2a0c3f33c1516ea6
2019-01-16 11:47:24 -08:00
Ryan Mitchell
cf9dd94323 Merge "Add encoding of name and actor overlayable fields" 2019-01-15 19:34:30 +00:00
Winson
2f3669b767 Add function to return path for last resolved resource
After an AssetManager.FindEntry call is made, either directly or from any of the resource entry calls, a stack of the steps taken to resolve the resource is saved. Those steps can be retrieved as a log later on by calling AssetManager.GetLastResourceResolution, which returns a formatted string of the resource ID/name and path taken, including the configs and package names of each step.

Logging and the saving of the steps to memory can be enabled/disabled with the @hide .setResourceResolutionLoggingEnabled() method on AssetManager.

Bug: 122374289

Test: cases for single and multi ApkAssets loaded
Test: case for no resolution made
Test: made test app to display log on device
Test: added debugging call to source and ran through on-device apps

Change-Id: I6a32b8d4020c3f8510032ff7f431510089fff43f
2019-01-14 14:52:00 -08:00
Ryan Mitchell
ef5673a4c4 Add encoding of name and actor overlayable fields
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
2019-01-11 14:45:09 -08:00
Aurimas Liutikas
6c2a8b480f Add TEST_MAPPING for androidfw to add presubmit tests.
Test: atest --host libandroidfw_tests
Change-Id: Id893e720139791b499f2f38a25a057738a488c2b
2018-12-17 21:05:44 +00:00
Ryan Mitchell
75e20dda2b Encoding of <overlayable> and <policy>
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-12-04 16:45:26 -08:00
Mårten Kongstad
67d5c938e9 idmap: optimize time to create idmap data
Change idmap to iterate over the resources in the overlay package
instead of the target package when scanning for resources defined in
both packages. This cuts down the runtime cost of creating an idmap
considerably since the algorithm now scales with the number of resources
in the overlay package (a handful) and not the number of resources in
the target package (android: 10k, SystemUI: 8k) at a minor cost to code
complexity.

Improvements on the runtime of ResTable::createIdmap (systrace on an
emulator running aosp_x86_64-eng):

  - target=android: 12.5 ms -> 3.0 ms
  - target=SystemUI: 8.6 ms -> 1.0 ms

The bulk of the cost of creating an idmap from installd is now the fork
and execl to call "idmap --fd ..." which weigh in at 16 ms.

Bug: 80150169
Test: make libandroidfw_tests
Test: atest OverlayHostTests OverlayDeviceTests
Change-Id: I98e18d5958c0cd835a73055b714f5bf0f4f95a09
2018-11-21 06:48:19 -08:00
Aurimas Liutikas
d42a670ee5 Add style value to ResolvedBag in AssetManager2.
Bug: 117176857
Test: updated AssetManager2Test.MergesStylesWithParentFromSingleApkAssets
Change-Id: I2b79eea8e43431a932756b267b91eb4423c968a5
2018-11-16 10:50:34 -08:00
Ryan Mitchell
45ac8e4002 Merge "Fix flaky idmap test" 2018-11-08 19:09:47 +00:00
Ryan Mitchell
c2b0782c37 Fix flaky idmap test
The entry pool is encoded in UTF-8 not UTF-16. This would cause stringAt
to return a pointer to a cache that holds the UTF-8 string converted to
UTF-16. If the cache becomes invalidated, the UTF-16 pointer is no
longer valid and causes seg faults when looked up.

Test: libandroidfw_tests
Change-Id: I0f13dbeadd0d148de2805efd6cadb8e220368e3b
2018-11-07 10:28:56 -08:00
Ryan Mitchell
5db396d5cc Only resolve non-dynamic resource references
Only resolve non-dynamic references and attributes if the package is
loaded as a library or if a shared library is attempting to retrieve
its own resources.

Bug: 116486668
Bug: 116620612
Test: libandroidfw_tests & manual test of broken apps
      & atest FieldsClassificationTest#testGetAlgorith

Change-Id: Icb827796a65072a39452dbe577d5e18f085ea4e2
2018-11-07 01:28:53 +00:00
Ryan Mitchell
b3ae42e976 Copy common resources between styles
The docuemntation of setTo states that the resources two styles from
different AssetManagers have in common will be set in the destination
theme. This change adds this functionality. The package ids of the
attributes, the package ids of reference values, and the cookie of
attribute values have to be rewritten to match the destination
AssetManager. This change can later be made more generic if rewriting
references between packages is needed elsewhere.

Bug: 115897657
Test: libandroidfw_tests and manual test of app specified in the bug
Change-Id: Iee999ea2cc8473168cac11aaf3c34e14c958e5ae
2018-11-01 17:01:28 -07:00
Mårten Kongstad
62f3415ea6 Merge "libandroidfw: introduce ExecuteBinary (POSIX only)" am: 120b7fba93 am: 2a656b455d
am: dcef167772

Change-Id: I751a22f6610a103a32bbbb6925e12e5db6e4ca60
2018-10-10 19:12:19 -07:00
Todd Kennedy
c611199baf Merge commit 'c5e694e9549da3911392abd01bae125444f56294' into manual_merge_c5e694e9549da3911392abd01bae125444f56294
Change-Id: Ia48491cbcef8c3696c24619db2c3b7229f5bccc6
2018-10-10 12:48:14 -07:00
Treehugger Robot
120b7fba93 Merge "libandroidfw: introduce ExecuteBinary (POSIX only)" 2018-10-09 21:43:38 +00:00
Treehugger Robot
b14c887974 Merge "libandroidfw: move ConfigDescription from aapt2 to libandroidfw" 2018-10-09 21:43:38 +00: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
Mårten Kongstad
2503a49b96 libandroidfw: introduce ExecuteBinary (POSIX only)
Introduce a wrapper around fork and exec.

Test: make libandroidfw_tests
Change-Id: Iff0de5319bb6bb101a3fbef6413dfb4e77198f11
2018-10-04 03:45:32 +00:00
Mårten Kongstad
3f1f4fc11d libandroidfw: add resource ID iterator
Add an iterator to LoadedPackage which allows the caller to iterate over
the resource IDs in the package. This will be used by idmap when
constructing the idmap file.

Bug: 78815803
Test: make libandroidfw_tests
Change-Id: Ia47daa21390d67ea2ef3665e88eb407837c4764f
2018-09-28 09:40:20 +02:00
Ryan Mitchell
b9b540baf1 AFW: Lookup shared library resource ids
Shared libraries were failing to retrieve correct resource ids from the
values of attributes in xml files. The packages of the shared ids were
not changed from 0 to their runtime assigned package ids.

Bug: 112776204
Test: atest FieldsClassificationTest#testGetAlgorithm
Change-Id: I509bc7632f5ec3e9b644e590934e6cf569a4d938
2018-08-24 10:11:01 -07:00
Anton Hansson
0f185f8b19 Merge "frameworks/base: Update a few more references to android.jar." am: 85e68063a9
am: 52e98e1b7a

Change-Id: Iffb2389f8ef3dcca139a99a617c2079910f3c902
2018-05-02 10:24:32 -07:00
Anton Hansson
0c70390040 frameworks/base: Update a few more references to android.jar.
These files are moving. Update the paths so that the old files can be
deleted.

Bug: 77525052
Test: ./build for one of these scripts
Change-Id: Iacca1f1930d6a2614866f6503a2b4c1eba4d4018
2018-05-01 18:34:10 +01:00
y
9efbbef2e0 AAPT2: Support id reference chaining from AAPT
AAPT would allow for ids to be declared in the form:

<item name="name" type="id>@id/other</item>

@id/name should hold a reference to @id/other. When
getResources().getValue() is called on R.id.name with resolveRefs
enabled, the resuling reference should be R.id.other.

Bug: 69445910
Test: Created tests for correct parsing of id references and correct
resolving of deep references

Change-Id: Id1feb37b2565c213dc6a19b4c401906260d7fc14
2018-04-18 11:46:53 -07:00
y
57cd195c43 AAPT2: GetBag infinite recursion fix
Style resources with circular parental dependencies caused infinite
recursion when calling AssetManager2::GetBag. This fix allows recursion
to cease when a circular dependency is found.

Bug: 77928512
Change-Id: Ib900c36ab1aef5da5b03234a9484c4dad3b63c02
Test: Manual test of b/77928512 and duplicates of 74493983
2018-04-13 08:50:09 -07:00
Ryan Mitchell
2ad530d76c Added decoding of truncated AAPT string lengths.
AAPT incorrectly writes a truncated string length when the string size
exceeded the maximum possible encode length value (0x7FFF). To decode a
truncated length, this change iterates through length values that end
in the encode length bits. Strings that exceed the maximum encode length
are not placed into StringPools in AAPT2.

Test: Successfully ran broken apps from the duplicates of the bugs
provided and created tests
Bug: 69320870

Change-Id: I99dd9b63e91ac250f81d5dfc26b7c0e6276ae162
(cherry picked from commit ea9e8b447a5d24d1b199507dac203c69d81736e2)
2018-04-04 15:56:11 +00:00
Svet Ganov
3f08542208 Fix resource by name lookup
Test: added: '@' cases to ResourceUtilsTest
      pass: ./out/host/darwin-x86/nativetest/libandroidfw_tests/libandroidfw_tests
      pass: ./out/host/darwin-x86/nativetest/aapt2_tests/aapt2_tests
      pass: cts-tradefed run cts-dev -m CtsAppSecurityHostTestCases
                -t android.appsecurity.cts.PermissionsHostTest

Bug: 74612500

Change-Id: I144e4ca1b63b9cce71052fc02089bb6092739889
2018-03-22 20:59:05 -07:00
Adam Lesinski
bebfcc46a2 Refactor AssetManager
Bug: 64071469
Test: atest CtsContentTestCases
Change-Id: Ia6856157e8813856268fba003e1e591d690cb26e
2018-02-28 19:06:48 -08:00
Adam Lesinski
bde1df21ad Revert "Replace AssetManager with AssetManager2 implementation"
This reverts commit 1187590da38457809dd368d4901c9c47ac5a6958.

Bug: 73134570
Change-Id: I59b4d714e447478ea124f086356f127f42251fb7
2018-02-09 12:43:24 -08:00
Adam Lesinski
2a447172a5 Revert "libandroidfw: Make sure to set the 'app as lib' flag"
This reverts commit 9ad287c828a116f844e5c03346c618d83727e4ae.

Bug: 73134570
Change-Id: If930d3a7c17fc2f7ffaebd31281ad5a5d120144f
2018-02-09 12:43:17 -08:00
Adam Lesinski
c9a9c1c1c3 Revert "libandroidfw: Add ApplyStyle and SetConfiguration benchmark"
This reverts commit 59f63bd801f10336c9f0499b7a0bc0bccb0fad2e.

Bug: 73134570
Change-Id: I6ace34b0d6545ff001664792b0bb1bbff5b5cbbe
2018-02-09 12:43:13 -08:00
Adam Lesinski
b8b3a26194 Revert "libandroidfw: Improve performance of AssetManager2"
This reverts commit 88c9959e5b417320bbc2484fab42ab4b12379533.

Bug: 73134570
Change-Id: I012643d2b4212cef5aef68feb4146add34f9ecfc
2018-02-09 12:43:10 -08:00
Adam Lesinski
dfeb7ceb2a Revert "AssetManager2: Allow out of order type/type spec"
This reverts commit 78695c354342bd95ba5f63937b4e789139b50072.

Bug: 73134570
Change-Id: I6acc35372d9071d067d2fb7caa775ee9ba689811
2018-02-09 12:43:07 -08:00
Adam Lesinski
ec7f06cc37 Revert "AssetManager2: Fix list function"
This reverts commit adc0b87ec235a71d722fb8d6aad50ceaeac8c6d5.

Bug:73134570
Change-Id: I9e652245e7661eb7a34dadb5f363a08bc8c9e57e
2018-02-09 12:43:04 -08:00
TreeHugger Robot
a9bf9d166a Merge "AssetManager2: Fix list function" 2018-02-09 08:18:16 +00:00
Adam Lesinski
adc0b87ec2 AssetManager2: Fix list function
List was skipping directories. Include them, and add tests to ensure
the order and precedence is correct.

Bug: 72511641
Test: make libandroidfw_tests
Test: atest CtsContentTestCases:AssetManagerTest
Change-Id: Iadf45883283d3e4aae93bd7c3343745912e34fa0
2018-02-08 22:37:48 -08:00
Adam Lesinski
78695c3543 AssetManager2: Allow out of order type/type spec
AssetManager2 assumes that RES_TABLE_TYPE_SPEC_TYPEs must immediately
precede their associated RES_TABLE_TYPE_TYPEs. This is not correct.
RES_TABLE_TYPE_SPEC_TYPEs must precede their associated
RES_TABLE_TYPE_TYPEs, but they do not need to immediately precede them.

For example, this is what we currently expect:

  RES_TABLE_TYPE_SPEC_TYPE id=1
  RES_TABLE_TYPE_TYPE id=1
  RES_TABLE_TYPE_SPEC_TYPE id=2
  RES_TABLE_TYPE_TYPE id=2

but this is also valid:

  RES_TABLE_TYPE_SPEC_TYPE id=1
  RES_TABLE_TYPE_SPEC_TYPE id=2
  RES_TABLE_TYPE_TYPE id=1
  RES_TABLE_TYPE_TYPE id=2

Bug: 73052092
Test: make libandroidfw_tests
Change-Id: I1f3c43760f8108eee24c2c6ed7bc16f70e951c2b
2018-02-08 15:16:32 -08:00
Adam Lesinski
88c9959e5b libandroidfw: Improve performance of AssetManager2
AssetManager2 relied on creating a list of configurations
present in the resource table so as to avoid copying and
converting ResTable_config's from the APK on every
resource retrieval.

ResTable, however, had a better optimization that pruned
the configurations that didn't match the currently set
configuration. This vastly reduced the number of ResTable_configs
to test.

In this CL, AssetManager2 follows suite with this optimization
and only maintains the filtered ResTable_configs, falling back
to the slow path when the configuration is overridden.

Test: mma frameworks/base/libs/androidfw
Test: adb sync system data
Test: adb shell /data/benchmarktest64/libandroidfw_benchmarks/libandroidfw_benchmarks
Change-Id: Ib57b75fbb32e1d310eec146e5a12dfc6de4385f9
2018-02-05 18:38:57 -08:00
Adam Lesinski
59f63bd801 libandroidfw: Add ApplyStyle and SetConfiguration benchmark
Test: mma frameworks/base/libs/androidfw
Test: adb sync system data
Test: adb shell /data/benchmarktest64/libandroidfw_benchmarks/libandroidfw_benchmarks
Change-Id: Ia0e868008a3b32dc8d1c69ed1f2c39f152bb7815
2018-02-05 18:38:57 -08:00
Adam Lesinski
9ad287c828 libandroidfw: Make sure to set the 'app as lib' flag
When an app is loaded as a shared library (eg. monochrome),
make sure to set the bit that it loaded as such, so that
conversions from package ID 7f -> shared library ID are done.

Bug: 72511998
Test: make libandroidfw_tests
Test: out/host/<host_os>/nativetest64/libandroidfw_tests/libandroidfw_tests
Change-Id: Icd11b7a5adff351165ca16d5853fb5a0002c34b1
2018-02-05 18:38:57 -08:00
Adam Lesinski
1187590da3 Replace AssetManager with AssetManager2 implementation
Test: atest CtsContentTestCases:android.content.res.cts
Test: make libandroidfw_tests
Change-Id: I2bb6d7656d2516d371e83e541ed02f91405f6d94
2018-02-05 18:38:49 -08:00
Adam Lesinski
f7d01dd7e1 Revert "Replace AssetManager with AssetManager2 implementation"
This reverts commit dcb3c6559b09ec89771858ec27a787027da9af50.

Bug:72511998
Change-Id: I665966ca109f66f85d8665db388c71ea2303c3b8
2018-01-25 17:39:40 -08:00
Adam Lesinski
646265cb2a Revert "libandroidfw: Add ApplyStyle and SetConfiguration benchmark"
This reverts commit d9c809c480e22ccced6762268efaa30bb9a6e491.

Bug:72511998
Change-Id: I3be2374e3662fc8397c00f1df1bce6de5f5a4549
2018-01-25 17:34:40 -08:00
Adam Lesinski
0dd369912a Revert "libandroidfw: Improve performance of AssetManager2"
This reverts commit 64ee69d0f1f412edee2eb7a0c846deebbfa37ef9.

Bug:72511998
Change-Id: Iab3ce449e60ec2451d391217543528d312089080
2018-01-25 17:34:39 -08:00
Adam Lesinski
64ee69d0f1 libandroidfw: Improve performance of AssetManager2
AssetManager2 relied on creating a list of configurations
present in the resource table so as to avoid copying and
converting ResTable_config's from the APK on every
resource retrieval.

ResTable, however, had a better optimization that pruned
the configurations that didn't match the currently set
configuration. This vastly reduced the number of ResTable_configs
to test.

In this CL, AssetManager2 follows suite with this optimization
and only maintains the filtered ResTable_configs, falling back
to the slow path when the configuration is overridden.

Test: mma frameworks/base/libs/androidfw
Test: adb sync system data
Test: adb shell /data/benchmarktest64/libandroidfw_benchmarks/libandroidfw_benchmarks
Change-Id: I5d46f8b005a37b72750d00bd75f090e7b5a36f60
2018-01-24 15:19:09 -08:00
Adam Lesinski
d9c809c480 libandroidfw: Add ApplyStyle and SetConfiguration benchmark
Test: mma frameworks/base/libs/androidfw
Test: adb sync system data
Test: adb shell /data/benchmarktest64/libandroidfw_benchmarks/libandroidfw_benchmarks
Change-Id: Ia6b441f186ccb455acbee15723f0d2d5657b09b5
2018-01-24 15:19:09 -08:00
Adam Lesinski
dcb3c6559b Replace AssetManager with AssetManager2 implementation
Test: atest CtsContentTestCases:android.content.res.cts
Test: make libandroidfw_tests
Change-Id: I572eb13c6a4372c7f656f5912821cececd5bf3d4
2018-01-24 15:19:04 -08:00