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