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.configString = propConfig.configString;
     53         newConfig.minSampleRate = propConfig.minSampleRate;
     54         newConfig.maxSampleRate = propConfig.maxSampleRate;
     55         newConfig.configArray.addAll(propConfig.configArray);
     56         for (VehicleAreaConfig area : propConfig.areaConfigs) {
     57             VehicleAreaConfig newArea = new VehicleAreaConfig();
     58             newArea.areaId = area.areaId;
     59             newArea.minInt32Value = area.minInt32Value;
     60             newArea.maxInt32Value = area.maxInt32Value;
     61             newArea.minInt64Value = area.minInt64Value;
     62             newArea.maxInt64Value = area.maxInt64Value;
     63             newArea.minFloatValue = area.minFloatValue;
     64             newArea.maxFloatValue = area.maxFloatValue;
     65             newConfig.areaConfigs.add(newArea);
     66         }
     67 
     68         return newConfig;
     69     }
     70 
     71     @CheckResult
     72     public VehiclePropConfigBuilder setAccess(int access) {
     73         mConfig.access = access;
     74         return this;
     75     }
     76 
     77     @CheckResult
     78     public VehiclePropConfigBuilder setChangeMode(int changeMode) {
     79         mConfig.changeMode = changeMode;
     80         return this;
     81     }
     82 
     83     @CheckResult
     84     public VehiclePropConfigBuilder setConfigString(String configString) {
     85         mConfig.configString = configString;
     86         return this;
     87     }
     88 
     89 
     90     @CheckResult
     91     public VehiclePropConfigBuilder setConfigArray(Collection<Integer> configArray) {
     92         mConfig.configArray.clear();
     93         mConfig.configArray.addAll(configArray);
     94         return this;
     95     }
     96 
     97     @CheckResult
     98     public VehiclePropConfigBuilder addAreaConfig(int areaId, int minValue, int maxValue) {
     99         VehicleAreaConfig area = new VehicleAreaConfig();
    100         area.areaId = areaId;
    101         area.minInt32Value = minValue;
    102         area.maxInt32Value = maxValue;
    103         mConfig.areaConfigs.add(area);
    104         return this;
    105     }
    106 
    107     @CheckResult
    108     public VehiclePropConfigBuilder addAreaConfig(int areaId, float minValue, float maxValue) {
    109         VehicleAreaConfig area = new VehicleAreaConfig();
    110         area.areaId = areaId;
    111         area.minFloatValue = minValue;
    112         area.maxFloatValue = maxValue;
    113         mConfig.areaConfigs.add(area);
    114         return this;
    115     }
    116 
    117     public VehiclePropConfig build() {
    118         return clone(mConfig);
    119     }
    120 }
    121