静态Overlay 只对有源代码的apk起作用,可以修改与增加一般apk资源,对frameworks 资源只能修改,无法新增。
1. Android平台Overlay机制
Android overlay 机制允许在不修改packages中apk的情况下,来自定义 framework和package中的资源文件,实现资源的定制。来达到显示不同的UI得目的(如MIUI)。
以下几类能够通过该机制定义:
(1),Configurations (string, bool, bool-array)
(2),Localization (string, string-array)
(3),UI Appearance (color, drawable, layout, style, theme, animation)
(4),Raw resources (audio, video, xml)
2. 为产品添加overlay目录
有两种不同的overaly目录定义,来影响最终的效果:
PRODUCT_PACKAGE_OVERLAYS: 用于特定的产品
DEVICE_PACKAGE_OVERLAYS: 多种产品共用
如果这两个目录下包含同一资源,那么 PRODUCT_PACKAGE_OVERLAYS 将覆盖 DEVICE_PACKAGE_OVERLAYS 中的
1. 以Settings apk为例子
Android.mk 中资源目录为
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res \
frameworks/support/v7/preference/res \
frameworks/support/v14/preference/res \
frameworks/support/v7/appcompat/res \
frameworks/support/v7/recyclerview/res
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/res_ext
所以LOCAL_RESOURCE_DIR 下的内容均可以定制。
现在要定制一下布局
packages\apps\Settings\res\drawable\appwidget_button_center.xml
1:创建overlay 目录
vendor/transsion/device/S31N/overlay/packages/apps/Settings/res/drawable
2:将对应定制布局appwidget_button_center.xml放入对应overlay目录即可
现在要定制packages\apps\Settings\res\values\strings.xml 下字符串
将<string name="sim_card_2_ringtone">SIM2 ringtone</string> 定制为ovelay SIM2 ringtone
增加<string name="sim_card_2_new">new add</string>
1:创建overlay目录
vendor/transsion/device/S31N/overlay/packages/apps/Settings/res/values
2:创建strings.xml文件并添加一下内容
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="sim_card_2_ringtone">"ovelay SIM2 ringtone"</string>
<string name="sim_card_2_new">"new add"</string>
</resources>
动态overlay能够定制第三方apk
以settings apk 为例子
Android.mk 文件
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
#include files in res diretory
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_SDK_VERSION = current
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
#the name of target apk
LOCAL_PACKAGE_NAME := SettingsOverlay
include $(BUILD_PACKAGE)
AndroidManifest.xml 文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.settings.overlay" >
<overlay
android:priority="1"
android:targetPackage="com.android.settings" />
</manifest>
第三方apk 编译脚本
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Module name should match apk name to be installed
LOCAL_MODULE := BoomPlayer
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
#LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := platform
#LOCAL_MODULE_PATH := $(TARGET_OUT)/vendor/operator/app
include $(BUILD_PREBUILT)
在overlay apk下定制,只需要保证 资源id 名字与三方apk 名字一样即可,并将编译生成的overlay apk push 到手机/vendor/overlay 或/system//vendor/overlay 下,
LOCAL_CERTIFICATE := platform 签名需要一致。
https://gerrit.omnirom.org/#/q/project:android_frameworks_base+branch:android-5.0+topic:rro
https://android-review.googlesource.com/#/q/I3d678921f642fe00dd9580bcb5828789c1b1c915