diff options
-rw-r--r-- | src/com/android/dialer/database/DialerDatabaseHelper.java | 6 | ||||
-rw-r--r-- | src/com/android/dialer/dialpad/SmartDialCursorLoader.java | 20 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/com/android/dialer/database/DialerDatabaseHelper.java b/src/com/android/dialer/database/DialerDatabaseHelper.java index 511c2a7bc..2177878c6 100644 --- a/src/com/android/dialer/database/DialerDatabaseHelper.java +++ b/src/com/android/dialer/database/DialerDatabaseHelper.java @@ -93,6 +93,9 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper { static final String PROPERTIES = "properties"; } + public static final Uri SMART_DIAL_UPDATED_URI = + Uri.parse("content://com.android.dialer/smart_dial_updated"); + public interface SmartDialDbColumns { static final String _ID = "id"; static final String DATA_ID = "data_id"; @@ -893,6 +896,9 @@ public class DialerDatabaseHelper extends SQLiteOpenHelper { final SharedPreferences.Editor editor = databaseLastUpdateSharedPref.edit(); editor.putLong(LAST_UPDATED_MILLIS, currentMillis); editor.commit(); + + // Notify content observers that smart dial database has been updated. + mContext.getContentResolver().notifyChange(SMART_DIAL_UPDATED_URI, null, false); } } diff --git a/src/com/android/dialer/dialpad/SmartDialCursorLoader.java b/src/com/android/dialer/dialpad/SmartDialCursorLoader.java index d01776c61..372692eae 100644 --- a/src/com/android/dialer/dialpad/SmartDialCursorLoader.java +++ b/src/com/android/dialer/dialpad/SmartDialCursorLoader.java @@ -18,8 +18,10 @@ package com.android.dialer.dialpad; import android.content.AsyncTaskLoader; import android.content.Context; +import android.content.Loader.ForceLoadContentObserver; import android.database.Cursor; import android.database.MatrixCursor; +import android.net.Uri; import android.util.Log; import com.android.contacts.common.list.PhoneNumberListAdapter.PhoneQuery; @@ -44,6 +46,8 @@ public class SmartDialCursorLoader extends AsyncTaskLoader<Cursor> { private String mQuery; private SmartDialNameMatcher mNameMatcher; + private ForceLoadContentObserver mObserver; + public SmartDialCursorLoader(Context context) { super(context); mContext = context; @@ -110,6 +114,12 @@ public class SmartDialCursorLoader extends AsyncTaskLoader<Cursor> { Cursor oldCursor = mCursor; mCursor = cursor; + if (mObserver == null) { + mObserver = new ForceLoadContentObserver(); + mContext.getContentResolver().registerContentObserver( + DialerDatabaseHelper.SMART_DIAL_UPDATED_URI, true, mObserver); + } + if (isStarted()) { /** If the Loader is in a started state, deliver the results to the client. */ super.deliverResult(cursor); @@ -144,6 +154,11 @@ public class SmartDialCursorLoader extends AsyncTaskLoader<Cursor> { /** Ensure the loader has been stopped. */ onStopLoading(); + if (mObserver != null) { + mContext.getContentResolver().unregisterContentObserver(mObserver); + mObserver = null; + } + /** Release all previously saved query results. */ if (mCursor != null) { releaseResources(mCursor); @@ -155,6 +170,11 @@ public class SmartDialCursorLoader extends AsyncTaskLoader<Cursor> { public void onCanceled(Cursor cursor) { super.onCanceled(cursor); + if (mObserver != null) { + mContext.getContentResolver().unregisterContentObserver(mObserver); + mObserver = null; + } + /** The load has been canceled, so we should release the resources associated with 'data'.*/ releaseResources(cursor); } |