Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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