summaryrefslogtreecommitdiffstats
path: root/src/com/android/dialer/database/DialerDatabaseHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/dialer/database/DialerDatabaseHelper.java')
-rw-r--r--src/com/android/dialer/database/DialerDatabaseHelper.java89
1 files changed, 46 insertions, 43 deletions
diff --git a/src/com/android/dialer/database/DialerDatabaseHelper.java b/src/com/android/dialer/database/DialerDatabaseHelper.java
index 95249a6f0..511c2a7bc 100644
--- a/src/com/android/dialer/database/DialerDatabaseHelper.java
+++ b/src/com/android/dialer/database/DialerDatabaseHelper.java
@@ -441,17 +441,19 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
public String getProperty(SQLiteDatabase db, String key, String defaultValue) {
try {
+ String value = null;
final Cursor cursor = db.query(Tables.PROPERTIES,
new String[] {PropertiesColumns.PROPERTY_VALUE},
PropertiesColumns.PROPERTY_KEY + "=?",
new String[] {key}, null, null, null);
- String value = null;
- try {
- if (cursor.moveToFirst()) {
- value = cursor.getString(0);
+ if (cursor != null) {
+ try {
+ if (cursor.moveToFirst()) {
+ value = cursor.getString(0);
+ }
+ } finally {
+ cursor.close();
}
- } finally {
- cursor.close();
}
return value != null ? value : defaultValue;
} catch (SQLiteException e) {
@@ -770,14 +772,6 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
final Cursor updatedContactCursor = mContext.getContentResolver().query(PhoneQuery.URI,
PhoneQuery.PROJECTION, PhoneQuery.SELECTION,
new String[]{lastUpdateMillis}, null);
-
- /** Sets the time after querying the database as the current update time. */
- final Long currentMillis = System.currentTimeMillis();
-
- if (DEBUG) {
- stopWatch.lap("Queried the Contacts database");
- }
-
if (updatedContactCursor == null) {
if (DEBUG) {
Log.e(TAG, "SmartDial query received null for cursor");
@@ -785,18 +779,25 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
return;
}
- /** Prevents the app from reading the dialer database when updating. */
- sInUpdate.getAndSet(true);
+ /** Sets the time after querying the database as the current update time. */
+ final Long currentMillis = System.currentTimeMillis();
- /** Removes contacts that have been deleted. */
- removeDeletedContacts(db, lastUpdateMillis);
- removePotentiallyCorruptedContacts(db, lastUpdateMillis);
+ try {
+ if (DEBUG) {
+ stopWatch.lap("Queried the Contacts database");
+ }
- if (DEBUG) {
- stopWatch.lap("Finished deleting deleted entries");
- }
+ /** Prevents the app from reading the dialer database when updating. */
+ sInUpdate.getAndSet(true);
+
+ /** Removes contacts that have been deleted. */
+ removeDeletedContacts(db, lastUpdateMillis);
+ removePotentiallyCorruptedContacts(db, lastUpdateMillis);
+
+ if (DEBUG) {
+ stopWatch.lap("Finished deleting deleted entries");
+ }
- try {
/** If the database did not exist before, jump through deletion as there is nothing
* to delete.
*/
@@ -830,12 +831,12 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + SmartDialDbColumns.LAST_SMARTDIAL_UPDATE_TIME +
" = " + Long.toString(currentMillis),
new String[] {});
- if (DEBUG) {
- stopWatch.lap("Queried the smart dial table for contact names");
- }
-
if (nameCursor != null) {
try {
+ if (DEBUG) {
+ stopWatch.lap("Queried the smart dial table for contact names");
+ }
+
/** Inserts prefixes of names into the prefix table.*/
insertNamePrefixes(db, nameCursor);
if (DEBUG) {
@@ -936,25 +937,27 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper {
" LIKE '" + looseQuery + "')" +
" ORDER BY " + SmartDialSortingOrder.SORT_ORDER,
new String[] {currentTimeStamp});
-
- if (DEBUG) {
- stopWatch.lap("Prefix query completed");
+ if (cursor == null) {
+ return result;
}
+ try {
+ if (DEBUG) {
+ stopWatch.lap("Prefix query completed");
+ }
- /** Gets the column ID from the cursor.*/
- final int columnDataId = 0;
- final int columnDisplayNamePrimary = 1;
- final int columnPhotoId = 2;
- final int columnNumber = 3;
- final int columnId = 4;
- final int columnLookupKey = 5;
- if (DEBUG) {
- stopWatch.lap("Found column IDs");
- }
+ /** Gets the column ID from the cursor.*/
+ final int columnDataId = 0;
+ final int columnDisplayNamePrimary = 1;
+ final int columnPhotoId = 2;
+ final int columnNumber = 3;
+ final int columnId = 4;
+ final int columnLookupKey = 5;
+ if (DEBUG) {
+ stopWatch.lap("Found column IDs");
+ }
- final Set<ContactMatch> duplicates = new HashSet<ContactMatch>();
- int counter = 0;
- try {
+ final Set<ContactMatch> duplicates = new HashSet<ContactMatch>();
+ int counter = 0;
if (DEBUG) {
stopWatch.lap("Moved cursor to start");
}