1 /*
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 
24 namespace android {
25 namespace hardware {
26 namespace contexthub {
27 namespace V1_X {
28 namespace implementation {
29 
30 template <class IContextHubInterface>
31 struct 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:
getHubsContextHub40     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     // We don't expose any nanoapps, therefore all nanoapp-related API calls return with BAD_PARAMS
sendMessageToHubContextHub64     Return<Result> sendMessageToHub(uint32_t /*hubId*/, const ContextHubMsg& /*msg*/) override {
65         return Result::BAD_PARAMS;
66     }
67 
loadNanoAppContextHub68     Return<Result> loadNanoApp(uint32_t /*hubId*/, const NanoAppBinary& /*appBinary*/,
69                                uint32_t /*transactionId*/) override {
70         return Result::BAD_PARAMS;
71     }
72 
unloadNanoAppContextHub73     Return<Result> unloadNanoApp(uint32_t /*hubId*/, uint64_t /*appId*/,
74                                  uint32_t /*transactionId*/) override {
75         return Result::BAD_PARAMS;
76     }
77 
enableNanoAppContextHub78     Return<Result> enableNanoApp(uint32_t /*hubId*/, uint64_t /*appId*/,
79                                  uint32_t /*transactionId*/) override {
80         return Result::BAD_PARAMS;
81     }
82 
disableNanoAppContextHub83     Return<Result> disableNanoApp(uint32_t /*hubId*/, uint64_t /*appId*/,
84                                   uint32_t /*transactionId*/) override {
85         return Result::BAD_PARAMS;
86     }
87 
88   protected:
89     static constexpr uint32_t kMockHubId = 0;
90 };
91 
92 }  // namespace implementation
93 }  // namespace V1_X
94 }  // namespace contexthub
95 }  // namespace hardware
96 }  // namespace android
97 
98 #endif  // ANDROID_HARDWARE_CONTEXTHUB_V1_X_CONTEXTHUB_H
99