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

Speculative fixes for keyboard crashes. Fixes #1821 #1836

Merged
merged 1 commit into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down