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

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

Merge "Remove native thermal service"

parents f593018a b124b8cf
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
# Copyright (C) 2012 The Android Open Source Project
# Copyright (C) 2018 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.
@@ -34,19 +34,23 @@
# made today requires touching the same file, just copy the old
# touch step and add it to the end of the list.
#
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
# *****************************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST ABOVE THE BANNER
# *****************************************************************

# For example:
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)

# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
$(call add-clean-step, find $(PRODUCT_OUT) -type f -name "libdvr.so" -print0 | xargs -0 rm -f)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libdvr_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libdvr_intermediates)
$(call add-clean-step, find $(PRODUCT_OUT) -type f -name "libgui*" -print0 | xargs -0 rm -f)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libgui_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libgui_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/bin/thermalserviced)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/etc/init/thermalservice.rc)
# ******************************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST ABOVE THIS BANNER
# ******************************************************************

libs/gui/CleanSpec.mk

deleted100644 → 0
+0 −52
Original line number Diff line number Diff line
# Copyright (C) 2012 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.
#

# If you don't need to do a full clean build but would like to touch
# a file or delete some intermediate files, add a clean step to the end
# of the list.  These steps will only be run once, if they haven't been
# run before.
#
# E.g.:
#     $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
#     $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
#
# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
# files that are missing or have been moved.
#
# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
# Use $(OUT_DIR) to refer to the "out" directory.
#
# If you need to re-do something that's already mentioned, just copy
# the command and add it to the bottom of the list.  E.g., if a change
# that you made last week required touching a file and a change you
# made today requires touching the same file, just copy the old
# touch step and add it to the end of the list.
#
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************

# For example:
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)

# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
$(call add-clean-step, find $(PRODUCT_OUT) -type f -name "libgui*" -print0 | xargs -0 rm -f)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libgui_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libgui_intermediates)
+0 −63
Original line number Diff line number Diff line
subdirs = [
    "libthermalcallback"
]

cc_library {
    name: "libthermalservice",

    srcs: [
        "aidl/android/os/IThermalEventListener.aidl",
        "aidl/android/os/IThermalService.aidl",
        "aidl/android/os/Temperature.cpp",
    ],
    aidl: {
      include_dirs: ["frameworks/native/services/thermalservice/aidl"],
      export_aidl_headers: true,
    },
    export_include_dirs: ["aidl"],

    shared_libs: [
        "libbinder",
        "libutils",
    ],

    cflags: [
        "-Wall",
        "-Werror",
        "-Wunused",
        "-Wunreachable-code",
    ],
}

cc_binary {
    name: "thermalserviced",

    srcs: [
        "ThermalService.cpp",
        "thermalserviced.cpp",
    ],

    include_dirs: ["frameworks/native"],

    shared_libs: [
        "libbase",
        "libthermalservice",
        "libbinder",
        "libutils",
        "libthermalcallback",
        "android.hardware.thermal@1.1",
        "android.hardware.thermal@2.0",
        "libhidlbase",
        "libhidltransport",
        "liblog",
    ],

    cflags: [
        "-Wall",
        "-Werror",
        "-Wunused",
        "-Wunreachable-code",
    ],

    init_rc: ["thermalservice.rc"],
}
+0 −162
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

#include "ThermalService.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>

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
 */
binder::Status ThermalService::notifyThrottling(
    const bool isThrottling, const Temperature& temperature) {
    Mutex::Autolock _l(mListenersLock);

    mThrottled = isThrottling;
    mThrottleTemperature = temperature;

    for (size_t i = 0; i < mListeners.size(); i++) {
      mListeners[i]->notifyThrottling(isThrottling, temperature);
    }
    return binder::Status::ok();
}

/**
 * Query whether the system is currently thermal throttling.
 * @return true if currently thermal throttling, else false
 */
binder::Status ThermalService::isThrottling(bool* _aidl_return) {
    Mutex::Autolock _l(mListenersLock);
    *_aidl_return = mThrottled;
    return binder::Status::ok();
}

/**
 * Register a new thermal event listener.
 * @param listener the client's IThermalEventListener instance to which
 *                 notifications are to be sent
 */
binder::Status ThermalService::registerThermalEventListener(
    const sp<IThermalEventListener>& listener) {
    {
        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++) {
            if (IInterface::asBinder(mListeners[i]) ==
                IInterface::asBinder(listener)) {
                return binder::Status::ok();
            }
        }

        mListeners.add(listener);
        IInterface::asBinder(listener)->linkToDeath(this);
    }

    return binder::Status::ok();
}

/**
 * Unregister a previously-registered thermal event listener.
 * @param listener the client's IThermalEventListener instance to which
 *                 notifications are to no longer be sent
 */
binder::Status ThermalService::unregisterThermalEventListener(
    const sp<IThermalEventListener>& listener) {
    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]) ==
            IInterface::asBinder(listener)) {
            IInterface::asBinder(mListeners[i])->unlinkToDeath(this);
            mListeners.removeAt(i);
            break;
        }
    }

    return binder::Status::ok();
}

void ThermalService::binderDied(const wp<IBinder>& who) {
    Mutex::Autolock _l(mListenersLock);

    for (size_t i = 0; i < mListeners.size(); i++) {
        if (IInterface::asBinder(mListeners[i]) == who) {
            mListeners.removeAt(i);
            break;
        }
    }
}

/**
 * Publish the supplied ThermalService to servicemanager.
 */
void ThermalService::publish(
    const sp<ThermalService>& service) {
    defaultServiceManager()->addService(String16("thermalservice"),
                                        service);
}

}  // namespace os
}  // namespace android
+0 −56
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

#ifndef ANDROID_THERMALSERVICE_THERMALSERVICE_H
#define ANDROID_THERMALSERVICE_THERMALSERVICE_H

#include <android/os/BnThermalService.h>
#include <android/os/IThermalEventListener.h>
#include <android/os/Temperature.h>
#include <utils/Mutex.h>
#include <utils/String16.h>
#include <utils/Vector.h>

namespace android {
namespace os {

class ThermalService : public BnThermalService,
                       public IBinder::DeathRecipient {
public:
  ThermalService() : mThrottled(false) {};
    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;
    Vector<sp<IThermalEventListener> > mListeners;
    bool mThrottled;
    Temperature mThrottleTemperature;

    binder::Status registerThermalEventListener(
        const sp<IThermalEventListener>& listener);
    binder::Status unregisterThermalEventListener(
        const sp<IThermalEventListener>& listener);
    binder::Status isThrottling(bool* _aidl_return);
    void binderDied(const wp<IBinder>& who);
};

};  // namespace os
};  // namespace android

#endif // ANDROID_THERMALSERVICE_THERMALSERVICE_H
Loading