LOCAL_PRIVILEGED_MODULE 是Android ROM编译时的一个变量,其与编译、安装、权限管理等几个方面都有关系。本文整理一下与LOCAL_PRIVILEGED_MODULE有关的知识。本文源代码分析基于Android6.0.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 (from base_rules.mk)
core/install_jni_libs.mk:6:# partition_tag (from base_rules.mk)
core/host_java_library.mk:43:include $(BUILD_SYSTEM)/base_rules.mk
core/prebuilt.mk:4:## Additional inputs from base_rules.make:
core/static_library_internal.mk:4:## Additional inputs from base_rules.make:
core/build-system.html:909:Set by the host_xxx.make includes to tell base_rules.make and the other
core/build-system.html:929:variable names used to locate the modules. See base_rules.make and
core/build-system.html:942:
Calculated in base_rules.make to determine if this module should actually
core/dex_preopt_odex_install.mk:2:# This file depends on variables set in base_rules.mk
core/host_executable_internal.mk:4:## Additional inputs from base_rules.make:
core/java_library.mk:21:# base_rules.mk looks at this
core/executable_internal.mk:4:## Additional inputs from base_rules.make:
core/dynamic_binary.mk:16:# This duplicates logic from base_rules.mk because we need to
core/dynamic_binary.mk:17:# know its results before base_rules.mk is included.
core/shared_library_internal.mk:4:## Additional inputs from base_rules.make:
core/host_dalvik_java_library.mk:51:include $(BUILD_SYSTEM)/base_rules.mk
core/host_shared_library_internal.mk:4:## Additional inputs from base_rules.make:
core/host_java_library_common.mk:42:# base_rules.mk looks at this
core/prebuilt_internal.mk:4:## Additional inputs from base_rules.make:
core/prebuilt_internal.mk:85: include $(BUILD_SYSTEM)/base_rules.mk
tools/apicheck/Android.mk:31:include $(BUILD_SYSTEM)/base_rules.mk
tools/fs_config/Android.mk:67:include $(BUILD_SYSTEM)/base_rules.mk
tools/fs_config/Android.mk:78:include $(BUILD_SYSTEM)/base_rules.mk
好,下面看看base_rules.mk中对于LOCAL_PRIVILEGED_MODULE的处理逻辑:
ifeq ($(my_module_path),)
ifdef LOCAL_IS_HOST_MODULE
partition_tag :=
else
ifeq (true,$(LOCAL_PROPRIETARY_MODULE))
partition_tag := _VENDOR
else ifeq (true,$(LOCAL_OEM_MODULE))
partition_tag := _OEM
else ifeq (true,$(LOCAL_ODM_MODULE))
partition_tag := _ODM
else
# The definition of should-install-to-system will be different depending
# on which goal (e.g., sdk or just droid) is being built.
partition_tag := $(if $(call should-install-to-system,$(my_module_tags)),,_DATA)
endif
endif
install_path_var := $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT$(partition_tag)_$(LOCAL_MODULE_CLASS)
ifeq (true,$(LOCAL_PRIVILEGED_MODULE))
install_path_var := $(install_path_var)_PRIVILEGED
endif
my_module_path := $($(install_path_var))
ifeq ($(strip $(my_module_path)),)
$(error $(LOCAL_PATH): unhandled install path "$(install_path_var) for $(LOCAL_MODULE)")
endif
endif
如果LOCAL_PRIVILEGED_MODULE为true,对安装路径变量install_path_var做了修改:
ifeq (true,$(LOCAL_PRIVILEGED_MODULE))
install_path_var := $(install_path_var)_PRIVILEGED
endif
增加一些调试信息来求证:
install_path_var := $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT$(partition_tag)_$(LOCAL_MODULE_CLASS)
$(warning ******************** test **********************************)
$(warning step1 - install_path_var : $(install_path_var))
$(warning ******************** test **********************************)
ifeq (true,$(LOCAL_PRIVILEGED_MODULE))
install_path_var := $(install_path_var)_PRIVILEGED
endif
$(warning ******************** test **********************************)
$(warning step2 - install_path_var : $(install_path_var))
$(warning ******************** test **********************************)
随便编译某个将LOCAL_PRIVILEGED_MODULE设置为true的系统应用,mm,看到如下warning信息:
build/core/base_rules.mk:130: ******************** test **********************************
build/core/base_rules.mk:131: step1 - install_path_var : TARGET_OUT_APPS
build/core/base_rules.mk:132: ******************** test **********************************
build/core/base_rules.mk:138: ******************** test **********************************
build/core/base_rules.mk:139: step2 - install_path_var : TARGET_OUT_APPS_PRIVILEGED
build/core/base_rules.mk:140: ******************** test **********************************
再打印TARGET_OUT_APPS和TARGET_OUT_APPS_PRIVILEGED两个变量:
install_path_var := $(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT$(partition_tag)_$(LOCAL_MODULE_CLASS)
$(warning ******************** test **********************************)
$(warning step1 - install_path_var : $(install_path_var))
$(warning ******************** test **********************************)
ifeq (true,$(LOCAL_PRIVILEGED_MODULE))
install_path_var := $(install_path_var)_PRIVILEGED
endif
$(warning ******************** test **********************************)
$(warning step2 - install_path_var : $(install_path_var))
$(warning ******************** test **********************************)
$(warning ******************** test **********************************)
$(warning values - install_path_var : $(TARGET_OUT_APPS))
$(warning values - install_path_var : $(TARGET_OUT_APPS_PRIVILEGED))
$(warning ******************** test **********************************)
warning信息:
build/core/base_rules.mk:138: ******************** test **********************************
build/core/base_rules.mk:139: values - install_path_var : out/target/product/xxx/system/app
build/core/base_rules.mk:140: values - install_path_var : out/target/product/xxx/system/priv-app
build/core/base_rules.mk:141: ******************** test **********************************
可以看到,正是对于LOCAL_PRIVILEGED_MODULE的处理,将安装路径从system/app改为system/priv-app。
LOCAL_PRIVILEGED_MODULE 详解(1)
LOCAL_PRIVILEGED_MODULE 详解(2)
LOCAL_PRIVILEGED_MODULE 详解(3)
LOCAL_PRIVILEGED_MODULE 详解(4)
LOCAL_PRIVILEGED_MODULE 详解(5)