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 20 import static org.junit.Assert.fail; 21 22 import android.car.Car; 23 import android.car.extendedapitest.testbase.CarApiTestBase; 24 import android.car.hardware.CarPropertyConfig; 25 import android.car.hardware.cabin.CarCabinManager; 26 import android.util.Log; 27 28 import androidx.test.filters.MediumTest; 29 30 import org.junit.Before; 31 import org.junit.Ignore; 32 import org.junit.Test; 33 34 import java.util.Arrays; 35 import java.util.HashSet; 36 import java.util.List; 37 import java.util.Set; 38 39 @MediumTest 40 public final class CarCabinManagerTest extends CarApiTestBase { 41 private static final String TAG = CarCabinManagerTest.class.getSimpleName(); 42 43 private CarCabinManager mCabinManager; 44 45 @Before setUp()46 public void setUp() throws Exception { 47 mCabinManager = (CarCabinManager) getCar().getCarManager(Car.CABIN_SERVICE); 48 assertThat(mCabinManager).isNotNull(); 49 } 50 51 @Test 52 @Ignore("b/256244980-ID_WINDOW_LOCK is incorrect") testAllCabinProperties()53 public void testAllCabinProperties() throws Exception { 54 List<CarPropertyConfig> properties = mCabinManager.getPropertyList(); 55 Set<Class> supportedTypes = new HashSet<>(Arrays.asList( 56 new Class[] { Integer.class, Boolean.class })); 57 58 for (CarPropertyConfig property : properties) { 59 if (supportedTypes.contains(property.getPropertyType())) { 60 assertTypeAndZone(property); 61 } else { 62 fail("Type is not supported for " + property); 63 } 64 } 65 } 66 assertTypeAndZone(CarPropertyConfig property)67 private void assertTypeAndZone(CarPropertyConfig property) { 68 int propId = property.getPropertyId(); 69 switch (propId) { 70 // Global boolean properties 71 case CarCabinManager.ID_MIRROR_LOCK: 72 case CarCabinManager.ID_MIRROR_FOLD: 73 assertThat(property.getPropertyType()).isAssignableTo(Boolean.class); 74 assertThat(property.isGlobalProperty()).isTrue(); 75 break; 76 77 // Zoned boolean properties 78 case CarCabinManager.ID_DOOR_LOCK: 79 case CarCabinManager.ID_SEAT_BELT_BUCKLED: 80 case CarCabinManager.ID_WINDOW_LOCK: 81 assertThat(property.getPropertyType()).isAssignableTo(Boolean.class); 82 assertThat(property.isGlobalProperty()).isFalse(); 83 break; 84 85 // Zoned integer properties 86 case CarCabinManager.ID_DOOR_POS: 87 case CarCabinManager.ID_DOOR_MOVE: 88 case CarCabinManager.ID_MIRROR_Z_POS: 89 case CarCabinManager.ID_MIRROR_Z_MOVE: 90 case CarCabinManager.ID_MIRROR_Y_POS: 91 case CarCabinManager.ID_MIRROR_Y_MOVE: 92 case CarCabinManager.ID_SEAT_MEMORY_SELECT: 93 case CarCabinManager.ID_SEAT_MEMORY_SET: 94 case CarCabinManager.ID_SEAT_BELT_HEIGHT_POS: 95 case CarCabinManager.ID_SEAT_BELT_HEIGHT_MOVE: 96 case CarCabinManager.ID_SEAT_FORE_AFT_POS: 97 case CarCabinManager.ID_SEAT_FORE_AFT_MOVE: 98 case CarCabinManager.ID_SEAT_BACKREST_ANGLE_1_POS: 99 case CarCabinManager.ID_SEAT_BACKREST_ANGLE_1_MOVE: 100 case CarCabinManager.ID_SEAT_BACKREST_ANGLE_2_POS: 101 case CarCabinManager.ID_SEAT_BACKREST_ANGLE_2_MOVE: 102 case CarCabinManager.ID_SEAT_HEIGHT_POS: 103 case CarCabinManager.ID_SEAT_HEIGHT_MOVE: 104 case CarCabinManager.ID_SEAT_DEPTH_POS: 105 case CarCabinManager.ID_SEAT_DEPTH_MOVE: 106 case CarCabinManager.ID_SEAT_TILT_POS: 107 case CarCabinManager.ID_SEAT_TILT_MOVE: 108 case CarCabinManager.ID_SEAT_LUMBAR_FORE_AFT_POS: 109 case CarCabinManager.ID_SEAT_LUMBAR_FORE_AFT_MOVE: 110 case CarCabinManager.ID_SEAT_LUMBAR_SIDE_SUPPORT_POS: 111 case CarCabinManager.ID_SEAT_LUMBAR_SIDE_SUPPORT_MOVE: 112 case CarCabinManager.ID_SEAT_HEADREST_HEIGHT_POS: 113 case CarCabinManager.ID_SEAT_HEADREST_HEIGHT_MOVE: 114 case CarCabinManager.ID_SEAT_HEADREST_ANGLE_POS: 115 case CarCabinManager.ID_SEAT_HEADREST_ANGLE_MOVE: 116 case CarCabinManager.ID_SEAT_HEADREST_FORE_AFT_POS: 117 case CarCabinManager.ID_SEAT_HEADREST_FORE_AFT_MOVE: 118 case CarCabinManager.ID_WINDOW_POS: 119 case CarCabinManager.ID_WINDOW_MOVE: 120 assertThat(property.getPropertyType()).isAssignableTo(Integer.class); 121 assertThat(property.isGlobalProperty()).isFalse(); 122 checkIntMinMax(property); 123 break; 124 default: 125 Log.e(TAG, "Property ID not handled: " + propId); 126 assertThat(false).isTrue(); 127 break; 128 } 129 } 130 checkIntMinMax(CarPropertyConfig<Integer> property)131 private void checkIntMinMax(CarPropertyConfig<Integer> property) { 132 Log.i(TAG, "checkIntMinMax property:" + property); 133 if (!property.isGlobalProperty()) { 134 int[] areaIds = property.getAreaIds(); 135 assertThat(areaIds.length).isGreaterThan(0); 136 assertThat(property.getAreaCount()).isEqualTo(areaIds.length); 137 138 for (int areId : areaIds) { 139 assertThat(property.hasArea(areId)).isTrue(); 140 int min = property.getMinValue(areId); 141 int max = property.getMaxValue(areId); 142 assertThat(min).isAtMost(max); 143 } 144 } else { 145 int min = property.getMinValue(); 146 int max = property.getMaxValue(); 147 assertThat(min).isAtMost(max); 148 for (int i = 0; i < 32; i++) { 149 assertThat(property.hasArea(0x1 << i)).isFalse(); 150 assertThat(property.getMinValue(0x1 << i)).isNull(); 151 assertThat(property.getMaxValue(0x1 << i)).isNull(); 152 } 153 } 154 } 155 } 156