From 2c081f043f8d9008197db0aa12162adb20688074 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Thu, 11 Oct 2012 11:31:47 -0700 Subject: [PATCH] Catch a rare sqlite error in phone state changed receiver, try once to recover, then abort --- .../calls/PhoneStateChangedReceiver.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java b/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java index 25acfb70c..05fa975fc 100644 --- a/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java +++ b/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java @@ -11,6 +11,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.database.Cursor; +import android.database.sqlite.SQLiteException; import android.net.Uri; import android.provider.CallLog.Calls; import android.provider.ContactsContract; @@ -56,13 +57,29 @@ public class PhoneStateChangedReceiver extends BroadcastReceiver { @Override public void run() { AndroidUtilities.sleepDeep(WAIT_BEFORE_READ_LOG); - Cursor calls = context.getContentResolver().query( + Cursor calls; + try { + calls = context.getContentResolver().query( Calls.CONTENT_URI, new String[] { Calls.NUMBER, Calls.DATE, Calls.CACHED_NAME }, Calls.TYPE + " = ? AND " + Calls.NEW + " = ?", new String[] { Integer.toString(Calls.MISSED_TYPE), "1" }, Calls.DATE + " DESC" ); + } catch (SQLiteException e) { // Sometimes database is locked, retry once + AndroidUtilities.sleepDeep(300L); + try { + calls = context.getContentResolver().query( + Calls.CONTENT_URI, + new String[] { Calls.NUMBER, Calls.DATE, Calls.CACHED_NAME }, + Calls.TYPE + " = ? AND " + Calls.NEW + " = ?", + new String[] { Integer.toString(Calls.MISSED_TYPE), "1" }, + Calls.DATE + " DESC" + ); + } catch (SQLiteException e2) { + calls = null; + } + } try { if (calls == null) return;