Commit Graph

1022 Commits

Author SHA1 Message Date
Jeremy Meyer
558358612b Merge "implement drawable frros" 2022-11-14 22:35:08 +00:00
Jeremy Meyer
a761f3325e implement drawable frros
Test: unit tests
Bug: 251283316
Change-Id: Iead53711c54596c3787eeba6dcf9ced129f94426
2022-11-14 18:38:12 +00:00
Brandon Liu
ce231553c8 Merge "Fix tests affected by sparse.apk" 2022-11-14 18:22:49 +00:00
Brandon Liu
742b11e05d Fix tests affected by sparse.apk
Regenerated sparse.apk with latest aapt2 and updated resource qualifier
to orientation from sdk version because config sdk version was fully
dropped in aapt2. Also added tests with runtime apk generated by Soong
build target to make these tests more comprehensive. Applied
parameterized test to avoid duplicate code.

Bug: b/249370927
Test: Added and verified affected atests pass
Change-Id: I94f6758d7862375fe4053f42fe89953d4afa48fd
2022-11-11 22:57:18 +00:00
George Burgess
11946ae704 Merge "CursorWindow_test: fix leaks" am: b3a175ac30 am: f8b09c78e6 am: 0f42146dce
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2240845

Change-Id: I1912bb10a4999f0c667b4acbdb895f6f1a5a731f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-11-02 22:23:32 +00:00
Eric Miao
0fa6e36f85 Merge "Revert "libandroidfw: use map for more efficient indexOfString()"" 2022-10-25 01:35:43 +00:00
Eric Miao
f9f51c8197 Revert "libandroidfw: use map for more efficient indexOfString()"
This reverts commit 63e5d41be7.

Reason for revert: b/253420843

This CL causes memory regression as described in above bug. To speed
up the lookup from resource string to resource ID, the original CL
introduced std::unordered_map for the purpose, unfortunately, that
adds much memory footprint due to the number of key strings per
process. We will need to revisit the solution with a more memory
efficient approach.

Change-Id: I9c6754d361f091e963d4bebea0e698e72e221e51
2022-10-24 22:24:00 +00:00
Eric Miao
e89f79cd2f Merge "libandroidfw: use map for more efficient indexOfString()" 2022-10-12 21:10:29 +00:00
Yurii Zubrytskyi
ab3cb30aa0 Ensure no duplicates in ThemeKey
Some apps keep adding the same resources to their theme key
objects on e.g. switching dark mode. Need to be prepared to
limit the size of the arrays, otherwise theme switching gets
slower with each toggle

+ a bit more efficient native handling

Bug: 242005877
Test: manual, 10k of theme switches with no noticable slowdown
Change-Id: Icf74770bd41ebeb0a31f527ae3616de00f23b0ae
2022-10-11 12:23:42 -07:00
Eric Miao
63e5d41be7 libandroidfw: use map for more efficient indexOfString()
Bug: 249320624

There number of calls to ResStringPool::indexOfString() is very high
due to many calls to Resources.getIdentifier() in JAVA code. This is
used to get the resource ID (a 32-bit integer) by its resource name
(a string).

One example pprof trace is at:

  https://pprof.corp.google.com/?id=9b9b377bf52bdeb972c6ad154acf3902

This happens to the key string pool in a package, which is normally
encoded in UTF-8, unsorted. The call to indexOfString() ends up going
through the whole key string pool and do a per string comparison til
the string is found.

For some large applications, the key string pool could have > 10k+
strings, which results in an excessive calling to string8At() or
stringAt(). Although these calls are pretty quick, the excessive
callings are not necessary and inefficient.

There are a few ways to improve this:

1. sort the key strings so the current implementation ends up doing
a binary search. However, for some reason, there is no code in aapt
or aapt2 to support sorting and use the SORTED_FLAG.

2. or when needed, setup a std::map<StringPiece, size_t> to map the
key string to its ID, and use the map for all subsequent calls to
indexOfString()

Here we chose the 2nd way with a few justifications:

1. std::map<> has a stable O(logN) lookup performance, and a key
comparison doesn't involve comparing the whole key so it's both
fast and relative stable.

2. by using StringPiece, we are not allocating memory if the string
mapped doesn't need decoding, and StringPiece supports comparison.

This CL reduces the number of calls into string8At() or stringAt()
to the key string pool from 2m+ down to ~400k.

See example pprof trace at:

  https://pprof.corp.google.com/?id=cb677fca932260b2dc7db64ee37c4b61

Change-Id: I77a0ef13daac6d8a5c63a681c52f8ab9712578ed
2022-10-11 17:50:26 +00:00
George Burgess IV
079077fd77 CursorWindow_test: fix leaks
`buf` isn't freed here. Convert it to either a unique_ptr or stack
array, depending on size.

