2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
USB HAL 구현
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Android 8.0 버전에서는 더 나은 구성과 코드 안정성을 위해 USB 명령어 처리가 init
스크립트에서 네이티브 USB 데몬으로 이전되었습니다. 가젯 함수 구성과 관련해서는 기기별 가젯 연산을 실행하는 데 init
스크립트(속성 트리거)가 사용됩니다.
이전 버전에서는 이러한 기기별 구성이 기기별 init
스크립트를 통해(속성 트리거를 사용하여) 구현되었습니다. 하드웨어 추상화 계층(HAL) 설계로 이전하면 결과적으로 이러한 문제를 해결하는 좀 더 깔끔한 구현이 가능합니다.
- 커널 sysfs 노드에 쓰기와 같은 연산이 실패할 수 있지만 속성 트리거를 설정하는 프레임워크 코드로 다시 전파되지는 않습니다. 따라서 프레임워크는 연산이 자동으로 실패했더라도 연산이 성공했다고 잘못 가정합니다.
init
스크립트에는 실행 가능한 연산 횟수가 제한되어 있습니다.
Android 12 버전에는 HAL 버전 번호와 USB 속도를 모두 반환하는 네트워크 제어 모델(NCM) 및 API 호출에 관한 USB 가젯 HAL 지원이 추가되었습니다. USB HAL을 통해 사용 가능한 API 호출에 관한 자세한 내용은 android.hardware.usb
패키지 요약을 참고하세요.
HAL 및 트레블
기기별 init
스크립트는 HAL 레이어에서 기기별 USB 작업을 실행하기 위한 대체 요소로 활용되었습니다. ADB를 통한 USB는 시스템 문제 디버깅을 위한 기본 인터페이스입니다. USB 구성을 실행하기 위한 네이티브 데몬이 있으면 프레임워크 코드의 종속 항목이 제거되므로 프레임워크가 비정상 종료될 때에도 USB가 실행되고 있어야 합니다.
Android 8.0에 도입된 트레블 모델에서도 마찬가지로 모든 HAL이 시스템 서비스와 분리되어 있으며 자체 네이티브 데몬에서 실행되어야 합니다. 이렇게 하면 HAL 레이어가 USB 데몬으로도 기능하게 되므로 독점적 USB 데몬 보유에 관한 요구사항이 사라집니다.
기본 HAL 구현은 모든 Android 8.0 이전 기기를 처리합니다. 따라서 Android 8.0 이전 기기와 관련된 기기별 작업이 발생하지 않습니다. Android 8.0은 HAL 인터페이스를 사용하여 USB 포트 상태를 쿼리하고 데이터 역할 및 전력 역할 전환을 처리합니다.
구현
새로운 USB HAL 인터페이스는 Android 8.0에서 실행되는 모든 기기에 구현되어야 합니다.
기본 구현은 Android 8.0 이전 기기를 처리해야 합니다. 기기가 dual_role_usb
클래스를 사용하여 타입 C 포트 상태를 보고하면 기본 구현으로 충분합니다. 타입 C 노드의 소유권을 시스템으로 이전하려면 기기별 USB 스크립트에서 사소한 변경이 필요할 수 있습니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Implement USB HAL\n\nThe Android 8.0 release moves handling of USB commands out of `init`\nscripts and into a native USB daemon for better configuration and code\nreliability. For the Gadget function configuration, `init` scripts\n(property triggers) are used to perform device-specific gadget operations.\n\nIn previous releases, these device-specific configurations were achieved through\ndevice-specific `init` scripts (using property triggers). Moving to a\nHardware Abstraction Layer (HAL) design results in a much cleaner implementation\nthat solves these problems:\n\n1. Operations such as writes to the kernel sysfs nodes could fail but not be propagated back to the frameworks code that sets the property trigger. As a result, frameworks incorrectly assumes the operations have succeeded even though they have silently failed.\n2. `init` scripts have a limited number of operations that could be executed.\n\nThe Android 12 release adds USB Gadget HAL support for Network Control\nModels (NCM) and API calls that return both the HAL version number and USB speed. For more\ninformation on the API calls available through the USB HAL, see\n[the `android.hardware.usb` package summary](https://developer.android.com/reference/android/hardware/usb/package-summary).\n\nHAL and Treble\n--------------\n\n\nThe device-specific `init` scripts were used as a substitution for\nHAL layers to perform device-specific USB operations. USB (through ADB) is a\nprimary interface for debugging system issues. Having a native daemon to perform\nUSB configuration eliminates the dependency on the framework code so even if the\nframework crashes USB should be running.\n\n\nUnder the\n[Treble](https://android-developers.googleblog.com/2017/05/here-comes-treble-modular-base-for.html)\nmodel also introduced in Android 8.0, all of the HALs are isolated from System\nservices and are required to run in their own native daemons. This eliminates\nthe requirement to have an exclusive USB daemon as the HAL layer nicely doubles\nas a USB daemon.\n\n\nThe default HAL implementation takes care of all pre-Android 8.0 devices. Therefore, there\nwouldn't be any device-specific work for the pre-Android 8.0 devices. Android 8.0 uses the HAL\ninterface to query the status of USB ports and to perform data role and power\nrole swaps.\n\nImplementation\n--------------\n\n\nNew USB HAL interface needs to be implemented on every device launching on Android 8.0.\nThe default implementation should take care of pre-Android 8.0 devices. The default\nimplementation is sufficient if the device uses the `dual_role_usb` class to report\ntype-c port status. Trivial changes might be required in device-specific USB scripts\nto transfer ownership of the typc-c nodes to system."]]