798 Commits

Author SHA1 Message Date
Ryan Mitchell
ee4a564d4f Allow for overlaying dynamic shared libraries
Overlays targeting shared libraries should be loaded into the
resources of every target that depends on the shared library.

Static shared libraries are currently not supported because overlays
should override all versions of static shared libraries and there is
not currently support for an overlay targeting multiple APKs.

Also created a test instrumentation and host test suite for testing
overlays and packages on the system image.

Bug: 140790224
Test: atest OverlayRemountedTest
Change-Id: I20a217b6368d6cf92b2b9f46908fd58012933f72
2020-01-10 23:20:19 +00:00
Ryan Mitchell
fe50d739f7 Assign shared libraries stable package ids
When a shared library package is loaded into an AssetManager, the
shared library will be assigned a unique package id. Subsequent
AssetManaagers that load a shared library of the same package name
as the original shared library will use previously assigned package
name. Shared libraries will have stable package ids throughout the
lifetime of application.

Bug: 140790224
Bug: 128496033
Test: libandroidfw_tests
Test: third-party app no longer crashes on open
Test: atest CtsHostsideWebViewTests
Change-Id: Idc0315be21ea00b74d1a918b7083ad655104c008
2020-01-10 23:15:06 +00:00
TreeHugger Robot
5a9109789e Merge "Add tests for layout overlaying" 2019-12-20 21:40:41 +00:00
TreeHugger Robot
548d6dcf77 Merge "idmap2: add debug information to idmap file format" 2019-12-20 14:38:36 +00:00
Automerger Merge Worker
944c611bd7 Merge changes from topic "icu65.1-upgrade" am: ad2026640c am: b1cc7c336b am: 4870a488d4
Change-Id: Ia5343e7e742c844a0b58d3964ec0eac2c3d0b75a
2019-12-20 12:29:42 +00:00
Nikita Iashchenko
ad2026640c Merge changes from topic "icu65.1-upgrade"
* changes:
  Regenerate LocaleDataTables.cpp
  Update API surface for ICU 65.1
2019-12-20 11:14:44 +00:00
Automerger Merge Worker
1d4949230e Merge "Add per-file ownership to libs/androidfw/LocaleDataTables.cpp" am: 073b0dad72 am: 36fac337ad am: b43a2e6740
Change-Id: Ib7ebb261de2d7492f0a5d1bd7faef7210b3ffe12
2019-12-19 21:33:05 +00:00
Nikita Iashchenko
7b085ddae0 Regenerate LocaleDataTables.cpp
LocaleDataTables.cpp was regenerated running the following command
(should be run from frameworks/base):

$ ./tools/localedata/extract_icu_data.py $ANDROID_BUILD_TOP > libs/androidfw/LocaleDataTables.cpp

Test: m droid
Change-Id: If180ff22a74b485cc3cca34a3f9ba98c826a2210
2019-12-19 19:36:50 +00:00
Mårten Kongstad
d7e8a534d0 idmap2: add debug information to idmap file format
Add a new variable length string to the idmap file format. This string will
hold debug information like fulfilled policies and any warnings triggered while
generating the file.

Bump the idmap version to 3.

Adjust the idmap header definition in ResourceType.h to take the new string
into account.

Example debug info:

  $ idmap2 create \
        --target-apk-path frameworks/base/cmds/idmap2/tests/data/target/target.apk \
        --overlay-apk-path frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk \
        --idmap-path /tmp/a.idmap \
        --policy public \
        --policy oem

  $ idmap2 dump --idmap-path /tmp/a.idmap
  target apk path  : frameworks/base/cmds/idmap2/tests/data/target/target.apk
  overlay apk path : frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk
  I fulfilled_policies=oem|public enforce_overlayable=true
  W failed to find resource "integer/not_in_target" in target resources
  0x7f010000 -> 0x7f010000 integer/int1
  0x7f02000c -> 0x7f020000 string/str1
  [...]

  $ idmap2 dump --idmap-path /tmp/a.idmap --verbose
  00000000: 504d4449  magic
  00000004: 00000003  version
  00000008: 76a20829  target crc
  0000000c: c054fb26  overlay crc
  00000010: ........  target path: frameworks/base/cmds/idmap2/tests/data/target/target.apk
  00000110: ........  overlay path: frameworks/base/cmds/idmap2/tests/data/overlay/overlay.apk
  00000210: ........  debug info: ...
  00000294:       7f  target package id
  00000295:       7f  overlay package id
  [...]

