blob: 99ff7255eae88386ec51aa106724105e5ffc0c28 [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -08001/*
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
17package com.android.incallui;
18
Eric Erfanian90508232017-03-24 09:31:16 -070019import static android.telecom.Call.Details.PROPERTY_HIGH_DEF_AUDIO;
Eric Erfanianccca3152017-02-22 16:32:36 -080020import static com.android.contacts.common.compat.CallCompat.Details.PROPERTY_ENTERPRISE_CALL;
21import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ACCEPT_VIDEO_UPGRADE_REQUEST;
erfanian1e4ef182018-06-11 11:05:51 -070022import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ANSWER_SPEAKEASY_CALL;
Eric Erfanianccca3152017-02-22 16:32:36 -080023import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ANSWER_VIDEO_INCOMING_CALL;
24import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ANSWER_VOICE_INCOMING_CALL;
25import static com.android.incallui.NotificationBroadcastReceiver.ACTION_DECLINE_INCOMING_CALL;
26import static com.android.incallui.NotificationBroadcastReceiver.ACTION_DECLINE_VIDEO_UPGRADE_REQUEST;
27import static com.android.incallui.NotificationBroadcastReceiver.ACTION_HANG_UP_ONGOING_CALL;
yuegb26c1ae2017-09-18 16:59:16 -070028import static com.android.incallui.NotificationBroadcastReceiver.ACTION_TURN_OFF_SPEAKER;
29import static com.android.incallui.NotificationBroadcastReceiver.ACTION_TURN_ON_SPEAKER;
Eric Erfanianccca3152017-02-22 16:32:36 -080030
Eric Erfaniand5e47f62017-03-15 14:41:07 -070031import android.Manifest;
Eric Erfanianccca3152017-02-22 16:32:36 -080032import android.app.Notification;
Eric Erfanianccca3152017-02-22 16:32:36 -080033import android.app.PendingIntent;
34import android.content.Context;
35import android.content.Intent;
Eric Erfanian83b20212017-05-31 08:53:10 -070036import android.content.res.Resources;
Eric Erfanianccca3152017-02-22 16:32:36 -080037import android.graphics.Bitmap;
Eric Erfanianccca3152017-02-22 16:32:36 -080038import android.graphics.drawable.BitmapDrawable;
39import android.graphics.drawable.Drawable;
Eric Erfaniand5e47f62017-03-15 14:41:07 -070040import android.graphics.drawable.Icon;
Eric Erfanianccca3152017-02-22 16:32:36 -080041import android.media.AudioAttributes;
42import android.net.Uri;
43import android.os.Build.VERSION;
44import android.os.Build.VERSION_CODES;
wangqicf61ca02017-08-31 15:32:55 -070045import android.os.Trace;
Eric Erfanianccca3152017-02-22 16:32:36 -080046import android.support.annotation.ColorRes;
47import android.support.annotation.NonNull;
48import android.support.annotation.Nullable;
Eric Erfaniand5e47f62017-03-15 14:41:07 -070049import android.support.annotation.RequiresPermission;
Eric Erfanianccca3152017-02-22 16:32:36 -080050import android.support.annotation.StringRes;
51import android.support.annotation.VisibleForTesting;
Eric Erfaniand5e47f62017-03-15 14:41:07 -070052import android.support.v4.os.BuildCompat;
Eric Erfanianccca3152017-02-22 16:32:36 -080053import android.telecom.Call.Details;
yuegb26c1ae2017-09-18 16:59:16 -070054import android.telecom.CallAudioState;
Eric Erfanianccca3152017-02-22 16:32:36 -080055import android.telecom.PhoneAccount;
56import android.telecom.TelecomManager;
roldenburgc14610d2017-10-31 12:51:06 -070057import android.telecom.VideoProfile;
Eric Erfanianccca3152017-02-22 16:32:36 -080058import android.text.BidiFormatter;
59import android.text.Spannable;
60import android.text.SpannableString;
erfanian1e4ef182018-06-11 11:05:51 -070061import android.text.Spanned;
Eric Erfanianccca3152017-02-22 16:32:36 -080062import android.text.TextDirectionHeuristics;
63import android.text.TextUtils;
64import android.text.style.ForegroundColorSpan;
65import com.android.contacts.common.ContactsUtils;
66import com.android.contacts.common.ContactsUtils.UserType;
Eric Erfanian2ca43182017-08-31 06:57:16 -070067import com.android.dialer.common.Assert;
Eric Erfanianccca3152017-02-22 16:32:36 -080068import com.android.dialer.common.LogUtil;
zachh190343a2018-05-31 17:30:46 -070069import com.android.dialer.configprovider.ConfigProviderComponent;
Eric Erfanian2ca43182017-08-31 06:57:16 -070070import com.android.dialer.contactphoto.BitmapUtil;
twyen5578d922018-06-25 12:36:26 -070071import com.android.dialer.contacts.ContactsComponent;
Eric Erfaniand8046e52017-04-06 09:41:50 -070072import com.android.dialer.enrichedcall.EnrichedCallManager;
73import com.android.dialer.enrichedcall.Session;
Eric Erfanian2ca43182017-08-31 06:57:16 -070074import com.android.dialer.lettertile.LetterTileDrawable;
75import com.android.dialer.lettertile.LetterTileDrawable.ContactType;
Eric Erfaniand8046e52017-04-06 09:41:50 -070076import com.android.dialer.multimedia.MultimediaData;
Eric Erfanian2ca43182017-08-31 06:57:16 -070077import com.android.dialer.notification.NotificationChannelId;
Eric Erfanian90508232017-03-24 09:31:16 -070078import com.android.dialer.oem.MotorolaUtils;
calderwoodraa93df432018-05-23 12:59:03 -070079import com.android.dialer.theme.base.ThemeComponent;
Eric Erfanianccca3152017-02-22 16:32:36 -080080import com.android.dialer.util.DrawableConverter;
81import com.android.incallui.ContactInfoCache.ContactCacheEntry;
82import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback;
83import com.android.incallui.InCallPresenter.InCallState;
84import com.android.incallui.async.PausableExecutorImpl;
yuegb26c1ae2017-09-18 16:59:16 -070085import com.android.incallui.audiomode.AudioModeProvider;
Eric Erfanianccca3152017-02-22 16:32:36 -080086import com.android.incallui.call.CallList;
87import com.android.incallui.call.DialerCall;
Eric Erfanianccca3152017-02-22 16:32:36 -080088import com.android.incallui.call.DialerCallListener;
yueg01a964d2017-10-03 15:25:41 -070089import com.android.incallui.call.TelecomAdapter;
wangqibb94ca62018-04-27 14:34:04 -070090import com.android.incallui.call.state.DialerCallState;
Eric Erfanianccca3152017-02-22 16:32:36 -080091import com.android.incallui.ringtone.DialerRingtoneManager;
92import com.android.incallui.ringtone.InCallTonePlayer;
93import com.android.incallui.ringtone.ToneGeneratorFactory;
erfanian1e4ef182018-06-11 11:05:51 -070094import com.android.incallui.speakeasy.SpeakEasyComponent;
Eric Erfanian90508232017-03-24 09:31:16 -070095import com.android.incallui.videotech.utils.SessionModificationState;
Eric Erfanian9d10e642018-07-10 18:48:42 +000096import com.google.common.base.Optional;
Eric Erfanianccca3152017-02-22 16:32:36 -080097import java.util.Objects;
98
99/** This class adds Notifications to the status bar for the in-call experience. */
Eric Erfaniand8046e52017-04-06 09:41:50 -0700100public class StatusBarNotifier
yuegb26c1ae2017-09-18 16:59:16 -0700101 implements InCallPresenter.InCallStateListener,
102 EnrichedCallManager.StateChangedListener,
wangqic8cf79e2017-10-17 09:21:00 -0700103 ContactInfoCacheCallback {
Eric Erfanianccca3152017-02-22 16:32:36 -0800104
Eric Erfanian2ca43182017-08-31 06:57:16 -0700105 private static final int NOTIFICATION_ID = 1;
106
Eric Erfanianccca3152017-02-22 16:32:36 -0800107 // Notification types
108 // Indicates that no notification is currently showing.
109 private static final int NOTIFICATION_NONE = 0;
110 // Notification for an active call. This is non-interruptive, but cannot be dismissed.
Eric Erfanian10b34a52017-05-04 08:23:17 -0700111 private static final int NOTIFICATION_IN_CALL = 1;
Eric Erfanianccca3152017-02-22 16:32:36 -0800112 // Notification for incoming calls. This is interruptive and will show up as a HUN.
Eric Erfanian10b34a52017-05-04 08:23:17 -0700113 private static final int NOTIFICATION_INCOMING_CALL = 2;
114 // Notification for incoming calls in the case where there is already an active call.
115 // This is non-interruptive, but otherwise behaves the same as NOTIFICATION_INCOMING_CALL
116 private static final int NOTIFICATION_INCOMING_CALL_QUIET = 3;
Eric Erfanianccca3152017-02-22 16:32:36 -0800117
Eric Erfanianccca3152017-02-22 16:32:36 -0800118 private static final long[] VIBRATE_PATTERN = new long[] {0, 1000, 1000};
119
linyuh183cb712017-12-27 17:02:37 -0800120 private final Context context;
121 private final ContactInfoCache contactInfoCache;
122 private final DialerRingtoneManager dialerRingtoneManager;
linyuh183cb712017-12-27 17:02:37 -0800123 private int currentNotification = NOTIFICATION_NONE;
wangqibb94ca62018-04-27 14:34:04 -0700124 private int callState = DialerCallState.INVALID;
linyuh183cb712017-12-27 17:02:37 -0800125 private int videoState = VideoProfile.STATE_AUDIO_ONLY;
126 private int savedIcon = 0;
127 private String savedContent = null;
128 private Bitmap savedLargeIcon;
129 private String savedContentTitle;
yuegb26c1ae2017-09-18 16:59:16 -0700130 private CallAudioState savedCallAudioState;
linyuh183cb712017-12-27 17:02:37 -0800131 private Uri ringtone;
132 private StatusBarCallListener statusBarCallListener;
Eric Erfanianccca3152017-02-22 16:32:36 -0800133
Eric Erfaniand8046e52017-04-06 09:41:50 -0700134 public StatusBarNotifier(@NonNull Context context, @NonNull ContactInfoCache contactInfoCache) {
wangqic8cf79e2017-10-17 09:21:00 -0700135 Trace.beginSection("StatusBarNotifier.Constructor");
linyuh183cb712017-12-27 17:02:37 -0800136 this.context = Assert.isNotNull(context);
linyuh183cb712017-12-27 17:02:37 -0800137 this.contactInfoCache = contactInfoCache;
138 dialerRingtoneManager =
Eric Erfanianccca3152017-02-22 16:32:36 -0800139 new DialerRingtoneManager(
140 new InCallTonePlayer(new ToneGeneratorFactory(), new PausableExecutorImpl()),
141 CallList.getInstance());
linyuh183cb712017-12-27 17:02:37 -0800142 currentNotification = NOTIFICATION_NONE;
wangqic8cf79e2017-10-17 09:21:00 -0700143 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800144 }
145
146 /**
147 * Should only be called from a irrecoverable state where it is necessary to dismiss all
148 * notifications.
149 */
yueg01a964d2017-10-03 15:25:41 -0700150 static void clearAllCallNotifications() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700151 LogUtil.e(
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700152 "StatusBarNotifier.clearAllCallNotifications",
153 "something terrible happened, clear all InCall notifications");
Eric Erfanianccca3152017-02-22 16:32:36 -0800154
yueg01a964d2017-10-03 15:25:41 -0700155 TelecomAdapter.getInstance().stopForegroundNotification();
Eric Erfanianccca3152017-02-22 16:32:36 -0800156 }
157
158 private static int getWorkStringFromPersonalString(int resId) {
159 if (resId == R.string.notification_ongoing_call) {
160 return R.string.notification_ongoing_work_call;
Eric Erfanianccca3152017-02-22 16:32:36 -0800161 } else if (resId == R.string.notification_incoming_call) {
162 return R.string.notification_incoming_work_call;
163 } else {
164 return resId;
165 }
166 }
167
168 /**
169 * Returns PendingIntent for answering a phone call. This will typically be used from Notification
170 * context.
171 */
172 private static PendingIntent createNotificationPendingIntent(Context context, String action) {
173 final Intent intent = new Intent(action, null, context, NotificationBroadcastReceiver.class);
174 return PendingIntent.getBroadcast(context, 0, intent, 0);
175 }
176
177 /** Creates notifications according to the state we receive from {@link InCallPresenter}. */
178 @Override
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700179 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
Eric Erfanianccca3152017-02-22 16:32:36 -0800180 public void onStateChange(InCallState oldState, InCallState newState, CallList callList) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700181 LogUtil.d("StatusBarNotifier.onStateChange", "%s->%s", oldState, newState);
wangqic8cf79e2017-10-17 09:21:00 -0700182 updateNotification();
Eric Erfanianccca3152017-02-22 16:32:36 -0800183 }
184
Eric Erfaniand8046e52017-04-06 09:41:50 -0700185 @Override
186 public void onEnrichedCallStateChanged() {
187 LogUtil.enterBlock("StatusBarNotifier.onEnrichedCallStateChanged");
wangqic8cf79e2017-10-17 09:21:00 -0700188 updateNotification();
Eric Erfaniand8046e52017-04-06 09:41:50 -0700189 }
190
Eric Erfanianccca3152017-02-22 16:32:36 -0800191 /**
192 * Updates the phone app's status bar notification *and* launches the incoming call UI in response
193 * to a new incoming call.
194 *
195 * <p>If an incoming call is ringing (or call-waiting), the notification will also include a
196 * "fullScreenIntent" that will cause the InCallScreen to be launched, unless the current
197 * foreground activity is marked as "immersive".
198 *
199 * <p>(This is the mechanism that actually brings up the incoming call UI when we receive a "new
200 * ringing connection" event from the telephony layer.)
201 *
202 * <p>Also note that this method is safe to call even if the phone isn't actually ringing (or,
203 * more likely, if an incoming call *was* ringing briefly but then disconnected). In that case,
204 * we'll simply update or cancel the in-call notification based on the current phone state.
205 *
wangqic8cf79e2017-10-17 09:21:00 -0700206 * @see #updateInCallNotification()
Eric Erfanianccca3152017-02-22 16:32:36 -0800207 */
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700208 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
wangqic8cf79e2017-10-17 09:21:00 -0700209 public void updateNotification() {
210 updateInCallNotification();
Eric Erfanianccca3152017-02-22 16:32:36 -0800211 }
212
213 /**
214 * Take down the in-call notification.
215 *
wangqic8cf79e2017-10-17 09:21:00 -0700216 * @see #updateInCallNotification()
Eric Erfanianccca3152017-02-22 16:32:36 -0800217 */
218 private void cancelNotification() {
linyuh183cb712017-12-27 17:02:37 -0800219 if (statusBarCallListener != null) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800220 setStatusBarCallListener(null);
221 }
linyuh183cb712017-12-27 17:02:37 -0800222 if (currentNotification != NOTIFICATION_NONE) {
yueg01a964d2017-10-03 15:25:41 -0700223 TelecomAdapter.getInstance().stopForegroundNotification();
linyuh183cb712017-12-27 17:02:37 -0800224 currentNotification = NOTIFICATION_NONE;
Eric Erfanianccca3152017-02-22 16:32:36 -0800225 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800226 }
227
228 /**
229 * Helper method for updateInCallNotification() and updateNotification(): Update the phone app's
230 * status bar notification based on the current telephony state, or cancels the notification if
231 * the phone is totally idle.
232 */
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700233 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
wangqic8cf79e2017-10-17 09:21:00 -0700234 private void updateInCallNotification() {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700235 LogUtil.d("StatusBarNotifier.updateInCallNotification", "");
Eric Erfanianccca3152017-02-22 16:32:36 -0800236
wangqic8cf79e2017-10-17 09:21:00 -0700237 final DialerCall call = getCallToShow(CallList.getInstance());
Eric Erfanianccca3152017-02-22 16:32:36 -0800238
239 if (call != null) {
wangqic8cf79e2017-10-17 09:21:00 -0700240 showNotification(call);
Eric Erfanianccca3152017-02-22 16:32:36 -0800241 } else {
242 cancelNotification();
243 }
244 }
245
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700246 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
wangqic8cf79e2017-10-17 09:21:00 -0700247 private void showNotification(final DialerCall call) {
wangqicf61ca02017-08-31 15:32:55 -0700248 Trace.beginSection("StatusBarNotifier.showNotification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800249 final boolean isIncoming =
wangqibb94ca62018-04-27 14:34:04 -0700250 (call.getState() == DialerCallState.INCOMING
251 || call.getState() == DialerCallState.CALL_WAITING);
Eric Erfanianccca3152017-02-22 16:32:36 -0800252 setStatusBarCallListener(new StatusBarCallListener(call));
253
254 // we make a call to the contact info cache to query for supplemental data to what the
255 // call provides. This includes the contact name and photo.
256 // This callback will always get called immediately and synchronously with whatever data
257 // it has available, and may make a subsequent call later (same thread) if it had to
258 // call into the contacts provider for more data.
linyuh183cb712017-12-27 17:02:37 -0800259 contactInfoCache.findInfo(call, isIncoming, this);
wangqicf61ca02017-08-31 15:32:55 -0700260 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800261 }
262
263 /** Sets up the main Ui for the notification */
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700264 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
Eric Erfanianccca3152017-02-22 16:32:36 -0800265 private void buildAndSendNotification(
266 CallList callList, DialerCall originalCall, ContactCacheEntry contactInfo) {
wangqicf61ca02017-08-31 15:32:55 -0700267 Trace.beginSection("StatusBarNotifier.buildAndSendNotification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800268 // This can get called to update an existing notification after contact information has come
269 // back. However, it can happen much later. Before we continue, we need to make sure that
270 // the call being passed in is still the one we want to show in the notification.
271 final DialerCall call = getCallToShow(callList);
272 if (call == null || !call.getId().equals(originalCall.getId())) {
wangqicf61ca02017-08-31 15:32:55 -0700273 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800274 return;
275 }
276
wangqicf61ca02017-08-31 15:32:55 -0700277 Trace.beginSection("prepare work");
Eric Erfanianccca3152017-02-22 16:32:36 -0800278 final int callState = call.getState();
yuegb26c1ae2017-09-18 16:59:16 -0700279 final CallAudioState callAudioState = AudioModeProvider.getInstance().getAudioState();
Eric Erfanianccca3152017-02-22 16:32:36 -0800280
wangqic8cf79e2017-10-17 09:21:00 -0700281 Trace.beginSection("read icon and strings");
Eric Erfanianccca3152017-02-22 16:32:36 -0800282 // Check if data has changed; if nothing is different, don't issue another notification.
283 final int iconResId = getIconToDisplay(call);
linyuh183cb712017-12-27 17:02:37 -0800284 Bitmap largeIcon = getLargeIconToDisplay(context, contactInfo, call);
twyend1d1d0c2017-10-05 17:34:43 -0700285 final CharSequence content = getContentString(call, contactInfo.userType);
Eric Erfanianccca3152017-02-22 16:32:36 -0800286 final String contentTitle = getContentTitle(contactInfo, call);
wangqic8cf79e2017-10-17 09:21:00 -0700287 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800288
289 final boolean isVideoUpgradeRequest =
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700290 call.getVideoTech().getSessionModificationState()
Eric Erfanian90508232017-03-24 09:31:16 -0700291 == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST;
Eric Erfanianccca3152017-02-22 16:32:36 -0800292 final int notificationType;
wangqibb94ca62018-04-27 14:34:04 -0700293 if (callState == DialerCallState.INCOMING
294 || callState == DialerCallState.CALL_WAITING
Eric Erfanianccca3152017-02-22 16:32:36 -0800295 || isVideoUpgradeRequest) {
zachh190343a2018-05-31 17:30:46 -0700296 if (ConfigProviderComponent.get(context)
297 .getConfigProvider()
Eric Erfanian2ca43182017-08-31 06:57:16 -0700298 .getBoolean("quiet_incoming_call_if_ui_showing", true)) {
299 notificationType =
300 InCallPresenter.getInstance().isShowingInCallUi()
301 ? NOTIFICATION_INCOMING_CALL_QUIET
302 : NOTIFICATION_INCOMING_CALL;
303 } else {
304 boolean alreadyActive =
305 callList.getActiveOrBackgroundCall() != null
306 && InCallPresenter.getInstance().isShowingInCallUi();
307 notificationType =
308 alreadyActive ? NOTIFICATION_INCOMING_CALL_QUIET : NOTIFICATION_INCOMING_CALL;
309 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800310 } else {
311 notificationType = NOTIFICATION_IN_CALL;
312 }
wangqicf61ca02017-08-31 15:32:55 -0700313 Trace.endSection(); // prepare work
Eric Erfanianccca3152017-02-22 16:32:36 -0800314
315 if (!checkForChangeAndSaveData(
316 iconResId,
twyend1d1d0c2017-10-05 17:34:43 -0700317 content.toString(),
Eric Erfanianccca3152017-02-22 16:32:36 -0800318 largeIcon,
319 contentTitle,
320 callState,
roldenburgc14610d2017-10-31 12:51:06 -0700321 call.getVideoState(),
Eric Erfanianccca3152017-02-22 16:32:36 -0800322 notificationType,
yuegb26c1ae2017-09-18 16:59:16 -0700323 contactInfo.contactRingtoneUri,
324 callAudioState)) {
wangqicf61ca02017-08-31 15:32:55 -0700325 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800326 return;
327 }
328
329 if (largeIcon != null) {
330 largeIcon = getRoundedIcon(largeIcon);
331 }
332
333 // This builder is used for the notification shown when the device is locked and the user
334 // has set their notification settings to 'hide sensitive content'
335 // {@see Notification.Builder#setPublicVersion}.
linyuh183cb712017-12-27 17:02:37 -0800336 Notification.Builder publicBuilder = new Notification.Builder(context);
Eric Erfanianccca3152017-02-22 16:32:36 -0800337 publicBuilder
338 .setSmallIcon(iconResId)
calderwoodraa93df432018-05-23 12:59:03 -0700339 .setColor(ThemeComponent.get(context).theme().getColorPrimary())
Eric Erfanianccca3152017-02-22 16:32:36 -0800340 // Hide work call state for the lock screen notification
341 .setContentTitle(getContentString(call, ContactsUtils.USER_TYPE_CURRENT));
342 setNotificationWhen(call, callState, publicBuilder);
343
344 // Builder for the notification shown when the device is unlocked or the user has set their
345 // notification settings to 'show all notification content'.
346 final Notification.Builder builder = getNotificationBuilder();
347 builder.setPublicVersion(publicBuilder.build());
348
349 // Set up the main intent to send the user to the in-call screen
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700350 builder.setContentIntent(createLaunchPendingIntent(false /* isFullScreen */));
Eric Erfanianccca3152017-02-22 16:32:36 -0800351
Eric Erfanian10b34a52017-05-04 08:23:17 -0700352 LogUtil.i("StatusBarNotifier.buildAndSendNotification", "notificationType=" + notificationType);
353 switch (notificationType) {
354 case NOTIFICATION_INCOMING_CALL:
Eric Erfanian2ca43182017-08-31 06:57:16 -0700355 if (BuildCompat.isAtLeastO()) {
356 builder.setChannelId(NotificationChannelId.INCOMING_CALL);
357 }
wangqic8cf79e2017-10-17 09:21:00 -0700358 // Set the intent as a full screen intent as well if a call is incoming
Eric Erfanian10b34a52017-05-04 08:23:17 -0700359 configureFullScreenIntent(builder, createLaunchPendingIntent(true /* isFullScreen */));
360 // Set the notification category and bump the priority for incoming calls
361 builder.setCategory(Notification.CATEGORY_CALL);
362 // This will be ignored on O+ and handled by the channel
Eric Erfanian10b34a52017-05-04 08:23:17 -0700363 builder.setPriority(Notification.PRIORITY_MAX);
linyuh183cb712017-12-27 17:02:37 -0800364 if (currentNotification != NOTIFICATION_INCOMING_CALL) {
Eric Erfanian10b34a52017-05-04 08:23:17 -0700365 LogUtil.i(
366 "StatusBarNotifier.buildAndSendNotification",
367 "Canceling old notification so this one can be noisy");
368 // Moving from a non-interuptive notification (or none) to a noisy one. Cancel the old
369 // notification (if there is one) so the fullScreenIntent or HUN will show
yueg01a964d2017-10-03 15:25:41 -0700370 TelecomAdapter.getInstance().stopForegroundNotification();
Eric Erfanian10b34a52017-05-04 08:23:17 -0700371 }
372 break;
373 case NOTIFICATION_INCOMING_CALL_QUIET:
Eric Erfanian2ca43182017-08-31 06:57:16 -0700374 if (BuildCompat.isAtLeastO()) {
375 builder.setChannelId(NotificationChannelId.ONGOING_CALL);
376 }
Eric Erfanian10b34a52017-05-04 08:23:17 -0700377 break;
378 case NOTIFICATION_IN_CALL:
Eric Erfanian2ca43182017-08-31 06:57:16 -0700379 if (BuildCompat.isAtLeastO()) {
380 publicBuilder.setColorized(true);
381 builder.setColorized(true);
382 builder.setChannelId(NotificationChannelId.ONGOING_CALL);
383 }
384 break;
385 default:
Eric Erfanian10b34a52017-05-04 08:23:17 -0700386 break;
Eric Erfanianccca3152017-02-22 16:32:36 -0800387 }
388
389 // Set the content
390 builder.setContentText(content);
391 builder.setSmallIcon(iconResId);
392 builder.setContentTitle(contentTitle);
393 builder.setLargeIcon(largeIcon);
yueg01a964d2017-10-03 15:25:41 -0700394 builder.setColor(InCallPresenter.getInstance().getThemeColorManager().getPrimaryColor());
Eric Erfanianccca3152017-02-22 16:32:36 -0800395
396 if (isVideoUpgradeRequest) {
397 builder.setUsesChronometer(false);
398 addDismissUpgradeRequestAction(builder);
399 addAcceptUpgradeRequestAction(builder);
400 } else {
yuegb26c1ae2017-09-18 16:59:16 -0700401 createIncomingCallNotification(call, callState, callAudioState, builder);
Eric Erfanianccca3152017-02-22 16:32:36 -0800402 }
403
404 addPersonReference(builder, contactInfo, call);
405
wangqicf61ca02017-08-31 15:32:55 -0700406 Trace.beginSection("fire notification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800407 // Fire off the notification
408 Notification notification = builder.build();
409
linyuh183cb712017-12-27 17:02:37 -0800410 if (dialerRingtoneManager.shouldPlayRingtone(callState, contactInfo.contactRingtoneUri)) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800411 notification.flags |= Notification.FLAG_INSISTENT;
412 notification.sound = contactInfo.contactRingtoneUri;
413 AudioAttributes.Builder audioAttributes = new AudioAttributes.Builder();
414 audioAttributes.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC);
415 audioAttributes.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE);
416 notification.audioAttributes = audioAttributes.build();
linyuh183cb712017-12-27 17:02:37 -0800417 if (dialerRingtoneManager.shouldVibrate(context.getContentResolver())) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800418 notification.vibrate = VIBRATE_PATTERN;
419 }
420 }
linyuh183cb712017-12-27 17:02:37 -0800421 if (dialerRingtoneManager.shouldPlayCallWaitingTone(callState)) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700422 LogUtil.v("StatusBarNotifier.buildAndSendNotification", "playing call waiting tone");
linyuh183cb712017-12-27 17:02:37 -0800423 dialerRingtoneManager.playCallWaitingTone();
Eric Erfanianccca3152017-02-22 16:32:36 -0800424 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800425
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700426 LogUtil.i(
427 "StatusBarNotifier.buildAndSendNotification",
428 "displaying notification for " + notificationType);
429
yueg01a964d2017-10-03 15:25:41 -0700430 // If a notification exists, this will only update it.
431 TelecomAdapter.getInstance().startForegroundNotification(NOTIFICATION_ID, notification);
432
wangqicf61ca02017-08-31 15:32:55 -0700433 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800434 call.getLatencyReport().onNotificationShown();
linyuh183cb712017-12-27 17:02:37 -0800435 currentNotification = notificationType;
wangqicf61ca02017-08-31 15:32:55 -0700436 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800437 }
438
439 private void createIncomingCallNotification(
yuegb26c1ae2017-09-18 16:59:16 -0700440 DialerCall call, int state, CallAudioState callAudioState, Notification.Builder builder) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800441 setNotificationWhen(call, state, builder);
442
443 // Add hang up option for any active calls (active | onhold), outgoing calls (dialing).
wangqibb94ca62018-04-27 14:34:04 -0700444 if (state == DialerCallState.ACTIVE
445 || state == DialerCallState.ONHOLD
446 || DialerCallState.isDialing(state)) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800447 addHangupAction(builder);
yuegb26c1ae2017-09-18 16:59:16 -0700448 addSpeakerAction(builder, callAudioState);
wangqibb94ca62018-04-27 14:34:04 -0700449 } else if (state == DialerCallState.INCOMING || state == DialerCallState.CALL_WAITING) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800450 addDismissAction(builder);
451 if (call.isVideoCall()) {
452 addVideoCallAction(builder);
453 } else {
454 addAnswerAction(builder);
erfanian94a7b3b2018-06-19 14:36:18 -0700455 addSpeakeasyAnswerAction(builder, call);
Eric Erfanianccca3152017-02-22 16:32:36 -0800456 }
457 }
458 }
459
460 /**
461 * Sets the notification's when section as needed. For active calls, this is explicitly set as the
462 * duration of the call. For all other states, the notification will automatically show the time
463 * at which the notification was created.
464 */
465 private void setNotificationWhen(DialerCall call, int state, Notification.Builder builder) {
wangqibb94ca62018-04-27 14:34:04 -0700466 if (state == DialerCallState.ACTIVE) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800467 builder.setUsesChronometer(true);
468 builder.setWhen(call.getConnectTimeMillis());
469 } else {
470 builder.setUsesChronometer(false);
471 }
472 }
473
474 /**
475 * Checks the new notification data and compares it against any notification that we are already
476 * displaying. If the data is exactly the same, we return false so that we do not issue a new
477 * notification for the exact same data.
478 */
479 private boolean checkForChangeAndSaveData(
480 int icon,
481 String content,
482 Bitmap largeIcon,
483 String contentTitle,
484 int state,
roldenburgc14610d2017-10-31 12:51:06 -0700485 int videoState,
Eric Erfanianccca3152017-02-22 16:32:36 -0800486 int notificationType,
yuegb26c1ae2017-09-18 16:59:16 -0700487 Uri ringtone,
488 CallAudioState callAudioState) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800489
490 // The two are different:
491 // if new title is not null, it should be different from saved version OR
492 // if new title is null, the saved version should not be null
493 final boolean contentTitleChanged =
linyuh183cb712017-12-27 17:02:37 -0800494 (contentTitle != null && !contentTitle.equals(savedContentTitle))
495 || (contentTitle == null && savedContentTitle != null);
Eric Erfanianccca3152017-02-22 16:32:36 -0800496
roldenburgc14610d2017-10-31 12:51:06 -0700497 boolean largeIconChanged;
linyuh183cb712017-12-27 17:02:37 -0800498 if (savedLargeIcon == null) {
roldenburgc14610d2017-10-31 12:51:06 -0700499 largeIconChanged = largeIcon != null;
500 } else {
linyuh183cb712017-12-27 17:02:37 -0800501 largeIconChanged = largeIcon == null || !savedLargeIcon.sameAs(largeIcon);
roldenburgc14610d2017-10-31 12:51:06 -0700502 }
Eric Erfanian8369df02017-05-03 10:27:13 -0700503
Eric Erfanianccca3152017-02-22 16:32:36 -0800504 // any change means we are definitely updating
505 boolean retval =
linyuh183cb712017-12-27 17:02:37 -0800506 (savedIcon != icon)
507 || !Objects.equals(savedContent, content)
508 || (callState != state)
509 || (this.videoState != videoState)
Eric Erfanian8369df02017-05-03 10:27:13 -0700510 || largeIconChanged
Eric Erfanianccca3152017-02-22 16:32:36 -0800511 || contentTitleChanged
linyuh183cb712017-12-27 17:02:37 -0800512 || !Objects.equals(this.ringtone, ringtone)
yuegb26c1ae2017-09-18 16:59:16 -0700513 || !Objects.equals(savedCallAudioState, callAudioState);
Eric Erfanianccca3152017-02-22 16:32:36 -0800514
wangqi9982f0d2017-10-11 17:46:07 -0700515 LogUtil.d(
516 "StatusBarNotifier.checkForChangeAndSaveData",
roldenburgc14610d2017-10-31 12:51:06 -0700517 "data changed: icon: %b, content: %b, state: %b, videoState: %b, largeIcon: %b, title: %b,"
518 + "ringtone: %b, audioState: %b, type: %b",
linyuh183cb712017-12-27 17:02:37 -0800519 (savedIcon != icon),
520 !Objects.equals(savedContent, content),
521 (callState != state),
522 (this.videoState != videoState),
wangqi9982f0d2017-10-11 17:46:07 -0700523 largeIconChanged,
524 contentTitleChanged,
linyuh183cb712017-12-27 17:02:37 -0800525 !Objects.equals(this.ringtone, ringtone),
wangqi9982f0d2017-10-11 17:46:07 -0700526 !Objects.equals(savedCallAudioState, callAudioState),
linyuh183cb712017-12-27 17:02:37 -0800527 currentNotification != notificationType);
Eric Erfanianccca3152017-02-22 16:32:36 -0800528 // If we aren't showing a notification right now or the notification type is changing,
529 // definitely do an update.
linyuh183cb712017-12-27 17:02:37 -0800530 if (currentNotification != notificationType) {
531 if (currentNotification == NOTIFICATION_NONE) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700532 LogUtil.d(
533 "StatusBarNotifier.checkForChangeAndSaveData", "showing notification for first time.");
Eric Erfanianccca3152017-02-22 16:32:36 -0800534 }
535 retval = true;
536 }
537
linyuh183cb712017-12-27 17:02:37 -0800538 savedIcon = icon;
539 savedContent = content;
540 callState = state;
541 this.videoState = videoState;
542 savedLargeIcon = largeIcon;
543 savedContentTitle = contentTitle;
544 this.ringtone = ringtone;
yuegb26c1ae2017-09-18 16:59:16 -0700545 savedCallAudioState = callAudioState;
Eric Erfanianccca3152017-02-22 16:32:36 -0800546
547 if (retval) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700548 LogUtil.d(
549 "StatusBarNotifier.checkForChangeAndSaveData", "data changed. Showing notification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800550 }
551
552 return retval;
553 }
554
555 /** Returns the main string to use in the notification. */
556 @VisibleForTesting
557 @Nullable
558 String getContentTitle(ContactCacheEntry contactInfo, DialerCall call) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700559 if (call.isConferenceCall()) {
560 return CallerInfoUtils.getConferenceString(
linyuh183cb712017-12-27 17:02:37 -0800561 context, call.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE));
Eric Erfanianccca3152017-02-22 16:32:36 -0800562 }
563
564 String preferredName =
twyen5578d922018-06-25 12:36:26 -0700565 ContactsComponent.get(context)
566 .contactDisplayPreferences()
567 .getDisplayName(contactInfo.namePrimary, contactInfo.nameAlternative);
Eric Erfanianccca3152017-02-22 16:32:36 -0800568 if (TextUtils.isEmpty(preferredName)) {
569 return TextUtils.isEmpty(contactInfo.number)
570 ? null
571 : BidiFormatter.getInstance()
572 .unicodeWrap(contactInfo.number, TextDirectionHeuristics.LTR);
573 }
574 return preferredName;
575 }
576
577 private void addPersonReference(
578 Notification.Builder builder, ContactCacheEntry contactInfo, DialerCall call) {
579 // Query {@link Contacts#CONTENT_LOOKUP_URI} directly with work lookup key is not allowed.
580 // So, do not pass {@link Contacts#CONTENT_LOOKUP_URI} to NotificationManager to avoid
581 // NotificationManager using it.
582 if (contactInfo.lookupUri != null && contactInfo.userType != ContactsUtils.USER_TYPE_WORK) {
583 builder.addPerson(contactInfo.lookupUri.toString());
584 } else if (!TextUtils.isEmpty(call.getNumber())) {
585 builder.addPerson(Uri.fromParts(PhoneAccount.SCHEME_TEL, call.getNumber(), null).toString());
586 }
587 }
588
589 /** Gets a large icon from the contact info object to display in the notification. */
Eric Erfanian83b20212017-05-31 08:53:10 -0700590 private static Bitmap getLargeIconToDisplay(
591 Context context, ContactCacheEntry contactInfo, DialerCall call) {
wangqic8cf79e2017-10-17 09:21:00 -0700592 Trace.beginSection("StatusBarNotifier.getLargeIconToDisplay");
Eric Erfanian83b20212017-05-31 08:53:10 -0700593 Resources resources = context.getResources();
Eric Erfanianccca3152017-02-22 16:32:36 -0800594 Bitmap largeIcon = null;
Eric Erfanianccca3152017-02-22 16:32:36 -0800595 if (contactInfo.photo != null && (contactInfo.photo instanceof BitmapDrawable)) {
596 largeIcon = ((BitmapDrawable) contactInfo.photo).getBitmap();
597 }
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700598 if (contactInfo.photo == null) {
Eric Erfanian83b20212017-05-31 08:53:10 -0700599 int width = (int) resources.getDimension(android.R.dimen.notification_large_icon_width);
600 int height = (int) resources.getDimension(android.R.dimen.notification_large_icon_height);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700601 @ContactType
602 int contactType =
603 LetterTileDrawable.getContactTypeFromPrimitives(
wangqi9982f0d2017-10-11 17:46:07 -0700604 call.isVoiceMailNumber(),
Eric Erfanian2ca43182017-08-31 06:57:16 -0700605 call.isSpam(),
606 contactInfo.isBusiness,
607 call.getNumberPresentation(),
608 call.isConferenceCall() && !call.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE));
Eric Erfanian83b20212017-05-31 08:53:10 -0700609 LetterTileDrawable lettertile = new LetterTileDrawable(resources);
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700610
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700611 lettertile.setCanonicalDialerLetterTileDetails(
612 contactInfo.namePrimary == null ? contactInfo.number : contactInfo.namePrimary,
613 contactInfo.lookupKey,
614 LetterTileDrawable.SHAPE_CIRCLE,
615 contactType);
616 largeIcon = lettertile.getBitmap(width, height);
617 }
618
Eric Erfanianccca3152017-02-22 16:32:36 -0800619 if (call.isSpam()) {
Eric Erfanian83b20212017-05-31 08:53:10 -0700620 Drawable drawable = resources.getDrawable(R.drawable.blocked_contact, context.getTheme());
Eric Erfanianccca3152017-02-22 16:32:36 -0800621 largeIcon = DrawableConverter.drawableToBitmap(drawable);
622 }
wangqic8cf79e2017-10-17 09:21:00 -0700623 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800624 return largeIcon;
625 }
626
627 private Bitmap getRoundedIcon(Bitmap bitmap) {
628 if (bitmap == null) {
629 return null;
630 }
631 final int height =
linyuh183cb712017-12-27 17:02:37 -0800632 (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_height);
Eric Erfanianccca3152017-02-22 16:32:36 -0800633 final int width =
linyuh183cb712017-12-27 17:02:37 -0800634 (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_width);
Eric Erfanianccca3152017-02-22 16:32:36 -0800635 return BitmapUtil.getRoundedBitmap(bitmap, width, height);
636 }
637
638 /**
639 * Returns the appropriate icon res Id to display based on the call for which we want to display
640 * information.
641 */
Eric Erfanian2827dd12017-10-26 09:37:50 -0700642 @VisibleForTesting
643 public int getIconToDisplay(DialerCall call) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800644 // Even if both lines are in use, we only show a single item in
645 // the expanded Notifications UI. It's labeled "Ongoing call"
646 // (or "On hold" if there's only one call, and it's on hold.)
647 // Also, we don't have room to display caller-id info from two
648 // different calls. So if both lines are in use, display info
649 // from the foreground call. And if there's a ringing call,
650 // display that regardless of the state of the other calls.
wangqibb94ca62018-04-27 14:34:04 -0700651 if (call.getState() == DialerCallState.ONHOLD) {
Eric Erfanian2827dd12017-10-26 09:37:50 -0700652 return R.drawable.quantum_ic_phone_paused_vd_theme_24;
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700653 } else if (call.getVideoTech().getSessionModificationState()
calderwoodra1dc2cea2017-09-20 16:30:41 -0700654 == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST
655 || call.isVideoCall()) {
linyuh8dc242d2018-03-28 13:09:47 -0700656 return R.drawable.quantum_ic_videocam_vd_white_24;
Eric Erfanian90508232017-03-24 09:31:16 -0700657 } else if (call.hasProperty(PROPERTY_HIGH_DEF_AUDIO)
linyuh183cb712017-12-27 17:02:37 -0800658 && MotorolaUtils.shouldShowHdIconInNotification(context)) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700659 // Normally when a call is ongoing the status bar displays an icon of a phone. This is a
660 // helpful hint for users so they know how to get back to the call. For Sprint HD calls, we
661 // replace this icon with an icon of a phone with a HD badge. This is a carrier requirement.
Eric Erfanian90508232017-03-24 09:31:16 -0700662 return R.drawable.ic_hd_call;
Eric Erfanian2827dd12017-10-26 09:37:50 -0700663 } else if (call.hasProperty(Details.PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
664 return R.drawable.quantum_ic_phone_locked_vd_theme_24;
Eric Erfanianccca3152017-02-22 16:32:36 -0800665 }
yueg48f93f42018-03-09 16:49:38 -0800666 // If ReturnToCall is enabled, use the static icon. The animated one will show in the bubble.
667 if (ReturnToCallController.isEnabled(context)) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700668 return R.drawable.quantum_ic_call_vd_theme_24;
669 } else {
670 return R.drawable.on_going_call;
671 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800672 }
673
674 /** Returns the message to use with the notification. */
twyend1d1d0c2017-10-05 17:34:43 -0700675 private CharSequence getContentString(DialerCall call, @UserType long userType) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800676 boolean isIncomingOrWaiting =
wangqibb94ca62018-04-27 14:34:04 -0700677 call.getState() == DialerCallState.INCOMING
678 || call.getState() == DialerCallState.CALL_WAITING;
Eric Erfanianccca3152017-02-22 16:32:36 -0800679
680 if (isIncomingOrWaiting
681 && call.getNumberPresentation() == TelecomManager.PRESENTATION_ALLOWED) {
682
683 if (!TextUtils.isEmpty(call.getChildNumber())) {
linyuh183cb712017-12-27 17:02:37 -0800684 return context.getString(R.string.child_number, call.getChildNumber());
Eric Erfanianccca3152017-02-22 16:32:36 -0800685 } else if (!TextUtils.isEmpty(call.getCallSubject()) && call.isCallSubjectSupported()) {
686 return call.getCallSubject();
687 }
688 }
689
690 int resId = R.string.notification_ongoing_call;
linyuh183cb712017-12-27 17:02:37 -0800691 String wifiBrand = context.getString(R.string.notification_call_wifi_brand);
Eric Erfanianccca3152017-02-22 16:32:36 -0800692 if (call.hasProperty(Details.PROPERTY_WIFI)) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700693 resId = R.string.notification_ongoing_call_wifi_template;
Eric Erfanianccca3152017-02-22 16:32:36 -0800694 }
695
696 if (isIncomingOrWaiting) {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700697 if (call.isSpam()) {
698 resId = R.string.notification_incoming_spam_call;
Eric Erfanian2ca43182017-08-31 06:57:16 -0700699 } else if (shouldShowEnrichedCallNotification(call.getEnrichedCallSession())) {
700 resId = getECIncomingCallText(call.getEnrichedCallSession());
Eric Erfaniand8046e52017-04-06 09:41:50 -0700701 } else if (call.hasProperty(Details.PROPERTY_WIFI)) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700702 resId = R.string.notification_incoming_call_wifi_template;
wangqi9982f0d2017-10-11 17:46:07 -0700703 } else if (call.getAccountHandle() != null && hasMultiplePhoneAccounts(call)) {
twyend1d1d0c2017-10-05 17:34:43 -0700704 return getMultiSimIncomingText(call);
yueg45e45732017-10-09 14:35:06 -0700705 } else if (call.isVideoCall()) {
706 resId = R.string.notification_incoming_video_call;
Eric Erfanianccca3152017-02-22 16:32:36 -0800707 } else {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700708 resId = R.string.notification_incoming_call;
Eric Erfanianccca3152017-02-22 16:32:36 -0800709 }
wangqibb94ca62018-04-27 14:34:04 -0700710 } else if (call.getState() == DialerCallState.ONHOLD) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800711 resId = R.string.notification_on_hold;
Qiong Liu706e4ae2018-06-26 15:56:44 +0800712 } else if (DialerCallState.isDialing(call.getState())) {
713 resId = R.string.notification_dialing;
calderwoodra1dc2cea2017-09-20 16:30:41 -0700714 } else if (call.isVideoCall()) {
715 resId =
716 call.getVideoTech().isPaused()
717 ? R.string.notification_ongoing_paused_video_call
718 : R.string.notification_ongoing_video_call;
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700719 } else if (call.getVideoTech().getSessionModificationState()
Eric Erfanian90508232017-03-24 09:31:16 -0700720 == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800721 resId = R.string.notification_requesting_video_call;
722 }
723
724 // Is the call placed through work connection service.
725 boolean isWorkCall = call.hasProperty(PROPERTY_ENTERPRISE_CALL);
726 if (userType == ContactsUtils.USER_TYPE_WORK || isWorkCall) {
727 resId = getWorkStringFromPersonalString(resId);
linyuh183cb712017-12-27 17:02:37 -0800728 wifiBrand = context.getString(R.string.notification_call_wifi_work_brand);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700729 }
730
731 if (resId == R.string.notification_incoming_call_wifi_template
732 || resId == R.string.notification_ongoing_call_wifi_template) {
Eric Erfanian938468d2017-10-24 14:05:52 -0700733 // TODO(a bug): Potentially apply this template logic everywhere.
linyuh183cb712017-12-27 17:02:37 -0800734 return context.getString(resId, wifiBrand);
Eric Erfanianccca3152017-02-22 16:32:36 -0800735 }
736
linyuh183cb712017-12-27 17:02:37 -0800737 return context.getString(resId);
Eric Erfanianccca3152017-02-22 16:32:36 -0800738 }
739
Eric Erfanian2ca43182017-08-31 06:57:16 -0700740 private boolean shouldShowEnrichedCallNotification(Session session) {
741 if (session == null) {
742 return false;
743 }
744 return session.getMultimediaData().hasData() || session.getMultimediaData().isImportant();
745 }
746
Eric Erfaniand8046e52017-04-06 09:41:50 -0700747 private int getECIncomingCallText(Session session) {
748 int resId;
749 MultimediaData data = session.getMultimediaData();
750 boolean hasImage = data.hasImageData();
751 boolean hasSubject = !TextUtils.isEmpty(data.getText());
752 boolean hasMap = data.getLocation() != null;
753 if (data.isImportant()) {
754 if (hasMap) {
755 if (hasImage) {
756 if (hasSubject) {
757 resId = R.string.important_notification_incoming_call_with_photo_message_location;
758 } else {
759 resId = R.string.important_notification_incoming_call_with_photo_location;
760 }
761 } else if (hasSubject) {
762 resId = R.string.important_notification_incoming_call_with_message_location;
763 } else {
764 resId = R.string.important_notification_incoming_call_with_location;
765 }
766 } else if (hasImage) {
767 if (hasSubject) {
768 resId = R.string.important_notification_incoming_call_with_photo_message;
769 } else {
770 resId = R.string.important_notification_incoming_call_with_photo;
771 }
Eric Erfanian2ca43182017-08-31 06:57:16 -0700772 } else if (hasSubject) {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700773 resId = R.string.important_notification_incoming_call_with_message;
Eric Erfanian2ca43182017-08-31 06:57:16 -0700774 } else {
775 resId = R.string.important_notification_incoming_call;
Eric Erfaniand8046e52017-04-06 09:41:50 -0700776 }
linyuh183cb712017-12-27 17:02:37 -0800777 if (context.getString(resId).length() > 50) {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700778 resId = R.string.important_notification_incoming_call_attachments;
779 }
780 } else {
781 if (hasMap) {
782 if (hasImage) {
783 if (hasSubject) {
784 resId = R.string.notification_incoming_call_with_photo_message_location;
785 } else {
786 resId = R.string.notification_incoming_call_with_photo_location;
787 }
788 } else if (hasSubject) {
789 resId = R.string.notification_incoming_call_with_message_location;
790 } else {
791 resId = R.string.notification_incoming_call_with_location;
792 }
793 } else if (hasImage) {
794 if (hasSubject) {
795 resId = R.string.notification_incoming_call_with_photo_message;
796 } else {
797 resId = R.string.notification_incoming_call_with_photo;
798 }
799 } else {
800 resId = R.string.notification_incoming_call_with_message;
801 }
802 }
linyuh183cb712017-12-27 17:02:37 -0800803 if (context.getString(resId).length() > 50) {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700804 resId = R.string.notification_incoming_call_attachments;
805 }
806 return resId;
807 }
808
twyend1d1d0c2017-10-05 17:34:43 -0700809 private CharSequence getMultiSimIncomingText(DialerCall call) {
810 PhoneAccount phoneAccount =
linyuh183cb712017-12-27 17:02:37 -0800811 context.getSystemService(TelecomManager.class).getPhoneAccount(call.getAccountHandle());
twyene931c122018-03-19 14:47:28 -0700812 if (phoneAccount == null) {
813 return context.getString(R.string.notification_incoming_call);
814 }
twyend1d1d0c2017-10-05 17:34:43 -0700815 SpannableString string =
816 new SpannableString(
linyuh183cb712017-12-27 17:02:37 -0800817 context.getString(
twyend1d1d0c2017-10-05 17:34:43 -0700818 R.string.notification_incoming_call_mutli_sim, phoneAccount.getLabel()));
819 int accountStart = string.toString().lastIndexOf(phoneAccount.getLabel().toString());
820 int accountEnd = accountStart + phoneAccount.getLabel().length();
821
822 string.setSpan(
823 new ForegroundColorSpan(phoneAccount.getHighlightColor()),
824 accountStart,
825 accountEnd,
826 Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
827 return string;
828 }
829
Eric Erfanianccca3152017-02-22 16:32:36 -0800830 /** Gets the most relevant call to display in the notification. */
831 private DialerCall getCallToShow(CallList callList) {
832 if (callList == null) {
833 return null;
834 }
835 DialerCall call = callList.getIncomingCall();
836 if (call == null) {
837 call = callList.getOutgoingCall();
838 }
839 if (call == null) {
840 call = callList.getVideoUpgradeRequestCall();
841 }
842 if (call == null) {
843 call = callList.getActiveOrBackgroundCall();
844 }
845 return call;
846 }
847
848 private Spannable getActionText(@StringRes int stringRes, @ColorRes int colorRes) {
linyuh183cb712017-12-27 17:02:37 -0800849 Spannable spannable = new SpannableString(context.getText(stringRes));
Eric Erfanianccca3152017-02-22 16:32:36 -0800850 if (VERSION.SDK_INT >= VERSION_CODES.N_MR1) {
851 // This will only work for cases where the Notification.Builder has a fullscreen intent set
852 // Notification.Builder that does not have a full screen intent will take the color of the
853 // app and the following leads to a no-op.
854 spannable.setSpan(
linyuh183cb712017-12-27 17:02:37 -0800855 new ForegroundColorSpan(context.getColor(colorRes)), 0, spannable.length(), 0);
Eric Erfanianccca3152017-02-22 16:32:36 -0800856 }
857 return spannable;
858 }
859
860 private void addAnswerAction(Notification.Builder builder) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700861 LogUtil.d(
862 "StatusBarNotifier.addAnswerAction",
863 "will show \"answer\" action in the incoming call Notification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800864 PendingIntent answerVoicePendingIntent =
linyuh183cb712017-12-27 17:02:37 -0800865 createNotificationPendingIntent(context, ACTION_ANSWER_VOICE_INCOMING_CALL);
Eric Erfanianccca3152017-02-22 16:32:36 -0800866 builder.addAction(
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700867 new Notification.Action.Builder(
linyuh183cb712017-12-27 17:02:37 -0800868 Icon.createWithResource(context, R.drawable.quantum_ic_call_white_24),
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700869 getActionText(
870 R.string.notification_action_answer, R.color.notification_action_accept),
871 answerVoicePendingIntent)
872 .build());
Eric Erfanianccca3152017-02-22 16:32:36 -0800873 }
874
erfanian94a7b3b2018-06-19 14:36:18 -0700875 private void addSpeakeasyAnswerAction(Notification.Builder builder, DialerCall call) {
876 if (!call.isSpeakEasyEligible()) {
877 return;
878 }
879
erfanian1e4ef182018-06-11 11:05:51 -0700880 if (!ConfigProviderComponent.get(context)
881 .getConfigProvider()
882 .getBoolean("enable_speakeasy_notification_button", false)) {
883 return;
884 }
885
886 if (!SpeakEasyComponent.get(context).speakEasyCallManager().isAvailable(context)) {
887 return;
888 }
889
890 Optional<Integer> buttonText = SpeakEasyComponent.get(context).speakEasyTextResource();
891 if (!buttonText.isPresent()) {
892 return;
893 }
894
895 LogUtil.d("StatusBarNotifier.addSpeakeasyAnswerAction", "showing button");
896 PendingIntent answerVoicePendingIntent =
897 createNotificationPendingIntent(context, ACTION_ANSWER_SPEAKEASY_CALL);
898
899 Spannable spannable = new SpannableString(context.getText(buttonText.get()));
900 // TODO(erfanian): Migrate these color values to somewhere more permanent in subsequent
901 // implementation.
902 spannable.setSpan(
903 new ForegroundColorSpan(
904 context.getColor(R.color.DO_NOT_USE_OR_I_WILL_BREAK_YOU_text_span_tertiary_button)),
905 0,
906 spannable.length(),
907 Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
908
909 builder.addAction(
910 new Notification.Action.Builder(
911 Icon.createWithResource(context, R.drawable.quantum_ic_call_white_24),
912 spannable,
913 answerVoicePendingIntent)
914 .build());
915 }
916
Eric Erfanianccca3152017-02-22 16:32:36 -0800917 private void addDismissAction(Notification.Builder builder) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700918 LogUtil.d(
919 "StatusBarNotifier.addDismissAction",
920 "will show \"decline\" action in the incoming call Notification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800921 PendingIntent declinePendingIntent =
linyuh183cb712017-12-27 17:02:37 -0800922 createNotificationPendingIntent(context, ACTION_DECLINE_INCOMING_CALL);
Eric Erfanianccca3152017-02-22 16:32:36 -0800923 builder.addAction(
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700924 new Notification.Action.Builder(
linyuh183cb712017-12-27 17:02:37 -0800925 Icon.createWithResource(context, R.drawable.quantum_ic_close_white_24),
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700926 getActionText(
927 R.string.notification_action_dismiss, R.color.notification_action_dismiss),
928 declinePendingIntent)
929 .build());
Eric Erfanianccca3152017-02-22 16:32:36 -0800930 }
931
932 private void addHangupAction(Notification.Builder builder) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700933 LogUtil.d(
934 "StatusBarNotifier.addHangupAction",
935 "will show \"hang-up\" action in the ongoing active call Notification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800936 PendingIntent hangupPendingIntent =
linyuh183cb712017-12-27 17:02:37 -0800937 createNotificationPendingIntent(context, ACTION_HANG_UP_ONGOING_CALL);
Eric Erfanianccca3152017-02-22 16:32:36 -0800938 builder.addAction(
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700939 new Notification.Action.Builder(
linyuh183cb712017-12-27 17:02:37 -0800940 Icon.createWithResource(context, R.drawable.quantum_ic_call_end_white_24),
941 context.getText(R.string.notification_action_end_call),
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700942 hangupPendingIntent)
943 .build());
Eric Erfanianccca3152017-02-22 16:32:36 -0800944 }
945
yuegb26c1ae2017-09-18 16:59:16 -0700946 private void addSpeakerAction(Notification.Builder builder, CallAudioState callAudioState) {
947 if ((callAudioState.getSupportedRouteMask() & CallAudioState.ROUTE_BLUETOOTH)
948 == CallAudioState.ROUTE_BLUETOOTH) {
949 // Don't add speaker button if bluetooth is connected
950 return;
951 }
952 if (callAudioState.getRoute() == CallAudioState.ROUTE_SPEAKER) {
953 addSpeakerOffAction(builder);
954 } else if ((callAudioState.getRoute() & CallAudioState.ROUTE_WIRED_OR_EARPIECE) != 0) {
955 addSpeakerOnAction(builder);
956 }
957 }
958
959 private void addSpeakerOnAction(Notification.Builder builder) {
960 LogUtil.d(
961 "StatusBarNotifier.addSpeakerOnAction",
962 "will show \"Speaker on\" action in the ongoing active call Notification");
963 PendingIntent speakerOnPendingIntent =
linyuh183cb712017-12-27 17:02:37 -0800964 createNotificationPendingIntent(context, ACTION_TURN_ON_SPEAKER);
yuegb26c1ae2017-09-18 16:59:16 -0700965 builder.addAction(
966 new Notification.Action.Builder(
wangqi6ca8c722018-03-29 10:19:58 -0700967 Icon.createWithResource(context, R.drawable.quantum_ic_volume_up_vd_theme_24),
linyuh183cb712017-12-27 17:02:37 -0800968 context.getText(R.string.notification_action_speaker_on),
yuegb26c1ae2017-09-18 16:59:16 -0700969 speakerOnPendingIntent)
970 .build());
971 }
972
973 private void addSpeakerOffAction(Notification.Builder builder) {
974 LogUtil.d(
975 "StatusBarNotifier.addSpeakerOffAction",
976 "will show \"Speaker off\" action in the ongoing active call Notification");
977 PendingIntent speakerOffPendingIntent =
linyuh183cb712017-12-27 17:02:37 -0800978 createNotificationPendingIntent(context, ACTION_TURN_OFF_SPEAKER);
yuegb26c1ae2017-09-18 16:59:16 -0700979 builder.addAction(
980 new Notification.Action.Builder(
wangqi6ca8c722018-03-29 10:19:58 -0700981 Icon.createWithResource(context, R.drawable.quantum_ic_phone_in_talk_vd_theme_24),
linyuh183cb712017-12-27 17:02:37 -0800982 context.getText(R.string.notification_action_speaker_off),
yuegb26c1ae2017-09-18 16:59:16 -0700983 speakerOffPendingIntent)
984 .build());
985 }
986
Eric Erfanianccca3152017-02-22 16:32:36 -0800987 private void addVideoCallAction(Notification.Builder builder) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700988 LogUtil.i(
989 "StatusBarNotifier.addVideoCallAction",
990 "will show \"video\" action in the incoming call Notification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800991 PendingIntent answerVideoPendingIntent =
linyuh183cb712017-12-27 17:02:37 -0800992 createNotificationPendingIntent(context, ACTION_ANSWER_VIDEO_INCOMING_CALL);
Eric Erfanianccca3152017-02-22 16:32:36 -0800993 builder.addAction(
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700994 new Notification.Action.Builder(
linyuh8dc242d2018-03-28 13:09:47 -0700995 Icon.createWithResource(context, R.drawable.quantum_ic_videocam_vd_white_24),
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700996 getActionText(
997 R.string.notification_action_answer_video,
998 R.color.notification_action_answer_video),
999 answerVideoPendingIntent)
1000 .build());
Eric Erfanianccca3152017-02-22 16:32:36 -08001001 }
1002
1003 private void addAcceptUpgradeRequestAction(Notification.Builder builder) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001004 LogUtil.i(
1005 "StatusBarNotifier.addAcceptUpgradeRequestAction",
1006 "will show \"accept upgrade\" action in the incoming call Notification");
Eric Erfanianccca3152017-02-22 16:32:36 -08001007 PendingIntent acceptVideoPendingIntent =
linyuh183cb712017-12-27 17:02:37 -08001008 createNotificationPendingIntent(context, ACTION_ACCEPT_VIDEO_UPGRADE_REQUEST);
Eric Erfanianccca3152017-02-22 16:32:36 -08001009 builder.addAction(
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001010 new Notification.Action.Builder(
linyuh8dc242d2018-03-28 13:09:47 -07001011 Icon.createWithResource(context, R.drawable.quantum_ic_videocam_vd_white_24),
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001012 getActionText(
1013 R.string.notification_action_accept, R.color.notification_action_accept),
1014 acceptVideoPendingIntent)
1015 .build());
Eric Erfanianccca3152017-02-22 16:32:36 -08001016 }
1017
1018 private void addDismissUpgradeRequestAction(Notification.Builder builder) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001019 LogUtil.i(
1020 "StatusBarNotifier.addDismissUpgradeRequestAction",
1021 "will show \"dismiss upgrade\" action in the incoming call Notification");
Eric Erfanianccca3152017-02-22 16:32:36 -08001022 PendingIntent declineVideoPendingIntent =
linyuh183cb712017-12-27 17:02:37 -08001023 createNotificationPendingIntent(context, ACTION_DECLINE_VIDEO_UPGRADE_REQUEST);
Eric Erfanianccca3152017-02-22 16:32:36 -08001024 builder.addAction(
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001025 new Notification.Action.Builder(
linyuh8dc242d2018-03-28 13:09:47 -07001026 Icon.createWithResource(context, R.drawable.quantum_ic_videocam_vd_white_24),
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001027 getActionText(
1028 R.string.notification_action_dismiss, R.color.notification_action_dismiss),
1029 declineVideoPendingIntent)
1030 .build());
Eric Erfanianccca3152017-02-22 16:32:36 -08001031 }
1032
1033 /** Adds fullscreen intent to the builder. */
Eric Erfanian10b34a52017-05-04 08:23:17 -07001034 private void configureFullScreenIntent(Notification.Builder builder, PendingIntent intent) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001035 // Ok, we actually want to launch the incoming call
1036 // UI at this point (in addition to simply posting a notification
1037 // to the status bar). Setting fullScreenIntent will cause
1038 // the InCallScreen to be launched immediately *unless* the
1039 // current foreground activity is marked as "immersive".
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001040 LogUtil.d("StatusBarNotifier.configureFullScreenIntent", "setting fullScreenIntent: " + intent);
Eric Erfanianccca3152017-02-22 16:32:36 -08001041 builder.setFullScreenIntent(intent, true);
Eric Erfanianccca3152017-02-22 16:32:36 -08001042 }
1043
1044 private Notification.Builder getNotificationBuilder() {
linyuh183cb712017-12-27 17:02:37 -08001045 final Notification.Builder builder = new Notification.Builder(context);
Eric Erfanianccca3152017-02-22 16:32:36 -08001046 builder.setOngoing(true);
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001047 builder.setOnlyAlertOnce(true);
Eric Erfanian10b34a52017-05-04 08:23:17 -07001048 // This will be ignored on O+ and handled by the channel
Eric Erfanian2ca43182017-08-31 06:57:16 -07001049 // noinspection deprecation
Eric Erfanian10b34a52017-05-04 08:23:17 -07001050 builder.setPriority(Notification.PRIORITY_HIGH);
Eric Erfanianccca3152017-02-22 16:32:36 -08001051
1052 return builder;
1053 }
1054
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001055 private PendingIntent createLaunchPendingIntent(boolean isFullScreen) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001056 Intent intent =
1057 InCallActivity.getIntent(
linyuh183cb712017-12-27 17:02:37 -08001058 context, false /* showDialpad */, false /* newOutgoingCall */, isFullScreen);
Eric Erfanianccca3152017-02-22 16:32:36 -08001059
linyuhc3968e62017-11-20 17:40:50 -08001060 int requestCode = InCallActivity.PendingIntentRequestCodes.NON_FULL_SCREEN;
Eric Erfanianccca3152017-02-22 16:32:36 -08001061 if (isFullScreen) {
1062 // Use a unique request code so that the pending intent isn't clobbered by the
1063 // non-full screen pending intent.
linyuhc3968e62017-11-20 17:40:50 -08001064 requestCode = InCallActivity.PendingIntentRequestCodes.FULL_SCREEN;
Eric Erfanianccca3152017-02-22 16:32:36 -08001065 }
1066
1067 // PendingIntent that can be used to launch the InCallActivity. The
1068 // system fires off this intent if the user pulls down the windowshade
1069 // and clicks the notification's expanded view. It's also used to
1070 // launch the InCallActivity immediately when when there's an incoming
1071 // call (see the "fullScreenIntent" field below).
linyuh183cb712017-12-27 17:02:37 -08001072 return PendingIntent.getActivity(context, requestCode, intent, 0);
Eric Erfanianccca3152017-02-22 16:32:36 -08001073 }
1074
1075 private void setStatusBarCallListener(StatusBarCallListener listener) {
linyuh183cb712017-12-27 17:02:37 -08001076 if (statusBarCallListener != null) {
1077 statusBarCallListener.cleanup();
Eric Erfanianccca3152017-02-22 16:32:36 -08001078 }
linyuh183cb712017-12-27 17:02:37 -08001079 statusBarCallListener = listener;
Eric Erfanianccca3152017-02-22 16:32:36 -08001080 }
1081
wangqi9982f0d2017-10-11 17:46:07 -07001082 private boolean hasMultiplePhoneAccounts(DialerCall call) {
1083 if (call.getCallCapableAccounts() == null) {
1084 return false;
1085 }
1086 return call.getCallCapableAccounts().size() > 1;
twyend1d1d0c2017-10-05 17:34:43 -07001087 }
1088
yuegb26c1ae2017-09-18 16:59:16 -07001089 @Override
wangqic8cf79e2017-10-17 09:21:00 -07001090 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
1091 public void onContactInfoComplete(String callId, ContactCacheEntry entry) {
1092 DialerCall call = CallList.getInstance().getCallById(callId);
1093 if (call != null) {
1094 call.getLogState().contactLookupResult = entry.contactLookupResult;
1095 buildAndSendNotification(CallList.getInstance(), call, entry);
1096 }
1097 }
1098
1099 @Override
1100 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
1101 public void onImageLoadComplete(String callId, ContactCacheEntry entry) {
1102 DialerCall call = CallList.getInstance().getCallById(callId);
1103 if (call != null) {
1104 buildAndSendNotification(CallList.getInstance(), call, entry);
1105 }
yuegb26c1ae2017-09-18 16:59:16 -07001106 }
1107
Eric Erfanianccca3152017-02-22 16:32:36 -08001108 private class StatusBarCallListener implements DialerCallListener {
1109
linyuh183cb712017-12-27 17:02:37 -08001110 private DialerCall dialerCall;
Eric Erfanianccca3152017-02-22 16:32:36 -08001111
1112 StatusBarCallListener(DialerCall dialerCall) {
linyuh183cb712017-12-27 17:02:37 -08001113 this.dialerCall = dialerCall;
1114 this.dialerCall.addListener(this);
Eric Erfanianccca3152017-02-22 16:32:36 -08001115 }
1116
1117 void cleanup() {
linyuh183cb712017-12-27 17:02:37 -08001118 dialerCall.removeListener(this);
Eric Erfanianccca3152017-02-22 16:32:36 -08001119 }
1120
1121 @Override
1122 public void onDialerCallDisconnect() {}
1123
1124 @Override
1125 public void onDialerCallUpdate() {
1126 if (CallList.getInstance().getIncomingCall() == null) {
linyuh183cb712017-12-27 17:02:37 -08001127 dialerRingtoneManager.stopCallWaitingTone();
Eric Erfanianccca3152017-02-22 16:32:36 -08001128 }
1129 }
1130
1131 @Override
1132 public void onDialerCallChildNumberChange() {}
1133
1134 @Override
1135 public void onDialerCallLastForwardedNumberChange() {}
1136
1137 @Override
1138 public void onDialerCallUpgradeToVideo() {}
1139
1140 @Override
1141 public void onWiFiToLteHandover() {}
1142
1143 @Override
1144 public void onHandoverToWifiFailure() {}
1145
Eric Erfanianc857f902017-05-15 14:05:33 -07001146 @Override
1147 public void onInternationalCallOnWifi() {}
1148
Eric Erfanian2ca43182017-08-31 06:57:16 -07001149 @Override
1150 public void onEnrichedCallSessionUpdate() {}
1151
Eric Erfanianccca3152017-02-22 16:32:36 -08001152 /**
1153 * Responds to changes in the session modification state for the call by dismissing the status
1154 * bar notification as required.
1155 */
1156 @Override
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001157 public void onDialerCallSessionModificationStateChange() {
linyuh183cb712017-12-27 17:02:37 -08001158 if (dialerCall.getVideoTech().getSessionModificationState()
Eric Erfanian90508232017-03-24 09:31:16 -07001159 == SessionModificationState.NO_REQUEST) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001160 cleanup();
wangqic8cf79e2017-10-17 09:21:00 -07001161 updateNotification();
Eric Erfanianccca3152017-02-22 16:32:36 -08001162 }
1163 }
1164 }
1165}