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 package android.car.apitest; 17 18 import static com.google.common.truth.Truth.assertThat; 19 import static com.google.common.truth.Truth.assertWithMessage; 20 21 import android.car.Car; 22 import android.car.hardware.CarPropertyConfig; 23 import android.car.hardware.hvac.CarHvacManager; 24 import android.hardware.automotive.vehicle.VehicleHvacFanDirection; 25 import android.util.Log; 26 27 import androidx.test.filters.MediumTest; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 32 import java.util.Arrays; 33 import java.util.HashSet; 34 import java.util.List; 35 import java.util.Set; 36 37 @MediumTest 38 public final class CarHvacManagerTest extends CarApiTestBase { 39 private static final String TAG = CarHvacManagerTest.class.getSimpleName(); 40 41 private CarHvacManager mHvacManager; 42 43 @Before setUp()44 public void setUp() throws Exception { 45 mHvacManager = (CarHvacManager) getCar().getCarManager(Car.HVAC_SERVICE); 46 assertThat(mHvacManager).isNotNull(); 47 } 48 49 @Test testAllHvacProperties()50 public void testAllHvacProperties() throws Exception { 51 List<CarPropertyConfig> properties = mHvacManager.getPropertyList(); 52 Set<Class> supportedTypes = new HashSet<>(Arrays.asList( 53 new Class[] { Integer.class, Float.class, Boolean.class, Integer[].class })); 54 55 for (CarPropertyConfig property : properties) { 56 if (supportedTypes.contains(property.getPropertyType())) { 57 assertTypeAndZone(property); 58 } else { 59 fail("Type is not supported for " + property); 60 } 61 } 62 } 63 64 @Test testHvacPosition()65 public void testHvacPosition() { 66 assertThat(VehicleHvacFanDirection.FACE).isEqualTo(CarHvacManager.FAN_DIRECTION_FACE); 67 assertThat(VehicleHvacFanDirection.FLOOR).isEqualTo(CarHvacManager.FAN_DIRECTION_FLOOR); 68 assertThat(VehicleHvacFanDirection.DEFROST).isEqualTo(CarHvacManager.FAN_DIRECTION_DEFROST); 69 } 70 assertTypeAndZone(CarPropertyConfig property)71 private void assertTypeAndZone(CarPropertyConfig property) { 72 switch (property.getPropertyId()) { 73 case CarHvacManager.ID_MIRROR_DEFROSTER_ON: // non-zoned bool 74 checkTypeAndGlobal(Integer.class, false, property); 75 break; 76 case CarHvacManager.ID_STEERING_WHEEL_HEAT: // non-zoned int 77 case CarHvacManager.ID_TEMPERATURE_DISPLAY_UNITS: 78 checkTypeAndGlobal(Integer.class, true, property); 79 checkIntMinMax(property); 80 break; 81 case CarHvacManager.ID_OUTSIDE_AIR_TEMP: 82 checkTypeAndGlobal(Float.class, true, property); 83 break; 84 case CarHvacManager.ID_ZONED_TEMP_SETPOINT: // zoned float 85 case CarHvacManager.ID_ZONED_TEMP_ACTUAL: 86 checkTypeAndGlobal(Float.class, false, property); 87 checkFloatMinMax(property); 88 break; 89 case CarHvacManager.ID_ZONED_FAN_SPEED_SETPOINT: // zoned int 90 case CarHvacManager.ID_ZONED_FAN_SPEED_RPM: 91 case CarHvacManager.ID_ZONED_SEAT_TEMP: 92 checkTypeAndGlobal(Integer.class, false, property); 93 checkIntMinMax(property); 94 break; 95 case CarHvacManager.ID_ZONED_FAN_DIRECTION: 96 checkTypeAndGlobal(Integer.class, false, property); 97 break; 98 case CarHvacManager.ID_ZONED_FAN_DIRECTION_AVAILABLE: 99 checkTypeAndGlobal(Integer[].class, false, property); 100 break; 101 case CarHvacManager.ID_ZONED_AC_ON: // zoned boolean 102 case CarHvacManager.ID_ZONED_AUTOMATIC_MODE_ON: 103 case CarHvacManager.ID_ZONED_AIR_RECIRCULATION_ON: 104 case CarHvacManager.ID_ZONED_MAX_AC_ON: 105 case CarHvacManager.ID_ZONED_DUAL_ZONE_ON: 106 case CarHvacManager.ID_ZONED_MAX_DEFROST_ON: 107 case CarHvacManager.ID_ZONED_HVAC_POWER_ON: 108 case CarHvacManager.ID_WINDOW_DEFROSTER_ON: 109 checkTypeAndGlobal(Boolean.class, false, property); 110 break; 111 default: 112 break; 113 } 114 } 115 checkTypeAndGlobal(Class<?> clazz, boolean global, CarPropertyConfig<Integer> property)116 private void checkTypeAndGlobal(Class<?> clazz, boolean global, 117 CarPropertyConfig<Integer> property) { 118 assertWithMessage("Wrong type, expecting %s type for id %s", clazz, 119 property.getPropertyId()).that(property.getPropertyType()).isEqualTo(clazz); 120 assertWithMessage( 121 "Wrong zone, should %s be global for id:%s, area type: %s" + property.getAreaType(), 122 property.getPropertyId(), property.getAreaType(), (global ? "" : "not ")) 123 .that(property.isGlobalProperty()).isEqualTo(global); 124 } 125 checkIntMinMax(CarPropertyConfig<Integer> property)126 private void checkIntMinMax(CarPropertyConfig<Integer> property) { 127 Log.i(TAG, "checkIntMinMax property:" + property); 128 if (!property.isGlobalProperty()) { 129 int[] areaIds = property.getAreaIds(); 130 assertThat(areaIds.length).isGreaterThan(0); 131 assertThat(property.getAreaCount()).isEqualTo(areaIds.length); 132 133 for (int areaId : areaIds) { 134 assertThat(property.hasArea(areaId)).isTrue(); 135 int min = property.getMinValue(areaId) == null ? 0 : property.getMinValue(areaId); 136 int max = property.getMaxValue(areaId) == null ? 0 : property.getMaxValue(areaId); 137 assertThat(min).isAtMost(max); 138 } 139 } else { 140 int min = property.getMinValue() == null ? 0 : property.getMinValue(); 141 int max = property.getMaxValue() == null ? 0 : property.getMinValue(); 142 assertThat(min).isAtMost(max); 143 for (int i = 0; i < 32; i++) { 144 assertThat(property.hasArea(0x1 << i)).isFalse(); 145 assertThat(property.getMinValue(0x1 << i)).isNull(); 146 assertThat(property.getMaxValue(0x1 << i)).isNull(); 147 } 148 } 149 } 150 checkFloatMinMax(CarPropertyConfig<Float> property)151 private void checkFloatMinMax(CarPropertyConfig<Float> property) { 152 Log.i(TAG, "checkFloatMinMax property:" + property); 153 if (!property.isGlobalProperty()) { 154 int[] areaIds = property.getAreaIds(); 155 assertThat(areaIds.length).isGreaterThan(0); 156 assertThat(property.getAreaCount()).isEqualTo(areaIds.length); 157 158 for (int areaId : areaIds) { 159 assertThat(property.hasArea(areaId)).isTrue(); 160 float min = 161 property.getMinValue(areaId) == null ? 0f : property.getMinValue(areaId); 162 float max = 163 property.getMaxValue(areaId) == null ? 0f : property.getMinValue(areaId); 164 assertThat(min).isAtMost(max); 165 } 166 } else { 167 float min = property.getMinValue() == null ? 0f : property.getMinValue(); 168 float max = property.getMaxValue() == null ? 0f : property.getMinValue(); 169 assertThat(min).isAtMost(max); 170 for (int i = 0; i < 32; i++) { 171 assertThat(property.hasArea(0x1 << i)).isFalse(); 172 assertThat(property.getMinValue(0x1 << i)).isNull(); 173 assertThat(property.getMaxValue(0x1 << i)).isNull(); 174 } 175 } 176 } 177 } 178