blob: 4026be712232152442e3c3e1cb05d4bdcd41df80 [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;
67import com.android.contacts.common.preference.ContactsPreferences;
Eric Erfanianccca3152017-02-22 16:32:36 -080068import com.android.contacts.common.util.ContactDisplayUtils;
Eric Erfanian2ca43182017-08-31 06:57:16 -070069import com.android.dialer.common.Assert;
Eric Erfanianccca3152017-02-22 16:32:36 -080070import com.android.dialer.common.LogUtil;
zachh190343a2018-05-31 17:30:46 -070071import com.android.dialer.configprovider.ConfigProviderComponent;
Eric Erfanian2ca43182017-08-31 06:57:16 -070072import com.android.dialer.contactphoto.BitmapUtil;
Eric Erfaniand8046e52017-04-06 09:41:50 -070073import com.android.dialer.enrichedcall.EnrichedCallManager;
74import com.android.dialer.enrichedcall.Session;
Eric Erfanian2ca43182017-08-31 06:57:16 -070075import com.android.dialer.lettertile.LetterTileDrawable;
76import com.android.dialer.lettertile.LetterTileDrawable.ContactType;
Eric Erfaniand8046e52017-04-06 09:41:50 -070077import com.android.dialer.multimedia.MultimediaData;
Eric Erfanian2ca43182017-08-31 06:57:16 -070078import com.android.dialer.notification.NotificationChannelId;
Eric Erfanian90508232017-03-24 09:31:16 -070079import com.android.dialer.oem.MotorolaUtils;
calderwoodraa93df432018-05-23 12:59:03 -070080import com.android.dialer.theme.base.ThemeComponent;
Eric Erfanianccca3152017-02-22 16:32:36 -080081import com.android.dialer.util.DrawableConverter;
82import com.android.incallui.ContactInfoCache.ContactCacheEntry;
83import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback;
84import com.android.incallui.InCallPresenter.InCallState;
85import com.android.incallui.async.PausableExecutorImpl;
yuegb26c1ae2017-09-18 16:59:16 -070086import com.android.incallui.audiomode.AudioModeProvider;
Eric Erfanianccca3152017-02-22 16:32:36 -080087import com.android.incallui.call.CallList;
88import com.android.incallui.call.DialerCall;
Eric Erfanianccca3152017-02-22 16:32:36 -080089import com.android.incallui.call.DialerCallListener;
yueg01a964d2017-10-03 15:25:41 -070090import com.android.incallui.call.TelecomAdapter;
wangqibb94ca62018-04-27 14:34:04 -070091import com.android.incallui.call.state.DialerCallState;
Eric Erfanianccca3152017-02-22 16:32:36 -080092import com.android.incallui.ringtone.DialerRingtoneManager;
93import com.android.incallui.ringtone.InCallTonePlayer;
94import com.android.incallui.ringtone.ToneGeneratorFactory;
erfanian1e4ef182018-06-11 11:05:51 -070095import com.android.incallui.speakeasy.SpeakEasyComponent;
Eric Erfanian90508232017-03-24 09:31:16 -070096import com.android.incallui.videotech.utils.SessionModificationState;
erfanian1e4ef182018-06-11 11:05:51 -070097import com.google.common.base.Optional;
Eric Erfanianccca3152017-02-22 16:32:36 -080098import java.util.Objects;
99
100/** This class adds Notifications to the status bar for the in-call experience. */
Eric Erfaniand8046e52017-04-06 09:41:50 -0700101public class StatusBarNotifier
yuegb26c1ae2017-09-18 16:59:16 -0700102 implements InCallPresenter.InCallStateListener,
103 EnrichedCallManager.StateChangedListener,
wangqic8cf79e2017-10-17 09:21:00 -0700104 ContactInfoCacheCallback {
Eric Erfanianccca3152017-02-22 16:32:36 -0800105
Eric Erfanian2ca43182017-08-31 06:57:16 -0700106 private static final int NOTIFICATION_ID = 1;
107
Eric Erfanianccca3152017-02-22 16:32:36 -0800108 // Notification types
109 // Indicates that no notification is currently showing.
110 private static final int NOTIFICATION_NONE = 0;
111 // Notification for an active call. This is non-interruptive, but cannot be dismissed.
Eric Erfanian10b34a52017-05-04 08:23:17 -0700112 private static final int NOTIFICATION_IN_CALL = 1;
Eric Erfanianccca3152017-02-22 16:32:36 -0800113 // Notification for incoming calls. This is interruptive and will show up as a HUN.
Eric Erfanian10b34a52017-05-04 08:23:17 -0700114 private static final int NOTIFICATION_INCOMING_CALL = 2;
115 // Notification for incoming calls in the case where there is already an active call.
116 // This is non-interruptive, but otherwise behaves the same as NOTIFICATION_INCOMING_CALL
117 private static final int NOTIFICATION_INCOMING_CALL_QUIET = 3;
Eric Erfanianccca3152017-02-22 16:32:36 -0800118
Eric Erfanianccca3152017-02-22 16:32:36 -0800119 private static final long[] VIBRATE_PATTERN = new long[] {0, 1000, 1000};
120
linyuh183cb712017-12-27 17:02:37 -0800121 private final Context context;
122 private final ContactInfoCache contactInfoCache;
123 private final DialerRingtoneManager dialerRingtoneManager;
124 @Nullable private ContactsPreferences contactsPreferences;
125 private int currentNotification = NOTIFICATION_NONE;
wangqibb94ca62018-04-27 14:34:04 -0700126 private int callState = DialerCallState.INVALID;
linyuh183cb712017-12-27 17:02:37 -0800127 private int videoState = VideoProfile.STATE_AUDIO_ONLY;
128 private int savedIcon = 0;
129 private String savedContent = null;
130 private Bitmap savedLargeIcon;
131 private String savedContentTitle;
yuegb26c1ae2017-09-18 16:59:16 -0700132 private CallAudioState savedCallAudioState;
linyuh183cb712017-12-27 17:02:37 -0800133 private Uri ringtone;
134 private StatusBarCallListener statusBarCallListener;
Eric Erfanianccca3152017-02-22 16:32:36 -0800135
Eric Erfaniand8046e52017-04-06 09:41:50 -0700136 public StatusBarNotifier(@NonNull Context context, @NonNull ContactInfoCache contactInfoCache) {
wangqic8cf79e2017-10-17 09:21:00 -0700137 Trace.beginSection("StatusBarNotifier.Constructor");
linyuh183cb712017-12-27 17:02:37 -0800138 this.context = Assert.isNotNull(context);
139 contactsPreferences = ContactsPreferencesFactory.newContactsPreferences(this.context);
140 this.contactInfoCache = contactInfoCache;
141 dialerRingtoneManager =
Eric Erfanianccca3152017-02-22 16:32:36 -0800142 new DialerRingtoneManager(
143 new InCallTonePlayer(new ToneGeneratorFactory(), new PausableExecutorImpl()),
144 CallList.getInstance());
linyuh183cb712017-12-27 17:02:37 -0800145 currentNotification = NOTIFICATION_NONE;
wangqic8cf79e2017-10-17 09:21:00 -0700146 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800147 }
148
149 /**
150 * Should only be called from a irrecoverable state where it is necessary to dismiss all
151 * notifications.
152 */
yueg01a964d2017-10-03 15:25:41 -0700153 static void clearAllCallNotifications() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700154 LogUtil.e(
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700155 "StatusBarNotifier.clearAllCallNotifications",
156 "something terrible happened, clear all InCall notifications");
Eric Erfanianccca3152017-02-22 16:32:36 -0800157
yueg01a964d2017-10-03 15:25:41 -0700158 TelecomAdapter.getInstance().stopForegroundNotification();
Eric Erfanianccca3152017-02-22 16:32:36 -0800159 }
160
161 private static int getWorkStringFromPersonalString(int resId) {
162 if (resId == R.string.notification_ongoing_call) {
163 return R.string.notification_ongoing_work_call;
Eric Erfanianccca3152017-02-22 16:32:36 -0800164 } else if (resId == R.string.notification_incoming_call) {
165 return R.string.notification_incoming_work_call;
166 } else {
167 return resId;
168 }
169 }
170
171 /**
172 * Returns PendingIntent for answering a phone call. This will typically be used from Notification
173 * context.
174 */
175 private static PendingIntent createNotificationPendingIntent(Context context, String action) {
176 final Intent intent = new Intent(action, null, context, NotificationBroadcastReceiver.class);
177 return PendingIntent.getBroadcast(context, 0, intent, 0);
178 }
179
180 /** Creates notifications according to the state we receive from {@link InCallPresenter}. */
181 @Override
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700182 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
Eric Erfanianccca3152017-02-22 16:32:36 -0800183 public void onStateChange(InCallState oldState, InCallState newState, CallList callList) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700184 LogUtil.d("StatusBarNotifier.onStateChange", "%s->%s", oldState, newState);
wangqic8cf79e2017-10-17 09:21:00 -0700185 updateNotification();
Eric Erfanianccca3152017-02-22 16:32:36 -0800186 }
187
Eric Erfaniand8046e52017-04-06 09:41:50 -0700188 @Override
189 public void onEnrichedCallStateChanged() {
190 LogUtil.enterBlock("StatusBarNotifier.onEnrichedCallStateChanged");
wangqic8cf79e2017-10-17 09:21:00 -0700191 updateNotification();
Eric Erfaniand8046e52017-04-06 09:41:50 -0700192 }
193
Eric Erfanianccca3152017-02-22 16:32:36 -0800194 /**
195 * Updates the phone app's status bar notification *and* launches the incoming call UI in response
196 * to a new incoming call.
197 *
198 * <p>If an incoming call is ringing (or call-waiting), the notification will also include a
199 * "fullScreenIntent" that will cause the InCallScreen to be launched, unless the current
200 * foreground activity is marked as "immersive".
201 *
202 * <p>(This is the mechanism that actually brings up the incoming call UI when we receive a "new
203 * ringing connection" event from the telephony layer.)
204 *
205 * <p>Also note that this method is safe to call even if the phone isn't actually ringing (or,
206 * more likely, if an incoming call *was* ringing briefly but then disconnected). In that case,
207 * we'll simply update or cancel the in-call notification based on the current phone state.
208 *
wangqic8cf79e2017-10-17 09:21:00 -0700209 * @see #updateInCallNotification()
Eric Erfanianccca3152017-02-22 16:32:36 -0800210 */
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700211 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
wangqic8cf79e2017-10-17 09:21:00 -0700212 public void updateNotification() {
213 updateInCallNotification();
Eric Erfanianccca3152017-02-22 16:32:36 -0800214 }
215
216 /**
217 * Take down the in-call notification.
218 *
wangqic8cf79e2017-10-17 09:21:00 -0700219 * @see #updateInCallNotification()
Eric Erfanianccca3152017-02-22 16:32:36 -0800220 */
221 private void cancelNotification() {
linyuh183cb712017-12-27 17:02:37 -0800222 if (statusBarCallListener != null) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800223 setStatusBarCallListener(null);
224 }
linyuh183cb712017-12-27 17:02:37 -0800225 if (currentNotification != NOTIFICATION_NONE) {
yueg01a964d2017-10-03 15:25:41 -0700226 TelecomAdapter.getInstance().stopForegroundNotification();
linyuh183cb712017-12-27 17:02:37 -0800227 currentNotification = NOTIFICATION_NONE;
Eric Erfanianccca3152017-02-22 16:32:36 -0800228 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800229 }
230
231 /**
232 * Helper method for updateInCallNotification() and updateNotification(): Update the phone app's
233 * status bar notification based on the current telephony state, or cancels the notification if
234 * the phone is totally idle.
235 */
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700236 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
wangqic8cf79e2017-10-17 09:21:00 -0700237 private void updateInCallNotification() {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700238 LogUtil.d("StatusBarNotifier.updateInCallNotification", "");
Eric Erfanianccca3152017-02-22 16:32:36 -0800239
wangqic8cf79e2017-10-17 09:21:00 -0700240 final DialerCall call = getCallToShow(CallList.getInstance());
Eric Erfanianccca3152017-02-22 16:32:36 -0800241
242 if (call != null) {
wangqic8cf79e2017-10-17 09:21:00 -0700243 showNotification(call);
Eric Erfanianccca3152017-02-22 16:32:36 -0800244 } else {
245 cancelNotification();
246 }
247 }
248
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700249 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
wangqic8cf79e2017-10-17 09:21:00 -0700250 private void showNotification(final DialerCall call) {
wangqicf61ca02017-08-31 15:32:55 -0700251 Trace.beginSection("StatusBarNotifier.showNotification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800252 final boolean isIncoming =
wangqibb94ca62018-04-27 14:34:04 -0700253 (call.getState() == DialerCallState.INCOMING
254 || call.getState() == DialerCallState.CALL_WAITING);
Eric Erfanianccca3152017-02-22 16:32:36 -0800255 setStatusBarCallListener(new StatusBarCallListener(call));
256
257 // we make a call to the contact info cache to query for supplemental data to what the
258 // call provides. This includes the contact name and photo.
259 // This callback will always get called immediately and synchronously with whatever data
260 // it has available, and may make a subsequent call later (same thread) if it had to
261 // call into the contacts provider for more data.
linyuh183cb712017-12-27 17:02:37 -0800262 contactInfoCache.findInfo(call, isIncoming, this);
wangqicf61ca02017-08-31 15:32:55 -0700263 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800264 }
265
266 /** Sets up the main Ui for the notification */
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700267 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
Eric Erfanianccca3152017-02-22 16:32:36 -0800268 private void buildAndSendNotification(
269 CallList callList, DialerCall originalCall, ContactCacheEntry contactInfo) {
wangqicf61ca02017-08-31 15:32:55 -0700270 Trace.beginSection("StatusBarNotifier.buildAndSendNotification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800271 // This can get called to update an existing notification after contact information has come
272 // back. However, it can happen much later. Before we continue, we need to make sure that
273 // the call being passed in is still the one we want to show in the notification.
274 final DialerCall call = getCallToShow(callList);
275 if (call == null || !call.getId().equals(originalCall.getId())) {
wangqicf61ca02017-08-31 15:32:55 -0700276 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800277 return;
278 }
279
wangqicf61ca02017-08-31 15:32:55 -0700280 Trace.beginSection("prepare work");
Eric Erfanianccca3152017-02-22 16:32:36 -0800281 final int callState = call.getState();
yuegb26c1ae2017-09-18 16:59:16 -0700282 final CallAudioState callAudioState = AudioModeProvider.getInstance().getAudioState();
Eric Erfanianccca3152017-02-22 16:32:36 -0800283
wangqic8cf79e2017-10-17 09:21:00 -0700284 Trace.beginSection("read icon and strings");
Eric Erfanianccca3152017-02-22 16:32:36 -0800285 // Check if data has changed; if nothing is different, don't issue another notification.
286 final int iconResId = getIconToDisplay(call);
linyuh183cb712017-12-27 17:02:37 -0800287 Bitmap largeIcon = getLargeIconToDisplay(context, contactInfo, call);
twyend1d1d0c2017-10-05 17:34:43 -0700288 final CharSequence content = getContentString(call, contactInfo.userType);
Eric Erfanianccca3152017-02-22 16:32:36 -0800289 final String contentTitle = getContentTitle(contactInfo, call);
wangqic8cf79e2017-10-17 09:21:00 -0700290 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800291
292 final boolean isVideoUpgradeRequest =
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700293 call.getVideoTech().getSessionModificationState()
Eric Erfanian90508232017-03-24 09:31:16 -0700294 == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST;
Eric Erfanianccca3152017-02-22 16:32:36 -0800295 final int notificationType;
wangqibb94ca62018-04-27 14:34:04 -0700296 if (callState == DialerCallState.INCOMING
297 || callState == DialerCallState.CALL_WAITING
Eric Erfanianccca3152017-02-22 16:32:36 -0800298 || isVideoUpgradeRequest) {
zachh190343a2018-05-31 17:30:46 -0700299 if (ConfigProviderComponent.get(context)
300 .getConfigProvider()
Eric Erfanian2ca43182017-08-31 06:57:16 -0700301 .getBoolean("quiet_incoming_call_if_ui_showing", true)) {
302 notificationType =
303 InCallPresenter.getInstance().isShowingInCallUi()
304 ? NOTIFICATION_INCOMING_CALL_QUIET
305 : NOTIFICATION_INCOMING_CALL;
306 } else {
307 boolean alreadyActive =
308 callList.getActiveOrBackgroundCall() != null
309 && InCallPresenter.getInstance().isShowingInCallUi();
310 notificationType =
311 alreadyActive ? NOTIFICATION_INCOMING_CALL_QUIET : NOTIFICATION_INCOMING_CALL;
312 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800313 } else {
314 notificationType = NOTIFICATION_IN_CALL;
315 }
wangqicf61ca02017-08-31 15:32:55 -0700316 Trace.endSection(); // prepare work
Eric Erfanianccca3152017-02-22 16:32:36 -0800317
318 if (!checkForChangeAndSaveData(
319 iconResId,
twyend1d1d0c2017-10-05 17:34:43 -0700320 content.toString(),
Eric Erfanianccca3152017-02-22 16:32:36 -0800321 largeIcon,
322 contentTitle,
323 callState,
roldenburgc14610d2017-10-31 12:51:06 -0700324 call.getVideoState(),
Eric Erfanianccca3152017-02-22 16:32:36 -0800325 notificationType,
yuegb26c1ae2017-09-18 16:59:16 -0700326 contactInfo.contactRingtoneUri,
327 callAudioState)) {
wangqicf61ca02017-08-31 15:32:55 -0700328 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800329 return;
330 }
331
332 if (largeIcon != null) {
333 largeIcon = getRoundedIcon(largeIcon);
334 }
335
336 // This builder is used for the notification shown when the device is locked and the user
337 // has set their notification settings to 'hide sensitive content'
338 // {@see Notification.Builder#setPublicVersion}.
linyuh183cb712017-12-27 17:02:37 -0800339 Notification.Builder publicBuilder = new Notification.Builder(context);
Eric Erfanianccca3152017-02-22 16:32:36 -0800340 publicBuilder
341 .setSmallIcon(iconResId)
calderwoodraa93df432018-05-23 12:59:03 -0700342 .setColor(ThemeComponent.get(context).theme().getColorPrimary())
Eric Erfanianccca3152017-02-22 16:32:36 -0800343 // Hide work call state for the lock screen notification
344 .setContentTitle(getContentString(call, ContactsUtils.USER_TYPE_CURRENT));
345 setNotificationWhen(call, callState, publicBuilder);
346
347 // Builder for the notification shown when the device is unlocked or the user has set their
348 // notification settings to 'show all notification content'.
349 final Notification.Builder builder = getNotificationBuilder();
350 builder.setPublicVersion(publicBuilder.build());
351
352 // Set up the main intent to send the user to the in-call screen
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700353 builder.setContentIntent(createLaunchPendingIntent(false /* isFullScreen */));
Eric Erfanianccca3152017-02-22 16:32:36 -0800354
Eric Erfanian10b34a52017-05-04 08:23:17 -0700355 LogUtil.i("StatusBarNotifier.buildAndSendNotification", "notificationType=" + notificationType);
356 switch (notificationType) {
357 case NOTIFICATION_INCOMING_CALL:
Eric Erfanian2ca43182017-08-31 06:57:16 -0700358 if (BuildCompat.isAtLeastO()) {
359 builder.setChannelId(NotificationChannelId.INCOMING_CALL);
360 }
wangqic8cf79e2017-10-17 09:21:00 -0700361 // Set the intent as a full screen intent as well if a call is incoming
Eric Erfanian10b34a52017-05-04 08:23:17 -0700362 configureFullScreenIntent(builder, createLaunchPendingIntent(true /* isFullScreen */));
363 // Set the notification category and bump the priority for incoming calls
364 builder.setCategory(Notification.CATEGORY_CALL);
365 // This will be ignored on O+ and handled by the channel
Eric Erfanian10b34a52017-05-04 08:23:17 -0700366 builder.setPriority(Notification.PRIORITY_MAX);
linyuh183cb712017-12-27 17:02:37 -0800367 if (currentNotification != NOTIFICATION_INCOMING_CALL) {
Eric Erfanian10b34a52017-05-04 08:23:17 -0700368 LogUtil.i(
369 "StatusBarNotifier.buildAndSendNotification",
370 "Canceling old notification so this one can be noisy");
371 // Moving from a non-interuptive notification (or none) to a noisy one. Cancel the old
372 // notification (if there is one) so the fullScreenIntent or HUN will show
yueg01a964d2017-10-03 15:25:41 -0700373 TelecomAdapter.getInstance().stopForegroundNotification();
Eric Erfanian10b34a52017-05-04 08:23:17 -0700374 }
375 break;
376 case NOTIFICATION_INCOMING_CALL_QUIET:
Eric Erfanian2ca43182017-08-31 06:57:16 -0700377 if (BuildCompat.isAtLeastO()) {
378 builder.setChannelId(NotificationChannelId.ONGOING_CALL);
379 }
Eric Erfanian10b34a52017-05-04 08:23:17 -0700380 break;
381 case NOTIFICATION_IN_CALL:
Eric Erfanian2ca43182017-08-31 06:57:16 -0700382 if (BuildCompat.isAtLeastO()) {
383 publicBuilder.setColorized(true);
384 builder.setColorized(true);
385 builder.setChannelId(NotificationChannelId.ONGOING_CALL);
386 }
387 break;
388 default:
Eric Erfanian10b34a52017-05-04 08:23:17 -0700389 break;
Eric Erfanianccca3152017-02-22 16:32:36 -0800390 }
391
392 // Set the content
393 builder.setContentText(content);
394 builder.setSmallIcon(iconResId);
395 builder.setContentTitle(contentTitle);
396 builder.setLargeIcon(largeIcon);
yueg01a964d2017-10-03 15:25:41 -0700397 builder.setColor(InCallPresenter.getInstance().getThemeColorManager().getPrimaryColor());
Eric Erfanianccca3152017-02-22 16:32:36 -0800398
399 if (isVideoUpgradeRequest) {
400 builder.setUsesChronometer(false);
401 addDismissUpgradeRequestAction(builder);
402 addAcceptUpgradeRequestAction(builder);
403 } else {
yuegb26c1ae2017-09-18 16:59:16 -0700404 createIncomingCallNotification(call, callState, callAudioState, builder);
Eric Erfanianccca3152017-02-22 16:32:36 -0800405 }
406
407 addPersonReference(builder, contactInfo, call);
408
wangqicf61ca02017-08-31 15:32:55 -0700409 Trace.beginSection("fire notification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800410 // Fire off the notification
411 Notification notification = builder.build();
412
linyuh183cb712017-12-27 17:02:37 -0800413 if (dialerRingtoneManager.shouldPlayRingtone(callState, contactInfo.contactRingtoneUri)) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800414 notification.flags |= Notification.FLAG_INSISTENT;
415 notification.sound = contactInfo.contactRingtoneUri;
416 AudioAttributes.Builder audioAttributes = new AudioAttributes.Builder();
417 audioAttributes.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC);
418 audioAttributes.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE);
419 notification.audioAttributes = audioAttributes.build();
linyuh183cb712017-12-27 17:02:37 -0800420 if (dialerRingtoneManager.shouldVibrate(context.getContentResolver())) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800421 notification.vibrate = VIBRATE_PATTERN;
422 }
423 }
linyuh183cb712017-12-27 17:02:37 -0800424 if (dialerRingtoneManager.shouldPlayCallWaitingTone(callState)) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700425 LogUtil.v("StatusBarNotifier.buildAndSendNotification", "playing call waiting tone");
linyuh183cb712017-12-27 17:02:37 -0800426 dialerRingtoneManager.playCallWaitingTone();
Eric Erfanianccca3152017-02-22 16:32:36 -0800427 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800428
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700429 LogUtil.i(
430 "StatusBarNotifier.buildAndSendNotification",
431 "displaying notification for " + notificationType);
432
yueg01a964d2017-10-03 15:25:41 -0700433 // If a notification exists, this will only update it.
434 TelecomAdapter.getInstance().startForegroundNotification(NOTIFICATION_ID, notification);
435
wangqicf61ca02017-08-31 15:32:55 -0700436 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800437 call.getLatencyReport().onNotificationShown();
linyuh183cb712017-12-27 17:02:37 -0800438 currentNotification = notificationType;
wangqicf61ca02017-08-31 15:32:55 -0700439 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800440 }
441
442 private void createIncomingCallNotification(
yuegb26c1ae2017-09-18 16:59:16 -0700443 DialerCall call, int state, CallAudioState callAudioState, Notification.Builder builder) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800444 setNotificationWhen(call, state, builder);
445
446 // Add hang up option for any active calls (active | onhold), outgoing calls (dialing).
wangqibb94ca62018-04-27 14:34:04 -0700447 if (state == DialerCallState.ACTIVE
448 || state == DialerCallState.ONHOLD
449 || DialerCallState.isDialing(state)) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800450 addHangupAction(builder);
yuegb26c1ae2017-09-18 16:59:16 -0700451 addSpeakerAction(builder, callAudioState);
wangqibb94ca62018-04-27 14:34:04 -0700452 } else if (state == DialerCallState.INCOMING || state == DialerCallState.CALL_WAITING) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800453 addDismissAction(builder);
454 if (call.isVideoCall()) {
455 addVideoCallAction(builder);
456 } else {
457 addAnswerAction(builder);
erfanian1e4ef182018-06-11 11:05:51 -0700458 addSpeakeasyAnswerAction(builder);
Eric Erfanianccca3152017-02-22 16:32:36 -0800459 }
460 }
461 }
462
463 /**
464 * Sets the notification's when section as needed. For active calls, this is explicitly set as the
465 * duration of the call. For all other states, the notification will automatically show the time
466 * at which the notification was created.
467 */
468 private void setNotificationWhen(DialerCall call, int state, Notification.Builder builder) {
wangqibb94ca62018-04-27 14:34:04 -0700469 if (state == DialerCallState.ACTIVE) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800470 builder.setUsesChronometer(true);
471 builder.setWhen(call.getConnectTimeMillis());
472 } else {
473 builder.setUsesChronometer(false);
474 }
475 }
476
477 /**
478 * Checks the new notification data and compares it against any notification that we are already
479 * displaying. If the data is exactly the same, we return false so that we do not issue a new
480 * notification for the exact same data.
481 */
482 private boolean checkForChangeAndSaveData(
483 int icon,
484 String content,
485 Bitmap largeIcon,
486 String contentTitle,
487 int state,
roldenburgc14610d2017-10-31 12:51:06 -0700488 int videoState,
Eric Erfanianccca3152017-02-22 16:32:36 -0800489 int notificationType,
yuegb26c1ae2017-09-18 16:59:16 -0700490 Uri ringtone,
491 CallAudioState callAudioState) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800492
493 // The two are different:
494 // if new title is not null, it should be different from saved version OR
495 // if new title is null, the saved version should not be null
496 final boolean contentTitleChanged =
linyuh183cb712017-12-27 17:02:37 -0800497 (contentTitle != null && !contentTitle.equals(savedContentTitle))
498 || (contentTitle == null && savedContentTitle != null);
Eric Erfanianccca3152017-02-22 16:32:36 -0800499
roldenburgc14610d2017-10-31 12:51:06 -0700500 boolean largeIconChanged;
linyuh183cb712017-12-27 17:02:37 -0800501 if (savedLargeIcon == null) {
roldenburgc14610d2017-10-31 12:51:06 -0700502 largeIconChanged = largeIcon != null;
503 } else {
linyuh183cb712017-12-27 17:02:37 -0800504 largeIconChanged = largeIcon == null || !savedLargeIcon.sameAs(largeIcon);
roldenburgc14610d2017-10-31 12:51:06 -0700505 }
Eric Erfanian8369df02017-05-03 10:27:13 -0700506
Eric Erfanianccca3152017-02-22 16:32:36 -0800507 // any change means we are definitely updating
508 boolean retval =
linyuh183cb712017-12-27 17:02:37 -0800509 (savedIcon != icon)
510 || !Objects.equals(savedContent, content)
511 || (callState != state)
512 || (this.videoState != videoState)
Eric Erfanian8369df02017-05-03 10:27:13 -0700513 || largeIconChanged
Eric Erfanianccca3152017-02-22 16:32:36 -0800514 || contentTitleChanged
linyuh183cb712017-12-27 17:02:37 -0800515 || !Objects.equals(this.ringtone, ringtone)
yuegb26c1ae2017-09-18 16:59:16 -0700516 || !Objects.equals(savedCallAudioState, callAudioState);
Eric Erfanianccca3152017-02-22 16:32:36 -0800517
wangqi9982f0d2017-10-11 17:46:07 -0700518 LogUtil.d(
519 "StatusBarNotifier.checkForChangeAndSaveData",
roldenburgc14610d2017-10-31 12:51:06 -0700520 "data changed: icon: %b, content: %b, state: %b, videoState: %b, largeIcon: %b, title: %b,"
521 + "ringtone: %b, audioState: %b, type: %b",
linyuh183cb712017-12-27 17:02:37 -0800522 (savedIcon != icon),
523 !Objects.equals(savedContent, content),
524 (callState != state),
525 (this.videoState != videoState),
wangqi9982f0d2017-10-11 17:46:07 -0700526 largeIconChanged,
527 contentTitleChanged,
linyuh183cb712017-12-27 17:02:37 -0800528 !Objects.equals(this.ringtone, ringtone),
wangqi9982f0d2017-10-11 17:46:07 -0700529 !Objects.equals(savedCallAudioState, callAudioState),
linyuh183cb712017-12-27 17:02:37 -0800530 currentNotification != notificationType);
Eric Erfanianccca3152017-02-22 16:32:36 -0800531 // If we aren't showing a notification right now or the notification type is changing,
532 // definitely do an update.
linyuh183cb712017-12-27 17:02:37 -0800533 if (currentNotification != notificationType) {
534 if (currentNotification == NOTIFICATION_NONE) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700535 LogUtil.d(
536 "StatusBarNotifier.checkForChangeAndSaveData", "showing notification for first time.");
Eric Erfanianccca3152017-02-22 16:32:36 -0800537 }
538 retval = true;
539 }
540
linyuh183cb712017-12-27 17:02:37 -0800541 savedIcon = icon;
542 savedContent = content;
543 callState = state;
544 this.videoState = videoState;
545 savedLargeIcon = largeIcon;
546 savedContentTitle = contentTitle;
547 this.ringtone = ringtone;
yuegb26c1ae2017-09-18 16:59:16 -0700548 savedCallAudioState = callAudioState;
Eric Erfanianccca3152017-02-22 16:32:36 -0800549
550 if (retval) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700551 LogUtil.d(
552 "StatusBarNotifier.checkForChangeAndSaveData", "data changed. Showing notification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800553 }
554
555 return retval;
556 }
557
558 /** Returns the main string to use in the notification. */
559 @VisibleForTesting
560 @Nullable
561 String getContentTitle(ContactCacheEntry contactInfo, DialerCall call) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700562 if (call.isConferenceCall()) {
563 return CallerInfoUtils.getConferenceString(
linyuh183cb712017-12-27 17:02:37 -0800564 context, call.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE));
Eric Erfanianccca3152017-02-22 16:32:36 -0800565 }
566
567 String preferredName =
568 ContactDisplayUtils.getPreferredDisplayName(
linyuh183cb712017-12-27 17:02:37 -0800569 contactInfo.namePrimary, contactInfo.nameAlternative, contactsPreferences);
Eric Erfanianccca3152017-02-22 16:32:36 -0800570 if (TextUtils.isEmpty(preferredName)) {
571 return TextUtils.isEmpty(contactInfo.number)
572 ? null
573 : BidiFormatter.getInstance()
574 .unicodeWrap(contactInfo.number, TextDirectionHeuristics.LTR);
575 }
576 return preferredName;
577 }
578
579 private void addPersonReference(
580 Notification.Builder builder, ContactCacheEntry contactInfo, DialerCall call) {
581 // Query {@link Contacts#CONTENT_LOOKUP_URI} directly with work lookup key is not allowed.
582 // So, do not pass {@link Contacts#CONTENT_LOOKUP_URI} to NotificationManager to avoid
583 // NotificationManager using it.
584 if (contactInfo.lookupUri != null && contactInfo.userType != ContactsUtils.USER_TYPE_WORK) {
585 builder.addPerson(contactInfo.lookupUri.toString());
586 } else if (!TextUtils.isEmpty(call.getNumber())) {
587 builder.addPerson(Uri.fromParts(PhoneAccount.SCHEME_TEL, call.getNumber(), null).toString());
588 }
589 }
590
591 /** Gets a large icon from the contact info object to display in the notification. */
Eric Erfanian83b20212017-05-31 08:53:10 -0700592 private static Bitmap getLargeIconToDisplay(
593 Context context, ContactCacheEntry contactInfo, DialerCall call) {
wangqic8cf79e2017-10-17 09:21:00 -0700594 Trace.beginSection("StatusBarNotifier.getLargeIconToDisplay");
Eric Erfanian83b20212017-05-31 08:53:10 -0700595 Resources resources = context.getResources();
Eric Erfanianccca3152017-02-22 16:32:36 -0800596 Bitmap largeIcon = null;
Eric Erfanianccca3152017-02-22 16:32:36 -0800597 if (contactInfo.photo != null && (contactInfo.photo instanceof BitmapDrawable)) {
598 largeIcon = ((BitmapDrawable) contactInfo.photo).getBitmap();
599 }
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700600 if (contactInfo.photo == null) {
Eric Erfanian83b20212017-05-31 08:53:10 -0700601 int width = (int) resources.getDimension(android.R.dimen.notification_large_icon_width);
602 int height = (int) resources.getDimension(android.R.dimen.notification_large_icon_height);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700603 @ContactType
604 int contactType =
605 LetterTileDrawable.getContactTypeFromPrimitives(
wangqi9982f0d2017-10-11 17:46:07 -0700606 call.isVoiceMailNumber(),
Eric Erfanian2ca43182017-08-31 06:57:16 -0700607 call.isSpam(),
608 contactInfo.isBusiness,
609 call.getNumberPresentation(),
610 call.isConferenceCall() && !call.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE));
Eric Erfanian83b20212017-05-31 08:53:10 -0700611 LetterTileDrawable lettertile = new LetterTileDrawable(resources);
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700612
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700613 lettertile.setCanonicalDialerLetterTileDetails(
614 contactInfo.namePrimary == null ? contactInfo.number : contactInfo.namePrimary,
615 contactInfo.lookupKey,
616 LetterTileDrawable.SHAPE_CIRCLE,
617 contactType);
618 largeIcon = lettertile.getBitmap(width, height);
619 }
620
Eric Erfanianccca3152017-02-22 16:32:36 -0800621 if (call.isSpam()) {
Eric Erfanian83b20212017-05-31 08:53:10 -0700622 Drawable drawable = resources.getDrawable(R.drawable.blocked_contact, context.getTheme());
Eric Erfanianccca3152017-02-22 16:32:36 -0800623 largeIcon = DrawableConverter.drawableToBitmap(drawable);
624 }
wangqic8cf79e2017-10-17 09:21:00 -0700625 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800626 return largeIcon;
627 }
628
629 private Bitmap getRoundedIcon(Bitmap bitmap) {
630 if (bitmap == null) {
631 return null;
632 }
633 final int height =
linyuh183cb712017-12-27 17:02:37 -0800634 (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_height);
Eric Erfanianccca3152017-02-22 16:32:36 -0800635 final int width =
linyuh183cb712017-12-27 17:02:37 -0800636 (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_width);
Eric Erfanianccca3152017-02-22 16:32:36 -0800637 return BitmapUtil.getRoundedBitmap(bitmap, width, height);
638 }
639
640 /**
641 * Returns the appropriate icon res Id to display based on the call for which we want to display
642 * information.
643 */
Eric Erfanian2827dd12017-10-26 09:37:50 -0700644 @VisibleForTesting
645 public int getIconToDisplay(DialerCall call) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800646 // Even if both lines are in use, we only show a single item in
647 // the expanded Notifications UI. It's labeled "Ongoing call"
648 // (or "On hold" if there's only one call, and it's on hold.)
649 // Also, we don't have room to display caller-id info from two
650 // different calls. So if both lines are in use, display info
651 // from the foreground call. And if there's a ringing call,
652 // display that regardless of the state of the other calls.
wangqibb94ca62018-04-27 14:34:04 -0700653 if (call.getState() == DialerCallState.ONHOLD) {
Eric Erfanian2827dd12017-10-26 09:37:50 -0700654 return R.drawable.quantum_ic_phone_paused_vd_theme_24;
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700655 } else if (call.getVideoTech().getSessionModificationState()
calderwoodra1dc2cea2017-09-20 16:30:41 -0700656 == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST
657 || call.isVideoCall()) {
linyuh8dc242d2018-03-28 13:09:47 -0700658 return R.drawable.quantum_ic_videocam_vd_white_24;
Eric Erfanian90508232017-03-24 09:31:16 -0700659 } else if (call.hasProperty(PROPERTY_HIGH_DEF_AUDIO)
linyuh183cb712017-12-27 17:02:37 -0800660 && MotorolaUtils.shouldShowHdIconInNotification(context)) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700661 // Normally when a call is ongoing the status bar displays an icon of a phone. This is a
662 // helpful hint for users so they know how to get back to the call. For Sprint HD calls, we
663 // 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 -0700664 return R.drawable.ic_hd_call;
Eric Erfanian2827dd12017-10-26 09:37:50 -0700665 } else if (call.hasProperty(Details.PROPERTY_HAS_CDMA_VOICE_PRIVACY)) {
666 return R.drawable.quantum_ic_phone_locked_vd_theme_24;
Eric Erfanianccca3152017-02-22 16:32:36 -0800667 }
yueg48f93f42018-03-09 16:49:38 -0800668 // If ReturnToCall is enabled, use the static icon. The animated one will show in the bubble.
669 if (ReturnToCallController.isEnabled(context)) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700670 return R.drawable.quantum_ic_call_vd_theme_24;
671 } else {
672 return R.drawable.on_going_call;
673 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800674 }
675
676 /** Returns the message to use with the notification. */
twyend1d1d0c2017-10-05 17:34:43 -0700677 private CharSequence getContentString(DialerCall call, @UserType long userType) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800678 boolean isIncomingOrWaiting =
wangqibb94ca62018-04-27 14:34:04 -0700679 call.getState() == DialerCallState.INCOMING
680 || call.getState() == DialerCallState.CALL_WAITING;
Eric Erfanianccca3152017-02-22 16:32:36 -0800681
682 if (isIncomingOrWaiting
683 && call.getNumberPresentation() == TelecomManager.PRESENTATION_ALLOWED) {
684
685 if (!TextUtils.isEmpty(call.getChildNumber())) {
linyuh183cb712017-12-27 17:02:37 -0800686 return context.getString(R.string.child_number, call.getChildNumber());
Eric Erfanianccca3152017-02-22 16:32:36 -0800687 } else if (!TextUtils.isEmpty(call.getCallSubject()) && call.isCallSubjectSupported()) {
688 return call.getCallSubject();
689 }
690 }
691
692 int resId = R.string.notification_ongoing_call;
linyuh183cb712017-12-27 17:02:37 -0800693 String wifiBrand = context.getString(R.string.notification_call_wifi_brand);
Eric Erfanianccca3152017-02-22 16:32:36 -0800694 if (call.hasProperty(Details.PROPERTY_WIFI)) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700695 resId = R.string.notification_ongoing_call_wifi_template;
Eric Erfanianccca3152017-02-22 16:32:36 -0800696 }
697
698 if (isIncomingOrWaiting) {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700699 if (call.isSpam()) {
700 resId = R.string.notification_incoming_spam_call;
Eric Erfanian2ca43182017-08-31 06:57:16 -0700701 } else if (shouldShowEnrichedCallNotification(call.getEnrichedCallSession())) {
702 resId = getECIncomingCallText(call.getEnrichedCallSession());
Eric Erfaniand8046e52017-04-06 09:41:50 -0700703 } else if (call.hasProperty(Details.PROPERTY_WIFI)) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700704 resId = R.string.notification_incoming_call_wifi_template;
wangqi9982f0d2017-10-11 17:46:07 -0700705 } else if (call.getAccountHandle() != null && hasMultiplePhoneAccounts(call)) {
twyend1d1d0c2017-10-05 17:34:43 -0700706 return getMultiSimIncomingText(call);
yueg45e45732017-10-09 14:35:06 -0700707 } else if (call.isVideoCall()) {
708 resId = R.string.notification_incoming_video_call;
Eric Erfanianccca3152017-02-22 16:32:36 -0800709 } else {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700710 resId = R.string.notification_incoming_call;
Eric Erfanianccca3152017-02-22 16:32:36 -0800711 }
wangqibb94ca62018-04-27 14:34:04 -0700712 } else if (call.getState() == DialerCallState.ONHOLD) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800713 resId = R.string.notification_on_hold;
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;
wangqibb94ca62018-04-27 14:34:04 -0700719 } else if (DialerCallState.isDialing(call.getState())) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800720 resId = R.string.notification_dialing;
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700721 } else if (call.getVideoTech().getSessionModificationState()
Eric Erfanian90508232017-03-24 09:31:16 -0700722 == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800723 resId = R.string.notification_requesting_video_call;
724 }
725
726 // Is the call placed through work connection service.
727 boolean isWorkCall = call.hasProperty(PROPERTY_ENTERPRISE_CALL);
728 if (userType == ContactsUtils.USER_TYPE_WORK || isWorkCall) {
729 resId = getWorkStringFromPersonalString(resId);
linyuh183cb712017-12-27 17:02:37 -0800730 wifiBrand = context.getString(R.string.notification_call_wifi_work_brand);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700731 }
732
733 if (resId == R.string.notification_incoming_call_wifi_template
734 || resId == R.string.notification_ongoing_call_wifi_template) {
Eric Erfanian938468d2017-10-24 14:05:52 -0700735 // TODO(a bug): Potentially apply this template logic everywhere.
linyuh183cb712017-12-27 17:02:37 -0800736 return context.getString(resId, wifiBrand);
Eric Erfanianccca3152017-02-22 16:32:36 -0800737 }
738
linyuh183cb712017-12-27 17:02:37 -0800739 return context.getString(resId);
Eric Erfanianccca3152017-02-22 16:32:36 -0800740 }
741
Eric Erfanian2ca43182017-08-31 06:57:16 -0700742 private boolean shouldShowEnrichedCallNotification(Session session) {
743 if (session == null) {
744 return false;
745 }
746 return session.getMultimediaData().hasData() || session.getMultimediaData().isImportant();
747 }
748
Eric Erfaniand8046e52017-04-06 09:41:50 -0700749 private int getECIncomingCallText(Session session) {
750 int resId;
751 MultimediaData data = session.getMultimediaData();
752 boolean hasImage = data.hasImageData();
753 boolean hasSubject = !TextUtils.isEmpty(data.getText());
754 boolean hasMap = data.getLocation() != null;
755 if (data.isImportant()) {
756 if (hasMap) {
757 if (hasImage) {
758 if (hasSubject) {
759 resId = R.string.important_notification_incoming_call_with_photo_message_location;
760 } else {
761 resId = R.string.important_notification_incoming_call_with_photo_location;
762 }
763 } else if (hasSubject) {
764 resId = R.string.important_notification_incoming_call_with_message_location;
765 } else {
766 resId = R.string.important_notification_incoming_call_with_location;
767 }
768 } else if (hasImage) {
769 if (hasSubject) {
770 resId = R.string.important_notification_incoming_call_with_photo_message;
771 } else {
772 resId = R.string.important_notification_incoming_call_with_photo;
773 }
Eric Erfanian2ca43182017-08-31 06:57:16 -0700774 } else if (hasSubject) {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700775 resId = R.string.important_notification_incoming_call_with_message;
Eric Erfanian2ca43182017-08-31 06:57:16 -0700776 } else {
777 resId = R.string.important_notification_incoming_call;
Eric Erfaniand8046e52017-04-06 09:41:50 -0700778 }
linyuh183cb712017-12-27 17:02:37 -0800779 if (context.getString(resId).length() > 50) {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700780 resId = R.string.important_notification_incoming_call_attachments;
781 }
782 } else {
783 if (hasMap) {
784 if (hasImage) {
785 if (hasSubject) {
786 resId = R.string.notification_incoming_call_with_photo_message_location;
787 } else {
788 resId = R.string.notification_incoming_call_with_photo_location;
789 }
790 } else if (hasSubject) {
791 resId = R.string.notification_incoming_call_with_message_location;
792 } else {
793 resId = R.string.notification_incoming_call_with_location;
794 }
795 } else if (hasImage) {
796 if (hasSubject) {
797 resId = R.string.notification_incoming_call_with_photo_message;
798 } else {
799 resId = R.string.notification_incoming_call_with_photo;
800 }
801 } else {
802 resId = R.string.notification_incoming_call_with_message;
803 }
804 }
linyuh183cb712017-12-27 17:02:37 -0800805 if (context.getString(resId).length() > 50) {
Eric Erfaniand8046e52017-04-06 09:41:50 -0700806 resId = R.string.notification_incoming_call_attachments;
807 }
808 return resId;
809 }
810
twyend1d1d0c2017-10-05 17:34:43 -0700811 private CharSequence getMultiSimIncomingText(DialerCall call) {
812 PhoneAccount phoneAccount =
linyuh183cb712017-12-27 17:02:37 -0800813 context.getSystemService(TelecomManager.class).getPhoneAccount(call.getAccountHandle());
twyene931c122018-03-19 14:47:28 -0700814 if (phoneAccount == null) {
815 return context.getString(R.string.notification_incoming_call);
816 }
twyend1d1d0c2017-10-05 17:34:43 -0700817 SpannableString string =
818 new SpannableString(
linyuh183cb712017-12-27 17:02:37 -0800819 context.getString(
twyend1d1d0c2017-10-05 17:34:43 -0700820 R.string.notification_incoming_call_mutli_sim, phoneAccount.getLabel()));
821 int accountStart = string.toString().lastIndexOf(phoneAccount.getLabel().toString());
822 int accountEnd = accountStart + phoneAccount.getLabel().length();
823
824 string.setSpan(
825 new ForegroundColorSpan(phoneAccount.getHighlightColor()),
826 accountStart,
827 accountEnd,
828 Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
829 return string;
830 }
831
Eric Erfanianccca3152017-02-22 16:32:36 -0800832 /** Gets the most relevant call to display in the notification. */
833 private DialerCall getCallToShow(CallList callList) {
834 if (callList == null) {
835 return null;
836 }
837 DialerCall call = callList.getIncomingCall();
838 if (call == null) {
839 call = callList.getOutgoingCall();
840 }
841 if (call == null) {
842 call = callList.getVideoUpgradeRequestCall();
843 }
844 if (call == null) {
845 call = callList.getActiveOrBackgroundCall();
846 }
847 return call;
848 }
849
850 private Spannable getActionText(@StringRes int stringRes, @ColorRes int colorRes) {
linyuh183cb712017-12-27 17:02:37 -0800851 Spannable spannable = new SpannableString(context.getText(stringRes));
Eric Erfanianccca3152017-02-22 16:32:36 -0800852 if (VERSION.SDK_INT >= VERSION_CODES.N_MR1) {
853 // This will only work for cases where the Notification.Builder has a fullscreen intent set
854 // Notification.Builder that does not have a full screen intent will take the color of the
855 // app and the following leads to a no-op.
856 spannable.setSpan(
linyuh183cb712017-12-27 17:02:37 -0800857 new ForegroundColorSpan(context.getColor(colorRes)), 0, spannable.length(), 0);
Eric Erfanianccca3152017-02-22 16:32:36 -0800858 }
859 return spannable;
860 }
861
862 private void addAnswerAction(Notification.Builder builder) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700863 LogUtil.d(
864 "StatusBarNotifier.addAnswerAction",
865 "will show \"answer\" action in the incoming call Notification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800866 PendingIntent answerVoicePendingIntent =
linyuh183cb712017-12-27 17:02:37 -0800867 createNotificationPendingIntent(context, ACTION_ANSWER_VOICE_INCOMING_CALL);
Eric Erfanianccca3152017-02-22 16:32:36 -0800868 builder.addAction(
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700869 new Notification.Action.Builder(
linyuh183cb712017-12-27 17:02:37 -0800870 Icon.createWithResource(context, R.drawable.quantum_ic_call_white_24),
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700871 getActionText(
872 R.string.notification_action_answer, R.color.notification_action_accept),
873 answerVoicePendingIntent)
874 .build());
Eric Erfanianccca3152017-02-22 16:32:36 -0800875 }
876
erfanian1e4ef182018-06-11 11:05:51 -0700877 private void addSpeakeasyAnswerAction(Notification.Builder builder) {
878 if (!ConfigProviderComponent.get(context)
879 .getConfigProvider()
880 .getBoolean("enable_speakeasy_notification_button", false)) {
881 return;
882 }
883
884 if (!SpeakEasyComponent.get(context).speakEasyCallManager().isAvailable(context)) {
885 return;
886 }
887
888 Optional<Integer> buttonText = SpeakEasyComponent.get(context).speakEasyTextResource();
889 if (!buttonText.isPresent()) {
890 return;
891 }
892
893 LogUtil.d("StatusBarNotifier.addSpeakeasyAnswerAction", "showing button");
894 PendingIntent answerVoicePendingIntent =
895 createNotificationPendingIntent(context, ACTION_ANSWER_SPEAKEASY_CALL);
896
897 Spannable spannable = new SpannableString(context.getText(buttonText.get()));
898 // TODO(erfanian): Migrate these color values to somewhere more permanent in subsequent
899 // implementation.
900 spannable.setSpan(
901 new ForegroundColorSpan(
902 context.getColor(R.color.DO_NOT_USE_OR_I_WILL_BREAK_YOU_text_span_tertiary_button)),
903 0,
904 spannable.length(),
905 Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
906
907 builder.addAction(
908 new Notification.Action.Builder(
909 Icon.createWithResource(context, R.drawable.quantum_ic_call_white_24),
910 spannable,
911 answerVoicePendingIntent)
912 .build());
913 }
914
Eric Erfanianccca3152017-02-22 16:32:36 -0800915 private void addDismissAction(Notification.Builder builder) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700916 LogUtil.d(
917 "StatusBarNotifier.addDismissAction",
918 "will show \"decline\" action in the incoming call Notification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800919 PendingIntent declinePendingIntent =
linyuh183cb712017-12-27 17:02:37 -0800920 createNotificationPendingIntent(context, ACTION_DECLINE_INCOMING_CALL);
Eric Erfanianccca3152017-02-22 16:32:36 -0800921 builder.addAction(
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700922 new Notification.Action.Builder(
linyuh183cb712017-12-27 17:02:37 -0800923 Icon.createWithResource(context, R.drawable.quantum_ic_close_white_24),
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700924 getActionText(
925 R.string.notification_action_dismiss, R.color.notification_action_dismiss),
926 declinePendingIntent)
927 .build());
Eric Erfanianccca3152017-02-22 16:32:36 -0800928 }
929
930 private void addHangupAction(Notification.Builder builder) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700931 LogUtil.d(
932 "StatusBarNotifier.addHangupAction",
933 "will show \"hang-up\" action in the ongoing active call Notification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800934 PendingIntent hangupPendingIntent =
linyuh183cb712017-12-27 17:02:37 -0800935 createNotificationPendingIntent(context, ACTION_HANG_UP_ONGOING_CALL);
Eric Erfanianccca3152017-02-22 16:32:36 -0800936 builder.addAction(
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700937 new Notification.Action.Builder(
linyuh183cb712017-12-27 17:02:37 -0800938 Icon.createWithResource(context, R.drawable.quantum_ic_call_end_white_24),
939 context.getText(R.string.notification_action_end_call),
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700940 hangupPendingIntent)
941 .build());
Eric Erfanianccca3152017-02-22 16:32:36 -0800942 }
943
yuegb26c1ae2017-09-18 16:59:16 -0700944 private void addSpeakerAction(Notification.Builder builder, CallAudioState callAudioState) {
945 if ((callAudioState.getSupportedRouteMask() & CallAudioState.ROUTE_BLUETOOTH)
946 == CallAudioState.ROUTE_BLUETOOTH) {
947 // Don't add speaker button if bluetooth is connected
948 return;
949 }
950 if (callAudioState.getRoute() == CallAudioState.ROUTE_SPEAKER) {
951 addSpeakerOffAction(builder);
952 } else if ((callAudioState.getRoute() & CallAudioState.ROUTE_WIRED_OR_EARPIECE) != 0) {
953 addSpeakerOnAction(builder);
954 }
955 }
956
957 private void addSpeakerOnAction(Notification.Builder builder) {
958 LogUtil.d(
959 "StatusBarNotifier.addSpeakerOnAction",
960 "will show \"Speaker on\" action in the ongoing active call Notification");
961 PendingIntent speakerOnPendingIntent =
linyuh183cb712017-12-27 17:02:37 -0800962 createNotificationPendingIntent(context, ACTION_TURN_ON_SPEAKER);
yuegb26c1ae2017-09-18 16:59:16 -0700963 builder.addAction(
964 new Notification.Action.Builder(
wangqi6ca8c722018-03-29 10:19:58 -0700965 Icon.createWithResource(context, R.drawable.quantum_ic_volume_up_vd_theme_24),
linyuh183cb712017-12-27 17:02:37 -0800966 context.getText(R.string.notification_action_speaker_on),
yuegb26c1ae2017-09-18 16:59:16 -0700967 speakerOnPendingIntent)
968 .build());
969 }
970
971 private void addSpeakerOffAction(Notification.Builder builder) {
972 LogUtil.d(
973 "StatusBarNotifier.addSpeakerOffAction",
974 "will show \"Speaker off\" action in the ongoing active call Notification");
975 PendingIntent speakerOffPendingIntent =
linyuh183cb712017-12-27 17:02:37 -0800976 createNotificationPendingIntent(context, ACTION_TURN_OFF_SPEAKER);
yuegb26c1ae2017-09-18 16:59:16 -0700977 builder.addAction(
978 new Notification.Action.Builder(
wangqi6ca8c722018-03-29 10:19:58 -0700979 Icon.createWithResource(context, R.drawable.quantum_ic_phone_in_talk_vd_theme_24),
linyuh183cb712017-12-27 17:02:37 -0800980 context.getText(R.string.notification_action_speaker_off),
yuegb26c1ae2017-09-18 16:59:16 -0700981 speakerOffPendingIntent)
982 .build());
983 }
984
Eric Erfanianccca3152017-02-22 16:32:36 -0800985 private void addVideoCallAction(Notification.Builder builder) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700986 LogUtil.i(
987 "StatusBarNotifier.addVideoCallAction",
988 "will show \"video\" action in the incoming call Notification");
Eric Erfanianccca3152017-02-22 16:32:36 -0800989 PendingIntent answerVideoPendingIntent =
linyuh183cb712017-12-27 17:02:37 -0800990 createNotificationPendingIntent(context, ACTION_ANSWER_VIDEO_INCOMING_CALL);
Eric Erfanianccca3152017-02-22 16:32:36 -0800991 builder.addAction(
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700992 new Notification.Action.Builder(
linyuh8dc242d2018-03-28 13:09:47 -0700993 Icon.createWithResource(context, R.drawable.quantum_ic_videocam_vd_white_24),
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700994 getActionText(
995 R.string.notification_action_answer_video,
996 R.color.notification_action_answer_video),
997 answerVideoPendingIntent)
998 .build());
Eric Erfanianccca3152017-02-22 16:32:36 -0800999 }
1000
1001 private void addAcceptUpgradeRequestAction(Notification.Builder builder) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001002 LogUtil.i(
1003 "StatusBarNotifier.addAcceptUpgradeRequestAction",
1004 "will show \"accept upgrade\" action in the incoming call Notification");
Eric Erfanianccca3152017-02-22 16:32:36 -08001005 PendingIntent acceptVideoPendingIntent =
linyuh183cb712017-12-27 17:02:37 -08001006 createNotificationPendingIntent(context, ACTION_ACCEPT_VIDEO_UPGRADE_REQUEST);
Eric Erfanianccca3152017-02-22 16:32:36 -08001007 builder.addAction(
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001008 new Notification.Action.Builder(
linyuh8dc242d2018-03-28 13:09:47 -07001009 Icon.createWithResource(context, R.drawable.quantum_ic_videocam_vd_white_24),
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001010 getActionText(
1011 R.string.notification_action_accept, R.color.notification_action_accept),
1012 acceptVideoPendingIntent)
1013 .build());
Eric Erfanianccca3152017-02-22 16:32:36 -08001014 }
1015
1016 private void addDismissUpgradeRequestAction(Notification.Builder builder) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001017 LogUtil.i(
1018 "StatusBarNotifier.addDismissUpgradeRequestAction",
1019 "will show \"dismiss upgrade\" action in the incoming call Notification");
Eric Erfanianccca3152017-02-22 16:32:36 -08001020 PendingIntent declineVideoPendingIntent =
linyuh183cb712017-12-27 17:02:37 -08001021 createNotificationPendingIntent(context, ACTION_DECLINE_VIDEO_UPGRADE_REQUEST);
Eric Erfanianccca3152017-02-22 16:32:36 -08001022 builder.addAction(
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001023 new Notification.Action.Builder(
linyuh8dc242d2018-03-28 13:09:47 -07001024 Icon.createWithResource(context, R.drawable.quantum_ic_videocam_vd_white_24),
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001025 getActionText(
1026 R.string.notification_action_dismiss, R.color.notification_action_dismiss),
1027 declineVideoPendingIntent)
1028 .build());
Eric Erfanianccca3152017-02-22 16:32:36 -08001029 }
1030
1031 /** Adds fullscreen intent to the builder. */
Eric Erfanian10b34a52017-05-04 08:23:17 -07001032 private void configureFullScreenIntent(Notification.Builder builder, PendingIntent intent) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001033 // Ok, we actually want to launch the incoming call
1034 // UI at this point (in addition to simply posting a notification
1035 // to the status bar). Setting fullScreenIntent will cause
1036 // the InCallScreen to be launched immediately *unless* the
1037 // current foreground activity is marked as "immersive".
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001038 LogUtil.d("StatusBarNotifier.configureFullScreenIntent", "setting fullScreenIntent: " + intent);
Eric Erfanianccca3152017-02-22 16:32:36 -08001039 builder.setFullScreenIntent(intent, true);
Eric Erfanianccca3152017-02-22 16:32:36 -08001040 }
1041
1042 private Notification.Builder getNotificationBuilder() {
linyuh183cb712017-12-27 17:02:37 -08001043 final Notification.Builder builder = new Notification.Builder(context);
Eric Erfanianccca3152017-02-22 16:32:36 -08001044 builder.setOngoing(true);
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001045 builder.setOnlyAlertOnce(true);
Eric Erfanian10b34a52017-05-04 08:23:17 -07001046 // This will be ignored on O+ and handled by the channel
Eric Erfanian2ca43182017-08-31 06:57:16 -07001047 // noinspection deprecation
Eric Erfanian10b34a52017-05-04 08:23:17 -07001048 builder.setPriority(Notification.PRIORITY_HIGH);
Eric Erfanianccca3152017-02-22 16:32:36 -08001049
1050 return builder;
1051 }
1052
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001053 private PendingIntent createLaunchPendingIntent(boolean isFullScreen) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001054 Intent intent =
1055 InCallActivity.getIntent(
linyuh183cb712017-12-27 17:02:37 -08001056 context, false /* showDialpad */, false /* newOutgoingCall */, isFullScreen);
Eric Erfanianccca3152017-02-22 16:32:36 -08001057
linyuhc3968e62017-11-20 17:40:50 -08001058 int requestCode = InCallActivity.PendingIntentRequestCodes.NON_FULL_SCREEN;
Eric Erfanianccca3152017-02-22 16:32:36 -08001059 if (isFullScreen) {
1060 // Use a unique request code so that the pending intent isn't clobbered by the
1061 // non-full screen pending intent.
linyuhc3968e62017-11-20 17:40:50 -08001062 requestCode = InCallActivity.PendingIntentRequestCodes.FULL_SCREEN;
Eric Erfanianccca3152017-02-22 16:32:36 -08001063 }
1064
1065 // PendingIntent that can be used to launch the InCallActivity. The
1066 // system fires off this intent if the user pulls down the windowshade
1067 // and clicks the notification's expanded view. It's also used to
1068 // launch the InCallActivity immediately when when there's an incoming
1069 // call (see the "fullScreenIntent" field below).
linyuh183cb712017-12-27 17:02:37 -08001070 return PendingIntent.getActivity(context, requestCode, intent, 0);
Eric Erfanianccca3152017-02-22 16:32:36 -08001071 }
1072
1073 private void setStatusBarCallListener(StatusBarCallListener listener) {
linyuh183cb712017-12-27 17:02:37 -08001074 if (statusBarCallListener != null) {
1075 statusBarCallListener.cleanup();
Eric Erfanianccca3152017-02-22 16:32:36 -08001076 }
linyuh183cb712017-12-27 17:02:37 -08001077 statusBarCallListener = listener;
Eric Erfanianccca3152017-02-22 16:32:36 -08001078 }
1079
wangqi9982f0d2017-10-11 17:46:07 -07001080 private boolean hasMultiplePhoneAccounts(DialerCall call) {
1081 if (call.getCallCapableAccounts() == null) {
1082 return false;
1083 }
1084 return call.getCallCapableAccounts().size() > 1;
twyend1d1d0c2017-10-05 17:34:43 -07001085 }
1086
yuegb26c1ae2017-09-18 16:59:16 -07001087 @Override
wangqic8cf79e2017-10-17 09:21:00 -07001088 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
1089 public void onContactInfoComplete(String callId, ContactCacheEntry entry) {
1090 DialerCall call = CallList.getInstance().getCallById(callId);
1091 if (call != null) {
1092 call.getLogState().contactLookupResult = entry.contactLookupResult;
1093 buildAndSendNotification(CallList.getInstance(), call, entry);
1094 }
1095 }
1096
1097 @Override
1098 @RequiresPermission(Manifest.permission.READ_PHONE_STATE)
1099 public void onImageLoadComplete(String callId, ContactCacheEntry entry) {
1100 DialerCall call = CallList.getInstance().getCallById(callId);
1101 if (call != null) {
1102 buildAndSendNotification(CallList.getInstance(), call, entry);
1103 }
yuegb26c1ae2017-09-18 16:59:16 -07001104 }
1105
Eric Erfanianccca3152017-02-22 16:32:36 -08001106 private class StatusBarCallListener implements DialerCallListener {
1107
linyuh183cb712017-12-27 17:02:37 -08001108 private DialerCall dialerCall;
Eric Erfanianccca3152017-02-22 16:32:36 -08001109
1110 StatusBarCallListener(DialerCall dialerCall) {
linyuh183cb712017-12-27 17:02:37 -08001111 this.dialerCall = dialerCall;
1112 this.dialerCall.addListener(this);
Eric Erfanianccca3152017-02-22 16:32:36 -08001113 }
1114
1115 void cleanup() {
linyuh183cb712017-12-27 17:02:37 -08001116 dialerCall.removeListener(this);
Eric Erfanianccca3152017-02-22 16:32:36 -08001117 }
1118
1119 @Override
1120 public void onDialerCallDisconnect() {}
1121
1122 @Override
1123 public void onDialerCallUpdate() {
1124 if (CallList.getInstance().getIncomingCall() == null) {
linyuh183cb712017-12-27 17:02:37 -08001125 dialerRingtoneManager.stopCallWaitingTone();
Eric Erfanianccca3152017-02-22 16:32:36 -08001126 }
1127 }
1128
1129 @Override
1130 public void onDialerCallChildNumberChange() {}
1131
1132 @Override
1133 public void onDialerCallLastForwardedNumberChange() {}
1134
1135 @Override
1136 public void onDialerCallUpgradeToVideo() {}
1137
1138 @Override
1139 public void onWiFiToLteHandover() {}
1140
1141 @Override
1142 public void onHandoverToWifiFailure() {}
1143
Eric Erfanianc857f902017-05-15 14:05:33 -07001144 @Override
1145 public void onInternationalCallOnWifi() {}
1146
Eric Erfanian2ca43182017-08-31 06:57:16 -07001147 @Override
1148 public void onEnrichedCallSessionUpdate() {}
1149
Eric Erfanianccca3152017-02-22 16:32:36 -08001150 /**
1151 * Responds to changes in the session modification state for the call by dismissing the status
1152 * bar notification as required.
1153 */
1154 @Override
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001155 public void onDialerCallSessionModificationStateChange() {
linyuh183cb712017-12-27 17:02:37 -08001156 if (dialerCall.getVideoTech().getSessionModificationState()
Eric Erfanian90508232017-03-24 09:31:16 -07001157 == SessionModificationState.NO_REQUEST) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001158 cleanup();
wangqic8cf79e2017-10-17 09:21:00 -07001159 updateNotification();
Eric Erfanianccca3152017-02-22 16:32:36 -08001160 }
1161 }
1162 }
1163}