Android RRO动态加载资源
在 Android 8.0 的时候,Android 项目可以动态的加载资源而可以不用再overlay 中去静态处理,这样就可以方便的对 Android 资源进行处理了。
例如:
1. -- Android.mkLOCAL_PATH := $(call my-dir)
$(warning mike LOCAL_PATH = $(LOCAL_PATH))include $(CLEAR_VARS)LOCAL_RESOURCE_DIR := \$(LOCAL_PATH)/res \$(warning mike LOCAL_RESOURCE_DIR = $(LOCAL_RESOURCE_DIR))
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/overlay
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_SDK_VERSION := current
# 用于当前目录的命名
LOCAL_PACKAGE_NAME := LauncherOverlay
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_MANIFEST_FILE := AndroidManifest.xml
include $(BUILD_PACKAGE)2. -- AndroidManifest.xml<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.android.launcher3overlay"><overlay android:targetPackage="com.android.launcher3" android:priority="1" android:isStatic="true"/>
</manifest>3. 直接在 res 中添加对应的资源。编译完成后,会生成一个 apk。
动态加载资源 RRO 具体实现在 com.android.server.om
,看看官方给的表述
用于管理 asset overlay 的服务。Asset overlays 来自于系统和 app apks 加载的额外资源。这个服务(OMS), 跟踪已经被安装了要使用的 overlay,提供了更改此资源的方法。在 Activity 的运行生命周期中,对正在运行的应用去更改它的资源。允许应用重新读取 overlay 的资源。OMS本身不会改变 overlay。相反,它只负责确保在技术和安全的角度,overlays 可以在外部的请求下被激活。在组件中这种打开或关闭 overlay 的方式能在不同的用例中被使用,如 主题或者是动态定制。
OMS从三个来源接收信息:
- 从 SystemService 类回调,特别是当 Android 框架正在启动以及最终用户切换 Android 用户时。
- 来至 PMS 的 Intent。Overlay 是一个常规的 apk,无论这个应用被安装,卸载等操作时,PMS 都会通过发送广播意图。当 OMS 接收到这些意图时,OMS 更新可用 overlay 的内部表示。如果这是一个可见的改变,将在受影响的 apk 中重新触发 asset 的更新。
- 通过 @link ioverlaymanager aidl 接口的外部请求。这个接口允许客户机去读取关于当前可用 overlay 的信息,更新一个 overlay 或者是相关的 order。如果请求的目标是与调用者运行相同的Android用户,或者调用者拥有“跨用户交互”的完全权限,则授予读取访问权限。如果调用方被授予读访问权限,并且另外还拥有更改覆盖包权限,则授予写访问权限。
英语不好,附上英语表述
/*** Service to manage asset overlays.** <p>Asset overlays are additional resources that come from apks loaded* alongside the system and app apks. This service, the OverlayManagerService* (OMS), tracks which installed overlays to use and provides methods to change* this. Changes propagate to running applications as part of the Activity* lifecycle. This allows Activities to reread their resources at a well* defined point.</p>** <p>By itself, the OMS will not change what overlays should be active.* Instead, it is only responsible for making sure that overlays *can* be used* from a technical and security point of view and to activate overlays in* response to external requests. The responsibility to toggle overlays on and* off lies within components that implement different use-cases such as themes* or dynamic customization.</p>** <p>The OMS receives input from three sources:</p>** <ul>* <li>Callbacks from the SystemService class, specifically when the* Android framework is booting and when the end user switches Android* users.</li>** <li>Intents from the PackageManagerService (PMS). Overlays are regular* apks, and whenever a package is installed (or removed, or has a* component enabled or disabled), the PMS broadcasts this as an intent.* When the OMS receives one of these intents, it updates its internal* representation of the available overlays and, if there was a visible* change, triggers an asset refresh in the affected apps.</li>** <li>External requests via the {@link IOverlayManager AIDL interface}.* The interface allows clients to read information about the currently* available overlays, change whether an overlay should be used or not, and* change the relative order in which overlay packages are loaded.* Read-access is granted if the request targets the same Android user as* the caller runs as, or if the caller holds the* INTERACT_ACROSS_USERS_FULL permission. Write-access is granted if the* caller is granted read-access and additionaly holds the* CHANGE_OVERLAY_PACKAGES permission.</li>* </ul>** <p>The AIDL interface works with String package names, int user IDs, and* {@link OverlayInfo} objects. OverlayInfo instances are used to track a* specific pair of target and overlay packages and include information such as* the current state of the overlay. OverlayInfo objects are immutable.</p>** <p>Internally, OverlayInfo objects are maintained by the* OverlayManagerSettings class. The OMS and its helper classes are notified of* changes to the settings by the OverlayManagerSettings.ChangeListener* callback interface. The file /data/system/overlays.xml is used to persist* the settings.</p>** <p>Creation and deletion of idmap files are handled by the IdmapManager* class.</p>** <p>The following is an overview of OMS and its related classes. Note how box* (2) does the heavy lifting, box (1) interacts with the Android framework,* and box (3) replaces box (1) during unit testing.</p>** <pre>* Android framework* | ^* . . . | . . . . | . . . .* . | | .* . AIDL, broadcasts .* . intents | .* . | | . . . . . . . . . . . .* . v | . .* . OverlayManagerService . OverlayManagerTests .* . \ . / .* . (1) \ . / (3) .* . . . . . . . . . . \ . . . / . . . . . . . . .* . \ / .* . (2) \ / .* . OverlayManagerServiceImpl .* . | | .* . | | .* . OverlayManagerSettings IdmapManager .* . .* . . . . . . . . . . . . . . . . . . . . . .* </pre>** <p>Finally, here is a list of keywords used in the OMS context.</p>** <ul>* <li><b>target [package]</b> -- A regular apk that may have its resource* pool extended by zero or more overlay packages.</li>** <li><b>overlay [package]</b> -- An apk that provides additional* resources to another apk.</li>** <li><b>OMS</b> -- The OverlayManagerService, i.e. this class.</li>** <li><b>approved</b> -- An overlay is approved if the OMS has verified* that it can be used technically speaking (its target package is* installed, at least one resource name in both packages match, the* idmap was created, etc) and that it is secure to do so. External* clients can not change this state.</li>** <li><b>not approved</b> -- The opposite of approved.</li>** <li><b>enabled</b> -- An overlay currently in active use and thus part* of resource lookups. This requires the overlay to be approved. Only* external clients can change this state.</li>** <li><b>disabled</b> -- The opposite of enabled.</li>** <li><b>idmap</b> -- A mapping of resource IDs between target and overlay* used during resource lookup. Also the name of the binary that creates* the mapping.</li>* </ul>*/
Android RRO动态加载资源相关推荐
- Android apk动态加载机制的研究(二):资源加载和activity生命周期管理
转载请注明出处:http://blog.csdn.net/singwhatiwanna/article/details/23387079 (来自singwhatiwanna的csdn博客) 前言 为了 ...
- Android基础——动态加载so库
Android中动态加载so 原因:如果把so文件直接放在libs目录下,在android程序启动的时候会默认加载libs目录下的所有so库,但这些so库可能会在某些地方存在冲突,使用动态加载so库, ...
- Android类动态加载技术
Android类动态加载技术 Android应用开发在一般情况下,常规的开发方式和代码架构就能满足我们的普通需求.但是有些特殊问题,常常引发我们进一步的沉思.我们从沉思中产生顿悟,从而产生新的技术形式 ...
- Android apk动态加载机制的研究
转载请注明出处:http://blog.csdn.net/singwhatiwanna/article/details/22597587 (来自singwhatiwanna的csdn博客) 背景 问题 ...
- Android JNI 动态加载
一,JNI动态加载主要依赖于jni_OnLoad和jni_OnUnLoad两个方法 官方文档链接:https://docs.oracle.com/javase/7/docs/technotes/gui ...
- Android app动态加载
在 Java 里面,我们可以把一些类放到 .jar 文件里面,然后用 ClassLoader 动态加载.例如: [java] view plaincopyprint? URLClassLoader u ...
- Android动态替换dex,Android DexClassLoader动态加载与插件化开发
参考链接: 一. 基本概念和注意点 1.1 首先需要了解一点:在Android中可以动态加载,但无法像Java中那样方便动态加载jar 原因:Android的虚拟机(Dalvik VM)是不认识Jav ...
- android listview动态加载网络图片不显示,Android Listview异步动态加载网络图片
Android Listview异步动态加载网络图片 详见: http://blog.sina.com.cn/s/blog_62186b460100zsvb.html 标签: Android SDK ...
- android 中动态加载广告sdk
关于动态加载sdk的话题,网上介绍比较多:今天通过第三方工具来取个巧,虽然方法也有点不太靠谱,但终归是一个思路. 项目里面接入了穿山甲sdk和广点通sdk广告,结果放到应用市场时说被拒了,因为有广告, ...
最新文章
- 【NCEPU】吴丹飞:新闻文章点击预测
- Centos 下 Nginx 信号控制
- 大学python实训总结-千锋Python实训总结 学好基础才能走的更远
- php麻将机器人ai算法,高性能麻将AI算法
- LeetCode 1775. 通过最少操作次数使数组的和相等(贪心+双指针)
- Java | 使用对数器判断自己的程序是否正确(generateRandomArray)
- 怎么使用oracle的加权平均数_什么是均线?均线怎么看
- ubuntu中wine的安装位置
- 查找包含具有指定名称的列的所有表 - MS SQL Server
- 【LeetCode】75. 颜色分类,使得相同颜色的元素相邻
- 【FFmpeg】使用 ffmpeg 软件让视频旋转适当角度(亲测有效)
- 博弈论与计算机,《黑 | 科技》| 人类的博弈论,计算机来背锅
- 网络通信安全基础和OpenSSL
- (附源码)springboot大学生就业质量调查分析系统 毕业设计161457
- MySQL8.0密码找回与权限刷新
- 墨者学院—Webmin未经身份验证的远程代码执行(简单复习)
- LeetCode 854 相似度为K的字符串
- 微信论坛交流小程序系统毕业设计毕设(6)开题答辩PPT
- 用Python实现查心率
- ArcGIS教程:欧氏距离 (空间分析)