Loading src/com/android/dialer/calllog/CallLogAdapter.java +5 −1 Original line number Diff line number Diff line Loading @@ -164,6 +164,9 @@ public class CallLogAdapter extends GroupingListAdapter mCurrentlyExpandedPosition = RecyclerView.NO_POSITION; mCurrentlyExpandedRowId = NO_EXPANDED_LIST_ITEM; } else { if (viewHolder.callType == CallLog.Calls.MISSED_TYPE) { CallLogAsyncTaskUtil.markCallAsRead(mContext, viewHolder.callIds); } expandViewHolderActions(viewHolder); } Loading Loading @@ -482,7 +485,8 @@ public class CallLogAdapter extends GroupingListAdapter details.features = getCallFeatures(c, count); details.geocode = c.getString(CallLogQuery.GEOCODED_LOCATION); details.transcription = c.getString(CallLogQuery.TRANSCRIPTION); if (details.callTypes[0] == CallLog.Calls.VOICEMAIL_TYPE) { if (details.callTypes[0] == CallLog.Calls.VOICEMAIL_TYPE || details.callTypes[0] == CallLog.Calls.MISSED_TYPE) { details.isRead = c.getInt(CallLogQuery.IS_READ) == 1; } Loading src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java +35 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.text.TextUtils; import android.util.Log; import com.android.contacts.common.GeoUtil; import com.android.contacts.common.util.PermissionsUtil; import com.android.dialer.DialtactsActivity; import com.android.dialer.PhoneCallDetails; import com.android.dialer.util.AppCompatConstants; Loading @@ -51,6 +52,7 @@ public class CallLogAsyncTaskUtil { DELETE_CALL, DELETE_BLOCKED_CALL, MARK_VOICEMAIL_READ, MARK_CALL_READ, GET_CALL_DETAILS, } Loading Loading @@ -379,6 +381,39 @@ public class CallLogAsyncTaskUtil { }); } public static void markCallAsRead(final Context context, final long[] callIds) { if (!PermissionsUtil.hasPhonePermissions(context)) { return; } if (sAsyncTaskExecutor == null) { initTaskExecutor(); } sAsyncTaskExecutor.submit(Tasks.MARK_CALL_READ, new AsyncTask<Void, Void, Void>() { @Override public Void doInBackground(Void... params) { StringBuilder where = new StringBuilder(); where.append(CallLog.Calls.TYPE).append(" = ").append(CallLog.Calls.MISSED_TYPE); where.append(" AND "); Long[] callIdLongs = new Long[callIds.length]; for (int i = 0; i < callIds.length; i++) { callIdLongs[i] = callIds[i]; } where.append(CallLog.Calls._ID).append( " IN (" + TextUtils.join(",", callIdLongs) + ")"); ContentValues values = new ContentValues(1); values.put(CallLog.Calls.IS_READ, "1"); context.getContentResolver().update( CallLog.Calls.CONTENT_URI, values, where.toString(), null); ((DialtactsActivity) context).updateTabUnreadCounts(); return null; } }); } @VisibleForTesting public static void resetForTest() { sAsyncTaskExecutor = null; Loading src/com/android/dialer/calllog/CallLogFragment.java +7 −6 Original line number Diff line number Diff line Loading @@ -289,6 +289,9 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis @Override public void onVoicemailUnreadCountFetched(Cursor cursor) {} @Override public void onMissedCallsUnreadCountFetched(Cursor cursor) {} @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { View view = inflater.inflate(R.layout.call_log_fragment, container, false); Loading Loading @@ -403,7 +406,6 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis @Override public void fetchCalls() { mCallLogQueryHandler.fetchCalls(mCallTypeFilter, mDateLimit); if (mVoicemailPlaybackPresenter != null) { ((ListsFragment) getParentFragment()).updateTabUnreadCounts(); } Loading Loading @@ -472,7 +474,7 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis fetchCalls(); mCallLogQueryHandler.fetchVoicemailStatus(); mCallLogQueryHandler.fetchMissedCallsUnreadCount(); updateOnTransition(true /* onEntry */); mRefreshDataRequired = false; } else { Loading @@ -496,12 +498,11 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis // On either of the transitions we update the missed call and voicemail notifications. // While exiting we additionally consume all missed calls (by marking them as read). mCallLogQueryHandler.markNewCallsAsOld(); if (!onEntry) { mCallLogQueryHandler.markMissedCallsAsRead(); } if (mCallTypeFilter == Calls.VOICEMAIL_TYPE) { CallLogNotificationsHelper.updateVoicemailNotifications(getActivity()); } else { } else if (((ListsFragment) getParentFragment()).getCurrentTabIndex() == ListsFragment.TAB_INDEX_HISTORY && !onEntry) { mCallLogQueryHandler.markMissedCallsAsRead(); CallLogNotificationsHelper.removeMissedCallNotifications(getActivity()); } } Loading src/com/android/dialer/calllog/CallLogQueryHandler.java +37 −6 Original line number Diff line number Diff line Loading @@ -62,6 +62,8 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { private static final int QUERY_VOICEMAIL_STATUS_TOKEN = 57; /** The token for the query to fetch the number of unread voicemails. */ private static final int QUERY_VOICEMAIL_UNREAD_COUNT_TOKEN = 58; /** The token for the query to fetch the number of missed calls. */ private static final int QUERY_MISSED_CALLS_UNREAD_COUNT_TOKEN = 59; private final int mLogLimit; Loading Loading @@ -225,19 +227,25 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { if (!PermissionsUtil.hasPhonePermissions(mContext)) { return; } // 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); getUnreadMissedCallsQuery(), null); } /** Fetch all missed calls received since last time the tab was opened. */ public void fetchMissedCallsUnreadCount() { if (!PermissionsUtil.hasPhonePermissions(mContext)) { return; } startQuery(QUERY_MISSED_CALLS_UNREAD_COUNT_TOKEN, null, Calls.CONTENT_URI, new String[]{Calls._ID}, getUnreadMissedCallsQuery(), null, null); } @Override protected synchronized void onNotNullableQueryComplete(int token, Object cookie, Cursor cursor) { Loading @@ -253,6 +261,8 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { updateVoicemailStatus(cursor); } else if (token == QUERY_VOICEMAIL_UNREAD_COUNT_TOKEN) { updateVoicemailUnreadCount(cursor); } else if (token == QUERY_MISSED_CALLS_UNREAD_COUNT_TOKEN) { updateMissedCallsUnreadCount(cursor); } else { Log.w(TAG, "Unknown query completed: ignoring: " + token); } Loading @@ -276,6 +286,17 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { } /** * @return Query string to get all unread missed calls. */ private String getUnreadMissedCallsQuery() { StringBuilder where = new StringBuilder(); where.append(Calls.IS_READ).append(" = 0"); where.append(" AND "); where.append(Calls.TYPE).append(" = ").append(Calls.MISSED_TYPE); return where.toString(); } private void updateVoicemailStatus(Cursor statusCursor) { final Listener listener = mListener.get(); if (listener != null) { Loading @@ -290,6 +311,13 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { } } private void updateMissedCallsUnreadCount(Cursor statusCursor) { final Listener listener = mListener.get(); if (listener != null) { listener.onMissedCallsUnreadCountFetched(statusCursor); } } /** Listener to completion of various queries. */ public interface Listener { /** Called when {@link CallLogQueryHandler#fetchVoicemailStatus()} completes. */ Loading @@ -298,6 +326,9 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { /** Called when {@link CallLogQueryHandler#fetchVoicemailUnreadCount()} completes. */ void onVoicemailUnreadCountFetched(Cursor cursor); /** Called when {@link CallLogQueryHandler#fetchMissedCallsUnreadCount()} completes. */ void onMissedCallsUnreadCountFetched(Cursor cursor); /** * Called when {@link CallLogQueryHandler#fetchCalls(int)} complete. * Returns true if takes ownership of cursor. Loading src/com/android/dialer/list/ListsFragment.java +23 −2 Original line number Diff line number Diff line Loading @@ -191,6 +191,7 @@ public class ListsFragment extends Fragment mCallLogQueryHandler = new CallLogQueryHandler(getActivity(), getActivity().getContentResolver(), this); mCallLogQueryHandler.fetchVoicemailStatus(); mCallLogQueryHandler.fetchMissedCallsUnreadCount(); Trace.endSection(); } Loading Loading @@ -345,6 +346,23 @@ public class ListsFragment extends Fragment mViewPagerTabs.updateTab(TAB_INDEX_VOICEMAIL); } @Override public void onMissedCallsUnreadCountFetched(Cursor cursor) { if (getActivity() == null || getActivity().isFinishing() || cursor == null) { return; } int count = 0; try { count = cursor.getCount(); } finally { cursor.close(); } mViewPagerTabs.setUnreadCount(count, TAB_INDEX_HISTORY); mViewPagerTabs.updateTab(TAB_INDEX_HISTORY); } @Override public boolean onCallsFetched(Cursor statusCursor) { // Return false; did not take ownership of cursor Loading @@ -360,10 +378,13 @@ public class ListsFragment extends Fragment * expands a voicemail in the call log. */ public void updateTabUnreadCounts() { if (mHasActiveVoicemailProvider && mCallLogQueryHandler != null) { if (mCallLogQueryHandler != null) { mCallLogQueryHandler.fetchMissedCallsUnreadCount(); if (mHasActiveVoicemailProvider) { mCallLogQueryHandler.fetchVoicemailUnreadCount(); } } } public void showRemoveView(boolean show) { mRemoveViewContent.setVisibility(show ? View.VISIBLE : View.GONE); Loading Loading
src/com/android/dialer/calllog/CallLogAdapter.java +5 −1 Original line number Diff line number Diff line Loading @@ -164,6 +164,9 @@ public class CallLogAdapter extends GroupingListAdapter mCurrentlyExpandedPosition = RecyclerView.NO_POSITION; mCurrentlyExpandedRowId = NO_EXPANDED_LIST_ITEM; } else { if (viewHolder.callType == CallLog.Calls.MISSED_TYPE) { CallLogAsyncTaskUtil.markCallAsRead(mContext, viewHolder.callIds); } expandViewHolderActions(viewHolder); } Loading Loading @@ -482,7 +485,8 @@ public class CallLogAdapter extends GroupingListAdapter details.features = getCallFeatures(c, count); details.geocode = c.getString(CallLogQuery.GEOCODED_LOCATION); details.transcription = c.getString(CallLogQuery.TRANSCRIPTION); if (details.callTypes[0] == CallLog.Calls.VOICEMAIL_TYPE) { if (details.callTypes[0] == CallLog.Calls.VOICEMAIL_TYPE || details.callTypes[0] == CallLog.Calls.MISSED_TYPE) { details.isRead = c.getInt(CallLogQuery.IS_READ) == 1; } Loading
src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java +35 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.text.TextUtils; import android.util.Log; import com.android.contacts.common.GeoUtil; import com.android.contacts.common.util.PermissionsUtil; import com.android.dialer.DialtactsActivity; import com.android.dialer.PhoneCallDetails; import com.android.dialer.util.AppCompatConstants; Loading @@ -51,6 +52,7 @@ public class CallLogAsyncTaskUtil { DELETE_CALL, DELETE_BLOCKED_CALL, MARK_VOICEMAIL_READ, MARK_CALL_READ, GET_CALL_DETAILS, } Loading Loading @@ -379,6 +381,39 @@ public class CallLogAsyncTaskUtil { }); } public static void markCallAsRead(final Context context, final long[] callIds) { if (!PermissionsUtil.hasPhonePermissions(context)) { return; } if (sAsyncTaskExecutor == null) { initTaskExecutor(); } sAsyncTaskExecutor.submit(Tasks.MARK_CALL_READ, new AsyncTask<Void, Void, Void>() { @Override public Void doInBackground(Void... params) { StringBuilder where = new StringBuilder(); where.append(CallLog.Calls.TYPE).append(" = ").append(CallLog.Calls.MISSED_TYPE); where.append(" AND "); Long[] callIdLongs = new Long[callIds.length]; for (int i = 0; i < callIds.length; i++) { callIdLongs[i] = callIds[i]; } where.append(CallLog.Calls._ID).append( " IN (" + TextUtils.join(",", callIdLongs) + ")"); ContentValues values = new ContentValues(1); values.put(CallLog.Calls.IS_READ, "1"); context.getContentResolver().update( CallLog.Calls.CONTENT_URI, values, where.toString(), null); ((DialtactsActivity) context).updateTabUnreadCounts(); return null; } }); } @VisibleForTesting public static void resetForTest() { sAsyncTaskExecutor = null; Loading
src/com/android/dialer/calllog/CallLogFragment.java +7 −6 Original line number Diff line number Diff line Loading @@ -289,6 +289,9 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis @Override public void onVoicemailUnreadCountFetched(Cursor cursor) {} @Override public void onMissedCallsUnreadCountFetched(Cursor cursor) {} @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { View view = inflater.inflate(R.layout.call_log_fragment, container, false); Loading Loading @@ -403,7 +406,6 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis @Override public void fetchCalls() { mCallLogQueryHandler.fetchCalls(mCallTypeFilter, mDateLimit); if (mVoicemailPlaybackPresenter != null) { ((ListsFragment) getParentFragment()).updateTabUnreadCounts(); } Loading Loading @@ -472,7 +474,7 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis fetchCalls(); mCallLogQueryHandler.fetchVoicemailStatus(); mCallLogQueryHandler.fetchMissedCallsUnreadCount(); updateOnTransition(true /* onEntry */); mRefreshDataRequired = false; } else { Loading @@ -496,12 +498,11 @@ public class CallLogFragment extends Fragment implements CallLogQueryHandler.Lis // On either of the transitions we update the missed call and voicemail notifications. // While exiting we additionally consume all missed calls (by marking them as read). mCallLogQueryHandler.markNewCallsAsOld(); if (!onEntry) { mCallLogQueryHandler.markMissedCallsAsRead(); } if (mCallTypeFilter == Calls.VOICEMAIL_TYPE) { CallLogNotificationsHelper.updateVoicemailNotifications(getActivity()); } else { } else if (((ListsFragment) getParentFragment()).getCurrentTabIndex() == ListsFragment.TAB_INDEX_HISTORY && !onEntry) { mCallLogQueryHandler.markMissedCallsAsRead(); CallLogNotificationsHelper.removeMissedCallNotifications(getActivity()); } } Loading
src/com/android/dialer/calllog/CallLogQueryHandler.java +37 −6 Original line number Diff line number Diff line Loading @@ -62,6 +62,8 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { private static final int QUERY_VOICEMAIL_STATUS_TOKEN = 57; /** The token for the query to fetch the number of unread voicemails. */ private static final int QUERY_VOICEMAIL_UNREAD_COUNT_TOKEN = 58; /** The token for the query to fetch the number of missed calls. */ private static final int QUERY_MISSED_CALLS_UNREAD_COUNT_TOKEN = 59; private final int mLogLimit; Loading Loading @@ -225,19 +227,25 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { if (!PermissionsUtil.hasPhonePermissions(mContext)) { return; } // 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); getUnreadMissedCallsQuery(), null); } /** Fetch all missed calls received since last time the tab was opened. */ public void fetchMissedCallsUnreadCount() { if (!PermissionsUtil.hasPhonePermissions(mContext)) { return; } startQuery(QUERY_MISSED_CALLS_UNREAD_COUNT_TOKEN, null, Calls.CONTENT_URI, new String[]{Calls._ID}, getUnreadMissedCallsQuery(), null, null); } @Override protected synchronized void onNotNullableQueryComplete(int token, Object cookie, Cursor cursor) { Loading @@ -253,6 +261,8 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { updateVoicemailStatus(cursor); } else if (token == QUERY_VOICEMAIL_UNREAD_COUNT_TOKEN) { updateVoicemailUnreadCount(cursor); } else if (token == QUERY_MISSED_CALLS_UNREAD_COUNT_TOKEN) { updateMissedCallsUnreadCount(cursor); } else { Log.w(TAG, "Unknown query completed: ignoring: " + token); } Loading @@ -276,6 +286,17 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { } /** * @return Query string to get all unread missed calls. */ private String getUnreadMissedCallsQuery() { StringBuilder where = new StringBuilder(); where.append(Calls.IS_READ).append(" = 0"); where.append(" AND "); where.append(Calls.TYPE).append(" = ").append(Calls.MISSED_TYPE); return where.toString(); } private void updateVoicemailStatus(Cursor statusCursor) { final Listener listener = mListener.get(); if (listener != null) { Loading @@ -290,6 +311,13 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { } } private void updateMissedCallsUnreadCount(Cursor statusCursor) { final Listener listener = mListener.get(); if (listener != null) { listener.onMissedCallsUnreadCountFetched(statusCursor); } } /** Listener to completion of various queries. */ public interface Listener { /** Called when {@link CallLogQueryHandler#fetchVoicemailStatus()} completes. */ Loading @@ -298,6 +326,9 @@ public class CallLogQueryHandler extends NoNullCursorAsyncQueryHandler { /** Called when {@link CallLogQueryHandler#fetchVoicemailUnreadCount()} completes. */ void onVoicemailUnreadCountFetched(Cursor cursor); /** Called when {@link CallLogQueryHandler#fetchMissedCallsUnreadCount()} completes. */ void onMissedCallsUnreadCountFetched(Cursor cursor); /** * Called when {@link CallLogQueryHandler#fetchCalls(int)} complete. * Returns true if takes ownership of cursor. Loading
src/com/android/dialer/list/ListsFragment.java +23 −2 Original line number Diff line number Diff line Loading @@ -191,6 +191,7 @@ public class ListsFragment extends Fragment mCallLogQueryHandler = new CallLogQueryHandler(getActivity(), getActivity().getContentResolver(), this); mCallLogQueryHandler.fetchVoicemailStatus(); mCallLogQueryHandler.fetchMissedCallsUnreadCount(); Trace.endSection(); } Loading Loading @@ -345,6 +346,23 @@ public class ListsFragment extends Fragment mViewPagerTabs.updateTab(TAB_INDEX_VOICEMAIL); } @Override public void onMissedCallsUnreadCountFetched(Cursor cursor) { if (getActivity() == null || getActivity().isFinishing() || cursor == null) { return; } int count = 0; try { count = cursor.getCount(); } finally { cursor.close(); } mViewPagerTabs.setUnreadCount(count, TAB_INDEX_HISTORY); mViewPagerTabs.updateTab(TAB_INDEX_HISTORY); } @Override public boolean onCallsFetched(Cursor statusCursor) { // Return false; did not take ownership of cursor Loading @@ -360,10 +378,13 @@ public class ListsFragment extends Fragment * expands a voicemail in the call log. */ public void updateTabUnreadCounts() { if (mHasActiveVoicemailProvider && mCallLogQueryHandler != null) { if (mCallLogQueryHandler != null) { mCallLogQueryHandler.fetchMissedCallsUnreadCount(); if (mHasActiveVoicemailProvider) { mCallLogQueryHandler.fetchVoicemailUnreadCount(); } } } public void showRemoveView(boolean show) { mRemoveViewContent.setVisibility(show ? View.VISIBLE : View.GONE); Loading