Call log auto refresh.

Modified ExtendedCursor to support registration/unregistration
of contentObserver & datasetObserver on the cursor.

Automatic refresh of voicemail when inserted through the voicemail
content provider still does not work because call log uri is not
notified in this case. This will require a fix in the content provider.

Moved the call to reset new flag from onResume() to onStop() such that
calls are now marked as read when the user leaves the call log screen.
If entries were continued to be marked as read in onResume() then it
triggers a refresh and moves the entries from "new" to the
"old" section immediately. We want the entrie to remain in the "new"
section until the user exits the call log screen.

bug: 5055868

Change-Id: Iaef05ae721df1ab19dc001e17f4cd7be4019863e
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index c2c7c12..7f42be3 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -868,7 +868,6 @@
         mVoiceMailNumber = ((TelephonyManager) getActivity().getSystemService(
                 Context.TELEPHONY_SERVICE)).getVoiceMailNumber();
         mCallLogQueryHandler = new CallLogQueryHandler(getActivity().getContentResolver(), this);
-
         setHasOptionsMenu(true);
     }
 
@@ -964,12 +963,22 @@
     @Override
     public void onPause() {
         super.onPause();
-
         // Kill the requests thread
         mAdapter.stopRequestProcessing();
     }
 
     @Override
+    public void onStop() {
+        super.onStop();
+        resetNewCallsFlag();
+        // Clear notifications only when window gains focus.  This activity won't
+        // immediately receive focus if the keyguard screen is above it.
+        if (getActivity().hasWindowFocus()) {
+            removeMissedCallNotifications();
+        }
+    }
+
+    @Override
     public void onDestroy() {
         super.onDestroy();
         mAdapter.stopRequestProcessing();
@@ -1158,7 +1167,6 @@
         // again once being shown.
         mAdapter.invalidateCache();
         startCallsQuery();
-        resetNewCallsFlag();
         startVoicemailStatusQuery();
         mAdapter.mPreDrawListener = null; // Let it restart the thread after next draw
         // Clear notifications only when window gains focus.  This activity won't
diff --git a/src/com/android/contacts/calllog/ExtendedCursor.java b/src/com/android/contacts/calllog/ExtendedCursor.java
index b17c018..499a350 100644
--- a/src/com/android/contacts/calllog/ExtendedCursor.java
+++ b/src/com/android/contacts/calllog/ExtendedCursor.java
@@ -19,7 +19,9 @@
 import com.android.common.io.MoreCloseables;
 
 import android.database.AbstractCursor;
+import android.database.ContentObserver;
 import android.database.Cursor;
+import android.database.DataSetObserver;
 
 /**
  * Wraps a cursor to add an additional column with the same value for all rows.
@@ -129,4 +131,24 @@
         MoreCloseables.closeQuietly(mCursor);
         super.close();
     }
-}
\ No newline at end of file
+
+    @Override
+    public void registerContentObserver(ContentObserver observer) {
+        mCursor.registerContentObserver(observer);
+    }
+
+    @Override
+    public void unregisterContentObserver(ContentObserver observer) {
+        mCursor.unregisterContentObserver(observer);
+    }
+
+    @Override
+    public void registerDataSetObserver(DataSetObserver observer) {
+        mCursor.registerDataSetObserver(observer);
+    }
+
+    @Override
+    public void unregisterDataSetObserver(DataSetObserver observer) {
+        mCursor.unregisterDataSetObserver(observer);
+    }
+}