From b2d5e7caf51de7805b98295e97c37a91792cbddf Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Mon, 12 Feb 2018 11:07:47 -0800 Subject: Clicking on a missed call in the call log no longer crashes the app. Bug: 72956783 Test: DialtactsActivityIntegrationTest PiperOrigin-RevId: 185404033 Change-Id: I486f7b1a6739bf49c6f19bba82227dd4d9794e1f --- java/com/android/dialer/app/calllog/CallLogAdapter.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'java/com/android/dialer/app/calllog') diff --git a/java/com/android/dialer/app/calllog/CallLogAdapter.java b/java/com/android/dialer/app/calllog/CallLogAdapter.java index 51df70219..baca590b5 100644 --- a/java/com/android/dialer/app/calllog/CallLogAdapter.java +++ b/java/com/android/dialer/app/calllog/CallLogAdapter.java @@ -54,6 +54,7 @@ import android.view.ViewGroup; import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.compat.PhoneNumberUtilsCompat; import com.android.contacts.common.preference.ContactsPreferences; +import com.android.dialer.app.DialtactsActivity; import com.android.dialer.app.R; import com.android.dialer.app.calllog.CallLogFragment.CallLogFragmentListener; import com.android.dialer.app.calllog.CallLogGroupBuilder.GroupCreator; @@ -381,9 +382,7 @@ public class CallLogAdapter extends GroupingListAdapter if (viewHolder.callType == CallLog.Calls.MISSED_TYPE) { CallLogAsyncTaskUtil.markCallAsRead(activity, viewHolder.callIds); if (activityType == ACTIVITY_TYPE_DIALTACTS) { - if (v.getContext() instanceof CallLogFragmentListener) { - ((CallLogFragmentListener) v.getContext()).updateTabUnreadCounts(); - } else if (v.getContext() instanceof MainActivityPeer.PeerSupplier) { + if (v.getContext() instanceof MainActivityPeer.PeerSupplier) { // This is really bad, but we must do this to prevent a dependency cycle, enforce // best practices in new code, and avoid refactoring DialtactsActivity. ((FragmentUtilListener) @@ -391,8 +390,7 @@ public class CallLogAdapter extends GroupingListAdapter .getImpl(CallLogFragmentListener.class) .updateTabUnreadCounts(); } else { - throw Assert.createIllegalStateFailException( - "View parent does not implement CallLogFragmentListener"); + ((DialtactsActivity) v.getContext()).updateTabUnreadCounts(); } } } -- cgit v1.2.3 From 39009b4ad73d5017295b30fb18a77224195f06af Mon Sep 17 00:00:00 2001 From: zachh Date: Mon, 12 Feb 2018 16:49:00 -0800 Subject: Mark calls as read in new call log. Playing with the existing app, the missed call becomes unbolded when: 1) Expanding the row. The closest analog of this is in the new UI is opening the bottom sheet, I've done that. 2) Swiping away from the call history tab. This can't be done in NewCallLogFragment because it doesn't know if the user is selected a new tab or pressed Home. So, I implemented this in NewMainActivityPeer. 3) After viewing the call log for 3(ish) seconds and leaving the activity pressing Home/Back. This is best done in NewCallLogFragment#onResume since MainActivity doesn't always know when the fragment is being displayed (it could be done after the user comes back to the app after pressing Home for example). Note that the notification is also removed in all of these cases. Also note that dismissing the notification makes the call unbolded (but this case already appears to be handled via the system call log content observer). Also, as part of writing tests for this, I made TestCallLogProvider more realistic. Bug: 70989622 Test: manual PiperOrigin-RevId: 185457438 Change-Id: Ib360d3bc73083bd1a018ed98e2b7d9a69fb7fafb --- .../app/calllog/CallLogNotificationsService.java | 13 ++--- .../dialer/app/calllog/MissedCallNotifier.java | 59 +++++++--------------- 2 files changed, 20 insertions(+), 52 deletions(-) (limited to 'java/com/android/dialer/app/calllog') diff --git a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java index 5949141f1..10e30ff72 100644 --- a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java +++ b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java @@ -31,6 +31,7 @@ import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutor.Worker; import com.android.dialer.common.concurrent.DialerExecutorComponent; +import com.android.dialer.notification.missedcalls.MissedCallNotificationCanceller; import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.util.PermissionsUtil; @@ -87,14 +88,6 @@ public class CallLogNotificationsService extends IntentService { context.startService(serviceIntent); } - public static void markSingleNewVoicemailAsOld(Context context, @Nullable Uri voicemailUri) { - LogUtil.enterBlock("CallLogNotificationsService.markSingleNewVoicemailAsOld"); - Intent serviceIntent = new Intent(context, CallLogNotificationsService.class); - serviceIntent.setAction(CallLogNotificationsService.ACTION_MARK_SINGLE_NEW_VOICEMAIL_AS_OLD); - serviceIntent.setData(voicemailUri); - context.startService(serviceIntent); - } - public static void cancelAllMissedCalls(Context context) { LogUtil.enterBlock("CallLogNotificationsService.cancelAllMissedCalls"); DialerExecutorComponent.get(context) @@ -175,7 +168,7 @@ public class CallLogNotificationsService extends IntentService { case ACTION_CANCEL_SINGLE_MISSED_CALL: Uri callUri = intent.getData(); CallLogNotificationsQueryHelper.markSingleMissedCallInCallLogAsRead(this, callUri); - MissedCallNotifier.cancelSingleMissedCallNotification(this, callUri); + MissedCallNotificationCanceller.cancelSingle(this, callUri); TelecomUtil.cancelMissedCallsNotification(this); break; case ACTION_CALL_BACK_FROM_MISSED_CALL_NOTIFICATION: @@ -196,7 +189,7 @@ public class CallLogNotificationsService extends IntentService { LogUtil.enterBlock("CallLogNotificationsService.cancelAllMissedCallsBackground"); Assert.isWorkerThread(); CallLogNotificationsQueryHelper.markAllMissedCallsInCallLogAsRead(context); - MissedCallNotifier.cancelAllMissedCallNotifications(context); + MissedCallNotificationCanceller.cancelAll(context); TelecomUtil.cancelMissedCallsNotification(context); } diff --git a/java/com/android/dialer/app/calllog/MissedCallNotifier.java b/java/com/android/dialer/app/calllog/MissedCallNotifier.java index 417f8f0f9..14bbdfa56 100644 --- a/java/com/android/dialer/app/calllog/MissedCallNotifier.java +++ b/java/com/android/dialer/app/calllog/MissedCallNotifier.java @@ -58,7 +58,9 @@ import com.android.dialer.duo.DuoConstants; import com.android.dialer.enrichedcall.FuzzyPhoneNumberMatcher; import com.android.dialer.notification.DialerNotificationManager; import com.android.dialer.notification.NotificationChannelId; -import com.android.dialer.notification.NotificationManagerUtils; +import com.android.dialer.notification.missedcalls.MissedCallConstants; +import com.android.dialer.notification.missedcalls.MissedCallNotificationCanceller; +import com.android.dialer.notification.missedcalls.MissedCallNotificationTags; import com.android.dialer.phonenumbercache.ContactInfo; import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.precall.PreCall; @@ -71,18 +73,6 @@ import java.util.Set; /** Creates a notification for calls that the user missed (neither answered nor rejected). */ public class MissedCallNotifier implements Worker, Void> { - /** Prefix used to generate a unique tag for each missed call notification. */ - private static final String NOTIFICATION_TAG_PREFIX = "MissedCall_"; - /** Common ID for all missed call notifications. */ - private static final int NOTIFICATION_ID = 1; - /** Tag for the group summary notification. */ - private static final String GROUP_SUMMARY_NOTIFICATION_TAG = "GroupSummary_MissedCall"; - /** - * Key used to associate all missed call notifications and the summary as belonging to a single - * group. - */ - private static final String GROUP_KEY = "MissedCallGroup"; - private final Context context; private final CallLogNotificationsQueryHelper callLogNotificationsQueryHelper; @@ -126,7 +116,7 @@ public class MissedCallNotifier implements Worker, Void> { if ((newCalls != null && newCalls.isEmpty()) || count == 0) { // No calls to notify about: clear the notification. CallLogNotificationsQueryHelper.markAllMissedCallsInCallLogAsRead(context); - cancelAllMissedCallNotifications(context); + MissedCallNotificationCanceller.cancelAll(context); return; } @@ -226,7 +216,10 @@ public class MissedCallNotifier implements Worker, Void> { LogUtil.i("MissedCallNotifier.updateMissedCallNotification", "adding missed call notification"); DialerNotificationManager.notify( - context, GROUP_SUMMARY_NOTIFICATION_TAG, NOTIFICATION_ID, notification); + context, + MissedCallConstants.GROUP_SUMMARY_NOTIFICATION_TAG, + MissedCallConstants.NOTIFICATION_ID, + notification); if (useCallList) { // Do not repost active notifications to prevent erasing post call notes. @@ -240,7 +233,10 @@ public class MissedCallNotifier implements Worker, Void> { String callTag = getNotificationTagForCall(call); if (!activeTags.contains(callTag)) { DialerNotificationManager.notify( - context, callTag, NOTIFICATION_ID, getNotificationForCall(call, null)); + context, + callTag, + MissedCallConstants.NOTIFICATION_ID, + getNotificationForCall(call, null)); } } } @@ -286,29 +282,8 @@ public class MissedCallNotifier implements Worker, Void> { } } - public static void cancelAllMissedCallNotifications(@NonNull Context context) { - NotificationManagerUtils.cancelAllInGroup(context, GROUP_KEY); - } - - public static void cancelSingleMissedCallNotification( - @NonNull Context context, @Nullable Uri callUri) { - if (callUri == null) { - LogUtil.e( - "MissedCallNotifier.cancelSingleMissedCallNotification", - "unable to cancel notification, uri is null"); - return; - } - // This will also dismiss the group summary if there are no more missed call notifications. - DialerNotificationManager.cancel( - context, getNotificationTagForCallUri(callUri), NOTIFICATION_ID); - } - private static String getNotificationTagForCall(@NonNull NewCall call) { - return getNotificationTagForCallUri(call.callsUri); - } - - private static String getNotificationTagForCallUri(@NonNull Uri callUri) { - return NOTIFICATION_TAG_PREFIX + callUri; + return MissedCallNotificationTags.getNotificationTagForCallUri(call.callsUri); } @WorkerThread @@ -324,7 +299,7 @@ public class MissedCallNotifier implements Worker, Void> { DialerNotificationManager.notify( context, getNotificationTagForCall(call), - NOTIFICATION_ID, + MissedCallConstants.NOTIFICATION_ID, getNotificationForCall(call, note)); return; } @@ -408,7 +383,7 @@ public class MissedCallNotifier implements Worker, Void> { private Notification.Builder createNotificationBuilder() { return new Notification.Builder(context) - .setGroup(GROUP_KEY) + .setGroup(MissedCallConstants.GROUP_KEY) .setSmallIcon(android.R.drawable.stat_notify_missed_call) .setColor(context.getResources().getColor(R.color.dialer_theme_color, null)) .setAutoCancel(true) @@ -437,7 +412,7 @@ public class MissedCallNotifier implements Worker, Void> { public void callBackFromMissedCall(String number, Uri callUri) { closeSystemDialogs(context); CallLogNotificationsQueryHelper.markSingleMissedCallInCallLogAsRead(context, callUri); - cancelSingleMissedCallNotification(context, callUri); + MissedCallNotificationCanceller.cancelSingle(context, callUri); DialerUtils.startActivityWithErrorToast( context, PreCall.getIntent( @@ -450,7 +425,7 @@ public class MissedCallNotifier implements Worker, Void> { public void sendSmsFromMissedCall(String number, Uri callUri) { closeSystemDialogs(context); CallLogNotificationsQueryHelper.markSingleMissedCallInCallLogAsRead(context, callUri); - cancelSingleMissedCallNotification(context, callUri); + MissedCallNotificationCanceller.cancelSingle(context, callUri); DialerUtils.startActivityWithErrorToast( context, IntentUtil.getSendSmsIntent(number).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } -- cgit v1.2.3