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 | |
| 19 | namespace aidl { |
| 20 | namespace android { |
| 21 | namespace hardware { |
| 22 | namespace contexthub { |
| 23 | |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 24 | using ::ndk::ScopedAStatus; |
| 25 | |
| 26 | ScopedAStatus ContextHub::getContextHubs(std::vector<ContextHubInfo>* out_contextHubInfos) { |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 27 | 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 Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 37 | |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 38 | out_contextHubInfos->push_back(hub); |
| 39 | |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 40 | return ndk::ScopedAStatus::ok(); |
| 41 | } |
| 42 | |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 43 | // 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] | 44 | ScopedAStatus 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 | |
| 50 | ScopedAStatus ContextHub::unloadNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */, |
| 51 | int32_t /* in_transactionId */) { |
| 52 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 53 | } |
| 54 | |
| 55 | ScopedAStatus ContextHub::disableNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */, |
| 56 | int32_t /* in_transactionId */) { |
| 57 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 58 | } |
| 59 | |
| 60 | ScopedAStatus ContextHub::enableNanoapp(int32_t /* in_contextHubId */, int64_t /* in_appId */, |
| 61 | int32_t /* in_transactionId */) { |
| 62 | return ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 63 | } |
| 64 | |
| 65 | ScopedAStatus ContextHub::onSettingChanged(Setting /* in_setting */, bool /*in_enabled */) { |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 66 | return ndk::ScopedAStatus::ok(); |
| 67 | } |
| 68 | |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 69 | ScopedAStatus ContextHub::queryNanoapps(int32_t in_contextHubId) { |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 70 | if (in_contextHubId == kMockHubId && mCallback != nullptr) { |
| 71 | std::vector<NanoappInfo> nanoapps; |
| 72 | mCallback->handleNanoappInfo(nanoapps); |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 73 | return ndk::ScopedAStatus::ok(); |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 74 | } else { |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 75 | return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 76 | } |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Arthur Ishiguro | fd5e65c | 2022-11-08 16:49:47 +0000 | [diff] [blame] | 79 | ScopedAStatus ContextHub::getPreloadedNanoappIds(std::vector<int64_t>* out_preloadedNanoappIds) { |
| 80 | if (out_preloadedNanoappIds == nullptr) { |
| 81 | return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 82 | } |
| 83 | |
| 84 | for (uint64_t i = 0; i < 10; ++i) { |
| 85 | out_preloadedNanoappIds->push_back(i); |
| 86 | } |
| 87 | return ndk::ScopedAStatus::ok(); |
| 88 | } |
| 89 | |
Anthony Stange | 7344af9 | 2022-12-22 14:21:31 +0000 | [diff] [blame] | 90 | ScopedAStatus ContextHub::onNanSessionStateChanged(bool /*sin_state*/) { |
| 91 | return ndk::ScopedAStatus::ok(); |
| 92 | } |
| 93 | |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 94 | ScopedAStatus ContextHub::registerCallback(int32_t in_contextHubId, |
| 95 | const std::shared_ptr<IContextHubCallback>& in_cb) { |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 96 | if (in_contextHubId == kMockHubId) { |
| 97 | mCallback = in_cb; |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 98 | return ndk::ScopedAStatus::ok(); |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 99 | } else { |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 100 | return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 101 | } |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 104 | ScopedAStatus ContextHub::sendMessageToHub(int32_t in_contextHubId, |
| 105 | const ContextHubMessage& /* in_message */) { |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 106 | if (in_contextHubId == kMockHubId) { |
| 107 | // Return true here to indicate that the HAL has accepted the message. |
| 108 | // Successful delivery of the message to a nanoapp should be handled at |
| 109 | // a higher level protocol. |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 110 | return ndk::ScopedAStatus::ok(); |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 111 | } else { |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 112 | return ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 113 | } |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Matthew Sedam | c8ce4d5 | 2023-01-09 20:18:21 +0000 | [diff] [blame] | 116 | ScopedAStatus ContextHub::setTestMode(bool /* enable */) { |
| 117 | return ndk::ScopedAStatus::ok(); |
| 118 | } |
| 119 | |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 120 | ScopedAStatus ContextHub::onHostEndpointConnected(const HostEndpointInfo& in_info) { |
Arthur Ishiguro | 065a9a5 | 2021-11-19 00:24:45 +0000 | [diff] [blame] | 121 | mConnectedHostEndpoints.insert(in_info.hostEndpointId); |
| 122 | |
| 123 | return ndk::ScopedAStatus::ok(); |
| 124 | } |
| 125 | |
Arthur Ishiguro | 070f47d | 2022-01-06 22:42:10 +0000 | [diff] [blame] | 126 | ScopedAStatus ContextHub::onHostEndpointDisconnected(char16_t in_hostEndpointId) { |
Arthur Ishiguro | 065a9a5 | 2021-11-19 00:24:45 +0000 | [diff] [blame] | 127 | if (mConnectedHostEndpoints.count(in_hostEndpointId) > 0) { |
| 128 | mConnectedHostEndpoints.erase(in_hostEndpointId); |
Arthur Ishiguro | 065a9a5 | 2021-11-19 00:24:45 +0000 | [diff] [blame] | 129 | } |
Arthur Ishiguro | bb1d8bf | 2022-07-06 15:29:13 +0000 | [diff] [blame] | 130 | |
| 131 | return ndk::ScopedAStatus::ok(); |
Arthur Ishiguro | 065a9a5 | 2021-11-19 00:24:45 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 134 | } // namespace contexthub |
| 135 | } // namespace hardware |
| 136 | } // namespace android |
| 137 | } // namespace aidl |