Caught by the static analyzer:
> frameworks/base/libs/androidfw/tests/CursorWindow_test.cpp:190:5:
warning: Potential leak of memory pointed to by 'buf'
[clang-analyzer-unix.Malloc]
> frameworks/base/libs/androidfw/tests/CursorWindow_test.cpp:268:5:
warning: Potential leak of memory pointed to by 'buf'
[clang-analyzer-unix.Malloc]
> frameworks/base/libs/androidfw/tests/CursorWindow_test.cpp:327:5:
warning: Potential leak of memory pointed to by 'buf'
[clang-analyzer-unix.Malloc]

Bug: 206470603
Test: TreeHugger
Change-Id: I6fee4a9c2eedce0385f794567b0083df24c63419
2022-10-06 15:56:19 -07:00
Yurii Zubrytskyi
1fc44ebb01 Clean up some resources code
More moves and fewer allocations

Bug: 237583012
Test: unit tests
Change-Id: I5cf43c8af0743c0e4d96808f1e55ceb4f02d7021
2022-09-29 14:28:51 -07:00
Lee Shombert
3e4d9f2007 Record resource access times
Bug: 246953799

Collect timing information for resource acquisition methods.  The
timing has nanosecond resolution and is collected inside the native
runtime code.  Timing values are accumulated in the runtime and are
periodically fetched and published by the java framework.  This
strategy means that normal resource methods incur a small runtime
overhead.  The longer time involved in publishing the values is
handled by an independent Java thread.

A public dumpTimers() method can be called from a dumpsys command, for
debug, but the dumpsys command is not hooked up in this commit.

No APIs are actually monitored in this commit, and the ResourceTimer
loop is not started.

Test: atest
 * androidfw_lib

Change-Id: I5995d3c6518ca2fa4c8ab9d3eb610167758c695d
2022-09-18 18:05:03 -07:00
Jeremy Meyer
be2b779746 Store frro configs in idmap file
This also includes the change to use the configs to decide which (if
any) frros to use at runtime

Bug: 243066074
Test: Manual, updated and created automated tests
Change-Id: I3f1d23e2958ad170799880b9f5eb5bd8ceb1fa67
2022-09-15 21:45:27 +00:00
Jeremy Meyer
6587102ec2 Store string frros in a string pool and copy that pool to the idmap
Bug: 232940948
Test: manual with test app and added automated tests
Change-Id: I30f5efefff7cf4fb0869188be78cc08e8efe7f04
2022-08-16 18:13:40 +00:00
TreeHugger Robot
d1345839c1 Merge "Revert "Force-initialize potential padding area."" 2022-06-22 17:37:13 +00:00
Jeff Sharkey
4425ec0dc6 Revert "Force-initialize potential padding area."
This reverts commit e33af7fe37.

Reason for revert: b/236673494

Bug: 213170822
Bug: 236673494
Change-Id: I07c971f0f3dabf15301d62b15e3b44760151097f
2022-06-22 15:40:07 +00:00
Jeff Sharkey
41451f090a Merge "Force-initialize potential padding area." 2022-06-09 15:24:44 +00:00
Jeff Sharkey
e33af7fe37 Force-initialize potential padding area.
When collapsing our heap-and-stack boundaries, we round up to ensure
our padding math is still aligned on the remote side.  This rounding
can leak a small amount of uninitialized memory, so this change
force-initializes any potential padding area.

Bug: 213170822
Test: atest libandroidfw_tests
Change-Id: Ife6fcd1b74aaabd932a77ea42e0d0ad3a6b9cae6
2022-06-08 22:38:56 +00:00
Victor Chang
d9ecf56a7c Regenerate LocaleDataTables.cpp due to ICU 71 upgrade am: 593ae0b0c9 am: 37e6dec90e am: b692927cfe am: 6037de2eed am: 77c545768c
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2117509

Change-Id: I556783d3e82d56ff8b7850a1489192fc03b27daf
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-08 14:53:05 +00:00
Victor Chang
b692927cfe Regenerate LocaleDataTables.cpp due to ICU 71 upgrade am: 593ae0b0c9 am: 37e6dec90e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2117509

Change-Id: I7c9e72983161790f166eff33cb574efc11709cd5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-06-08 13:18:48 +00:00
Greg Kaiser
851c62d45c Grab pointer into array post-resize()
This is a defensive change.  The current code is safe due to the
resize() which happens 30 lines above this one.  However, if that
resize() were to change or disappear, then this code would be
dangerous, as the resize() could potentially cause a reallocation,
and move our memory buffer.

Since it's no additional cost to grab the pointer into the
array after the resize(), we do that.

