Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 1 | /* |
| 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 Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 19 | namespace aidl::android::hardware::contexthub { |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 20 | |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 21 | using ::ndk::ScopedAStatus; |
| 22 | |
| 23 | ScopedAStatus ContextHub::getContextHubs(std::vector<ContextHubInfo>* out_contextHubInfos) { |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 24 | 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 Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 34 | hub.supportsReliableMessages = false; |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 35 | |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 36 | out_contextHubInfos->push_back(hub); |
| 37 | |
Matthew Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 38 | return ScopedAStatus::ok(); |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 41 | // We don't expose any nanoapps for the default impl, therefore all nanoapp-related APIs fail. |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 42 | ScopedAStatus 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 | |
| 48 | ScopedAStatus ContextHub::unloadNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */, |
| 49 | int32_t /* in_transactionId */) { |
| 50 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 51 | } |
| 52 | |
| 53 | ScopedAStatus ContextHub::disableNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */, |
| 54 | int32_t /* in_transactionId */) { |
| 55 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 56 | } |
| 57 | |
| 58 | ScopedAStatus ContextHub::enableNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */, |
| 59 | int32_t /* in_transactionId */) { |
| 60 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 61 | } |
| 62 | |
| 63 | ScopedAStatus ContextHub::onSettingChanged(Setting /* in_setting */, bool /*in_enabled */) { |
Matthew Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 64 | return ScopedAStatus::ok(); |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 67 | ScopedAStatus ContextHub::queryNanoapps(int32_t in_contextHubId) { |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 68 | if (in_contextHubId == kMockHubId && mCallback != nullptr) { |
| 69 | std::vector<NanoappInfo> nanoapps; |
| 70 | mCallback->handleNanoappInfo(nanoapps); |
Matthew Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 71 | return ScopedAStatus::ok(); |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 72 | } else { |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 73 | return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 74 | } |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Matthew Sedam | d70f84d | 2023-03-06 18:34:24 +0000 | [diff] [blame] | 77 | ScopedAStatus ContextHub::getPreloadedNanoappIds(int32_t /* in_contextHubId */, |
| 78 | std::vector<int64_t>* out_preloadedNanoappIds) { |
Arthur Ishiguro | fd5e65c | 2022-11-08 16:49:47 +0000 | [diff] [blame] | 79 | 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 Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 86 | return ScopedAStatus::ok(); |
Arthur Ishiguro | fd5e65c | 2022-11-08 16:49:47 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Anthony Stange | 7fba100 | 2023-03-02 21:45:20 +0000 | [diff] [blame] | 89 | ScopedAStatus ContextHub::onNanSessionStateChanged(const NanSessionStateUpdate& /*in_update*/) { |
Matthew Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 90 | return ScopedAStatus::ok(); |
Anthony Stange | 7344af9 | 2022-12-22 14:21:31 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 93 | ScopedAStatus ContextHub::registerCallback(int32_t in_contextHubId, |
| 94 | const std::shared_ptr<IContextHubCallback>& in_cb) { |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 95 | if (in_contextHubId == kMockHubId) { |
| 96 | mCallback = in_cb; |
Matthew Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 97 | return ScopedAStatus::ok(); |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 98 | } else { |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 99 | return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 100 | } |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 103 | ScopedAStatus ContextHub::sendMessageToHub(int32_t in_contextHubId, |
| 104 | const ContextHubMessage& /* in_message */) { |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 105 | 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 Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 109 | return ScopedAStatus::ok(); |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 110 | } else { |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 111 | return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 112 | } |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Matthew Sedam | c8ce4d5 | 2023-01-09 20:18:21 +0000 | [diff] [blame] | 115 | ScopedAStatus ContextHub::setTestMode(bool /* enable */) { |
Matthew Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 116 | return ScopedAStatus::ok(); |
Matthew Sedam | c8ce4d5 | 2023-01-09 20:18:21 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 119 | ScopedAStatus ContextHub::onHostEndpointConnected(const HostEndpointInfo& in_info) { |
Arthur Ishiguro | 065a9a5 | 2021-11-19 00:24:45 +0000 | [diff] [blame] | 120 | mConnectedHostEndpoints.insert(in_info.hostEndpointId); |
| 121 | |
Matthew Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 122 | return ScopedAStatus::ok(); |
Arthur Ishiguro | 065a9a5 | 2021-11-19 00:24:45 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 125 | ScopedAStatus ContextHub::onHostEndpointDisconnected(char16_t in_hostEndpointId) { |
Arthur Ishiguro | 065a9a5 | 2021-11-19 00:24:45 +0000 | [diff] [blame] | 126 | if (mConnectedHostEndpoints.count(in_hostEndpointId) > 0) { |
| 127 | mConnectedHostEndpoints.erase(in_hostEndpointId); |
Arthur Ishiguro | 065a9a5 | 2021-11-19 00:24:45 +0000 | [diff] [blame] | 128 | } |
Arthur Ishiguro | bb1d8bf | 2022-07-06 15:29:13 +0000 | [diff] [blame] | 129 | |
Matthew Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 130 | return ScopedAStatus::ok(); |
Arthur Ishiguro | 065a9a5 | 2021-11-19 00:24:45 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Matthew Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 133 | ScopedAStatus ContextHub::sendMessageDeliveryStatusToHub( |
| 134 | int32_t /* in_contextHubId */, |
| 135 | const MessageDeliveryStatus& /* in_messageDeliveryStatus */) { |
| 136 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 137 | } |
| 138 | |
Yifei Zhang | 51eba2e | 2024-10-24 15:11:54 -0700 | [diff] [blame] | 139 | ScopedAStatus 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 = {}; |
Yifei Zhang | 3c26580 | 2024-11-04 15:00:05 -0800 | [diff] [blame] | 161 | hubInfo2.hubId = UINT64_C(0x1234567812345678); |
| 162 | hubInfo2.hubDetails = |
Yifei Zhang | 51eba2e | 2024-10-24 15:11:54 -0700 | [diff] [blame] | 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 | |
| 171 | ScopedAStatus ContextHub::getEndpoints(std::vector<EndpointInfo>* /* _aidl_return */) { |
| 172 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 173 | }; |
| 174 | |
| 175 | ScopedAStatus ContextHub::registerEndpoint(const EndpointInfo& /* in_endpoint */) { |
| 176 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 177 | }; |
| 178 | |
| 179 | ScopedAStatus ContextHub::unregisterEndpoint(const EndpointInfo& /* in_endpoint */) { |
| 180 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 181 | }; |
| 182 | |
| 183 | ScopedAStatus ContextHub::registerEndpointCallback( |
| 184 | const std::shared_ptr<IEndpointCallback>& /* in_callback */) { |
| 185 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 186 | }; |
| 187 | |
| 188 | ScopedAStatus ContextHub::requestSessionIdRange(int32_t /* in_size */, |
| 189 | std::vector<int32_t>* /* _aidl_return */) { |
| 190 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 191 | }; |
| 192 | |
| 193 | ScopedAStatus 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 | |
| 200 | ScopedAStatus ContextHub::sendMessageToEndpoint(int32_t /* in_sessionId */, |
| 201 | const Message& /* in_msg */) { |
| 202 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 203 | }; |
| 204 | |
| 205 | ScopedAStatus ContextHub::sendMessageDeliveryStatusToEndpoint( |
| 206 | int32_t /* in_sessionId */, const MessageDeliveryStatus& /* in_msgStatus */) { |
| 207 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 208 | }; |
| 209 | |
| 210 | ScopedAStatus ContextHub::closeEndpointSession(int32_t /* in_sessionId */, Reason /* in_reason */) { |
| 211 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 212 | }; |
| 213 | |
| 214 | ScopedAStatus ContextHub::endpointSessionOpenComplete(int32_t /* in_sessionId */) { |
| 215 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 216 | }; |
| 217 | |
Matthew Sedam | adfd557 | 2023-11-21 05:53:00 -0800 | [diff] [blame] | 218 | } // namespace aidl::android::hardware::contexthub |