Commit Graph

30 Commits

Author SHA1 Message Date
Ryan Mitchell
d338dfe583 Avoid Asset::LoadImpl crash when getBuffer is null
If for some reason Asset::getBuffer returns a null pointer, error out
instead of dereferencing the null pointer.

Bug: 125943266
Bug: 154461471

Test: boots
Change-Id: I957be4f9b8c49c2a6829e8b82fae0ae8d8d7639e
2020-05-28 14:03:27 -07:00
Ryan Mitchell
a90930528d Invalidate idmap when target updates
When the target package update, check if the idmap file must change.
If so, propagate the idmap changes to the targets overlay paths, and
invalidate cached overlay ApkAssets in ResourcesManager.

Bug: 147794117
Bug: 150877400
Test: OverlayRemountedTest
Test: libandroidfw_tests
Change-Id: I6115c30bae3672b188a5ff270720a0eea15b43b5
2020-04-07 12:14:51 -07:00
Ryan Mitchell
39cacf2de7 Allow using loaders on non-RM Resources instances
Currently there is a limitation where ResourcesLoaders cannot be  used
on Resources object not created through ResourcesManager. This change
creates an update handler for Resources objects that are not registered
with ResourcesManager.

The handler changes the loaders on the asset manager owned by the
Resources instance.

Bug: 151666644
Test: atest ResourceLoaderValuesTest
Change-Id: I5a89f686386bdb088dc964014e7becc0c2b4770f
2020-03-19 18:33:55 -07:00
Ryan Mitchell
4ea1e42889 Move AssetsProvider to native layer
Querying in the native layer for assets provided through
AssetsProviders does not currently work. This change refactors the
AssetProvider API to return a file descriptor that is read in the
native layer and can bubble up to the java layer.

This change also removes the InputStream API to favor of developers
using memfd_create.

Bug: 142716192
Test: atest ResourceLoaderValuesTest
Change-Id: I1a7eca0994c3b7cc32008d9a72bf91086ff0e816
2020-03-19 18:33:55 -07:00
Ryan Mitchell
c07aa70270 Add ResourcesProvider.loadFromDirectory
This API allows a directory to be loaded as if it was a zipped APK.
This is a substitute for the DirectoryAssetProvider API that
currently does not work in the native layer.

Bug: 142716192
Test: atest FrameworksResourceLoaderTests
Change-Id: Ia13e15653e75b421423dd56f9fe89e183ab4cb9a
2020-03-19 18:33:55 -07:00
Ryan Mitchell
ef40d2e832 Refactor ApkAsset loading APIs
To add the partner requested ResourcesProvider#loadFromDir APIs, this
change adds format type integer that allows us to reduce the number of
ApkAssets loading overrides.

This change also adds hidden offset and length based ResourcesProvider
APIs that could not make R.

Bug: 142716192
Test: atest FrameworksResourceLoaderTests
Change-Id: I926fde257cae701901dcd4ca408024feae8c90a6
Merged-In: I926fde257cae701901dcd4ca408024feae8c90a6
2020-03-19 18:33:55 -07:00
Ryan Mitchell
e35e87f514 Fix bugprone-use-after-move warnings
Bug: 150783499
Test: WITH_TIDY=1 make
Change-Id: I185cb21521676ddbc4f2b7f098611a2efc7275e6
(cherry picked from commit c658184d36)
Merged-In: I185cb21521676ddbc4f2b7f098611a2efc7275e6
2020-03-19 16:57:50 -07: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
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
Songchun Fan
898b316402 [base] close zip archive when parsing fails
Test: manual
Change-Id: I54c054da6000df15dba81ad211eb1cf61e88c5a8
2019-08-28 12:52:27 -07: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
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
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
Elliott Hughes
e94bde383b Merge "Track libziparchive API change." am: 71e79a2396
am: b17db5960e

Change-Id: I07b669391eb8030bd09529f224fefefe73a6d1f5
2019-05-09 16:29:49 -07:00
Elliott Hughes
7a6cc0c006 Track libziparchive API change.
Bug: http://b/129068177
Test: treehugger
Change-Id: Id4b202502b07e08102deda49f7d28ba10a63bb0a
2019-05-08 12:29:25 -07:00
Elliott Hughes
dfe3d688fc Merge "Track libziparchive API change." am: 32581e1dd2
am: 78791cd8d7

Change-Id: Id4ac5019e267fbd0a32a41437e92c3f802e334e8
2019-05-06 17:45:35 -07:00
Elliott Hughes
b97e737c18 Track libziparchive API change.
Bug: http://b/129068177
Test: treehugger
Change-Id: I88f49a06db416a7c6ec8afe87cc9cca825eb5ccb
2019-05-03 22:42:31 -07:00
Winson
b0085ce5b6 Fix AssetManager2 isUpToDate check
This logic was lost in the AssetManager1 -> 2 migration.

The old AM1 checked the last modification time of the file
and compared it to a previously stored value. This re-adds the
logic to ApkAssets and fixes the checks in the JNI/Java layer.

Unfortunately I couldn't find a failing/practical case where
this check mattered. It only came up when diagnosing an issue
which ended up being unrelated.

