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

Commit b6070b9c authored by Tej Singh's avatar Tej Singh
Browse files

Migrate statsd to thermal hal v2

Part 1 of 2 in migrating statsd to thermal hal v2. Updates the
temperature puller to use thermal hal v2.

Bug: 119228310
Test: adb shell cmd stats pull-source 10021 on blueline. Received 8 cpu
temps, 2 gpu, 1 skin, 1 battery, 1 usb, and 1 npu. Did not receive any
bcl or power amplifier

Change-Id: I8804e282ea928c1815c2a29e72728edf9a053988
parent d44eb0f7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ cc_defaults {
        "android.hardware.power@1.0",
        "android.hardware.power@1.1",
        "android.hardware.power.stats@1.0",
        "android.hardware.thermal@1.0",
        "android.hardware.thermal@2.0",
        "libpackagelistparser",
        "libsysutils",
        "libcutils",
+2 −1
Original line number Diff line number Diff line
@@ -2786,13 +2786,14 @@ message BatteryLevel {
 *   frameworks/base/cmds/statsd/src/external/ResourceThermalManagerPuller.cpp
 */
message Temperature {
    // The type of temperature being reported. Eg. CPU, GPU, SKIN, BATTERY.
    // The type of temperature being reported. Eg. CPU, GPU, SKIN, BATTERY, BCL_.
    optional android.os.TemperatureTypeEnum sensor_location = 1;

    // The name of the temperature source. Eg. CPU0
    optional string sensor_name = 2;

    // Temperature in tenths of a degree C.
    // For BCL, it is decimillivolt, decimilliamps, and percentage * 10.
    optional int32 temperature_deci_celsius = 3;
}

+9 −8
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
#define DEBUG false  // STOPSHIP if true
#include "Log.h"

#include <android/hardware/thermal/1.0/IThermal.h>
#include <android/hardware/thermal/2.0/IThermal.h>
#include "external/ResourceThermalManagerPuller.h"
#include "external/StatsPuller.h"

@@ -31,10 +31,11 @@
using android::hardware::hidl_death_recipient;
using android::hardware::hidl_vec;
using android::hidl::base::V1_0::IBase;
using android::hardware::thermal::V1_0::IThermal;
using android::hardware::thermal::V1_0::Temperature;
using android::hardware::thermal::V1_0::ThermalStatus;
using android::hardware::thermal::V1_0::ThermalStatusCode;
using ::android::hardware::thermal::V2_0::IThermal;
using ::android::hardware::thermal::V2_0::Temperature;
using ::android::hardware::thermal::V2_0::TemperatureType;
using ::android::hardware::thermal::V1_0::ThermalStatus;
using ::android::hardware::thermal::V1_0::ThermalStatusCode;
using android::hardware::Return;
using android::hardware::Void;

@@ -49,7 +50,7 @@ namespace os {
namespace statsd {

bool getThermalHalLocked();
sp<android::hardware::thermal::V1_0::IThermal> gThermalHal = nullptr;
sp<android::hardware::thermal::V2_0::IThermal> gThermalHal = nullptr;
std::mutex gThermalHalMutex;

struct ThermalHalDeathRecipient : virtual public hidl_death_recipient {
@@ -107,7 +108,7 @@ bool ResourceThermalManagerPuller::PullInternal(vector<shared_ptr<LogEvent>>* da
    data->clear();
    bool resultSuccess = true;

    Return<void> ret = gThermalHal->getTemperatures(
    Return<void> ret = gThermalHal->getCurrentTemperatures(false, TemperatureType::SKIN,
            [&](ThermalStatus status, const hidl_vec<Temperature>& temps) {
        if (status.code != ThermalStatusCode::SUCCESS) {
            ALOGE("Failed to get temperatures from ThermalHAL. Status: %d", status.code);
@@ -121,7 +122,7 @@ bool ResourceThermalManagerPuller::PullInternal(vector<shared_ptr<LogEvent>>* da
                ptr->write((static_cast<int>(temps[i].type)));
                ptr->write(temps[i].name);
                // Convert the temperature to an int.
                int32_t temp = static_cast<int>(temps[i].currentValue * 10);
                int32_t temp = static_cast<int>(temps[i].value * 10);
                ptr->write(temp);
                ptr->init();
                data->push_back(ptr);
+11 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ enum BatteryStatusEnum {
}

// These constants are defined in hardware/interfaces/thermal/1.0/types.hal
// and in hardware/interfaces/thermal/2.0/types.hal
// They are primarily used by android/os/HardwarePropertiesManager.java.
// Any change to the types in the thermal hal should be made here as well.
enum TemperatureTypeEnum {
@@ -65,6 +66,16 @@ enum TemperatureTypeEnum {
    TEMPERATURE_TYPE_GPU = 1;
    TEMPERATURE_TYPE_BATTERY = 2;
    TEMPERATURE_TYPE_SKIN = 3;
    TEMPERATURE_TYPE_USB_PORT = 4;
    TEMPERATURE_TYPE_POWER_AMPLIFIER = 5;

    // Battery Charge Limit - virtual thermal sensors.
    TEMPERATURE_TYPE_BCL_VOLTAGE = 6;
    TEMPERATURE_TYPE_BCL_CURRENT = 7;
    TEMPERATURE_TYPE_BCL_PERCENTAGE = 8;

    // Neural Processing Unit.
    TEMPERATURE_TYPE_NPU = 9;
}

// Wakelock types, primarily used by android/os/PowerManager.java.