File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed
WordPressUtils/src/main/java/org/wordpress/android/util Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change 44import android .text .TextUtils ;
55import android .view .inputmethod .InputMethodManager ;
66import android .widget .EditText ;
7+ import android .widget .TextView ;
78
89/**
910 * EditText utils
@@ -14,13 +15,10 @@ private EditTextUtils() {
1415 }
1516
1617 /**
17- * returns text string from passed EditText
18+ * returns non-null text string from passed TextView
1819 */
19- public static String getText (EditText edit ) {
20- if (edit .getText () == null ) {
21- return "" ;
22- }
23- return edit .getText ().toString ();
20+ public static String getText (TextView textView ) {
21+ return (textView != null ) ? textView .getText ().toString () : "" ;
2422 }
2523
2624 /**
Original file line number Diff line number Diff line change 77import android .database .sqlite .SQLiteException ;
88import android .database .sqlite .SQLiteStatement ;
99
10+ import org .wordpress .android .util .AppLog .T ;
11+
1012import java .util .ArrayList ;
1113import java .util .List ;
1214
@@ -118,4 +120,22 @@ public static boolean dropAllTables(SQLiteDatabase db) throws SQLiteException {
118120 db .endTransaction ();
119121 }
120122 }
123+
124+ /*
125+ * Android's CursorWindow has a max size of 2MB per row which can be exceeded
126+ * with a very large text column, causing an IllegalStateException when the
127+ * row is read - prevent this by limiting the amount of text that's stored in
128+ * the text column.
129+ * https://github.com/android/platform_frameworks_base/blob/b77bc869241644a662f7e615b0b00ecb5aee373d/core/res/res/values/config.xml#L1268
130+ * https://github.com/android/platform_frameworks_base/blob/3bdbf644d61f46b531838558fabbd5b990fc4913/core/java/android/database/CursorWindow.java#L103
131+ */
132+ // Max 512K characters (a UTF-8 char is 4 bytes max, so a 512K characters string is always < 2Mb)
133+ private static final int MAX_TEXT_LEN = 1024 * 1024 / 2 ;
134+ public static String maxSQLiteText (final String text ) {
135+ if (text .length () <= MAX_TEXT_LEN ) {
136+ return text ;
137+ }
138+ AppLog .w (T .UTILS , "sqlite > max text exceeded, storing truncated text" );
139+ return text .substring (0 , MAX_TEXT_LEN );
140+ }
121141}
You can’t perform that action at this time.
0 commit comments