hal深入剖析之aidl实战-android framework车机车载手机系统开发

适用于 HAL 的 AIDL Android 11 引入了在 Android 中使用 AIDL 实现 HAL 的功能。这样就可以在不使用 HIDL 的情况下实现 Android 的部分代码。我们强烈建议尽量将 HAL 转换为只使用 AIDL(如果上游 HAL 使用 HIDL,则必须使用 HIDL)。 如果 HAL 使用 AIDL 在框架组件(例如system.img中的组件)和硬件组件(例如vendor.img中的组件)之间进行通信,则必须使用稳定的 AIDL。不过,如需在分区内进行通信(例如从一个 HAL 到另一个),则对所... 阅读详情
AI摘要

本文详细介绍车机车载环境下AIDL HAL的开发流程。包括创建相关目录、定义aidl文件、编写Android.bp、编译接口文件、编写服务端代码,还涉及将模块加入兼容性矩阵、增加selinux权限、编写测试模块、将程序加入整机编译及最终测试等步骤。

1、创建相关的目录hal目录及aidl存放目录

~/nx563j_xiaomi$ mkdir hardware/interfaces/mytest
~/nx563j_xiaomi$ cd hardware/interfaces/mytest/

这个是hal工程根目录
接下来要创建aidl的文件存放目录

test@test:~/nx563j_xiaomi/hardware/interfaces/mytest$ mkdir aidl
test@test:~/nx563j_xiaomi/hardware/interfaces/mytest$ cd aidl/
test@test:~/nx563j_xiaomi/hardware/interfaces/mytest/aidl$ mkdir -p  android/hardware/mytest

注意mkdir -p android/hardware/mytest其实就是包名目录,即模块包名就是android.hardware.mytest.

提示:这个如果为了项目的更加好的维护性建议到自己项目目标的vendor下面进行,目前只是为了演示方便,直接在system的hardware下面

2、创建定义对应aidl文件

创建最重要的aidl接口文件,需要在第一步创建的目录下

test@test:~/nx563j_xiaomi/hardware/interfaces/mytest/aidl/android/hardware/mytest$ touch IMyTest.aidl
test@test:~/nx563j_xiaomi/hardware/interfaces/mytest/aidl/android/hardware/mytest$ touch MyTestObj.aidl
test@test:~/nx563j_xiaomi/hardware/interfaces/mytest/aidl$ tree
.
`-- android
    `-- hardware
        `-- mytest
            |-- IMyTest.aidl
            `-- MyTestObj.aidl

编写aidl内容:
IMyTest.aidl

package android.hardware.mytest; 
import android.hardware.mytest.MyTestObj; 
@VintfStability 
interface IMyTest {
    MyTestObj test();
}

MyTestObj.aidl

package android.hardware.mytest; 
@VintfStability 
parcelable MyTestObj {
    String key;
    int value;
}

其实和普通的aidl基本一样,唯一差别就是要多一些稳定性的声明比如@VintfStability这个注解官方解释如下:

VintfStability
VintfStability declares that a user-defined type (interface, parcelable, and enum) can be used across the system and vendor domains.

还是就是parcelable都是需要进行结构化,成员属性写清楚到aidl

3、编写顶层aidl的Android.bp

最开始的aidl目录创建一个Android.bp

test@test:~/nx563j_xiaomi/hardware/interfaces/mytest/aidl$ touch Android.bp

Android.bp

aidl_interface {
    name: "android.hardware.mytest",
    vendor_available: true,
    srcs: ["android/hardware/mytest/*.aidl"],
    stability: "vintf",
    owner:"qianli.ma",
    backend: {
        cpp: {
            enabled: false,
        },
        java: {
            sdk_version: "module_current",
        },
    },

}

需要注意以下几个点:
1、要写aidl_interface目标
2、设置成 vendor_available: true即代表vendor和system都可以用,不是vendor独享
3、stability: “vintf” stability保证接口是稳定的属性,目前只支持vintf
4、backend 这里的后端有4个,C++/JAVA/NDK/RUST, 我们将使用NDK和java,因此将CPP声明为false,为啥不使用c++呢?为啥出来个ndk呢?这个google官方给出了解释
https://source.android.google.cn/docs/core/architecture/aidl/aidl-hals#choosing-runtime

Building against the AIDL runtime
AIDL has three different backends: Java, NDK, CPP. To use Stable AIDL, you must always use the system copy of libbinder at system/lib*/libbinder.so and talk on /dev/binder. For code on the vendor image, this means that libbinder (from the VNDK) cannot be used: this library has an unstable C++ API and unstable internals. Instead, native vendor code must use the NDK backend of AIDL, link against libbinder_ndk (which is backed by system libbinder.so), and link against the -ndk_platform libraries created by aidl_interface entries.

大概意思就是一般aidl的vendor和system跨进程中不使用libbinder的包,因为一般vendor使用是vndk下面的包,故无法访问dev/binder,访问其实是dev/vndbinder,所有一般使用是NDK

4、编译接口文件

编译命令:
test@test:~/nx563j_xiaomi$ mmm hardware/interfaces/mytest

但是出现如下错误

[ 62% 200/319] echo "API dump for the current version of AIDL interface android.hardware.mytest does not exist." && echo Run "m android.hardware.mytest-update-api", or add "unstable: true" to the build r
FAILED: out/soong/.intermediates/hardware/interfaces/mytest/aidl/android.hardware.mytest-api/checkapi_current.timestamp
echo "API dump for the current version of AIDL interface android.hardware.mytest does not exist." && echo Run "m android.hardware.mytest-update-api", or add "unstable: true" to the build rule for the int
erface if it does not need to be versioned && false # hash of input list: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
API dump for the current version of AIDL interface android.hardware.mytest does not exist.
Run m android.hardware.mytest-update-api, or add unstable: true to the build rule for the interface if it does not need to be versioned
12:38:45 ninja failed with: exit status 1

#### failed to build some targets (01:04 (mm:ss)) ####

大概意思我们的接口是不存在的需要更新api执行:
m android.hardware.mytest-update-api

下面执行新的编译命令:

m android.hardware.mytest-update-api

成功后如下打印

out/soong/Android-lineage_nx563j.mk was modified, regenerating...
[100% 190/190] //hardware/interfaces/mytest/aidl:android.hardware.mytest-api Updating AIDL API dump version current for android.hardware.mytest (see hardware/interfaces/mytest/aidl/aidl_api/android.hardw

#### build completed successfully (06:57 (mm:ss)) ####

此时的目录已经被生成了aidl_api目录

test@test:~/nx563j_xiaomi/hardware/interfaces/mytest$ tree
.
`-- aidl
    |-- Android.bp
    |-- aidl_api
    |   `-- android.hardware.mytest
    |       `-- current
    |           `-- android
    |               `-- hardware
    |                   `-- mytest
    |                       |-- IMyTest.aidl
    |                       `-- MyTestObj.aidl
    `-- android
        `-- hardware
            `-- mytest
                |-- IMyTest.aidl
                `-- MyTestObj.aidl

然后在进行刚才的编译
test@test:~/nx563j_xiaomi$ mmm hardware/interfaces/mytest
成功后会有如下打印

============================================
[100% 128/128] Install: out/target/product/nx563j/system/framework/android.hardware.mytest-V1-java.jar

#### build completed successfully (03:20 (mm:ss)) ####

这里主要是在编译相关目录生成相关接口代码和库,具体路径如下:

test@test:~/nx563j_xiaomi/out/soong/.intermediates/hardware/interfaces/mytest/aidl$ ls -l
total 20
drwxrwxr-x  3 test test 4096 Dec 12 13:07 android.hardware.mytest-V1-java
drwxrwxr-x  3 test test 4096 Dec 12 13:07 android.hardware.mytest-V1-java-source
drwxrwxr-x 16 test test 4096 Dec 12 13:07 android.hardware.mytest-V1-ndk
drwxrwxr-x  3 test test 4096 Dec 12 13:07 android.hardware.mytest-V1-ndk-source
drwxrwxr-x  3 test test 4096 Dec 12 13:07 android.hardware.mytest-api
test@test:~/nx563j_xiaomi/out/soong/.intermediates/hardware/interfaces/mytest/aidl$ 

因为bp中backend只对ndk和java有开放,c++已经关闭了

android.hardware.mytest-V1-ndk 代表aidl相关的库
android.hardware.mytest-V1-ndk-source 代表aidl相关的源文件比如一些头文件或者bp,bn文件
有了上面的生成代码和库,我们就可以写一个服务端的程序了

5、编写服务端程序代码

准备好相关的源文件和xml,rc配置文件

test@test:~/nx563j_xiaomi/hardware/interfaces/mytest/aidl/default$ tree
.
|-- Android.bp
|-- MyTestImpl.cpp
|-- MyTestImpl.h
|-- android.hardware.mytest.rc
|-- main.cpp
`-- mytest-default.xml

0 directories, 6 files

分为两部分:

源码部分

MyTestImpl.cpp —Binder服务端的具体实现部分cpp

#define LOG_TAG "MyTestImpl"
#define LOG_NDEBUG 0

#include "MyTestImpl.h"


#include <log/log.h>

#include <stdio.h>

namespace aidl::android::hardware::mytest {
    
::ndk::ScopedAStatus MyTestImpl::test(::aidl::android::hardware::mytest::MyTestObj* _aidl_return) {
        *_aidl_return = mObj;
        ALOGE(" MyTestImpl::test ok");
        return ::ndk::ScopedAStatus::ok();
}


}  // namespace aidl::android::hardware::mytest

MyTestImpl.h—Binder服务端的具体实现部分头文件

#ifndef ANDROID_HARDWARE_MYTESTIMPL_H
#define ANDROID_HARDWARE_MYTESTIMPL_H

#include <aidl/android/hardware/mytest/BnMyTest.h>

namespace aidl::android::hardware::mytest {

class MyTestImpl : public BnMyTest {
  public:
    ::aidl::android::hardware::mytest::MyTestObj  mObj = {"hello",1};
    ::ndk::ScopedAStatus test(::aidl::android::hardware::mytest::MyTestObj* _aidl_return) override;

};

}  // namespace aidl::android::hardware::mytest

#endif  

main.cpp ----主程序入口cpp

#include "MyTestImpl.h"
#define LOG_TAG "MyTestImpl"
#define LOG_NDEBUG 0
#include <iostream>

#include <android-base/logging.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <stdio.h>
using aidl::android::hardware::mytest::MyTestImpl;

int main() {
    ABinderProcess_setThreadPoolMaxThreadCount(0);
    std::shared_ptr<MyTestImpl> test = ::ndk::SharedRefBase::make<MyTestImpl>();

    const std::string instance = std::string() + MyTestImpl::descriptor + "/default";
    printf("MyTestImpl instance =%s  sde =%p \n", instance.c_str(),test->asBinder().get());
    binder_status_t status =
          AServiceManager_addService(test->asBinder().get(), instance.c_str());
    CHECK_EQ(status, STATUS_OK);
    printf("MyTestImpl AServiceManager_addService status=%d \n", status);
    fflush(stdout);
    ABinderProcess_joinThreadPool();
    return EXIT_FAILURE;  // should not reach
}

bp和配置文件部分

Android.bp --编译可执行文件的bp

cc_binary {
    name: "android.hardware.mytest.example",
    relative_install_path: "hw",
    vendor: true,
    init_rc: ["android.hardware.mytest.rc"],
    vintf_fragments: ["mytest-default.xml"],
    shared_libs: [
        "android.hardware.mytest-V1-ndk", 
        "liblog",
        "libbase",
        "libcutils",
        "libutils",
        "libbinder_ndk",
    ],
    srcs: [
        "main.cpp",
        "MyTestImpl.cpp",
    ],
}

android.hardware.mytest.rc --开机自启动

service vendor.mytest-default /vendor/bin/hw/android.hardware.mytest.example
    class hal
    user root
    group root

mytest-default.xml ----声明接口到vintf中

<manifest version="1.0" type="device">
    <hal format="aidl">
        <name>android.hardware.mytest</name>
        <version>1</version>
        <interface>
        	<name>IMyTest</name>
        	<instance>default</instance>
    	</interface>
    </hal>
</manifest>

然后再执行编译命令:

 mmm hardware/interfaces/mytest/

出现如下成功提示:

aservices
============================================
[100% 10/10] Install: out/target/product/nx563j/vendor/bin/hw/android.hardware.mytest.example

#### build completed successfully (5 seconds) ####

到此基本上aidl业务模块就完成了,一个简单接口实现就好了

6、模块加入到兼容性矩阵中

应该添加到的目录即文件
hardware/interfaces/compatibility_matrices

test@test:~/nx563j_xiaomi/hardware/interfaces/compatibility_matrices$ ll
total 188
drwxrwxr-x  4 test test  4096 Dec 12 11:39 ./
drwxrwxr-x 54 test test  4096 Dec 12 11:43 ../
-rw-rw-r--  1 test test  2764 Mar  4  2023 Android.bp
-rw-rw-r--  1 test test  4860 Mar  4  2023 Android.mk
-rw-rw-r--  1 test test  2440 Mar  4  2023 CleanSpec.mk
drwxrwxr-x  2 test test  4096 Mar  4  2023 build/
-rw-rw-r--  1 test test   942 Mar  4  2023 clear_vars.mk
-rw-rw-r--  1 test test 15448 Mar  4  2023 compatibility_matrix.3.xml
-rw-rw-r--  1 test test 16709 Mar  4  2023 compatibility_matrix.4.xml
-rw-rw-r--  1 test test 18568 Mar  4  2023 compatibility_matrix.5.xml
-rw-rw-r--  1 test test 21273 Mar  4  2023 compatibility_matrix.6.xml
-rw-rw-r--  1 test test 26116 Dec 12 11:39 compatibility_matrix.7.xml
-rw-rw-r--  1 test test 26380 Dec 12 11:39 compatibility_matrix.current.xml
-rw-rw-r--  1 test test    56 Mar  4  2023 compatibility_matrix.empty.xml
-rw-rw-r--  1 test test  5349 Mar  4  2023 compatibility_matrix.mk
drwxrwxr-x  3 test test  4096 Mar  4  2023 exclude/
-rw-rw-r--  1 test test    41 Mar  4  2023 manifest.empty.xml

这里应该选数字最大的7和current两个xml文件
compatibility_matrix.7.xml
compatibility_matrix.current.xml
2个文件加入如下内容:

    <hal format="aidl">
        <name>android.hardware.mytest</name>
        <version>1</version>
        <interface>
        <name>IMyTest</name>
        <instance>default</instance>
        </interface>
    </hal>

7、增加对应selinux权限

这里直接做成了一个patch方便大家直接apply
到system/sepolicy/然后apply下面这个patch

add-selinux.patch

commit 7b459a68fe188b9f051850ac0629c868a31de2c2
Author: Your Name <you@example.com>
Date:   Sun Oct 8 10:03:22 2023 +0800

    add selinux for hal mytest
    
    Change-Id: I5feeec2aa30cd7fe0d306922225d512c10a0725e

diff --git a/prebuilts/api/33.0/private/hwservice_contexts b/prebuilts/api/33.0/private/hwservice_contexts
index 4a44dc58b..8092f0485 100644
--- a/prebuilts/api/33.0/private/hwservice_contexts
+++ b/prebuilts/api/33.0/private/hwservice_contexts
@@ -6,6 +6,7 @@ android.frameworks.schedulerservice::ISchedulingPolicyService   u:object_r:fwk_s
 android.frameworks.sensorservice::ISensorManager                u:object_r:fwk_sensor_hwservice:s0
 android.frameworks.stats::IStats                                u:object_r:fwk_stats_hwservice:s0
 android.hardware.atrace::IAtraceDevice                          u:object_r:hal_atrace_hwservice:s0
+android.hardware.mytest::IMyTest                                u:object_r:hal_mytest_hwservice:s0
 android.hardware.audio.effect::IEffectsFactory                  u:object_r:hal_audio_hwservice:s0
 android.hardware.audio::IDevicesFactory                         u:object_r:hal_audio_hwservice:s0
 android.hardware.authsecret::IAuthSecret                        u:object_r:hal_authsecret_hwservice:s0
diff --git a/prebuilts/api/33.0/private/service_contexts b/prebuilts/api/33.0/private/service_contexts
index 72fa16629..936638f18 100644
--- a/prebuilts/api/33.0/private/service_contexts
+++ b/prebuilts/api/33.0/private/service_contexts
@@ -15,6 +15,7 @@ android.hardware.contexthub.IContextHub/default                      u:object_r:
 android.hardware.drm.IDrmFactory/clearkey                            u:object_r:hal_drm_service:s0
 android.hardware.drm.ICryptoFactory/clearkey                         u:object_r:hal_drm_service:s0
 android.hardware.dumpstate.IDumpstateDevice/default                  u:object_r:hal_dumpstate_service:s0
+android.hardware.mytest.IMyTest/default                  	     u:object_r:hal_mytest_service:s0
 android.hardware.gnss.IGnss/default                                  u:object_r:hal_gnss_service:s0
 android.hardware.graphics.allocator.IAllocator/default               u:object_r:hal_graphics_allocator_service:s0
 android.hardware.graphics.composer3.IComposer/default                u:object_r:hal_graphics_composer_service:s0
diff --git a/private/hwservice_contexts b/private/hwservice_contexts
index 4a44dc58b..8092f0485 100644
--- a/private/hwservice_contexts
+++ b/private/hwservice_contexts
@@ -6,6 +6,7 @@ android.frameworks.schedulerservice::ISchedulingPolicyService   u:object_r:fwk_s
 android.frameworks.sensorservice::ISensorManager                u:object_r:fwk_sensor_hwservice:s0
 android.frameworks.stats::IStats                                u:object_r:fwk_stats_hwservice:s0
 android.hardware.atrace::IAtraceDevice                          u:object_r:hal_atrace_hwservice:s0
+android.hardware.mytest::IMyTest                                u:object_r:hal_mytest_hwservice:s0
 android.hardware.audio.effect::IEffectsFactory                  u:object_r:hal_audio_hwservice:s0
 android.hardware.audio::IDevicesFactory                         u:object_r:hal_audio_hwservice:s0
 android.hardware.authsecret::IAuthSecret                        u:object_r:hal_authsecret_hwservice:s0
diff --git a/private/service_contexts b/private/service_contexts
index 72fa16629..936638f18 100644
--- a/private/service_contexts
+++ b/private/service_contexts
@@ -15,6 +15,7 @@ android.hardware.contexthub.IContextHub/default                      u:object_r:
 android.hardware.drm.IDrmFactory/clearkey                            u:object_r:hal_drm_service:s0
 android.hardware.drm.ICryptoFactory/clearkey                         u:object_r:hal_drm_service:s0
 android.hardware.dumpstate.IDumpstateDevice/default                  u:object_r:hal_dumpstate_service:s0
+android.hardware.mytest.IMyTest/default                  	     u:object_r:hal_mytest_service:s0
 android.hardware.gnss.IGnss/default                                  u:object_r:hal_gnss_service:s0
 android.hardware.graphics.allocator.IAllocator/default               u:object_r:hal_graphics_allocator_service:s0
 android.hardware.graphics.composer3.IComposer/default                u:object_r:hal_graphics_composer_service:s0
diff --git a/vendor/file_contexts b/vendor/file_contexts
index 392a750fd..b87914600 100644
--- a/vendor/file_contexts
+++ b/vendor/file_contexts
@@ -105,6 +105,7 @@
 /(vendor|system/vendor)/bin/hw/wpa_supplicant                                 u:object_r:hal_wifi_supplicant_default_exec:s0
 /(vendor|system/vendor)/bin/install-recovery\.sh                              u:object_r:vendor_install_recovery_exec:s0
 /(vendor|system/vendor)/bin/vndservicemanager                                 u:object_r:vndservicemanager_exec:s0
+/(vendor|system/vendor)/bin/hw/android\.hardware\.mytest\.example         	 u:object_r:hal_mytest_default_exec:s0
 
 #############################
 # Same process HALs installed by platform into /vendor
diff --git a/vendor/hal-aidl-mytest.te b/vendor/hal-aidl-mytest.te
new file mode 100644
index 000000000..378df3826
--- /dev/null
+++ b/vendor/hal-aidl-mytest.te
@@ -0,0 +1,39 @@
+# type hal_mytest, domain;
+# type hal_mytest_service, vendor_service, service_manager_type;
+# type hal_mytest_hwservice, hwservice_manager_type, protected_hwservice;
+# type hal_mytest_default_exec, exec_type, vendor_file_type, file_type;
+# init_daemon_domain(hal_mytest);
+
+
+
+# get_prop(hal_mytest, hwservicemanager_prop)
+# add_hwservice(hal_mytest, hal_mytest_hwservice)
+# hwbinder_use(hal_mytest);
+
+
+# allow platform_app hal_mytest_hwservice:hwservice_manager { find };
+# allow platform_app hal_mytest:binder {call};
+
+
+hal_attribute(mytest);
+type hal_mytest_default, domain, mlstrustedsubject;
+hal_server_domain(hal_mytest_default, hal_mytest);
+type hal_mytest_default_exec, exec_type, vendor_file_type, file_type;
+init_daemon_domain(hal_mytest_default);
+
+#Allow hwbinder call form hal client to server
+binder_call(hal_mytest_client, hal_mytest_default_exec)
+
+#add hwservice related rules
+type hal_mytest_service, vendor_service, service_manager_type;
+type hal_mytest_hwservice, hwservice_manager_type, protected_hwservice;
+get_prop(hal_mytest, hwservicemanager_prop)
+add_service(hal_mytest_default, hal_mytest_service)
+add_hwservice(hal_mytest_server, hal_mytest_hwservice)
+allow hal_mytest_client hal_mytest_hwservice:hwservice_manager find;
+hal_client_domain(system_server, hal_mytest)
+hwbinder_use(hal_mytest);
+
+allow hal_mytest_default servicemanager:binder { call transfer };
+allow {  platform_app shell } hal_mytest_hwservice:hwservice_manager { find };
+allow {  platform_app shell } hal_mytest:binder {call};

8、编写一个测试模块,来测试一下aidl的hal是否正常运行

aidl目录下创建一个test_hal目录:

