| Yifan Hong | 7dcf7b0 | 2019-10-08 17:27:11 -0700 | [diff] [blame] | 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> | 
| Yifan Hong | 3aa3b3c | 2020-01-31 13:02:07 -0800 | [diff] [blame] | 20 | #include <android/hardware/health/2.1/IHealth.h> | 
| Yifan Hong | 7dcf7b0 | 2019-10-08 17:27:11 -0700 | [diff] [blame] | 21 | #include <health/utils.h> | 
 | 22 | #include <health2impl/Health.h> | 
| Yifan Hong | 7dcf7b0 | 2019-10-08 17:27:11 -0700 | [diff] [blame] | 23 |  | 
 | 24 | namespace android { | 
 | 25 | namespace hardware { | 
 | 26 | namespace health { | 
| Yifan Hong | 7dcf7b0 | 2019-10-08 17:27:11 -0700 | [diff] [blame] | 27 |  | 
| Yifan Hong | 3aa3b3c | 2020-01-31 13:02:07 -0800 | [diff] [blame] | 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 { | 
| Yifan Hong | 7dcf7b0 | 2019-10-08 17:27:11 -0700 | [diff] [blame] | 36 |         LOG(WARNING) << "Charger uses system defaults."; | 
 | 37 |         auto config = std::make_unique<healthd_config>(); | 
 | 38 |         InitHealthdConfig(config.get()); | 
| Yifan Hong | 3aa3b3c | 2020-01-31 13:02:07 -0800 | [diff] [blame] | 39 |         service = new V2_1::implementation::Health(std::move(config)); | 
| Yifan Hong | 7dcf7b0 | 2019-10-08 17:27:11 -0700 | [diff] [blame] | 40 |     } | 
| Yifan Hong | 3aa3b3c | 2020-01-31 13:02:07 -0800 | [diff] [blame] | 41 |     return service; | 
| Yifan Hong | 7dcf7b0 | 2019-10-08 17:27:11 -0700 | [diff] [blame] | 42 | } | 
 | 43 |  | 
 | 44 | }  // namespace health | 
 | 45 | }  // namespace hardware | 
 | 46 | }  // namespace android |