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 | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 24 | ::ndk::ScopedAStatus ContextHub::getContextHubs(std::vector<ContextHubInfo>* out_contextHubInfos) { |
| 25 | ContextHubInfo hub = {}; |
| 26 | hub.name = "Mock Context Hub"; |
| 27 | hub.vendor = "AOSP"; |
| 28 | hub.toolchain = "n/a"; |
| 29 | hub.id = kMockHubId; |
| 30 | hub.peakMips = 1; |
| 31 | hub.maxSupportedMessageLengthBytes = 4096; |
| 32 | hub.chrePlatformId = UINT64_C(0x476f6f6754000000); |
| 33 | hub.chreApiMajorVersion = 1; |
| 34 | hub.chreApiMinorVersion = 6; |
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 | |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 38 | return ndk::ScopedAStatus::ok(); |
| 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 | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 42 | ::ndk::ScopedAStatus ContextHub::loadNanoapp(int32_t /* in_contextHubId */, |
| 43 | const NanoappBinary& /* in_appBinary */, |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 44 | int32_t /* in_transactionId */, bool* _aidl_return) { |
| 45 | *_aidl_return = false; |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 46 | return ndk::ScopedAStatus::ok(); |
| 47 | } |
| 48 | |
| 49 | ::ndk::ScopedAStatus ContextHub::unloadNanoapp(int32_t /* in_contextHubId */, |
| 50 | int64_t /* in_appId */, |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 51 | int32_t /* in_transactionId */, bool* _aidl_return) { |
| 52 | *_aidl_return = false; |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 53 | return ndk::ScopedAStatus::ok(); |
| 54 | } |
| 55 | |
| 56 | ::ndk::ScopedAStatus ContextHub::disableNanoapp(int32_t /* in_contextHubId */, |
| 57 | int64_t /* in_appId */, |
| 58 | int32_t /* in_transactionId */, |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 59 | bool* _aidl_return) { |
| 60 | *_aidl_return = false; |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 61 | return ndk::ScopedAStatus::ok(); |
| 62 | } |
| 63 | |
| 64 | ::ndk::ScopedAStatus ContextHub::enableNanoapp(int32_t /* in_contextHubId */, |
| 65 | int64_t /* in_appId */, |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 66 | int32_t /* in_transactionId */, bool* _aidl_return) { |
| 67 | *_aidl_return = false; |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 68 | return ndk::ScopedAStatus::ok(); |
| 69 | } |
| 70 | |
| 71 | ::ndk::ScopedAStatus ContextHub::onSettingChanged(Setting /* in_setting */, bool /*in_enabled */) { |
| 72 | return ndk::ScopedAStatus::ok(); |
| 73 | } |
| 74 | |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 75 | ::ndk::ScopedAStatus ContextHub::queryNanoapps(int32_t in_contextHubId, bool* _aidl_return) { |
| 76 | if (in_contextHubId == kMockHubId && mCallback != nullptr) { |
| 77 | std::vector<NanoappInfo> nanoapps; |
| 78 | mCallback->handleNanoappInfo(nanoapps); |
| 79 | *_aidl_return = true; |
| 80 | } else { |
| 81 | *_aidl_return = false; |
| 82 | } |
| 83 | |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 84 | return ndk::ScopedAStatus::ok(); |
| 85 | } |
| 86 | |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 87 | ::ndk::ScopedAStatus ContextHub::registerCallback(int32_t in_contextHubId, |
| 88 | const std::shared_ptr<IContextHubCallback>& in_cb, |
| 89 | bool* _aidl_return) { |
| 90 | if (in_contextHubId == kMockHubId) { |
| 91 | mCallback = in_cb; |
| 92 | *_aidl_return = true; |
| 93 | } else { |
| 94 | *_aidl_return = false; |
| 95 | } |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 96 | return ndk::ScopedAStatus::ok(); |
| 97 | } |
| 98 | |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 99 | ::ndk::ScopedAStatus ContextHub::sendMessageToHub(int32_t in_contextHubId, |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 100 | const ContextHubMessage& /* in_message */, |
Arthur Ishiguro | 94e1aa2 | 2021-10-26 17:25:19 +0000 | [diff] [blame] | 101 | bool* _aidl_return) { |
| 102 | if (in_contextHubId == kMockHubId) { |
| 103 | // Return true here to indicate that the HAL has accepted the message. |
| 104 | // Successful delivery of the message to a nanoapp should be handled at |
| 105 | // a higher level protocol. |
| 106 | *_aidl_return = true; |
| 107 | } else { |
| 108 | *_aidl_return = false; |
| 109 | } |
| 110 | |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 111 | return ndk::ScopedAStatus::ok(); |
| 112 | } |
| 113 | |
Arthur Ishiguro | 065a9a5 | 2021-11-19 00:24:45 +0000 | [diff] [blame] | 114 | ::ndk::ScopedAStatus ContextHub::onHostEndpointConnected(const HostEndpointInfo& in_info) { |
| 115 | mConnectedHostEndpoints.insert(in_info.hostEndpointId); |
| 116 | |
| 117 | return ndk::ScopedAStatus::ok(); |
| 118 | } |
| 119 | |
| 120 | ::ndk::ScopedAStatus ContextHub::onHostEndpointDisconnected(char16_t in_hostEndpointId) { |
| 121 | if (mConnectedHostEndpoints.count(in_hostEndpointId) > 0) { |
| 122 | mConnectedHostEndpoints.erase(in_hostEndpointId); |
| 123 | return ndk::ScopedAStatus::ok(); |
| 124 | } else { |
| 125 | return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT)); |
| 126 | } |
| 127 | } |
| 128 | |
Arthur Ishiguro | a257b78 | 2021-08-04 10:40:29 -0700 | [diff] [blame] | 129 | } // namespace contexthub |
| 130 | } // namespace hardware |
| 131 | } // namespace android |
| 132 | } // namespace aidl |