Bug: 232940948
Test: TreeHugger
Change-Id: I29b6cbeb064c7654eb21d2e42e05a0587604c32b
2022-06-02 05:30:32 -07:00
Jeremy Meyer
56f36e8f2f Move StringPool to libandroidfw
Test: verified affected tests pass
Bug: 232940948
Change-Id: I22089893d7e5013f759c39ce190bec07fa6435db
2022-05-31 23:43:03 +00:00
Victor Chang
593ae0b0c9 Regenerate LocaleDataTables.cpp due to ICU 71 upgrade
The command:
./tools/localedata/extract_icu_data.py $ANDROID_BUILD_TOP > libs/androidfw/LocaleDataTables.cpp

Bug: 232747988
Test: m droid
Change-Id: I43f09f62bc6d746eb1138b0de431fb614a7baa6a
2022-05-23 23:51:00 +01:00
Colin Cross
5430347529 Merge "Tweak linux_glibc properties for musl builds in frameworks/base" am: ee415b6dd4 am: 0465454af5 am: 8927c1f94e am: 24e387ae49
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2019598

Change-Id: Ieb4af745d7b219c8d74017dcb95edb1a07297cdb
2022-03-15 05:25:50 +00:00
Colin Cross
24e387ae49 Merge "Tweak linux_glibc properties for musl builds in frameworks/base" am: ee415b6dd4 am: 0465454af5 am: 8927c1f94e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2019598

Change-Id: I33e43c2b80acf35e7f9790d82c98d38bf2134697
2022-03-15 05:02:57 +00:00
Colin Cross
e8f6f0becc Tweak linux_glibc properties for musl builds in frameworks/base
For convenience, builds against musl libc currently use the
linux_glibc properties because they are almost always linux-specific
and not glibc-specific.  In preparation for removing this hack,
tweak the linux_glibc properties by either moving them to host_linux,
which will apply to linux_glibc, linux_musl and linux_bionic, or
by setting appropriate musl or linux_musl properties.  Properties
that must not be repeated while musl uses linux_musl and also still
uses the linux_glibc properties are moved to glibc properties, which
don't apply to musl.  Whether these stay as glibc properties or get
moved back to linux_glibc later once the musl hack is removed is TBD.

Bug: 223257095
Test: m checkbuild
Test: m USE_HOST_MUSL=true host-native
Change-Id: I7058c8f1dadd7bbfd7e169bdf0a0441eb6d10ec5
2022-03-09 16:31:28 -08:00
Yurii Zubrytskyi
ba6f8a3cc6 [res] Update resources to c++23
Test: manual
Change-Id: I769e907103cf0dbf1e02b95a78040ebc722c05a9
2022-02-16 17:46:20 -08:00
Treehugger Robot
a2f9e47c87 Merge "Fix cert-dcl16-c warnings" am: d78c0842df am: a4e7dfab4c am: 34fe73e15f
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1977907

Change-Id: Ia481193cdbd62c60d572db1c087597b439348ebd
2022-02-14 17:35:45 +00:00
Xin Li
a6a261b1be Merge "Merge sc-v2-dev-plus-aosp-without-vendor@8084891" into stage-aosp-master 2022-02-14 17:30:12 +00:00
Treehugger Robot
34fe73e15f Merge "Fix cert-dcl16-c warnings" am: d78c0842df am: a4e7dfab4c
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1977907

Change-Id: I4ae11f4853a0b69267521b13b1c61b167b6b29e6
2022-02-14 17:18:58 +00:00
Chih-Hung Hsieh
623cf543a8 Fix cert-dcl16-c warnings
Bug: 120614316
Test: make tidy-frameworks-base_subset
Change-Id: Ie71c06e02fcb9a2f90508c37d926a79e0b591c5a
2022-02-09 15:30:51 -08:00
Xin Li
f55c524f34 Merge SQ1A.220205.002
Bug: 213904741
Merged-In: Ib2b0342af85679c0514fb4d88530376b58e6e12a
Change-Id: I82a9718a548507487ab9fa1795e08fc42dca0086
2022-02-07 23:18:56 -08:00
Yurii Zubrytskyi
4812c71042 Merge "Proper bounds checking in LocaleValue" 2022-01-20 19:27:01 +00:00
Yurii Zubrytskyi
18c66d8fee Add missing size check when parsing staged aliases
Need to have the same kind of data size check as in other
types parsing

Bug: 203938029
Test: manual
Change-Id: I9f5d2851ff59da90163ead6c0416f0bba3868cc4
Merged-In: I9f5d2851ff59da90163ead6c0416f0bba3868cc4
(cherry picked from commit 8002034e6b)
(cherry picked from commit abdf5a518d)
Merged-In:I9f5d2851ff59da90163ead6c0416f0bba3868cc4
2021-12-15 00:02:00 +00:00
TreeHugger Robot
a76a6cc3bc Merge "Dump theme inheritance information in UnsupportedOperationException" 2021-12-14 05:45:31 +00:00
TreeHugger Robot
9014bfd74d Merge "add libandroidfw_tests back to TEST_MAPPING" 2021-12-14 04:37:30 +00:00
Felka Chang
00964e9aea Dump theme inheritance information in UnsupportedOperationException
It isn't enough to only dump the theme id and name because there is
no whole theme inheritance map. Developers need the map to figure out
why the attribute value is so strange.

A theme is a kind of style. This patch creates an API to retrieve the
parent id for any style.  And, it dumps the whole inheritance between
themes until it can't find the parent style.

Test: manual test described in b/209708201#comment5
Bug: 209708201

Change-Id: I9de0e6e9aaeff7cb9fc89dc9b8a04925e84f975c
2021-12-14 11:42:30 +08:00
Victor Chang
6fa65b01b0 Merge changes from topic "icu70" am: da0880a0fe am: 4bd88f5cd6 am: fd779286da am: 14682b1f76
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1914692

Change-Id: I0fc0a3a2afb0f3ec796cdcc686a8796daa194a16
2021-12-09 11:40:59 +00:00
Victor Chang
14682b1f76 Merge changes from topic "icu70" am: da0880a0fe am: 4bd88f5cd6 am: fd779286da
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1914692

Change-Id: Ic1df8684bec29041368790400232c42599b11188
2021-12-09 11:11:30 +00:00
Victor Chang
fd779286da Merge changes from topic "icu70" am: da0880a0fe am: 4bd88f5cd6
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1914692

Change-Id: Ie7aaa680ad81f065d9d3d2d38928092e9ee3aa38
2021-12-09 10:44:14 +00:00
Victor Chang
4bd88f5cd6 Merge changes from topic "icu70" am: da0880a0fe
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1914692

Change-Id: Ibbdc18a918397f831eac512394bd31e9f1038c18
2021-12-09 10:20:52 +00:00
TreeHugger Robot
1c376943ee Merge "Add missing size check when parsing staged aliases" into sc-qpr1-dev am: 81e1e9b53b
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16371979

Change-Id: I04bc0f2026f7780fc27bd3e4c9250edea898673f
2021-12-07 20:06:53 +00:00
TreeHugger Robot
5b0a126114 Merge "Add missing size check when parsing staged aliases" into sc-v2-dev am: 067e59bbf6
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16371987

Change-Id: I3b6895218f9b6b0d2a83a4bf94881cd1fb588758
2021-12-07 20:06:12 +00:00
TreeHugger Robot
067e59bbf6 Merge "Add missing size check when parsing staged aliases" into sc-v2-dev 2021-12-07 19:45:44 +00:00
TreeHugger Robot
9bd21329dd Merge "Fix segfault with sparse encoding" into sc-v2-dev am: 829f7d5ebf
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16378785

Change-Id: Ia19e4bc608b97718bb61c474b091103412788545
2021-12-03 21:39:38 +00:00
Jason O'Brien
74f78adb63 Fix segfault with sparse encoding
The native code that underlies `Resources#getIdentifier()` did not take
sparse encoding into account when calculating offsets, resulting in
either garbage or SEGV_MAPERR whenever a resource is first encountered
in a sparsely encoded configuration.

Bug: 197976367
Test: atest libandroidfw_tests --host
Change-Id: Ib7550fe2e05005550f59129a06be5712b74bc9c8
(cherry picked from commit 984e897303)
2021-12-02 14:59:52 +00:00
TreeHugger Robot
32cb668a40 Merge "Fix segfault with sparse encoding" 2021-12-02 11:01:15 +00:00
Yurii Zubrytskyi
85b3e879f8 Add missing size check when parsing staged aliases
Need to have the same kind of data size check as in other
types parsing

Bug: 203938029
Test: manual
Change-Id: I9f5d2851ff59da90163ead6c0416f0bba3868cc4
Merged-In: I9f5d2851ff59da90163ead6c0416f0bba3868cc4
(cherry picked from commit 8002034e6b)
2021-12-01 17:18:08 +00:00
Yurii Zubrytskyi
abdf5a518d Add missing size check when parsing staged aliases
Need to have the same kind of data size check as in other
types parsing

Bug: 203938029
Test: manual
Change-Id: I9f5d2851ff59da90163ead6c0416f0bba3868cc4
Merged-In: I9f5d2851ff59da90163ead6c0416f0bba3868cc4
(cherry picked from commit 8002034e6b)
2021-12-01 17:17:07 +00:00