Android10.0(Q) HAL层 light2.0 改动记录及排错过程

简介: Android10.0(Q) HAL层 light2.0 改动记录及排错过程

LightsService 灯光服务提供了LCD背光灯、键盘灯、按键灯、警示灯、电池灯、


消息通知灯、蓝牙灯、wifi灯等八种类型灯光;都是基于 android.hardware.light.V2_0.Type


现有需求需要新增第九中类型灯光控制,找到定义 Type 的地方


hardware\interfaces\light\2.0\types.hal

/**
 * These light IDs correspond to logical lights, not physical.
 * So for example, if your INDICATOR light is in line with your
 * BUTTONS, it might make sense to also light the INDICATOR
 * light to a reasonable color when the BUTTONS are lit.
 */
enum Type : int32_t {
    BACKLIGHT,
    KEYBOARD,
    BUTTONS,
    BATTERY,
    NOTIFICATIONS,
    ATTENTION,
    BLUETOOTH,
    WIFI,
    FLASH_TRIG,
    COUNT,
};

hardware\interfaces\light\2.0\default\Light.cpp

const static std::map<Type, const char*> kLogicalLights = {
    {Type::BACKLIGHT,     LIGHT_ID_BACKLIGHT},
    {Type::KEYBOARD,      LIGHT_ID_KEYBOARD},
    {Type::BUTTONS,       LIGHT_ID_BUTTONS},
    {Type::BATTERY,       LIGHT_ID_BATTERY},
    {Type::NOTIFICATIONS, LIGHT_ID_NOTIFICATIONS},
    {Type::ATTENTION,     LIGHT_ID_ATTENTION},
    {Type::BLUETOOTH,     LIGHT_ID_BLUETOOTH},
    {Type::WIFI,          LIGHT_ID_WIFI},
    {Type::FLASH_TRIG,    LIGHT_ID_FLASH_TRIG}
};

frameworks\base\services\core\java\com\android\server\lights\LightsManager.java

package com.android.server.lights;
import android.hardware.light.V2_0.Type;
public abstract class LightsManager {
    public static final int LIGHT_ID_BACKLIGHT = Type.BACKLIGHT;
    public static final int LIGHT_ID_KEYBOARD = Type.KEYBOARD;
    public static final int LIGHT_ID_BUTTONS = Type.BUTTONS;
    public static final int LIGHT_ID_BATTERY = Type.BATTERY;
    public static final int LIGHT_ID_NOTIFICATIONS = Type.NOTIFICATIONS;
    public static final int LIGHT_ID_ATTENTION = Type.ATTENTION;
    public static final int LIGHT_ID_BLUETOOTH = Type.BLUETOOTH;
    public static final int LIGHT_ID_WIFI = Type.WIFI;
    public static final int LIGHT_ID_FLASH_TRIG = Type.FLASH_TRIG;
    public static final int LIGHT_ID_COUNT = Type.COUNT;
    public abstract Light getLight(int id);
}

修改如上几个地方后,编译报错

错误一、which does not match hash on record. This interface has been frozen. Do not change it!

ERROR: output handler failed.
HIDL c++-sources: hardware/interfaces/light/2.0/types.hal hardware/interfaces/light/2.0/ILight.hal hardware/interfaces/current.txt => 'out/soong/.intermediates/hardware/interfaces/light/2.0/android.hardware.light@2.0_genc++/gen/android/hardware/light/2.0/LightAll.cpp'
FAILED: out/soong/.intermediates/hardware/interfaces/light/2.0/android.hardware.light@2.0_genc++/gen/android/hardware/light/2.0/LightAll.cpp out/soong/.intermediates/hardware/interfaces/light/2.0/android.hardware.light@2.0_genc++/gen/android/hardware/light/2.0/types.cpp
rm -rf out/soong/.intermediates/hardware/interfaces/light/2.0/android.hardware.light@2.0_genc++/gen && out/soong/host/linux-x86/bin/hidl-gen -R -p . -d out/soong/.intermediates/hardware/interfaces/light/2.0/android.hardware.light@2.0_genc++/gen/android/hardware/light/2.0/LightAll.cpp.d -o out/soong/.intermediates/hardware/interfaces/light/2.0/android.hardware.light@2.0_genc++/gen -L c++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.light@2.0
ERROR: android.hardware.light@2.0::types has hash cd082c47c3940f2c4d4ef489c9f34e0c737dfcbd7dd09e0e270563e699a9d91e which does not match hash on record. This interface has been frozen. Do not change it!
ERROR: Could not parse android.hardware.light@2.0::types. Aborting.

原因:Android P 开始,Google 对 Hidl 有了严格的限制。Google release 出来的 hidl 接口不允许修改。


需要重新生成修改 hardware 对应的 hashcode,错误中已经包含新的 hashcode 值 cd082c47c3940f2c4d4ef489c9f34e0c737dfcbd7dd09e0e270563e699a9d91e


如果没有此 hashcode 值,可以通过指令 hidl-gen -L hash -r 来生成,得到和错误提示中的hash值一模一样

$ hidl-gen -L hash -r android.hardware:hardware/interfaces -r android.hidl:system/libhidl/transport android.hardware.light@2.0::types
cd082c47c3940f2c4d4ef489c9f34e0c737dfcbd7dd09e0e270563e699a9d91e android.hardware.light@2.0::types

将刚刚得到的新 hashcode 值更新到 hardware/interfaces/current.txt


可直接在文档末尾增加 cd082c47c3940f2c4d4ef489c9f34e0c737dfcbd7dd09e0e270563e699a9d91e android.hardware.light@2.0::types


错误二、error: VNDK library: android.hardware.light@2.0’s ABI has INCOMPATIBLE CHANGES Please check compatibility report at: out/soong/.intermediates/hardware/interfaces/light/2.0/android.hardware.light@2.0/android_arm64_armv8-a_cortex-a53_vendor_shared/android.hardware.light@2.0.so.abidiff

Install: out/target/product/full_171_bsp/system/lib64/vndk-29/android.hardware.keymaster@3.0.so
//hardware/interfaces/light/2.0:android.hardware.light@2.0 header-abi-diff android.hardware.light@2.0.so.abidiff
FAILED: out/soong/.intermediates/hardware/interfaces/light/2.0/android.hardware.light@2.0/android_arm64_armv8-a_cortex-a53_vendor_shared/android.hardware.light@2.0.so.abidiff
(prebuilts/clang-tools/linux-x86/bin/header-abi-diff -allow-unreferenced-changes -allow-unreferenced-elf-symbol-changes -lib android.hardware.light@2.0 -arch arm64 -o 'out/soong/.intermediates/hardware/interfaces/light/2.0/android.hardware.light@2.0/android_arm64_armv8-a_cortex-a53_vendor_shared/android.hardware.light@2.0.so.abidiff' -new 'out/soong/.intermediates/hardware/interfaces/light/2.0/android.hardware.light@2.0/android_arm64_armv8-a_cortex-a53_vendor_shared/android.hardware.light@2.0.so.lsdump' -old prebuilts/abi-dumps/vndk/29/64/arm64_armv8-a/source-based/android.hardware.light@2.0.so.lsdump)|| (echo 'error: Please update ABI references with: $ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py  -l android.hardware.light@2.0' && (mkdir -p $DIST_DIR/abidiffs && cp 'out/soong/.intermediates/hardware/interfaces/light/2.0/android.hardware.light@2.0/android_arm64_armv8-a_cortex-a53_vendor_shared/android.hardware.light@2.0.so.abidiff' $DIST_DIR/abidiffs/) && exit 1)
******************************************************
error: VNDK library: android.hardware.light@2.0's ABI has INCOMPATIBLE CHANGES Please check compatibility report at: out/soong/.intermediates/hardware/interfaces/light/2.0/android.hardware.light@2.0/android_arm64_armv8-a_cortex-a53_vendor_shared/android.hardware.light@2.0.so.abidiff
******************************************************
error: Please update ABI references with: $ANDROID_BUILD_TOP/development/vndk/tools/header-checker/utils/create_reference_dumps.py  -l android.hardware.light@2.0

根据提示执行指令 development/vndk/tools/header-checker/utils/create_reference_dumps.py -l android.hardware.light@2.0 ,发现报错


$ development/vndk/tools/header-checker/utils/create_reference_dumps.py -l android.hardware.light@2.0
Removing reference dumps...
removing /platform/prebuilts/abi-dumps/vndk/28/32/arm_armv7-a-neon/source-based/android.hardware.gnss@1.0.so.lsdump.gz
removing /platform/prebuilts/abi-dumps/ndk/28/32/arm_armv7-a-neon/source-based/android.hardware.gnss@1.0.so.lsdump.gz
making libs for product: aosp_arm_ab
Traceback (most recent call last):
  File "development/vndk/tools/header-checker/utils/create_reference_dumps.py", line 224, in <module>
    main()
  File "development/vndk/tools/header-checker/utils/create_reference_dumps.py", line 215, in main
    make_libs_for_product(args.libs, args.llndk, product)
  File "development/vndk/tools/header-checker/utils/create_reference_dumps.py", line 97, in make_libs_for_product
    make_libraries(libs, product, llndk_mode)
  File "/platform/development/vndk/tools/header-checker/utils/utils.py", line 146, in make_libraries
    make_targets(lib_targets, product)
  File "/platform/development/vndk/tools/header-checker/utils/utils.py", line 137, in make_targets
    stderr=subprocess.STDOUT)
  File "/usr/lib/python3.5/subprocess.py", line 581, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['build/soong/soong_ui.bash', '--make-mode', '-j', 'android.hardware.gnss@1.0.vendor', 'TARGET_PRODUCT=aosp_arm_ab']' returned non-zero exit status 1

看到 making libs for product: aosp_arm_ab 这行,这个是因为我的项目 product名字不一样导致的,加上参数-product product_name 即可,product_name 是你的项目的 product 名称。


development/vndk/tools/header-checker/utils/create_reference_dumps.py -l android.hardware.light@2.0 -product full_171_bsp

AllowBuildBrokenUsesNetwork: true
 BuildBrokenUsesNetwork: true
//hardware/interfaces/light/2.0:android.hardware.light@2.0 header-abi-linker android.hardware.light@2.0.so.lsdump [arm]
Creating dumps for target_arch: arm and variant  armv8-a
Created abi dump at /prebuilts/abi-dumps/vndk/29/64/arm_armv8-a/source-based/android.hardware.light@2.0.so.lsdump
Creating dumps for target_arch: arm64 and variant  armv8-a
Created abi dump at /prebuilts/abi-dumps/vndk/29/64/arm64_armv8-a/source-based/android.hardware.light@2.0.so.lsdump
msg: Processed 2 libraries in  14.642458236217498  minutes


参考文章


Android P VNDK报错

目录
相关文章
|
6月前
|
安全 Android开发
Android HAL 层
Android HAL 层
54 1
|
6月前
|
安全 编译器 API
Android HAL深入探索(5): 调试HAL报错与解决方案
Android HAL深入探索(5): 调试HAL报错与解决方案
1241 1
|
6月前
|
传感器 Java Android开发
Android HAL深入探索(1): 架构概述
Android HAL深入探索(1): 架构概述
663 1
|
6月前
|
编解码 调度 Android开发
Android音频框架之一 详解audioPolicy流程及HAL驱动加载与配置
Android音频框架之一 详解audioPolicy流程及HAL驱动加载与配置
675 0
|
6月前
|
Android开发 C++
Android S HAL库的编译
Android S HAL库的编译
76 0
|
6月前
|
Android开发 C++
Android P HAL层添加HIDL实例
Android P HAL层添加HIDL实例
119 0
|
6月前
|
前端开发 Java 编译器
Android HAL深入探索(7)hidl-gen和hidl2aidl的使用详解
Android HAL深入探索(7)hidl-gen和hidl2aidl的使用详解
992 0
|
6月前
|
编解码 监控 API
Android HAL深入探索(6): HIDL 添加SELinux 完整调试过程
Android HAL深入探索(6): HIDL 添加SELinux 完整调试过程
1001 0
|
Linux 编译器 开发工具
Android11.0(R) MTK6765 TP 驱动移植调试排错过程
Android11.0(R) MTK6765 TP 驱动移植调试排错过程
493 0