diff --git a/CHANGELOG.md b/CHANGELOG.md index a2ff05c1c..9d7fe7a21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,6 +86,7 @@ Emojis for the following are chosen based on [gitmoji](https://gitmoji.dev/). ### Bug Fixes +- The keyboard service no longer crashes when an editor starts input with no `EditorInfo` ([#699](https://github.com/scribe-org/Scribe-Android/issues/699)). - Downloading or checking for language data updates no longer crashes the app when the server returns a malformed timestamp ([#700](https://github.com/scribe-org/Scribe-Android/issues/700)). ### 🔒 Security diff --git a/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt b/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt index d079c06f0..3a75144e8 100644 --- a/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt +++ b/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt @@ -442,16 +442,17 @@ abstract class GeneralKeyboardIME( restarting: Boolean, ) { super.onStartInput(attribute, restarting) - inputTypeClass = attribute!!.inputType and TYPE_MASK_CLASS - enterKeyType = attribute.imeOptions and (IME_MASK_ACTION or IME_FLAG_NO_ENTER_ACTION) + val editorInfo = attribute ?: EditorInfo() + inputTypeClass = editorInfo.inputType and TYPE_MASK_CLASS + enterKeyType = editorInfo.imeOptions and (IME_MASK_ACTION or IME_FLAG_NO_ENTER_ACTION) currentEnterKeyType = enterKeyType // This setter triggers the logic in the property override if not shadowed. hasTextBeforeCursor = currentInputConnection?.getTextBeforeCursor(1, 0)?.isNotEmpty() == true - isNumericKeyboardActive = shouldUseNumericKeyboard(attribute.inputType) + isNumericKeyboardActive = shouldUseNumericKeyboard(editorInfo.inputType) keyboardMode = if (isNumericKeyboardActive) keyboardSymbols else keyboardLetters - val keyboardXml = getKeyboardLayoutXMLForInputType(attribute.inputType, getKeyboardLayoutXML()) + val keyboardXml = getKeyboardLayoutXMLForInputType(editorInfo.inputType, getKeyboardLayoutXML()) loadLanguageData() diff --git a/app/src/testKeyboards/kotlin/be/scri/services/GeneralKeyboardIMEInputTypeTest.kt b/app/src/testKeyboards/kotlin/be/scri/services/GeneralKeyboardIMEInputTypeTest.kt index 797167697..7ebbc9201 100644 --- a/app/src/testKeyboards/kotlin/be/scri/services/GeneralKeyboardIMEInputTypeTest.kt +++ b/app/src/testKeyboards/kotlin/be/scri/services/GeneralKeyboardIMEInputTypeTest.kt @@ -3,6 +3,7 @@ package be.scri.services import android.text.InputType +import android.view.inputmethod.EditorInfo import be.scri.R import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse @@ -55,4 +56,15 @@ class GeneralKeyboardIMEInputTypeTest { GeneralKeyboardIME.getKeyboardLayoutXMLForInputType(inputType, R.xml.keys_letters_english), ) } + + @Test + fun defaultEditorInfo_fallsBackToLetterLayout() { + val fallback = EditorInfo() + + assertFalse(GeneralKeyboardIME.shouldUseNumericKeyboard(fallback.inputType)) + assertEquals( + R.xml.keys_letters_english, + GeneralKeyboardIME.getKeyboardLayoutXMLForInputType(fallback.inputType, R.xml.keys_letters_english), + ) + } }