diff options
| author | Yifan Hong <elsk@google.com> | 2017-10-04 10:59:51 -0700 |
|---|---|---|
| committer | Yifan Hong <elsk@google.com> | 2017-10-19 14:52:00 -0700 |
| commit | 287c41fffeb144476092766466b86db9cfaf5e8c (patch) | |
| tree | 2166da863036d78f81b964db71498808ec4aff66 /healthd | |
| parent | 12df1b9508ecc27accad7b46bb7cd773e0ba73ab (diff) | |
| download | core-287c41fffeb144476092766466b86db9cfaf5e8c.tar.gz core-287c41fffeb144476092766466b86db9cfaf5e8c.tar.bz2 core-287c41fffeb144476092766466b86db9cfaf5e8c.zip | |
Remove unused files in healthd.
Test: mma
Change-Id: I19c13aa3f1fdecd3f7072dccfe9dbd580f09e22a
Diffstat (limited to 'healthd')
| -rw-r--r-- | healthd/BatteryPropertiesRegistrar.cpp | 118 | ||||
| -rw-r--r-- | healthd/BatteryPropertiesRegistrar.h | 50 | ||||
| -rw-r--r-- | healthd/healthd.cpp | 123 | ||||
| -rw-r--r-- | healthd/healthd_mode_android.cpp | 65 | ||||
| -rw-r--r-- | healthd/include/healthd/healthd.h | 5 |
5 files changed, 5 insertions, 356 deletions
diff --git a/healthd/BatteryPropertiesRegistrar.cpp b/healthd/BatteryPropertiesRegistrar.cpp deleted file mode 100644 index e51a06d5e..000000000 --- a/healthd/BatteryPropertiesRegistrar.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2013 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 "BatteryPropertiesRegistrar.h" -#include <batteryservice/BatteryService.h> -#include <batteryservice/IBatteryPropertiesListener.h> -#include <batteryservice/IBatteryPropertiesRegistrar.h> -#include <binder/IPCThreadState.h> -#include <binder/IServiceManager.h> -#include <binder/PermissionCache.h> -#include <private/android_filesystem_config.h> -#include <utils/Errors.h> -#include <utils/Mutex.h> -#include <utils/String16.h> - -#include <healthd/healthd.h> - -namespace android { - -void BatteryPropertiesRegistrar::publish( - const sp<BatteryPropertiesRegistrar>& service) { - defaultServiceManager()->addService(String16("batteryproperties"), service); -} - -void BatteryPropertiesRegistrar::notifyListeners(const struct BatteryProperties& props) { - Vector<sp<IBatteryPropertiesListener> > listenersCopy; - - // Binder currently may service an incoming oneway transaction whenever an - // outbound oneway call is made (if there is already a pending incoming - // oneway call waiting). This is considered a bug and may change in the - // future. For now, avoid recursive mutex lock while making outbound - // calls by making a local copy of the current list of listeners. - { - Mutex::Autolock _l(mRegistrationLock); - listenersCopy = mListeners; - } - for (size_t i = 0; i < listenersCopy.size(); i++) { - listenersCopy[i]->batteryPropertiesChanged(props); - } -} - -void BatteryPropertiesRegistrar::registerListener(const sp<IBatteryPropertiesListener>& listener) { - { - if (listener == NULL) - return; - Mutex::Autolock _l(mRegistrationLock); - // check whether this is a duplicate - for (size_t i = 0; i < mListeners.size(); i++) { - if (IInterface::asBinder(mListeners[i]) == IInterface::asBinder(listener)) { - return; - } - } - - mListeners.add(listener); - IInterface::asBinder(listener)->linkToDeath(this); - } - healthd_battery_update(); -} - -void BatteryPropertiesRegistrar::unregisterListener(const sp<IBatteryPropertiesListener>& listener) { - if (listener == NULL) - return; - Mutex::Autolock _l(mRegistrationLock); - 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; - } - } -} - -status_t BatteryPropertiesRegistrar::getProperty(int id, struct BatteryProperty *val) { - return healthd_get_property(id, val); -} - -void BatteryPropertiesRegistrar::scheduleUpdate() { - healthd_battery_update(); -} - -status_t BatteryPropertiesRegistrar::dump(int fd, const Vector<String16>& /*args*/) { - IPCThreadState* self = IPCThreadState::self(); - const int pid = self->getCallingPid(); - const int uid = self->getCallingUid(); - if ((uid != AID_SHELL) && - !PermissionCache::checkPermission( - String16("android.permission.DUMP"), pid, uid)) - return PERMISSION_DENIED; - - healthd_dump_battery_state(fd); - return OK; -} - -void BatteryPropertiesRegistrar::binderDied(const wp<IBinder>& who) { - Mutex::Autolock _l(mRegistrationLock); - - for (size_t i = 0; i < mListeners.size(); i++) { - if (IInterface::asBinder(mListeners[i]) == who) { - mListeners.removeAt(i); - break; - } - } -} - -} // namespace android diff --git a/healthd/BatteryPropertiesRegistrar.h b/healthd/BatteryPropertiesRegistrar.h deleted file mode 100644 index 14e914514..000000000 --- a/healthd/BatteryPropertiesRegistrar.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2013 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 HEALTHD_BATTERYPROPERTIES_REGISTRAR_H -#define HEALTHD_BATTERYPROPERTIES_REGISTRAR_H - -#include <binder/IBinder.h> -#include <utils/Mutex.h> -#include <utils/String16.h> -#include <utils/Vector.h> -#include <batteryservice/BatteryService.h> -#include <batteryservice/IBatteryPropertiesListener.h> -#include <batteryservice/IBatteryPropertiesRegistrar.h> - -namespace android { - -class BatteryPropertiesRegistrar : public BnBatteryPropertiesRegistrar, - public IBinder::DeathRecipient { -public: - void publish(const sp<BatteryPropertiesRegistrar>& service); - void notifyListeners(const struct BatteryProperties& props); - void scheduleUpdate(); - -private: - Mutex mRegistrationLock; - Vector<sp<IBatteryPropertiesListener> > mListeners; - - void registerListener(const sp<IBatteryPropertiesListener>& listener); - void unregisterListener(const sp<IBatteryPropertiesListener>& listener); - status_t getProperty(int id, struct BatteryProperty *val); - status_t dump(int fd, const Vector<String16>& args); - void binderDied(const wp<IBinder>& who); -}; - -}; // namespace android - -#endif // HEALTHD_BATTERYPROPERTIES_REGISTRAR_H diff --git a/healthd/healthd.cpp b/healthd/healthd.cpp deleted file mode 100644 index ed1971a97..000000000 --- a/healthd/healthd.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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. - */ - -#define LOG_TAG "healthd" -#define KLOG_LEVEL 6 - -#include <healthd/healthd.h> - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <cutils/klog.h> - -#include <android/hardware/health/1.0/IHealth.h> -#include <android/hardware/health/1.0/types.h> -#include <hal_conversion.h> - -using namespace android; - -using IHealth = ::android::hardware::health::V1_0::IHealth; -using Result = ::android::hardware::health::V1_0::Result; -using HealthConfig = ::android::hardware::health::V1_0::HealthConfig; -using HealthInfo = ::android::hardware::health::V1_0::HealthInfo; - -using ::android::hardware::health::V1_0::hal_conversion::convertToHealthConfig; -using ::android::hardware::health::V1_0::hal_conversion::convertFromHealthConfig; -using ::android::hardware::health::V1_0::hal_conversion::convertToHealthInfo; -using ::android::hardware::health::V1_0::hal_conversion::convertFromHealthInfo; - -// device specific hal interface; -static sp<IHealth> gHealth; - -// main healthd loop -extern int healthd_main(void); - -// Android mode -extern void healthd_mode_android_init(struct healthd_config *config); -extern int healthd_mode_android_preparetowait(void); -extern void healthd_mode_android_heartbeat(void); -extern void healthd_mode_android_battery_update( - struct android::BatteryProperties *props); - -static struct healthd_mode_ops android_ops = { - .init = healthd_mode_android_init, - .preparetowait = healthd_mode_android_preparetowait, - .heartbeat = healthd_mode_android_heartbeat, - .battery_update = healthd_mode_android_battery_update, -}; - -// default energy counter property redirect to talk to device -// HAL -static int healthd_board_get_energy_counter(int64_t *energy) { - - if (gHealth == nullptr) { - return NAME_NOT_FOUND; - } - - Result result = Result::NOT_SUPPORTED; - gHealth->energyCounter([=, &result] (Result ret, int64_t energyOut) { - result = ret; - *energy = energyOut; - }); - - return result == Result::SUCCESS ? OK : NAME_NOT_FOUND; -} - -void healthd_board_init(struct healthd_config *config) { - - // Initialize the board HAL - Equivalent of healthd_board_init(config) - // in charger/recovery mode. - - gHealth = IHealth::getService(); - if (gHealth == nullptr) { - KLOG_WARNING(LOG_TAG, "unable to get HAL interface, using defaults\n"); - return; - } - - HealthConfig halConfig; - convertToHealthConfig(config, halConfig); - gHealth->init(halConfig, [=] (const auto &halConfigOut) { - convertFromHealthConfig(halConfigOut, config); - // always redirect energy counter queries - config->energyCounter = healthd_board_get_energy_counter; - }); -} - -int healthd_board_battery_update(struct android::BatteryProperties *props) { - int logthis = 0; - - if (gHealth == nullptr) { - return logthis; - } - - HealthInfo info; - convertToHealthInfo(props, info); - gHealth->update(info, - [=, &logthis] (int32_t ret, const auto &infoOut) { - logthis = ret; - convertFromHealthInfo(infoOut, props); - }); - - return logthis; -} - -int main(int /*argc*/, char ** /*argv*/) { - - healthd_mode_ops = &android_ops; - - return healthd_main(); -} diff --git a/healthd/healthd_mode_android.cpp b/healthd/healthd_mode_android.cpp deleted file mode 100644 index c6123137a..000000000 --- a/healthd/healthd_mode_android.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2013 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. - */ - -#define LOG_TAG "healthd-android" - -#include <healthd/healthd.h> -#include "BatteryPropertiesRegistrar.h" - -#include <binder/IPCThreadState.h> -#include <binder/ProcessState.h> -#include <cutils/klog.h> -#include <sys/epoll.h> - -using namespace android; - -static int gBinderFd; -static sp<BatteryPropertiesRegistrar> gBatteryPropertiesRegistrar; - -void healthd_mode_android_battery_update( - struct android::BatteryProperties *props) { - if (gBatteryPropertiesRegistrar != NULL) - gBatteryPropertiesRegistrar->notifyListeners(*props); - - return; -} - -int healthd_mode_android_preparetowait(void) { - IPCThreadState::self()->flushCommands(); - return -1; -} - -void healthd_mode_android_heartbeat(void) { -} - -static void binder_event(uint32_t /*epevents*/) { - IPCThreadState::self()->handlePolledCommands(); -} - -void healthd_mode_android_init(struct healthd_config* /*config*/) { - ProcessState::self()->setThreadPoolMaxThreadCount(0); - IPCThreadState::self()->disableBackgroundScheduling(true); - IPCThreadState::self()->setupPolling(&gBinderFd); - - if (gBinderFd >= 0) { - if (healthd_register_event(gBinderFd, binder_event)) - KLOG_ERROR(LOG_TAG, - "Register for binder events failed\n"); - } - - gBatteryPropertiesRegistrar = new BatteryPropertiesRegistrar(); - gBatteryPropertiesRegistrar->publish(gBatteryPropertiesRegistrar); -} diff --git a/healthd/include/healthd/healthd.h b/healthd/include/healthd/healthd.h index 17efbd62a..97c7a8ce4 100644 --- a/healthd/include/healthd/healthd.h +++ b/healthd/include/healthd/healthd.h @@ -82,8 +82,13 @@ enum EventWakeup { int healthd_register_event(int fd, void (*handler)(uint32_t), EventWakeup wakeup = EVENT_NO_WAKEUP_FD); void healthd_battery_update(); + +// deprecated. +// TODO(b/62229583): This function should be removed since it is only used by +// BatteryPropertiesRegistrar. android::status_t healthd_get_property(int id, struct android::BatteryProperty *val); + void healthd_dump_battery_state(int fd); struct healthd_mode_ops { |
