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

Commit 6e68da33 authored by Tri Vo's avatar Tri Vo Committed by Android (Google) Code Review
Browse files

Merge "Add Thermal HAL VTS"

parents 06afc8ec 59d05ebc
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ interface IThermal {
     *         always returns and never removes such temperatures.
     *
     */
    @callflow(next={"*"})
    @entry
    @exit
    getTemperatures()
        generates (ThermalStatus status, vec<Temperature> temperatures);

@@ -47,6 +50,9 @@ interface IThermal {
     *         the same regardless the number of calls to this method.
     *
     */
    @callflow(next={"*"})
    @entry
    @exit
    getCpuUsages() generates (ThermalStatus status, vec<CpuUsage> cpuUsages);

    /*
@@ -63,6 +69,9 @@ interface IThermal {
     *         the list such cooling devices.
     *
     */
    @callflow(next={"*"})
    @entry
    @exit
    getCoolingDevices()
        generates (ThermalStatus status, vec<CoolingDevice> devices);

+138 −143
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <errno.h>
#include <hardware/hardware.h>
#include <hardware/thermal.h>
#include <vector>

#include "Thermal.h"

@@ -29,8 +30,7 @@ namespace thermal {
namespace V1_0 {
namespace implementation {

Thermal::Thermal(thermal_module_t* module) : mModule(module) {
}
Thermal::Thermal(thermal_module_t* module) : mModule(module) {}

// Methods from ::android::hardware::thermal::V1_0::IThermal follow.
Return<void> Thermal::getTemperatures(getTemperatures_cb _hidl_cb) {
@@ -44,17 +44,14 @@ Return<void> Thermal::getTemperatures(getTemperatures_cb _hidl_cb) {
    return Void();
  }

    ssize_t list_size = mModule->getTemperatures(mModule, nullptr, 0);
    if (list_size >= 0) {
       temperature_t *list = new temperature_t[list_size];
       ssize_t size = mModule->getTemperatures(mModule, list, list_size);
  ssize_t size = mModule->getTemperatures(mModule, nullptr, 0);
  if (size >= 0) {
           if (list_size > size) {
               list_size = size;
           }

           temperatures.resize(list_size);
           for (ssize_t i = 0; i < list_size; ++i) {
    std::vector<temperature_t> list;
    list.resize(size);
    size = mModule->getTemperatures(mModule, list.data(), list.size());
    if (size >= 0) {
      temperatures.resize(list.size());
      for (size_t i = 0; i < list.size(); ++i) {
        switch (list[i].type) {
          case DEVICE_TEMPERATURE_UNKNOWN:
            temperatures[i].type = TemperatureType::UNKNOWN;
@@ -72,7 +69,8 @@ Return<void> Thermal::getTemperatures(getTemperatures_cb _hidl_cb) {
            temperatures[i].type = TemperatureType::SKIN;
            break;
          default:
                       ALOGE("Unknown temperature %s type", list[i].name);;
            ALOGE("Unknown temperature %s type", list[i].name);
            ;
        }
        temperatures[i].name = list[i].name;
        temperatures[i].currentValue = list[i].current_value;
@@ -80,14 +78,11 @@ Return<void> Thermal::getTemperatures(getTemperatures_cb _hidl_cb) {
        temperatures[i].shutdownThreshold = list[i].shutdown_threshold;
        temperatures[i].vrThrottlingThreshold = list[i].vr_throttling_threshold;
      }
       } else {
           status.code = ThermalStatusCode::FAILURE;
           status.debugMessage = strerror(-size);
    }
       delete[] list;
    } else {
  }
  if (size < 0) {
    status.code = ThermalStatusCode::FAILURE;
        status.debugMessage = strerror(-list_size);
    status.debugMessage = strerror(-size);
  }
  _hidl_cb(status, temperatures);
  return Void();
@@ -106,11 +101,13 @@ Return<void> Thermal::getCpuUsages(getCpuUsages_cb _hidl_cb) {

  ssize_t size = mModule->getCpuUsages(mModule, nullptr);
  if (size >= 0) {
        cpu_usage_t *list = new cpu_usage_t[size];
        size = mModule->getCpuUsages(mModule, list);
    std::vector<cpu_usage_t> list;
    list.resize(size);
    size = mModule->getCpuUsages(mModule, list.data());
    if (size >= 0) {
      list.resize(size);
      cpuUsages.resize(size);
            for (ssize_t i = 0; i < size; ++i) {
      for (size_t i = 0; i < list.size(); ++i) {
        cpuUsages[i].name = list[i].name;
        cpuUsages[i].active = list[i].active;
        cpuUsages[i].total = list[i].total;
@@ -120,8 +117,8 @@ Return<void> Thermal::getCpuUsages(getCpuUsages_cb _hidl_cb) {
      status.code = ThermalStatusCode::FAILURE;
      status.debugMessage = strerror(-size);
    }
        delete[] list;
    } else {
  }
  if (size < 0) {
    status.code = ThermalStatusCode::FAILURE;
    status.debugMessage = strerror(-size);
  }
@@ -140,16 +137,15 @@ Return<void> Thermal::getCoolingDevices(getCoolingDevices_cb _hidl_cb) {
    return Void();
  }

    ssize_t list_size = mModule->getCoolingDevices(mModule, nullptr, 0);
    if (list_size >= 0) {
        cooling_device_t *list = new cooling_device_t[list_size];
        ssize_t size = mModule->getCoolingDevices(mModule, list, list_size);
  ssize_t size = mModule->getCoolingDevices(mModule, nullptr, 0);
  if (size >= 0) {
            if (list_size > size) {
                list_size = size;
            }
            coolingDevices.resize(list_size);
            for (ssize_t i = 0; i < list_size; ++i) {
    std::vector<cooling_device_t> list;
    list.resize(size);
    size = mModule->getCoolingDevices(mModule, list.data(), list.size());
    if (size >= 0) {
      list.resize(size);
      coolingDevices.resize(list.size());
      for (size_t i = 0; i < list.size(); ++i) {
        switch (list[i].type) {
          case FAN_RPM:
            coolingDevices[i].type = CoolingType::FAN_RPM;
@@ -160,15 +156,11 @@ Return<void> Thermal::getCoolingDevices(getCoolingDevices_cb _hidl_cb) {
        coolingDevices[i].name = list[i].name;
        coolingDevices[i].currentValue = list[i].current_value;
      }

        } else {
            status.code = ThermalStatusCode::FAILURE;
            status.debugMessage = strerror(-size);
    }
        delete[] list;
    } else {
  }
  if (size < 0) {
    status.code = ThermalStatusCode::FAILURE;
        status.debugMessage = strerror(-list_size);
    status.debugMessage = strerror(-size);
  }
  _hidl_cb(status, coolingDevices);
  return Void();
@@ -177,7 +169,8 @@ Return<void> Thermal::getCoolingDevices(getCoolingDevices_cb _hidl_cb) {
IThermal* HIDL_FETCH_IThermal(const char* /* name */) {
  thermal_module_t* module;
  status_t err = hw_get_module(THERMAL_HARDWARE_MODULE_ID,
            const_cast<hw_module_t const**>(reinterpret_cast<hw_module_t**>(&module)));
                               const_cast<hw_module_t const**>(
                                   reinterpret_cast<hw_module_t**>(&module)));
  if (err || !module) {
    ALOGE("Couldn't load %s module (%s)", THERMAL_HARDWARE_MODULE_ID,
          strerror(-err));
@@ -185,9 +178,11 @@ IThermal* HIDL_FETCH_IThermal(const char* /* name */) {

  if (err == 0 && module->common.methods->open) {
    struct hw_device_t* device;
        err = module->common.methods->open(&module->common, THERMAL_HARDWARE_MODULE_ID, &device);
    err = module->common.methods->open(&module->common,
                                       THERMAL_HARDWARE_MODULE_ID, &device);
    if (err) {
            ALOGE("Couldn't open %s module (%s)", THERMAL_HARDWARE_MODULE_ID, strerror(-err));
      ALOGE("Couldn't open %s module (%s)", THERMAL_HARDWARE_MODULE_ID,
            strerror(-err));
    } else {
      return new Thermal(reinterpret_cast<thermal_module_t*>(device));
    }
+3 −3
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ enum TemperatureType : int32_t {
    SKIN = 3,
};

enum CoolingType : int32_t {
enum CoolingType : uint32_t {
    /** Fan cooling device speed in RPM. */
    FAN_RPM = 0,
};
@@ -118,9 +118,9 @@ struct CpuUsage {

enum ThermalStatusCode : uint32_t {
    /** No errors. */
    SUCCESS,
    SUCCESS = 0,
    /** Unknown failure occured. */
    FAILURE
    FAILURE = 1
};

/**
+84 −0
Original line number Diff line number Diff line
#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

LOCAL_PATH := $(call my-dir)

# build VTS driver for Thermal v1.0.
include $(CLEAR_VARS)

LOCAL_MODULE := libvts_driver_hidl_thermal@1.0

LOCAL_SRC_FILES := \
  Thermal.vts \
  types.vts \

LOCAL_C_INCLUDES := \
  android.hardware.thermal@1.0 \
  system/core/base/include \
  system/core/include \

LOCAL_SHARED_LIBRARIES += \
  android.hardware.thermal@1.0 \
  libbase \
  libutils \
  libcutils \
  liblog \
  libhidl \
  libhwbinder \
  libprotobuf-cpp-full \
  libvts_common \
  libvts_datatype \
  libvts_measurement \
  libvts_multidevice_proto \

LOCAL_STATIC_LIBRARIES := \

LOCAL_PROTOC_OPTIMIZE_TYPE := full

LOCAL_MULTILIB := both

include $(BUILD_SHARED_LIBRARY)

# build profiler for thermal.
include $(CLEAR_VARS)

LOCAL_MODULE := libvts_profiler_hidl_thermal@1.0

LOCAL_SRC_FILES := \
   Thermal.vts \
   types.vts \

LOCAL_C_INCLUDES += \
  test/vts/drivers/libprofiling \

LOCAL_VTS_MODE := PROFILER

LOCAL_SHARED_LIBRARIES := \
   android.hardware.thermal@1.0 \
   libbase \
   libcutils \
   liblog \
   libhidl \
   libhwbinder \
   libprotobuf-cpp-full \
   libvts_common \
   libvts_multidevice_proto \
   libvts_profiling \
   libutils \

LOCAL_PROTOC_OPTIMIZE_TYPE := full

include $(BUILD_SHARED_LIBRARY)
+82 −0
Original line number Diff line number Diff line
component_class: HAL_HIDL
component_type_version: 1.0
component_name: "IThermal"

package: "android.hardware.thermal"

import: "android.hardware.thermal@1.0::types"

interface: {
    api: {
        name: "getTemperatures"
        return_type_hidl: {
            type: TYPE_STRUCT
            predefined_type: "::android::hardware::thermal::V1_0::ThermalStatus"
        }
        return_type_hidl: {
            type: TYPE_VECTOR
            vector_value: {
                type: TYPE_STRUCT
                predefined_type: "::android::hardware::thermal::V1_0::Temperature"
            }
        }
        callflow: {
            next: "*"
        }
        callflow: {
            entry: true
        }
        callflow: {
            exit: true
        }
    }

    api: {
        name: "getCpuUsages"
        return_type_hidl: {
            type: TYPE_STRUCT
            predefined_type: "::android::hardware::thermal::V1_0::ThermalStatus"
        }
        return_type_hidl: {
            type: TYPE_VECTOR
            vector_value: {
                type: TYPE_STRUCT
                predefined_type: "::android::hardware::thermal::V1_0::CpuUsage"
            }
        }
        callflow: {
            next: "*"
        }
        callflow: {
            entry: true
        }
        callflow: {
            exit: true
        }
    }

    api: {
        name: "getCoolingDevices"
        return_type_hidl: {
            type: TYPE_STRUCT
            predefined_type: "::android::hardware::thermal::V1_0::ThermalStatus"
        }
        return_type_hidl: {
            type: TYPE_VECTOR
            vector_value: {
                type: TYPE_STRUCT
                predefined_type: "::android::hardware::thermal::V1_0::CoolingDevice"
            }
        }
        callflow: {
            next: "*"
        }
        callflow: {
            entry: true
        }
        callflow: {
            exit: true
        }
    }

}
Loading