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 "context_hub_settings_util.h"
21
22 #include <log/log.h>
23 #include <unistd.h>
24
25 namespace android {
26 namespace hardware {
27 namespace contexthub {
28 namespace common {
29 namespace implementation {
30
31 // Aliased for consistency with the way these symbols are referenced in
32 // CHRE-side code
33 namespace fbs = ::chre::fbs;
34
35 using ::android::hardware::contexthub::V1_1::SettingValue;
36 using ::android::hardware::contexthub::V1_2::Setting;
37
38 static_assert(sizeof(::android::hardware::contexthub::V1_1::Setting) ==
39 sizeof(Setting),
40 "New and old Setting types must have the same size");
41
getFbsSetting(const Setting & setting,fbs::Setting * fbsSetting)42 bool getFbsSetting(const Setting &setting, fbs::Setting *fbsSetting) {
43 bool foundSetting = true;
44
45 switch (setting) {
46 case Setting::LOCATION:
47 *fbsSetting = fbs::Setting::LOCATION;
48 break;
49 case Setting::WIFI_AVAILABLE:
50 *fbsSetting = fbs::Setting::WIFI_AVAILABLE;
51 break;
52 case Setting::AIRPLANE_MODE:
53 *fbsSetting = fbs::Setting::AIRPLANE_MODE;
54 break;
55 case Setting::MICROPHONE:
56 *fbsSetting = fbs::Setting::MICROPHONE;
57 break;
58 default:
59 foundSetting = false;
60 ALOGE("Setting update with invalid enum value %hhu", setting);
61 break;
62 }
63
64 return foundSetting;
65 }
66
getFbsSettingValue(const SettingValue & newValue,fbs::SettingState * fbsState)67 bool getFbsSettingValue(const SettingValue &newValue,
68 fbs::SettingState *fbsState) {
69 bool foundSettingValue = true;
70
71 switch (newValue) {
72 case SettingValue::ENABLED:
73 *fbsState = fbs::SettingState::ENABLED;
74 break;
75 case SettingValue::DISABLED:
76 *fbsState = fbs::SettingState::DISABLED;
77 break;
78 default:
79 foundSettingValue = false;
80 ALOGE("Setting value update with invalid enum value %hhu", newValue);
81 break;
82 }
83
84 return foundSettingValue;
85 }
86
87 } // namespace implementation
88 } // namespace common
89 } // namespace contexthub
90 } // namespace hardware
91 } // namespace android
92