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 #include "Contexthub.h"
17 
18 #include <vector>
19 
20 namespace android {
21 namespace hardware {
22 namespace contexthub {
23 namespace V1_1 {
24 namespace implementation {
25 
26 using ::android::hardware::contexthub::V1_0::ContextHub;
27 using ::android::hardware::contexthub::V1_0::HubAppInfo;
28 using ::android::hardware::contexthub::V1_0::Result;
29 
30 namespace {
31 
32 constexpr uint32_t kMockHubId = 0;
33 
34 }  // anonymous namespace
35 
getHubs(getHubs_cb _hidl_cb)36 Return<void> Contexthub::getHubs(getHubs_cb _hidl_cb) {
37     ContextHub hub = {};
38     hub.name = "Mock Context Hub";
39     hub.vendor = "AOSP";
40     hub.toolchain = "n/a";
41     hub.platformVersion = 1;
42     hub.toolchainVersion = 1;
43     hub.hubId = kMockHubId;
44     hub.peakMips = 1;
45     hub.peakPowerDrawMw = 1;
46     hub.maxSupportedMsgLen = 4096;
47     hub.chrePlatformId = UINT64_C(0x476f6f6754000000);
48     hub.chreApiMajorVersion = 1;
49     hub.chreApiMinorVersion = 4;
50 
51     // Report a single mock hub
52     std::vector<ContextHub> hubs;
53     hubs.push_back(hub);
54 
55     _hidl_cb(hubs);
56     return Void();
57 }
58 
registerCallback(uint32_t hubId,const sp<IContexthubCallback> & cb)59 Return<Result> Contexthub::registerCallback(uint32_t hubId, const sp<IContexthubCallback>& cb) {
60     if (hubId == kMockHubId) {
61         mCallback = cb;
62         return Result::OK;
63     }
64     return Result::BAD_PARAMS;
65 }
66 
67 // We don't expose any nanoapps, therefore all nanoapp-related API calls return with BAD_PARAMS
sendMessageToHub(uint32_t,const ContextHubMsg &)68 Return<Result> Contexthub::sendMessageToHub(uint32_t /*hubId*/, const ContextHubMsg& /*msg*/) {
69     return Result::BAD_PARAMS;
70 }
71 
loadNanoApp(uint32_t,const NanoAppBinary &,uint32_t)72 Return<Result> Contexthub::loadNanoApp(uint32_t /*hubId*/, const NanoAppBinary& /*appBinary*/,
73                                        uint32_t /*transactionId*/) {
74     return Result::BAD_PARAMS;
75 }
76 
unloadNanoApp(uint32_t,uint64_t,uint32_t)77 Return<Result> Contexthub::unloadNanoApp(uint32_t /*hubId*/, uint64_t /*appId*/,
78                                          uint32_t /*transactionId*/) {
79     return Result::BAD_PARAMS;
80 }
81 
enableNanoApp(uint32_t,uint64_t,uint32_t)82 Return<Result> Contexthub::enableNanoApp(uint32_t /*hubId*/, uint64_t /*appId*/,
83                                          uint32_t /*transactionId*/) {
84     return Result::BAD_PARAMS;
85 }
86 
disableNanoApp(uint32_t,uint64_t,uint32_t)87 Return<Result> Contexthub::disableNanoApp(uint32_t /*hubId*/, uint64_t /*appId*/,
88                                           uint32_t /*transactionId*/) {
89     return Result::BAD_PARAMS;
90 }
91 
queryApps(uint32_t hubId)92 Return<Result> Contexthub::queryApps(uint32_t hubId) {
93     if (hubId == kMockHubId && mCallback != nullptr) {
94         std::vector<HubAppInfo> nanoapps;
95         mCallback->handleAppsInfo(nanoapps);
96         return Result::OK;
97     }
98     return Result::BAD_PARAMS;
99 }
100 
onSettingChanged(Setting,SettingValue)101 Return<void> Contexthub::onSettingChanged(Setting /*setting*/, SettingValue /*newValue*/) {
102     return Void();
103 }
104 
105 }  // namespace implementation
106 }  // namespace V1_1
107 }  // namespace contexthub
108 }  // namespace hardware
109 }  // namespace android
110