blob: 5272957f070ab16070d701aaab2a9fa76385a795 [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
19namespace aidl {
20namespace android {
21namespace hardware {
22namespace contexthub {
23
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000024using ::ndk::ScopedAStatus;
25
26ScopedAStatus ContextHub::getContextHubs(std::vector<ContextHubInfo>* out_contextHubInfos) {
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000027 ContextHubInfo hub = {};
28 hub.name = "Mock Context Hub";
29 hub.vendor = "AOSP";
30 hub.toolchain = "n/a";
31 hub.id = kMockHubId;
32 hub.peakMips = 1;
33 hub.maxSupportedMessageLengthBytes = 4096;
34 hub.chrePlatformId = UINT64_C(0x476f6f6754000000);
35 hub.chreApiMajorVersion = 1;
36 hub.chreApiMinorVersion = 6;
Arthur Ishiguroa257b782021-08-04 10:40:29 -070037
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000038 out_contextHubInfos->push_back(hub);
39
Arthur Ishiguroa257b782021-08-04 10:40:29 -070040 return ndk::ScopedAStatus::ok();
41}
42
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000043// We don't expose any nanoapps for the default impl, therefore all nanoapp-related APIs fail.
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000044ScopedAStatus ContextHub::loadNanoapp(int32_t /* in_contextHubId */,
45 const NanoappBinary& /* in_appBinary */,
46 int32_t /* in_transactionId */) {
47 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
48}
49
50ScopedAStatus ContextHub::unloadNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */,
51 int32_t /* in_transactionId */) {
52 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
53}
54
55ScopedAStatus ContextHub::disableNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */,
56 int32_t /* in_transactionId */) {
57 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
58}
59
60ScopedAStatus ContextHub::enableNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */,
61 int32_t /* in_transactionId */) {
62 return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
63}
64
65ScopedAStatus ContextHub::onSettingChanged(Setting /* in_setting */, bool /*in_enabled */) {
Arthur Ishiguroa257b782021-08-04 10:40:29 -070066 return ndk::ScopedAStatus::ok();
67}
68
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000069ScopedAStatus ContextHub::queryNanoapps(int32_t in_contextHubId) {
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000070 if (in_contextHubId == kMockHubId && mCallback != nullptr) {
71 std::vector<NanoappInfo> nanoapps;
72 mCallback->handleNanoappInfo(nanoapps);
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000073 return ndk::ScopedAStatus::ok();
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000074 } else {
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000075 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000076 }
Arthur Ishiguroa257b782021-08-04 10:40:29 -070077}
78
Matthew Sedamd70f84d2023-03-06 18:34:24 +000079ScopedAStatus ContextHub::getPreloadedNanoappIds(int32_t /* in_contextHubId */,
80 std::vector<int64_t>* out_preloadedNanoappIds) {
Arthur Ishigurofd5e65c2022-11-08 16:49:47 +000081 if (out_preloadedNanoappIds == nullptr) {
82 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
83 }
84
85 for (uint64_t i = 0; i < 10; ++i) {
86 out_preloadedNanoappIds->push_back(i);
87 }
88 return ndk::ScopedAStatus::ok();
89}
90
Anthony Stange7fba1002023-03-02 21:45:20 +000091ScopedAStatus ContextHub::onNanSessionStateChanged(const NanSessionStateUpdate& /*in_update*/) {
Anthony Stange7344af92022-12-22 14:21:31 +000092 return ndk::ScopedAStatus::ok();
93}
94
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000095ScopedAStatus ContextHub::registerCallback(int32_t in_contextHubId,
96 const std::shared_ptr<IContextHubCallback>& in_cb) {
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000097 if (in_contextHubId == kMockHubId) {
98 mCallback = in_cb;
Arthur Ishiguro070f47d2022-01-06 22:42:10 +000099 return ndk::ScopedAStatus::ok();
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000100 } else {
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000101 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000102 }
Arthur Ishiguroa257b782021-08-04 10:40:29 -0700103}
104
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000105ScopedAStatus ContextHub::sendMessageToHub(int32_t in_contextHubId,
106 const ContextHubMessage& /* in_message */) {
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000107 if (in_contextHubId == kMockHubId) {
108 // Return true here to indicate that the HAL has accepted the message.
109 // Successful delivery of the message to a nanoapp should be handled at
110 // a higher level protocol.
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000111 return ndk::ScopedAStatus::ok();
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000112 } else {
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000113 return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000114 }
Arthur Ishiguroa257b782021-08-04 10:40:29 -0700115}
116
Matthew Sedamc8ce4d52023-01-09 20:18:21 +0000117ScopedAStatus ContextHub::setTestMode(bool /* enable */) {
118 return ndk::ScopedAStatus::ok();
119}
120
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000121ScopedAStatus ContextHub::onHostEndpointConnected(const HostEndpointInfo& in_info) {
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000122 mConnectedHostEndpoints.insert(in_info.hostEndpointId);
123
124 return ndk::ScopedAStatus::ok();
125}
126
Arthur Ishiguro070f47d2022-01-06 22:42:10 +0000127ScopedAStatus ContextHub::onHostEndpointDisconnected(char16_t in_hostEndpointId) {
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000128 if (mConnectedHostEndpoints.count(in_hostEndpointId) > 0) {
129 mConnectedHostEndpoints.erase(in_hostEndpointId);
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000130 }
Arthur Ishigurobb1d8bf2022-07-06 15:29:13 +0000131
132 return ndk::ScopedAStatus::ok();
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000133}
134
Arthur Ishiguroa257b782021-08-04 10:40:29 -0700135} // namespace contexthub
136} // namespace hardware
137} // namespace android
138} // namespace aidl