LOCAL_PRIVILEGED_MODULE 是Android ROM编译时的一个变量,其与编译、安装、权限管理等几个方面都有关系。本文整理一下与LOCAL_PRIVILEGED_MODULE有关的知识。本文源代码分析基于Android6.0.1。
1.编译时作用
对于Android系统应用,LOCAL_PRIVILEGED_MODULE 决定了其编译后的在ROM中的安装位置:
如果不设置或者设置为false,安装位置为system/app;
如果设置为true,安装位置为system/priv-app。
那么,Android的编译系统是如何处理这个变量的呢?
我们知道,Android编译系统源代码主要是位于 build/core下的xxx.mk文件,在build/下搜索对于LOCAL_PRIVILEGED_MODULE的使用,可以看到:
$ grep -nr "LOCAL_PRIVILEGED_MODULE" *
core/clear_vars.mk:148:LOCAL_PRIVILEGED_MODULE:=
core/base_rules.mk:129: ifeq (true,$(LOCAL_PRIVILEGED_MODULE))
base_rules.mk里面有对LOCAL_PRIVILEGED_MODULE的处理。从base_rules.mk的头部注释来看,这个文件是用来定义通用的编译命令,并且支持自定义扩展。
# Users can define base-rules-hook in their buildspec.mk to perform
# arbitrary operations as each module is included.
ifdef base-rules-hook
$(if $(base-rules-hook),)
endif
###########################################################
## Common instructions for a generic module.
###########################################################
在build/下搜索也发现base_rules.mk多处include:
$ grep -nr "base_rules" *
core/java.mk:74:# Define the intermediate targets before including base_rules so they get
core/java.mk:292:# TODO: It looks like the only thing we need from base_rules is
core/java.mk:294:# common_java.mk, and moving the include of base_rules.mk to
core/java.mk:298:include $(BUILD_SYSTEM)/base_rules.mk
core/java.mk:340:# Override some target variables that base_rules set up for us.
core/install_jni_libs_internal.mk:7:# partition_tag (from base_rules.mk)
core/host_static_library_internal.mk:4:## Additional inputs from base_rules.make:
core/binary.mk:9:include $(BUILD_SYSTEM)/base_rules.mk
core/package_internal.mk:20:## Additional inputs from base_rules.make:
core/phony_package.mk:8:include $(BUILD_SYSTEM)/base_rules.mk
core/install_jni_libs.mk:5:# my_module_path