定义并实现HIDL接口

问题描述 投票:1回答:1

为了测试的目的,我想创建一个HIDL接口+实现,并把这个组合作为一个系统服务来运行。为此,我定义了 IGuotie.hal 接口。

package [email protected];

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

以下文件用于实现该接口 Guotie.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
} 

Guotie.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
} 

service.cpp

#define LOG_TAG "[email protected]"

#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
}

[email protected]

service guotieserver /vendor/bin/hw/[email protected]
    class hal
    user root
    group root
    seclabel u:r:su:s0

Android.bp

hidl_interface {
    name: "[email protected]",
    root: "android.hardware",
    vndk: {
        enabled: true,
    },
    srcs: [
        "IGuotie.hal",
    ],
    interfaces: [
        "[email protected]",
    ],
    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: [email protected]
Added VNDK-core: [email protected]
 error: VNDK library list has been changed.
        Changing the VNDK library list is not allowed in API locked branches.

有些文章建议增加(在我的情况下)。[email protected]build/make/target/product/vndk/28.txt. 然而,vndk文件夹并不存在。相反,我把它添加到 build/make/target/product/gsi/29.txtcurrent.txt 但构建仍然失败(我是按字母顺序添加的)。有什么建议吗?

android android-source hal hidl
1个回答
0
投票

添加一个接口到 android.hardware 通常只由Google自己完成。供应商的HIDL接口不是VNDK的一部分。

您可能应该将自己视为供应商,并将这部分从您的 Android.bp:

vndk: {
    enabled: true,
},

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

关于什么是VNDK的更多信息,请参见官方文档。https:/source.android.comdevicesarchitecturevndk。.

© www.soinside.com 2019 - 2024. All rights reserved.