Merge "Add a flag to check the current thread on db accesses"
This commit is contained in:
commit
27e35d47af
|
@ -69,6 +69,11 @@ public class Email extends Application {
|
|||
*/
|
||||
public static final boolean LOGD = false;
|
||||
|
||||
/**
|
||||
* If true, enable the UI thread check when accessing the filesystem.
|
||||
*/
|
||||
public static final boolean DEBUG_THREAD_CHECK = false; // DON'T SUBMIT WITH TRUE
|
||||
|
||||
/**
|
||||
* The MIME type(s) of attachments we're willing to send via attachments.
|
||||
*
|
||||
|
@ -179,6 +184,8 @@ public class Email extends Application {
|
|||
|
||||
private static File sTempDirectory;
|
||||
|
||||
private static Thread sUiThread;
|
||||
|
||||
/* package for testing */ static int getColorIndexFromAccountId(long accountId) {
|
||||
// Account id is 1-based, so - 1.
|
||||
// Use abs so that it won't possibly return negative.
|
||||
|
@ -280,6 +287,7 @@ public class Email extends Application {
|
|||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
sUiThread = Thread.currentThread();
|
||||
Preferences prefs = Preferences.getPreferences(this);
|
||||
DEBUG = prefs.getEnableDebugLogging();
|
||||
setTempDirectory(this);
|
||||
|
@ -331,4 +339,10 @@ public class Email extends Application {
|
|||
public static synchronized boolean getNotifyUiAccountsChanged() {
|
||||
return sAccountsChangedNotification;
|
||||
}
|
||||
|
||||
public static void warnIfUiThread() {
|
||||
if (Thread.currentThread().equals(sUiThread)) {
|
||||
Log.w(Email.LOG_TAG, "Method called on the UI thread", new Exception("STACK TRACE"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -884,6 +884,7 @@ public class EmailProvider extends ContentProvider {
|
|||
|
||||
@Override
|
||||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
||||
if (Email.DEBUG_THREAD_CHECK) Email.warnIfUiThread();
|
||||
final int match = sURIMatcher.match(uri);
|
||||
Context context = getContext();
|
||||
// Pick the correct database for this operation
|
||||
|
@ -1029,6 +1030,7 @@ public class EmailProvider extends ContentProvider {
|
|||
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues values) {
|
||||
if (Email.DEBUG_THREAD_CHECK) Email.warnIfUiThread();
|
||||
int match = sURIMatcher.match(uri);
|
||||
Context context = getContext();
|
||||
// See the comment at delete(), above
|
||||
|
@ -1142,6 +1144,7 @@ public class EmailProvider extends ContentProvider {
|
|||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
||||
String sortOrder) {
|
||||
if (Email.DEBUG_THREAD_CHECK) Email.warnIfUiThread();
|
||||
Cursor c = null;
|
||||
Uri notificationUri = EmailContent.CONTENT_URI;
|
||||
int match = sURIMatcher.match(uri);
|
||||
|
@ -1237,6 +1240,7 @@ public class EmailProvider extends ContentProvider {
|
|||
|
||||
@Override
|
||||
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
||||
if (Email.DEBUG_THREAD_CHECK) Email.warnIfUiThread();
|
||||
int match = sURIMatcher.match(uri);
|
||||
Context context = getContext();
|
||||
// See the comment at delete(), above
|
||||
|
|
Loading…
Reference in New Issue