blob: 8bbfb4e7fd12833b2f565822208459d6ea43b55d [file] [log] [blame]
Yifan Hong7dcf7b02019-10-08 17:27:11 -07001/*
2 * Copyright (C) 2019 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#include "charger_utils.h"
18
19#include <android-base/logging.h>
Yifan Hong3aa3b3c2020-01-31 13:02:07 -080020#include <android/hardware/health/2.1/IHealth.h>
Yifan Hong7dcf7b02019-10-08 17:27:11 -070021#include <health/utils.h>
22#include <health2impl/Health.h>
Yifan Hong7dcf7b02019-10-08 17:27:11 -070023
24namespace android {
25namespace hardware {
26namespace health {
Yifan Hong7dcf7b02019-10-08 17:27:11 -070027
Yifan Hong3aa3b3c2020-01-31 13:02:07 -080028sp<V2_1::IHealth> GetHealthServiceOrDefault() {
29 // No need to use get_health_service from libhealthhalutils that
30 // checks for "backup" instance provided by healthd, since
31 // V2_1::implementation::Health does the same thing.
32 sp<V2_1::IHealth> service = V2_1::IHealth::getService();
33 if (service != nullptr) {
34 LOG(INFO) << "Charger uses health HAL service.";
35 } else {
Yifan Hong7dcf7b02019-10-08 17:27:11 -070036 LOG(WARNING) << "Charger uses system defaults.";
37 auto config = std::make_unique<healthd_config>();
38 InitHealthdConfig(config.get());
Yifan Hong3aa3b3c2020-01-31 13:02:07 -080039 service = new V2_1::implementation::Health(std::move(config));
Yifan Hong7dcf7b02019-10-08 17:27:11 -070040 }
Yifan Hong3aa3b3c2020-01-31 13:02:07 -080041 return service;
Yifan Hong7dcf7b02019-10-08 17:27:11 -070042}
43
44} // namespace health
45} // namespace hardware
46} // namespace android