• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.car.hal;
18 
19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.DUMP_INFO;
20 
21 import android.hardware.automotive.vehicle.V2_0.VehicleAreaConfig;
22 import android.hardware.automotive.vehicle.V2_0.VehiclePropConfig;
23 
24 import com.android.car.CarServiceUtils;
25 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
26 
27 import java.util.ArrayList;
28 
29 /**
30  * HidlHalPropConfig is a HalPropConfig with an HIDL backend.
31  */
32 public final class HidlHalPropConfig extends HalPropConfig {
33     private final VehiclePropConfig mConfig;
34 
HidlHalPropConfig(VehiclePropConfig config)35     public HidlHalPropConfig(VehiclePropConfig config) {
36         mConfig = config;
37 
38         // Do some validity checks to make sure we do not return null for get functions.
39         if (mConfig.areaConfigs == null) {
40             mConfig.areaConfigs = new ArrayList<VehicleAreaConfig>();
41         }
42         if (mConfig.configString == null) {
43             mConfig.configString = "";
44         }
45     }
46 
47     /**
48      * Get the property ID.
49      */
50     @Override
getPropId()51     public int getPropId() {
52         return mConfig.prop;
53     }
54 
55     /**
56      * Get the access mode.
57      */
58     @Override
getAccess()59     public int getAccess() {
60         return mConfig.access;
61     }
62 
63     /**
64      * Get the change mode.
65      */
66     @Override
getChangeMode()67     public int getChangeMode() {
68         return mConfig.changeMode;
69     }
70 
71     /**
72      * Get the area configs.
73      */
74     @Override
getAreaConfigs()75     public HalAreaConfig[] getAreaConfigs() {
76         int size = mConfig.areaConfigs.size();
77         HalAreaConfig[] areaConfigs = new HalAreaConfig[size];
78         for (int i = 0; i < size; i++) {
79             areaConfigs[i] = new HidlHalAreaConfig(mConfig.areaConfigs.get(i), mConfig.access);
80         }
81         return areaConfigs;
82     }
83 
84     /**
85      * Get the config array.
86      */
87     @Override
getConfigArray()88     public int[] getConfigArray() {
89         return CarServiceUtils.toIntArray(mConfig.configArray);
90     }
91 
92     /**
93      * Get the config string.
94      */
95     @Override
getConfigString()96     public String getConfigString() {
97         return mConfig.configString;
98     }
99 
100     /**
101      * Get the min sample rate.
102      */
103     @Override
getMinSampleRate()104     public float getMinSampleRate() {
105         return mConfig.minSampleRate;
106     }
107 
108     /**
109      * Get the max sample rate.
110      */
111     @Override
getMaxSampleRate()112     public float getMaxSampleRate() {
113         return mConfig.maxSampleRate;
114     }
115 
116     /**
117      * Converts to AIDL or HIDL VehiclePropConfig.
118      */
119     @Override
toVehiclePropConfig()120     public Object toVehiclePropConfig() {
121         return mConfig;
122     }
123 
124     /**
125      * Get the string representation for debugging.
126      */
127     @Override
128     @ExcludeFromCodeCoverageGeneratedReport(reason = DUMP_INFO)
toString()129     public String toString() {
130         return mConfig.toString();
131     }
132 }
133