Skip to content

Commit

Permalink
Merge branch 'hotfix/4.1.1' into release/4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Jun 19, 2015
2 parents cd371d6 + 6c9ad36 commit ef87489
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.text.TextUtils;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

/**
* EditText utils
Expand All @@ -14,13 +15,10 @@ private EditTextUtils() {
}

/**
* returns text string from passed EditText
* returns non-null text string from passed TextView
*/
public static String getText(EditText edit) {
if (edit.getText() == null) {
return "";
}
return edit.getText().toString();
public static String getText(TextView textView) {
return (textView != null) ? textView.getText().toString() : "";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteStatement;

import org.wordpress.android.util.AppLog.T;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -118,4 +120,22 @@ public static boolean dropAllTables(SQLiteDatabase db) throws SQLiteException {
db.endTransaction();
}
}

/*
* Android's CursorWindow has a max size of 2MB per row which can be exceeded
* with a very large text column, causing an IllegalStateException when the
* row is read - prevent this by limiting the amount of text that's stored in
* the text column.
* https://github.com/android/platform_frameworks_base/blob/b77bc869241644a662f7e615b0b00ecb5aee373d/core/res/res/values/config.xml#L1268
* https://github.com/android/platform_frameworks_base/blob/3bdbf644d61f46b531838558fabbd5b990fc4913/core/java/android/database/CursorWindow.java#L103
*/
// Max 512K characters (a UTF-8 char is 4 bytes max, so a 512K characters string is always < 2Mb)
private static final int MAX_TEXT_LEN = 1024 * 1024 / 2;
public static String maxSQLiteText(final String text) {
if (text.length() <= MAX_TEXT_LEN) {
return text;
}
AppLog.w(T.UTILS, "sqlite > max text exceeded, storing truncated text");
return text.substring(0, MAX_TEXT_LEN);
}
}

0 comments on commit ef87489

Please sign in to comment.