summaryrefslogtreecommitdiff
path: root/libs/androidfw/ApkAssets.cpp
AgeCommit message (Collapse)Author
2020-12-08Revert^2 "libandroidfw hardening for IncFs"Ryan Mitchell
55ef6167a2c235bd88c7216238b2001b46795b79 Change-Id: I02d4890d181655dfd0a14c188468db512559d27b Merged-In: I02d4890d181655dfd0a14c188468db512559d27b
2020-05-28Avoid Asset::LoadImpl crash when getBuffer is nullRyan Mitchell
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-04-07Invalidate idmap when target updatesRyan Mitchell
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-03-19Allow using loaders on non-RM Resources instancesRyan Mitchell
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-19Move AssetsProvider to native layerRyan Mitchell
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-19Add ResourcesProvider.loadFromDirectoryRyan Mitchell
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-19Refactor ApkAsset loading APIsRyan Mitchell
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-19Fix bugprone-use-after-move warningsRyan Mitchell
Bug: 150783499 Test: WITH_TIDY=1 make Change-Id: I185cb21521676ddbc4f2b7f098611a2efc7275e6 (cherry picked from commit c658184d366ee08cedd9ec208ea327530b52bfad) Merged-In: I185cb21521676ddbc4f2b7f098611a2efc7275e6
2019-11-13Do not look for R.class of overlaysRyan Mitchell
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-10-17Allow for RRO internal referencingRyan Mitchell
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-10Add ResourceLoader API with .apk and .arsc supportWinson
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-08-28[base] close zip archive when parsing failsSongchun Fan
Test: manual Change-Id: I54c054da6000df15dba81ad211eb1cf61e88c5a8
2019-06-17Merge "Move off ZipString and over to std::string/std::string_view as ↵Elliott Hughes
appropriate." into qt-dev-plus-aosp am: ee1c95f060 am: 0566225cb8 Change-Id: I351ea009ee322ecd8bd117e4b2b686c636fb6770
2019-06-17Move off ZipString and over to std::string/std::string_view as appropriate.Elliott Hughes
Bug: http://b/129068177 Test: treehugger Change-Id: Ib46761d89772d3a3c655a39df573fd305c117d19
2019-06-13Suppress compressed rersources.arsc on hostRyan Mitchell
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-05-09Merge "Track libziparchive API change." am: 71e79a2396Elliott Hughes
am: b17db5960e Change-Id: I07b669391eb8030bd09529f224fefefe73a6d1f5
2019-05-08Track libziparchive API change.Elliott Hughes
Bug: http://b/129068177 Test: treehugger Change-Id: Id4b202502b07e08102deda49f7d28ba10a63bb0a
2019-05-06Merge "Track libziparchive API change." am: 32581e1dd2Elliott Hughes
am: 78791cd8d7 Change-Id: Id4ac5019e267fbd0a32a41437e92c3f802e334e8
2019-05-03Track libziparchive API change.Elliott Hughes
Bug: http://b/129068177 Test: treehugger Change-Id: I88f49a06db416a7c6ec8afe87cc9cca825eb5ccb
2019-03-29Fix AssetManager2 isUpToDate checkWinson
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
2018-10-15Change ZipArchiveHandle from void* to ZipArchive*Ryan Prichard
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-02-28Refactor AssetManagerAdam Lesinski
Bug: 64071469 Test: atest CtsContentTestCases Change-Id: Ia6856157e8813856268fba003e1e591d690cb26e
2018-02-09Revert "AssetManager2: Fix list function"Adam Lesinski
This reverts commit adc0b87ec235a71d722fb8d6aad50ceaeac8c6d5. Bug:73134570 Change-Id: I9e652245e7661eb7a34dadb5f363a08bc8c9e57e
2018-02-08AssetManager2: Fix list functionAdam Lesinski
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
2017-11-13libandroidfw: Support loading ApkAssets from a file descriptorAdam Lesinski
Test: make aapt2_tests Change-Id: I041f9e9e3d3f6a10684cbd8baa49f4dda7d6dc40
2017-10-13AssetManager2: Implement IDMAP supportAdam Lesinski
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-09-25A few fixes to AssetManager2 for compatAdam Lesinski
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-02-15AssetManager2: Various fixesAdam Lesinski
- 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-01-31AssetManager2: Add other support methodsAdam Lesinski
- 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-11libandroidfw: Add new support for shared librariesAdam Lesinski
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-11New implementation of AssetManager/ResTableAdam Lesinski
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