Android overlays - sharmasadhna/mylearnings GitHub Wiki
The Android build system uses resource overlays to customize a product at build time. Resource overlays specify resource files that are applied on top of the defaults.
Sometimes you don’t actually want to add an application but would rather modify existing ones included by default in the AOSP.
That’s where overlays can be useful. Overlays are a mechanism included in the AOSP to allow device manufacturers to change the resources provided (such as for apps), without actually modifying the original resources included in the AOSP.
The customizable recourses fall into the following categories:
• Configurations (string, bool, bool-array)
• Localization (string, string-array)
• UI Appearance (color, drawable, layout, style, theme, animation)
• Raw resources (audio, video, xml)
For detailed introduction on Android application resources, please refer to: http://developer.android.com/guide/topics/resources/available-resources.html To use the overlay capability, you must create an overlay tree and tell the build system about it. The easiest location for an overlay is within a device-specific directory such as the one defined in below sections
To add an overlay directory to a product, change the product configuration makefile (for example: device/advantech/dltv72/dlt.mk) to add the following lines:
PRODUCT_PACKAGE_OVERLAYS := device/advantech/dltv72/overlay
or:
DEVICE_PACKAGE_OVERLAYS := device/advantech/dltv72/overlay
There are two types of overlay directories that affect a product:
• PRODUCT_PACKAGE_OVERLAYS: used by a particular product
• DEVICE_PACKAGE_OVERLAYS: used several products that share a common device model
The PRODUCT_PACKAGE_OVERLAYS will override the DEVICE_PACKAGE_OVERLAYS if they contain same resources
To use resource overlays, modify the project buildfile to set PRODUCT_PACKAGE_OVERLAYS or DEVICE_PACKAGE_OVERLAYS to a path relative to your top-level directory.
For example, to setup overlay for below file :
frameworks/base/core/res/res/values/config.xml
we created the file device/advantech/dltv72/overlay/frameworks/base/core/res/res/values/config.xml
and modified "<integername="config_longPressOnPowerBehavior">2</integer>"
,to redefine longPressOnPowerBehavior
for our device.
Note that:
• For color, bool, string, array, style/theme types, the resource values are identifed by their keys, so for these types, there is no need to put the resources in a file with the same name as in the original base package.
• For layout, animation, picture drawables and raw types, the resources are indentifed by their file name, and overlay for these resources should keep the file name same as in the base packages.
For more details on overlays check below links:
• https://source.android.com/setup/develop/new-device#use-resource-overlays
• https://mmmyddd.github.io/wiki/android/overlay.html
Q: Why we didn't use overlay mechanism to implement custom bootanimation?
Ans: The overlays can be implemented only when resources are referenced in the source files from their resource id's, For ex: we can use overlay to override values in audio_assets.xml and config_longPressOnPowerBehavior, because in the source code they are referred dynamically through their resource files mContext.getResources().getXml(com.android.internal.R.xml.audio_assets) or mContext.getResources().getInteger(com.android.internal.R.integer.config_longPressOnPowerBehavior); But in case of default android bootanimation, the source code frameworks/base/cmds/bootanimation/Bootanimation.cpp refers the default bootanimation images frameworks/base/core/res/assets/images/android-logo-mask.png and frameworks/base/core/res/assets/images/android-logo-shine.png their names and not from their resource id's. Because of this, overlay mechanism do not apply for customizing bootanimation. Instead we can create our own bootanimation.zip and place it in system/media/. More on customizing bootanimation can be found at https://android.googlesource.com/platform/frameworks/base/+/master/cmds/bootanimation/FORMAT.md