Skip to content

Cleanup reflection usage in InputManagerEventInjectionStrategy.#2398

Merged
copybara-service[bot] merged 1 commit into
mainfrom
piper_769778949
Jun 12, 2025
Merged

Cleanup reflection usage in InputManagerEventInjectionStrategy.#2398
copybara-service[bot] merged 1 commit into
mainfrom
piper_769778949

Conversation

@copybara-service
Copy link
Copy Markdown

@copybara-service copybara-service Bot commented Jun 10, 2025

Cleanup reflection usage in InputManagerEventInjectionStrategy.

InputManagerEventInjectionStrategy unfortunately uses a heavy
amount of reflection to access hidden Android APIs.
This commit attempts to clean it up as follows:

  • use Context.getSystemService instead of InputManager.getInstance on APIs > 23.
    Retrieving a Context can be tricky when espresso is used outside of Instrumentation,
    so also change InputManager retrival to on demand.
  • directly call MotionEvent.setSource. It has been available as a SDK method since API 12
  • copy in the InputManager constants instead of using reflection. These values have not changed
  • remove unnecessary caching and use ReflectiveMethod, which performs lazy caching instead.

@copybara-service copybara-service Bot changed the title Use getSystemService to get InputManager. Cleanup reflection usage in InputManagerEventInjectionStrategy. Jun 12, 2025
@copybara-service copybara-service Bot force-pushed the piper_769778949 branch 3 times, most recently from 224e2d9 to 5d2c5c9 Compare June 12, 2025 22:50
InputManagerEventInjectionStrategy unfortunately uses a heavy
amount of reflection to access hidden Android APIs.
This commit attempts to clean it up as follows:

- use Context.getSystemService instead of InputManager.getInstance on APIs > 23.
  Retrieving a Context can be tricky when espresso is used outside of Instrumentation,
  so also change InputManager retrival to on demand.
- directly call MotionEvent.setSource. It has been available as a SDK method since API 12
- copy in the InputManager constants instead of using reflection. These values have not changed
- remove unnecessary caching and use ReflectiveMethod, which performs lazy caching instead.

PiperOrigin-RevId: 770828718
@copybara-service copybara-service Bot merged commit fddcda4 into main Jun 12, 2025
@copybara-service copybara-service Bot deleted the piper_769778949 branch June 12, 2025 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant