• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 #define LOG_TAG "ContextHubHal"
18 #define LOG_NDEBUG 0
19 
20 #include "generic_context_hub_v1_2.h"
21 
22 #include "context_hub_settings_util.h"
23 #include "permissions_util.h"
24 
25 #include <chrono>
26 #include <cinttypes>
27 #include <vector>
28 
29 #include <log/log.h>
30 #include <unistd.h>
31 
32 namespace android {
33 namespace hardware {
34 namespace contexthub {
35 namespace V1_2 {
36 namespace implementation {
37 
38 using ::android::chre::HostProtocolHost;
39 using ::android::hardware::Return;
40 using ::android::hardware::contexthub::common::implementation::getFbsSetting;
41 using ::android::hardware::contexthub::common::implementation::
42     getFbsSettingValue;
43 using ::android::hardware::contexthub::common::implementation::
44     kSupportedPermissions;
45 using ::android::hardware::contexthub::common::implementation::
46     stringVectorToHidl;
47 using ::android::hardware::contexthub::V1_X::implementation::
48     IContextHubCallbackWrapperBase;
49 using ::android::hardware::contexthub::V1_X::implementation::
50     IContextHubCallbackWrapperV1_2;
51 using ::flatbuffers::FlatBufferBuilder;
52 
53 using V1_0::ContextHub;
54 using V1_1::SettingValue;
55 using V1_2::IContexthub;
56 
57 // Aliased for consistency with the way these symbols are referenced in
58 // CHRE-side code
59 namespace fbs = ::chre::fbs;
60 
getHubs_1_2(IContexthub::getHubs_1_2_cb _hidl_cb)61 Return<void> GenericContextHubV1_2::getHubs_1_2(
62     IContexthub::getHubs_1_2_cb _hidl_cb) {
63   std::vector<ContextHub> retHubs;
64   getHubs([&retHubs](std::vector<ContextHub> hubs) { retHubs = hubs; });
65   _hidl_cb(retHubs, stringVectorToHidl(kSupportedPermissions));
66 
67   return Void();
68 }
69 
registerCallback_1_2(uint32_t hubId,const sp<IContexthubCallback> & cb)70 Return<Result> GenericContextHubV1_2::registerCallback_1_2(
71     uint32_t hubId, const sp<IContexthubCallback> &cb) {
72   sp<IContextHubCallbackWrapperBase> wrappedCallback;
73   if (cb != nullptr) {
74     wrappedCallback = new IContextHubCallbackWrapperV1_2(cb);
75   }
76   return registerCallbackCommon(hubId, wrappedCallback);
77 }
78 
onSettingChanged(V1_1::Setting setting,SettingValue newValue)79 Return<void> GenericContextHubV1_2::onSettingChanged(V1_1::Setting setting,
80                                                      SettingValue newValue) {
81   return onSettingChanged_1_2(reinterpret_cast<V1_2::Setting &>(setting),
82                               newValue);
83 }
84 
onSettingChanged_1_2(Setting setting,SettingValue newValue)85 Return<void> GenericContextHubV1_2::onSettingChanged_1_2(
86     Setting setting, SettingValue newValue) {
87   fbs::Setting fbsSetting;
88   fbs::SettingState fbsState;
89   if (getFbsSetting(setting, &fbsSetting) &&
90       getFbsSettingValue(newValue, &fbsState)) {
91     mConnection.sendSettingChangedNotification(fbsSetting, fbsState);
92   }
93 
94   return Void();
95 }
96 
97 }  // namespace implementation
98 }  // namespace V1_2
99 }  // namespace contexthub
100 }  // namespace hardware
101 }  // namespace android
102