-
-
Notifications
You must be signed in to change notification settings - Fork 208
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
feat: add pinWithKeyEvent to put keys one by one for pin as key evnets #691
Conversation
lib/unlock-helpers.js
Outdated
const KEYCODE_NUMPAD_ENTER = 66; | ||
const KEYCODE_POWER = 26; | ||
const KEYCODE_WAKEUP = 224; // Can work over API Level 20 | ||
const UNLOCK_WAIT_TIME = 100; | ||
const HIDE_KEYBOARD_WAIT_TIME = 100; | ||
const INPUT_KEYS_WAIT_TIME = 100; | ||
// mapping of Android keycode and numbers | ||
const ANDROID_KEY_CODE_NUMBER = { | ||
'0': 7, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this mapping could be generated dynamically, there is no need to hardcode each item
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const ZERO_KEY_CODE = 7;
result = _.range(10).reduce((acc) => {
acc[String.fromCharCode('0'.charCodeAt(0) + _.size(acc))] = ZERO_KEY_CODE + _.size(acc);
return acc;
}, {});
lib/unlock-helpers.js
Outdated
|
||
// Some devices accept entering the code without pressing the Enter key | ||
// When I rushed commands without this wait before pressKeyCode, rarely UI2 sever crashed | ||
await sleep(UNLOCK_WAIT_TIME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we extract this duplicated block into a separate function to avoid duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Some devices like Samsung have customized keyboard in
pin
.Then, it is reliable to send keys as keycode like
password
rather than finding numbers with ids. I named the strategy aspinWithKeyEvent
for now. (Suggestions are welcome)As backward compatibility,
pin
should be there, but thepinUnlockWithKeyEvent
can be used as a fallback method when no system key ids in the pin view. Afaik, this fallback is pretty enough.After this change: