Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add KeyEventDeviceType to KeyData #47315

Merged
merged 8 commits into from
Nov 6, 2023

Conversation

gspencergoog
Copy link
Contributor

@gspencergoog gspencergoog commented Oct 25, 2023

Description

Before we deprecate the RawKeyEvent code, it needs to provide parity in functionality. One thing that is missing is the eventSource field from the RawKeyEventDataAndroid class, which provides the device type for the event.

See https://developer.android.com/reference/android/view/InputDevice#SOURCE_KEYBOARD for an example.

This PR implements that support, and sets the source to KeyEventDeviceType.keyboard for platforms that don't provide this information. The main thing it does is add the enum KeyEventDeviceType, and a new field KeyData.deviceType.

Related Issues

Tests

  • Updated tests to also read/write/verify this property.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Oct 25, 2023
@gspencergoog gspencergoog force-pushed the key_event_device_type branch 2 times, most recently from c5256ea to a5384f1 Compare October 25, 2023 23:31
@gspencergoog gspencergoog force-pushed the key_event_device_type branch 3 times, most recently from 899ddb4 to d7db7bf Compare October 26, 2023 23:22
@gspencergoog gspencergoog marked this pull request as ready for review October 26, 2023 23:29
@gspencergoog gspencergoog requested review from dkwingsmt and removed request for chinmaygarde and cbracken October 26, 2023 23:29
@gspencergoog gspencergoog force-pushed the key_event_device_type branch 3 times, most recently from adaeb93 to 17395ad Compare October 27, 2023 21:24
lib/ui/key.dart Outdated
///
/// Not all platforms supply an accurate type.
///
/// Defaults to [keyboard].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think default value should belong to a variable/field, not a type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point. I already removed this comment in other places, I just missed this one.

@gspencergoog gspencergoog force-pushed the key_event_device_type branch 3 times, most recently from ba2b0d7 to 67cc255 Compare October 27, 2023 23:52
@mossmana
Copy link
Contributor

mossmana commented Nov 3, 2023

@gspencergoog Before I pull down the branch and test. Do you happen to know if this change will also help to address flutter/flutter#120351 and similar issues? There is a whole class of issues related to the way certain IME key events vs. batch edits are handled.

@gspencergoog
Copy link
Contributor Author

@mossmana No, that has to do with touch keyboards, which don't produce key events. This has to do with events generated by hardware keyboards.

@mossmana
Copy link
Contributor

mossmana commented Nov 6, 2023

@mossmana No, that has to do with touch keyboards, which don't produce key events. This has to do with events generated by hardware keyboards.

Interesting, I didn't realize only hardware keyboards sent key events. Based on this comment flutter/flutter#120351 (comment), the Samsung soft keyboard does appear to send key events in some cases. Perhaps, the word key event is being overloaded.

@gspencergoog
Copy link
Contributor Author

gspencergoog commented Nov 6, 2023

Yes, some soft keyboards also synthesize hardware key events, sometimes only for specific keys, sometimes for all keys, but it's very dependent upon the soft keyboard and its settings. And the default keyboards don't seem to produce any events (GBoard, iOS keyboard).

@@ -27,6 +67,7 @@ class KeyData {
required this.logical,
required this.character,
required this.synthesized,
this.deviceType = KeyEventDeviceType.keyboard,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to pass the smoke test for the framework, this needs to be optional. Should we keep it that way, just to make migration easier? I'm leaning towards "yes", although all the other properties are required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think it's fine. At the end of the day it's PlatformDispatcher that creates this object, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, usually, although you could write your own test framework or something that used it.

Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gspencergoog gspencergoog added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 6, 2023
@auto-submit auto-submit bot merged commit cc925b0 into flutter:main Nov 6, 2023
26 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 7, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 7, 2023
…137979)

flutter/engine@461d815...b1a5d77

2023-11-07 skia-flutter-autoroll@skia.org Roll Skia from 7e3119240ae4 to 9106e374e08d (1 revision) (flutter/engine#47732)
2023-11-07 skia-flutter-autoroll@skia.org Roll Dart SDK from 82731b940e7f to aded6314af29 (1 revision) (flutter/engine#47731)
2023-11-07 skia-flutter-autoroll@skia.org Roll Fuchsia Mac SDK from HQfFSkurc6-jKM2jh... to wmM4lS2lYcphFSHPV... (flutter/engine#47730)
2023-11-07 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from _vGlgDiKOrtlKrZAP... to NaQb_BU6PSbKXSAoU... (flutter/engine#47728)
2023-11-07 skia-flutter-autoroll@skia.org Roll Skia from bd5f57c9bd1a to 7e3119240ae4 (10 revisions) (flutter/engine#47726)
2023-11-06 gspencergoog@users.noreply.github.com Add `KeyEventDeviceType` to `KeyData` (flutter/engine#47315)
2023-11-06 skia-flutter-autoroll@skia.org Roll Skia from 2b218381e226 to bd5f57c9bd1a (2 revisions) (flutter/engine#47719)
2023-11-06 skia-flutter-autoroll@skia.org Roll Dart SDK from 07d4c9d85a5a to 82731b940e7f (1 revision) (flutter/engine#47717)
2023-11-06 skia-flutter-autoroll@skia.org Roll Skia from 77aeee3b81a5 to 2b218381e226 (1 revision) (flutter/engine#47715)
2023-11-06 30870216+gaaclarke@users.noreply.github.com [Impeller] scales blur coverage to match rendered output (flutter/engine#47621)
2023-11-06 jonahwilliams@google.com [Impeller] Fix EntityPassTarget::Flip with implict MSAA. (flutter/engine#47701)
2023-11-06 skia-flutter-autoroll@skia.org Roll Dart SDK from 9211fc6406bb to 07d4c9d85a5a (1 revision) (flutter/engine#47709)
2023-11-06 jonahwilliams@google.com [Impeller] fix drawVertices dest fast path to apply alpha. (flutter/engine#47695)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from _vGlgDiKOrtl to NaQb_BU6PSbK
  fuchsia/sdk/core/mac-amd64 from HQfFSkurc6-j to wmM4lS2lYcph

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
jiahaog added a commit to jiahaog/flutter-engine that referenced this pull request Nov 7, 2023
This was introduced in flutter#47315.
Internally, this lint breaks the build.

See also https://errorprone.info/bugpattern/ImmutableEnumChecker.

Fixes: b/309552840
@jiahaog jiahaog mentioned this pull request Nov 7, 2023
8 tasks
auto-submit bot pushed a commit that referenced this pull request Nov 7, 2023
This was introduced in #47315. Internally, this lint breaks the build with the following error:

```
shell/platform/android/io/flutter/embedding/android/KeyData.java:78: Error: DeviceType is an enum, which should be immutable, but field DeviceType.value is not final [ImmutableEnum]
    private long value;
    ~~~~~~~~~~~~~~~~~~~
```

See also https://errorprone.info/bugpattern/ImmutableEnumChecker.

Fixes: b/309552840

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
output.timestamp = event.getEventTime();
output.type = type;
output.logicalKey = logicalKey;
output.physicalKey = physicalKey;
output.character = character;
output.synthesized = false;
output.deviceType = KeyData.DeviceType.kKeyboard;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Android triage (specifically flutter/flutter#151308):

Does this line override the above switch statement in all cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seems like it does. That line should probably be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-android platform-ios platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants