android - 定义和实现 HIDL 接口(interface)

标签 android android-source hal

出于测试目的,我想创建一个 HIDL 接口(interface) + 实现并将组合作为系统服务运行。为此,我定义了 IGuotie.hal 接口(interface):

package android.hardware.guotie@2.0;

interface IGuotie {
    add(int32_t i, int32_t k) generates (int32_t result);
};

以下文件用于实现接口(interface)

国铁.h

#pragma once

#include <android/hardware/guotie/2.0/IGuotie.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>

namespace android {
namespace hardware {
namespace guotie {
namespace V2_0 {
namespace implementation {

using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;

struct Guotie : public IGuotie {
    // Methods from ::android::hardware::guotie::V2_0::IGuotie follow.
    Return<int32_t> add(int32_t i, int32_t k) override;

    // Methods from ::android::hidl::base::V1_0::IBase follow.
   static IGuotie* getInstance(void); 
};

}  // namespace implementation
}  // namespace V2_0
}  // namespace guotie
}  // namespace hardware
} 

锅贴.cpp

#include "Guotie.h"

namespace android {
namespace hardware {
namespace guotie {
namespace V2_0 {
namespace implementation {

// Methods from ::android::hardware::guotie::V2_0::IGuotie follow.
Return<int32_t> Guotie::add(int32_t i, int32_t k) {
    return i + k;
}

IGuotie *Guotie::getInstance(void) {
    return new Guotie();
}

}  // namespace implementation
}  // namespace V2_0
}  // namespace guotie
}  // namespace hardware
} 

服务.cpp

#define LOG_TAG "android.hardware.graphics.allocator@2.0-service"

#include <android/hardware/guotie/2.0/IGuotie.h>

#include <hidl/LegacySupport.h>

#include "Guotie.h"

using android::hardware::guotie::V2_0::IGuotie;
using android::hardware::guotie::V2_0::implementation::Guotie;
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using android::sp;

int main() {
      int res;
      android::sp<IGuotie> ser = Guotie::getInstance();
      ALOGE("simp main");
      configureRpcThreadpool(1, true /*callerWillJoin*/);

      if (ser != nullptr) {
          res = ser->registerAsService();
          if(res != 0)
            ALOGE("Can't register instance of GuotieHardware, nullptr");
      } else {
          ALOGE("Can't create instance of GuotieHardware, nullptr");
       }

      joinRpcThreadpool();

      return 0; // should never get here
}

android.hardware.guotie@2.0-service.rc

service guotieserver /vendor/bin/hw/android.hardware.guotie@2.0-service
    class hal
    user root
    group root
    seclabel u:r:su:s0

Android.bp

hidl_interface {
    name: "android.hardware.guotie@2.0",
    root: "android.hardware",
    vndk: {
        enabled: true,
    },
    srcs: [
        "IGuotie.hal",
    ],
    interfaces: [
        "android.hidl.base@1.0",
    ],
    gen_java: true,
}

构建结果出现以下错误信息

FAILED: out/target/product/generic/obj/PACKAGING/vndk_intermediates/check-list-timestamp
/bin/bash -c "(( diff --old-line-format=\"Removed %L\"    --new-line-format=\"Added %L\"      --unchanged-line-format=\"\"    build/make/target/product/gsi/29.txt out/target/product/generic/obj/PACKAGING/vndk_intermediates/libs.txt       || ( echo -e \" error: VNDK library list has been changed.\\n\" \"       Changing the VNDK library list is not allowed in API locked branches.\"; exit 1 )) ) && (mkdir -p out/target/product/generic/obj/PACKAGING/vndk_intermediates/ ) && (touch out/target/product/generic/obj/PACKAGING/vndk_intermediates/check-list-timestamp )"
Removed VNDK-code: android.hardware.guotie@2.0.so
Added VNDK-core: android.hardware.guotie@2.0.so
 error: VNDK library list has been changed.
        Changing the VNDK library list is not allowed in API locked branches.

一些文章建议添加(在我的例子中)android.hardware.guotie@2.0.sobuild/make/target/product/vndk/28.txt .但是,vndk 文件夹不存在。相反,我将它添加到 build/make/target/product/gsi/29.txtcurrent.txt 但构建仍然失败(我按字母顺序添加它)。有什么建议吗?

最佳答案

android.hardware 添加接口(interface)通常只能由谷歌自己完成。供应商 HIDL 接口(interface)不是 VNDK 的一部分。

您可能应该将自己视为供应商,只需将此部分从您的 Android.bp 中删除即可。 :

vndk: {
    enabled: true,
},

并将命名空间更改为vendor.<you>.guotie

有关 VNDK 是什么的更多信息,请参阅官方文档:https://source.android.com/devices/architecture/vndk .

关于android - 定义和实现 HIDL 接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61363638/

相关文章:

android - react native 矢量图标 :processReleaseResources

java - 使用 uri 将文件读取到字节数组

android - 基于语言在 webview 中加载本地 HTML 文件,如果找不到文件则使用默认值

android-source - 为我的平板电脑构建 AOSP

无法对齐 "pointer targets signedness"

hateoas - Spring HATEOAS 与 Traverson

java - 如何更改 ViewPager 幻灯片上 fragment 的内容?

android - UiAutomation vs AccessibilityService

android - 尝试编译 AOSP 7.1.1 第 6 版时缺少 'libaudiopolicyservice_intermediates"?

java - 使用 RestTemplate 使用 Spring Hateoas Restservice