Loading src/com/android/contacts/calllog/CallLogFragment.java +38 −10 Original line number Diff line number Diff line Loading @@ -990,7 +990,7 @@ public class CallLogFragment extends ListFragment implements ViewPagerVisibility @Override public void onStop() { super.onStop(); resetNewCallsFlag(); updateOnExit(); } @Override Loading @@ -1000,10 +1000,6 @@ public class CallLogFragment extends ListFragment implements ViewPagerVisibility mAdapter.changeCursor(null); } private void resetNewCallsFlag() { mCallLogQueryHandler.markNewCallsAsOld(); } private void startCallsQuery() { mAdapter.setLoading(true); mCallLogQueryHandler.fetchAllCalls(); Loading Loading @@ -1153,6 +1149,10 @@ public class CallLogFragment extends ListFragment implements ViewPagerVisibility if (visible && isResumed()) { refreshData(); } if (!visible) { updateOnExit(); } } /** Requests updates to the data to be shown. */ Loading @@ -1163,11 +1163,7 @@ public class CallLogFragment extends ListFragment implements ViewPagerVisibility startCallsQuery(); startVoicemailStatusQuery(); mAdapter.mPreDrawListener = null; // Let it restart the thread after next draw // 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(); } updateOnEntry(); } /** Removes the missed call notifications. */ Loading @@ -1185,4 +1181,36 @@ public class CallLogFragment extends ListFragment implements ViewPagerVisibility Log.e(TAG, "Failed to clear missed calls notification due to remote exception"); } } /** Updates call data and notification state while leaving the call log tab. */ private void updateOnExit() { updateOnTransition(false); } /** Updates call data and notification state while entering the call log tab. */ private void updateOnEntry() { updateOnTransition(true); } private void updateOnTransition(boolean onEntry) { // We don't want to update any call data when keyguard is on because the user has likely not // seen the new calls yet. if (!mKeyguardManager.inKeyguardRestrictedInputMode()) { // On either of the transitions we reset the new flag and update the notifications. // While exiting we additionally consume all missed calls (by marking them as read). // This will ensure that they no more appear in the "new" section when we return back. mCallLogQueryHandler.markNewCallsAsOld(); if (!onEntry) { mCallLogQueryHandler.markMissedCallsAsRead(); } removeMissedCallNotifications(); updateVoicemailNotifications(); } } private void updateVoicemailNotifications() { Intent serviceIntent = new Intent(getActivity(), CallLogNotificationsService.class); serviceIntent.setAction(CallLogNotificationsService.ACTION_UPDATE_NOTIFICATIONS); getActivity().startService(serviceIntent); } } src/com/android/contacts/calllog/CallLogQueryHandler.java +23 −15 Original line number Diff line number Diff line Loading @@ -51,9 +51,12 @@ import javax.annotation.concurrent.GuardedBy; private static final int QUERY_OLD_CALLS_TOKEN = 54; /** The token for the query to mark all missed calls as old after seeing the call log. */ private static final int UPDATE_MARK_AS_OLD_TOKEN = 55; /** The token for the query to mark all missed calls as read after seeing the call log. */ private static final int UPDATE_MARK_MISSED_CALL_AS_READ_TOKEN = 56; /** The token for the query to fetch voicemail status messages. */ private static final int QUERY_VOICEMAIL_STATUS_TOKEN = 56; private static final int QUERY_VOICEMAIL_STATUS_TOKEN = 57; private final WeakReference<Listener> mListener; Loading Loading @@ -149,14 +152,11 @@ import javax.annotation.concurrent.GuardedBy; /** Fetches the list of calls in the call log, either the new one or the old ones. */ private void fetchCalls(int token, boolean isNew, boolean voicemailOnly) { // We need to check for NULL explicitly otherwise entries with where NEW or READ are NULL // We need to check for NULL explicitly otherwise entries with where READ is NULL // may not match either the query or its negation. String selection = String.format( "(%s IS NOT NULL AND %s = 1 AND (%s = ? OR %s = ?)) OR " + "(%s IS NOT NULL AND %s = 0)", Calls.NEW, Calls.NEW, Calls.TYPE, Calls.TYPE, Calls.IS_READ, Calls.IS_READ); final String[] selectionArgs; // We consider the calls that are not yet consumed (i.e. IS_READ = 0) as "new". String selection = String.format("%s IS NOT NULL AND %s = 0", Calls.IS_READ, Calls.IS_READ); String[] selectionArgs = null; if (!isNew) { // Negate the query. selection = String.format("NOT (%s)", selection); Loading @@ -165,13 +165,6 @@ import javax.annotation.concurrent.GuardedBy; // Add a clause to fetch only items of type voicemail. selection = String.format("(%s) AND (%s = ?)", selection, Calls.TYPE); selectionArgs = new String[]{ Integer.toString(Calls.MISSED_TYPE), Integer.toString(Calls.VOICEMAIL_TYPE), Integer.toString(Calls.VOICEMAIL_TYPE), }; } else { selectionArgs = new String[]{ Integer.toString(Calls.MISSED_TYPE), Integer.toString(Calls.VOICEMAIL_TYPE), }; } Loading Loading @@ -199,6 +192,21 @@ import javax.annotation.concurrent.GuardedBy; values, where.toString(), null); } /** Updates all missed calls to mark them as read. */ public void markMissedCallsAsRead() { // Mark all "new" calls as not new anymore. StringBuilder where = new StringBuilder(); where.append(Calls.IS_READ).append(" = 0"); where.append(" AND "); where.append(Calls.TYPE).append(" = ").append(Calls.MISSED_TYPE); ContentValues values = new ContentValues(1); values.put(Calls.IS_READ, "1"); startUpdate(UPDATE_MARK_MISSED_CALL_AS_READ_TOKEN, null, Calls.CONTENT_URI, values, where.toString(), null); } /** * Invalidate the current list of calls. * <p> Loading Loading
src/com/android/contacts/calllog/CallLogFragment.java +38 −10 Original line number Diff line number Diff line Loading @@ -990,7 +990,7 @@ public class CallLogFragment extends ListFragment implements ViewPagerVisibility @Override public void onStop() { super.onStop(); resetNewCallsFlag(); updateOnExit(); } @Override Loading @@ -1000,10 +1000,6 @@ public class CallLogFragment extends ListFragment implements ViewPagerVisibility mAdapter.changeCursor(null); } private void resetNewCallsFlag() { mCallLogQueryHandler.markNewCallsAsOld(); } private void startCallsQuery() { mAdapter.setLoading(true); mCallLogQueryHandler.fetchAllCalls(); Loading Loading @@ -1153,6 +1149,10 @@ public class CallLogFragment extends ListFragment implements ViewPagerVisibility if (visible && isResumed()) { refreshData(); } if (!visible) { updateOnExit(); } } /** Requests updates to the data to be shown. */ Loading @@ -1163,11 +1163,7 @@ public class CallLogFragment extends ListFragment implements ViewPagerVisibility startCallsQuery(); startVoicemailStatusQuery(); mAdapter.mPreDrawListener = null; // Let it restart the thread after next draw // 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(); } updateOnEntry(); } /** Removes the missed call notifications. */ Loading @@ -1185,4 +1181,36 @@ public class CallLogFragment extends ListFragment implements ViewPagerVisibility Log.e(TAG, "Failed to clear missed calls notification due to remote exception"); } } /** Updates call data and notification state while leaving the call log tab. */ private void updateOnExit() { updateOnTransition(false); } /** Updates call data and notification state while entering the call log tab. */ private void updateOnEntry() { updateOnTransition(true); } private void updateOnTransition(boolean onEntry) { // We don't want to update any call data when keyguard is on because the user has likely not // seen the new calls yet. if (!mKeyguardManager.inKeyguardRestrictedInputMode()) { // On either of the transitions we reset the new flag and update the notifications. // While exiting we additionally consume all missed calls (by marking them as read). // This will ensure that they no more appear in the "new" section when we return back. mCallLogQueryHandler.markNewCallsAsOld(); if (!onEntry) { mCallLogQueryHandler.markMissedCallsAsRead(); } removeMissedCallNotifications(); updateVoicemailNotifications(); } } private void updateVoicemailNotifications() { Intent serviceIntent = new Intent(getActivity(), CallLogNotificationsService.class); serviceIntent.setAction(CallLogNotificationsService.ACTION_UPDATE_NOTIFICATIONS); getActivity().startService(serviceIntent); } }
src/com/android/contacts/calllog/CallLogQueryHandler.java +23 −15 Original line number Diff line number Diff line Loading @@ -51,9 +51,12 @@ import javax.annotation.concurrent.GuardedBy; private static final int QUERY_OLD_CALLS_TOKEN = 54; /** The token for the query to mark all missed calls as old after seeing the call log. */ private static final int UPDATE_MARK_AS_OLD_TOKEN = 55; /** The token for the query to mark all missed calls as read after seeing the call log. */ private static final int UPDATE_MARK_MISSED_CALL_AS_READ_TOKEN = 56; /** The token for the query to fetch voicemail status messages. */ private static final int QUERY_VOICEMAIL_STATUS_TOKEN = 56; private static final int QUERY_VOICEMAIL_STATUS_TOKEN = 57; private final WeakReference<Listener> mListener; Loading Loading @@ -149,14 +152,11 @@ import javax.annotation.concurrent.GuardedBy; /** Fetches the list of calls in the call log, either the new one or the old ones. */ private void fetchCalls(int token, boolean isNew, boolean voicemailOnly) { // We need to check for NULL explicitly otherwise entries with where NEW or READ are NULL // We need to check for NULL explicitly otherwise entries with where READ is NULL // may not match either the query or its negation. String selection = String.format( "(%s IS NOT NULL AND %s = 1 AND (%s = ? OR %s = ?)) OR " + "(%s IS NOT NULL AND %s = 0)", Calls.NEW, Calls.NEW, Calls.TYPE, Calls.TYPE, Calls.IS_READ, Calls.IS_READ); final String[] selectionArgs; // We consider the calls that are not yet consumed (i.e. IS_READ = 0) as "new". String selection = String.format("%s IS NOT NULL AND %s = 0", Calls.IS_READ, Calls.IS_READ); String[] selectionArgs = null; if (!isNew) { // Negate the query. selection = String.format("NOT (%s)", selection); Loading @@ -165,13 +165,6 @@ import javax.annotation.concurrent.GuardedBy; // Add a clause to fetch only items of type voicemail. selection = String.format("(%s) AND (%s = ?)", selection, Calls.TYPE); selectionArgs = new String[]{ Integer.toString(Calls.MISSED_TYPE), Integer.toString(Calls.VOICEMAIL_TYPE), Integer.toString(Calls.VOICEMAIL_TYPE), }; } else { selectionArgs = new String[]{ Integer.toString(Calls.MISSED_TYPE), Integer.toString(Calls.VOICEMAIL_TYPE), }; } Loading Loading @@ -199,6 +192,21 @@ import javax.annotation.concurrent.GuardedBy; values, where.toString(), null); } /** Updates all missed calls to mark them as read. */ public void markMissedCallsAsRead() { // Mark all "new" calls as not new anymore. StringBuilder where = new StringBuilder(); where.append(Calls.IS_READ).append(" = 0"); where.append(" AND "); where.append(Calls.TYPE).append(" = ").append(Calls.MISSED_TYPE); ContentValues values = new ContentValues(1); values.put(Calls.IS_READ, "1"); startUpdate(UPDATE_MARK_MISSED_CALL_AS_READ_TOKEN, null, Calls.CONTENT_URI, values, where.toString(), null); } /** * Invalidate the current list of calls. * <p> Loading