• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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>
20 #include <android/hardware/health/2.1/IHealth.h>
21 #include <health/utils.h>
22 #include <health2impl/Health.h>
23 
24 namespace android {
25 namespace hardware {
26 namespace health {
27 
GetHealthServiceOrDefault()28 sp<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 {
36         LOG(WARNING) << "Charger uses system defaults.";
37         auto config = std::make_unique<healthd_config>();
38         InitHealthdConfig(config.get());
39         service = new V2_1::implementation::Health(std::move(config));
40     }
41     return service;
42 }
43 
44 }  // namespace health
45 }  // namespace hardware
46 }  // namespace android
47