Test: manually ran with other overlay changes

Change-Id: I758e4af1d32a9c03b2204a8a3a26e82b7e83feda
2019-03-29 12:18:18 -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
Adam Lesinski
bebfcc46a2 Refactor AssetManager
Bug: 64071469
Test: atest CtsContentTestCases
Change-Id: Ia6856157e8813856268fba003e1e591d690cb26e
2018-02-28 19:06:48 -08:00
Adam Lesinski
ec7f06cc37 Revert "AssetManager2: Fix list function"
This reverts commit adc0b87ec2.

Bug:73134570
Change-Id: I9e652245e7661eb7a34dadb5f363a08bc8c9e57e
2018-02-09 12:43:04 -08: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
441500b23f libandroidfw: Support loading ApkAssets from a file descriptor
Test: make aapt2_tests
Change-Id: I041f9e9e3d3f6a10684cbd8baa49f4dda7d6dc40
2017-11-13 17:53:45 -08:00
Adam Lesinski
970bd8d283 AssetManager2: Implement IDMAP support
This enables RRO (runtime resource overlays) with AssetManager2

Test: make libandroidfw_tests
Test: out/host/<platform>/nativetest64/libandroidfw_tests/libandroidfw_tests --testdata=frameworks/base/libs/androidfw/tests/data
Change-Id: Id8079104faefbfaa3f4017d8f7ee1a8968f151a2
2017-10-13 10:23:34 -07:00
Adam Lesinski
03ebac8c68 A few fixes to AssetManager2 for compat
Theme copying should behave the way it did with the old AssetManager
(copy only the framework attributes when copying from a Theme object
from a different AssetManager).

Cleanup the dependencies on libziparchive in ApkAssets.

Test: make libandroidfw_tests
Test: out/host/<platform>/nativetests64/libandroidfw_tests/libandroidfw_tests --testdata=frameworks/base/libs/androidfw/tests/data
Change-Id: I973f7e6eb14ce311306e2ec66a623a4790c8d233
2017-09-25 18:24:41 -07:00
Adam Lesinski
d1ecd7af68 AssetManager2: Various fixes
- Use FileMaps to open Assets (prevents closing of ApkAssets underlying
zip)
- Implement OpenDir and List methods
- Fix issue where DynamicRefTable wasn't properly constructed

Test: make libandroidfw_tests
Change-Id: Ib21a84e1114d028120744aa3bc1c6eb9d9399fa8
2017-02-15 10:50:23 -08:00
Adam Lesinski
0c40524953 AssetManager2: Add other support methods
- Add GetResourceConfigurations()
- Add GetResourceLocales()
- Add ResolveReference()
- Add stub for GetResourceId()
- Change LoadedArsc and ApkAssets factory method to return const

Test: make libandroidfw_tests
Change-Id: Ia797dc9381a523b1a3e7029048a413e544730379
2017-01-31 16:20:29 -08:00
Adam Lesinski
da431a22da libandroidfw: Add new support for shared libraries
This adds support for shared resource libraries in the new
ResTable/AssetManager implementation.

The dynamic package map encoded in resources.arsc is parsed
and stored with LoadedArsc, and combined to form a resolved table
in AssetManager2.

Benchmarks show that this implementation is an order of magnitude
faster on angler-userdebug (make libandroidfw_benchmarks).

Test: libandroidfw_tests
Change-Id: I57c80248728b63b162bf8269ac9495b53c3e7fa0
2017-01-11 17:20:36 -08:00
Adam Lesinski
7ad1110ecd New implementation of AssetManager/ResTable
The multiwindow model and Resources-per-activity
model that came in N puts greater demands on AssetManagers.
They are created whenever window dimensions change, which
can be frequently. There is a need to be able to cheaply
create a new AssetManager for each Activity, which shares
a lot of underlying state.

In order to make the creation of AssetManagers cheap,
we need a new implementation of the native AssetManager
and ResTable to support immutable representations of
APKs. This new data structure/class is ApkAssets.

ApkAssets have the same functionality of an AssetManager, except
that they operate on a single APK, and they do not do any caching.
Once loaded, they are immutable.

ApkAssets will be exposed as a Java object, with its implementation in
native code. The existing Java StringBlock will be owned by ApkAssets,
which means that Strings can be shared across AssetManagers.

ApkAssets can be cached by the ResourcesManager. Creating an AssetManager
requires only a list of ApkAssets and a configuration.

AssetManager2 (named with the suffix '2' for now while transitioning
to the new implementation) caches bags that are accessed.

Since ApkAssets are expected to be kept around longer, they do more validation
of the resource table, which cause slower load times. Measured on an angler-userdebug,
loading the framework assets takes 11ms with ApkAssets, and 2ms with the old
AssetManager implementation.

The tradeoff is that there does not need to be any security checks once an ApkAssets
is loaded, and regular resource retrieval is faster. Measured on an angler-userdebug,
accessing resource (android:string/ok) with many locales takes 18us with AssetManager2,
and 19us with AssetManager (this is per resource, so these add up).

Test: make libandroidfw_tests
Change-Id: Id0e57ee828f17008891fe3741935a9be8830b01d
2017-01-11 13:30:57 -08:00