Also, tell cpplint to accept non-const references as function parameters:
they make more sense as out-parameters than pointers that are assumed to
be non-null.

Also, switch to regular expressions in the RawPrintVisitorTests: no more
manual fixups of the stream offsets! Tell cpplint that the <regex>
header is OK to use.

Bug: 140790707
Test: idmap2_tests
Change-Id: Ib94684a3b4001240321801e21af8e132fbcf6609
2019-12-19 16:51:51 +00:00
Victor Chang
dbd6c5e267 Add per-file ownership to libs/androidfw/LocaleDataTables.cpp
Test: treehugger
Change-Id: I61366a576e75137cef2b6607cd860cfd16c23869
2019-12-19 15:55:52 +00:00
Automerger Merge Worker
cfb045a481 Merge "Regenerate LocaleDataTables.cpp" am: 6658c31b4e am: ccc64a5aef am: ffbeb382a2
Change-Id: Ic6beb9b8a0374663babf41431e5f59ad7c18f7d0
2019-12-17 14:45:33 +00:00
Victor Chang
e84c6b50c2 Regenerate LocaleDataTables.cpp
LocaleDataTables.cpp is outdated due to ICU update over the years

Test: ./tools/localedata/extract_icu_data.py $ANDROID_BUILD_TOP
Test: m droid
Change-Id: I21918cc0f50c7347e514dc7b015607e19cffb377
2019-12-16 15:31:09 +00:00
Ryan Mitchell
df9e732962 Add tests for layout overlaying
Add tests to ensure that findViewbyId retrieves the correct view when
an id is overlaid in a RRO.

Also fixes a bug that made strings hardcoded in the overlays.xml
file unable to be retrieved from the string pool.

Bug: 135943783
Test: atest OverlayDeviceTests
Change-Id: I2bf03f151cb696d28f6bb9018eb319af29ba48f4
2019-12-12 10:55:33 -08:00
Alec Mouri
7d77ff827c [DisplayEventDispatcher] Kick DisplayEventDispatcher out of libandroidfw.
DisplayEventDispatcher will live in libgui for now, as a shim over
DisplayEventReceiver. This is so that we can keep libgui out of the
UI-renderer module while we can work on stabilizing the interface with
libandroidfw for asset management required by graphics classes.

It also doesn't make much sense to have display-event functionality in a
separate grab-bag library, especially when there's two users, and
there is potentially an opportunity to somehow merge with
DisplayEventReceiver to simplify code a bit.

Change-Id: Ife0f9c8ad2053437087fdbf0618b892928ce6864
Bug: 142760698
Test: builds
2019-11-25 13:49:32 -08:00
Winson
d9d1736767 Overlayable actor enforcement
Validates that the caller of an OverlayManager API that mutates state
is actually allowed to act on the target as defined in the target's
overlayable tag.

<overlayable name="MyResources" actor="namespace/name">

An actor is valid if any of the following is true:
 - is root/system
 - is the target overlay package
 - has the CHANGE_OVERLAY_PACKAGES permission and an actor is not defined
 - is the same package name as the sole resolved Activity for the actor specified
     in the overlayable definition, with only pre-installed, namespaced actors
     currently supported

Bug: 119442583
Bug: 135052950

Test: atest SystemConfigNamedActorTest
Test: atest com.android.server.om

Change-Id: If56b9e8366852eaef84f6bb25c3e6871eaa3f219
2019-11-21 12:01:41 -08:00
Ryan Mitchell
73bfe41bab Do not look for R.class of overlays
Now that RROs are loaded as shared libraries,
LoadedApk#makeApplication is attempting to find the onResourcesLoaded
method of the overlays. This is a performance hit and causes more
memory than necessary to be allocated during application start up.

Bug: 143314947
Test: com.android.performance.tests.HermeticMemoryTest
Change-Id: I3b8cd22dae83e0164d6678c80279f9fffceb34e6
2019-11-13 14:51:14 -08:00
Ryan Mitchell
8a891d86ab Allow for RRO internal referencing
This change allows RROs to reference their own internal resources as
expected.

Overlays are loaded as shared libraries so they can have their own
resource id space that does not conflict with the resource id space of
the target or other overlays.

References to overlay resources that override target resources now
appear as references to the target resources.

Overlay values that are inlined into the xml file specified using
android:overlayResources are now able to be used at runtime.

