Android兼容性矩阵
起因
新上的设备,发现hal不支持,因此记录下, 下图已经是修复了正常的了
36的对应的native函数是android_location_GnssLocationProvider_is_supported
,这一看就是hal没有
static jboolean android_location_GnssLocationProvider_is_supported(
JNIEnv* /* env */, jclass /* clazz */) {
return (gnssHal != nullptr) ? JNI_TRUE : JNI_FALSE;
}
/* Initializes the GNSS service handle. */
static void android_location_GnssLocationProvider_set_gps_service_handle() {
gnssHal_V2_0 = IGnss_V2_0::getService();
if (gnssHal_V2_0 != nullptr) {
gnssHal = gnssHal_V2_0;
gnssHal_V1_1 = gnssHal_V2_0;
return;
}
ALOGD("gnssHal 2.0 was null, trying 1.1");
gnssHal_V1_1 = IGnss_V1_1::getService();
if (gnssHal_V1_1 != nullptr) {
gnssHal = gnssHal_V1_1;
return;
}
ALOGD("gnssHal 1.1 was null, trying 1.0");
gnssHal = IGnss_V1_0::getService();
}
后来配置mainfest.xml就OK了,,这就引出了google的兼容性矩阵配置
兼容性矩阵
FCM(Framework Compatibility Matrixes) 框架兼容性矩阵包含系统兼容性矩阵、产品兼容性矩阵和 system_ext 兼容性矩阵。 设备清单必须符合 FCM 的要求(即在构建时、运行时和 VTS 中强制执行的要求)。
system_ext FCM 和产品 FCM 是对设备专用 FCM(安装在 system 分区中)的补充。
- 设备 FCM 应反映 system 分区中各模块的要求。 xml位于/system中
- system_ext FCM 应反映 system_ext 分区中各模块的要求。 xml位于system_ext
- 产品 FCM 应反映 product 分区中各模块的要求。 xml位于/product分区中
使用type="framework"
描述
<?xml version="1.0" encoding="UTF-8"?>
<!-- Comments, Legal notices, etc. here -->
<compatibility-matrix version="1.0" type="framework" level="3">
<hal>
<name>android.hardware.camera</name>
<version>1.0</version>
<version>3.1-4</version>
<interface>
<name>ICameraProvider</name>
<instance>default</instance>
<regex-instance>[a-z_]+/[0-9]+</regex-instance>
</interface>
</hal>
</compatibility-matrix>
DCM(Device Compatibility Matrixes) 设备兼容性矩阵说明了设备期望框架满足的一组要求(在启动和 OTA 时会强制执行相应要求)
使用type="device"
描述
<compatibility-matrix version="1.0" type="device">
<hal>
<name>android.framework.sensor</name>
<version>1.0</version>
<interface>
<name>ISensorManager</name>
<instance>default</instance>
</interface>
</hal>
</compatibility-matrix>
enum Level : size_t {
// Non-Treble devices.
LEGACY = 0,
// Actual values starts from 1.
O = 1,
O_MR1 = 2,
P = 3,
Q = 4,
R = 5,
S = 6,
T = 7,
U = 8,
// To add new values: (1) add above this line. (2) edit if needed:
// - RuntimeInfo::gkiAndroidReleaseToLevel
// - analyze_matrix.cpp, GetDescription()
// The maximum of all specified Levels + 1.
LAST_PLUS_ONE,
// For older manifests and compatibility matrices, "level" is not specified.
UNSPECIFIED = SIZE_MAX,
};
AOSP中位于
hardware/interfaces/compatibility_matrices/compatibility_matrix.4.xml
hardware/interfaces/compatibility_matrices/compatibility_matrix.3.xml
hardware/interfaces/compatibility_matrices/compatibility_matrix.empty.xml
hardware/interfaces/compatibility_matrices/compatibility_matrix.2.xml
hardware/interfaces/compatibility_matrices/compatibility_matrix.legacy.xml
hardware/interfaces/compatibility_matrices/compatibility_matrix.1.xml
描述需要的hal信息
<!-- hardware/interfaces/compatibility_matrices/compatibility_matrix.4.xml -->
<hal format="hidl" optional="true">
<name>android.hardware.dumpstate</name>
<version>1.0</version>
<interface>
<name>IDumpstateDevice</name>
<instance>default</instance>
</interface>
</hal>
我们可以在hardware/interfaces/dumpstate/1.0/
下找到相关接口的信息
package android.hardware.dumpstate@1.0;
interface IDumpstateDevice {
/**
* Dump device-specific state into the given file descriptors.
*
* One file descriptor must be passed to this method but two may be passed:
* the first descriptor must be used to dump device-specific state in text
* format, the second descriptor is optional and may be used to dump
* device-specific state in binary format.
*
* @param h A native handle with one or two valid file descriptors.
*/
dumpstateBoard(handle h);
};
DM 设备清单
DM (Device Manifests) 由厂商维护,其中包含vendor Manifests 和 ODM Manifests两个部分。 描述设备支持的组件
DM 与 FCM 需要匹配HAl才能正常工作,一般厂商使用下面宏指定
DEVICE_FRAMEWORK_MANIFEST_FILE := device/mci/cutefish_k6/framework_manifest.xml
DEVICE_MANIFEST_FILE := device/mci/cutefish_k6/manifest.xml
在Android中位于
/odm/etc/vintf/manifest_$(ro.boot.product.hardware.sku).xml
/odm/etc/vintf/manifest.xml
/odm/etc/manifest_$(ro.boot.product.hardware.sku).xml
/odm/etc/manifest.xml
/vendor/etc/vintf/manifest_$(ro.boot.product.vendor.sku).xml
/vendor/etc/vintf/manifest.xml
- VINTF 对象会按以下顺序加载设备清单:
- 如果该供应商清单存在,请合并以下内容:
供应商清单
可选的供应商清单 Fragment
可选的 ODM 清单
可选的 ODM 清单 Fragment - 否则,如果存在 ODM 清单,将 ODM 清单与可选的 ODM 清单片段合并在一起。
- /vendor/manifest.xml(旧版,无片段)
- 如果该供应商清单存在,请合并以下内容:
格式如下,更多介绍可参见官方
<!-- https://source.android.com/docs/core/architecture/vintf/objects?hl=zh-cn#manifest-fragments -->
<manifest version="1.0" type="device">
<hal format="hidl">
<name>android.hardware.foo</name>
<transport>hwbinder</transport>
<fqname>@1.0::IFoo/default</fqname> <!-- 可选且可重复, 为hal指定实例的一种方法 -->
</hal>
</manifest>
新设备开发建议
在为新设备定义设备目标 FCM 版本时:
- 不要定义 DEVICE_MANIFEST_FILE 和 PRODUCT_ENFORCE_VINTF_MANIFEST。
- 为目标 FCM 版本实现 HAL。
- 编写正确的设备清单文件。
- 将目标 FCM 版本写入设备清单文件。//也就是前面说的需要匹配
- 设置 DEVICE_MANIFEST_FILE。
- 将 PRODUCT_ENFORCE_VINTF_MANIFEST 设为 true。
通过vintf_fragments
添加了设备清单,vendor侧提供了2个版本1.0接口ICustomHardware的实现,其分别是default和custom
cc_binary {
name: "flagstaff.hardware.custom_hardware@1.0-service",
...
vintf_fragments: ["flagstaff.hardware.custom_hardware@1.0.xml"],
}
# Android.mk版本使用
LOCAL_VINTF_FRAGMENTS := manifest_android.hardware.sensors@1.0.xml"
<manifest version="1.0" type="device">
<hal format="hidl">
<name>flagstaff.hardware.custom_hardware</name>
<transport>hwbinder</transport>
<version>1.0</version>
<interface>
<name>ICustomHardware</name>
<instance>default</instance>
<instance>custom</instance>
</interface>
</hal>
</manifest>
获取实例
//获取default实例
android::sp<ICustomHardware> instance = ICustomHardware::getService();
//获取custom实例
android::sp<ICustomHardware> custom = ICustomHardware::getService("custom");
添加FCM清单,通过DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE
宏添加
DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE += \
compatibility_matrix/framework_compatibility_matrix.xml
framework需要版本为1.0接口ICustomHardware的两个实现,其分别是default和custom。但是此处的optional为true意味着该组件为可选,所以即使不提供对应的DM的话也不影响系统编译运行测试的
<compatibility-matrix version="2.0" type="framework">
<hal format="hidl" optional="true">
<name>flagstaff.hardware.custom_hardware</name>
<version>1.0</version>
<interface>
<name>ICustomHardware</name>
<instance>default</instance>
<instance>custom</instance>
</interface>
</hal>
</compatibility-matrix>
其他
查找AIDL生成的中间文件路径
out/soong/.intermediates/frameworks/base/framework/android_common/gen/aidl/frameworks/base/location/java/android/location/ILocationManager.java
DM与FCM不对应遇到的错误
W hwservicemanager: getTransport: Cannot find entry android.hardware.neuralnetworks@1.0::IDevice/armnn in either framework or device manifest.
<!-- /vendor/etc/vintf/manifest.xml -->
<hal format="hidl">
<name>android.hardware.neuralnetworks</name>
<transport>hwbinder</transport>
<version>1.0</version>
<interface>
<name>IDevice</name>
<instance>armnn</instance>
</interface>
<fqname>@1.0::IDevice/armnn</fqname>
</hal>