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