Clear missed call notification.

The current implementation failed to clear missed call notification
because it requires the parent activity's window to in focus.

Due to some reasons getActivity().hasWindowFocus() returns false when
invoked from onResume(). By experimenting it came up that the window
gets focus AFTER the fragment is resumed.

The fix is to to use KeygaurdManager.inKeyguardRestrictedInputMode() to
determine if the keygaurd is on, and not remove the notification if so.

Bug: 4521535

Change-Id: I56cf82d708d7c694a966bdd6b79a328895c86048
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index 58dcc8b..490c938 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -33,6 +33,7 @@
 import com.android.internal.telephony.ITelephony;
 import com.google.common.annotations.VisibleForTesting;
 
+import android.app.KeyguardManager;
 import android.app.ListFragment;
 import android.content.ContentUris;
 import android.content.Context;
@@ -171,6 +172,7 @@
     private View mStatusMessageView;
     private TextView mStatusMessageText;
     private TextView mStatusMessageAction;
+    private KeyguardManager mKeyguardManager;
 
     public static final class ContactInfo {
         public long personId = -1;
@@ -857,6 +859,8 @@
         mVoiceMailNumber = ((TelephonyManager) getActivity().getSystemService(
                 Context.TELEPHONY_SERVICE)).getVoiceMailNumber();
         mCallLogQueryHandler = new CallLogQueryHandler(getActivity().getContentResolver(), this);
+        mKeyguardManager =
+                (KeyguardManager) getActivity().getSystemService(Context.KEYGUARD_SERVICE);
         setHasOptionsMenu(true);
     }
 
@@ -960,11 +964,6 @@
     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
@@ -1158,9 +1157,9 @@
         startCallsQuery();
         startVoicemailStatusQuery();
         mAdapter.mPreDrawListener = null; // Let it restart the thread after next draw
-        // Clear notifications only when window gains focus.  This activity won't
-        // immediately receive focus if the keyguard screen is above it.
-        if (getActivity().hasWindowFocus()) {
+        // We don't want to remove notification when keyguard is on because the user has likely not
+        // seen the new call yet.
+        if (!mKeyguardManager.inKeyguardRestrictedInputMode()) {
             removeMissedCallNotifications();
         }
     }