From cfd18f2e12a48a3e8f8a1428c269df9a277be1b3 Mon Sep 17 00:00:00 2001 From: "Randall E. Barker" Date: Fri, 13 Sep 2019 17:20:39 -0700 Subject: [PATCH] Speculative fixes for keyboard crashes. Fixes #1821 --- .../org/mozilla/vrbrowser/input/CustomKeyboard.java | 13 +++++++------ .../vrbrowser/ui/widgets/KeyboardWidget.java | 8 +++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/input/CustomKeyboard.java b/app/src/common/shared/org/mozilla/vrbrowser/input/CustomKeyboard.java index 29f9f3e82..5a44cab6b 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/input/CustomKeyboard.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/input/CustomKeyboard.java @@ -114,7 +114,7 @@ private int getParentFieldInt(Object obj, String fieldName) { Field mField = getField(obj.getClass().getSuperclass(), fieldName); mField.setAccessible(true); return mField.getInt(obj); - } catch (IllegalAccessException e) { + } catch (IllegalAccessException | RuntimeException e) { e.printStackTrace(); return 0; } @@ -125,7 +125,7 @@ private Object getFieldObject(Object obj, String fieldName) { Field mField = getField(obj.getClass(), fieldName); mField.setAccessible(true); return mField.get(obj); - } catch (IllegalAccessException e) { + } catch (IllegalAccessException | RuntimeException e) { e.printStackTrace(); return null; } @@ -135,7 +135,7 @@ private Object getParentFieldObject(Object obj, String fieldName) { Field mField = getField(obj.getClass().getSuperclass(), fieldName); mField.setAccessible(true); return mField.get(this); - } catch (IllegalAccessException e) { + } catch (IllegalAccessException| RuntimeException e) { e.printStackTrace(); return null; } @@ -157,14 +157,15 @@ public static Field getField(Class clazz, String fieldName) { } public static void setParentField(Object obj, String fieldName, Object value) { + if (obj.getClass().getSuperclass() == null) { + return; + } try { Field privateField = obj.getClass().getSuperclass().getDeclaredField(fieldName); privateField.setAccessible(true); privateField.set(obj, value); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { + } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java index ecf7319bb..9f53b9282 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java @@ -19,6 +19,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.ExtractedText; import android.view.inputmethod.ExtractedTextRequest; import android.view.inputmethod.InputConnection; import android.widget.ImageButton; @@ -799,7 +800,12 @@ private String getTextBeforeCursor(InputConnection aConnection) { return ""; } - String fullText = aConnection.getExtractedText(new ExtractedTextRequest(),0).text.toString(); + ExtractedText extracted = aConnection.getExtractedText(new ExtractedTextRequest(),0); + if ((extracted == null) || extracted.text == null) { + return ""; + } + + String fullText = extracted.text.toString(); return aConnection.getTextBeforeCursor(fullText.length(),0).toString(); }