See go/rro-references for more information.

Bug: 135943783
Test: idmap2_tests
Test: libandroidfw_tests
Change-Id: Ie349c56d7fd3f7d94b7d595ed6d01dc6b59b6178
2019-10-17 13:09:33 -07:00
Ryan Mitchell
e753ffef54 Idmap format changes for bidirectional lookup
This change modifies the idmap file format to allow for target resources
to map to arbitrary type/value combinations and to allow overlay
resources to be mapped back to target resource ids so references to
overlay resources can appear as references to target resources at
runtime.

The mappings of target resources to overlay resources and vice-versa are
both encoded as sparse arrays. Instead of looking up a resource by
indexing into an array that maps to the overlay resource id, the runtime
will binary search over the sparse array to find the type and value that
overlays the target resource.

Bug: 135943783
Test: idmap2_tests
Change-Id: I5d5344cdb7fe35f4f2e8d6781016299dea5d1e20
2019-10-17 11:37:24 -07:00
Winson Chiu
8e4f087cc1 Merge "Add ResourceLoader API with .apk and .arsc support" 2019-10-11 18:05:00 +00:00
Winson
9947f1e4fa Add ResourceLoader API with .apk and .arsc support
ResourceLoaders allow inserting another .apk/.arsc into AssetManager's
resource resolution search. The effect is similar to overlays,
where a entry of >= config later in the path list will return that
ApkAsset's resource value instead.

Because loading from an .arsc is supported, which doesn't contain
any actual files, ResourceLoader exposes loadDrawable and
loadXmlResourceParser to allow an application load those files from
anywhere or create them in code.

The data being loaded is either pushed into an .apk or .arsc that
mocks itself as the package being "overlaid" and is passed in
through ResourcesProvider, an interface with static methods that
supports loading from a readable path on disk or a FileDescriptor.

The APIs are accessed through a Context's getResources(), which
has been changed to be unique per "Context-scope", which is usually
the lifetime of the Java object. The exception is that Activities
who get their Resources object persisted across recreations
maintain that logic for persisting ResourceLoaders.

Bug: 135270223

Test: atest FrameworksResourceLoaderTests

Change-Id: I6929f0828629ad39a21fa155e7fec73bd75eec7d
2019-10-10 15:41:03 -07:00
Ryan Mitchell
9e4f52b2e5 Parse <overlay> and abstract resource mapping
This change introduces idmap parsing of <overlay> tags.

The <overlay> tag allows one to explicitly map resources in the target
to either a resource in the overlay or an inline attribute value.

Use the android:resourcesMap atttribute on the <overlay> tag in the
android manifest to specify a file to provide the resource mapping.

Bug: 135943783
Bug: 135051420
Test: idmap2_tests
Change-Id: I1740dcdc01849c43b1f2cb8c6645d666dbb05dba
2019-10-04 16:11:37 -07:00
Jeongik Cha
dee02a0fae Merge changes from topic "system_ext"
am: a828ee6442

Change-Id: I2b636d0c54c932342586de47a38c16e93bf978e8
2019-09-26 15:40:26 -07:00
Ryan Mitchell
2e3942246d Enable CTS verification of overlayable API
Allows retrieval of a string representation of overlayable resources
that can be compared during CTS testing to verify that the overlayable
resources on device match the expected overlayable API.

Bug: 135052616
Test: libandroidfw_tests
Test: atest OverlayHostTest
Change-Id: I613f28c202a0904a917577f932d072111c1aa7bd
2019-09-26 17:53:20 +00:00
Jeongik Cha
3e725f2224 Consider overlay in system_ext as system's
When there is overlay package in system_ext, turn on POLICY_SYSTEM_PARTITION.
In other words, overlay pacakge in /system_ext is considered as system's one

Test: mv vendor/overlay/framework-res__auto_generated_rro.apk system_ext/overlay
      and then check if it works properly.
Bug: 136715327

Change-Id: Ib225368eae41203a8630f4310d26e9cf1afa706a
Merged-In: Ib225368eae41203a8630f4310d26e9cf1afa706a
(cherry picked from commit cba9579158cc70bf8eadb6e8a239e0ab2dc073d2)
2019-09-23 22:01:29 +00:00
Xin Li
d57e959e71 Merge qt-r1-dev-plus-aosp-without-vendor (5817612) into stage-aosp-master
Bug: 135460123
Change-Id: I65906d82b14125c0893d5cde0cfebb73bf9e38ab
Merged-In: I1f2564837c33cd4c6c3db6aac3cbaf8c09707da9
2019-09-10 11:16:29 -07:00
Yi Kong
f9b9903da9 Merge "Fix reversed logic" am: 946e857c71 am: ae6248d35b am: 6f1a7d3c10 am: 4559d83655
am: 55be4efaae

Change-Id: Ia459eab9db6ecb6558f868495189655146025f9b
2019-08-30 08:08:14 -07:00
Yi Kong
4559d83655 Merge "Fix reversed logic" am: 946e857c71 am: ae6248d35b
am: 6f1a7d3c10

Change-Id: Iae9b7033032bc381110ed11e9a99ab450f47704d
2019-08-30 07:36:29 -07:00
Yi Kong
ae6248d35b Merge "Fix reversed logic"
am: 946e857c71

Change-Id: I22194d1d2923170a224ad6d782dd8155e957ebe3
2019-08-30 07:16:21 -07:00
Yi Kong
f69c334dea Fix reversed logic
To check if a value falls in a range, it should be
  a >= MIN && a <= MAX
instead of
  a >= MIN || a <= MAX

Found by an experimental Clang warning change,
https://reviews.llvm.org/D66044.

Test: presubmit
Change-Id: I91e2a04687285d9311fd831197c73af38ec8379c
2019-08-30 02:09:30 +00:00
Songchun Fan
0d2b5392e9 Merge "[base] close zip archive when parsing fails" 2019-08-28 21:31:03 +00:00
Songchun Fan
898b316402 [base] close zip archive when parsing fails
Test: manual
Change-Id: I54c054da6000df15dba81ad211eb1cf61e88c5a8
2019-08-28 12:52:27 -07:00
Ryan Mitchell
8da1c38b69 Fix security issue in DynamicRefTable::load.
A crafted resources arsc could cause libandroidfw to read data out of
bounds of the resources arsc. This change updates the logic to calculate
whether the ref table chunk is large enough to hold the number of
entries specified in the header.

Bug: 129475100
Test: adb shell push ResTableTest data
Test: adb shell push poc.arsc data
Test: ./ResTableTest poc.arsc
Change-Id: Ifbaad87bdbcb7eecf554ef362e0118f53532a22a
2019-08-23 13:11:14 -07:00
Jeongik Cha
cba9579158 Consider overlay in system_ext as system's
When there is overlay package in system_ext, turn on POLICY_SYSTEM_PARTITION.
In other words, overlay pacakge in /system_ext is considered as system's one

Test: mv vendor/overlay/framework-res__auto_generated_rro.apk system_ext/overlay
      and then check if it works properly.
Bug: 136715327

Change-Id: Ib225368eae41203a8630f4310d26e9cf1afa706a
2019-07-10 00:33:26 +09:00
Ryan Mitchell
913c8074a7 Merge "Set idmap2 binary uid and gid after forking" into qt-dev am: ebad9125c8 am: e9acb9c566
am: 18e2a06453

Change-Id: I0bf570d5c4198f3ff9e5c4c62c8b88bc48db7ec6
2019-07-02 12:28:17 -07:00
Ryan Mitchell
18e2a06453 Merge "Set idmap2 binary uid and gid after forking" into qt-dev am: ebad9125c8
am: e9acb9c566

Change-Id: I30d650e7d5548f6e53f37c22f62e4de244145bdc
2019-07-02 11:53:41 -07:00
Ryan Mitchell
e9acb9c566 Merge "Set idmap2 binary uid and gid after forking" into qt-dev
am: ebad9125c8

Change-Id: I13b16878cad1cb742c0b417fa09ec406e8f1bf2d
2019-07-02 10:52:24 -07:00
Ryan Mitchell
3fc3c813ff Merge "Set idmap2 binary uid and gid after forking" into qt-dev
am: ebad9125c8

Change-Id: Ia4a881fc50118e15c4b6cbe66164c76e7b765298
2019-07-02 10:32:13 -07:00
Ryan Mitchell
a8f13667c2 Set idmap2 binary uid and gid after forking
The file permissions of the idmap2 binary are currently not set
correctly when the system forks and execs the idmap binary during
zygote. This chnages sets the uid and gid after forking to the same uid
and gid of the parent process.

