Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.incallui; |
| 18 | |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 19 | import static android.telecom.Call.Details.PROPERTY_HIGH_DEF_AUDIO; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 20 | import static com.android.contacts.common.compat.CallCompat.Details.PROPERTY_ENTERPRISE_CALL; |
| 21 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ACCEPT_VIDEO_UPGRADE_REQUEST; |
| 22 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ANSWER_VIDEO_INCOMING_CALL; |
| 23 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ANSWER_VOICE_INCOMING_CALL; |
| 24 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_DECLINE_INCOMING_CALL; |
| 25 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_DECLINE_VIDEO_UPGRADE_REQUEST; |
| 26 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_HANG_UP_ONGOING_CALL; |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 27 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_TURN_OFF_SPEAKER; |
| 28 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_TURN_ON_SPEAKER; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 29 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 30 | import android.Manifest; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 31 | import android.app.Notification; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 32 | import android.app.PendingIntent; |
| 33 | import android.content.Context; |
| 34 | import android.content.Intent; |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 35 | import android.content.res.Resources; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 36 | import android.graphics.Bitmap; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 37 | import android.graphics.drawable.BitmapDrawable; |
| 38 | import android.graphics.drawable.Drawable; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 39 | import android.graphics.drawable.Icon; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 40 | import android.media.AudioAttributes; |
| 41 | import android.net.Uri; |
| 42 | import android.os.Build.VERSION; |
| 43 | import android.os.Build.VERSION_CODES; |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 44 | import android.os.Trace; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 45 | import android.support.annotation.ColorRes; |
| 46 | import android.support.annotation.NonNull; |
| 47 | import android.support.annotation.Nullable; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 48 | import android.support.annotation.RequiresPermission; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 49 | import android.support.annotation.StringRes; |
| 50 | import android.support.annotation.VisibleForTesting; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 51 | import android.support.v4.os.BuildCompat; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 52 | import android.telecom.Call.Details; |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 53 | import android.telecom.CallAudioState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 54 | import android.telecom.PhoneAccount; |
| 55 | import android.telecom.TelecomManager; |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 56 | import android.telecom.VideoProfile; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 57 | import android.text.BidiFormatter; |
| 58 | import android.text.Spannable; |
| 59 | import android.text.SpannableString; |
| 60 | import android.text.TextDirectionHeuristics; |
| 61 | import android.text.TextUtils; |
| 62 | import android.text.style.ForegroundColorSpan; |
| 63 | import com.android.contacts.common.ContactsUtils; |
| 64 | import com.android.contacts.common.ContactsUtils.UserType; |
| 65 | import com.android.contacts.common.preference.ContactsPreferences; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 66 | import com.android.contacts.common.util.ContactDisplayUtils; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 67 | import com.android.dialer.common.Assert; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 68 | import com.android.dialer.common.LogUtil; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 69 | import com.android.dialer.configprovider.ConfigProviderBindings; |
| 70 | import com.android.dialer.contactphoto.BitmapUtil; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 71 | import com.android.dialer.enrichedcall.EnrichedCallManager; |
| 72 | import com.android.dialer.enrichedcall.Session; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 73 | import com.android.dialer.lettertile.LetterTileDrawable; |
| 74 | import com.android.dialer.lettertile.LetterTileDrawable.ContactType; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 75 | import com.android.dialer.multimedia.MultimediaData; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 76 | import com.android.dialer.notification.NotificationChannelId; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 77 | import com.android.dialer.oem.MotorolaUtils; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 78 | import com.android.dialer.util.DrawableConverter; |
| 79 | import com.android.incallui.ContactInfoCache.ContactCacheEntry; |
| 80 | import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback; |
| 81 | import com.android.incallui.InCallPresenter.InCallState; |
| 82 | import com.android.incallui.async.PausableExecutorImpl; |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 83 | import com.android.incallui.audiomode.AudioModeProvider; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 84 | import com.android.incallui.call.CallList; |
| 85 | import com.android.incallui.call.DialerCall; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 86 | import com.android.incallui.call.DialerCallListener; |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 87 | import com.android.incallui.call.TelecomAdapter; |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame^] | 88 | import com.android.incallui.call.state.DialerCallState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 89 | import com.android.incallui.ringtone.DialerRingtoneManager; |
| 90 | import com.android.incallui.ringtone.InCallTonePlayer; |
| 91 | import com.android.incallui.ringtone.ToneGeneratorFactory; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 92 | import com.android.incallui.videotech.utils.SessionModificationState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 93 | import java.util.Objects; |
| 94 | |
| 95 | /** This class adds Notifications to the status bar for the in-call experience. */ |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 96 | public class StatusBarNotifier |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 97 | implements InCallPresenter.InCallStateListener, |
| 98 | EnrichedCallManager.StateChangedListener, |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 99 | ContactInfoCacheCallback { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 100 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 101 | private static final int NOTIFICATION_ID = 1; |
| 102 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 103 | // Notification types |
| 104 | // Indicates that no notification is currently showing. |
| 105 | private static final int NOTIFICATION_NONE = 0; |
| 106 | // Notification for an active call. This is non-interruptive, but cannot be dismissed. |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 107 | private static final int NOTIFICATION_IN_CALL = 1; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 108 | // Notification for incoming calls. This is interruptive and will show up as a HUN. |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 109 | private static final int NOTIFICATION_INCOMING_CALL = 2; |
| 110 | // Notification for incoming calls in the case where there is already an active call. |
| 111 | // This is non-interruptive, but otherwise behaves the same as NOTIFICATION_INCOMING_CALL |
| 112 | private static final int NOTIFICATION_INCOMING_CALL_QUIET = 3; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 113 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 114 | private static final long[] VIBRATE_PATTERN = new long[] {0, 1000, 1000}; |
| 115 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 116 | private final Context context; |
| 117 | private final ContactInfoCache contactInfoCache; |
| 118 | private final DialerRingtoneManager dialerRingtoneManager; |
| 119 | @Nullable private ContactsPreferences contactsPreferences; |
| 120 | private int currentNotification = NOTIFICATION_NONE; |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame^] | 121 | private int callState = DialerCallState.INVALID; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 122 | private int videoState = VideoProfile.STATE_AUDIO_ONLY; |
| 123 | private int savedIcon = 0; |
| 124 | private String savedContent = null; |
| 125 | private Bitmap savedLargeIcon; |
| 126 | private String savedContentTitle; |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 127 | private CallAudioState savedCallAudioState; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 128 | private Uri ringtone; |
| 129 | private StatusBarCallListener statusBarCallListener; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 130 | |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 131 | public StatusBarNotifier(@NonNull Context context, @NonNull ContactInfoCache contactInfoCache) { |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 132 | Trace.beginSection("StatusBarNotifier.Constructor"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 133 | this.context = Assert.isNotNull(context); |
| 134 | contactsPreferences = ContactsPreferencesFactory.newContactsPreferences(this.context); |
| 135 | this.contactInfoCache = contactInfoCache; |
| 136 | dialerRingtoneManager = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 137 | new DialerRingtoneManager( |
| 138 | new InCallTonePlayer(new ToneGeneratorFactory(), new PausableExecutorImpl()), |
| 139 | CallList.getInstance()); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 140 | currentNotification = NOTIFICATION_NONE; |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 141 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Should only be called from a irrecoverable state where it is necessary to dismiss all |
| 146 | * notifications. |
| 147 | */ |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 148 | static void clearAllCallNotifications() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 149 | LogUtil.e( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 150 | "StatusBarNotifier.clearAllCallNotifications", |
| 151 | "something terrible happened, clear all InCall notifications"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 152 | |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 153 | TelecomAdapter.getInstance().stopForegroundNotification(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | private static int getWorkStringFromPersonalString(int resId) { |
| 157 | if (resId == R.string.notification_ongoing_call) { |
| 158 | return R.string.notification_ongoing_work_call; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 159 | } else if (resId == R.string.notification_incoming_call) { |
| 160 | return R.string.notification_incoming_work_call; |
| 161 | } else { |
| 162 | return resId; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Returns PendingIntent for answering a phone call. This will typically be used from Notification |
| 168 | * context. |
| 169 | */ |
| 170 | private static PendingIntent createNotificationPendingIntent(Context context, String action) { |
| 171 | final Intent intent = new Intent(action, null, context, NotificationBroadcastReceiver.class); |
| 172 | return PendingIntent.getBroadcast(context, 0, intent, 0); |
| 173 | } |
| 174 | |
| 175 | /** Creates notifications according to the state we receive from {@link InCallPresenter}. */ |
| 176 | @Override |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 177 | @RequiresPermission(Manifest.permission.READ_PHONE_STATE) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 178 | public void onStateChange(InCallState oldState, InCallState newState, CallList callList) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 179 | LogUtil.d("StatusBarNotifier.onStateChange", "%s->%s", oldState, newState); |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 180 | updateNotification(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 181 | } |
| 182 | |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 183 | @Override |
| 184 | public void onEnrichedCallStateChanged() { |
| 185 | LogUtil.enterBlock("StatusBarNotifier.onEnrichedCallStateChanged"); |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 186 | updateNotification(); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 189 | /** |
| 190 | * Updates the phone app's status bar notification *and* launches the incoming call UI in response |
| 191 | * to a new incoming call. |
| 192 | * |
| 193 | * <p>If an incoming call is ringing (or call-waiting), the notification will also include a |
| 194 | * "fullScreenIntent" that will cause the InCallScreen to be launched, unless the current |
| 195 | * foreground activity is marked as "immersive". |
| 196 | * |
| 197 | * <p>(This is the mechanism that actually brings up the incoming call UI when we receive a "new |
| 198 | * ringing connection" event from the telephony layer.) |
| 199 | * |
| 200 | * <p>Also note that this method is safe to call even if the phone isn't actually ringing (or, |
| 201 | * more likely, if an incoming call *was* ringing briefly but then disconnected). In that case, |
| 202 | * we'll simply update or cancel the in-call notification based on the current phone state. |
| 203 | * |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 204 | * @see #updateInCallNotification() |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 205 | */ |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 206 | @RequiresPermission(Manifest.permission.READ_PHONE_STATE) |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 207 | public void updateNotification() { |
| 208 | updateInCallNotification(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Take down the in-call notification. |
| 213 | * |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 214 | * @see #updateInCallNotification() |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 215 | */ |
| 216 | private void cancelNotification() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 217 | if (statusBarCallListener != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 218 | setStatusBarCallListener(null); |
| 219 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 220 | if (currentNotification != NOTIFICATION_NONE) { |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 221 | TelecomAdapter.getInstance().stopForegroundNotification(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 222 | currentNotification = NOTIFICATION_NONE; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 223 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Helper method for updateInCallNotification() and updateNotification(): Update the phone app's |
| 228 | * status bar notification based on the current telephony state, or cancels the notification if |
| 229 | * the phone is totally idle. |
| 230 | */ |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 231 | @RequiresPermission(Manifest.permission.READ_PHONE_STATE) |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 232 | private void updateInCallNotification() { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 233 | LogUtil.d("StatusBarNotifier.updateInCallNotification", ""); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 234 | |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 235 | final DialerCall call = getCallToShow(CallList.getInstance()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 236 | |
| 237 | if (call != null) { |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 238 | showNotification(call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 239 | } else { |
| 240 | cancelNotification(); |
| 241 | } |
| 242 | } |
| 243 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 244 | @RequiresPermission(Manifest.permission.READ_PHONE_STATE) |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 245 | private void showNotification(final DialerCall call) { |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 246 | Trace.beginSection("StatusBarNotifier.showNotification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 247 | final boolean isIncoming = |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame^] | 248 | (call.getState() == DialerCallState.INCOMING |
| 249 | || call.getState() == DialerCallState.CALL_WAITING); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 250 | setStatusBarCallListener(new StatusBarCallListener(call)); |
| 251 | |
| 252 | // we make a call to the contact info cache to query for supplemental data to what the |
| 253 | // call provides. This includes the contact name and photo. |
| 254 | // This callback will always get called immediately and synchronously with whatever data |
| 255 | // it has available, and may make a subsequent call later (same thread) if it had to |
| 256 | // call into the contacts provider for more data. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 257 | contactInfoCache.findInfo(call, isIncoming, this); |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 258 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /** Sets up the main Ui for the notification */ |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 262 | @RequiresPermission(Manifest.permission.READ_PHONE_STATE) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 263 | private void buildAndSendNotification( |
| 264 | CallList callList, DialerCall originalCall, ContactCacheEntry contactInfo) { |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 265 | Trace.beginSection("StatusBarNotifier.buildAndSendNotification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 266 | // This can get called to update an existing notification after contact information has come |
| 267 | // back. However, it can happen much later. Before we continue, we need to make sure that |
| 268 | // the call being passed in is still the one we want to show in the notification. |
| 269 | final DialerCall call = getCallToShow(callList); |
| 270 | if (call == null || !call.getId().equals(originalCall.getId())) { |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 271 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 272 | return; |
| 273 | } |
| 274 | |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 275 | Trace.beginSection("prepare work"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 276 | final int callState = call.getState(); |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 277 | final CallAudioState callAudioState = AudioModeProvider.getInstance().getAudioState(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 278 | |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 279 | Trace.beginSection("read icon and strings"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 280 | // Check if data has changed; if nothing is different, don't issue another notification. |
| 281 | final int iconResId = getIconToDisplay(call); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 282 | Bitmap largeIcon = getLargeIconToDisplay(context, contactInfo, call); |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 283 | final CharSequence content = getContentString(call, contactInfo.userType); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 284 | final String contentTitle = getContentTitle(contactInfo, call); |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 285 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 286 | |
| 287 | final boolean isVideoUpgradeRequest = |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 288 | call.getVideoTech().getSessionModificationState() |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 289 | == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 290 | final int notificationType; |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame^] | 291 | if (callState == DialerCallState.INCOMING |
| 292 | || callState == DialerCallState.CALL_WAITING |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 293 | || isVideoUpgradeRequest) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 294 | if (ConfigProviderBindings.get(context) |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 295 | .getBoolean("quiet_incoming_call_if_ui_showing", true)) { |
| 296 | notificationType = |
| 297 | InCallPresenter.getInstance().isShowingInCallUi() |
| 298 | ? NOTIFICATION_INCOMING_CALL_QUIET |
| 299 | : NOTIFICATION_INCOMING_CALL; |
| 300 | } else { |
| 301 | boolean alreadyActive = |
| 302 | callList.getActiveOrBackgroundCall() != null |
| 303 | && InCallPresenter.getInstance().isShowingInCallUi(); |
| 304 | notificationType = |
| 305 | alreadyActive ? NOTIFICATION_INCOMING_CALL_QUIET : NOTIFICATION_INCOMING_CALL; |
| 306 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 307 | } else { |
| 308 | notificationType = NOTIFICATION_IN_CALL; |
| 309 | } |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 310 | Trace.endSection(); // prepare work |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 311 | |
| 312 | if (!checkForChangeAndSaveData( |
| 313 | iconResId, |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 314 | content.toString(), |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 315 | largeIcon, |
| 316 | contentTitle, |
| 317 | callState, |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 318 | call.getVideoState(), |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 319 | notificationType, |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 320 | contactInfo.contactRingtoneUri, |
| 321 | callAudioState)) { |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 322 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 323 | return; |
| 324 | } |
| 325 | |
| 326 | if (largeIcon != null) { |
| 327 | largeIcon = getRoundedIcon(largeIcon); |
| 328 | } |
| 329 | |
| 330 | // This builder is used for the notification shown when the device is locked and the user |
| 331 | // has set their notification settings to 'hide sensitive content' |
| 332 | // {@see Notification.Builder#setPublicVersion}. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 333 | Notification.Builder publicBuilder = new Notification.Builder(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 334 | publicBuilder |
| 335 | .setSmallIcon(iconResId) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 336 | .setColor(context.getResources().getColor(R.color.dialer_theme_color, context.getTheme())) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 337 | // Hide work call state for the lock screen notification |
| 338 | .setContentTitle(getContentString(call, ContactsUtils.USER_TYPE_CURRENT)); |
| 339 | setNotificationWhen(call, callState, publicBuilder); |
| 340 | |
| 341 | // Builder for the notification shown when the device is unlocked or the user has set their |
| 342 | // notification settings to 'show all notification content'. |
| 343 | final Notification.Builder builder = getNotificationBuilder(); |
| 344 | builder.setPublicVersion(publicBuilder.build()); |
| 345 | |
| 346 | // Set up the main intent to send the user to the in-call screen |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 347 | builder.setContentIntent(createLaunchPendingIntent(false /* isFullScreen */)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 348 | |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 349 | LogUtil.i("StatusBarNotifier.buildAndSendNotification", "notificationType=" + notificationType); |
| 350 | switch (notificationType) { |
| 351 | case NOTIFICATION_INCOMING_CALL: |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 352 | if (BuildCompat.isAtLeastO()) { |
| 353 | builder.setChannelId(NotificationChannelId.INCOMING_CALL); |
| 354 | } |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 355 | // Set the intent as a full screen intent as well if a call is incoming |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 356 | configureFullScreenIntent(builder, createLaunchPendingIntent(true /* isFullScreen */)); |
| 357 | // Set the notification category and bump the priority for incoming calls |
| 358 | builder.setCategory(Notification.CATEGORY_CALL); |
| 359 | // This will be ignored on O+ and handled by the channel |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 360 | builder.setPriority(Notification.PRIORITY_MAX); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 361 | if (currentNotification != NOTIFICATION_INCOMING_CALL) { |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 362 | LogUtil.i( |
| 363 | "StatusBarNotifier.buildAndSendNotification", |
| 364 | "Canceling old notification so this one can be noisy"); |
| 365 | // Moving from a non-interuptive notification (or none) to a noisy one. Cancel the old |
| 366 | // notification (if there is one) so the fullScreenIntent or HUN will show |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 367 | TelecomAdapter.getInstance().stopForegroundNotification(); |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 368 | } |
| 369 | break; |
| 370 | case NOTIFICATION_INCOMING_CALL_QUIET: |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 371 | if (BuildCompat.isAtLeastO()) { |
| 372 | builder.setChannelId(NotificationChannelId.ONGOING_CALL); |
| 373 | } |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 374 | break; |
| 375 | case NOTIFICATION_IN_CALL: |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 376 | if (BuildCompat.isAtLeastO()) { |
| 377 | publicBuilder.setColorized(true); |
| 378 | builder.setColorized(true); |
| 379 | builder.setChannelId(NotificationChannelId.ONGOING_CALL); |
| 380 | } |
| 381 | break; |
| 382 | default: |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 383 | break; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | // Set the content |
| 387 | builder.setContentText(content); |
| 388 | builder.setSmallIcon(iconResId); |
| 389 | builder.setContentTitle(contentTitle); |
| 390 | builder.setLargeIcon(largeIcon); |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 391 | builder.setColor(InCallPresenter.getInstance().getThemeColorManager().getPrimaryColor()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 392 | |
| 393 | if (isVideoUpgradeRequest) { |
| 394 | builder.setUsesChronometer(false); |
| 395 | addDismissUpgradeRequestAction(builder); |
| 396 | addAcceptUpgradeRequestAction(builder); |
| 397 | } else { |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 398 | createIncomingCallNotification(call, callState, callAudioState, builder); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | addPersonReference(builder, contactInfo, call); |
| 402 | |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 403 | Trace.beginSection("fire notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 404 | // Fire off the notification |
| 405 | Notification notification = builder.build(); |
| 406 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 407 | if (dialerRingtoneManager.shouldPlayRingtone(callState, contactInfo.contactRingtoneUri)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 408 | notification.flags |= Notification.FLAG_INSISTENT; |
| 409 | notification.sound = contactInfo.contactRingtoneUri; |
| 410 | AudioAttributes.Builder audioAttributes = new AudioAttributes.Builder(); |
| 411 | audioAttributes.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC); |
| 412 | audioAttributes.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE); |
| 413 | notification.audioAttributes = audioAttributes.build(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 414 | if (dialerRingtoneManager.shouldVibrate(context.getContentResolver())) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 415 | notification.vibrate = VIBRATE_PATTERN; |
| 416 | } |
| 417 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 418 | if (dialerRingtoneManager.shouldPlayCallWaitingTone(callState)) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 419 | LogUtil.v("StatusBarNotifier.buildAndSendNotification", "playing call waiting tone"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 420 | dialerRingtoneManager.playCallWaitingTone(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 421 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 422 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 423 | LogUtil.i( |
| 424 | "StatusBarNotifier.buildAndSendNotification", |
| 425 | "displaying notification for " + notificationType); |
| 426 | |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 427 | // If a notification exists, this will only update it. |
| 428 | TelecomAdapter.getInstance().startForegroundNotification(NOTIFICATION_ID, notification); |
| 429 | |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 430 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 431 | call.getLatencyReport().onNotificationShown(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 432 | currentNotification = notificationType; |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 433 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | private void createIncomingCallNotification( |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 437 | DialerCall call, int state, CallAudioState callAudioState, Notification.Builder builder) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 438 | setNotificationWhen(call, state, builder); |
| 439 | |
| 440 | // Add hang up option for any active calls (active | onhold), outgoing calls (dialing). |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame^] | 441 | if (state == DialerCallState.ACTIVE |
| 442 | || state == DialerCallState.ONHOLD |
| 443 | || DialerCallState.isDialing(state)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 444 | addHangupAction(builder); |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 445 | addSpeakerAction(builder, callAudioState); |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame^] | 446 | } else if (state == DialerCallState.INCOMING || state == DialerCallState.CALL_WAITING) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 447 | addDismissAction(builder); |
| 448 | if (call.isVideoCall()) { |
| 449 | addVideoCallAction(builder); |
| 450 | } else { |
| 451 | addAnswerAction(builder); |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Sets the notification's when section as needed. For active calls, this is explicitly set as the |
| 458 | * duration of the call. For all other states, the notification will automatically show the time |
| 459 | * at which the notification was created. |
| 460 | */ |
| 461 | private void setNotificationWhen(DialerCall call, int state, Notification.Builder builder) { |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame^] | 462 | if (state == DialerCallState.ACTIVE) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 463 | builder.setUsesChronometer(true); |
| 464 | builder.setWhen(call.getConnectTimeMillis()); |
| 465 | } else { |
| 466 | builder.setUsesChronometer(false); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Checks the new notification data and compares it against any notification that we are already |
| 472 | * displaying. If the data is exactly the same, we return false so that we do not issue a new |
| 473 | * notification for the exact same data. |
| 474 | */ |
| 475 | private boolean checkForChangeAndSaveData( |
| 476 | int icon, |
| 477 | String content, |
| 478 | Bitmap largeIcon, |
| 479 | String contentTitle, |
| 480 | int state, |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 481 | int videoState, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 482 | int notificationType, |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 483 | Uri ringtone, |
| 484 | CallAudioState callAudioState) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 485 | |
| 486 | // The two are different: |
| 487 | // if new title is not null, it should be different from saved version OR |
| 488 | // if new title is null, the saved version should not be null |
| 489 | final boolean contentTitleChanged = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 490 | (contentTitle != null && !contentTitle.equals(savedContentTitle)) |
| 491 | || (contentTitle == null && savedContentTitle != null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 492 | |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 493 | boolean largeIconChanged; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 494 | if (savedLargeIcon == null) { |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 495 | largeIconChanged = largeIcon != null; |
| 496 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 497 | largeIconChanged = largeIcon == null || !savedLargeIcon.sameAs(largeIcon); |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 498 | } |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 499 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 500 | // any change means we are definitely updating |
| 501 | boolean retval = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 502 | (savedIcon != icon) |
| 503 | || !Objects.equals(savedContent, content) |
| 504 | || (callState != state) |
| 505 | || (this.videoState != videoState) |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 506 | || largeIconChanged |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 507 | || contentTitleChanged |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 508 | || !Objects.equals(this.ringtone, ringtone) |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 509 | || !Objects.equals(savedCallAudioState, callAudioState); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 510 | |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 511 | LogUtil.d( |
| 512 | "StatusBarNotifier.checkForChangeAndSaveData", |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 513 | "data changed: icon: %b, content: %b, state: %b, videoState: %b, largeIcon: %b, title: %b," |
| 514 | + "ringtone: %b, audioState: %b, type: %b", |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 515 | (savedIcon != icon), |
| 516 | !Objects.equals(savedContent, content), |
| 517 | (callState != state), |
| 518 | (this.videoState != videoState), |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 519 | largeIconChanged, |
| 520 | contentTitleChanged, |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 521 | !Objects.equals(this.ringtone, ringtone), |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 522 | !Objects.equals(savedCallAudioState, callAudioState), |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 523 | currentNotification != notificationType); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 524 | // If we aren't showing a notification right now or the notification type is changing, |
| 525 | // definitely do an update. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 526 | if (currentNotification != notificationType) { |
| 527 | if (currentNotification == NOTIFICATION_NONE) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 528 | LogUtil.d( |
| 529 | "StatusBarNotifier.checkForChangeAndSaveData", "showing notification for first time."); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 530 | } |
| 531 | retval = true; |
| 532 | } |
| 533 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 534 | savedIcon = icon; |
| 535 | savedContent = content; |
| 536 | callState = state; |
| 537 | this.videoState = videoState; |
| 538 | savedLargeIcon = largeIcon; |
| 539 | savedContentTitle = contentTitle; |
| 540 | this.ringtone = ringtone; |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 541 | savedCallAudioState = callAudioState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 542 | |
| 543 | if (retval) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 544 | LogUtil.d( |
| 545 | "StatusBarNotifier.checkForChangeAndSaveData", "data changed. Showing notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | return retval; |
| 549 | } |
| 550 | |
| 551 | /** Returns the main string to use in the notification. */ |
| 552 | @VisibleForTesting |
| 553 | @Nullable |
| 554 | String getContentTitle(ContactCacheEntry contactInfo, DialerCall call) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 555 | if (call.isConferenceCall()) { |
| 556 | return CallerInfoUtils.getConferenceString( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 557 | context, call.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | String preferredName = |
| 561 | ContactDisplayUtils.getPreferredDisplayName( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 562 | contactInfo.namePrimary, contactInfo.nameAlternative, contactsPreferences); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 563 | if (TextUtils.isEmpty(preferredName)) { |
| 564 | return TextUtils.isEmpty(contactInfo.number) |
| 565 | ? null |
| 566 | : BidiFormatter.getInstance() |
| 567 | .unicodeWrap(contactInfo.number, TextDirectionHeuristics.LTR); |
| 568 | } |
| 569 | return preferredName; |
| 570 | } |
| 571 | |
| 572 | private void addPersonReference( |
| 573 | Notification.Builder builder, ContactCacheEntry contactInfo, DialerCall call) { |
| 574 | // Query {@link Contacts#CONTENT_LOOKUP_URI} directly with work lookup key is not allowed. |
| 575 | // So, do not pass {@link Contacts#CONTENT_LOOKUP_URI} to NotificationManager to avoid |
| 576 | // NotificationManager using it. |
| 577 | if (contactInfo.lookupUri != null && contactInfo.userType != ContactsUtils.USER_TYPE_WORK) { |
| 578 | builder.addPerson(contactInfo.lookupUri.toString()); |
| 579 | } else if (!TextUtils.isEmpty(call.getNumber())) { |
| 580 | builder.addPerson(Uri.fromParts(PhoneAccount.SCHEME_TEL, call.getNumber(), null).toString()); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | /** Gets a large icon from the contact info object to display in the notification. */ |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 585 | private static Bitmap getLargeIconToDisplay( |
| 586 | Context context, ContactCacheEntry contactInfo, DialerCall call) { |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 587 | Trace.beginSection("StatusBarNotifier.getLargeIconToDisplay"); |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 588 | Resources resources = context.getResources(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 589 | Bitmap largeIcon = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 590 | if (contactInfo.photo != null && (contactInfo.photo instanceof BitmapDrawable)) { |
| 591 | largeIcon = ((BitmapDrawable) contactInfo.photo).getBitmap(); |
| 592 | } |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 593 | if (contactInfo.photo == null) { |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 594 | int width = (int) resources.getDimension(android.R.dimen.notification_large_icon_width); |
| 595 | int height = (int) resources.getDimension(android.R.dimen.notification_large_icon_height); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 596 | @ContactType |
| 597 | int contactType = |
| 598 | LetterTileDrawable.getContactTypeFromPrimitives( |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 599 | call.isVoiceMailNumber(), |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 600 | call.isSpam(), |
| 601 | contactInfo.isBusiness, |
| 602 | call.getNumberPresentation(), |
| 603 | call.isConferenceCall() && !call.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE)); |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 604 | LetterTileDrawable lettertile = new LetterTileDrawable(resources); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 605 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 606 | lettertile.setCanonicalDialerLetterTileDetails( |
| 607 | contactInfo.namePrimary == null ? contactInfo.number : contactInfo.namePrimary, |
| 608 | contactInfo.lookupKey, |
| 609 | LetterTileDrawable.SHAPE_CIRCLE, |
| 610 | contactType); |
| 611 | largeIcon = lettertile.getBitmap(width, height); |
| 612 | } |
| 613 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 614 | if (call.isSpam()) { |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 615 | Drawable drawable = resources.getDrawable(R.drawable.blocked_contact, context.getTheme()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 616 | largeIcon = DrawableConverter.drawableToBitmap(drawable); |
| 617 | } |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 618 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 619 | return largeIcon; |
| 620 | } |
| 621 | |
| 622 | private Bitmap getRoundedIcon(Bitmap bitmap) { |
| 623 | if (bitmap == null) { |
| 624 | return null; |
| 625 | } |
| 626 | final int height = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 627 | (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_height); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 628 | final int width = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 629 | (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_width); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 630 | return BitmapUtil.getRoundedBitmap(bitmap, width, height); |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Returns the appropriate icon res Id to display based on the call for which we want to display |
| 635 | * information. |
| 636 | */ |
Eric Erfanian | 2827dd1 | 2017-10-26 09:37:50 -0700 | [diff] [blame] | 637 | @VisibleForTesting |
| 638 | public int getIconToDisplay(DialerCall call) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 639 | // Even if both lines are in use, we only show a single item in |
| 640 | // the expanded Notifications UI. It's labeled "Ongoing call" |
| 641 | // (or "On hold" if there's only one call, and it's on hold.) |
| 642 | // Also, we don't have room to display caller-id info from two |
| 643 | // different calls. So if both lines are in use, display info |
| 644 | // from the foreground call. And if there's a ringing call, |
| 645 | // display that regardless of the state of the other calls. |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame^] | 646 | if (call.getState() == DialerCallState.ONHOLD) { |
Eric Erfanian | 2827dd1 | 2017-10-26 09:37:50 -0700 | [diff] [blame] | 647 | return R.drawable.quantum_ic_phone_paused_vd_theme_24; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 648 | } else if (call.getVideoTech().getSessionModificationState() |
calderwoodra | 1dc2cea | 2017-09-20 16:30:41 -0700 | [diff] [blame] | 649 | == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST |
| 650 | || call.isVideoCall()) { |
linyuh | 8dc242d | 2018-03-28 13:09:47 -0700 | [diff] [blame] | 651 | return R.drawable.quantum_ic_videocam_vd_white_24; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 652 | } else if (call.hasProperty(PROPERTY_HIGH_DEF_AUDIO) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 653 | && MotorolaUtils.shouldShowHdIconInNotification(context)) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 654 | // Normally when a call is ongoing the status bar displays an icon of a phone. This is a |
| 655 | // helpful hint for users so they know how to get back to the call. For Sprint HD calls, we |
| 656 | // replace this icon with an icon of a phone with a HD badge. This is a carrier requirement. |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 657 | return R.drawable.ic_hd_call; |
Eric Erfanian | 2827dd1 | 2017-10-26 09:37:50 -0700 | [diff] [blame] | 658 | } else if (call.hasProperty(Details.PROPERTY_HAS_CDMA_VOICE_PRIVACY)) { |
| 659 | return R.drawable.quantum_ic_phone_locked_vd_theme_24; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 660 | } |
yueg | 48f93f4 | 2018-03-09 16:49:38 -0800 | [diff] [blame] | 661 | // If ReturnToCall is enabled, use the static icon. The animated one will show in the bubble. |
| 662 | if (ReturnToCallController.isEnabled(context)) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 663 | return R.drawable.quantum_ic_call_vd_theme_24; |
| 664 | } else { |
| 665 | return R.drawable.on_going_call; |
| 666 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | /** Returns the message to use with the notification. */ |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 670 | private CharSequence getContentString(DialerCall call, @UserType long userType) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 671 | boolean isIncomingOrWaiting = |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame^] | 672 | call.getState() == DialerCallState.INCOMING |
| 673 | || call.getState() == DialerCallState.CALL_WAITING; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 674 | |
| 675 | if (isIncomingOrWaiting |
| 676 | && call.getNumberPresentation() == TelecomManager.PRESENTATION_ALLOWED) { |
| 677 | |
| 678 | if (!TextUtils.isEmpty(call.getChildNumber())) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 679 | return context.getString(R.string.child_number, call.getChildNumber()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 680 | } else if (!TextUtils.isEmpty(call.getCallSubject()) && call.isCallSubjectSupported()) { |
| 681 | return call.getCallSubject(); |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | int resId = R.string.notification_ongoing_call; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 686 | String wifiBrand = context.getString(R.string.notification_call_wifi_brand); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 687 | if (call.hasProperty(Details.PROPERTY_WIFI)) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 688 | resId = R.string.notification_ongoing_call_wifi_template; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | if (isIncomingOrWaiting) { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 692 | if (call.isSpam()) { |
| 693 | resId = R.string.notification_incoming_spam_call; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 694 | } else if (shouldShowEnrichedCallNotification(call.getEnrichedCallSession())) { |
| 695 | resId = getECIncomingCallText(call.getEnrichedCallSession()); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 696 | } else if (call.hasProperty(Details.PROPERTY_WIFI)) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 697 | resId = R.string.notification_incoming_call_wifi_template; |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 698 | } else if (call.getAccountHandle() != null && hasMultiplePhoneAccounts(call)) { |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 699 | return getMultiSimIncomingText(call); |
yueg | 45e4573 | 2017-10-09 14:35:06 -0700 | [diff] [blame] | 700 | } else if (call.isVideoCall()) { |
| 701 | resId = R.string.notification_incoming_video_call; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 702 | } else { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 703 | resId = R.string.notification_incoming_call; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 704 | } |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame^] | 705 | } else if (call.getState() == DialerCallState.ONHOLD) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 706 | resId = R.string.notification_on_hold; |
calderwoodra | 1dc2cea | 2017-09-20 16:30:41 -0700 | [diff] [blame] | 707 | } else if (call.isVideoCall()) { |
| 708 | resId = |
| 709 | call.getVideoTech().isPaused() |
| 710 | ? R.string.notification_ongoing_paused_video_call |
| 711 | : R.string.notification_ongoing_video_call; |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame^] | 712 | } else if (DialerCallState.isDialing(call.getState())) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 713 | resId = R.string.notification_dialing; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 714 | } else if (call.getVideoTech().getSessionModificationState() |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 715 | == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 716 | resId = R.string.notification_requesting_video_call; |
| 717 | } |
| 718 | |
| 719 | // Is the call placed through work connection service. |
| 720 | boolean isWorkCall = call.hasProperty(PROPERTY_ENTERPRISE_CALL); |
| 721 | if (userType == ContactsUtils.USER_TYPE_WORK || isWorkCall) { |
| 722 | resId = getWorkStringFromPersonalString(resId); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 723 | wifiBrand = context.getString(R.string.notification_call_wifi_work_brand); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | if (resId == R.string.notification_incoming_call_wifi_template |
| 727 | || resId == R.string.notification_ongoing_call_wifi_template) { |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 728 | // TODO(a bug): Potentially apply this template logic everywhere. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 729 | return context.getString(resId, wifiBrand); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 730 | } |
| 731 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 732 | return context.getString(resId); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 733 | } |
| 734 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 735 | private boolean shouldShowEnrichedCallNotification(Session session) { |
| 736 | if (session == null) { |
| 737 | return false; |
| 738 | } |
| 739 | return session.getMultimediaData().hasData() || session.getMultimediaData().isImportant(); |
| 740 | } |
| 741 | |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 742 | private int getECIncomingCallText(Session session) { |
| 743 | int resId; |
| 744 | MultimediaData data = session.getMultimediaData(); |
| 745 | boolean hasImage = data.hasImageData(); |
| 746 | boolean hasSubject = !TextUtils.isEmpty(data.getText()); |
| 747 | boolean hasMap = data.getLocation() != null; |
| 748 | if (data.isImportant()) { |
| 749 | if (hasMap) { |
| 750 | if (hasImage) { |
| 751 | if (hasSubject) { |
| 752 | resId = R.string.important_notification_incoming_call_with_photo_message_location; |
| 753 | } else { |
| 754 | resId = R.string.important_notification_incoming_call_with_photo_location; |
| 755 | } |
| 756 | } else if (hasSubject) { |
| 757 | resId = R.string.important_notification_incoming_call_with_message_location; |
| 758 | } else { |
| 759 | resId = R.string.important_notification_incoming_call_with_location; |
| 760 | } |
| 761 | } else if (hasImage) { |
| 762 | if (hasSubject) { |
| 763 | resId = R.string.important_notification_incoming_call_with_photo_message; |
| 764 | } else { |
| 765 | resId = R.string.important_notification_incoming_call_with_photo; |
| 766 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 767 | } else if (hasSubject) { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 768 | resId = R.string.important_notification_incoming_call_with_message; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 769 | } else { |
| 770 | resId = R.string.important_notification_incoming_call; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 771 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 772 | if (context.getString(resId).length() > 50) { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 773 | resId = R.string.important_notification_incoming_call_attachments; |
| 774 | } |
| 775 | } else { |
| 776 | if (hasMap) { |
| 777 | if (hasImage) { |
| 778 | if (hasSubject) { |
| 779 | resId = R.string.notification_incoming_call_with_photo_message_location; |
| 780 | } else { |
| 781 | resId = R.string.notification_incoming_call_with_photo_location; |
| 782 | } |
| 783 | } else if (hasSubject) { |
| 784 | resId = R.string.notification_incoming_call_with_message_location; |
| 785 | } else { |
| 786 | resId = R.string.notification_incoming_call_with_location; |
| 787 | } |
| 788 | } else if (hasImage) { |
| 789 | if (hasSubject) { |
| 790 | resId = R.string.notification_incoming_call_with_photo_message; |
| 791 | } else { |
| 792 | resId = R.string.notification_incoming_call_with_photo; |
| 793 | } |
| 794 | } else { |
| 795 | resId = R.string.notification_incoming_call_with_message; |
| 796 | } |
| 797 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 798 | if (context.getString(resId).length() > 50) { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 799 | resId = R.string.notification_incoming_call_attachments; |
| 800 | } |
| 801 | return resId; |
| 802 | } |
| 803 | |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 804 | private CharSequence getMultiSimIncomingText(DialerCall call) { |
| 805 | PhoneAccount phoneAccount = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 806 | context.getSystemService(TelecomManager.class).getPhoneAccount(call.getAccountHandle()); |
twyen | e931c12 | 2018-03-19 14:47:28 -0700 | [diff] [blame] | 807 | if (phoneAccount == null) { |
| 808 | return context.getString(R.string.notification_incoming_call); |
| 809 | } |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 810 | SpannableString string = |
| 811 | new SpannableString( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 812 | context.getString( |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 813 | R.string.notification_incoming_call_mutli_sim, phoneAccount.getLabel())); |
| 814 | int accountStart = string.toString().lastIndexOf(phoneAccount.getLabel().toString()); |
| 815 | int accountEnd = accountStart + phoneAccount.getLabel().length(); |
| 816 | |
| 817 | string.setSpan( |
| 818 | new ForegroundColorSpan(phoneAccount.getHighlightColor()), |
| 819 | accountStart, |
| 820 | accountEnd, |
| 821 | Spannable.SPAN_INCLUSIVE_EXCLUSIVE); |
| 822 | return string; |
| 823 | } |
| 824 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 825 | /** Gets the most relevant call to display in the notification. */ |
| 826 | private DialerCall getCallToShow(CallList callList) { |
| 827 | if (callList == null) { |
| 828 | return null; |
| 829 | } |
| 830 | DialerCall call = callList.getIncomingCall(); |
| 831 | if (call == null) { |
| 832 | call = callList.getOutgoingCall(); |
| 833 | } |
| 834 | if (call == null) { |
| 835 | call = callList.getVideoUpgradeRequestCall(); |
| 836 | } |
| 837 | if (call == null) { |
| 838 | call = callList.getActiveOrBackgroundCall(); |
| 839 | } |
| 840 | return call; |
| 841 | } |
| 842 | |
| 843 | private Spannable getActionText(@StringRes int stringRes, @ColorRes int colorRes) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 844 | Spannable spannable = new SpannableString(context.getText(stringRes)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 845 | if (VERSION.SDK_INT >= VERSION_CODES.N_MR1) { |
| 846 | // This will only work for cases where the Notification.Builder has a fullscreen intent set |
| 847 | // Notification.Builder that does not have a full screen intent will take the color of the |
| 848 | // app and the following leads to a no-op. |
| 849 | spannable.setSpan( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 850 | new ForegroundColorSpan(context.getColor(colorRes)), 0, spannable.length(), 0); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 851 | } |
| 852 | return spannable; |
| 853 | } |
| 854 | |
| 855 | private void addAnswerAction(Notification.Builder builder) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 856 | LogUtil.d( |
| 857 | "StatusBarNotifier.addAnswerAction", |
| 858 | "will show \"answer\" action in the incoming call Notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 859 | PendingIntent answerVoicePendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 860 | createNotificationPendingIntent(context, ACTION_ANSWER_VOICE_INCOMING_CALL); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 861 | builder.addAction( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 862 | new Notification.Action.Builder( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 863 | Icon.createWithResource(context, R.drawable.quantum_ic_call_white_24), |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 864 | getActionText( |
| 865 | R.string.notification_action_answer, R.color.notification_action_accept), |
| 866 | answerVoicePendingIntent) |
| 867 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | private void addDismissAction(Notification.Builder builder) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 871 | LogUtil.d( |
| 872 | "StatusBarNotifier.addDismissAction", |
| 873 | "will show \"decline\" action in the incoming call Notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 874 | PendingIntent declinePendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 875 | createNotificationPendingIntent(context, ACTION_DECLINE_INCOMING_CALL); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 876 | builder.addAction( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 877 | new Notification.Action.Builder( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 878 | Icon.createWithResource(context, R.drawable.quantum_ic_close_white_24), |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 879 | getActionText( |
| 880 | R.string.notification_action_dismiss, R.color.notification_action_dismiss), |
| 881 | declinePendingIntent) |
| 882 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | private void addHangupAction(Notification.Builder builder) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 886 | LogUtil.d( |
| 887 | "StatusBarNotifier.addHangupAction", |
| 888 | "will show \"hang-up\" action in the ongoing active call Notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 889 | PendingIntent hangupPendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 890 | createNotificationPendingIntent(context, ACTION_HANG_UP_ONGOING_CALL); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 891 | builder.addAction( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 892 | new Notification.Action.Builder( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 893 | Icon.createWithResource(context, R.drawable.quantum_ic_call_end_white_24), |
| 894 | context.getText(R.string.notification_action_end_call), |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 895 | hangupPendingIntent) |
| 896 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 897 | } |
| 898 | |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 899 | private void addSpeakerAction(Notification.Builder builder, CallAudioState callAudioState) { |
| 900 | if ((callAudioState.getSupportedRouteMask() & CallAudioState.ROUTE_BLUETOOTH) |
| 901 | == CallAudioState.ROUTE_BLUETOOTH) { |
| 902 | // Don't add speaker button if bluetooth is connected |
| 903 | return; |
| 904 | } |
| 905 | if (callAudioState.getRoute() == CallAudioState.ROUTE_SPEAKER) { |
| 906 | addSpeakerOffAction(builder); |
| 907 | } else if ((callAudioState.getRoute() & CallAudioState.ROUTE_WIRED_OR_EARPIECE) != 0) { |
| 908 | addSpeakerOnAction(builder); |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | private void addSpeakerOnAction(Notification.Builder builder) { |
| 913 | LogUtil.d( |
| 914 | "StatusBarNotifier.addSpeakerOnAction", |
| 915 | "will show \"Speaker on\" action in the ongoing active call Notification"); |
| 916 | PendingIntent speakerOnPendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 917 | createNotificationPendingIntent(context, ACTION_TURN_ON_SPEAKER); |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 918 | builder.addAction( |
| 919 | new Notification.Action.Builder( |
wangqi | 6ca8c72 | 2018-03-29 10:19:58 -0700 | [diff] [blame] | 920 | Icon.createWithResource(context, R.drawable.quantum_ic_volume_up_vd_theme_24), |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 921 | context.getText(R.string.notification_action_speaker_on), |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 922 | speakerOnPendingIntent) |
| 923 | .build()); |
| 924 | } |
| 925 | |
| 926 | private void addSpeakerOffAction(Notification.Builder builder) { |
| 927 | LogUtil.d( |
| 928 | "StatusBarNotifier.addSpeakerOffAction", |
| 929 | "will show \"Speaker off\" action in the ongoing active call Notification"); |
| 930 | PendingIntent speakerOffPendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 931 | createNotificationPendingIntent(context, ACTION_TURN_OFF_SPEAKER); |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 932 | builder.addAction( |
| 933 | new Notification.Action.Builder( |
wangqi | 6ca8c72 | 2018-03-29 10:19:58 -0700 | [diff] [blame] | 934 | Icon.createWithResource(context, R.drawable.quantum_ic_phone_in_talk_vd_theme_24), |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 935 | context.getText(R.string.notification_action_speaker_off), |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 936 | speakerOffPendingIntent) |
| 937 | .build()); |
| 938 | } |
| 939 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 940 | private void addVideoCallAction(Notification.Builder builder) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 941 | LogUtil.i( |
| 942 | "StatusBarNotifier.addVideoCallAction", |
| 943 | "will show \"video\" action in the incoming call Notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 944 | PendingIntent answerVideoPendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 945 | createNotificationPendingIntent(context, ACTION_ANSWER_VIDEO_INCOMING_CALL); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 946 | builder.addAction( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 947 | new Notification.Action.Builder( |
linyuh | 8dc242d | 2018-03-28 13:09:47 -0700 | [diff] [blame] | 948 | Icon.createWithResource(context, R.drawable.quantum_ic_videocam_vd_white_24), |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 949 | getActionText( |
| 950 | R.string.notification_action_answer_video, |
| 951 | R.color.notification_action_answer_video), |
| 952 | answerVideoPendingIntent) |
| 953 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | private void addAcceptUpgradeRequestAction(Notification.Builder builder) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 957 | LogUtil.i( |
| 958 | "StatusBarNotifier.addAcceptUpgradeRequestAction", |
| 959 | "will show \"accept upgrade\" action in the incoming call Notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 960 | PendingIntent acceptVideoPendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 961 | createNotificationPendingIntent(context, ACTION_ACCEPT_VIDEO_UPGRADE_REQUEST); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 962 | builder.addAction( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 963 | new Notification.Action.Builder( |
linyuh | 8dc242d | 2018-03-28 13:09:47 -0700 | [diff] [blame] | 964 | Icon.createWithResource(context, R.drawable.quantum_ic_videocam_vd_white_24), |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 965 | getActionText( |
| 966 | R.string.notification_action_accept, R.color.notification_action_accept), |
| 967 | acceptVideoPendingIntent) |
| 968 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | private void addDismissUpgradeRequestAction(Notification.Builder builder) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 972 | LogUtil.i( |
| 973 | "StatusBarNotifier.addDismissUpgradeRequestAction", |
| 974 | "will show \"dismiss upgrade\" action in the incoming call Notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 975 | PendingIntent declineVideoPendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 976 | createNotificationPendingIntent(context, ACTION_DECLINE_VIDEO_UPGRADE_REQUEST); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 977 | builder.addAction( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 978 | new Notification.Action.Builder( |
linyuh | 8dc242d | 2018-03-28 13:09:47 -0700 | [diff] [blame] | 979 | Icon.createWithResource(context, R.drawable.quantum_ic_videocam_vd_white_24), |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 980 | getActionText( |
| 981 | R.string.notification_action_dismiss, R.color.notification_action_dismiss), |
| 982 | declineVideoPendingIntent) |
| 983 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | /** Adds fullscreen intent to the builder. */ |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 987 | private void configureFullScreenIntent(Notification.Builder builder, PendingIntent intent) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 988 | // Ok, we actually want to launch the incoming call |
| 989 | // UI at this point (in addition to simply posting a notification |
| 990 | // to the status bar). Setting fullScreenIntent will cause |
| 991 | // the InCallScreen to be launched immediately *unless* the |
| 992 | // current foreground activity is marked as "immersive". |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 993 | LogUtil.d("StatusBarNotifier.configureFullScreenIntent", "setting fullScreenIntent: " + intent); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 994 | builder.setFullScreenIntent(intent, true); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | private Notification.Builder getNotificationBuilder() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 998 | final Notification.Builder builder = new Notification.Builder(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 999 | builder.setOngoing(true); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1000 | builder.setOnlyAlertOnce(true); |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 1001 | // This will be ignored on O+ and handled by the channel |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1002 | // noinspection deprecation |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 1003 | builder.setPriority(Notification.PRIORITY_HIGH); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1004 | |
| 1005 | return builder; |
| 1006 | } |
| 1007 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1008 | private PendingIntent createLaunchPendingIntent(boolean isFullScreen) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1009 | Intent intent = |
| 1010 | InCallActivity.getIntent( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1011 | context, false /* showDialpad */, false /* newOutgoingCall */, isFullScreen); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1012 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1013 | int requestCode = InCallActivity.PendingIntentRequestCodes.NON_FULL_SCREEN; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1014 | if (isFullScreen) { |
| 1015 | // Use a unique request code so that the pending intent isn't clobbered by the |
| 1016 | // non-full screen pending intent. |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1017 | requestCode = InCallActivity.PendingIntentRequestCodes.FULL_SCREEN; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | // PendingIntent that can be used to launch the InCallActivity. The |
| 1021 | // system fires off this intent if the user pulls down the windowshade |
| 1022 | // and clicks the notification's expanded view. It's also used to |
| 1023 | // launch the InCallActivity immediately when when there's an incoming |
| 1024 | // call (see the "fullScreenIntent" field below). |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1025 | return PendingIntent.getActivity(context, requestCode, intent, 0); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | private void setStatusBarCallListener(StatusBarCallListener listener) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1029 | if (statusBarCallListener != null) { |
| 1030 | statusBarCallListener.cleanup(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1031 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1032 | statusBarCallListener = listener; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1033 | } |
| 1034 | |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 1035 | private boolean hasMultiplePhoneAccounts(DialerCall call) { |
| 1036 | if (call.getCallCapableAccounts() == null) { |
| 1037 | return false; |
| 1038 | } |
| 1039 | return call.getCallCapableAccounts().size() > 1; |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 1042 | @Override |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 1043 | @RequiresPermission(Manifest.permission.READ_PHONE_STATE) |
| 1044 | public void onContactInfoComplete(String callId, ContactCacheEntry entry) { |
| 1045 | DialerCall call = CallList.getInstance().getCallById(callId); |
| 1046 | if (call != null) { |
| 1047 | call.getLogState().contactLookupResult = entry.contactLookupResult; |
| 1048 | buildAndSendNotification(CallList.getInstance(), call, entry); |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | @Override |
| 1053 | @RequiresPermission(Manifest.permission.READ_PHONE_STATE) |
| 1054 | public void onImageLoadComplete(String callId, ContactCacheEntry entry) { |
| 1055 | DialerCall call = CallList.getInstance().getCallById(callId); |
| 1056 | if (call != null) { |
| 1057 | buildAndSendNotification(CallList.getInstance(), call, entry); |
| 1058 | } |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1061 | private class StatusBarCallListener implements DialerCallListener { |
| 1062 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1063 | private DialerCall dialerCall; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1064 | |
| 1065 | StatusBarCallListener(DialerCall dialerCall) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1066 | this.dialerCall = dialerCall; |
| 1067 | this.dialerCall.addListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | void cleanup() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1071 | dialerCall.removeListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | @Override |
| 1075 | public void onDialerCallDisconnect() {} |
| 1076 | |
| 1077 | @Override |
| 1078 | public void onDialerCallUpdate() { |
| 1079 | if (CallList.getInstance().getIncomingCall() == null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1080 | dialerRingtoneManager.stopCallWaitingTone(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | @Override |
| 1085 | public void onDialerCallChildNumberChange() {} |
| 1086 | |
| 1087 | @Override |
| 1088 | public void onDialerCallLastForwardedNumberChange() {} |
| 1089 | |
| 1090 | @Override |
| 1091 | public void onDialerCallUpgradeToVideo() {} |
| 1092 | |
| 1093 | @Override |
| 1094 | public void onWiFiToLteHandover() {} |
| 1095 | |
| 1096 | @Override |
| 1097 | public void onHandoverToWifiFailure() {} |
| 1098 | |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 1099 | @Override |
| 1100 | public void onInternationalCallOnWifi() {} |
| 1101 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1102 | @Override |
| 1103 | public void onEnrichedCallSessionUpdate() {} |
| 1104 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1105 | /** |
| 1106 | * Responds to changes in the session modification state for the call by dismissing the status |
| 1107 | * bar notification as required. |
| 1108 | */ |
| 1109 | @Override |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1110 | public void onDialerCallSessionModificationStateChange() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1111 | if (dialerCall.getVideoTech().getSessionModificationState() |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 1112 | == SessionModificationState.NO_REQUEST) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1113 | cleanup(); |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 1114 | updateNotification(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | } |