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