건강 2.0 구현

모든 healthd 코드는 health@2.0-impl 및 libhealthservice 로 리팩터링된 다음 health@2.0 HAL을 구현하도록 수정되었습니다. 이 두 라이브러리는 health@2.0-service에 의해 정적으로 연결되어 이전에 healthd 가 수행한 작업을 수행할 수 있습니다(즉, healthd_mainloop 실행 및 폴링 수행). init에서 health@2.0-service는 인터페이스 IHealth 의 구현을 hwservicemanager 에 등록합니다. Android 8.x 공급업체 이미지 및 Android 9 프레임워크로 기기를 업그레이드하는 경우 공급업체 이미지에서 health@2.0 서비스를 제공하지 않을 수 있습니다. 이것은 사용 중단 일정 에 의해 시행됩니다.

이 문제를 해결하려면:

  1. healthdIHealthhwservicemanager 에 등록합니다(시스템 데몬임에도 불구하고). IHealth 는 인스턴스 이름이 "backup"인 시스템 매니페스트에 추가됩니다.
  2. Framework 및 storagedbinder 대신 healthd 를 통해 hwbinder 와 통신합니다.
  3. 프레임워크 및 storaged 에 대한 코드는 사용 가능한 경우 인스턴스를 "기본값"으로 가져온 다음 "백업"으로 가져오도록 변경됩니다.
    • C++ 클라이언트 코드는 libhealthhalutils 에 정의된 논리를 사용합니다.
    • Java 클라이언트 코드는 HealthServiceWrapper 에 정의된 로직을 사용합니다.
  4. IHealth/default가 널리 사용 가능하고 Android 8.1 공급업체 이미지가 더 이상 사용되지 않으면 IHealth/backup 및 healthd 가 사용되지 않을 수 있습니다. 자세한 내용은 health@1.0 지원 중단 을 참조하세요.

healthd에 대한 보드별 빌드 변수

BOARD_PERIODIC_CHORES_INTERVAL_*healthd 를 빌드하는 데 사용되는 보드별 변수입니다. 시스템/공급업체 빌드 분할의 일부로 시스템 모듈에 대해 보드별 값을 정의 할 수 없습니다 . health@2.0에서 공급업체는 healthd_mode_ops->init 에서 이 두 값을 재정의할 수 있습니다( health@2.0-service.<device> 에서 libhealthservice 종속성을 삭제하고 이 기능을 다시 구현하여).

정적 구현 라이브러리

다른 HAL 구현 라이브러리와 달리 구현 라이브러리 health@2.0-impl은 health@2.0-service, 충전기, 복구 및 기존 healthd 링크가 있는 정적 라이브러리입니다.

health@2.0.impl은 위에서 설명한 대로 IHealth 를 구현하며 libbatterymonitorlibhealthd. BOARD . 이러한 health@2.0-impl 사용자는 BatteryMonitor 또는 libhealthd 의 기능을 직접 사용해서는 안 됩니다. 대신 이러한 호출은 IHealth 인터페이스의 구현인 Health 클래스에 대한 호출로 대체되어야 합니다. 더 일반화하기 위해 healthd_common 코드도 health@2.0-impl에 포함되어 있습니다. 새로운 healthd_common 에는 health@2.0-service, Charger 및 healthd 사이의 나머지 공통 코드와 BatteryMonitor 대신 IHealth 메소드 호출이 포함됩니다.

Health 2.0 서비스 구현

기기에 대해 health@2.0 서비스를 구현할 때 기본 구현이 다음과 같은 경우:

  • 기기에 충분하다면 android.hardware.health@2.0-service 직접 사용하세요.
  • 장치에 충분하지 않은 경우 android.hardware.health@2.0-service.(device) 실행 파일을 만들고 다음을 포함합니다.

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

