blob: 5713a1bf0825d902937f60eab7f62769034b3dd6 [file] [log] [blame]
Arthur Ishiguroa257b782021-08-04 10:40:29 -07001/*
2 * Copyright (C) 2021 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#include "contexthub-impl/ContextHub.h"
18
Matthew Sedamadfd5572023-11-21 05:53:00 -080019namespace aidl::android::hardware::contexthub {
Arthur Ishiguroa257b782021-08-04 10:40:29 -070020
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000021using ::ndk::ScopedAStatus;
22
23ScopedAStatus ContextHub::getContextHubs(std::vector<ContextHubInfo>* out_contextHubInfos) {
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000024 ContextHubInfo hub = {};
25 hub.name = "Mock Context Hub";
26 hub.vendor = "AOSP";
27 hub.toolchain = "n/a";
28 hub.id = kMockHubId;
29 hub.peakMips = 1;
30 hub.maxSupportedMessageLengthBytes = 4096;
31 hub.chrePlatformId = UINT64_C(0x476f6f6754000000);
32 hub.chreApiMajorVersion = 1;
33 hub.chreApiMinorVersion = 6;
Matthew Sedamadfd5572023-11-21 05:53:00 -080034 hub.supportsReliableMessages = false;
Arthur Ishiguroa257b782021-08-04 10:40:29 -070035
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000036 out_contextHubInfos->push_back(hub);
37
Matthew Sedamadfd5572023-11-21 05:53:00 -080038 return ScopedAStatus::ok();
Arthur Ishiguroa257b782021-08-04 10:40:29 -070039}
40
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000041// We don't expose any nanoapps for the default impl, therefore all nanoapp-related APIs fail.
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000042ScopedAStatus ContextHub::loadNanoapp(int32_t /* in_contextHubId */,
43 const NanoappBinary& /* in_appBinary */,
44 int32_t /* in_transactionId */) {
45 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
46}
47
48ScopedAStatus ContextHub::unloadNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */,
49 int32_t /* in_transactionId */) {
50 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
51}
52
53ScopedAStatus ContextHub::disableNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */,
54 int32_t /* in_transactionId */) {
55 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
56}
57
58ScopedAStatus ContextHub::enableNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */,
59 int32_t /* in_transactionId */) {
60 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
61}
62
63ScopedAStatus ContextHub::onSettingChanged(Setting /* in_setting */, bool /*in_enabled */) {
Matthew Sedamadfd5572023-11-21 05:53:00 -080064 return ScopedAStatus::ok();
Arthur Ishiguroa257b782021-08-04 10:40:29 -070065}
66
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000067ScopedAStatus ContextHub::queryNanoapps(int32_t in_contextHubId) {
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000068 if (in_contextHubId == kMockHubId && mCallback != nullptr) {
69 std::vector<NanoappInfo> nanoapps;
70 mCallback->handleNanoappInfo(nanoapps);
Matthew Sedamadfd5572023-11-21 05:53:00 -080071 return ScopedAStatus::ok();
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000072 } else {
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000073 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000074 }
Arthur Ishiguroa257b782021-08-04 10:40:29 -070075}
76
Matthew Sedamd70f84d2023-03-06 18:34:24 +000077ScopedAStatus ContextHub::getPreloadedNanoappIds(int32_t /* in_contextHubId */,
78 std::vector<int64_t>* out_preloadedNanoappIds) {
Arthur Ishigurofd5e65c2022-11-08 16:49:47 +000079 if (out_preloadedNanoappIds == nullptr) {
80 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
81 }
82
83 for (uint64_t i = 0; i < 10; ++i) {
84 out_preloadedNanoappIds->push_back(i);
85 }
Matthew Sedamadfd5572023-11-21 05:53:00 -080086 return ScopedAStatus::ok();
Arthur Ishigurofd5e65c2022-11-08 16:49:47 +000087}
88
Anthony Stange7fba1002023-03-02 21:45:20 +000089ScopedAStatus ContextHub::onNanSessionStateChanged(const NanSessionStateUpdate& /*in_update*/) {
Matthew Sedamadfd5572023-11-21 05:53:00 -080090 return ScopedAStatus::ok();
Anthony Stange7344af92022-12-22 14:21:31 +000091}
92
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000093ScopedAStatus ContextHub::registerCallback(int32_t in_contextHubId,
94 const std::shared_ptr<IContextHubCallback>& in_cb) {
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000095 if (in_contextHubId == kMockHubId) {
96 mCallback = in_cb;
Matthew Sedamadfd5572023-11-21 05:53:00 -080097 return ScopedAStatus::ok();
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000098 } else {
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000099 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000100 }
Arthur Ishiguroa257b782021-08-04 10:40:29 -0700101}
102
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000103ScopedAStatus ContextHub::sendMessageToHub(int32_t in_contextHubId,
104 const ContextHubMessage& /* in_message */) {
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000105 if (in_contextHubId == kMockHubId) {
106 // Return true here to indicate that the HAL has accepted the message.
107 // Successful delivery of the message to a nanoapp should be handled at
108 // a higher level protocol.
Matthew Sedamadfd5572023-11-21 05:53:00 -0800109 return ScopedAStatus::ok();
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000110 } else {
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000111 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000112 }
Arthur Ishiguroa257b782021-08-04 10:40:29 -0700113}
114
Matthew Sedamc8ce4d52023-01-09 20:18:21 +0000115ScopedAStatus ContextHub::setTestMode(bool /* enable */) {
Matthew Sedamadfd5572023-11-21 05:53:00 -0800116 return ScopedAStatus::ok();
Matthew Sedamc8ce4d52023-01-09 20:18:21 +0000117}
118
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000119ScopedAStatus ContextHub::onHostEndpointConnected(const HostEndpointInfo& in_info) {
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000120 mConnectedHostEndpoints.insert(in_info.hostEndpointId);
121
Matthew Sedamadfd5572023-11-21 05:53:00 -0800122 return ScopedAStatus::ok();
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000123}
124
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000125ScopedAStatus ContextHub::onHostEndpointDisconnected(char16_t in_hostEndpointId) {
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000126 if (mConnectedHostEndpoints.count(in_hostEndpointId) > 0) {
127 mConnectedHostEndpoints.erase(in_hostEndpointId);
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000128 }
Arthur Ishigurobb1d8bf2022-07-06 15:29:13 +0000129
Matthew Sedamadfd5572023-11-21 05:53:00 -0800130 return ScopedAStatus::ok();
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000131}
132
Matthew Sedamadfd5572023-11-21 05:53:00 -0800133ScopedAStatus ContextHub::sendMessageDeliveryStatusToHub(
134 int32_t /* in_contextHubId */,
135 const MessageDeliveryStatus& /* in_messageDeliveryStatus */) {
136 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
137}
138
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700139ScopedAStatus ContextHub::getHubs(std::vector<HubInfo>* _aidl_return) {
140 ContextHubInfo hub = {};
141 hub.name = "Mock Context Hub";
142 hub.vendor = "AOSP";
143 hub.toolchain = "n/a";
144 hub.id = kMockHubId;
145 hub.peakMips = 1;
146 hub.maxSupportedMessageLengthBytes = 4096;
147 hub.chrePlatformId = UINT64_C(0x476f6f6754000000);
148 hub.chreApiMajorVersion = 1;
149 hub.chreApiMinorVersion = 6;
150 hub.supportsReliableMessages = false;
151
152 HubInfo hubInfo1 = {};
153 hubInfo1.hubId = hub.chrePlatformId;
154 hubInfo1.hubDetails = HubInfo::HubDetails::make<HubInfo::HubDetails::Tag::contextHubInfo>(hub);
155
156 VendorHubInfo vendorHub = {};
157 vendorHub.name = "Mock Vendor Hub";
158 vendorHub.version = 42;
159
160 HubInfo hubInfo2 = {};
161 hubInfo1.hubId = UINT64_C(0x1234567812345678);
162 hubInfo1.hubDetails =
163 HubInfo::HubDetails::make<HubInfo::HubDetails::Tag::vendorHubInfo>(vendorHub);
164
165 _aidl_return->push_back(hubInfo1);
166 _aidl_return->push_back(hubInfo2);
167
168 return ScopedAStatus::ok();
169};
170
171ScopedAStatus ContextHub::getEndpoints(std::vector<EndpointInfo>* /* _aidl_return */) {
172 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
173};
174
175ScopedAStatus ContextHub::registerEndpoint(const EndpointInfo& /* in_endpoint */) {
176 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
177};
178
179ScopedAStatus ContextHub::unregisterEndpoint(const EndpointInfo& /* in_endpoint */) {
180 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
181};
182
183ScopedAStatus ContextHub::registerEndpointCallback(
184 const std::shared_ptr<IEndpointCallback>& /* in_callback */) {
185 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
186};
187
188ScopedAStatus ContextHub::requestSessionIdRange(int32_t /* in_size */,
189 std::vector<int32_t>* /* _aidl_return */) {
190 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
191};
192
193ScopedAStatus ContextHub::openEndpointSession(
194 int32_t /* in_sessionId */, const EndpointId& /* in_destination */,
195 const EndpointId& /* in_initiator */,
196 const std::optional<std::string>& /* in_serviceDescriptor */) {
197 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
198};
199
200ScopedAStatus ContextHub::sendMessageToEndpoint(int32_t /* in_sessionId */,
201 const Message& /* in_msg */) {
202 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
203};
204
205ScopedAStatus ContextHub::sendMessageDeliveryStatusToEndpoint(
206 int32_t /* in_sessionId */, const MessageDeliveryStatus& /* in_msgStatus */) {
207 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
208};
209
210ScopedAStatus ContextHub::closeEndpointSession(int32_t /* in_sessionId */, Reason /* in_reason */) {
211 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
212};
213
214ScopedAStatus ContextHub::endpointSessionOpenComplete(int32_t /* in_sessionId */) {
215 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
216};
217
Matthew Sedamadfd5572023-11-21 05:53:00 -0800218} // namespace aidl::android::hardware::contexthub