From 4b311055be8e5834b9f4b7372adf8d486fd72565 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Fri, 25 Sep 2020 11:22:27 +0700 Subject: [PATCH 1/3] fix(android/engine): Check keyboard entry points --- .../java/com/tavultesoft/kmea/KMManager.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java b/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java index 458bdb234a..338a145ee0 100644 --- a/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java +++ b/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java @@ -394,10 +394,10 @@ public final class KMManager { public static boolean executeHardwareKeystroke( int code, int shift, KeyboardType keyboard, int lstates, int eventModifiers) { - if (keyboard == KeyboardType.KEYBOARD_TYPE_INAPP) { + if (keyboard == KeyboardType.KEYBOARD_TYPE_INAPP && InAppKeyboard != null) { InAppKeyboard.executeHardwareKeystroke(code, shift, lstates, eventModifiers); return true; - } else if (keyboard == KeyboardType.KEYBOARD_TYPE_SYSTEM) { + } else if (keyboard == KeyboardType.KEYBOARD_TYPE_SYSTEM && SystemKeyboard != null) { SystemKeyboard.executeHardwareKeystroke(code, shift, lstates, eventModifiers); return true; } @@ -483,7 +483,7 @@ public final class KMManager { } public static void onStartInput(EditorInfo attribute, boolean restarting) { - if (!restarting) { + if (!restarting && SystemKeyboard != null) { String packageName = attribute.packageName; int inputType = attribute.inputType; if (packageName.equals("android") && inputType == (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)) { @@ -1789,6 +1789,12 @@ public final class KMManager { private void pageLoaded(WebView view, String url) { Log.d("KMEA", "pageLoaded: [inapp] " + url); + if (InAppKeyboard == null) { + KMLog.LogError(TAG, "pageLoaded and InAppKeyboard null"); + InAppKeyboardLoaded = false; + return; + } + if (url.startsWith("file")) { //endsWith(KMFilename_KeyboardHtml)) { InAppKeyboardLoaded = true; @@ -1839,6 +1845,12 @@ public final class KMManager { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Log.d("KMEA", "shouldOverrideUrlLoading [inapp]: "+url); + if (InAppKeyboard == null) { + KMLog.LogError(TAG, "shouldOverrideUrlLoading and InAppKeyboard null"); + InAppKeyboardLoaded = false; + return false; + } + if(url.indexOf("pageLoaded") >= 0) { pageLoaded(view, url); } else if (url.indexOf("hideKeyboard") >= 0) { @@ -2019,6 +2031,12 @@ public final class KMManager { private void pageLoaded(WebView view, String url) { Log.d("KMEA", "pageLoaded: [system] " + url); + if (SystemKeyboard == null) { + KMLog.LogError(TAG, "pageLoaded and SystemKeyboard null"); + SystemKeyboardLoaded = false; + return; + } + if (url.startsWith("file:")) { SystemKeyboardLoaded = true; if (!SystemKeyboard.keyboardSet) { @@ -2068,6 +2086,12 @@ public final class KMManager { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (SystemKeyboard == null) { + KMLog.LogError(TAG, "shouldOverrideUrlLoading and SystemKeyboard null"); + SystemKeyboardLoaded = false; + return false; + } + if(url.indexOf("pageLoaded") >= 0) { pageLoaded(view, url); } else if (url.indexOf("hideKeyboard") >= 0) { From c010ec6465c1b732c388d0a4f8808451b90ab25d Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Mon, 19 Oct 2020 14:57:49 +0700 Subject: [PATCH 2/3] fix(android/engine): Add more checks for Keyboard --- .../java/com/tavultesoft/kmea/KMManager.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java b/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java index a7ea23810c..06db83e054 100644 --- a/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java +++ b/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java @@ -1796,7 +1796,6 @@ public final class KMManager { Log.d("KMEA", "pageLoaded: [inapp] " + url); if (InAppKeyboard == null) { KMLog.LogError(TAG, "pageLoaded and InAppKeyboard null"); - InAppKeyboardLoaded = false; return; } @@ -1852,7 +1851,6 @@ public final class KMManager { Log.d("KMEA", "shouldOverrideUrlLoading [inapp]: "+url); if (InAppKeyboard == null) { KMLog.LogError(TAG, "shouldOverrideUrlLoading and InAppKeyboard null"); - InAppKeyboardLoaded = false; return false; } @@ -2038,7 +2036,6 @@ public final class KMManager { Log.d("KMEA", "pageLoaded: [system] " + url); if (SystemKeyboard == null) { KMLog.LogError(TAG, "pageLoaded and SystemKeyboard null"); - SystemKeyboardLoaded = false; return; } @@ -2093,7 +2090,6 @@ public final class KMManager { public boolean shouldOverrideUrlLoading(WebView view, String url) { if (SystemKeyboard == null) { KMLog.LogError(TAG, "shouldOverrideUrlLoading and SystemKeyboard null"); - SystemKeyboardLoaded = false; return false; } @@ -2300,6 +2296,11 @@ public final class KMManager { Handler mainLoop = new Handler(Looper.getMainLooper()); mainLoop.post(new Runnable() { public void run() { + if (InAppKeyboard == null) { + KMLog.LogError(TAG, "dispatchKey failed: InAppKeyboard is null"); + return; + } + if (InAppKeyboard.subKeysWindow != null || KMTextView.activeView == null || KMTextView.activeView.getClass() != KMTextView.class) { if ((KMTextView.activeView == null) && isDebugMode()) { Log.w(HANDLER_TAG, "dispatchKey failed: activeView is null"); @@ -2331,6 +2332,11 @@ public final class KMManager { Handler mainLoop = new Handler(Looper.getMainLooper()); mainLoop.post(new Runnable() { public void run() { + if (InAppKeyboard == null) { + KMLog.LogError(TAG, "insertText failed: InAppKeyboard is null"); + return; + } + if (InAppKeyboard.subKeysWindow != null || KMTextView.activeView == null || KMTextView.activeView.getClass() != KMTextView.class) { if ((KMTextView.activeView == null) && isDebugMode()) { Log.w("IAK: JS Handler", "insertText failed: activeView is null"); @@ -2422,6 +2428,11 @@ public final class KMManager { Handler mainLoop = new Handler(Looper.getMainLooper()); mainLoop.post(new Runnable() { public void run() { + if (SystemKeyboard == null) { + KMLog.LogError(TAG, "dispatchKey failed: SystemKeyboard is null"); + return; + } + if (SystemKeyboard.subKeysWindow != null) { return; } @@ -2456,6 +2467,11 @@ public final class KMManager { Handler mainLoop = new Handler(Looper.getMainLooper()); mainLoop.post(new Runnable() { public void run() { + if (SystemKeyboard == null) { + KMLog.LogError(TAG, "insertText failed: SystemKeyboard is null"); + return; + } + if (SystemKeyboard.subKeysWindow != null) { return; } From 4b3a5687873981585e52b416bedbaf5d456b5c87 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Tue, 20 Oct 2020 09:53:36 +0700 Subject: [PATCH 3/3] fix(android/engine): Log executeHardwareKeystroke error once per session --- .../app/src/main/java/com/tavultesoft/kmea/KMManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java b/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java index 06db83e054..7ffeaaaf8c 100644 --- a/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java +++ b/android/KMEA/app/src/main/java/com/tavultesoft/kmea/KMManager.java @@ -125,6 +125,8 @@ public final class KMManager { private static boolean shouldAllowSetKeyboard = true; private static boolean didCopyAssets = false; + private static boolean didLogHardwareKeystrokeException = false; + private static GlobeKeyAction inappKbGlobeKeyAction = GlobeKeyAction.GLOBE_KEY_ACTION_SHOW_MENU; private static GlobeKeyAction sysKbGlobeKeyAction = GlobeKeyAction.GLOBE_KEY_ACTION_SHOW_MENU; // This is used to keep track of the starting system keyboard index while the screen is locked @@ -400,6 +402,9 @@ public final class KMManager { } else if (keyboard == KeyboardType.KEYBOARD_TYPE_SYSTEM && SystemKeyboard != null) { SystemKeyboard.executeHardwareKeystroke(code, shift, lstates, eventModifiers); return true; + } else if (!didLogHardwareKeystrokeException) { + KMLog.LogError(TAG, "executeHardwareKeystroke: " + keyboard.toString() + " keyboard is null"); + didLogHardwareKeystrokeException = true; } return false;