그 다음에:

  • 보드별 libhealthd:

    • 존재하며 링크합니다.
    • 존재하지 않습니다. healthd_board_inithealthd_board_battery_update 기능에 대한 빈 구현을 제공하십시오.
  • 보드별 BOARD_PERIODIC_CHORES_INTERVAL_* 변수인 경우:

    • 정의되고 장치별 HealthServiceCommon.cpp ( hardware/interfaces/health/2.0/utils/libhealthservice 에서 복사)를 생성하고 이를 healthd_mode_service_2_0_init 에서 사용자 지정합니다.
    • 정의되지 않았 libhealthservice 에 정적으로 연결됩니다.
  • 장치의 경우:

    • getStorageInfogetDiskStats API를 구현해야 하는 경우 get_storage_infoget_disk_stats 함수에서 구현을 제공합니다.
    • 해당 API를 구현하지 않아야 하며 libstoragehealthdefault 에 정적으로 연결합니다.
  • 필요한 SELinux 권한을 업데이트합니다.

  • 복구 이미지에 패스스루 구현을 설치하여 복구에서 HAL을 구현합니다. 예시:

    // Android.bp
    cc_library_shared {
        name: "android.hardware.health@2.0-impl-<device>",
        recovery_available: true,
        relative_install_path: "hw",
        static_libs: [
            "android.hardware.health@2.0-impl",
            "libhealthd.<device>"
            // Include the following or implement device-specific storage APIs
            "libhealthstoragedefault",
        ],
        srcs: [
            "HealthImpl.cpp",
        ],
        overrides: [
            "android.hardware.health@2.0-impl-default",
        ],
    }
    
    // HealthImpl.cpp
    #include <health2/Health.h>
    #include <healthd/healthd.h>
    using android::hardware::health::V2_0::IHealth;
    using android::hardware::health::V2_0::implementation::Health;
    extern "C" IHealth* HIDL_FETCH_IHealth(const char* name) {
        const static std::string providedInstance{"default"};
        if (providedInstance != name) return nullptr;
        return Health::initInstance(&gHealthdConfig).get();
    }
    
    # device.mk
    PRODUCT_PACKAGES += android.hardware.health@2.0-impl-<device>
    

자세한 내용은 hardware/interfaces/health/2.0/README.md 를 참조하십시오.

건강 클라이언트

상태 2.1 HAL에 대한 상태 클라이언트를 참조하십시오.

SELinux 변경 사항

새로운 health@2.0 HAL에는 다음 SELinux 변경 사항이 포함됩니다.

  • file_contexts 에 health@2.0-service를 추가합니다.
  • system_serverstoragedhal_health 를 사용하도록 허용합니다.
  • system_server ( BatteryService )가 batteryproperties_service ( IBatteryPropertiesRegistrar )를 등록할 수 있도록 합니다.
  • hal_healthhealthd 를 제공하도록 허용합니다.
  • system_server / storaged 가 바인더를 통해 healthd 를 호출하도록 허용하는 규칙을 제거합니다.
  • healthdbatteryproperties_service ( IBatteryPropertiesRegistrar )를 등록하도록 허용하는 규칙을 제거합니다.

자체 구현이 있는 장치의 경우 일부 공급업체 SELinux 변경이 필요할 수 있습니다. 예시:

# 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 it links to board-specific libhealthd or implements storage APIs.

커널 인터페이스

상태 2.1 HAL에 대한 커널 인터페이스를 참조하세요.

테스트

Android 9에는 health@2.0 HAL을 위해 특별히 작성된 새로운 VTS 테스트 가 포함되어 있습니다. 기기가 기기 매니페스트에서 health@2.0 HAL을 제공한다고 선언하는 경우 해당 VTS 테스트를 통과해야 합니다. 테스트는 기본 인스턴스(기기가 HAL을 올바르게 구현하는지 확인하기 위해)와 백업 인스턴스(제거되기 전에 healthd 가 계속 올바르게 작동하는지 확인하기 위해) 모두에 대해 작성됩니다.

배터리 정보 요구 사항

배터리 정보 요구 사항 을 참조하십시오.