test_hal/
|-- Android.bp
`-- main.cpp

Android.bp

cc_binary {
    name: "test-hal-mytest",
    shared_libs: [
        "android.hardware.mytest-V1-ndk", 
        "liblog",
        "libbase",
        "libcutils",
        "libutils",
        "libbinder_ndk",
    ],
    srcs: [
        "main.cpp",
    ],
}

主要就是需要引入 “android.hardware.mytest-V1-ndk”, 这个依赖库

main.cpp

#define LOG_TAG "Test-HAL"
#define LOG_NDEBUG 0
#include <iostream>

#include <log/log.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <aidl/android/hardware/mytest/IMyTest.h>

#include <stdio.h>
using aidl::android::hardware::mytest::IMyTest;

int main() {
    printf("test hal mytest main 1\n");
    std::shared_ptr<IMyTest> service = IMyTest::fromBinder(ndk::SpAIBinder(AServiceManager_getService("android.hardware.mytest.IMyTest/default")));
    printf("test hal mytest service = %p\n",service.get());
    ALOGE("Test hal  MyTest");

    if (service == nullptr) {
        return -1;
    }
    ::aidl::android::hardware::mytest::MyTestObj obj;
    service->test(&obj);
    printf("test hal mytest main  test result  %s %d \n",obj.key.c_str(),obj.value);
    fflush(stdout);
    return EXIT_FAILURE;  // should not reach
}




9、device下面加入相关的程序进入编译到整机

device/nubia/nx563j/device.mk文件中加入如下:

PRODUCT_PACKAGES += \
    android.hardware.mytest \
    android.hardware.mytest.example \
    test-hal-mytest \

10、测试部分

测试方法
1、先看看是否mytest的hal服务是否开机自启动了
2、执行test-hal-mytest看看是否输出正常
在这里插入图片描述

更多framework干货请关注“千里马学框架”

AIDL接口实现应用层调用HAL服务 由于Google在Android 11及其之后的android版本中废弃了 HIDL作为 HAL接口的方式,官网推荐扩展了原有的 AIDL作为HAL的接口描述语言。AIDL后端指的就是AIDL生成的目标代码。 阅读详情

相关推荐

Android Aidl for hal开发案例

一次Aidl for hal的实现案例,包含bp编译、aidl接口、服务端、客户端、selinux的实现以及一些问题的解决。

TangYuanTuoHai的博客 4955

Android 11(R) Power HAL AIDL简析 -- 基本接口

1 前言 Android 11 引入了在 Android 中使用 AIDL 实现 HAL 的功能。这样就可以在不使用 HIDL 的情况下实现 Android 的部分代码。Power HAL模块即可以采用AIDL方式来实现。在Android 11中已经引入这个Power AIDL Interface,源码位于: /hardware/interfaces/power/aidl/ 在学习这部分之前,推荐阅读AIDL的相关知识,特别是Android 10之后引入的对稳定的 Android 接口定义语言 (AI

转载和创作优秀的博客 3521

Android的HAL转Aidl

本篇记录作者在把代码hal转换为aidl接口所碰到的问题,以及如何解决的总结。

qq_34150669的博客 2045

Android 11 创建自定义AIDL HAL

项目中需要在Android 11中自定义HAL,由于从Android 11开始,可以使用AIDL定义HAL,本文简单记录了AIDL的HAL创建方法。

gongxiancao的博客 3530

AIDL for HALs实战

Google 在Android 11引入了`AIDL for HALs`,旨在代替HIDL原先的作用。在之后的Android版本推荐使用AIDL 实现Hal层的访问。

qq_40731414的博客 1万+

Android12之aidl与hal直通(四十八)

AIDL+HAL直通模式。

Android系统攻城狮 3472

Android AIDL HAL开发实战(一)

前阵子有个AIDL HAL的开发需求,实现过程中遇到了不少问题。最近回顾时发现又忘了很多细节,正所谓好记性不如烂笔头,于是写下这篇。网上关于AIDL HAL的使用或说明一般比较简单,如果想了解复杂一些的使用可以阅读本篇。

青山渺渺 2307

AndroidQ 打通应用层到HAL层—(JNI服务和AIDL服务实现)

前面两篇文章实现了自定义HAL和HIDL服务,本篇接着往上层实现,这篇文章要写的是JNI服务和framework层AIDL服务实现,由AIDL服务调用JNI层的服务的函数,为了提供给上层APP使用 同样我们参照系统其他服务的方式来写,来到frameworks/base/services/core/jni目录下,这下面有许多JNI的服务,创建cpp文件com_android_server_am_HelloService.cpp,为什么要叫这个名字,因为等下我们实现的AIDL服务包名为”com.android.server.am” #include #include #include #inclu

Android AIDL 从入门到精通

AIDL 是 Android 特有的 IPC 进程间通讯方式 AIDL 的写法其实和绑定服务的代码差不多,IBander 也是 android 默认提供的一个 AIDL 接口 需要注意的是 5.0 之后,不能隐式启动 service,不能想以前一样定义 action 来启动服务了,尤其是不是跨应用启动服务,这也算是一种安全上的考虑 若是想非常详细的了解 AIDL ,请看慕课网的科普视频 AID...

Android 开发架构 894

Java + Selenium + TestNg + Allure Web UI 自动化

我们知道,在Python中针对Web UI自动化有Python + Selenium + Pytest/Unittest +Allure的技术栈。那么对于Java而言,也有其独特的Web UI 自动化技术栈。相同的,我们同样的运用Selenium框架,测试报告同样运用Allure。不同的是,我们运用的语言由Python转化为了Java,测试用例管理框架从Pytest转化为了TestNG。

qq_45594960的博客 1913

Agent 长期记忆三代演进:从 RAG 到 Memory Graph,mem0 / Zep / LangMem / Letta 深度横评

文章摘要 2026年,Agent长期记忆技术迎来关键突破,OpenAI、Anthropic等厂商通过扩大上下文窗口和推出记忆工具,推动长期记忆从工程补丁发展为独立技术层。本文通过分析三代记忆架构演进(RAG→结构化Fact→MemoryGraph)和四大方案(mem0/Zep/LangMem/Letta)的8维度横评,揭示以下核心观点: 长上下文≠长期记忆:128K上下文如同RAM,仍需硬盘式记忆层筛选和结构化存储,避免“Context Rot”导致的准确率下降。 三代架构演进: Gen1(RAG):向量检

LDZKKJ的博客 1422

【android12】 添加自定义系统服务,AIDL实现HAL Service层

系统路径:frameworks/base/core/java/android/app/IHelloWorldManager.aidl 2.添加AIDL接口实现类 系统路径:frameworks/base/core/java/android/app/HelloWorldManagerService.java 3.添加接口管理类HelloWorldManager.java 系统路径:frameworks/base/core/java/android/app/HelloWorldManager.java 4.在C

我不是程序员的博客 2837

基于QEMU的openEuler aarch64虚拟机快速部署与漏洞验证指南

本文提供了一份基于QEMU在个人电脑上快速部署openEuler aarch64虚拟机的详细指南。内容涵盖从软件准备、目录规划、QEMU安装、虚拟磁盘创建到系统安装与SSH配置的全过程,并以CVE-2024-1086内核漏洞为例,演示了如何在该虚拟环境中进行安全漏洞的验证与补丁测试,为安全研究和运维测试提供了一个低成本、高效率的ARM架构沙箱环境。

earth的博客 438

Android HAL 层框架分析以及代码示例

本文参考 《Android系统源代码情景分析》 一 硬件抽象层概述 二 开发Android硬件驱动程序 三 开发Android硬件抽象层模块 3.1 硬件抽象层模块文件 命名规范 3.2 硬件抽象层模块结构体 以及 硬件抽象层设备结构体 定义规范 3.3 编写硬件抽象层模块接口 四 开发Android硬件访问服务 4.1 定义硬件访问服务接口 4.2 实现硬件访问服务 4.3 实现硬...

奶牛养殖场小马 1万+

基于反相器的超声波发生和气泡检测电路

本文主要介绍了关于超声波的两种电路——基于反相器的振荡电路和基于逻辑们的气泡检测电路

xehagy的博客 1958

彻底解决Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource

Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource

renkai721的专栏 24万+

HAL: 将 HIDL 接口改造为 Stable AIDL

Android HAL 将 HIDL 接口改造为 Stable AIDL

fufudayo的博客 1万+

【算法】克里金kriging参数值预测模型

模型中特征值2个,目标值1个,data数据集如图所示。搭建kriging参数值预测模型。

weixin_48618536的博客 5059

Android 使用AIDL HAL

修改hardware/interfaces/automotive/audiocontrol/aidl的Android.bp文件将freeze改为false。修改AIDL 文件 添相应的接口更新接口 update-api冻结接口freeze-api编译中间文件6.修改兼容性矩形和device清单,service的清单按照上述的方式修改完成之后 在CarService应用端编译还是会出现错误找不到对应的接口。

dawnminghuang的专栏 4621

2024年全国青少年信息素养大赛初赛真题(算法创意实践挑战赛C++小学组:带解析)

2024全国青少年信息素养大赛C++算法创意实践挑战赛初赛真题及解析

王老师青少年编程 2809

电磁场仿真软件:Sonnet_(3).Sonnet用户界面与操作

Sonnet支持用户通过二次开发自定义工具,例如:编写Python脚本,实现自定义功能。将脚本保存为工具插件。在Sonnet中加载并使用自定义工具。# 示例:自定义工具 import sonnet def custom_tool(design , object , parameter , value) : """自定义工具示例,设置对象的指定参数。

kkchenjj的博客 1523

android hal学习——aidl,java service,jni编写

一、参考二、代码 1、aidl package android.os;interface IExampleService { void setVal(int val); int getVal();} 2、修改相应的Android.mk vim frameworks/base/Android.mk 找到下面的这句话:## READ ME: ####################

brightming的专栏 3359

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

实现自己的HAL-6 serivce 和aidl层的代码

serivce 和aidl层的代码 Z:\itop-3399_8.1\frameworks\base\core\java\android\os 在这个路径下创建IHelloWorldService.aidl /** * Copyright (c) 2007, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use t

yangbinbingA的博客 1550

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

android hal aidl升级部分-android framework车载手机系统开发

第一版本的aidl没有指定版本,只有一个aidl_api下面current文件夹即默认就是版本v1,那么如果后面有相关的接口修改呢?大概就是修改时候一定要考虑老版本的兼容问题,一般不删除原来接口和修改。可以看到这里的版本多了版本1,而且还带有hash号文件。Android.bp需要把原来V1版本的库变成V2。执行后相关的aidl_api目录多个一个版本目录。MyTestImpl.cpp增加相关方法实现。可以看到out临时文件目录多了V2相关的库。MyTestImpl.h增加相关方法引入。

learnframework的博客 2148
上一篇: android framework实战之VNDK深入剖析
下一篇: android hal aidl升级部分-android framework车载手机系统开发
千里马学框架
博客等级 码龄6年 1万+粉丝 650原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千里马学框架

帮助你了,就请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值