blob: 3c353e6a78f1fdf05e9df6f27799bf40b92e2d4d [file] [log] [blame]
Yifan Hong954c3ff2018-01-16 17:48:22 -08001/*
2 * Copyright (C) 2018 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#define LOG_TAG "HealthHalUtils"
18
19#include <android-base/logging.h>
20#include <healthhalutils/HealthHalUtils.h>
21
22namespace android {
23namespace hardware {
24namespace health {
25namespace V2_0 {
26
27sp<IHealth> get_health_service() {
Yifan Honga76a2bf2021-10-18 15:22:31 -070028 // For the core and vendor variant, the "backup" instance points to healthd,
29 // which is removed.
30 // For the recovery variant, the "backup" instance has a different
31 // meaning. It points to android.hardware.health@2.0-impl-default.recovery
32 // which was assumed by OEMs to be always installed when a
33 // vendor-specific libhealthd is not necessary. Hence, its behavior
34 // is kept. See health/2.0/README.md.
35 // android.hardware.health@2.0-impl-default.recovery, and subsequently the
36 // special handling of recovery mode below, can be removed once health@2.1
37 // is the minimum required version (i.e. compatibility matrix level 5 is the
38 // minimum supported level). Health 2.1 requires OEMs to install the
39 // implementation to the recovery partition when it is necessary (i.e. on
40 // non-A/B devices, where IsBatteryOk() is needed in recovery).
41 for (auto&& instanceName :
42#ifdef __ANDROID_RECOVERY__
43 { "default", "backup" }
44#else
45 {"default"}
46#endif
47 ) {
Yifan Hong954c3ff2018-01-16 17:48:22 -080048 auto ret = IHealth::getService(instanceName);
49 if (ret != nullptr) {
50 return ret;
51 }
52 LOG(INFO) << "health: cannot get " << instanceName << " service";
53 }
54 return nullptr;
55}
56
57} // namespace V2_0
58} // namespace health
59} // namespace hardware
60} // namespace android