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