From ff40f157168bc54fec724350387670876ae382b1 Mon Sep 17 00:00:00 2001 From: Christine Chen Date: Mon, 14 Oct 2013 17:46:58 -0700 Subject: Clears notification when there is no call. Bug: 11083320 Change-Id: I05efd985114a78d87098a46b1c4c33ad5bcc5b94 --- src/com/android/incallui/InCallApp.java | 2 +- src/com/android/incallui/InCallPresenter.java | 15 ++++++++++++++- src/com/android/incallui/StatusBarNotifier.java | 12 ++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/com/android/incallui/InCallApp.java b/src/com/android/incallui/InCallApp.java index dcc78481..7d276bce 100644 --- a/src/com/android/incallui/InCallApp.java +++ b/src/com/android/incallui/InCallApp.java @@ -63,7 +63,7 @@ public class InCallApp extends Application { // TODO: Commands of this nature should exist in the CallList or a // CallController class that has access to CallCommandClient and // CallList. - InCallPresenter.getInstance().hangUpOngoingCall(); + InCallPresenter.getInstance().hangUpOngoingCall(context); } } } diff --git a/src/com/android/incallui/InCallPresenter.java b/src/com/android/incallui/InCallPresenter.java index 2fbbf34b..5830e726 100644 --- a/src/com/android/incallui/InCallPresenter.java +++ b/src/com/android/incallui/InCallPresenter.java @@ -16,6 +16,7 @@ package com.android.incallui; +import com.android.incallui.service.PhoneNumberService; import com.google.android.collect.Sets; import com.google.common.base.Preconditions; @@ -211,6 +212,9 @@ public class InCallPresenter implements CallList.Listener { */ @Override public void onCallListChange(CallList callList) { + if (callList == null) { + return; + } InCallState newState = getPotentialStateFromCallList(callList); newState = startOrFinishUi(newState); @@ -270,8 +274,12 @@ public class InCallPresenter implements CallList.Listener { * Given the call list, return the state in which the in-call screen should be. */ public static InCallState getPotentialStateFromCallList(CallList callList) { + InCallState newState = InCallState.NO_CALLS; + if (callList == null) { + return newState; + } if (callList.getIncomingCall() != null) { newState = InCallState.INCOMING; } else if (callList.getOutgoingCall() != null) { @@ -321,10 +329,15 @@ public class InCallPresenter implements CallList.Listener { /** * Hangs up any active or outgoing calls. */ - public void hangUpOngoingCall() { + public void hangUpOngoingCall(Context context) { // By the time we receive this intent, we could be shut down and call list // could be null. Bail in those cases. if (mCallList == null) { + if (mStatusBarNotifier == null) { + // The In Call UI has crashed but the notification still stayed up. We should not + // come to this stage. + StatusBarNotifier.clearInCallNotification(context); + } return; } diff --git a/src/com/android/incallui/StatusBarNotifier.java b/src/com/android/incallui/StatusBarNotifier.java index 1690c549..459921f1 100644 --- a/src/com/android/incallui/StatusBarNotifier.java +++ b/src/com/android/incallui/StatusBarNotifier.java @@ -140,6 +140,15 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener { mIsShowingNotification = false; } + /* package */ static void clearInCallNotification(Context backupContext) { + Log.i(StatusBarNotifier.class.getSimpleName(), + "Something terrible happened. Clear all InCall notifications"); + + NotificationManager notificationManager = + (NotificationManager) backupContext.getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.cancel(IN_CALL_NOTIFICATION); + } + /** * Helper method for updateInCallNotification() and * updateNotificationAndLaunchIncomingCallUi(): Update the phone app's @@ -390,6 +399,9 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener { * Gets the most relevant call to display in the notification. */ private Call getCallToShow(CallList callList) { + if (callList == null) { + return null; + } Call call = callList.getIncomingCall(); if (call == null) { call = callList.getOutgoingCall(); -- cgit v1.2.3