]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/platform-hardware-interfaces.git/blob - health/2.0/README.md
health: convert README to markdown format.
[android/platform-hardware-interfaces.git] / health / 2.0 / README.md
1 # Upgrading from Health 1.0 HAL
3 1. Remove `android.hardware.health@1.0*` from `PRODUCT_PACKAGES`
4    in `device/<manufacturer>/<device>/device.mk`
6 1. If the device does not have a vendor-specific `libhealthd` AND does not
7    implement storage-related APIs, just do the following:
9    ```mk
10    PRODUCT_PACKAGES += android.hardware.health@2.0-service
11    ```
13    Otherwise, continue to the next step.
15 1. Create directory
16    `device/<manufacturer>/<device>/health`
18 1. Create `device/<manufacturer>/<device>/health/Android.bp`
19    (or equivalent `device/<manufacturer>/<device>/health/Android.mk`)
21     ```bp
22     cc_binary {
23         name: "android.hardware.health@2.0-service.<device>",
24         init_rc: ["android.hardware.health@2.0-service.<device>.rc"],
25         proprietary: true,
26         relative_install_path: "hw",
27         srcs: [
28             "HealthService.cpp",
29         ],
31         cflags: [
32             "-Wall",
33             "-Werror",
34         ],
36         static_libs: [
37             "android.hardware.health@2.0-impl",
38             "android.hardware.health@1.0-convert",
39             "libhealthservice",
40             "libbatterymonitor",
41         ],
43         shared_libs: [
44             "libbase",
45             "libcutils",
46             "libhidlbase",
47             "libhidltransport",
48             "libutils",
49             "android.hardware.health@2.0",
50         ],
52         header_libs: ["libhealthd_headers"],
54         overrides: [
55             "healthd",
56         ],
57     }
58     ```
60     1. (recommended) To remove `healthd` from the build, keep "overrides" section.
61     1. To keep `healthd` in the build, remove "overrides" section.
63 1. Create `device/<manufacturer>/<device>/health/android.hardware.health@2.0-service.<device>.rc`
65     ```rc
66     service vendor.health-hal-2-0 /vendor/bin/hw/android.hardware.health@2.0-service.<device>
67         class hal
68         user system
69         group system
70         file /dev/kmsg w
71     ```
73 1. Create `device/<manufacturer>/<device>/health/HealthService.cpp`:
75     ```c++
76     #include <health2/service.h>
77     int main() { return health_service_main(); }
78     ```
80 1. `libhealthd` dependency:
82     1. If the device has a vendor-specific `libhealthd.<soc>`, add it to static_libs.
84     1. If the device does not have a vendor-specific `libhealthd`, add the following
85         lines to `HealthService.cpp`:
87         ```c++
88         #include <healthd/healthd.h>
89         void healthd_board_init(struct healthd_config*) {}
91         int healthd_board_battery_update(struct android::BatteryProperties*) {
92             // return 0 to log periodic polled battery status to kernel log
93             return 0;
94         }
95         ```
97 1. Storage related APIs:
99     1. If the device does not implement `IHealth.getDiskStats` and
100         `IHealth.getStorageInfo`, add `libstoragehealthdefault` to `static_libs`.
102     1. If the device implements one of these two APIs, add and implement the
103         following functions in `HealthService.cpp`:
105         ```c++
106         void get_storage_info(std::vector<struct StorageInfo>& info) {
107             // ...
108         }
109         void get_disk_stats(std::vector<struct DiskStats>& stats) {
110             // ...
111         }
112         ```
114 1. Update necessary SELinux permissions. For example,
116     ```
117     # device/<manufacturer>/<device>/sepolicy/vendor/file_contexts
118     /vendor/bin/hw/android\.hardware\.health@2\.0-service.<device> u:object_r:hal_health_default_exec:s0
120     # device/<manufacturer>/<device>/sepolicy/vendor/hal_health_default.te
121     # Add device specific permissions to hal_health_default domain, especially
122     # if a device-specific libhealthd is used and/or device-specific storage related
123     # APIs are implemented.
124     ```
126 1. Implementing health HAL in recovery. The health HAL is used for battery
127 status checks during OTA for non-A/B devices. If the health HAL is not
128 implemented in recovery, `is_battery_ok()` will always return `true`.
130     1. If the device does not have a vendor-specific `libhealthd`, nothing needs to
131     be done. A "backup" implementation is provided in
132     `android.hardware.health@2.0-impl-default`, which is always installed to recovery
133     image by default.
135     1. If the device does have a vendor-specific `libhealthd`, implement the following
136     module and include it in `PRODUCT_PACKAGES` (replace `<device>` with appropriate
137     strings):
139     ```bp
140     // Android.bp
141     cc_library_shared {
142         name: "android.hardware.health@2.0-impl-<device>",
143         recovery_available: true,
144         relative_install_path: "hw",
145         static_libs: [
146             "android.hardware.health@2.0-impl",
147             "libhealthd.<device>"
148             // Include the following or implement device-specific storage APIs
149             "libhealthstoragedefault",
150         ],
151         srcs: [
152             "HealthImpl.cpp",
153         ],
154         overrides: [
155             "android.hardware.health@2.0-impl-default",
156         ],
157     }
158     ```
160     ```c++
161     // HealthImpl.cpp
162     #include <health2/Health.h>
163     #include <healthd/healthd.h>
164     using android::hardware::health::V2_0::IHealth;
165     using android::hardware::health::V2_0::implementation::Health;
166     extern "C" IHealth* HIDL_FETCH_IHealth(const char* name) {
167         const static std::string providedInstance{"default"};
168         if (providedInstance != name) return nullptr;
169         return Health::initInstance(&gHealthdConfig).get();
170     }
171     ```
173     ```mk
174     # device.mk
175     PRODUCT_PACKAGES += android.hardware.health@2.0-impl-<device>
176     ```