1 /* 2 * Copyright (C) 2023 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.systemui.car.hvac; 18 19 import android.car.hardware.CarPropertyConfig; 20 import android.car.hardware.property.AreaIdConfig; 21 22 /** 23 * Utility class for HVAC-related use cases. 24 */ 25 public final class HvacUtils { 26 /** 27 * @see #shouldAllowControl(boolean, boolean, boolean, boolean) 28 */ shouldAllowControl(boolean disableViewIfPowerOff, boolean powerOn)29 public static boolean shouldAllowControl(boolean disableViewIfPowerOff, boolean powerOn) { 30 return shouldAllowControl(disableViewIfPowerOff, powerOn, /* disableViewIfAutoOn= */false, 31 /* autoOn= */false); 32 } 33 34 /** 35 * @see #shouldAllowControl(boolean, boolean, boolean, boolean) 36 */ shouldAllowControl(boolean disableViewIfPowerOff, boolean powerOn, boolean autoOn)37 public static boolean shouldAllowControl(boolean disableViewIfPowerOff, boolean powerOn, 38 boolean autoOn) { 39 return shouldAllowControl(disableViewIfPowerOff, powerOn, /* disableViewIfAutoOn= */true, 40 autoOn); 41 } 42 43 /** 44 * Returns whether the view can be controlled. 45 * 46 * @param disableViewIfPowerOff whether the view can be controlled when hvac power is off 47 * @param powerOn is hvac power on 48 * @param disableViewIfAutoOn whether the view can be controlled when hvac auto mode is on 49 * @param autoOn is auto mode on 50 * @return is the view controllable 51 */ shouldAllowControl(boolean disableViewIfPowerOff, boolean powerOn, boolean disableViewIfAutoOn, boolean autoOn)52 public static boolean shouldAllowControl(boolean disableViewIfPowerOff, boolean powerOn, 53 boolean disableViewIfAutoOn, boolean autoOn) { 54 return (!disableViewIfPowerOff || powerOn) && (!disableViewIfAutoOn || !autoOn); 55 } 56 57 /** 58 * For an {@code Integer} property, return the highest minimum value specified for all area IDs. 59 * If there are no minimum values provided by all of the area IDs or if the property is not an 60 * {@code Integer} property, return {@code null}. 61 * 62 * @param carPropertyConfig {@code Integer} CarPropertyConfig 63 * @return highest min value or {@code null} 64 */ getHighestMinValueForAllAreaIds(CarPropertyConfig<?> carPropertyConfig)65 public static Integer getHighestMinValueForAllAreaIds(CarPropertyConfig<?> carPropertyConfig) { 66 if (!carPropertyConfig.getPropertyType().equals(Integer.class)) { 67 return null; 68 } 69 Integer highestMinValue = null; 70 for (AreaIdConfig<?> areaIdConfig: carPropertyConfig.getAreaIdConfigs()) { 71 if (highestMinValue == null || (areaIdConfig.getMinValue() != null 72 && (Integer) areaIdConfig.getMinValue() > highestMinValue)) { 73 highestMinValue = (Integer) areaIdConfig.getMinValue(); 74 } 75 } 76 return highestMinValue; 77 } 78 79 /** 80 * For an {@code Integer} property, return the lowest maximum value specified for all area IDs. 81 * If there are no maximum values provided by all of the area IDs or if the property is not an 82 * {@code Integer} property, return {@code null}. 83 * 84 * @param carPropertyConfig {@code Integer} CarPropertyConfig 85 * @return lowest max value or {@code null} 86 */ getLowestMaxValueForAllAreaIds(CarPropertyConfig<?> carPropertyConfig)87 public static Integer getLowestMaxValueForAllAreaIds(CarPropertyConfig<?> carPropertyConfig) { 88 if (!carPropertyConfig.getPropertyType().equals(Integer.class)) { 89 return null; 90 } 91 Integer lowestMaxValue = null; 92 for (AreaIdConfig<?> areaIdConfig: carPropertyConfig.getAreaIdConfigs()) { 93 if (lowestMaxValue == null || (areaIdConfig.getMaxValue() != null 94 && (Integer) areaIdConfig.getMaxValue() < lowestMaxValue)) { 95 lowestMaxValue = (Integer) areaIdConfig.getMaxValue(); 96 } 97 } 98 return lowestMaxValue; 99 } 100 } 101