mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 10:44:41 +00:00
Add new contexthub HAL 1.2 methods to default impl
Bug: 166846988 Test: Run VTS against default HAL Change-Id: I158a49e54f340a2ba25f79894d6ec465070326f8
This commit is contained in:
@@ -23,10 +23,29 @@ namespace contexthub {
|
||||
namespace V1_1 {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::contexthub::V1_0::Result;
|
||||
|
||||
Return<void> Contexthub::onSettingChanged(Setting /*setting*/, SettingValue /*newValue*/) {
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<Result> Contexthub::registerCallback(uint32_t hubId, const sp<IContexthubCallback>& cb) {
|
||||
if (hubId == kMockHubId) {
|
||||
mCallback = cb;
|
||||
return Result::OK;
|
||||
}
|
||||
return Result::BAD_PARAMS;
|
||||
}
|
||||
|
||||
Return<Result> Contexthub::queryApps(uint32_t hubId) {
|
||||
if (hubId == kMockHubId && mCallback != nullptr) {
|
||||
std::vector<HubAppInfo> nanoapps;
|
||||
mCallback->handleAppsInfo(nanoapps);
|
||||
return Result::OK;
|
||||
}
|
||||
return Result::BAD_PARAMS;
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_1
|
||||
} // namespace contexthub
|
||||
|
||||
@@ -27,9 +27,19 @@ namespace implementation {
|
||||
|
||||
class Contexthub
|
||||
: public ::android::hardware::contexthub::V1_X::implementation::ContextHub<IContexthub> {
|
||||
using Result = ::android::hardware::contexthub::V1_0::Result;
|
||||
|
||||
public:
|
||||
// Methods from V1_0::IContexthub
|
||||
Return<Result> registerCallback(uint32_t hubId, const sp<IContexthubCallback>& cb) override;
|
||||
|
||||
Return<Result> queryApps(uint32_t hubId) override;
|
||||
|
||||
// Methods from V1_1::IContexthub
|
||||
Return<void> onSettingChanged(Setting setting, SettingValue newValue) override;
|
||||
|
||||
private:
|
||||
sp<IContexthubCallback> mCallback;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
@@ -41,6 +41,7 @@ cc_binary {
|
||||
],
|
||||
header_libs: [
|
||||
"android.hardware.contexthub@1.X-common-impl",
|
||||
"android.hardware.contexthub@1.X-common-utils",
|
||||
],
|
||||
vintf_fragments: ["android.hardware.contexthub@1.2.xml"],
|
||||
}
|
||||
|
||||
@@ -17,23 +17,47 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
using ::android::hardware::contexthub::V1_0::Result;
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace contexthub {
|
||||
namespace V1_2 {
|
||||
namespace implementation {
|
||||
|
||||
// TODO(b/166846988): Implement new methods.
|
||||
Return<Result> Contexthub::registerCallback_1_2(uint32_t /* hubId */,
|
||||
const sp<IContexthubCallback>& /* cb */) {
|
||||
return Result::UNKNOWN_FAILURE;
|
||||
using ::android::hardware::contexthub::V1_0::Result;
|
||||
using ::android::hardware::contexthub::V1_X::implementation::IContextHubCallbackWrapperV1_0;
|
||||
using ::android::hardware::contexthub::V1_X::implementation::IContextHubCallbackWrapperV1_2;
|
||||
|
||||
Return<Result> Contexthub::registerCallback(uint32_t hubId,
|
||||
const sp<V1_0::IContexthubCallback>& cb) {
|
||||
if (hubId == kMockHubId) {
|
||||
mCallback = new IContextHubCallbackWrapperV1_0(cb);
|
||||
return Result::OK;
|
||||
}
|
||||
return Result::BAD_PARAMS;
|
||||
}
|
||||
|
||||
Return<Result> Contexthub::queryApps(uint32_t hubId) {
|
||||
if (hubId == kMockHubId && mCallback != nullptr) {
|
||||
std::vector<V1_2::HubAppInfo> nanoapps;
|
||||
mCallback->handleAppsInfo(nanoapps);
|
||||
return Result::OK;
|
||||
}
|
||||
return Result::BAD_PARAMS;
|
||||
}
|
||||
|
||||
Return<Result> Contexthub::registerCallback_1_2(uint32_t hubId,
|
||||
const sp<V1_2::IContexthubCallback>& cb) {
|
||||
if (hubId == kMockHubId) {
|
||||
mCallback = new IContextHubCallbackWrapperV1_2(cb);
|
||||
return Result::OK;
|
||||
}
|
||||
return Result::BAD_PARAMS;
|
||||
}
|
||||
|
||||
// We don't expose any nanoapps, therefore all nanoapp-related API calls return with BAD_PARAMS
|
||||
Return<Result> Contexthub::sendMessageToHub_1_2(uint32_t /* hubId */,
|
||||
const ContextHubMsg& /* msg */) {
|
||||
return Result::UNKNOWN_FAILURE;
|
||||
return Result::BAD_PARAMS;
|
||||
}
|
||||
|
||||
Return<void> Contexthub::onSettingChanged(SettingV1_1 /*setting*/, SettingValue /*newValue*/) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "ContextHub.h"
|
||||
#include "IContextHubCallbackWrapper.h"
|
||||
|
||||
#include <android/hardware/contexthub/1.2/IContexthub.h>
|
||||
|
||||
@@ -29,20 +30,32 @@ class Contexthub
|
||||
: public ::android::hardware::contexthub::V1_X::implementation::ContextHub<IContexthub> {
|
||||
using ContextHubMsg = ::android::hardware::contexthub::V1_2::ContextHubMsg;
|
||||
using IContexthubCallback = ::android::hardware::contexthub::V1_2::IContexthubCallback;
|
||||
using IContextHubCallbackWrapperBase =
|
||||
::android::hardware::contexthub::V1_X::implementation::IContextHubCallbackWrapperBase;
|
||||
using Result = ::android::hardware::contexthub::V1_0::Result;
|
||||
using SettingValue = ::android::hardware::contexthub::V1_1::SettingValue;
|
||||
using SettingV1_1 = ::android::hardware::contexthub::V1_1::Setting;
|
||||
|
||||
public:
|
||||
Return<Result> registerCallback_1_2(uint32_t hubId, const sp<IContexthubCallback>& cb) override;
|
||||
// Methods from V1_0::IContexthub
|
||||
Return<Result> registerCallback(uint32_t hubId,
|
||||
const sp<V1_0::IContexthubCallback>& cb) override;
|
||||
|
||||
Return<Result> sendMessageToHub_1_2(uint32_t hubId, const ContextHubMsg& msg) override;
|
||||
Return<Result> queryApps(uint32_t hubId) override;
|
||||
|
||||
// Methods from V1_1::IContexthub
|
||||
Return<void> onSettingChanged(SettingV1_1 setting, SettingValue newValue) override;
|
||||
|
||||
// Methods from V1_2::IContexthub
|
||||
Return<void> onSettingChanged_1_2(Setting setting, SettingValue newValue) override;
|
||||
|
||||
Return<Result> registerCallback_1_2(uint32_t hubId,
|
||||
const sp<V1_2::IContexthubCallback>& cb) override;
|
||||
|
||||
Return<Result> sendMessageToHub_1_2(uint32_t hubId, const ContextHubMsg& msg) override;
|
||||
|
||||
private:
|
||||
sp<IContextHubCallbackWrapperBase> mCallback;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
@@ -60,14 +60,6 @@ struct ContextHub : public IContextHubInterface {
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<Result> registerCallback(uint32_t hubId, const sp<IContexthubCallback>& cb) override {
|
||||
if (hubId == kMockHubId) {
|
||||
mCallback = cb;
|
||||
return Result::OK;
|
||||
}
|
||||
return Result::BAD_PARAMS;
|
||||
}
|
||||
|
||||
// We don't expose any nanoapps, therefore all nanoapp-related API calls return with BAD_PARAMS
|
||||
Return<Result> sendMessageToHub(uint32_t /*hubId*/, const ContextHubMsg& /*msg*/) override {
|
||||
return Result::BAD_PARAMS;
|
||||
@@ -93,19 +85,8 @@ struct ContextHub : public IContextHubInterface {
|
||||
return Result::BAD_PARAMS;
|
||||
}
|
||||
|
||||
Return<Result> queryApps(uint32_t hubId) override {
|
||||
if (hubId == kMockHubId && mCallback != nullptr) {
|
||||
std::vector<HubAppInfo> nanoapps;
|
||||
mCallback->handleAppsInfo(nanoapps);
|
||||
return Result::OK;
|
||||
}
|
||||
return Result::BAD_PARAMS;
|
||||
}
|
||||
|
||||
private:
|
||||
protected:
|
||||
static constexpr uint32_t kMockHubId = 0;
|
||||
|
||||
sp<IContexthubCallback> mCallback;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
3
contexthub/common/default/1.X/OWNERS
Normal file
3
contexthub/common/default/1.X/OWNERS
Normal file
@@ -0,0 +1,3 @@
|
||||
arthuri@google.com
|
||||
bduddie@google.com
|
||||
stange@google.com
|
||||
30
contexthub/common/default/1.X/utils/Android.bp
Normal file
30
contexthub/common/default/1.X/utils/Android.bp
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// Copyright (C) 2020 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
cc_library_headers {
|
||||
name: "android.hardware.contexthub@1.X-common-utils",
|
||||
vendor_available: true,
|
||||
defaults: ["hidl_defaults"],
|
||||
export_include_dirs: ["."],
|
||||
shared_libs: [
|
||||
"android.hardware.contexthub@1.0",
|
||||
"android.hardware.contexthub@1.1",
|
||||
"android.hardware.contexthub@1.2",
|
||||
"libbinder",
|
||||
"libcutils",
|
||||
"libhidlbase",
|
||||
"libutils",
|
||||
],
|
||||
}
|
||||
123
contexthub/common/default/1.X/utils/IContextHubCallbackWrapper.h
Normal file
123
contexthub/common/default/1.X/utils/IContextHubCallbackWrapper.h
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_HARDWARE_CONTEXTHUB_V1_X_ICONTEXTHUBCALLBACKWRAPPER_H
|
||||
#define ANDROID_HARDWARE_CONTEXTHUB_V1_X_ICONTEXTHUBCALLBACKWRAPPER_H
|
||||
|
||||
#include "android/hardware/contexthub/1.0/IContexthub.h"
|
||||
#include "android/hardware/contexthub/1.0/IContexthubCallback.h"
|
||||
#include "android/hardware/contexthub/1.0/types.h"
|
||||
#include "android/hardware/contexthub/1.2/IContexthubCallback.h"
|
||||
#include "android/hardware/contexthub/1.2/types.h"
|
||||
|
||||
#include <utils/LightRefBase.h>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace contexthub {
|
||||
namespace V1_X {
|
||||
namespace implementation {
|
||||
|
||||
inline V1_0::ContextHubMsg convertToOldMsg(V1_2::ContextHubMsg msg) {
|
||||
return msg.msg_1_0;
|
||||
}
|
||||
|
||||
inline hidl_vec<V1_0::HubAppInfo> convertToOldAppInfo(hidl_vec<V1_2::HubAppInfo> appInfos) {
|
||||
hidl_vec<V1_0::HubAppInfo> convertedInfo(appInfos.size());
|
||||
for (int i = 0; i < appInfos.size(); ++i) {
|
||||
convertedInfo[i] = appInfos[i].info_1_0;
|
||||
}
|
||||
|
||||
return convertedInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* The IContexthubCallback classes below abstract away the common logic between both the V1.0, and
|
||||
* V1.2 versions of the Contexthub HAL callback interface. This allows users of these classes to
|
||||
* only care about the HAL version at init time and then interact with either version of the
|
||||
* callback without worrying about the class type by utilizing the base class.
|
||||
*/
|
||||
class IContextHubCallbackWrapperBase : public VirtualLightRefBase {
|
||||
public:
|
||||
virtual Return<void> handleClientMsg(V1_2::ContextHubMsg msg) = 0;
|
||||
|
||||
virtual Return<void> handleTxnResult(uint32_t txnId, V1_0::TransactionResult result) = 0;
|
||||
|
||||
virtual Return<void> handleHubEvent(V1_0::AsyncEventType evt) = 0;
|
||||
|
||||
virtual Return<void> handleAppAbort(uint64_t appId, uint32_t abortCode) = 0;
|
||||
|
||||
virtual Return<void> handleAppsInfo(hidl_vec<V1_2::HubAppInfo> appInfo) = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class ContextHubCallbackWrapper : public IContextHubCallbackWrapperBase {
|
||||
public:
|
||||
ContextHubCallbackWrapper(sp<T> callback) : mCallback(callback){};
|
||||
|
||||
virtual Return<void> handleClientMsg(V1_2::ContextHubMsg msg) override {
|
||||
return mCallback->handleClientMsg(convertToOldMsg(msg));
|
||||
}
|
||||
|
||||
virtual Return<void> handleTxnResult(uint32_t txnId, V1_0::TransactionResult result) override {
|
||||
return mCallback->handleTxnResult(txnId, result);
|
||||
}
|
||||
|
||||
virtual Return<void> handleHubEvent(V1_0::AsyncEventType evt) override {
|
||||
return mCallback->handleHubEvent(evt);
|
||||
}
|
||||
|
||||
virtual Return<void> handleAppAbort(uint64_t appId, uint32_t abortCode) override {
|
||||
return mCallback->handleAppAbort(appId, abortCode);
|
||||
}
|
||||
|
||||
virtual Return<void> handleAppsInfo(hidl_vec<V1_2::HubAppInfo> appInfo) override {
|
||||
return mCallback->handleAppsInfo(convertToOldAppInfo(appInfo));
|
||||
}
|
||||
|
||||
protected:
|
||||
sp<T> mCallback;
|
||||
};
|
||||
|
||||
class IContextHubCallbackWrapperV1_0 : public ContextHubCallbackWrapper<V1_0::IContexthubCallback> {
|
||||
public:
|
||||
IContextHubCallbackWrapperV1_0(sp<V1_0::IContexthubCallback> callback)
|
||||
: ContextHubCallbackWrapper(callback){};
|
||||
};
|
||||
|
||||
class IContextHubCallbackWrapperV1_2 : public ContextHubCallbackWrapper<V1_2::IContexthubCallback> {
|
||||
public:
|
||||
IContextHubCallbackWrapperV1_2(sp<V1_2::IContexthubCallback> callback)
|
||||
: ContextHubCallbackWrapper(callback){};
|
||||
|
||||
Return<void> handleClientMsg(V1_2::ContextHubMsg msg) override {
|
||||
return mCallback->handleClientMsg_1_2(msg);
|
||||
}
|
||||
|
||||
Return<void> handleAppsInfo(hidl_vec<V1_2::HubAppInfo> appInfo) override {
|
||||
return mCallback->handleAppsInfo_1_2(appInfo);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_X
|
||||
} // namespace contexthub
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // ANDROID_HARDWARE_CONTEXTHUB_V1_X_ICONTEXTHUBCALLBACKWRAPPER_H
|
||||
Reference in New Issue
Block a user