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

Commit 73a96151 authored by Wei Wang's avatar Wei Wang Committed by Android (Google) Code Review
Browse files

Merge "thermalservice: plumb up Thermal HAL 2.0 and add dump"

parents b39e5d1f 52150001
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -40,11 +40,13 @@ cc_binary {
    include_dirs: ["frameworks/native"],

    shared_libs: [
        "libbase",
        "libthermalservice",
        "libbinder",
        "libutils",
        "libthermalcallback",
        "android.hardware.thermal@1.1",
        "android.hardware.thermal@2.0",
        "libhidlbase",
        "libhidltransport",
        "liblog",
+39 −3
Original line number Diff line number Diff line
@@ -15,11 +15,16 @@
 */

#include "ThermalService.h"
#include <android/os/IThermalService.h>
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <android/os/IThermalEventListener.h>
#include <android/os/IThermalService.h>
#include <android/os/Temperature.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/PermissionCache.h>
#include <log/log.h>
#include <private/android_filesystem_config.h>
#include <utils/Errors.h>
#include <utils/Mutex.h>
#include <utils/String16.h>
@@ -27,6 +32,35 @@
namespace android {
namespace os {

/**
 * Dump thermal service
 * @param fd file descriptor for dumping
 * @param args not used
 */
status_t ThermalService::dump(int fd, const Vector<String16>& /* args */) {
    status_t ret = OK;
    std::string result;
    const IPCThreadState* ipc = IPCThreadState::self();
    const int pid = ipc->getCallingPid();
    const int uid = ipc->getCallingUid();
    if ((uid != AID_SHELL) &&
        !PermissionCache::checkPermission(String16("android.permission.DUMP"), pid, uid)) {
        result = android::base::
                StringPrintf("Permission Denial: can't dump ThermalService from pid=%d, uid=%d\n",
                             pid, uid);
        ret = PERMISSION_DENIED;
    } else {
        Mutex::Autolock _l(mListenersLock);
        result = android::base::StringPrintf("ThermalEventListener registered: %d\n",
                                             (int)mListeners.size());
    }
    if (!android::base::WriteStringToFd(result, fd)) {
        SLOGE("Failed to dump fd: %d", fd);
        ret = FDS_NOT_ALLOWED;
    }
    return ret;
}

/**
 * Notify registered listeners of a thermal throttling start/stop event.
 * @param temperature the temperature at which the event was generated
@@ -62,8 +96,9 @@ binder::Status ThermalService::isThrottling(bool* _aidl_return) {
binder::Status ThermalService::registerThermalEventListener(
    const sp<IThermalEventListener>& listener) {
    {
        if (listener == NULL)
        if (listener == NULL) {
            return binder::Status::ok();
        }
        Mutex::Autolock _l(mListenersLock);
        // check whether this is a duplicate
        for (size_t i = 0; i < mListeners.size(); i++) {
@@ -87,8 +122,9 @@ binder::Status ThermalService::registerThermalEventListener(
 */
binder::Status ThermalService::unregisterThermalEventListener(
    const sp<IThermalEventListener>& listener) {
    if (listener == NULL)
    if (listener == NULL) {
        return binder::Status::ok();
    }
    Mutex::Autolock _l(mListenersLock);
    for (size_t i = 0; i < mListeners.size(); i++) {
        if (IInterface::asBinder(mListeners[i]) ==
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ public:
    void publish(const sp<ThermalService>& service);
    binder::Status notifyThrottling(
        const bool isThrottling, const Temperature& temperature);
    status_t dump(int fd, const Vector<String16>& args) override;

private:
    Mutex mListenersLock;
+2 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ cc_library_shared {
    name: "libthermalcallback",
    srcs: [
        "ThermalCallback.cpp",
        "ThermalChangedCallback.cpp",
    ],
    cflags: [
        "-Wall",
@@ -10,6 +11,7 @@ cc_library_shared {
    include_dirs: ["frameworks/native"],
    shared_libs: [
        "android.hardware.thermal@1.1",
        "android.hardware.thermal@2.0",
        "libhidlbase",
        "libhidltransport",
        "liblog",
+4 −4
Original line number Diff line number Diff line
#define LOG_TAG "android.hardware.thermal.thermalcallback@1.1-impl"
#include <log/log.h>

#include "ThermalCallback.h"
#include "services/thermalservice/ThermalService.h"
#include <math.h>
#include <android/os/Temperature.h>
#include <hardware/thermal.h>
#include <cmath>
#include "ThermalCallback.h"
#include "services/thermalservice/ThermalService.h"

namespace android {
namespace hardware {
@@ -57,7 +57,7 @@ Return<void> ThermalCallback::notifyThrottling(
        android::os::Temperature thermal_svc_temp(value, type);
        mThermalService->notifyThrottling(isThrottling, thermal_svc_temp);
    } else {
        ALOGE("IThermalService binder service not created, drop throttling event");
        SLOGE("IThermalService binder service not created, drop throttling event");
    }
    return Void();
}
Loading