blob: 19d963969d6a2e42e7e210bce69d60b7d40c57a4 [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"
Matthew Sedam0ec290c2024-12-11 11:18:15 -080018#include "aidl/android/hardware/contexthub/IContextHubCallback.h"
Arthur Ishiguroa257b782021-08-04 10:40:29 -070019
Matthew Sedam92c2bd82024-11-11 19:52:30 +000020#ifndef LOG_TAG
21#define LOG_TAG "CHRE"
22#endif
23
24#include <inttypes.h>
25#include <log/log.h>
Matthew Sedam0ec290c2024-12-11 11:18:15 -080026#include <optional>
27#include <thread>
Arthur Ishiguroa257b782021-08-04 10:40:29 -070028
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000029using ::ndk::ScopedAStatus;
30
Matthew Sedam92c2bd82024-11-11 19:52:30 +000031namespace aidl::android::hardware::contexthub {
32
33namespace {
34
35constexpr uint64_t kMockVendorHubId = 0x1234567812345678;
36constexpr uint64_t kMockVendorHub2Id = 0x0EADBEEFDEADBEEF;
37
38// Mock endpoints for the default implementation.
39// These endpoints just echo back any messages sent to them.
40constexpr size_t kMockEndpointCount = 4;
41const EndpointInfo kMockEndpointInfos[kMockEndpointCount] = {
42 {
43 .id = {.hubId = kMockVendorHubId, .id = UINT64_C(0x1)},
44 .type = EndpointInfo::EndpointType::GENERIC,
45 .name = "Mock Endpoint 1",
46 .version = 1,
47 },
48 {
49 .id = {.hubId = kMockVendorHubId, .id = UINT64_C(0x2)},
50 .type = EndpointInfo::EndpointType::GENERIC,
51 .name = "Mock Endpoint 2",
52 .version = 2,
53 },
54 {
55 .id = {.hubId = kMockVendorHub2Id, .id = UINT64_C(0x1)},
56 .type = EndpointInfo::EndpointType::GENERIC,
57 .name = "Mock Endpoint 3",
58 .version = 1,
59 },
60 {
61 .id = {.hubId = kMockVendorHub2Id, .id = UINT64_C(0x2)},
62 .type = EndpointInfo::EndpointType::GENERIC,
63 .name = "Mock Endpoint 4",
64 .version = 2,
65 },
66};
67
Matthew Sedam0ec290c2024-12-11 11:18:15 -080068//! Mutex used to ensure callbacks are called after the initial function returns.
69std::mutex gCallbackMutex;
70
Matthew Sedam92c2bd82024-11-11 19:52:30 +000071} // anonymous namespace
72
Arthur Ishiguro0d6009e2024-12-24 16:31:20 -080073ScopedAStatus ContextHub::getContextHubs(std::vector<ContextHubInfo>* /* out_contextHubInfos */) {
Matthew Sedamadfd5572023-11-21 05:53:00 -080074 return ScopedAStatus::ok();
Arthur Ishiguroa257b782021-08-04 10:40:29 -070075}
76
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000077// We don't expose any nanoapps for the default impl, therefore all nanoapp-related APIs fail.
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000078ScopedAStatus ContextHub::loadNanoapp(int32_t /* in_contextHubId */,
79 const NanoappBinary& /* in_appBinary */,
80 int32_t /* in_transactionId */) {
81 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
82}
83
84ScopedAStatus ContextHub::unloadNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */,
85 int32_t /* in_transactionId */) {
86 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
87}
88
89ScopedAStatus ContextHub::disableNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */,
90 int32_t /* in_transactionId */) {
91 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
92}
93
94ScopedAStatus ContextHub::enableNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */,
95 int32_t /* in_transactionId */) {
96 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
97}
98
99ScopedAStatus ContextHub::onSettingChanged(Setting /* in_setting */, bool /*in_enabled */) {
Matthew Sedamadfd5572023-11-21 05:53:00 -0800100 return ScopedAStatus::ok();
Arthur Ishiguroa257b782021-08-04 10:40:29 -0700101}
102
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000103ScopedAStatus ContextHub::queryNanoapps(int32_t in_contextHubId) {
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000104 if (in_contextHubId == kMockHubId && mCallback != nullptr) {
105 std::vector<NanoappInfo> nanoapps;
106 mCallback->handleNanoappInfo(nanoapps);
Matthew Sedamadfd5572023-11-21 05:53:00 -0800107 return ScopedAStatus::ok();
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000108 } else {
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000109 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000110 }
Arthur Ishiguroa257b782021-08-04 10:40:29 -0700111}
112
Matthew Sedamd70f84d2023-03-06 18:34:24 +0000113ScopedAStatus ContextHub::getPreloadedNanoappIds(int32_t /* in_contextHubId */,
114 std::vector<int64_t>* out_preloadedNanoappIds) {
Arthur Ishigurofd5e65c2022-11-08 16:49:47 +0000115 if (out_preloadedNanoappIds == nullptr) {
116 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
117 }
118
119 for (uint64_t i = 0; i < 10; ++i) {
120 out_preloadedNanoappIds->push_back(i);
121 }
Matthew Sedamadfd5572023-11-21 05:53:00 -0800122 return ScopedAStatus::ok();
Arthur Ishigurofd5e65c2022-11-08 16:49:47 +0000123}
124
Anthony Stange7fba1002023-03-02 21:45:20 +0000125ScopedAStatus ContextHub::onNanSessionStateChanged(const NanSessionStateUpdate& /*in_update*/) {
Matthew Sedamadfd5572023-11-21 05:53:00 -0800126 return ScopedAStatus::ok();
Anthony Stange7344af92022-12-22 14:21:31 +0000127}
128
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000129ScopedAStatus ContextHub::registerCallback(int32_t in_contextHubId,
130 const std::shared_ptr<IContextHubCallback>& in_cb) {
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000131 if (in_contextHubId == kMockHubId) {
132 mCallback = in_cb;
Matthew Sedamadfd5572023-11-21 05:53:00 -0800133 return ScopedAStatus::ok();
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000134 } else {
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000135 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000136 }
Arthur Ishiguroa257b782021-08-04 10:40:29 -0700137}
138
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000139ScopedAStatus ContextHub::sendMessageToHub(int32_t in_contextHubId,
140 const ContextHubMessage& /* in_message */) {
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000141 if (in_contextHubId == kMockHubId) {
142 // Return true here to indicate that the HAL has accepted the message.
143 // Successful delivery of the message to a nanoapp should be handled at
144 // a higher level protocol.
Matthew Sedamadfd5572023-11-21 05:53:00 -0800145 return ScopedAStatus::ok();
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000146 } else {
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000147 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000148 }
Arthur Ishiguroa257b782021-08-04 10:40:29 -0700149}
150
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000151ScopedAStatus ContextHub::setTestMode(bool enable) {
152 if (enable) {
153 std::unique_lock<std::mutex> lock(mEndpointMutex);
154 mEndpoints.clear();
155 mEndpointSessions.clear();
156 mEndpointCallback = nullptr;
157 }
Matthew Sedamadfd5572023-11-21 05:53:00 -0800158 return ScopedAStatus::ok();
Matthew Sedamc8ce4d52023-01-09 20:18:21 +0000159}
160
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000161ScopedAStatus ContextHub::onHostEndpointConnected(const HostEndpointInfo& in_info) {
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000162 mConnectedHostEndpoints.insert(in_info.hostEndpointId);
163
Matthew Sedamadfd5572023-11-21 05:53:00 -0800164 return ScopedAStatus::ok();
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000165}
166
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000167ScopedAStatus ContextHub::onHostEndpointDisconnected(char16_t in_hostEndpointId) {
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000168 if (mConnectedHostEndpoints.count(in_hostEndpointId) > 0) {
169 mConnectedHostEndpoints.erase(in_hostEndpointId);
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000170 }
Arthur Ishigurobb1d8bf2022-07-06 15:29:13 +0000171
Matthew Sedamadfd5572023-11-21 05:53:00 -0800172 return ScopedAStatus::ok();
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000173}
174
Matthew Sedamadfd5572023-11-21 05:53:00 -0800175ScopedAStatus ContextHub::sendMessageDeliveryStatusToHub(
176 int32_t /* in_contextHubId */,
177 const MessageDeliveryStatus& /* in_messageDeliveryStatus */) {
178 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
179}
180
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700181ScopedAStatus ContextHub::getHubs(std::vector<HubInfo>* _aidl_return) {
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000182 if (_aidl_return == nullptr) {
183 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
184 }
185
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700186 VendorHubInfo vendorHub = {};
187 vendorHub.name = "Mock Vendor Hub";
188 vendorHub.version = 42;
189
Arthur Ishiguro0d6009e2024-12-24 16:31:20 -0800190 HubInfo hubInfo1 = {};
191 hubInfo1.hubId = kMockVendorHubId;
192 hubInfo1.hubDetails =
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700193 HubInfo::HubDetails::make<HubInfo::HubDetails::Tag::vendorHubInfo>(vendorHub);
194
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000195 VendorHubInfo vendorHub2 = {};
196 vendorHub2.name = "Mock Vendor Hub 2";
197 vendorHub2.version = 24;
198
Arthur Ishiguro0d6009e2024-12-24 16:31:20 -0800199 HubInfo hubInfo2 = {};
200 hubInfo2.hubId = kMockVendorHub2Id;
201 hubInfo2.hubDetails =
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000202 HubInfo::HubDetails::make<HubInfo::HubDetails::Tag::vendorHubInfo>(vendorHub2);
203
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700204 _aidl_return->push_back(hubInfo1);
205 _aidl_return->push_back(hubInfo2);
206
207 return ScopedAStatus::ok();
208};
209
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000210ScopedAStatus ContextHub::getEndpoints(std::vector<EndpointInfo>* _aidl_return) {
211 if (_aidl_return == nullptr) {
212 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
213 }
214
215 Service echoService;
216 echoService.format = Service::RpcFormat::CUSTOM;
Arthur Ishiguro39087712024-12-13 09:48:13 -0800217 echoService.serviceDescriptor = "android.hardware.contexthub.test.EchoService";
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000218 echoService.majorVersion = 1;
219 echoService.minorVersion = 0;
220
221 for (const EndpointInfo& endpoint : kMockEndpointInfos) {
222 EndpointInfo endpointWithService(endpoint);
223 endpointWithService.services.push_back(echoService);
224 _aidl_return->push_back(std::move(endpointWithService));
225 }
226
227 return ScopedAStatus::ok();
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700228};
229
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000230ScopedAStatus ContextHub::registerEndpoint(const EndpointInfo& in_endpoint) {
231 std::unique_lock<std::mutex> lock(mEndpointMutex);
232
233 for (const EndpointInfo& endpoint : mEndpoints) {
234 if ((endpoint.id.id == in_endpoint.id.id && endpoint.id.hubId == in_endpoint.id.hubId) ||
235 endpoint.name == in_endpoint.name) {
236 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
237 }
238 }
239 mEndpoints.push_back(in_endpoint);
240 return ScopedAStatus::ok();
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700241};
242
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000243ScopedAStatus ContextHub::unregisterEndpoint(const EndpointInfo& in_endpoint) {
244 std::unique_lock<std::mutex> lock(mEndpointMutex);
245
246 for (auto it = mEndpoints.begin(); it != mEndpoints.end(); ++it) {
247 if (it->id.id == in_endpoint.id.id && it->id.hubId == in_endpoint.id.hubId) {
248 mEndpoints.erase(it);
249 return ScopedAStatus::ok();
250 }
251 }
252 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700253};
254
255ScopedAStatus ContextHub::registerEndpointCallback(
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000256 const std::shared_ptr<IEndpointCallback>& in_callback) {
257 std::unique_lock<std::mutex> lock(mEndpointMutex);
258
259 mEndpointCallback = in_callback;
260 return ScopedAStatus::ok();
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700261};
262
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000263ScopedAStatus ContextHub::requestSessionIdRange(int32_t in_size,
Yifei Zhangcef8f662024-12-06 16:03:26 -0800264 std::array<int32_t, 2>* _aidl_return) {
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000265 constexpr int32_t kMaxSize = 1024;
266 if (in_size > kMaxSize || _aidl_return == nullptr) {
267 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
268 }
269
270 {
271 std::lock_guard<std::mutex> lock(mEndpointMutex);
272 mMaxValidSessionId = in_size;
273 }
274
Matthew Sedam0ec290c2024-12-11 11:18:15 -0800275 (*_aidl_return)[0] = 0;
276 (*_aidl_return)[1] = in_size;
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000277 return ScopedAStatus::ok();
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700278};
279
280ScopedAStatus ContextHub::openEndpointSession(
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000281 int32_t in_sessionId, const EndpointId& in_destination, const EndpointId& in_initiator,
282 const std::optional<std::string>& in_serviceDescriptor) {
283 // We are not calling onCloseEndpointSession on failure because the remote endpoints (our
284 // mock endpoints) always accept the session.
285
Matthew Sedam0ec290c2024-12-11 11:18:15 -0800286 std::weak_ptr<IEndpointCallback> callback;
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000287 {
288 std::unique_lock<std::mutex> lock(mEndpointMutex);
289 if (in_sessionId > mMaxValidSessionId) {
290 ALOGE("openEndpointSession: session ID %" PRId32 " is invalid", in_sessionId);
291 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
292 }
293
294 for (const EndpointSession& session : mEndpointSessions) {
295 bool sessionAlreadyExists =
296 (session.initiator == in_destination && session.peer == in_initiator) ||
297 (session.peer == in_destination && session.initiator == in_initiator);
298 if (sessionAlreadyExists) {
299 ALOGD("openEndpointSession: session ID %" PRId32 " already exists", in_sessionId);
300 return (session.sessionId == in_sessionId &&
301 session.serviceDescriptor == in_serviceDescriptor)
302 ? ScopedAStatus::ok()
303 : ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
304 } else if (session.sessionId == in_sessionId) {
305 ALOGE("openEndpointSession: session ID %" PRId32 " is invalid: endpoint mismatch",
306 in_sessionId);
307 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
308 }
309 }
310
311 // Verify the initiator and destination are valid endpoints
312 bool initiatorIsValid = findEndpoint(in_initiator, mEndpoints.begin(), mEndpoints.end());
313 if (!initiatorIsValid) {
314 ALOGE("openEndpointSession: initiator %" PRIu64 ":%" PRIu64 " is invalid",
315 in_initiator.id, in_initiator.hubId);
316 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
317 }
318 bool destinationIsValid = findEndpoint(in_destination, &kMockEndpointInfos[0],
319 &kMockEndpointInfos[kMockEndpointCount]);
320 if (!destinationIsValid) {
321 ALOGE("openEndpointSession: destination %" PRIu64 ":%" PRIu64 " is invalid",
322 in_destination.id, in_destination.hubId);
323 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
324 }
325
326 mEndpointSessions.push_back({
327 .sessionId = in_sessionId,
328 .initiator = in_initiator,
329 .peer = in_destination,
330 .serviceDescriptor = in_serviceDescriptor,
331 });
332
Matthew Sedam0ec290c2024-12-11 11:18:15 -0800333 if (mEndpointCallback == nullptr) {
334 return ScopedAStatus::ok();
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000335 }
Matthew Sedam0ec290c2024-12-11 11:18:15 -0800336 callback = mEndpointCallback;
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000337 }
338
Matthew Sedam0ec290c2024-12-11 11:18:15 -0800339 std::unique_lock<std::mutex> lock(gCallbackMutex);
340 std::thread{[callback, in_sessionId]() {
341 std::unique_lock<std::mutex> lock(gCallbackMutex);
342 if (auto cb = callback.lock(); cb != nullptr) {
343 cb->onEndpointSessionOpenComplete(in_sessionId);
344 }
345 }}.detach();
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000346 return ScopedAStatus::ok();
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700347};
348
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000349ScopedAStatus ContextHub::sendMessageToEndpoint(int32_t in_sessionId, const Message& in_msg) {
Matthew Sedam0ec290c2024-12-11 11:18:15 -0800350 std::weak_ptr<IEndpointCallback> callback;
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000351 {
352 std::unique_lock<std::mutex> lock(mEndpointMutex);
Matthew Sedam0ec290c2024-12-11 11:18:15 -0800353 bool foundSession = false;
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000354 for (const EndpointSession& session : mEndpointSessions) {
355 if (session.sessionId == in_sessionId) {
356 foundSession = true;
357 break;
358 }
359 }
360
Matthew Sedam0ec290c2024-12-11 11:18:15 -0800361 if (!foundSession) {
362 ALOGE("sendMessageToEndpoint: session ID %" PRId32 " is invalid", in_sessionId);
363 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000364 }
365
Matthew Sedam0ec290c2024-12-11 11:18:15 -0800366 if (mEndpointCallback == nullptr) {
367 return ScopedAStatus::ok();
368 }
369 callback = mEndpointCallback;
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000370 }
Matthew Sedam0ec290c2024-12-11 11:18:15 -0800371
372 std::unique_lock<std::mutex> lock(gCallbackMutex);
373 if ((in_msg.flags & Message::FLAG_REQUIRES_DELIVERY_STATUS) != 0) {
374 MessageDeliveryStatus msgStatus = {};
375 msgStatus.messageSequenceNumber = in_msg.sequenceNumber;
376 msgStatus.errorCode = ErrorCode::OK;
377
378 std::thread{[callback, in_sessionId, msgStatus]() {
379 std::unique_lock<std::mutex> lock(gCallbackMutex);
380 if (auto cb = callback.lock(); cb != nullptr) {
381 cb->onMessageDeliveryStatusReceived(in_sessionId, msgStatus);
382 }
383 }}.detach();
384 }
385
386 // Echo the message back
387 std::thread{[callback, in_sessionId, in_msg]() {
388 std::unique_lock<std::mutex> lock(gCallbackMutex);
389 if (auto cb = callback.lock(); cb != nullptr) {
390 cb->onMessageReceived(in_sessionId, in_msg);
391 }
392 }}.detach();
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000393 return ScopedAStatus::ok();
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700394};
395
396ScopedAStatus ContextHub::sendMessageDeliveryStatusToEndpoint(
397 int32_t /* in_sessionId */, const MessageDeliveryStatus& /* in_msgStatus */) {
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000398 return ScopedAStatus::ok();
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700399};
400
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000401ScopedAStatus ContextHub::closeEndpointSession(int32_t in_sessionId, Reason /* in_reason */) {
402 std::unique_lock<std::mutex> lock(mEndpointMutex);
403
404 for (auto it = mEndpointSessions.begin(); it != mEndpointSessions.end(); ++it) {
405 if (it->sessionId == in_sessionId) {
406 mEndpointSessions.erase(it);
407 return ScopedAStatus::ok();
408 }
409 }
410 ALOGE("closeEndpointSession: session ID %" PRId32 " is invalid", in_sessionId);
411 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700412};
413
414ScopedAStatus ContextHub::endpointSessionOpenComplete(int32_t /* in_sessionId */) {
Matthew Sedam92c2bd82024-11-11 19:52:30 +0000415 return ScopedAStatus::ok();
Yifei Zhang51eba2e2024-10-24 15:11:54 -0700416};
417
Matthew Sedamadfd5572023-11-21 05:53:00 -0800418} // namespace aidl::android::hardware::contexthub