Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit e536e33

Browse files
authored
Speculative fixes for keyboard crashes. Fixes #1821 (#1836)
1 parent df21d29 commit e536e33

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

app/src/common/shared/org/mozilla/vrbrowser/input/CustomKeyboard.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private int getParentFieldInt(Object obj, String fieldName) {
114114
Field mField = getField(obj.getClass().getSuperclass(), fieldName);
115115
mField.setAccessible(true);
116116
return mField.getInt(obj);
117-
} catch (IllegalAccessException e) {
117+
} catch (IllegalAccessException | RuntimeException e) {
118118
e.printStackTrace();
119119
return 0;
120120
}
@@ -125,7 +125,7 @@ private Object getFieldObject(Object obj, String fieldName) {
125125
Field mField = getField(obj.getClass(), fieldName);
126126
mField.setAccessible(true);
127127
return mField.get(obj);
128-
} catch (IllegalAccessException e) {
128+
} catch (IllegalAccessException | RuntimeException e) {
129129
e.printStackTrace();
130130
return null;
131131
}
@@ -135,7 +135,7 @@ private Object getParentFieldObject(Object obj, String fieldName) {
135135
Field mField = getField(obj.getClass().getSuperclass(), fieldName);
136136
mField.setAccessible(true);
137137
return mField.get(this);
138-
} catch (IllegalAccessException e) {
138+
} catch (IllegalAccessException| RuntimeException e) {
139139
e.printStackTrace();
140140
return null;
141141
}
@@ -157,14 +157,15 @@ public static Field getField(Class<?> clazz, String fieldName) {
157157
}
158158

159159
public static void setParentField(Object obj, String fieldName, Object value) {
160+
if (obj.getClass().getSuperclass() == null) {
161+
return;
162+
}
160163
try {
161164
Field privateField = obj.getClass().getSuperclass().getDeclaredField(fieldName);
162165
privateField.setAccessible(true);
163166
privateField.set(obj, value);
164167

165-
} catch (NoSuchFieldException e) {
166-
e.printStackTrace();
167-
} catch (IllegalAccessException e) {
168+
} catch (NoSuchFieldException | IllegalAccessException e) {
168169
e.printStackTrace();
169170
}
170171
}

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.view.View;
2020
import android.view.ViewGroup;
2121
import android.view.inputmethod.EditorInfo;
22+
import android.view.inputmethod.ExtractedText;
2223
import android.view.inputmethod.ExtractedTextRequest;
2324
import android.view.inputmethod.InputConnection;
2425
import android.widget.ImageButton;
@@ -799,7 +800,12 @@ private String getTextBeforeCursor(InputConnection aConnection) {
799800
return "";
800801
}
801802

802-
String fullText = aConnection.getExtractedText(new ExtractedTextRequest(),0).text.toString();
803+
ExtractedText extracted = aConnection.getExtractedText(new ExtractedTextRequest(),0);
804+
if ((extracted == null) || extracted.text == null) {
805+
return "";
806+
}
807+
808+
String fullText = extracted.text.toString();
803809
return aConnection.getTextBeforeCursor(fullText.length(),0).toString();
804810
}
805811

0 commit comments

Comments
 (0)