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 com.android.cts.deviceowner; 17 18 import android.content.Context; 19 import android.content.pm.PackageManager; 20 import android.os.HardwarePropertiesManager; 21 import android.test.AndroidTestCase; 22 import android.util.Log; 23 24 import java.lang.Math; 25 26 public class VrTemperatureTest extends BaseDeviceOwnerTest { 27 public static final int MIN_DEVICE_TEMPERATURE = -20; 28 public static final int MAX_DEVICE_TEMPERATURE = 200; 29 supportsVrHighPerformance()30 public boolean supportsVrHighPerformance() { 31 PackageManager pm = getContext().getPackageManager(); 32 return pm.hasSystemFeature(PackageManager.FEATURE_VR_MODE_HIGH_PERFORMANCE); 33 } 34 checkDeviceTemp(float temp, float throttlingTemp, float shutdownTemp, float vrThrottlingTemp)35 private void checkDeviceTemp(float temp, float throttlingTemp, float shutdownTemp, 36 float vrThrottlingTemp) { 37 38 // Compare current temperature and shutdown threshold to determine direction. 39 if (shutdownTemp != HardwarePropertiesManager.UNDEFINED_TEMPERATURE 40 && throttlingTemp != HardwarePropertiesManager.UNDEFINED_TEMPERATURE) { 41 42 // Cold (lower) thresholds. 43 if (throttlingTemp > shutdownTemp) { 44 // Compare current temperature and shutdown threshold. 45 assertTrue(temp > shutdownTemp 46 || temp == HardwarePropertiesManager.UNDEFINED_TEMPERATURE); 47 } 48 49 // Warm (upper) thresholds. 50 else if (throttlingTemp < shutdownTemp) { 51 // Compare current temperature and shutdown threshold. 52 assertTrue(temp < shutdownTemp 53 || temp == HardwarePropertiesManager.UNDEFINED_TEMPERATURE); 54 } 55 } 56 57 // Compare VR throttling and shutdown thresholds. 58 assertTrue(vrThrottlingTemp <= MIN_DEVICE_TEMPERATURE || 59 vrThrottlingTemp <= shutdownTemp || 60 shutdownTemp == HardwarePropertiesManager.UNDEFINED_TEMPERATURE); 61 } 62 63 private void checkTemps(float[] temps, float[] throttlingThresholds, 64 float[] shutdownThresholds, float[] vrThrottlingThresholds) { 65 assertEquals(temps.length, throttlingThresholds.length); 66 assertEquals(temps.length, shutdownThresholds.length); 67 boolean hasVrThreshold = vrThrottlingThresholds != null && 68 vrThrottlingThresholds.length > 0; 69 if (hasVrThreshold) { 70 assertEquals(temps.length, vrThrottlingThresholds.length); 71 } 72 for (int i = 0; i < temps.length; ++i) { 73 checkDeviceTemp(temps[i], throttlingThresholds[i], shutdownThresholds[i], 74 !hasVrThreshold ? MIN_DEVICE_TEMPERATURE : vrThrottlingThresholds[i]); 75 } 76 } 77 78 /** 79 * Tests that temperature sensors return valid values. 80 */ 81 public void testVrTemperatures() throws InterruptedException, SecurityException { 82 if (!supportsVrHighPerformance()) 83 return; 84 85 HardwarePropertiesManager hm = (HardwarePropertiesManager) getContext().getSystemService( 86 Context.HARDWARE_PROPERTIES_SERVICE); 87 88 float[] cpuTemps = hm.getDeviceTemperatures( 89 HardwarePropertiesManager.DEVICE_TEMPERATURE_CPU, 90 HardwarePropertiesManager.TEMPERATURE_CURRENT); 91 float[] cpuThrottlingThresholds = hm.getDeviceTemperatures( 92 HardwarePropertiesManager.DEVICE_TEMPERATURE_CPU, 93 HardwarePropertiesManager.TEMPERATURE_THROTTLING); 94 float[] cpuShutdownThresholds = hm.getDeviceTemperatures( 95 HardwarePropertiesManager.DEVICE_TEMPERATURE_CPU, 96 HardwarePropertiesManager.TEMPERATURE_SHUTDOWN); 97 98 float[] gpuTemps = hm.getDeviceTemperatures( 99 HardwarePropertiesManager.DEVICE_TEMPERATURE_GPU, 100 HardwarePropertiesManager.TEMPERATURE_CURRENT); 101 float[] gpuThrottlingThresholds = hm.getDeviceTemperatures( 102 HardwarePropertiesManager.DEVICE_TEMPERATURE_GPU, 103 HardwarePropertiesManager.TEMPERATURE_THROTTLING); 104 float[] gpuShutdownThresholds = hm.getDeviceTemperatures( 105 HardwarePropertiesManager.DEVICE_TEMPERATURE_GPU, 106 HardwarePropertiesManager.TEMPERATURE_SHUTDOWN); 107 108 float[] batteryTemps = hm.getDeviceTemperatures( 109 HardwarePropertiesManager.DEVICE_TEMPERATURE_BATTERY, 110 HardwarePropertiesManager.TEMPERATURE_CURRENT); 111 float[] batteryThrottlingThresholds = hm.getDeviceTemperatures( 112 HardwarePropertiesManager.DEVICE_TEMPERATURE_BATTERY, 113 HardwarePropertiesManager.TEMPERATURE_THROTTLING); 114 float[] batteryShutdownThresholds = hm.getDeviceTemperatures( 115 HardwarePropertiesManager.DEVICE_TEMPERATURE_BATTERY, 116 HardwarePropertiesManager.TEMPERATURE_SHUTDOWN); 117 118 float[] skinTemps = hm.getDeviceTemperatures( 119 HardwarePropertiesManager.DEVICE_TEMPERATURE_SKIN, 120 HardwarePropertiesManager.TEMPERATURE_CURRENT); 121 float[] skinThrottlingThresholds = hm.getDeviceTemperatures( 122 HardwarePropertiesManager.DEVICE_TEMPERATURE_SKIN, 123 HardwarePropertiesManager.TEMPERATURE_THROTTLING); 124 float[] skinShutdownThresholds = hm.getDeviceTemperatures( 125 HardwarePropertiesManager.DEVICE_TEMPERATURE_SKIN, 126 HardwarePropertiesManager.TEMPERATURE_SHUTDOWN); 127 float[] skinVrThrottlingThresholds = hm.getDeviceTemperatures( 128 HardwarePropertiesManager.DEVICE_TEMPERATURE_SKIN, 129 HardwarePropertiesManager.TEMPERATURE_THROTTLING_BELOW_VR_MIN); 130 131 checkTemps(cpuTemps, cpuThrottlingThresholds, cpuShutdownThresholds, null); 132 checkTemps(gpuTemps, gpuThrottlingThresholds, gpuShutdownThresholds, null); 133 checkTemps(batteryTemps, batteryThrottlingThresholds, batteryShutdownThresholds, null); 134 checkTemps(skinTemps, skinThrottlingThresholds, skinShutdownThresholds, 135 skinVrThrottlingThresholds); 136 } 137 } 138