blob: 73d06319dd87af402d7e36ffbdbe9387d409f676 [file] [log] [blame]
Arthur Ishiguro46c2bd02020-10-06 11:05:17 -07001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_HARDWARE_CONTEXTHUB_V1_X_CONTEXTHUB_H
18#define ANDROID_HARDWARE_CONTEXTHUB_V1_X_CONTEXTHUB_H
19
20#include <android/hardware/contexthub/1.0/IContexthub.h>
21#include <android/hardware/contexthub/1.0/types.h>
22#include <hidl/Status.h>
23
24namespace android {
25namespace hardware {
26namespace contexthub {
27namespace V1_X {
28namespace implementation {
29
30template <class IContextHubInterface>
31struct ContextHub : public IContextHubInterface {
32 using ContextHubMsg = ::android::hardware::contexthub::V1_0::ContextHubMsg;
33 using HubAppInfo = ::android::hardware::contexthub::V1_0::HubAppInfo;
34 using IContexthubCallback = ::android::hardware::contexthub::V1_0::IContexthubCallback;
35 using NanoAppBinary = ::android::hardware::contexthub::V1_0::NanoAppBinary;
36 using Result = ::android::hardware::contexthub::V1_0::Result;
37 using getHubs_cb = ::android::hardware::contexthub::V1_0::IContexthub::getHubs_cb;
38
39 public:
40 Return<void> getHubs(getHubs_cb _hidl_cb) override {
41 ::android::hardware::contexthub::V1_0::ContextHub hub = {};
42 hub.name = "Mock Context Hub";
43 hub.vendor = "AOSP";
44 hub.toolchain = "n/a";
45 hub.platformVersion = 1;
46 hub.toolchainVersion = 1;
47 hub.hubId = kMockHubId;
48 hub.peakMips = 1;
49 hub.peakPowerDrawMw = 1;
50 hub.maxSupportedMsgLen = 4096;
51 hub.chrePlatformId = UINT64_C(0x476f6f6754000000);
52 hub.chreApiMajorVersion = 1;
53 hub.chreApiMinorVersion = 4;
54
55 // Report a single mock hub
56 std::vector<::android::hardware::contexthub::V1_0::ContextHub> hubs;
57 hubs.push_back(hub);
58
59 _hidl_cb(hubs);
60 return Void();
61 }
62
63 Return<Result> registerCallback(uint32_t hubId, const sp<IContexthubCallback>& cb) override {
64 if (hubId == kMockHubId) {
65 mCallback = cb;
66 return Result::OK;
67 }
68 return Result::BAD_PARAMS;
69 }
70
71 // We don't expose any nanoapps, therefore all nanoapp-related API calls return with BAD_PARAMS
72 Return<Result> sendMessageToHub(uint32_t /*hubId*/, const ContextHubMsg& /*msg*/) override {
73 return Result::BAD_PARAMS;
74 }
75
76 Return<Result> loadNanoApp(uint32_t /*hubId*/, const NanoAppBinary& /*appBinary*/,
77 uint32_t /*transactionId*/) override {
78 return Result::BAD_PARAMS;
79 }
80
81 Return<Result> unloadNanoApp(uint32_t /*hubId*/, uint64_t /*appId*/,
82 uint32_t /*transactionId*/) override {
83 return Result::BAD_PARAMS;
84 }
85
86 Return<Result> enableNanoApp(uint32_t /*hubId*/, uint64_t /*appId*/,
87 uint32_t /*transactionId*/) override {
88 return Result::BAD_PARAMS;
89 }
90
91 Return<Result> disableNanoApp(uint32_t /*hubId*/, uint64_t /*appId*/,
92 uint32_t /*transactionId*/) override {
93 return Result::BAD_PARAMS;
94 }
95
96 Return<Result> queryApps(uint32_t hubId) override {
97 if (hubId == kMockHubId && mCallback != nullptr) {
98 std::vector<HubAppInfo> nanoapps;
99 mCallback->handleAppsInfo(nanoapps);
100 return Result::OK;
101 }
102 return Result::BAD_PARAMS;
103 }
104
105 private:
106 static constexpr uint32_t kMockHubId = 0;
107
108 sp<IContexthubCallback> mCallback;
109};
110
111} // namespace implementation
112} // namespace V1_X
113} // namespace contexthub
114} // namespace hardware
115} // namespace android
116
117#endif // ANDROID_HARDWARE_CONTEXTHUB_V1_X_CONTEXTHUB_H