Yifan Hong | e438211 | 2019-10-02 19:09:37 -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 <memory> |
| 18 | #include <string_view> |
| 19 | |
| 20 | #include <health/utils.h> |
| 21 | #include <health2impl/Health.h> |
| 22 | |
| 23 | using ::android::sp; |
| 24 | using ::android::hardware::health::InitHealthdConfig; |
| 25 | using ::android::hardware::health::V2_1::IHealth; |
| 26 | using ::android::hardware::health::V2_1::implementation::Health; |
| 27 | |
| 28 | using namespace std::literals; |
| 29 | |
| 30 | // Passthrough implementation of the health service. Use default configuration. |
| 31 | // It does not invoke callbacks unless update() is called explicitly. No |
| 32 | // background thread is spawned to handle callbacks. |
| 33 | // |
| 34 | // The passthrough implementation is only allowed in recovery mode, charger, and |
| 35 | // opened by the hwbinder service. |
| 36 | // If Android is booted normally, the hwbinder service is used instead. |
| 37 | // |
| 38 | // This implementation only implements the "default" instance. It rejects |
| 39 | // other instance names. |
| 40 | // Note that the Android framework only reads values from the "default" |
| 41 | // health HAL 2.1 instance. |
| 42 | extern "C" IHealth* HIDL_FETCH_IHealth(const char* instance) { |
| 43 | if (instance != "default"sv) { |
| 44 | return nullptr; |
| 45 | } |
| 46 | auto config = std::make_unique<healthd_config>(); |
| 47 | InitHealthdConfig(config.get()); |
| 48 | |
| 49 | // This implementation uses default config. If you want to customize it |
| 50 | // (e.g. with healthd_board_init), do it here. |
| 51 | |
| 52 | return new Health(std::move(config)); |
| 53 | } |