Handle fast rotation and nudging

When the user rotates quickly, the TYPE_VIEW_FOCUSED events for the
focus changes can arrive after the focus has already moved. If the event
is for a view which has since scrolled off the screen, its source will
be null. In order to handle fast rotation, RotaryService must update
mFocusedNode when performing ACTION_FOCUS rather than relying on the
subsequent TYPE_VIEW_FOCUSED event.

When performing an action that changes the focus in a way which can't be
predicted ahead of time, e.g. performing ACTION_FOCUS on a FocusArea,
find the focus immediately afterward rather than waiting for the
TYPE_VIEW_FOCUSED event.

In order to determine whether mFocusedNode should be updated for each
TYPE_VIEW_FOCUSED events, keep track of the last node focused by the
RotaryService, whether by performing ACTION_FOCUS on it or by performing
an action which changes the focus unpredictably as described above,
until the corresponding event is received. This is sufficient to
distinguish between externally triggered events, which should set
mFocusedNode, and self-triggered events, which shouldn't.

Test: rotate quickly with occasional nudges on emulator and Seahawk
Bug: 169886834
Change-Id: Ic35bbb448e315de9b5e9e4b0ddcf8be2bcb44b30
3 files changed
tree: 7b3ce3db32a8035182c8cbe91adfd538472413ac
  1. res/
  2. src/
  3. tests/
  4. Android.bp
  5. AndroidManifest.xml
  6. OWNERS
  7. readme.md
readme.md

Car rotary service

Building

make CarRotaryController -j64

Enable/disable RotaryService

To enable, run:

adb shell settings put secure enabled_accessibility_services com.android.car.rotary/com.android.car.rotary.RotaryService

To disable, run:

adb shell settings delete secure enabled_accessibility_services

Inject events

Inject RotaryEvent

To rotate the controller counter-clockwise, run:

adb shell cmd car_service inject-rotary

For clockwise, run:

adb shell cmd car_service inject-rotary -c true

To rotate the controller multiple times (100 ms ago and 50 ms ago), run:

adb shell cmd car_service inject-rotary -dt 100 50

Inject KeyEvent

To nudge the controller up, run:

adb shell cmd car_service inject-key 280

Use KeyCode 280 for nudge up, 281 for nudge down,282 for nudge left,283 for nudge right.

To click the controller center button, run:

adb shell cmd car_service inject-key 23