Bug: 134897503
Test: device boots and generates idmap
Change-Id: Ic7fac49e5982f3c47713603b905c3a6be117a05b
2019-07-01 21:19:21 +00:00
Elliott Hughes
e6936e2792 Merge "Move off ZipString and over to std::string/std::string_view as appropriate." into qt-dev-plus-aosp am: ee1c95f060
am: 0566225cb8

Change-Id: I351ea009ee322ecd8bd117e4b2b686c636fb6770
2019-06-17 16:39:52 -07:00
Elliott Hughes
0566225cb8 Merge "Move off ZipString and over to std::string/std::string_view as appropriate." into qt-dev-plus-aosp
am: ee1c95f060

Change-Id: Ic87fff08eaf240bbaa370432b6955520206d3882
2019-06-17 16:26:05 -07:00
Elliott Hughes
a65cae9e7f Move off ZipString and over to std::string/std::string_view as appropriate.
(Cherrypick to AOSP master, resolving merge conflicts.)

Bug: http://b/129068177
Test: treehugger
Change-Id: Ib46761d89772d3a3c655a39df573fd305c117d19
Merged-In: Ib46761d89772d3a3c655a39df573fd305c117d19
2019-06-17 16:05:19 -07:00
Elliott Hughes
78de4f999d Move off ZipString and over to std::string/std::string_view as appropriate.
Bug: http://b/129068177
Test: treehugger
Change-Id: Ib46761d89772d3a3c655a39df573fd305c117d19
2019-06-17 16:47:58 +00:00
TreeHugger Robot
5f5c8463a3 Merge "Suppress compressed rersources.arsc on host" 2019-06-14 16:05:14 +00:00
Ryan Mitchell
31b1105762 Suppress compressed rersources.arsc on host
Do not print warnings when an APK loaded into aapt2's symbol table has a
compressed resources.arsc. This log is helpful at runtime since
compressed arscs take longer uncompress.

Bug: 130617130
Test: manual
Change-Id: I52847663ad8f46ba00d3dd1ebb2292ab54737680
2019-06-13 13:47:26 -07:00
Ady Abraham
44c4be7ee5 Merge "DisplayEventDispatcher: use eConfigChangedDispatch" into qt-r1-dev am: 619946fdc4
am: 8c219250c7

Change-Id: I70fd60cd1324ade4f3bc6b88036ec7b9be6d9e01
2019-06-07 18:54:09 -07:00
Ady Abraham
8c219250c7 Merge "DisplayEventDispatcher: use eConfigChangedDispatch" into qt-r1-dev
am: 619946fdc4

Change-Id: I98ecea42a933ed20ddd7b085baa88c277e53e353
2019-06-07 18:36:52 -07:00
Ady Abraham
9c501aad4b DisplayEventDispatcher: use eConfigChangedDispatch
In order to get DISPLAY_EVENT_CONFIG_CHANGED, eConfigChangedDispatch needs
to be used when creating DisplayEventDispatcher.

Bug: 131688378
Test: adb shell /data/nativetest64/libsurfaceflinger_unittest/libsurfaceflinger_unittest
Test: trigger config change and observe logcat
Change-Id: I0de8037ee5b024b7d9729750f582be919087be41
2019-06-07 10:26:47 -07:00
Daniel Santiago Rivera
4ca1cc9640 Update LOG_WINDOW format params.
Params of size_t use %zu formatting, while int64_t use PRId64. These
params had not been updated in a while since LOG_WINDOW is a no-op
macro when LOG_NDEBUG is off.

Test: Enable LOG_NDEBUG and do make
Change-Id: I59e9fa1aa343fd0a1da83c40fd24f3ef7bae5ed4
2019-05-24 16:36:55 -07:00
Eric Holk
64bd7c068c Merge "Remove obtainStyledAttribute and AssetManager2::GetBag tracing" into qt-dev
am: bdc1ba53ef

Change-Id: I664783b86275e5a6513c1d464aa0bc7d12829ad0
2019-05-21 14:36:36 -07:00
Eric Holk
4487398e0d Remove obtainStyledAttribute and AssetManager2::GetBag tracing
These traces are small and noisy, so they hurt performance more than they help.

This reverts commit c37457799be3db0590a5d94832b2fef5f64ef439.

Test: m
Bug: 132721345
Change-Id: I9ef719f54f2bc8a54f23e88f46d74e35417a6519
(cherry picked from commit 3509b624feecbcb8be850f9e1f397cdd7aeea5e2)
2019-05-21 00:31:03 +00:00