Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 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 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 17 | #define LOG_TAG "HealthLoop" |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 18 | #define KLOG_LEVEL 6 |
| 19 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 20 | #include <health/HealthLoop.h> |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 21 | |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 22 | #include <errno.h> |
Bart Van Assche | 7087858 | 2024-08-04 07:14:29 -0700 | [diff] [blame] | 23 | #include <sys/epoll.h> // epoll_create1(), epoll_ctl(), epoll_wait() |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 24 | #include <sys/timerfd.h> |
Bart Van Assche | 7087858 | 2024-08-04 07:14:29 -0700 | [diff] [blame] | 25 | #include <unistd.h> // read() |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 26 | |
| 27 | #include <android-base/logging.h> |
| 28 | #include <batteryservice/BatteryService.h> |
Bart Van Assche | 7087858 | 2024-08-04 07:14:29 -0700 | [diff] [blame] | 29 | #include <cutils/klog.h> // KLOG_*() |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 30 | #include <cutils/uevent.h> |
| 31 | #include <healthd/healthd.h> |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 32 | |
Bart Van Assche | 5c604b9 | 2024-07-29 14:22:31 -0700 | [diff] [blame^] | 33 | #include <BpfSyscallWrappers.h> |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 34 | #include <health/utils.h> |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 35 | |
Bart Van Assche | 5c604b9 | 2024-07-29 14:22:31 -0700 | [diff] [blame^] | 36 | using android::base::ErrnoError; |
| 37 | using android::base::Result; |
| 38 | using android::base::unique_fd; |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 39 | using namespace android; |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 40 | using namespace std::chrono_literals; |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 41 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 42 | namespace android { |
| 43 | namespace hardware { |
| 44 | namespace health { |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 45 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 46 | HealthLoop::HealthLoop() { |
| 47 | InitHealthdConfig(&healthd_config_); |
| 48 | awake_poll_interval_ = -1; |
| 49 | wakealarm_wake_interval_ = healthd_config_.periodic_chores_interval_fast; |
| 50 | } |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 51 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 52 | HealthLoop::~HealthLoop() { |
| 53 | LOG(FATAL) << "HealthLoop cannot be destroyed"; |
| 54 | } |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 55 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 56 | int HealthLoop::RegisterEvent(int fd, BoundFunction func, EventWakeup wakeup) { |
| 57 | CHECK(!reject_event_register_); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 58 | |
Bart Van Assche | 6fe3618 | 2024-08-05 15:43:27 -0700 | [diff] [blame] | 59 | auto* event_handler = event_handlers_ |
| 60 | .emplace_back(std::make_unique<EventHandler>( |
| 61 | EventHandler{this, fd, std::move(func)})) |
| 62 | .get(); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 63 | |
Bart Van Assche | 0cfcfac | 2024-08-05 15:51:46 -0700 | [diff] [blame] | 64 | struct epoll_event ev = { |
| 65 | .events = EPOLLIN | EPOLLERR, |
| 66 | .data.ptr = reinterpret_cast<void*>(event_handler), |
| 67 | }; |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 68 | |
| 69 | if (wakeup == EVENT_WAKEUP_FD) ev.events |= EPOLLWAKEUP; |
| 70 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 71 | if (epoll_ctl(epollfd_, EPOLL_CTL_ADD, fd, &ev) == -1) { |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 72 | KLOG_ERROR(LOG_TAG, "epoll_ctl failed; errno=%d\n", errno); |
| 73 | return -1; |
| 74 | } |
| 75 | |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 76 | return 0; |
| 77 | } |
| 78 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 79 | void HealthLoop::WakeAlarmSetInterval(int interval) { |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 80 | struct itimerspec itval; |
| 81 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 82 | if (wakealarm_fd_ == -1) return; |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 83 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 84 | wakealarm_wake_interval_ = interval; |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 85 | |
| 86 | if (interval == -1) interval = 0; |
| 87 | |
| 88 | itval.it_interval.tv_sec = interval; |
| 89 | itval.it_interval.tv_nsec = 0; |
| 90 | itval.it_value.tv_sec = interval; |
| 91 | itval.it_value.tv_nsec = 0; |
| 92 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 93 | if (timerfd_settime(wakealarm_fd_, 0, &itval, NULL) == -1) |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 94 | KLOG_ERROR(LOG_TAG, "wakealarm_set_interval: timerfd_settime failed\n"); |
| 95 | } |
| 96 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 97 | void HealthLoop::AdjustWakealarmPeriods(bool charger_online) { |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 98 | // Fast wake interval when on charger (watch for overheat); |
| 99 | // slow wake interval when on battery (watch for drained battery). |
| 100 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 101 | int new_wake_interval = charger_online ? healthd_config_.periodic_chores_interval_fast |
| 102 | : healthd_config_.periodic_chores_interval_slow; |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 103 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 104 | if (new_wake_interval != wakealarm_wake_interval_) WakeAlarmSetInterval(new_wake_interval); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 105 | |
| 106 | // During awake periods poll at fast rate. If wake alarm is set at fast |
| 107 | // rate then just use the alarm; if wake alarm is set at slow rate then |
| 108 | // poll at fast rate while awake and let alarm wake up at slow rate when |
| 109 | // asleep. |
| 110 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 111 | if (healthd_config_.periodic_chores_interval_fast == -1) |
| 112 | awake_poll_interval_ = -1; |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 113 | else |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 114 | awake_poll_interval_ = new_wake_interval == healthd_config_.periodic_chores_interval_fast |
| 115 | ? -1 |
| 116 | : healthd_config_.periodic_chores_interval_fast * 1000; |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 119 | void HealthLoop::PeriodicChores() { |
| 120 | ScheduleBatteryUpdate(); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 123 | #define UEVENT_MSG_LEN 2048 |
Bart Van Assche | 0cfcfac | 2024-08-05 15:51:46 -0700 | [diff] [blame] | 124 | void HealthLoop::UeventEvent(uint32_t epevents) { |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 125 | // No need to lock because uevent_fd_ is guaranteed to be initialized. |
| 126 | |
Bart Van Assche | 0cfcfac | 2024-08-05 15:51:46 -0700 | [diff] [blame] | 127 | if (epevents & EPOLLERR) { |
| 128 | // The netlink receive buffer overflowed. |
| 129 | ScheduleBatteryUpdate(); |
| 130 | return; |
| 131 | } |
| 132 | |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 133 | char msg[UEVENT_MSG_LEN + 2]; |
| 134 | char* cp; |
| 135 | int n; |
| 136 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 137 | n = uevent_kernel_multicast_recv(uevent_fd_, msg, UEVENT_MSG_LEN); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 138 | if (n <= 0) return; |
| 139 | if (n >= UEVENT_MSG_LEN) /* overflow -- discard */ |
| 140 | return; |
| 141 | |
| 142 | msg[n] = '\0'; |
| 143 | msg[n + 1] = '\0'; |
| 144 | cp = msg; |
| 145 | |
| 146 | while (*cp) { |
Bart Van Assche | ac9f9cb | 2021-10-19 11:55:53 -0700 | [diff] [blame] | 147 | if (!strcmp(cp, "SUBSYSTEM=power_supply")) { |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 148 | ScheduleBatteryUpdate(); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 149 | break; |
| 150 | } |
| 151 | |
| 152 | /* advance to after the next \0 */ |
| 153 | while (*cp++) |
| 154 | ; |
| 155 | } |
| 156 | } |
| 157 | |
Bart Van Assche | 5c604b9 | 2024-07-29 14:22:31 -0700 | [diff] [blame^] | 158 | // Attach a BPF filter to the @uevent_fd file descriptor. This fails in recovery mode because BPF is |
| 159 | // not supported in recovery mode. This fails for kernel versions 5.4 and before because the BPF |
| 160 | // program is rejected by the BPF verifier of older kernels. |
| 161 | Result<void> HealthLoop::AttachFilter(int uevent_fd) { |
| 162 | static const char prg[] = |
| 163 | "/sys/fs/bpf/vendor/prog_filterPowerSupplyEvents_skfilter_power_supply"; |
| 164 | int filter_fd(bpf::retrieveProgram(prg)); |
| 165 | if (filter_fd < 0) { |
| 166 | return ErrnoError() << "failed to load BPF program " << prg; |
| 167 | } |
| 168 | if (setsockopt(uevent_fd, SOL_SOCKET, SO_ATTACH_BPF, &filter_fd, sizeof(filter_fd)) < 0) { |
| 169 | close(filter_fd); |
| 170 | return ErrnoError() << "failed to attach BPF program"; |
| 171 | } |
| 172 | close(filter_fd); |
| 173 | return {}; |
| 174 | } |
| 175 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 176 | void HealthLoop::UeventInit(void) { |
Bart Van Assche | 5c604b9 | 2024-07-29 14:22:31 -0700 | [diff] [blame^] | 177 | uevent_fd_.reset(uevent_create_socket(64 * 1024, true)); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 178 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 179 | if (uevent_fd_ < 0) { |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 180 | KLOG_ERROR(LOG_TAG, "uevent_init: uevent_open_socket failed\n"); |
| 181 | return; |
| 182 | } |
| 183 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 184 | fcntl(uevent_fd_, F_SETFL, O_NONBLOCK); |
Bart Van Assche | 5c604b9 | 2024-07-29 14:22:31 -0700 | [diff] [blame^] | 185 | |
| 186 | Result<void> attach_result = AttachFilter(uevent_fd_); |
| 187 | if (!attach_result.ok()) { |
| 188 | std::string error_msg = attach_result.error().message(); |
| 189 | error_msg += |
| 190 | ". This is expected in recovery mode and also for kernel versions before 5.10."; |
| 191 | KLOG_WARNING(LOG_TAG, "%s", error_msg.c_str()); |
| 192 | } else { |
| 193 | KLOG_INFO(LOG_TAG, "Successfully attached the BPF filter to the uevent socket"); |
| 194 | } |
| 195 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 196 | if (RegisterEvent(uevent_fd_, &HealthLoop::UeventEvent, EVENT_WAKEUP_FD)) |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 197 | KLOG_ERROR(LOG_TAG, "register for uevent events failed\n"); |
Bart Van Assche | 5c604b9 | 2024-07-29 14:22:31 -0700 | [diff] [blame^] | 198 | |
| 199 | if (uevent_bind(uevent_fd_.get()) < 0) { |
| 200 | uevent_fd_.reset(); |
| 201 | KLOG_ERROR(LOG_TAG, "uevent_init: binding socket failed\n"); |
| 202 | return; |
| 203 | } |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 206 | void HealthLoop::WakeAlarmEvent(uint32_t /*epevents*/) { |
| 207 | // No need to lock because wakealarm_fd_ is guaranteed to be initialized. |
| 208 | |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 209 | unsigned long long wakeups; |
| 210 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 211 | if (read(wakealarm_fd_, &wakeups, sizeof(wakeups)) == -1) { |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 212 | KLOG_ERROR(LOG_TAG, "wakealarm_event: read wakealarm fd failed\n"); |
| 213 | return; |
| 214 | } |
| 215 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 216 | PeriodicChores(); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 219 | void HealthLoop::WakeAlarmInit(void) { |
| 220 | wakealarm_fd_.reset(timerfd_create(CLOCK_BOOTTIME_ALARM, TFD_NONBLOCK)); |
| 221 | if (wakealarm_fd_ == -1) { |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 222 | KLOG_ERROR(LOG_TAG, "wakealarm_init: timerfd_create failed\n"); |
| 223 | return; |
| 224 | } |
| 225 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 226 | if (RegisterEvent(wakealarm_fd_, &HealthLoop::WakeAlarmEvent, EVENT_WAKEUP_FD)) |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 227 | KLOG_ERROR(LOG_TAG, "Registration of wakealarm event failed\n"); |
| 228 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 229 | WakeAlarmSetInterval(healthd_config_.periodic_chores_interval_fast); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 230 | } |
| 231 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 232 | void HealthLoop::MainLoop(void) { |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 233 | int nevents = 0; |
| 234 | while (1) { |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 235 | reject_event_register_ = true; |
| 236 | size_t eventct = event_handlers_.size(); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 237 | struct epoll_event events[eventct]; |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 238 | int timeout = awake_poll_interval_; |
| 239 | |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 240 | int mode_timeout; |
| 241 | |
| 242 | /* Don't wait for first timer timeout to run periodic chores */ |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 243 | if (!nevents) PeriodicChores(); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 244 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 245 | Heartbeat(); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 246 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 247 | mode_timeout = PrepareToWait(); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 248 | if (timeout < 0 || (mode_timeout > 0 && mode_timeout < timeout)) timeout = mode_timeout; |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 249 | nevents = epoll_wait(epollfd_, events, eventct, timeout); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 250 | if (nevents == -1) { |
| 251 | if (errno == EINTR) continue; |
| 252 | KLOG_ERROR(LOG_TAG, "healthd_mainloop: epoll_wait failed\n"); |
| 253 | break; |
| 254 | } |
| 255 | |
| 256 | for (int n = 0; n < nevents; ++n) { |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 257 | if (events[n].data.ptr) { |
| 258 | auto* event_handler = reinterpret_cast<EventHandler*>(events[n].data.ptr); |
| 259 | event_handler->func(event_handler->object, events[n].events); |
| 260 | } |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
| 264 | return; |
| 265 | } |
| 266 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 267 | int HealthLoop::InitInternal() { |
| 268 | epollfd_.reset(epoll_create1(EPOLL_CLOEXEC)); |
| 269 | if (epollfd_ == -1) { |
Nick Kralevich | 8c038f2 | 2018-12-15 11:36:47 -0800 | [diff] [blame] | 270 | KLOG_ERROR(LOG_TAG, "epoll_create1 failed; errno=%d\n", errno); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 271 | return -1; |
| 272 | } |
| 273 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 274 | // Call subclass's init for any additional init steps. |
| 275 | // Note that healthd_config_ is initialized before wakealarm_fd_; see |
| 276 | // AdjustUeventWakealarmPeriods(). |
| 277 | Init(&healthd_config_); |
| 278 | |
| 279 | WakeAlarmInit(); |
| 280 | UeventInit(); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 285 | int HealthLoop::StartLoop() { |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 286 | int ret; |
| 287 | |
| 288 | klog_set_level(KLOG_LEVEL); |
| 289 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 290 | ret = InitInternal(); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 291 | if (ret) { |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 292 | KLOG_ERROR(LOG_TAG, "Initialization failed, exiting\n"); |
| 293 | return 2; |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 294 | } |
| 295 | |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 296 | MainLoop(); |
| 297 | KLOG_ERROR(LOG_TAG, "Main loop terminated, exiting\n"); |
Hridya Valsaraju | d3e3d72 | 2017-12-11 17:31:00 -0800 | [diff] [blame] | 298 | return 3; |
| 299 | } |
Yifan Hong | 50c9e25 | 2019-10-03 16:26:13 -0700 | [diff] [blame] | 300 | |
| 301 | } // namespace health |
| 302 | } // namespace hardware |
| 303 | } // namespace android |