2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
동적으로 사용 가능한 HAL
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Android 9에서는 Android 하드웨어 하위 시스템이 사용 중이 아니거나 필요하지 않은 경우 동적 종료를 지원합니다. 예를 들어 사용자가 Wi-Fi를 사용하고 있지 않은 경우 Wi-Fi 하위 시스템이 메모리, 전력 또는 기타 시스템 리소스를 사용하지 않습니다. 이전 버전의 Android에서는 HAL/드라이버가 Android 휴대전화가 부팅되는 동안 Android 기기에서 계속 열려 있었습니다.
동적 종료를 구현하려면 다음 섹션에 설명된 대로 데이터 흐름을 연결하고 동적 프로세스를 실행합니다.
HAL 정의 변경사항
동적 종료를 사용하려면 어떤 프로세스가 어떤 HAL 인터페이스를 제공하는지에 관한 정보가 필요하며(이 정보는 추후 다른 상황에서도 유용할 수 있음), 부팅 시 프로세스를 시작하지 않고 종료 시 다시 요청할 때까지 프로세스를 다시 시작하지 않아야 합니다.
# some init.rc script associated with the HAL
service vendor.some-service-name /vendor/bin/hw/some-binary-service
# init language extension, provides information of what service is served
# if multiple interfaces are served, they can be specified one on each line
interface android.hardware.light@2.0::ILight default
# restarted if hwservicemanager dies
# would also cause the hal to start early during boot if disabled wasn't set
class hal
# will not be restarted if it exits until it is requested to be restarted
oneshot
# will only be started when requested
disabled
# ... other properties
init 및 hwservicemanager 변경사항
동적 종료에서는 hwservicemanager
가 init
에 요청된 서비스를 시작하라고 알려야 합니다. Android 9에서 init
에는 ctl.interface_start
, ctl.interface_stop
, ctl.interface_restart
라는 추가 제어 메시지(예: ctl.start
)가 3개 포함되어 있습니다.
이러한 메시지는 init
에 특정 하드웨어 인터페이스를 표시하거나 숨기라고 신호를 보내는 데 사용할 수 있습니다. 서비스가 요청되었지만 등록되지 않은 경우 hwservicemanager
에서 서비스 시작을 요청합니다. 그러나 동적 HAL은 이러한 것을 사용하지 않아도 됩니다.
HAL 종료 확인
Android 9에서는 HAL 종료를 직접 확인해야 합니다. Android 10 이상에서는 자동 수명 주기를 사용하여 확인할 수도 있습니다.
동적 종료에는 HAL을 언제 시작하고 언제 종료할지 판단하는 여러 정책이 필요합니다. 어떤 이유든 HAL이 종료되면 HAL 정의에서 제공된 정보와 init
및 hwservicemanager
의 변경사항에서 제공된 인프라를 사용하여 HAL이 다시 필요해질 때 자동으로 다시 시작됩니다. 여기에는 다음과 같은 몇 가지 전략이 포함될 수 있습니다.
- HAL은 누군가가 가깝거나 유사한 API를 호출하는 경우 자체적으로 종료를 호출할 수 있습니다. 이 동작은 상응하는 HAL 인터페이스에서 지정해야 합니다.
- HAL은 작업이 완료되면 종료될 수 있습니다. HAL 파일에 설명되어 있습니다.
자동 수명 주기
Android 10은 커널과 hwservicemanager
에 더 많은 지원을 추가하여 HAL이 클라이언트가 없을 때마다 자동으로 종료될 수 있습니다. 이 기능을 사용하려면 다음 단계뿐 아니라 HAL 정의 변경의 모든 단계를 실행합니다.
- C++에서 서비스를 멤버 함수
registerAsService
가 아닌 LazyServiceRegistrar
로 등록합니다. 예를 들면 다음과 같습니다.
// only one instance of LazyServiceRegistrar per process
LazyServiceRegistrar registrar;
registrar.registerAsService(myHidlService /* , "default" */);
- HAL 클라이언트가 사용 중일 때만 최상위 수준 HAL(
hwservicemanager
로 등록된 인터페이스) 참조를 유지하는지 확인합니다. 계속 실행되는 hwbinder 스레드에서 이 참조를 삭제하는 경우 지연을 방지하려면 클라이언트는 참조를 삭제한 후 IPCThreadState::self()->flushCommands()
도 호출하여 연결된 참조 수 변경사항을 바인더 드라이버에 알리도록 해야 합니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[],[],null,["# Dynamically available HALs\n\nAndroid 9 supports the dynamic shutdown of Android hardware subsystems when they are not in use or not needed. For example, when a user is not using Wi-Fi, the Wi-Fi subsystems should not be taking up memory, power, or other system resources. In earlier versions of Android, HALs/drivers were kept open on Android devices for the entire duration an Android phone was booted.\n\nImplementing dynamic shutdown involves wiring up data flows and executing\ndynamic processes as detailed in the following sections.\n\nChanges to HAL definitions\n--------------------------\n\nDynamic shutdown requires information on which processes serve what HAL\ninterfaces (this information may also be useful later in other contexts) as\nwell as not starting processes on boot and not restarting them (until\nrequested again) when they exit. \n\n```objective-c\n# some init.rc script associated with the HAL\nservice vendor.some-service-name /vendor/bin/hw/some-binary-service\n # init language extension, provides information of what service is served\n # if multiple interfaces are served, they can be specified one on each line\n interface android.hardware.light@2.0::ILight default\n # restarted if hwservicemanager dies\n # would also cause the hal to start early during boot if disabled wasn't set\n class hal\n # will not be restarted if it exits until it is requested to be restarted\n oneshot\n # will only be started when requested\n disabled\n # ... other properties\n```\n\nChanges to init and hwservicemanager\n------------------------------------\n\nDynamic shutdown also requires the `hwservicemanager` to tell\n`init` to start requested services. In Android 9,\n`init` includes three additional control messages (e.g.\n`ctl.start`): `ctl.interface_start`,\n`ctl.interface_stop`, and `ctl.interface_restart`.\nThese messages can be used to signal `init` to bring up and down\nspecific hardware interfaces. When a service is requested and isn't\nregistered, `hwservicemanager` requests that the service be\nstarted. However, dynamic HALs don't require using any of these.\n\nDetermine HAL exit\n------------------\n\nIn Android 9, HAL exit has to be manually\ndetermined. For Android 10 and higher, it can also\nbe determined with\n[automatic lifecycles](#automatic-lifecycles).\n\nDynamic shutdown requires multiple policies for deciding when to start a\nHAL and when to shutdown a HAL. If a HAL decides to exit for any reason, it\nwill automatically be restarted when it is needed again using the information\nprovided in the HAL definition and the infrastructure provided by changes to\n`init` and `hwservicemanager`. This could involve a\ncouple of different strategies, including:\n\n- A HAL could choose to call exit on itself if someone calls a close or similar API on it. This behavior must be specified in the corresponding HAL interface.\n- HALs can shut down when their task is completed (documented in the HAL file).\n\nAutomatic lifecycles\n--------------------\n\nAndroid 10 adds more support to the kernel and\n`hwservicemanager`, which allows HALs to shut down automatically\nwhenever they have no clients. To use this feature, do all of the steps in\n[Changes to HAL definitions](#changes-HAL-definitions) as well\nas:\n\n- Register the service in C++ with `LazyServiceRegistrar` instead of the member function, `registerAsService`, for example: \n\n ```scilab\n // only one instance of LazyServiceRegistrar per process\n LazyServiceRegistrar registrar;\n registrar.registerAsService(myHidlService /* , \"default\" */);\n ```\n- Verify that the HAL client keeps a reference to the top-level HAL (the interface registered with `hwservicemanager`) only when it's in use. To avoid delays if this reference is dropped on a hwbinder thread that continues to execute, the client should also call `IPCThreadState::self()-\u003eflushCommands()` after dropping the reference to ensure that the binder driver is notified of the associated reference count changes."]]