recovery 升级前兼容性检查(Vendor Interface Object)
从android P(9.0)版本开始,我们发现编译出来的OTA升级了里面多了一个文件,compatibility.zip,这个里面存储这system与vendor分区的一些特性,用来做升级前的兼容性检查。其实从android O开始已经增加了这个功能,但是没有默认打开。直到android P上,已经默认打开了。
解压compatibility.zip后,内容如下:
我们先从google的官方了解下这个功能。
https://source.android.com/devices/architecture/vintf/
Framework(system)和Device(vendor)匹配的框架如下:
Manifest 描述了提供给对方的feature, Matrix 描述了需要对方提供的feature。Manifest 和 Matrix 在OTA升级前会进行匹配检查,以确保framework和device是兼容的。总的来说,manifest是提供端,matrix是需求端。
下面以android P最新的aosp的code为例。
Framework Manifest:
manifest.xml的源文件由google手动生成,其存在路径:
system/libhidl/vintfdata/manifest.xml
system/libhidl/vintfdata/manifest_healthd_exclude.xml
至于xml的内容就不贴上来了,可以到对应的目录去查看源文件。manifest.xml的格式可以参考官方文档即可,也不在此详细讲解。
Framework Compatibility Matrix:
Framework compatibility matrix描述的是framework对 device的需求。这个matrix文件是和Android Framework Image(system.img)关联的。Framework compatibility matrix的这些需要被device manifest支持。
compatibility matrix源文件路径:
hardware/interfaces/compatibility_matrices/compatibility_matrix.1.xml
hardware/interfaces/compatibility_matrices/compatibility_matrix.2.xml
hardware/interfaces/compatibility_matrices/compatibility_matrix.3.xml
hardware/interfaces/compatibility_matrices/compatibility_matrix.empty.xml
hardware/interfaces/compatibility_matrices/compatibility_matrix.legacy.xml
Device Manifest:
由BoardConfig.mk中定义
device/xxxx/xxxx/BoardConfig.mk定义:
DEVICE_MANIFEST_FILE := device/xxxx/xxxx/manifest.xml
源文件为 device/xxxx/xxxx/manifest.xml
Device Compatibility Matrix:
如果BoardConfig.mk中有定义,则以定义的文件为源文件:
#DEVICE_MATRIX_FILE := device/amlogic/common/compatibility_matrix.xml
如果没有定义,则使用缺省的源文件:
system/libhidl/vintfdata/device_compatibility_matrix.default.xml
如上,我们找到了device manifest,device compatibility matrix,framework manifest,framework compatibility matrix各自对应的源文件,然后我们通过编译规则生成最终的xml文件。
build/make/target/board/Android.mk(定义了Device Manifest生成规则)
# Device Manifest
ifdef DEVICE_MANIFEST_FILE
# $(DEVICE_MANIFEST_FILE) can be a list of files
include $(CLEAR_VARS)
LOCAL_MODULE := device_manifest.xml
LOCAL_MODULE_STEM := manifest.xml
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc/vintf
GEN := $(local-generated-sources-dir)/manifest.xml
$(GEN): PRIVATE_DEVICE_MANIFEST_FILE := $(DEVICE_MANIFEST_FILE)
$(GEN): $(DEVICE_MANIFEST_FILE) $(HOST_OUT_EXECUTABLES)/assemble_vintf
BOARD_SEPOLICY_VERS=$(BOARD_SEPOLICY_VERS) \
PRODUCT_ENFORCE_VINTF_MANIFEST=$(PRODUCT_ENFORCE_VINTF_MANIFEST) \
PRODUCT_SHIPPING_API_LEVEL=$(PRODUCT_SHIPPING_API_LEVEL) \
$(HOST_OUT_EXECUTABLES)/assemble_vintf -o $@ \
-i $(call normalize-path-list,$(PRIVATE_DEVICE_MANIFEST_FILE))
LOCAL_PREBUILT_MODULE_FILE := $(GEN)
include $(BUILD_PREBUILT)
BUILT_VENDOR_MANIFEST := $(LOCAL_BUILT_MODULE)
endif
system/libhidl/vintfdata/Android.mk(定义了Device Compatibility Matrix / Framework Manifest编译规则)
# Device Compatibility Matrix
ifdef DEVICE_MATRIX_FILE
DEVICE_MATRIX_INPUT_FILE := $(DEVICE_MATRIX_FILE)
else
DEVICE_MATRIX_INPUT_FILE := $(LOCAL_PATH)/device_compatibility_matrix.default.xml
endif
include $(CLEAR_VARS)
LOCAL_MODULE := device_compatibility_matrix.xml
LOCAL_MODULE_STEM := compatibility_matrix.xml
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/etc/vintf
GEN := $(local-generated-sources-dir)/compatibility_matrix.xml
$(GEN): PRIVATE_VINTF_VNDK_VERSION := $(VINTF_VNDK_VERSION)
$(GEN): $(DEVICE_MATRIX_INPUT_FILE) $(HOST_OUT_EXECUTABLES)/assemble_vintf
REQUIRED_VNDK_VERSION=$(PRIVATE_VINTF_VNDK_VERSION) \
BOARD_SYSTEMSDK_VERSIONS="$(BOARD_SYSTEMSDK_VERSIONS)" \
$(HOST_OUT_EXECUTABLES)/assemble_vintf -i $< -o $@
LOCAL_PREBUILT_MODULE_FILE := $(GEN)
include $(BUILD_PREBUILT)
BUILT_VENDOR_MATRIX := $(LOCAL_BUILT_MODULE)
# Framework Manifest
include $(CLEAR_VARS)
LOCAL_MODULE := framework_manifest.xml
LOCAL_MODULE_STEM := manifest.xml
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT)/etc/vintf
GEN := $(local-generated-sources-dir)/manifest.xml
$(GEN): PRIVATE_FLAGS :=
ifeq ($(PRODUCT_ENFORCE_VINTF_MANIFEST),true)
ifdef BUILT_VENDOR_MATRIX
$(GEN): $(BUILT_VENDOR_MATRIX)
$(GEN): PRIVATE_FLAGS += -c "$(BUILT_VENDOR_MATRIX)"
endif
endif
$(GEN): PRIVATE_VINTF_VNDK_VERSION := $(VINTF_VNDK_VERSION)
$(GEN): PRIVATE_FRAMEWORK_MANIFEST_INPUT_FILES := $(FRAMEWORK_MANIFEST_INPUT_FILES)
$(GEN): $(FRAMEWORK_MANIFEST_INPUT_FILES) $(HOST_OUT_EXECUTABLES)/assemble_vintf
PROVIDED_VNDK_VERSIONS="$(PRIVATE_VINTF_VNDK_VERSION) $(PRODUCT_EXTRA_VNDK_VERSIONS)" \
PLATFORM_SYSTEMSDK_VERSIONS="$(PLATFORM_SYSTEMSDK_VERSIONS)" \
$(HOST_OUT_EXECUTABLES)/assemble_vintf \
-i $(call normalize-path-list,$(PRIVATE_FRAMEWORK_MANIFEST_INPUT_FILES)) \
-o $@ $(PRIVATE_FLAGS)
hardware/interfaces/compatibility_matrices/Android.mk
hardware/interfaces/compatibility_matrices/compatibility_matrix.mk (定义了Framework Compatibility Matrix规则)
# 详细规则请查看源文件,就不贴代码了
有了上述源文件及编译规则,则可以生成最终的xml文件了, 具体的调用,都是使用了out/host/linux-x86/bin/assemble_vintf工具。
生成的最终的xml对应的分区路径如下:
/system/compatibility_matrix.xml
/system/etc/vintf/manifest.xml
/vendor/etc/vintf/compatibility_matrix.xml
/vendor/etc/vintf/manifest.xml
至此,我们在升级过程,可以从升级包update.zip中获取manifest与matrix文件(system_manifest.xml system_matrix.xml vendor_manifest.xml vendor_matrix.xml),然后挂载/system /vendor分区,与system/vendor分区对应的xml对比校验,检查是否符合升级条件。满足条件,则继续后面的升级,如果不满足条件,则终止升级。
具体的代码实现,bootable/recovery/install.cpp中
在升级包的完整性校验完成之后,就进行兼容性校验,最终的实现调用的接口是(system/libvintf/VintfObject.cpp):android::vintf::VintfObjectRecovery::CheckCompatibility
参考: