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