Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa4333b8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Improve the comments of Thermal HAL 2.0 API"

parents 86fde623 84cf5c9f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+12 −10
Original line number Diff line number Diff line
@@ -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<TemperatureThreshold> 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.
+18 −2
Original line number Diff line number Diff line
@@ -155,7 +155,15 @@ Return<void> Thermal::registerThermalChangedCallback(const sp<IThermalChangedCal
                                                     bool filterType, TemperatureType type,
                                                     registerThermalChangedCallback_cb _hidl_cb) {
    ThermalStatus status;
    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;
    }
    std::lock_guard<std::mutex> _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<void> Thermal::registerThermalChangedCallback(const sp<IThermalChangedCal
Return<void> Thermal::unregisterThermalChangedCallback(
    const sp<IThermalChangedCallback>& callback, unregisterThermalChangedCallback_cb _hidl_cb) {
    ThermalStatus status;
    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<std::mutex> _lock(thermal_callback_mutex_);
    callbacks_.erase(
+13 −3
Original line number Diff line number Diff line
@@ -133,7 +133,12 @@ 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); });
            [](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<ThermalCallback> 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.