1 /*
2  * Copyright (c) 2022, 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 "AidlHalPropConfig.h"
18 
19 #include <VehicleUtils.h>
20 
21 namespace android {
22 namespace frameworks {
23 namespace automotive {
24 namespace vhal {
25 
26 using ::aidl::android::hardware::automotive::vehicle::VehicleAreaConfig;
27 using ::aidl::android::hardware::automotive::vehicle::VehiclePropConfig;
28 using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyAccess;
29 
30 using ::android::hardware::automotive::vehicle::toInt;
31 
AidlHalPropConfig(VehiclePropConfig && config)32 AidlHalPropConfig::AidlHalPropConfig(VehiclePropConfig&& config) {
33     mPropConfig = std::move(config);
34     if (mPropConfig.areaConfigs.size() == 0) {
35         VehicleAreaConfig globalAreaConfig;
36         globalAreaConfig.areaId = 0;
37         mAreaConfigs.push_back(std::make_unique<AidlHalAreaConfig>(std::move(globalAreaConfig),
38                                                                    toInt(mPropConfig.access)));
39     } else {
40         for (VehicleAreaConfig& areaConfig : mPropConfig.areaConfigs) {
41             int32_t access = (areaConfig.access == VehiclePropertyAccess::NONE)
42                     ? toInt(mPropConfig.access)
43                     : toInt(areaConfig.access);
44             mAreaConfigs.push_back(
45                     std::make_unique<AidlHalAreaConfig>(std::move(areaConfig), access));
46         }
47     }
48 }
49 
getPropId() const50 int32_t AidlHalPropConfig::getPropId() const {
51     return mPropConfig.prop;
52 }
53 
getAccess() const54 int32_t AidlHalPropConfig::getAccess() const {
55     return toInt(mPropConfig.access);
56 }
57 
getChangeMode() const58 int32_t AidlHalPropConfig::getChangeMode() const {
59     return toInt(mPropConfig.changeMode);
60 }
61 
getAreaConfigSize() const62 size_t AidlHalPropConfig::getAreaConfigSize() const {
63     return mAreaConfigs.size();
64 }
65 
getConfigArray() const66 std::vector<int32_t> AidlHalPropConfig::getConfigArray() const {
67     return mPropConfig.configArray;
68 }
69 
getConfigString() const70 std::string AidlHalPropConfig::getConfigString() const {
71     return mPropConfig.configString;
72 }
73 
getMinSampleRate() const74 float AidlHalPropConfig::getMinSampleRate() const {
75     return mPropConfig.minSampleRate;
76 }
77 
getMaxSampleRate() const78 float AidlHalPropConfig::getMaxSampleRate() const {
79     return mPropConfig.maxSampleRate;
80 }
81 
AidlHalAreaConfig(VehicleAreaConfig && areaConfig,int32_t access)82 AidlHalAreaConfig::AidlHalAreaConfig(VehicleAreaConfig&& areaConfig, int32_t access) {
83     mAreaConfig = std::move(areaConfig);
84     mAccess = access;
85 }
86 
getAreaId() const87 int32_t AidlHalAreaConfig::getAreaId() const {
88     return mAreaConfig.areaId;
89 }
90 
getAccess() const91 int32_t AidlHalAreaConfig::getAccess() const {
92     return mAccess;
93 }
94 
getMinInt32Value() const95 int32_t AidlHalAreaConfig::getMinInt32Value() const {
96     return mAreaConfig.minInt32Value;
97 }
98 
getMaxInt32Value() const99 int32_t AidlHalAreaConfig::getMaxInt32Value() const {
100     return mAreaConfig.maxInt32Value;
101 }
102 
getMinInt64Value() const103 int64_t AidlHalAreaConfig::getMinInt64Value() const {
104     return mAreaConfig.minInt64Value;
105 }
106 
getMaxInt64Value() const107 int64_t AidlHalAreaConfig::getMaxInt64Value() const {
108     return mAreaConfig.maxInt64Value;
109 }
110 
getMinFloatValue() const111 float AidlHalAreaConfig::getMinFloatValue() const {
112     return mAreaConfig.minFloatValue;
113 }
114 
getMaxFloatValue() const115 float AidlHalAreaConfig::getMaxFloatValue() const {
116     return mAreaConfig.maxFloatValue;
117 }
118 
isVariableUpdateRateSupported() const119 bool AidlHalAreaConfig::isVariableUpdateRateSupported() const {
120     return mAreaConfig.supportVariableUpdateRate;
121 }
122 
123 }  // namespace vhal
124 }  // namespace automotive
125 }  // namespace frameworks
126 }  // namespace android
127