• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "healthd-android"
18 
19 #include <healthd/healthd.h>
20 #include "BatteryPropertiesRegistrar.h"
21 
22 #include <binder/IPCThreadState.h>
23 #include <binder/ProcessState.h>
24 #include <cutils/klog.h>
25 #include <sys/epoll.h>
26 
27 using namespace android;
28 
29 static int gBinderFd;
30 static sp<BatteryPropertiesRegistrar> gBatteryPropertiesRegistrar;
31 
healthd_mode_android_battery_update(struct android::BatteryProperties * props)32 void healthd_mode_android_battery_update(
33     struct android::BatteryProperties *props) {
34     if (gBatteryPropertiesRegistrar != NULL)
35         gBatteryPropertiesRegistrar->notifyListeners(*props);
36 
37     return;
38 }
39 
healthd_mode_android_preparetowait(void)40 int healthd_mode_android_preparetowait(void) {
41     IPCThreadState::self()->flushCommands();
42     return -1;
43 }
44 
healthd_mode_android_heartbeat(void)45 void healthd_mode_android_heartbeat(void) {
46 }
47 
binder_event(uint32_t)48 static void binder_event(uint32_t /*epevents*/) {
49     IPCThreadState::self()->handlePolledCommands();
50 }
51 
healthd_mode_android_init(struct healthd_config *)52 void healthd_mode_android_init(struct healthd_config* /*config*/) {
53     ProcessState::self()->setThreadPoolMaxThreadCount(0);
54     IPCThreadState::self()->disableBackgroundScheduling(true);
55     IPCThreadState::self()->setupPolling(&gBinderFd);
56 
57     if (gBinderFd >= 0) {
58         if (healthd_register_event(gBinderFd, binder_event))
59             KLOG_ERROR(LOG_TAG,
60                        "Register for binder events failed\n");
61     }
62 
63     gBatteryPropertiesRegistrar = new BatteryPropertiesRegistrar();
64     gBatteryPropertiesRegistrar->publish(gBatteryPropertiesRegistrar);
65 }
66