Skip to content

Commit b45bc52

Browse files
committed
Merge branch 'develop' into feature/update-to-gradle-2.4
2 parents 1aac66a + 889623c commit b45bc52

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/EditTextUtils.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.text.TextUtils;
55
import android.view.inputmethod.InputMethodManager;
66
import 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
/**

WordPressUtils/src/main/java/org/wordpress/android/util/NetworkUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public static boolean isAirplaneModeOn(Context context) {
7777
* and returns false
7878
*/
7979
public static boolean checkConnection(Context context) {
80+
if (context == null) {
81+
return false;
82+
}
8083
if (isNetworkAvailable(context)) {
8184
return true;
8285
}

WordPressUtils/src/main/java/org/wordpress/android/util/SqlUtils.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import android.database.sqlite.SQLiteException;
88
import android.database.sqlite.SQLiteStatement;
99

10+
import org.wordpress.android.util.AppLog.T;
11+
1012
import java.util.ArrayList;
1113
import 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
}

0 commit comments

Comments
 (0)