755 Commits

Author SHA1 Message Date
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
a117526b4a Merge "Remove RRO policy product_services" 2019-01-18 00:41:31 +00:00
Ryan Mitchell
9853845074 Merge "Add enforcement of idmap policies" 2019-01-18 00:41:11 +00: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
Aurimas Liutikas
ce7c99c661 Add source style for each TypedValue.
This API will be used by Android Studio layout inspector to
query where a given resource attribute originated from to allow
developers to have an easier way to find what needs to be changed
to affect a given resource attribute.

Test: CTS added in the topic
Bug: 111439551
Change-Id: Ifbb52b39912ed0444030a86164290a1cd4155250
2019-01-15 16:11:23 -08:00
Ryan Mitchell
cf9dd94323 Merge "Add encoding of name and actor overlayable fields" 2019-01-15 19:34:30 +00:00
Winson Chiu
55d9a6042b Merge "Add function to return path for last resolved resource" 2019-01-15 18:38:17 +00:00
Nick Kralevich
20f260b639 Merge "CursorWindow.cpp: replace dup() with fcntl(F_DUPFD_CLOEXEC)" am: adf025b1ff am: de408b3cb4
am: 7f74aeed50

Change-Id: I20f72f6de160a38d3b6067e685c396e6a27e2dc7
2019-01-15 03:31:12 -08:00
Chih-Hung Hsieh
bc80706599 Merge "Fix/suppress androidfw google-explicit-constructor warnings" am: 392f0052c2 am: 99a3d72b98
am: cd06f9ee04

Change-Id: I0340acdbd6530f9bd9f67333974bcc65ff97e0e5
2019-01-14 14:58:22 -08: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
Nick Kralevich
e104df9483 CursorWindow.cpp: replace dup() with fcntl(F_DUPFD_CLOEXEC)
Replace calls to dup() with fcntl(F_DUPFD_CLOEXEC). The only difference
between the two is that O_CLOEXEC is set on the newly duped file
descriptor. This helps address file descriptor leaks crossing an exec()
boundary.

Test: compiles and boots
Bug: 120983106
Change-Id: Icc2ff2f7f398905aa8283c8797898114d34a9829
2019-01-14 14:05:06 -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
Chih-Hung Hsieh
c2ace0c694 Fix/suppress androidfw 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: Id02c36c24f5708584e317c035cef3ef2762b537e
2019-01-10 19:53:08 +00:00
Ryan Mitchell
ed2af4df00 Merge "Add actor and name parsing for overlayable" 2018-12-19 17:31:50 +00:00
Dan Shi
8d7267e82a Add libandroidfw_tests to device-tests suite
For it to be included in device-tests.zip to run test in a suite.

Bug: none
Test: none
Change-Id: Ic20bede356f82a80582acb3883ad1ab9e76a6bdc
2018-12-18 16:06:40 -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
54237ffed4 Add actor and name parsing for overlayable
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-13 16:05:10 -08:00
Ryan Mitchell
267d6ac11e Merge "Refactor policy parsing" 2018-12-13 00:07:32 +00:00
Todd Kennedy
81e6e1dc1f Merge "Adding rtmitchell to androidfw OWNERS" 2018-12-13 00:03:50 +00:00
Ryan Mitchell
2d708911a7 Adding rtmitchell to androidfw OWNERS
AAPT2 + AndroidFW!

Change-Id: I40bb405d8f0a17d8477bff931bafa2c2ab8fa274
2018-12-12 15:59:00 -08:00
Chih-hung Hsieh
5374655451 Merge "Fix cert-dcl16-c clang-tidy warnings." am: 20b64c4bc7 am: 3038f743bf
am: 82b999a59c

Change-Id: Ie4bb31fc7366d65e92209c31f6721e20c8538e9a
2018-12-11 19:34:07 -08:00
Ryan Mitchell
1bb1fe068a Refactor policy parsing
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-11 13:48:45 -08:00
Chih-Hung Hsieh
054dab1d47 Fix cert-dcl16-c clang-tidy warnings.
Bug: 120614316
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,cert-dcl16-c
Change-Id: I2dc262d3407aafa969e921236dc3fc3ae60eb9d4
2018-12-11 11:27:17 -08:00
TreeHugger Robot
764acc461c Merge "Encoding of <overlayable> and <policy>" 2018-12-05 07:06:21 +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
Ryan Mitchell
449a54fb6b Do not include system overlay data when excluded
Do not include configurations or locales from overlays overriding system
resources when exclude_system is specified in GetResourceConfigurations
or GetResourceLocales.

Bug: 120083032
Test: run cts -m CtsContentTestCases -t
  android.content.res.cts.AssetManagerTest#testGetNonSystemLocales

Change-Id: I4ba3b07d3bb9ac72b196ff7ed4d1e853b51f7eea
2018-12-04 00:58:14 +00:00
Mårten Kongstad
59d5a5a938 idmap: use more robust data structures
The problem of creating idmap data consists of three steps:

  1. create the mapping overlay resid -> target resid
  2. fix the padding between the target resids
  3. write the mapping as a binary stream

Because we iterate over the resources in the overlay package, there are
no guarantees on the order in which target resources are processed. This
means we can't fix the padding until after step 1. On the other hand,
after step 2 the mapping should be immutable.

Introduce new data structures that help enforce immutability and
ownership of data, as outlined above.

Bug: 80150169
Test: make libandroidfw_tests
Test: atest OverlayHostTests OverlayDeviceTests
Change-Id: I45689e8003c96d251a63a758f77609972ae963df
2018-11-27 13:04:29 -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
Ryan Mitchell
0d5a91b137 Merge "Fix copying null reference across themes" 2018-11-20 01:00:45 +00:00
Ryan Mitchell
b85d9b2a32 Fix copying null reference across themes
When themes have two different AssetManagers, we only copy attributes
that exist in both the themes. If the value of the attribute or
reference is equal to 0 (a null reference but not using the TYPE_NULL
type), do not attempt to fix the package id of that null reference.

Bug: 119522708
Test: manual test of broken app
Change-Id: Id615d5a47b7f121b08bbba885d106b9cd3f54afc
2018-11-19 14:09:14 -08:00
Aurimas Liutikas
588bdc6719 Merge "Add style value to ResolvedBag in AssetManager2." 2018-11-19 20:48:55 +00: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
TreeHugger Robot
db54beb98c Merge "Prepare for switch to idmap2" 2018-11-15 23:37:04 +00:00
Mårten Kongstad
06a1ac8229 Prepare for switch to idmap2
Prepare the idmap and asset managers for interfacing with idmap2 instead
of today's installd + idmap pipeline, but don't make the switch just
yet.

Instead, idmap2 runs as its own native daemon with an AIDL interface.
This removes the need for installd to fork and exec on each idmap call,
saving about 50 ms per call.

Bug: 78815803
Test: atest OverlayDeviceTests OverlayHostTests
Change-Id: I60852e15d99329896ff9de6559d1e7cd1c67e33d
2018-11-12 13:24:33 -08:00
Mårten Kongstad
e0930d324c libandroidfw: add FALLTHROUGH_INTENDED to silence warnings
Add FALLTHROUGH_INTENDED to silence compiler warnings such as the
following:

-------- 8< --------
[ 42% 27/63] //frameworks/base/libs/androidfw:libandroidfw clang++
Locale.cpp
frameworks/base/libs/androidfw/Locale.cpp:166:7: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
      case 5:
      ^
frameworks/base/libs/androidfw/Locale.cpp:166:7: note: insert 'FALLTHROUGH_INTENDED;' to silence this warning
      case 5:
      ^
      FALLTHROUGH_INTENDED;
frameworks/base/libs/androidfw/Locale.cpp:166:7: note: insert 'break;' to avoid fall-through
      case 5:
      ^
      break;
1 warning generated.
-------- >8 --------

Test: 'make libandroidfw' builds with no compiler warnings
Change-Id: I6bc67f2c072f88c9f1a92b7378a6f1a460db70b4
2018-11-12 13:07:08 -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
3064067908 Merge "Copy common resources between styles" 2018-11-05 23:56:39 +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
Chih-hung Hsieh
51025d638d Merge "Allow implicit-fallthrough warnings locally." am: 36afe11a64 am: 9c5738238d
am: 469705cca4

Change-Id: I4bc5f389495ed535762438632e65ccd6c66f3739
2018-10-25 17:58:17 -07:00
Chih-Hung Hsieh
e8abd06776 Allow implicit-fallthrough warnings locally.
It will be a global error by default.

Test: make checkbuild
Bug: 112564944
Change-Id: I26616fd50ccf3639fa7c01d850a14d079273ede7
Exempt-From-Owner-Approval: do not block on new warnings
2018-10-22 09:56:12 -07:00
Ryan Prichard
559dbd88c7 Merge "Change ZipArchiveHandle from void* to ZipArchive*" am: f79542efd3 am: a34a1e0c97
am: 498357670e

Change-Id: I4fe5a70c750328bb67cdc02a08e4f9eeb97ac20d
2018-10-15 22:05:59 -07:00
Ryan Prichard
a34a1e0c97 Merge "Change ZipArchiveHandle from void* to ZipArchive*"
am: f79542efd3

Change-Id: Iebca19f2757ae77c07eca46a721c6966621fea14
2018-10-15 19:06:02 -07:00
Ryan Prichard
3addcd3965 Change ZipArchiveHandle from void* to ZipArchive*
Bug: none
Test: m checkbuild
Exempt-From-Owner-Approval: owner is OOO for another week,
  it's a fairly minor change to this repository
Change-Id: If4cf57619034ab98b06115ca60beb2fb26c4cd19
2018-10-15 23:22:47 +00: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
Mårten Kongstad
2a656b455d Merge "libandroidfw: introduce ExecuteBinary (POSIX only)"
am: 120b7fba93

Change-Id: I6e0b320e8887e32b8ea3fd1cfcf0804714fe1eb3
2018-10-09 16:08:34 -07:00
Mårten Kongstad
b7c0800fa0 Merge "libandroidfw: move ConfigDescription from aapt2 to libandroidfw"
am: b14c887974

Change-Id: I14be80a2d2c3620919a78da5a42ed56ec1d1737f
2018-10-09 16:04:34 -07:00