1 /* 2 * Copyright (C) 2022 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.server.power; 18 19 import static org.junit.Assert.assertArrayEquals; 20 import static org.junit.Assert.assertEquals; 21 import static org.junit.Assert.assertNotNull; 22 import static org.junit.Assert.assertTrue; 23 24 import android.hardware.thermal.CoolingType; 25 import android.hardware.thermal.IThermal; 26 import android.hardware.thermal.IThermalChangedCallback; 27 import android.hardware.thermal.TemperatureThreshold; 28 import android.hardware.thermal.TemperatureType; 29 import android.hardware.thermal.ThrottlingSeverity; 30 import android.os.Binder; 31 import android.os.CoolingDevice; 32 import android.os.RemoteException; 33 import android.os.Temperature; 34 35 import org.junit.Before; 36 import org.junit.Test; 37 import org.mockito.ArgumentCaptor; 38 import org.mockito.Captor; 39 import org.mockito.Mock; 40 import org.mockito.Mockito; 41 import org.mockito.MockitoAnnotations; 42 43 import java.util.List; 44 import java.util.concurrent.CompletableFuture; 45 import java.util.concurrent.TimeUnit; 46 47 48 public class ThermalManagerServiceMockingTest { 49 @Mock private IThermal mAidlHalMock; 50 private Binder mAidlBinder = new Binder(); 51 private CompletableFuture<Temperature> mTemperatureFuture; 52 private ThermalManagerService.ThermalHalWrapper.TemperatureChangedCallback mTemperatureCallback; 53 private ThermalManagerService.ThermalHalAidlWrapper mAidlWrapper; 54 @Captor 55 ArgumentCaptor<IThermalChangedCallback> mAidlCallbackCaptor; 56 57 @Before setUp()58 public void setUp() { 59 MockitoAnnotations.initMocks(this); 60 Mockito.when(mAidlHalMock.asBinder()).thenReturn(mAidlBinder); 61 mAidlBinder.attachInterface(mAidlHalMock, IThermal.class.getName()); 62 mTemperatureFuture = new CompletableFuture<>(); 63 mTemperatureCallback = temperature -> mTemperatureFuture.complete(temperature); 64 mAidlWrapper = new ThermalManagerService.ThermalHalAidlWrapper(mTemperatureCallback); 65 mAidlWrapper.initProxyAndRegisterCallback(mAidlBinder); 66 } 67 68 @Test setCallback_aidl()69 public void setCallback_aidl() throws Exception { 70 Mockito.verify(mAidlHalMock, Mockito.times(1)).registerThermalChangedCallback( 71 mAidlCallbackCaptor.capture()); 72 android.hardware.thermal.Temperature halT = 73 new android.hardware.thermal.Temperature(); 74 halT.type = TemperatureType.SOC; 75 halT.name = "test"; 76 halT.throttlingStatus = ThrottlingSeverity.SHUTDOWN; 77 halT.value = 99.0f; 78 mAidlCallbackCaptor.getValue().notifyThrottling(halT); 79 Temperature temperature = mTemperatureFuture.get(100, TimeUnit.MILLISECONDS); 80 assertEquals(halT.name, temperature.getName()); 81 assertEquals(halT.type, temperature.getType()); 82 assertEquals(halT.value, temperature.getValue(), 0.1f); 83 assertEquals(halT.throttlingStatus, temperature.getStatus()); 84 } 85 86 @Test setCallback_illegalState_aidl()87 public void setCallback_illegalState_aidl() throws Exception { 88 Mockito.doThrow(new IllegalStateException()).when( 89 mAidlHalMock).registerThermalChangedCallback(Mockito.any()); 90 verifyWrapperStatusOnCallbackError(); 91 } 92 93 @Test setCallback_illegalArgument_aidl()94 public void setCallback_illegalArgument_aidl() throws Exception { 95 Mockito.doThrow(new IllegalStateException()).when( 96 mAidlHalMock).registerThermalChangedCallback(Mockito.any()); 97 verifyWrapperStatusOnCallbackError(); 98 } 99 100 verifyWrapperStatusOnCallbackError()101 void verifyWrapperStatusOnCallbackError() throws RemoteException { 102 android.hardware.thermal.Temperature halT1 = new android.hardware.thermal.Temperature(); 103 halT1.type = TemperatureType.MODEM; 104 halT1.name = "test1"; 105 Mockito.when(mAidlHalMock.getTemperaturesWithType(Mockito.anyInt())).thenReturn( 106 new android.hardware.thermal.Temperature[]{ 107 halT1 108 }); 109 List<Temperature> ret = mAidlWrapper.getCurrentTemperatures(true, TemperatureType.MODEM); 110 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperaturesWithType( 111 TemperatureType.MODEM); 112 assertNotNull(ret); 113 Temperature expectedT1 = new Temperature(halT1.value, halT1.type, halT1.name, 114 halT1.throttlingStatus); 115 List<Temperature> expectedRet = List.of(expectedT1); 116 // test that even if the callback fails to register without hal connection error, the 117 // wrapper should still work 118 assertTrue("Got temperature list as " + ret + " with different values compared to " 119 + expectedRet, expectedRet.containsAll(ret)); 120 } 121 122 @Test getCurrentTemperatures_aidl()123 public void getCurrentTemperatures_aidl() throws RemoteException { 124 android.hardware.thermal.Temperature halT1 = new android.hardware.thermal.Temperature(); 125 halT1.type = TemperatureType.MODEM; 126 halT1.name = "test1"; 127 halT1.throttlingStatus = ThrottlingSeverity.EMERGENCY; 128 halT1.value = 99.0f; 129 android.hardware.thermal.Temperature halT2 = new android.hardware.thermal.Temperature(); 130 halT2.name = "test2"; 131 halT2.type = TemperatureType.SOC; 132 halT2.throttlingStatus = ThrottlingSeverity.NONE; 133 134 Mockito.when(mAidlHalMock.getTemperatures()).thenReturn( 135 new android.hardware.thermal.Temperature[]{ 136 halT2, halT1 137 }); 138 List<Temperature> ret = mAidlWrapper.getCurrentTemperatures(false, TemperatureType.UNKNOWN); 139 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatures(); 140 141 Temperature expectedT1 = new Temperature(halT1.value, halT1.type, halT1.name, 142 halT1.throttlingStatus); 143 Temperature expectedT2 = new Temperature(halT2.value, halT2.type, halT2.name, 144 halT2.throttlingStatus); 145 List<Temperature> expectedRet = List.of(expectedT1, expectedT2); 146 assertTrue("Got temperature list as " + ret + " with different values compared to " 147 + expectedRet, expectedRet.containsAll(ret)); 148 } 149 150 @Test getCurrentTemperatures_withFilter_aidl()151 public void getCurrentTemperatures_withFilter_aidl() throws RemoteException { 152 android.hardware.thermal.Temperature halT1 = new android.hardware.thermal.Temperature(); 153 halT1.type = TemperatureType.MODEM; 154 halT1.name = "test1"; 155 halT1.throttlingStatus = ThrottlingSeverity.EMERGENCY; 156 halT1.value = 99.0f; 157 android.hardware.thermal.Temperature halT2 = new android.hardware.thermal.Temperature(); 158 halT2.name = "test2"; 159 halT2.type = TemperatureType.MODEM; 160 halT2.throttlingStatus = ThrottlingSeverity.NONE; 161 162 android.hardware.thermal.Temperature halT3WithDiffType = 163 new android.hardware.thermal.Temperature(); 164 halT3WithDiffType.type = TemperatureType.BCL_CURRENT; 165 halT3WithDiffType.throttlingStatus = ThrottlingSeverity.CRITICAL; 166 167 Mockito.when(mAidlHalMock.getTemperaturesWithType(Mockito.anyInt())).thenReturn( 168 new android.hardware.thermal.Temperature[]{ 169 halT2, halT1, halT3WithDiffType, 170 }); 171 List<Temperature> ret = mAidlWrapper.getCurrentTemperatures(true, TemperatureType.MODEM); 172 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperaturesWithType( 173 TemperatureType.MODEM); 174 175 Temperature expectedT1 = new Temperature(halT1.value, halT1.type, halT1.name, 176 halT1.throttlingStatus); 177 Temperature expectedT2 = new Temperature(halT2.value, halT2.type, halT2.name, 178 halT2.throttlingStatus); 179 List<Temperature> expectedRet = List.of(expectedT1, expectedT2); 180 assertTrue("Got temperature list as " + ret + " with different values compared to " 181 + expectedRet, expectedRet.containsAll(ret)); 182 } 183 184 @Test getCurrentTemperatures_nullResult_aidl()185 public void getCurrentTemperatures_nullResult_aidl() throws RemoteException { 186 Mockito.when(mAidlHalMock.getTemperaturesWithType(Mockito.anyInt())).thenReturn(null); 187 List<Temperature> ret = mAidlWrapper.getCurrentTemperatures(true, 188 Temperature.TYPE_SOC); 189 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperaturesWithType( 190 Temperature.TYPE_SOC); 191 assertNotNull(ret); 192 assertEquals(0, ret.size()); 193 194 Mockito.when(mAidlHalMock.getTemperatures()).thenReturn(null); 195 ret = mAidlWrapper.getCurrentTemperatures(false, Temperature.TYPE_SOC); 196 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatures(); 197 assertNotNull(ret); 198 assertEquals(0, ret.size()); 199 } 200 201 @Test getCurrentTemperatures_invalidStatus_aidl()202 public void getCurrentTemperatures_invalidStatus_aidl() throws RemoteException { 203 android.hardware.thermal.Temperature halTInvalid = 204 new android.hardware.thermal.Temperature(); 205 halTInvalid.name = "test"; 206 halTInvalid.type = TemperatureType.MODEM; 207 halTInvalid.throttlingStatus = 99; 208 209 Mockito.when(mAidlHalMock.getTemperatures()).thenReturn( 210 new android.hardware.thermal.Temperature[]{ 211 halTInvalid 212 }); 213 List<Temperature> ret = mAidlWrapper.getCurrentTemperatures(false, 0); 214 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatures(); 215 216 List<Temperature> expectedRet = List.of( 217 new Temperature(halTInvalid.value, halTInvalid.type, halTInvalid.name, 218 ThrottlingSeverity.NONE)); 219 assertTrue("Got temperature list as " + ret + " with different values compared to " 220 + expectedRet, expectedRet.containsAll(ret)); 221 } 222 223 @Test getCurrentTemperatures_illegalArgument_aidl()224 public void getCurrentTemperatures_illegalArgument_aidl() throws RemoteException { 225 Mockito.when(mAidlHalMock.getTemperatures()).thenThrow(new IllegalArgumentException()); 226 List<Temperature> ret = mAidlWrapper.getCurrentTemperatures(false, 0); 227 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatures(); 228 assertNotNull(ret); 229 assertEquals(0, ret.size()); 230 231 Mockito.when(mAidlHalMock.getTemperaturesWithType(TemperatureType.MODEM)).thenThrow( 232 new IllegalArgumentException()); 233 ret = mAidlWrapper.getCurrentTemperatures(true, TemperatureType.MODEM); 234 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperaturesWithType( 235 TemperatureType.MODEM); 236 assertNotNull(ret); 237 assertEquals(0, ret.size()); 238 } 239 240 @Test getCurrentTemperatures_illegalState_aidl()241 public void getCurrentTemperatures_illegalState_aidl() throws RemoteException { 242 Mockito.when(mAidlHalMock.getTemperatures()).thenThrow(new IllegalStateException()); 243 List<Temperature> ret = mAidlWrapper.getCurrentTemperatures(false, 0); 244 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatures(); 245 assertNotNull(ret); 246 assertEquals(0, ret.size()); 247 248 Mockito.when(mAidlHalMock.getTemperaturesWithType(TemperatureType.MODEM)).thenThrow( 249 new IllegalStateException()); 250 ret = mAidlWrapper.getCurrentTemperatures(true, TemperatureType.MODEM); 251 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperaturesWithType( 252 TemperatureType.MODEM); 253 assertNotNull(ret); 254 assertEquals(0, ret.size()); 255 } 256 257 @Test getCurrentCoolingDevices_aidl()258 public void getCurrentCoolingDevices_aidl() throws RemoteException { 259 android.hardware.thermal.CoolingDevice halC1 = new android.hardware.thermal.CoolingDevice(); 260 halC1.type = CoolingType.SPEAKER; 261 halC1.name = "test1"; 262 halC1.value = 10; 263 android.hardware.thermal.CoolingDevice halC2 = new android.hardware.thermal.CoolingDevice(); 264 halC2.type = CoolingType.MODEM; 265 halC2.name = "test2"; 266 halC2.value = 110; 267 268 Mockito.when(mAidlHalMock.getCoolingDevicesWithType(Mockito.anyInt())).thenReturn( 269 new android.hardware.thermal.CoolingDevice[]{ 270 halC1, halC2 271 } 272 ); 273 Mockito.when(mAidlHalMock.getCoolingDevices()).thenReturn( 274 new android.hardware.thermal.CoolingDevice[]{ 275 halC1, halC2 276 } 277 ); 278 List<CoolingDevice> ret = mAidlWrapper.getCurrentCoolingDevices(false, 279 CoolingType.COMPONENT); 280 Mockito.verify(mAidlHalMock, Mockito.times(1)).getCoolingDevices(); 281 282 CoolingDevice expectedC1 = new CoolingDevice(halC1.value, halC1.type, halC1.name); 283 CoolingDevice expectedC2 = new CoolingDevice(halC2.value, halC2.type, halC2.name); 284 List<CoolingDevice> expectedRet = List.of(expectedC1, expectedC2); 285 assertTrue("Got cooling device list as " + ret + " with different values compared to " 286 + expectedRet, expectedRet.containsAll(ret)); 287 } 288 289 @Test getCurrentCoolingDevices_nullResult_aidl()290 public void getCurrentCoolingDevices_nullResult_aidl() throws RemoteException { 291 Mockito.when(mAidlHalMock.getCoolingDevicesWithType(Mockito.anyInt())).thenReturn(null); 292 List<CoolingDevice> ret = mAidlWrapper.getCurrentCoolingDevices(true, 293 CoolingType.COMPONENT); 294 Mockito.verify(mAidlHalMock, Mockito.times(1)).getCoolingDevicesWithType( 295 CoolingType.COMPONENT); 296 assertNotNull(ret); 297 assertEquals(0, ret.size()); 298 299 Mockito.when(mAidlHalMock.getCoolingDevices()).thenReturn(null); 300 ret = mAidlWrapper.getCurrentCoolingDevices(false, CoolingType.COMPONENT); 301 Mockito.verify(mAidlHalMock, Mockito.times(1)).getCoolingDevices(); 302 assertNotNull(ret); 303 assertEquals(0, ret.size()); 304 } 305 306 @Test getCurrentCoolingDevices_withFilter_aidl()307 public void getCurrentCoolingDevices_withFilter_aidl() throws RemoteException { 308 android.hardware.thermal.CoolingDevice halC1 = new android.hardware.thermal.CoolingDevice(); 309 halC1.type = CoolingType.SPEAKER; 310 halC1.name = "test1"; 311 halC1.value = 10; 312 android.hardware.thermal.CoolingDevice halC2 = new android.hardware.thermal.CoolingDevice(); 313 halC2.type = CoolingType.MODEM; 314 halC2.name = "test2"; 315 halC2.value = 110; 316 317 Mockito.when(mAidlHalMock.getCoolingDevicesWithType(Mockito.anyInt())).thenReturn( 318 new android.hardware.thermal.CoolingDevice[]{ 319 halC1, halC2 320 } 321 ); 322 List<CoolingDevice> ret = mAidlWrapper.getCurrentCoolingDevices(true, CoolingType.SPEAKER); 323 Mockito.verify(mAidlHalMock, Mockito.times(1)).getCoolingDevicesWithType( 324 CoolingType.SPEAKER); 325 326 CoolingDevice expectedC1 = new CoolingDevice(halC1.value, halC1.type, halC1.name); 327 List<CoolingDevice> expectedRet = List.of(expectedC1); 328 assertTrue("Got cooling device list as " + ret + " with different values compared to " 329 + expectedRet, expectedRet.containsAll(ret)); 330 } 331 332 @Test getCurrentCoolingDevices_invalidType_aidl()333 public void getCurrentCoolingDevices_invalidType_aidl() throws RemoteException { 334 android.hardware.thermal.CoolingDevice halC1 = new android.hardware.thermal.CoolingDevice(); 335 halC1.type = 99; 336 halC1.name = "test1"; 337 halC1.value = 10; 338 android.hardware.thermal.CoolingDevice halC2 = new android.hardware.thermal.CoolingDevice(); 339 halC2.type = -1; 340 halC2.name = "test2"; 341 halC2.value = 110; 342 343 Mockito.when(mAidlHalMock.getCoolingDevices()).thenReturn( 344 new android.hardware.thermal.CoolingDevice[]{ 345 halC1, halC2 346 } 347 ); 348 List<CoolingDevice> ret = mAidlWrapper.getCurrentCoolingDevices(false, 0); 349 Mockito.verify(mAidlHalMock, Mockito.times(1)).getCoolingDevices(); 350 351 assertTrue("Got cooling device list as " + ret + ", expecting empty list", ret.isEmpty()); 352 } 353 354 @Test getCurrentCoolingDevices_illegalArgument_aidl()355 public void getCurrentCoolingDevices_illegalArgument_aidl() throws RemoteException { 356 Mockito.when(mAidlHalMock.getCoolingDevices()).thenThrow(new IllegalArgumentException()); 357 List<CoolingDevice> ret = mAidlWrapper.getCurrentCoolingDevices(false, 0); 358 Mockito.verify(mAidlHalMock, Mockito.times(1)).getCoolingDevices(); 359 assertNotNull(ret); 360 assertEquals(0, ret.size()); 361 362 Mockito.when(mAidlHalMock.getCoolingDevicesWithType(Mockito.anyInt())).thenThrow( 363 new IllegalArgumentException()); 364 ret = mAidlWrapper.getCurrentCoolingDevices(true, CoolingType.SPEAKER); 365 Mockito.verify(mAidlHalMock, Mockito.times(1)).getCoolingDevicesWithType( 366 CoolingType.SPEAKER); 367 assertNotNull(ret); 368 assertEquals(0, ret.size()); 369 } 370 371 @Test getCurrentCoolingDevices_illegalState_aidl()372 public void getCurrentCoolingDevices_illegalState_aidl() throws RemoteException { 373 Mockito.when(mAidlHalMock.getCoolingDevices()).thenThrow(new IllegalStateException()); 374 List<CoolingDevice> ret = mAidlWrapper.getCurrentCoolingDevices(false, 0); 375 Mockito.verify(mAidlHalMock, Mockito.times(1)).getCoolingDevices(); 376 assertNotNull(ret); 377 assertEquals(0, ret.size()); 378 379 Mockito.when(mAidlHalMock.getCoolingDevicesWithType(Mockito.anyInt())).thenThrow( 380 new IllegalStateException()); 381 ret = mAidlWrapper.getCurrentCoolingDevices(true, CoolingType.SPEAKER); 382 Mockito.verify(mAidlHalMock, Mockito.times(1)).getCoolingDevicesWithType( 383 CoolingType.SPEAKER); 384 assertNotNull(ret); 385 assertEquals(0, ret.size()); 386 } 387 388 @Test getTemperatureThresholds_aidl()389 public void getTemperatureThresholds_aidl() throws RemoteException { 390 TemperatureThreshold halT1 = new TemperatureThreshold(); 391 halT1.name = "test1"; 392 halT1.type = Temperature.TYPE_SKIN; 393 halT1.hotThrottlingThresholds = new float[]{1, 2, 3}; 394 halT1.coldThrottlingThresholds = new float[]{}; 395 396 TemperatureThreshold halT2 = new TemperatureThreshold(); 397 halT2.name = "test2"; 398 halT2.type = Temperature.TYPE_SOC; 399 halT2.hotThrottlingThresholds = new float[]{}; 400 halT2.coldThrottlingThresholds = new float[]{3, 2, 1}; 401 402 Mockito.when(mAidlHalMock.getTemperatureThresholds()).thenReturn( 403 new TemperatureThreshold[]{halT1, halT2} 404 ); 405 List<TemperatureThreshold> ret = mAidlWrapper.getTemperatureThresholds(false, 406 Temperature.TYPE_UNKNOWN); 407 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatureThresholds(); 408 409 assertEquals("Got unexpected temperature thresholds size", 2, ret.size()); 410 TemperatureThreshold threshold = ret.get(0).type == Temperature.TYPE_SKIN ? ret.get(0) 411 : ret.get(1); 412 413 assertEquals(halT1.name, threshold.name); 414 assertEquals(halT1.type, threshold.type); 415 assertArrayEquals(halT1.hotThrottlingThresholds, threshold.hotThrottlingThresholds, 0.1f); 416 assertArrayEquals(halT1.coldThrottlingThresholds, threshold.coldThrottlingThresholds, 0.1f); 417 418 threshold = ret.get(0).type == Temperature.TYPE_SOC ? ret.get(0) : ret.get(1); 419 420 assertEquals(halT2.name, threshold.name); 421 assertEquals(halT2.type, threshold.type); 422 assertArrayEquals(halT2.hotThrottlingThresholds, threshold.hotThrottlingThresholds, 0.1f); 423 assertArrayEquals(halT2.coldThrottlingThresholds, threshold.coldThrottlingThresholds, 0.1f); 424 } 425 426 @Test getTemperatureThresholds_withFilter_aidl()427 public void getTemperatureThresholds_withFilter_aidl() throws RemoteException { 428 TemperatureThreshold halT1 = new TemperatureThreshold(); 429 halT1.name = "test1"; 430 halT1.type = Temperature.TYPE_SKIN; 431 halT1.hotThrottlingThresholds = new float[]{1, 2, 3}; 432 halT1.coldThrottlingThresholds = new float[]{}; 433 434 TemperatureThreshold halT2 = new TemperatureThreshold(); 435 halT2.name = "test2"; 436 halT2.type = Temperature.TYPE_SOC; 437 halT2.hotThrottlingThresholds = new float[]{}; 438 halT2.coldThrottlingThresholds = new float[]{3, 2, 1}; 439 440 Mockito.when(mAidlHalMock.getTemperatureThresholdsWithType(Mockito.anyInt())).thenReturn( 441 new TemperatureThreshold[]{halT1, halT2} 442 ); 443 List<TemperatureThreshold> ret = mAidlWrapper.getTemperatureThresholds(true, 444 Temperature.TYPE_SKIN); 445 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatureThresholdsWithType( 446 Temperature.TYPE_SKIN); 447 448 assertEquals("Got unexpected temperature thresholds size", 1, ret.size()); 449 TemperatureThreshold threshold = ret.get(0); 450 assertEquals(halT1.name, threshold.name); 451 assertEquals(halT1.type, threshold.type); 452 assertArrayEquals(halT1.hotThrottlingThresholds, threshold.hotThrottlingThresholds, 0.1f); 453 assertArrayEquals(halT1.coldThrottlingThresholds, threshold.coldThrottlingThresholds, 0.1f); 454 } 455 456 @Test getTemperatureThresholds_nullResult_aidl()457 public void getTemperatureThresholds_nullResult_aidl() throws RemoteException { 458 Mockito.when(mAidlHalMock.getTemperatureThresholdsWithType(Mockito.anyInt())).thenReturn( 459 null); 460 List<TemperatureThreshold> ret = mAidlWrapper.getTemperatureThresholds(true, 461 Temperature.TYPE_SOC); 462 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatureThresholdsWithType( 463 Temperature.TYPE_SOC); 464 assertNotNull(ret); 465 assertEquals(0, ret.size()); 466 467 Mockito.when(mAidlHalMock.getTemperatureThresholds()).thenReturn(null); 468 ret = mAidlWrapper.getTemperatureThresholds(false, Temperature.TYPE_SOC); 469 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatureThresholds(); 470 assertNotNull(ret); 471 assertEquals(0, ret.size()); 472 } 473 474 @Test getTemperatureThresholds_illegalArgument_aidl()475 public void getTemperatureThresholds_illegalArgument_aidl() throws RemoteException { 476 Mockito.when(mAidlHalMock.getTemperatureThresholdsWithType(Mockito.anyInt())).thenThrow( 477 new IllegalArgumentException()); 478 List<TemperatureThreshold> ret = mAidlWrapper.getTemperatureThresholds(true, 479 Temperature.TYPE_SOC); 480 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatureThresholdsWithType( 481 Temperature.TYPE_SOC); 482 assertNotNull(ret); 483 assertEquals(0, ret.size()); 484 485 Mockito.when(mAidlHalMock.getTemperatureThresholds()).thenThrow( 486 new IllegalArgumentException()); 487 ret = mAidlWrapper.getTemperatureThresholds(false, 488 Temperature.TYPE_SOC); 489 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatureThresholds(); 490 assertNotNull(ret); 491 assertEquals(0, ret.size()); 492 } 493 494 @Test getTemperatureThresholds_illegalState_aidl()495 public void getTemperatureThresholds_illegalState_aidl() throws RemoteException { 496 Mockito.when(mAidlHalMock.getTemperatureThresholdsWithType(Mockito.anyInt())).thenThrow( 497 new IllegalStateException()); 498 List<TemperatureThreshold> ret = mAidlWrapper.getTemperatureThresholds(true, 499 Temperature.TYPE_SOC); 500 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatureThresholdsWithType( 501 Temperature.TYPE_SOC); 502 assertNotNull(ret); 503 assertEquals(0, ret.size()); 504 505 Mockito.when(mAidlHalMock.getTemperatureThresholds()).thenThrow( 506 new IllegalStateException()); 507 ret = mAidlWrapper.getTemperatureThresholds(false, 508 Temperature.TYPE_SOC); 509 Mockito.verify(mAidlHalMock, Mockito.times(1)).getTemperatureThresholds(); 510 assertNotNull(ret); 511 assertEquals(0, ret.size()); 512 } 513 } 514