Merge pull request #3721 from keymanapp/fix/android/kmmanager-robustness

fix(android/engine): Improve KMManager robustness
This commit is contained in:
Darcy Wong 2020-10-22 12:53:44 +07:00 • committed by GitHub
commit 9f3ce40d11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
@ -394,12 +396,15 @@ 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;
} else if (!didLogHardwareKeystrokeException) {
KMLog.LogError(TAG, "executeHardwareKeystroke: " + keyboard.toString() + " keyboard is null");
didLogHardwareKeystrokeException = true;
}
return false;
@ -483,7 +488,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)) {
@ -1794,6 +1799,11 @@ 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");
return;
}
if (url.startsWith("file")) { //endsWith(KMFilename_KeyboardHtml)) {
InAppKeyboardLoaded = true;
@ -1844,6 +1854,11 @@ 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");
return false;
}
if(url.indexOf("pageLoaded") >= 0) {
pageLoaded(view, url);
} else if (url.indexOf("hideKeyboard") >= 0) {
@ -2024,6 +2039,11 @@ 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");
return;
}
if (url.startsWith("file:")) {
SystemKeyboardLoaded = true;
if (!SystemKeyboard.keyboardSet) {
@ -2073,6 +2093,11 @@ public final class KMManager {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (SystemKeyboard == null) {
KMLog.LogError(TAG, "shouldOverrideUrlLoading and SystemKeyboard null");
return false;
}
if(url.indexOf("pageLoaded") >= 0) {
pageLoaded(view, url);
} else if (url.indexOf("hideKeyboard") >= 0) {
@ -2276,6 +2301,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");
@ -2307,6 +2337,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");
@ -2398,6 +2433,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;
}
@ -2432,6 +2472,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;
}