Home | History | Annotate | Download | only in test
      1 /*
      2  * Copyright (C) 2016 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.vehiclehal.test;
     18 
     19 import android.annotation.CheckResult;
     20 import android.hardware.automotive.vehicle.V2_0.VehicleAreaConfig;
     21 import android.hardware.automotive.vehicle.V2_0.VehiclePropConfig;
     22 import android.hardware.automotive.vehicle.V2_0.VehiclePropertyAccess;
     23 import android.hardware.automotive.vehicle.V2_0.VehiclePropertyChangeMode;
     24 
     25 import java.util.Collection;
     26 
     27 /**
     28  * A builder class for {@link android.hardware.automotive.vehicle.V2_0.VehiclePropConfig}
     29  */
     30 public class VehiclePropConfigBuilder {
     31 
     32     private final VehiclePropConfig mConfig;
     33 
     34     @CheckResult
     35     public static VehiclePropConfigBuilder newBuilder(int propId) {
     36         return new VehiclePropConfigBuilder(propId);
     37     }
     38 
     39     private VehiclePropConfigBuilder(int propId) {
     40         mConfig = new VehiclePropConfig();
     41         mConfig.prop = propId;
     42         mConfig.access = VehiclePropertyAccess.READ_WRITE;
     43         mConfig.changeMode = VehiclePropertyChangeMode.ON_CHANGE;
     44     }
     45 
     46     private VehiclePropConfig clone(VehiclePropConfig propConfig) {
     47         VehiclePropConfig newConfig = new VehiclePropConfig();
     48 
     49         newConfig.prop = propConfig.prop;
     50         newConfig.access = propConfig.access;
     51         newConfig.changeMode = propConfig.changeMode;
     52         newConfig.supportedAreas = propConfig.supportedAreas;
     53         newConfig.configFlags = propConfig.configFlags;
     54         newConfig.configString = propConfig.configString;
     55         newConfig.minSampleRate = propConfig.minSampleRate;
     56         newConfig.maxSampleRate = propConfig.maxSampleRate;
     57         newConfig.configArray.addAll(propConfig.configArray);
     58         for (VehicleAreaConfig area : propConfig.areaConfigs) {
     59             VehicleAreaConfig newArea = new VehicleAreaConfig();
     60             newArea.areaId = area.areaId;
     61             newArea.minInt32Value = area.minInt32Value;
     62             newArea.maxInt32Value = area.maxInt32Value;
     63             newArea.minInt64Value = area.minInt64Value;
     64             newArea.maxInt64Value = area.maxInt64Value;
     65             newArea.minFloatValue = area.minFloatValue;
     66             newArea.maxFloatValue = area.maxFloatValue;
     67             newConfig.areaConfigs.add(newArea);
     68         }
     69 
     70         return newConfig;
     71     }
     72 
     73     @CheckResult
     74     public VehiclePropConfigBuilder setAccess(int access) {
     75         mConfig.access = access;
     76         return this;
     77     }
     78 
     79     @CheckResult
     80     public VehiclePropConfigBuilder setChangeMode(int changeMode) {
     81         mConfig.changeMode = changeMode;
     82         return this;
     83     }
     84 
     85     @CheckResult
     86     public VehiclePropConfigBuilder setSupportedAreas(int supportedAreas) {
     87         mConfig.supportedAreas = supportedAreas;
     88         return this;
     89     }
     90 
     91     @CheckResult
     92     public VehiclePropConfigBuilder setConfigFlags(int configFlags) {
     93         mConfig.configFlags = configFlags;
     94         return this;
     95     }
     96 
     97     @CheckResult
     98     public VehiclePropConfigBuilder setConfigString(String configString) {
     99         mConfig.configString = configString;
    100         return this;
    101     }
    102 
    103 
    104     @CheckResult
    105     public VehiclePropConfigBuilder setConfigArray(Collection<Integer> configArray) {
    106         mConfig.configArray.clear();
    107         mConfig.configArray.addAll(configArray);
    108         return this;
    109     }
    110 
    111     @CheckResult
    112     public VehiclePropConfigBuilder addAreaConfig(int areaId, int minValue, int maxValue) {
    113         VehicleAreaConfig area = new VehicleAreaConfig();
    114         area.areaId = areaId;
    115         area.minInt32Value = minValue;
    116         area.maxInt32Value = maxValue;
    117         mConfig.areaConfigs.add(area);
    118         return this;
    119     }
    120 
    121     @CheckResult
    122     public VehiclePropConfigBuilder addAreaConfig(int areaId, float minValue, float maxValue) {
    123         VehicleAreaConfig area = new VehicleAreaConfig();
    124         area.areaId = areaId;
    125         area.minFloatValue = minValue;
    126         area.maxFloatValue = maxValue;
    127         mConfig.areaConfigs.add(area);
    128         return this;
    129     }
    130 
    131     public VehiclePropConfig build() {
    132         return clone(mConfig);
    133     }
    134 }
    135