diff --git a/current.txt b/current.txt index a128669e17..be71351ac5 100644 --- a/current.txt +++ b/current.txt @@ -534,7 +534,7 @@ b53ac9d61c24efb16a2d63a861cef20680f6d57adb244a03b9778c675550628b android.hardwar ae5faa38538a9f50eb71eb7f9b998271124d2c64b761cb11c4d820c7732b4ddc android.hardware.sensors@2.0::ISensorsCallback 3a98242a57d0820dacaca0f7db52bec433eae1f21c498763c6f1ece611c3967b android.hardware.sensors@2.0::types ce4b98211959449361146d4b1e5554dc841ceb4d4577154d7b2fb6d1eb504f76 android.hardware.soundtrigger@2.2::ISoundTriggerHw -5cc81d517c5f3fef12e719b0f5683c7c99e3e8895fcb80e6f6653b454f463320 android.hardware.thermal@2.0::IThermal +bd88b48639cae30982021024e22371076c76faa8466e38ca598529452b618eae android.hardware.thermal@2.0::IThermal cc4d2ef36da776c475ad054f0f3416d8a8865def9d9e2129f10074b28e36d203 android.hardware.thermal@2.0::IThermalChangedCallback b47f90302595874dfddb19bd05a054727bf18b3a930bc810ea14957b859ae8bf android.hardware.thermal@2.0::types 61bc302e7c974c59b25898c585c6e9685e8a81021b1bed3eedf5224198f2785a android.hardware.usb@1.2::IUsb diff --git a/thermal/2.0/IThermal.hal b/thermal/2.0/IThermal.hal index f890694d2c..3ea4590991 100644 --- a/thermal/2.0/IThermal.hal +++ b/thermal/2.0/IThermal.hal @@ -56,22 +56,24 @@ interface IThermal extends @1.0::IThermal { * they go offline, if these devices exist on boot. The method * always returns and never removes such temperatures. The thresholds * are returned as static values and must not change across calls. The actual - * throttling state is determined in driver and HAL and must not be simply - * compared with these thresholds. To get accurate throttling status, use - * getCurrentTemperatures or registerThermalChangedCallback and listen. + * throttling state is determined in device thermal mitigation policy/agorithm + * which might not be simple thresholds so these values Thermal HAL provided + * may not be accurate to detemin the throttling status. To get accurate + * throttling status, use getCurrentTemperatures or registerThermalChangedCallback + * and listen to the callback. */ getTemperatureThresholds(bool filterType, TemperatureType type) generates (ThermalStatus status, vec temperatureThresholds); /** * Register an IThermalChangedCallback, used by the Thermal HAL - * to send thermal events when thermal mitigation status changed. + * to receive thermal events when thermal mitigation status changed. * Multiple registrations with different IThermalChangedCallback must be allowed. * Multiple registrations with same IThermalChangedCallback is not allowed, client * should unregister the given IThermalChangedCallback first. * - * @param callback the IThermalChangedCallback to use for sending - * thermal events (cannot be nullptr). + * @param callback the IThermalChangedCallback to use for receiving + * thermal events (nullptr callback will lead to failure with status code FAILURE). * @param filterType if filter for given sensor type. * @param type the type to be filtered. * @@ -84,11 +86,11 @@ interface IThermal extends @1.0::IThermal { generates (ThermalStatus status); /** - * Register an IThermalChangedCallback, used by the Thermal HAL - * to send thermal events when thermal mitigation status changed. + * Unregister an IThermalChangedCallback, used by the Thermal HAL + * to receive thermal events when thermal mitigation status changed. * - * @param callback the IThermalChangedCallback to use for sending - * thermal events, or nullptr to set no callback. + * @param callback the IThermalChangedCallback used for receiving + * thermal events (nullptr callback will lead to failure with status code FAILURE). * * @return status Status of the operation. If status code is FAILURE, * the status.debugMessage must be populated with a human-readable error message. diff --git a/thermal/2.0/default/Thermal.cpp b/thermal/2.0/default/Thermal.cpp index 442af61fa5..0ef4b63324 100644 --- a/thermal/2.0/default/Thermal.cpp +++ b/thermal/2.0/default/Thermal.cpp @@ -155,7 +155,15 @@ Return Thermal::registerThermalChangedCallback(const sp _lock(thermal_callback_mutex_); if (std::any_of(callbacks_.begin(), callbacks_.end(), [&](const CallbackSetting& c) { return interfacesEqual(c.callback, callback); @@ -175,7 +183,15 @@ Return Thermal::registerThermalChangedCallback(const sp Thermal::unregisterThermalChangedCallback( const sp& callback, unregisterThermalChangedCallback_cb _hidl_cb) { ThermalStatus status; - status.code = ThermalStatusCode::SUCCESS; + if (callback == nullptr) { + status.code = ThermalStatusCode::FAILURE; + status.debugMessage = "Invalid nullptr callback"; + LOG(ERROR) << status.debugMessage; + _hidl_cb(status); + return Void(); + } else { + status.code = ThermalStatusCode::SUCCESS; + } bool removed = false; std::lock_guard _lock(thermal_callback_mutex_); callbacks_.erase( diff --git a/thermal/2.0/vts/functional/VtsHalThermalV2_0TargetTest.cpp b/thermal/2.0/vts/functional/VtsHalThermalV2_0TargetTest.cpp index 3893014e20..cc2f3df612 100644 --- a/thermal/2.0/vts/functional/VtsHalThermalV2_0TargetTest.cpp +++ b/thermal/2.0/vts/functional/VtsHalThermalV2_0TargetTest.cpp @@ -132,8 +132,13 @@ TEST_F(ThermalHidlTest, NotifyThrottlingTest) { TEST_F(ThermalHidlTest, RegisterThermalChangedCallbackTest) { // Expect to fail with same callback auto ret = mThermal->registerThermalChangedCallback( - mThermalCallback, false, TemperatureType::SKIN, - [](ThermalStatus status) { EXPECT_NE(ThermalStatusCode::SUCCESS, status.code); }); + mThermalCallback, false, TemperatureType::SKIN, + [](ThermalStatus status) { EXPECT_EQ(ThermalStatusCode::FAILURE, status.code); }); + ASSERT_TRUE(ret.isOk()); + // Expect to fail with null callback + ret = mThermal->registerThermalChangedCallback( + nullptr, false, TemperatureType::SKIN, + [](ThermalStatus status) { EXPECT_EQ(ThermalStatusCode::FAILURE, status.code); }); ASSERT_TRUE(ret.isOk()); sp localThermalCallback = new (std::nothrow) ThermalCallback(); // Expect to succeed with different callback @@ -141,11 +146,16 @@ TEST_F(ThermalHidlTest, RegisterThermalChangedCallbackTest) { localThermalCallback, false, TemperatureType::SKIN, [](ThermalStatus status) { EXPECT_EQ(ThermalStatusCode::SUCCESS, status.code); }); ASSERT_TRUE(ret.isOk()); - // Remove the local callback. + // Remove the local callback ret = mThermal->unregisterThermalChangedCallback( localThermalCallback, [](ThermalStatus status) { EXPECT_EQ(ThermalStatusCode::SUCCESS, status.code); }); ASSERT_TRUE(ret.isOk()); + // Expect to fail with null callback + ret = mThermal->unregisterThermalChangedCallback(nullptr, [](ThermalStatus status) { + EXPECT_EQ(ThermalStatusCode::FAILURE, status.code); + }); + ASSERT_TRUE(ret.isOk()); } // Test Thermal->unregisterThermalChangedCallback.