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
OK/Select on IR Remotes causing Exception #65233
Comments
|
Hi @clarkap |
flutter doctor -v |
Logs |
|
To clarify,
The button works fine from the emulator dpad. It is from a real set top ir
remote that it fails.
Works fine from Android apps though.
I hope this clarifies things for you.
…Sent from my Nexus 5
On Mon, 7 Sep 2020, 4:38 pm Pedro Massango, ***@***.***> wrote:
For some reason I'm not able to create an emulator with Directional Pad on
Android Studio 4.0. So this will need additional triage.
[image: Screen Shot 2020-09-07 at 09 34 29]
<https://user-images.githubusercontent.com/67424416/92366692-66277a00-f0ed-11ea-8280-9cb8cd6c57c4.png>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#65233 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABOB4WEXBA3URGYP73MQYL3SESL2BANCNFSM4QXN4HFQ>
.
|
|
Thanks for making it clear |
|
I don't have access to an actual Android TV to try this on, unfortunately. @clarkap would you be willing to add some code to your Flutter repo so I can see what the key information being sent is? If you could add the following just before the call to _synchronizeModifiers in print('Message received: $message');
print('RawKeyEvent: $event');
print('RawKeyEventData: ${event.data}');
print('pressedKeys: $_keysPressed'); |
|
Not A Problem,
I/flutter (10676): Message received: {keymap: android, productId: 1, flags:
8, vendorId: 1, source: 769, type: keydown, deviceId: 3, scanCode: 97,
keyCode: 23, plainCodePoint: 0, metaState: 0, codePoint: 0, repeatCount: 0}
I/flutter (10676): RawKeyEvent: RawKeyDownEvent#051d3(logicalKey:
LogicalKeyboardKey#70077(keyId: "0x100070077", keyLabel: null, debugName:
"Select"), physicalKey: PhysicalKeyboardKey#700e4(usbHidUsage:
"0x000700e4", debugName: "Control Right"))
I/flutter (10676): RawKeyEventData: RawKeyEventDataAndroid(keyLabel: null
flags: 8, codePoint: 0, keyCode: 23, scanCode: 97, metaState: 0, modifiers
down: {})
I/flutter (10676): pressedKeys: {PhysicalKeyboardKey#700e4(usbHidUsage:
"0x000700e4", debugName: "Control Right"): LogicalKeyboardKey#70077(keyId:
"0x100070077", keyLabel: null, debugName: "Select")}
I/flutter (10676): Message received: {keymap: android, productId: 1, flags:
8, vendorId: 1, source: 769, type: keyup, deviceId: 3, scanCode: 97,
keyCode: 23, plainCodePoint: 0, metaState: 0, codePoint: 0, repeatCount: 0}
══╡ EXCEPTION CAUGHT BY SERVICES LIBRARY
╞══════════════════════════════════════════════════════════
The following assertion was thrown during a platform message callback:
'package:flutter/src/widgets/shortcuts.dart': Failed assertion: line 77 pos
16: 'keys.isNotEmpty':
is not true.
…On Wed, 16 Sep 2020 at 08:30, Greg Spencer ***@***.***> wrote:
I don't have access to an actual Android TV to try this on, unfortunately.
@clarkap <https://github.com/clarkap> would you be willing to add some
code to your Flutter repo so I can see what the key information being sent
is?
If you could add the following just before the call to
_synchronizeModifiers
<https://cs.opensource.google/flutter/flutter/+/master:packages/flutter/lib/src/services/raw_keyboard.dart;l=618>
in flutter/packages/flutter/lib/src/services/raw_keyboard.dart, and then
rebuild your app and post what the log prints when you press the OK/Select
button, that would give me a lot more to go on.
print('Message received: $message');
print('RawKeyEvent: $event');
print('RawKeyEventData: ${event.data}');
print('pressedKeys: $_keysPressed');
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#65233 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABOB4WDSEP5GVY4H4FVD2TTSGABKNANCNFSM4QXN4HFQ>
.
|
|
As Adam Savage would say: "Well, there's your problem!" Although it's not your problem, it's Flutter's: we're translating the physical scan code for the remote as if it were a keyboard, and it's not, so the scan code is mapping to a "Control Right" even though it's not a control key. And the reason the assertion is firing is because although the physical key purports to be a control key, the corresponding metaState bit is not set. |
|
And I'm not quite sure what to do here: the physical key mapping only makes sense when the input is a keyboard, but we use the physical key scancode to make sure that we match the appropriate key down with the right key up. Perhaps we need to just not synchronize the modifiers if the source isn't a keyboard. |
|
Do we need a separate set of mappings for IR remotes maybe? Or in general for lots of classes of devices? How does Android know what key this "really" is? |
|
Android looks at the I think the right fix here is to have a way to tell if something is not a keyboard (which we should be able to do with platform APIs), and just skip the modifier key synchronization if it isn't a keyboard. Other devices don't use modifier key masks anyhow, so synchronization doesn't make sense. |
|
Is there any fix to this problem? |
|
Is there any way to fix this problem, or should I abandon Flutter for my TV appliacation and go to Kotlin? |
|
Looks like this is happening with other remotes as well. |
As a Workaround for those systems, I did this inside this file
Edit the function handleRawKeyMessage:Future<Map<String, dynamic>> handleRawKeyMessage(dynamic message) async {
if (_transitMode == null) {
_transitMode = KeyDataTransitMode.rawKeyData;
// Convert raw events using a listener so that conversion only occurs if
// the raw event should be dispatched.
_rawKeyboard.addListener(_convertRawEventAndStore);
}
+ try {
+ if (message["scanCode"] == 97) {
+ message["scanCode"] = 28;
+ message["keyCode"] = 66;
+ }
+ } catch (x) {
+ print(x);
+ }
final RawKeyEvent rawEvent = RawKeyEvent.fromMessage(message as Map<String, dynamic>);
...This will send And add to the function _assertEventIsRegular:void _assertEventIsRegular(KeyEvent event) {
assert(() {
const String common = 'If this occurs in real application, please report this '
'bug to Flutter. If this occurs in unit tests, please ensure that '
"simulated events follow Flutter's event model as documented in "
'`HardwareKeyboard`. This was the event: ';
+ if (event.physicalKey == PhysicalKeyboardKey.controlRight) {
+ return true;
+ }
if (event is KeyDownEvent) {
...This is just a Workaround and is not meant to be committed to the source branch. |
|
Is this going to be merged into flutter soon? I'm not a huge fan of patching the SDK code. Happy to put together a PR if it helps? |
|
Currently I have code to intercept the ok button in the Android Activity.
This then simulates the correct keypress before handing the event down to
the Flutter View.
It's clunky and a real fix such as the above would be welcome.
I can look over any patch if you want before submitting for PR.
…On Thu, 12 Jan 2023 at 09:43, RtypeStudios ***@***.***> wrote:
Is this going to be merged into flutter soon? I'm not a huge fan of
patching the SDK code. Happy to put together a PR if it helps?
—
Reply to this email directly, view it on GitHub
<#65233 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABOB4WDHGLOSEVOIZPNBW5LWR5OTHANCNFSM4QXN4HFQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
@clarkap Do you have an example of this? I'd much rather that than modifying the flutter SDK to get this working. |
|
This works for me but YMMV. `class MainActivity: FlutterActivity() { }` |
|
Thanks, will give that a go and report back. |

I am receiving this exception when pressing the OK/DPAD_CENTER button.
This is happening on two separate systems, on running Android 4.4 and the other Android 9.0.
This happens on stable through to master
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 1.22.0-10.0.pre.82, on Linux, locale en_AU.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.0)
[✓] Connected device (3 available)
• No issues found!
Very simple test app
The text was updated successfully, but these errors were encountered: