summaryrefslogtreecommitdiff
path: root/libs/androidfw/tests/AssetManager2_test.cpp
AgeCommit message (Collapse)Author
2021-05-13Set ApkAssets path for fabricated rrosRyan Mitchell
Fabricated RROs do not provide assets but are stored on disk. Ensure that the path to the frro is returned when querying for the ApkAssets path (which is mostly for debug purposes). Bug: 181338216 Test: enable frro, use cmd overlay lookup to see path in resolution Change-Id: Ibf9b1bf0a995325affbf084c71b1e87c5682e734
2021-01-13Optimize FilterApkAssets by caching configRyan Mitchell
ResTable_config of every ResTable_type is read from device every time AssetManager::RebuildFilterList is invoked. For large APKs (like framework-res.apk), this causes a large number of page faults when accessing the config from disk. The configs are also used in the slow path of AssetManager::FindEntryInternal, which makes it even slower. Instead cache the config on the TypeSpec of its ApkAsset. Bug: 177247024 Test: libandroidfw_tests Change-Id: I66d507c4eeb2399f7558f3d9dfc53c157129ada0
2020-11-17Revert^2 "Cache resolved theme values"Ryan Mitchell
6ca48473e533a8b89abac6294a0bb8130b8c8c89 Change-Id: Icb295186b85e1edcdcebc1d746f7ff0d6ef66829
2020-11-17Set resource id correctly when resolve failsRyan Mitchell
If for some reason the resource id cannot be resolved to a value (there is no configuration that matches the AssetManager configuration or some error occurs), set the resource id of the SelectedValue to the resource id that could not be resolved. This was the behavior before the AssetManager IncFs hardening refactor. Bug: 173203252 Test: atest com.google.android.config.pts.PreinstalledAppsTestCase Test: Chrome icon appears on launcher Change-Id: Iad1760c0e246da1a4bf64d1c2ec60bb08da32d06
2020-11-17Revert^2 "libandroidfw hardening for IncFs"Ryan Mitchell
55ef6167a2c235bd88c7216238b2001b46795b79 Change-Id: I02d4890d181655dfd0a14c188468db512559d27b
2020-11-13Revert "libandroidfw hardening for IncFs"Ryan Mitchell
Revert "Move map_ptr to incfs namspace" Revert submission 12787270 Reason for revert: b/173250495 Reverted Changes: I5cd1bc8a2:libandroidfw hardening for IncFs Ice5dbcfb2:Move map_ptr to incfs namspace I29ccdc8ed:Do not cache bag parent stack until requested I1e9e9acaa:Cache resolved theme values Change-Id: Ib90ef68339710086df41e9abe0833a542d03a74f
2020-11-12libandroidfw hardening for IncFsRyan Mitchell
Migrate libandroifw to using incfs::util::map_ptr to prevent processes from crashing when parsing the resources.arsc, parsing compiled xml, files, and retrieving resource values. This change propagates incremental failures to the JNI level where they are raised as ResourcesNotFoundException. Performance of ResourcesPerfWorkloads without change (time in nanoseconds): [1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.883s) youtube_ns_median: 93812805 youtube_ns_standardDeviation: 4387062 youtube_ns_mean: 94455597 [2/3] com.android.resources.perf.PerfTest#maps: PASSED (11.265s) maps_ns_standardDeviation: 2997543 maps_ns_mean: 83480371 maps_ns_median: 82210941 [3/3] com.android.resources.perf.PerfTest#gmail: PASSED (24.963s) gmail_ns_median: 266141091 gmail_ns_standardDeviation: 3492043 gmail_ns_mean: 267472765 With change and verification forcibly enabled for all apks (including the framework-res.apk): [1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.646s) youtube_ns_median: 101999396 youtube_ns_standardDeviation: 4625782 youtube_ns_mean: 102631770 [2/3] com.android.resources.perf.PerfTest#maps: PASSED (11.286s) maps_ns_standardDeviation: 2692088 maps_ns_mean: 91326538 maps_ns_median: 90519884 [3/3] com.android.resources.perf.PerfTest#gmail: PASSED (24.694s) gmail_ns_median: 290284442 gmail_ns_standardDeviation: 5764632 gmail_ns_mean: 291660464 With change and verification disabled: [1/3] com.android.resources.perf.PerfTest#youtube: PASSED (11.748s) youtube_ns_median: 95490747 youtube_ns_standardDeviation: 7282249 youtube_ns_mean: 98442515 [2/3] com.android.resources.perf.PerfTest#maps: PASSED (10.862s) maps_ns_standardDeviation: 4484213 maps_ns_mean: 87912988 maps_ns_median: 86325549 [3/3] com.android.resources.perf.PerfTest#gmail: PASSED (24.034s) gmail_ns_median: 282175838 gmail_ns_standardDeviation: 6560876 gmail_ns_mean: 282869146 These tests were done on a Pixel 3 and with cpu settings configured by libs/hwui/tests/scripts/prep_generic.sh: Locked CPUs 4,5,6,7 to 1459200 / 2803200 KHz Disabled CPUs 0,1,2,3 Bug: 160635104 Bug: 169423204 Test: boot device && atest ResourcesPerfWorkloads Change-Id: I5cd1bc8a2257bffaba6ca4a1c96f4e6640106866
2020-03-23Assigned package ids to overlays lastRyan Mitchell
Before overlays could reference internal resources, overlays were added to AssetManagers before shared libraries. Overlays are now loaded as shared libraries so they must be assigned package ids after non-overlay shared libraries so enabling and disabling overlays does not affect the package ids of the non-overlay shared libraries. Since overlays are added to the end of the AssetManager by ResourcesManager, enabling and disabling overlays will not change the assets cookie of shared libraries loaded through ResourcesManager, but it will change the apk assets cookie or overlays added through AssetManager#addAssetPathAsSharedLibrary. The package ids of shared libraries added through AssetManager#addAssetPathAsSharedLibrary will not be affected by overlays since overlay package ids are assigned last. Bug: 146685730 Test: CtsHostsideWebViewTests Change-Id: If7ea17d51b18769bf2465e29af3ae6a71004d06c
2020-03-23Revert "Assign shared libraries stable package ids"Ryan Mitchell
This change must be reverted because it broke packages with the same package name but different package ids loaded at once. Bug: 146685730 Test: MultiSplitInstallTest This reverts commit fe50d739f75e13ebf64c010bf6ef504bcc81d860. Change-Id: If6364fd660c76284452f77e7d4f09a3df9dede1d
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-02-10Sort bag by attribute key when using libsRyan Mitchell
When shared libraries are assigned package ids in a different order than compile order, bag resources that use attributes from both multiple libraries will not be sorted in ascending attribute id order. This change detects when the attribute ids are not in order and sorts the bag entries accordingly. The change is designed to be less invasive. Deduping the GetBag logic should probably be spun off in a separate bug. Bug: 147674078 Test: libandroidfw_tests Change-Id: Id8ce8e9c7ef294fcc312b77468136067d392dbd0
2020-01-10Assign shared libraries stable package idsRyan Mitchell
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
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-09-26Enable CTS verification of overlayable APIRyan Mitchell
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-02-07Surface <overlayable> info in Java AssetManagerMÃ¥rten Kongstad
Add a new, hidden method to AssetManager to extract a mapping overlayable name -> overlayable actor for all <overlayable> blocks in a package. [This will eventually be used to check if the caller of the OMS AIDL API is the registered actor for a given overlay.] Also, teach AssetManager2 to not accept packages that re-use the same overlayable name. [Such packages have always been ill-formed.] Bug: 123894537 Test: make libandroidfw_tests Change-Id: I1117fd3503f04fe4c73eb7114901e022508f4d9e
2019-01-24Fix GetResourceName for shared librariesRyan Mitchell
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-14Add function to return path for last resolved resourceWinson
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
2018-11-16Add style value to ResolvedBag in AssetManager2.Aurimas Liutikas
Bug: 117176857 Test: updated AssetManager2Test.MergesStylesWithParentFromSingleApkAssets Change-Id: I2b79eea8e43431a932756b267b91eb4423c968a5
2018-04-18AAPT2: Support id reference chaining from AAPTy
AAPT would allow for ids to be declared in the form: <item name="name" type="id>@id/other</item> @id/name should hold a reference to @id/other. When getResources().getValue() is called on R.id.name with resolveRefs enabled, the resuling reference should be R.id.other. Bug: 69445910 Test: Created tests for correct parsing of id references and correct resolving of deep references Change-Id: Id1feb37b2565c213dc6a19b4c401906260d7fc14
2018-04-13AAPT2: GetBag infinite recursion fixy
Style resources with circular parental dependencies caused infinite recursion when calling AssetManager2::GetBag. This fix allows recursion to cease when a circular dependency is found. Bug: 77928512 Change-Id: Ib900c36ab1aef5da5b03234a9484c4dad3b63c02 Test: Manual test of b/77928512 and duplicates of 74493983
2018-02-28Refactor AssetManagerAdam Lesinski
Bug: 64071469 Test: atest CtsContentTestCases Change-Id: Ia6856157e8813856268fba003e1e591d690cb26e
2018-02-09Revert "libandroidfw: Make sure to set the 'app as lib' flag"Adam Lesinski
This reverts commit 9ad287c828a116f844e5c03346c618d83727e4ae. Bug: 73134570 Change-Id: If930d3a7c17fc2f7ffaebd31281ad5a5d120144f
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
2018-02-05libandroidfw: Make sure to set the 'app as lib' flagAdam Lesinski
When an app is loaded as a shared library (eg. monochrome), make sure to set the bit that it loaded as such, so that conversions from package ID 7f -> shared library ID are done. Bug: 72511998 Test: make libandroidfw_tests Test: out/host/<host_os>/nativetest64/libandroidfw_tests/libandroidfw_tests Change-Id: Icd11b7a5adff351165ca16d5853fb5a0002c34b1
2017-12-05libandroidfw: Remove pre-verificationAdam Lesinski
This added more up-front cost to loading an APK and didn't provide a significant benefit to resource retrieval. Test: make libandroidfw_tests Change-Id: Idbf993abc433fa8c8950d106c66469b310b66f7f
2017-11-29libandroidfw: Do not clear last resource id in ResolveReferenceAdam Lesinski
If the value passed to AssetManager::ResolveReference is not a reference, the caller may be expecting for the last reference to not be cleared, as a more appropriate value should most likely be retained. This was causing an issue when a caller was manually resolving references and expecting the last resource ID resolved to be propagated across calls to ResolveReference. Test: make libandroidfw_tests Change-Id: I5b7f586e2cd541059023eaa9ba23e324a21a9a1e
2017-10-17AssetManager2: Run ApkAssets that have failed verificationAdam Lesinski
ApkAssets who have failed verification should still run for compatibility. Not all resources are accessed, and therefore errors in the APK are not necessarily fatal. However, this means we must do bounds checks when retrieving resources, which is slower. Test: make libandroidfw_tests && $ANDROID_BUILD_TOP/out/host/<host>/nativetest64/libandroidfw_tests/libandroidfw_tests Test: make libandroidfw_benchmarks && adb sync system && adb sync data && /data/benchmarktest64/libandroidfw_benchmarks/libandroidfw_benchmarks Change-Id: I4cc926c064bca0491785d82cdac0419d74d7d9b0
2017-05-11Fix support for @empty in style resolutionAdam Lesinski
If @empty is encountered in XML, do not fallback to searching through the theme. Bug: 36891052 Test: make aapt2_tests Test: bit CtsContentTestCases:android.content.res.cts.TypedArrayTest Change-Id: Ie3bf7b70af9c7913513a1092afd95d26bec5e635
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-02-08AssetManager2: Add GetResourceIdAdam Lesinski
Add ability to lookup a resource by name. Test: make libandroidfw_tests Change-Id: I262ba5ce4c9892458226fbdb44cf21f9877fb92d
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