blob: 6da690da4f712cd63037ff607773f9641c14c59f [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 Ishiguro94e1aa22021-10-26 17:25:19 +000024::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 Ishiguroa257b782021-08-04 10:40:29 -070035
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000036 out_contextHubInfos->push_back(hub);
37
Arthur Ishiguroa257b782021-08-04 10:40:29 -070038 return ndk::ScopedAStatus::ok();
39}
40
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000041// We don't expose any nanoapps for the default impl, therefore all nanoapp-related APIs fail.
Arthur Ishiguroa257b782021-08-04 10:40:29 -070042::ndk::ScopedAStatus ContextHub::loadNanoapp(int32_t /* in_contextHubId */,
43 const NanoappBinary& /* in_appBinary */,
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000044 int32_t /* in_transactionId */, bool* _aidl_return) {
45 *_aidl_return = false;
Arthur Ishiguroa257b782021-08-04 10:40:29 -070046 return ndk::ScopedAStatus::ok();
47}
48
49::ndk::ScopedAStatus ContextHub::unloadNanoapp(int32_t /* in_contextHubId */,
50 int64_t /* in_appId */,
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000051 int32_t /* in_transactionId */, bool* _aidl_return) {
52 *_aidl_return = false;
Arthur Ishiguroa257b782021-08-04 10:40:29 -070053 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 Ishiguro94e1aa22021-10-26 17:25:19 +000059 bool* _aidl_return) {
60 *_aidl_return = false;
Arthur Ishiguroa257b782021-08-04 10:40:29 -070061 return ndk::ScopedAStatus::ok();
62}
63
64::ndk::ScopedAStatus ContextHub::enableNanoapp(int32_t /* in_contextHubId */,
65 int64_t /* in_appId */,
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000066 int32_t /* in_transactionId */, bool* _aidl_return) {
67 *_aidl_return = false;
Arthur Ishiguroa257b782021-08-04 10:40:29 -070068 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 Ishiguro94e1aa22021-10-26 17:25:19 +000075::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 Ishiguroa257b782021-08-04 10:40:29 -070084 return ndk::ScopedAStatus::ok();
85}
86
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000087::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 Ishiguroa257b782021-08-04 10:40:29 -070096 return ndk::ScopedAStatus::ok();
97}
98
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +000099::ndk::ScopedAStatus ContextHub::sendMessageToHub(int32_t in_contextHubId,
Arthur Ishiguroa257b782021-08-04 10:40:29 -0700100 const ContextHubMessage& /* in_message */,
Arthur Ishiguro94e1aa22021-10-26 17:25:19 +0000101 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 Ishiguroa257b782021-08-04 10:40:29 -0700111 return ndk::ScopedAStatus::ok();
112}
113
Arthur Ishiguro065a9a52021-11-19 00:24:45 +0000114::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 Ishiguroa257b782021-08-04 10:40:29 -0700129} // namespace contexthub
130} // namespace hardware
131} // namespace android
132} // namespace aidl