[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# OEM custom inputs\n\nUse OEM custom inputs to add new Car input events for new and non-standard\nAndroid features. Non-standard input events are not mapped by the existing\nAndroid `KeyEvent`, designed to be generic and to work on any Android surface\nbut not extended to implement OEM-specific features. For example, a button\nlocated on the steering wheel control that, when pressed, opens a maps app\n(through an intent) with the car's current location. This feature enables\ndrivers to visualize their current location without becoming distracted while\ndriving.\n\nThis article describes how to reuse an existing Android `KeyEvent` to\ncreate a `CustomInputEvent` for use *only* when no Android `KeyEvent` can\nbe used to represent the feature.\n\nHW_CUSTOM_INPUT\n---------------\n\nAn OEM custom input is represented by [HW_CUSTOM_INPUT](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/automotive/vehicle/2.0/types.hal) and\n[CustomInputEvent.java](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/car-lib/src/android/car/input). [HW_CUSTOM_INPUT](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/automotive/vehicle/2.0/types.hal) is the\nnative event, instantiated by the car hardware (Vehicle HAL). OEMs determine\nhow to instantiate this event. Access to [HW_CUSTOM_INPUT](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/automotive/vehicle/2.0/types.hal) is\nset as \\[read only\\], with `VehiclePropertyAccess:READ`.\n\nTo ensure the Vehicle HAL can always broadcast the latest available value, the\n[HW_CUSTOM_INPUT](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/automotive/vehicle/2.0/types.hal) notification is set as `ON_CHANGE`, with\n`VehiclePropertyChangeMode:ON_CHANGE`.\n\n[HW_CUSTOM_INPUT](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/automotive/vehicle/2.0/types.hal) values are composed of an array of generic\n`int32`, set as `GLOBAL` (with `VehicleArea:GLOBAL`) The three\ngeneric integers are:\n\n1. The first element represents the input code to be defined by the OEM.\n You can associate any semantic to the input code.\n\n | **Note:** If you don't need more than 10 input codes, then you can use the generic functions (see `INPUT_CODE_F1` to `INPUT_CODE_F10` constants defined in `CustomInputType`, see `types.hal` file) to help readability. Using the generic functions is completely optional.\n2. The second element stores the target display, such as the main display\n or cluster.\n\n3. The third element contains the number of times the event was repeated.\n For example, to indicate how many times a button was pressed.\n\nCustomInputEvent and Car Input API\n----------------------------------\n\n[InputHalService](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/service/src/com/android/car/hal/InputHalService.java) is the Car service that receives an incoming\n`HW_CUSTOM_INPUT` from the Vehicle HAL.\n\n[InputHalService](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/service/src/com/android/car/hal/InputHalService.java) converts the incoming `HW_CUSTOM_INPUT` into\nthe `CustomInputEvent`, a Java [parcelable](https://developer.android.com/reference/android/os/Parcelable) class located in\n[car-lib/src/android/car/input](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/car-lib/src/android/car/input), along with the respective\n[aidl interface](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/car-lib/src/android/car/input).\n\n[CarInputService](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/service/src/com/android/car/CarInputService.java), a core Car Input service, receives incoming\nCustomInputEvents and then sends them to any registered Android system service.\n\nTo register and receive incoming CustomInputEvents, system services must:\n\n- Implement [CarInputManager.CarInputCaptureCallback#onKeyEvents](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/service/src/com/android/car/CarInputService.java).\n\n- Register through [CarInputManager#requestInputEventCapture](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/service/src/com/android/car/CarInputService.java),\n passing `CarInputManager.INPUT_TYPE_CUSTOM_INPUT_EVENT` as the input\n type parameter.\n\n To unregister, services must invoke\n [CarInputManager#releaseInputEventCapture](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/service/src/com/android/car/CarInputService.java).\n\nThe following diagram illustrates the workflow of an OEM Custom Input event.\n\nOEM Android system services\n---------------------------\n\nOEMs provide their Android system service to handle incoming\nCustomInputEvents from `CarInputService`.\n\nOnly those services marked with the\n[android.permission.INJECT_EVENTS](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/core/res/AndroidManifest.xml;l=3303) privilege permission\ncan register and receive CustomInputEvents from the Car Input API\n([CarInputManager](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/car-lib/src/android/car/input/CarInputManager.java)). No third party service or application can\nbe signed with this Android system permission (only OEM services).\nTherefore, no third party service or application can register\nagainst the Car Input API.\n\nOEM Android system services can access `SystemApi` and public methods.\n\nReference implementation\n------------------------\n\nSee the reference implementation in\n[packages/services/Car/tests/SampleCustomInputService](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/tests/), which\nis provided as an example and a guideline. For example, to add a new button\nin the steering wheel control. When pressed, this new button starts the\nmaps app with the current car location.\n\nIn this example, the OEM selected `INPUT_CODE_F1` (the first `CustomInputEvent`\nconvenience function) to represent this new feature (opening the maps app with\nthe current car location).\n| **Note:** The input code range represented by `INPUT_CODE_F1` up to `INPUT_CODE_F10` constants is used for convenience only. OEMs cat set any value for input code.\n\nDuring start up, this service registers itself against `CarInputManager`\nthrough `requestInputEventCapture` (see the\n[reference implementation registration code](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/tests/SampleCustomInputService/src/com/android/car/custominput/sample/SampleCustomInputService.java).\n\nWhen receiving incoming CustomInputEvents, this service sends the intent\nto start the maps app. To learn how this is accomplished, see\n[CustomInputEventListener.java](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/tests/SampleCustomInputService/src/com/android/car/custominput/sample/CustomInputEventListener.java)."]]