summaryrefslogtreecommitdiffstats
path: root/health/2.0/README
blob: 2281f989699e2ed0225ab2ca1bc4c27c91d4c541 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
Upgrading from health@1.0 HAL

0. Remove android.hardware.health@1.0* from PRODUCT_PACKAGES
   in device/<manufacturer>/<device>/device.mk

1. If the device does not have a vendor-specific libhealthd AND does not
   implement storage-related APIs, just do the following:

    1.1 (recommended) To remove healthd from the build,
        PRODUCT_PACKAGES += android.hardware.health@2.0-service.override
        DEVICE_FRAMEWORK_MANIFEST_FILE += \
            system/libhidl/vintfdata/manifest_healthd_exclude.xml
    1.2 To keep healthd in the build,
        PRODUCT_PACKAGES += android.hardware.health@2.0-service

   Otherwise, continue to Step 2.

2. Create directory
   device/<manufacturer>/<device>/health

3. Create device/<manufacturer>/<device>/health/Android.bp
   (or equivalent device/<manufacturer>/<device>/health/Android.mk)

cc_binary {
    name: "android.hardware.health@2.0-service.<device>",
    init_rc: ["android.hardware.health@2.0-service.<device>.rc"],
    proprietary: true,
    relative_install_path: "hw",
    srcs: [
        "HealthService.cpp",
    ],

    cflags: [
        "-Wall",
        "-Werror",
    ],

    static_libs: [
        "android.hardware.health@2.0-impl",
        "android.hardware.health@1.0-convert",
        "libhealthservice",
        "libbatterymonitor",
    ],

    shared_libs: [
        "libbase",
        "libcutils",
        "libhidlbase",
        "libhidltransport",
        "libutils",
        "android.hardware.health@2.0",
    ],

    header_libs: ["libhealthd_headers"],

    // Uncomment the following to remove healthd from the build.
    // overrides: [
    //     "healthd",
    // ],
}

    3.1 (recommended) To remove healthd from the build, keep "overrides"
          section, and include the following in device.mk:
            DEVICE_FRAMEWORK_MANIFEST_FILE += \
                system/libhidl/vintfdata/manifest_healthd_exclude.xml
    3.2 To keep healthd in the build, remove "overrides" section.

4. Create device/<manufacturer>/<device>/health/android.hardware.health@2.0-service.<device>.rc

service vendor.health-hal-2-0 /vendor/bin/hw/android.hardware.health@2.0-service.<device>
    class hal
    user system
    group system

5. Create device/<manufacturer>/<device>/health/HealthService.cpp:

#include <health2/service.h>
int main() { return health_service_main(); }

6. libhealthd dependency:

6.1 If the device has a vendor-specific libhealthd.<soc>, add it to static_libs.

6.2 If the device does not have a vendor-specific libhealthd, add the following
    lines to HealthService.cpp:

#include <healthd/healthd.h>
void healthd_board_init(struct healthd_config*) {}

int healthd_board_battery_update(struct android::BatteryProperties*) {
    // return 0 to log periodic polled battery status to kernel log
    return 0;
}

7. Storage related APIs:

7.1 If the device does not implement IHealth.getDiskStats and
    IHealth.getStorageInfo, add libstoragehealthdefault to static_libs.

7.2 If the device implements one of these two APIs, add and implement the
    following functions in HealthService.cpp:

void get_storage_info(std::vector<struct StorageInfo>& info) {
    // ...
}
void get_disk_stats(std::vector<struct DiskStats>& stats) {
    // ...
}

8. Update necessary SELinux permissions. For example,

# device/<manufacturer>/<device>/sepolicy/vendor/file_contexts
/vendor/bin/hw/android\.hardware\.health@2\.0-service.<device> u:object_r:hal_health_default_exec:s0

# device/<manufacturer>/<device>/sepolicy/vendor/hal_health_default.te
# Add device specific permissions to hal_health_default domain, especially
# if Step 6.1 or Step 7.2 is done.