Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.incallui; |
| 18 | |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 19 | import static android.telecom.Call.Details.PROPERTY_HIGH_DEF_AUDIO; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 20 | import static com.android.contacts.common.compat.CallCompat.Details.PROPERTY_ENTERPRISE_CALL; |
| 21 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ACCEPT_VIDEO_UPGRADE_REQUEST; |
erfanian | 1e4ef18 | 2018-06-11 11:05:51 -0700 | [diff] [blame^] | 22 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ANSWER_SPEAKEASY_CALL; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 23 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ANSWER_VIDEO_INCOMING_CALL; |
| 24 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ANSWER_VOICE_INCOMING_CALL; |
| 25 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_DECLINE_INCOMING_CALL; |
| 26 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_DECLINE_VIDEO_UPGRADE_REQUEST; |
| 27 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_HANG_UP_ONGOING_CALL; |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 28 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_TURN_OFF_SPEAKER; |
| 29 | import static com.android.incallui.NotificationBroadcastReceiver.ACTION_TURN_ON_SPEAKER; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 30 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 31 | import android.Manifest; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 32 | import android.app.Notification; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 33 | import android.app.PendingIntent; |
| 34 | import android.content.Context; |
| 35 | import android.content.Intent; |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 36 | import android.content.res.Resources; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 37 | import android.graphics.Bitmap; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 38 | import android.graphics.drawable.BitmapDrawable; |
| 39 | import android.graphics.drawable.Drawable; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 40 | import android.graphics.drawable.Icon; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 41 | import android.media.AudioAttributes; |
| 42 | import android.net.Uri; |
| 43 | import android.os.Build.VERSION; |
| 44 | import android.os.Build.VERSION_CODES; |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 45 | import android.os.Trace; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 46 | import android.support.annotation.ColorRes; |
| 47 | import android.support.annotation.NonNull; |
| 48 | import android.support.annotation.Nullable; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 49 | import android.support.annotation.RequiresPermission; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 50 | import android.support.annotation.StringRes; |
| 51 | import android.support.annotation.VisibleForTesting; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 52 | import android.support.v4.os.BuildCompat; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 53 | import android.telecom.Call.Details; |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 54 | import android.telecom.CallAudioState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 55 | import android.telecom.PhoneAccount; |
| 56 | import android.telecom.TelecomManager; |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 57 | import android.telecom.VideoProfile; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 58 | import android.text.BidiFormatter; |
| 59 | import android.text.Spannable; |
| 60 | import android.text.SpannableString; |
erfanian | 1e4ef18 | 2018-06-11 11:05:51 -0700 | [diff] [blame^] | 61 | import android.text.Spanned; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 62 | import android.text.TextDirectionHeuristics; |
| 63 | import android.text.TextUtils; |
| 64 | import android.text.style.ForegroundColorSpan; |
| 65 | import com.android.contacts.common.ContactsUtils; |
| 66 | import com.android.contacts.common.ContactsUtils.UserType; |
| 67 | import com.android.contacts.common.preference.ContactsPreferences; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 68 | import com.android.contacts.common.util.ContactDisplayUtils; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 69 | import com.android.dialer.common.Assert; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 70 | import com.android.dialer.common.LogUtil; |
zachh | 190343a | 2018-05-31 17:30:46 -0700 | [diff] [blame] | 71 | import com.android.dialer.configprovider.ConfigProviderComponent; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 72 | import com.android.dialer.contactphoto.BitmapUtil; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 73 | import com.android.dialer.enrichedcall.EnrichedCallManager; |
| 74 | import com.android.dialer.enrichedcall.Session; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 75 | import com.android.dialer.lettertile.LetterTileDrawable; |
| 76 | import com.android.dialer.lettertile.LetterTileDrawable.ContactType; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 77 | import com.android.dialer.multimedia.MultimediaData; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 78 | import com.android.dialer.notification.NotificationChannelId; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 79 | import com.android.dialer.oem.MotorolaUtils; |
calderwoodra | a93df43 | 2018-05-23 12:59:03 -0700 | [diff] [blame] | 80 | import com.android.dialer.theme.base.ThemeComponent; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 81 | import com.android.dialer.util.DrawableConverter; |
| 82 | import com.android.incallui.ContactInfoCache.ContactCacheEntry; |
| 83 | import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback; |
| 84 | import com.android.incallui.InCallPresenter.InCallState; |
| 85 | import com.android.incallui.async.PausableExecutorImpl; |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 86 | import com.android.incallui.audiomode.AudioModeProvider; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 87 | import com.android.incallui.call.CallList; |
| 88 | import com.android.incallui.call.DialerCall; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 89 | import com.android.incallui.call.DialerCallListener; |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 90 | import com.android.incallui.call.TelecomAdapter; |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 91 | import com.android.incallui.call.state.DialerCallState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 92 | import com.android.incallui.ringtone.DialerRingtoneManager; |
| 93 | import com.android.incallui.ringtone.InCallTonePlayer; |
| 94 | import com.android.incallui.ringtone.ToneGeneratorFactory; |
erfanian | 1e4ef18 | 2018-06-11 11:05:51 -0700 | [diff] [blame^] | 95 | import com.android.incallui.speakeasy.SpeakEasyComponent; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 96 | import com.android.incallui.videotech.utils.SessionModificationState; |
erfanian | 1e4ef18 | 2018-06-11 11:05:51 -0700 | [diff] [blame^] | 97 | import com.google.common.base.Optional; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 98 | import java.util.Objects; |
| 99 | |
| 100 | /** This class adds Notifications to the status bar for the in-call experience. */ |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 101 | public class StatusBarNotifier |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 102 | implements InCallPresenter.InCallStateListener, |
| 103 | EnrichedCallManager.StateChangedListener, |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 104 | ContactInfoCacheCallback { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 105 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 106 | private static final int NOTIFICATION_ID = 1; |
| 107 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 108 | // 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 Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 112 | private static final int NOTIFICATION_IN_CALL = 1; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 113 | // Notification for incoming calls. This is interruptive and will show up as a HUN. |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 114 | 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 Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 118 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 119 | private static final long[] VIBRATE_PATTERN = new long[] {0, 1000, 1000}; |
| 120 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 121 | 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; |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 126 | private int callState = DialerCallState.INVALID; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 127 | 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; |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 132 | private CallAudioState savedCallAudioState; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 133 | private Uri ringtone; |
| 134 | private StatusBarCallListener statusBarCallListener; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 135 | |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 136 | public StatusBarNotifier(@NonNull Context context, @NonNull ContactInfoCache contactInfoCache) { |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 137 | Trace.beginSection("StatusBarNotifier.Constructor"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 138 | this.context = Assert.isNotNull(context); |
| 139 | contactsPreferences = ContactsPreferencesFactory.newContactsPreferences(this.context); |
| 140 | this.contactInfoCache = contactInfoCache; |
| 141 | dialerRingtoneManager = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 142 | new DialerRingtoneManager( |
| 143 | new InCallTonePlayer(new ToneGeneratorFactory(), new PausableExecutorImpl()), |
| 144 | CallList.getInstance()); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 145 | currentNotification = NOTIFICATION_NONE; |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 146 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Should only be called from a irrecoverable state where it is necessary to dismiss all |
| 151 | * notifications. |
| 152 | */ |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 153 | static void clearAllCallNotifications() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 154 | LogUtil.e( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 155 | "StatusBarNotifier.clearAllCallNotifications", |
| 156 | "something terrible happened, clear all InCall notifications"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 157 | |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 158 | TelecomAdapter.getInstance().stopForegroundNotification(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 159 | } |
| 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 Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 164 | } 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 Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 182 | @RequiresPermission(Manifest.permission.READ_PHONE_STATE) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 183 | public void onStateChange(InCallState oldState, InCallState newState, CallList callList) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 184 | LogUtil.d("StatusBarNotifier.onStateChange", "%s->%s", oldState, newState); |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 185 | updateNotification(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 186 | } |
| 187 | |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 188 | @Override |
| 189 | public void onEnrichedCallStateChanged() { |
| 190 | LogUtil.enterBlock("StatusBarNotifier.onEnrichedCallStateChanged"); |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 191 | updateNotification(); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 194 | /** |
| 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 | * |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 209 | * @see #updateInCallNotification() |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 210 | */ |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 211 | @RequiresPermission(Manifest.permission.READ_PHONE_STATE) |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 212 | public void updateNotification() { |
| 213 | updateInCallNotification(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Take down the in-call notification. |
| 218 | * |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 219 | * @see #updateInCallNotification() |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 220 | */ |
| 221 | private void cancelNotification() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 222 | if (statusBarCallListener != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 223 | setStatusBarCallListener(null); |
| 224 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 225 | if (currentNotification != NOTIFICATION_NONE) { |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 226 | TelecomAdapter.getInstance().stopForegroundNotification(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 227 | currentNotification = NOTIFICATION_NONE; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 228 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 229 | } |
| 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 Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 236 | @RequiresPermission(Manifest.permission.READ_PHONE_STATE) |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 237 | private void updateInCallNotification() { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 238 | LogUtil.d("StatusBarNotifier.updateInCallNotification", ""); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 239 | |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 240 | final DialerCall call = getCallToShow(CallList.getInstance()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 241 | |
| 242 | if (call != null) { |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 243 | showNotification(call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 244 | } else { |
| 245 | cancelNotification(); |
| 246 | } |
| 247 | } |
| 248 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 249 | @RequiresPermission(Manifest.permission.READ_PHONE_STATE) |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 250 | private void showNotification(final DialerCall call) { |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 251 | Trace.beginSection("StatusBarNotifier.showNotification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 252 | final boolean isIncoming = |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 253 | (call.getState() == DialerCallState.INCOMING |
| 254 | || call.getState() == DialerCallState.CALL_WAITING); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 255 | 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. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 262 | contactInfoCache.findInfo(call, isIncoming, this); |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 263 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /** Sets up the main Ui for the notification */ |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 267 | @RequiresPermission(Manifest.permission.READ_PHONE_STATE) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 268 | private void buildAndSendNotification( |
| 269 | CallList callList, DialerCall originalCall, ContactCacheEntry contactInfo) { |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 270 | Trace.beginSection("StatusBarNotifier.buildAndSendNotification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 271 | // 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())) { |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 276 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 277 | return; |
| 278 | } |
| 279 | |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 280 | Trace.beginSection("prepare work"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 281 | final int callState = call.getState(); |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 282 | final CallAudioState callAudioState = AudioModeProvider.getInstance().getAudioState(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 283 | |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 284 | Trace.beginSection("read icon and strings"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 285 | // Check if data has changed; if nothing is different, don't issue another notification. |
| 286 | final int iconResId = getIconToDisplay(call); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 287 | Bitmap largeIcon = getLargeIconToDisplay(context, contactInfo, call); |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 288 | final CharSequence content = getContentString(call, contactInfo.userType); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 289 | final String contentTitle = getContentTitle(contactInfo, call); |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 290 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 291 | |
| 292 | final boolean isVideoUpgradeRequest = |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 293 | call.getVideoTech().getSessionModificationState() |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 294 | == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 295 | final int notificationType; |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 296 | if (callState == DialerCallState.INCOMING |
| 297 | || callState == DialerCallState.CALL_WAITING |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 298 | || isVideoUpgradeRequest) { |
zachh | 190343a | 2018-05-31 17:30:46 -0700 | [diff] [blame] | 299 | if (ConfigProviderComponent.get(context) |
| 300 | .getConfigProvider() |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 301 | .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 Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 313 | } else { |
| 314 | notificationType = NOTIFICATION_IN_CALL; |
| 315 | } |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 316 | Trace.endSection(); // prepare work |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 317 | |
| 318 | if (!checkForChangeAndSaveData( |
| 319 | iconResId, |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 320 | content.toString(), |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 321 | largeIcon, |
| 322 | contentTitle, |
| 323 | callState, |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 324 | call.getVideoState(), |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 325 | notificationType, |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 326 | contactInfo.contactRingtoneUri, |
| 327 | callAudioState)) { |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 328 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 329 | 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}. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 339 | Notification.Builder publicBuilder = new Notification.Builder(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 340 | publicBuilder |
| 341 | .setSmallIcon(iconResId) |
calderwoodra | a93df43 | 2018-05-23 12:59:03 -0700 | [diff] [blame] | 342 | .setColor(ThemeComponent.get(context).theme().getColorPrimary()) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 343 | // 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 Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 353 | builder.setContentIntent(createLaunchPendingIntent(false /* isFullScreen */)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 354 | |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 355 | LogUtil.i("StatusBarNotifier.buildAndSendNotification", "notificationType=" + notificationType); |
| 356 | switch (notificationType) { |
| 357 | case NOTIFICATION_INCOMING_CALL: |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 358 | if (BuildCompat.isAtLeastO()) { |
| 359 | builder.setChannelId(NotificationChannelId.INCOMING_CALL); |
| 360 | } |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 361 | // Set the intent as a full screen intent as well if a call is incoming |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 362 | 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 Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 366 | builder.setPriority(Notification.PRIORITY_MAX); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 367 | if (currentNotification != NOTIFICATION_INCOMING_CALL) { |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 368 | 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 |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 373 | TelecomAdapter.getInstance().stopForegroundNotification(); |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 374 | } |
| 375 | break; |
| 376 | case NOTIFICATION_INCOMING_CALL_QUIET: |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 377 | if (BuildCompat.isAtLeastO()) { |
| 378 | builder.setChannelId(NotificationChannelId.ONGOING_CALL); |
| 379 | } |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 380 | break; |
| 381 | case NOTIFICATION_IN_CALL: |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 382 | if (BuildCompat.isAtLeastO()) { |
| 383 | publicBuilder.setColorized(true); |
| 384 | builder.setColorized(true); |
| 385 | builder.setChannelId(NotificationChannelId.ONGOING_CALL); |
| 386 | } |
| 387 | break; |
| 388 | default: |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 389 | break; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | // Set the content |
| 393 | builder.setContentText(content); |
| 394 | builder.setSmallIcon(iconResId); |
| 395 | builder.setContentTitle(contentTitle); |
| 396 | builder.setLargeIcon(largeIcon); |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 397 | builder.setColor(InCallPresenter.getInstance().getThemeColorManager().getPrimaryColor()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 398 | |
| 399 | if (isVideoUpgradeRequest) { |
| 400 | builder.setUsesChronometer(false); |
| 401 | addDismissUpgradeRequestAction(builder); |
| 402 | addAcceptUpgradeRequestAction(builder); |
| 403 | } else { |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 404 | createIncomingCallNotification(call, callState, callAudioState, builder); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | addPersonReference(builder, contactInfo, call); |
| 408 | |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 409 | Trace.beginSection("fire notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 410 | // Fire off the notification |
| 411 | Notification notification = builder.build(); |
| 412 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 413 | if (dialerRingtoneManager.shouldPlayRingtone(callState, contactInfo.contactRingtoneUri)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 414 | 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(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 420 | if (dialerRingtoneManager.shouldVibrate(context.getContentResolver())) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 421 | notification.vibrate = VIBRATE_PATTERN; |
| 422 | } |
| 423 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 424 | if (dialerRingtoneManager.shouldPlayCallWaitingTone(callState)) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 425 | LogUtil.v("StatusBarNotifier.buildAndSendNotification", "playing call waiting tone"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 426 | dialerRingtoneManager.playCallWaitingTone(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 427 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 428 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 429 | LogUtil.i( |
| 430 | "StatusBarNotifier.buildAndSendNotification", |
| 431 | "displaying notification for " + notificationType); |
| 432 | |
yueg | 01a964d | 2017-10-03 15:25:41 -0700 | [diff] [blame] | 433 | // If a notification exists, this will only update it. |
| 434 | TelecomAdapter.getInstance().startForegroundNotification(NOTIFICATION_ID, notification); |
| 435 | |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 436 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 437 | call.getLatencyReport().onNotificationShown(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 438 | currentNotification = notificationType; |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 439 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | private void createIncomingCallNotification( |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 443 | DialerCall call, int state, CallAudioState callAudioState, Notification.Builder builder) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 444 | setNotificationWhen(call, state, builder); |
| 445 | |
| 446 | // Add hang up option for any active calls (active | onhold), outgoing calls (dialing). |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 447 | if (state == DialerCallState.ACTIVE |
| 448 | || state == DialerCallState.ONHOLD |
| 449 | || DialerCallState.isDialing(state)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 450 | addHangupAction(builder); |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 451 | addSpeakerAction(builder, callAudioState); |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 452 | } else if (state == DialerCallState.INCOMING || state == DialerCallState.CALL_WAITING) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 453 | addDismissAction(builder); |
| 454 | if (call.isVideoCall()) { |
| 455 | addVideoCallAction(builder); |
| 456 | } else { |
| 457 | addAnswerAction(builder); |
erfanian | 1e4ef18 | 2018-06-11 11:05:51 -0700 | [diff] [blame^] | 458 | addSpeakeasyAnswerAction(builder); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 459 | } |
| 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) { |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 469 | if (state == DialerCallState.ACTIVE) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 470 | 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, |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 488 | int videoState, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 489 | int notificationType, |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 490 | Uri ringtone, |
| 491 | CallAudioState callAudioState) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 492 | |
| 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 = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 497 | (contentTitle != null && !contentTitle.equals(savedContentTitle)) |
| 498 | || (contentTitle == null && savedContentTitle != null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 499 | |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 500 | boolean largeIconChanged; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 501 | if (savedLargeIcon == null) { |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 502 | largeIconChanged = largeIcon != null; |
| 503 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 504 | largeIconChanged = largeIcon == null || !savedLargeIcon.sameAs(largeIcon); |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 505 | } |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 506 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 507 | // any change means we are definitely updating |
| 508 | boolean retval = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 509 | (savedIcon != icon) |
| 510 | || !Objects.equals(savedContent, content) |
| 511 | || (callState != state) |
| 512 | || (this.videoState != videoState) |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 513 | || largeIconChanged |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 514 | || contentTitleChanged |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 515 | || !Objects.equals(this.ringtone, ringtone) |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 516 | || !Objects.equals(savedCallAudioState, callAudioState); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 517 | |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 518 | LogUtil.d( |
| 519 | "StatusBarNotifier.checkForChangeAndSaveData", |
roldenburg | c14610d | 2017-10-31 12:51:06 -0700 | [diff] [blame] | 520 | "data changed: icon: %b, content: %b, state: %b, videoState: %b, largeIcon: %b, title: %b," |
| 521 | + "ringtone: %b, audioState: %b, type: %b", |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 522 | (savedIcon != icon), |
| 523 | !Objects.equals(savedContent, content), |
| 524 | (callState != state), |
| 525 | (this.videoState != videoState), |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 526 | largeIconChanged, |
| 527 | contentTitleChanged, |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 528 | !Objects.equals(this.ringtone, ringtone), |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 529 | !Objects.equals(savedCallAudioState, callAudioState), |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 530 | currentNotification != notificationType); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 531 | // If we aren't showing a notification right now or the notification type is changing, |
| 532 | // definitely do an update. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 533 | if (currentNotification != notificationType) { |
| 534 | if (currentNotification == NOTIFICATION_NONE) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 535 | LogUtil.d( |
| 536 | "StatusBarNotifier.checkForChangeAndSaveData", "showing notification for first time."); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 537 | } |
| 538 | retval = true; |
| 539 | } |
| 540 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 541 | savedIcon = icon; |
| 542 | savedContent = content; |
| 543 | callState = state; |
| 544 | this.videoState = videoState; |
| 545 | savedLargeIcon = largeIcon; |
| 546 | savedContentTitle = contentTitle; |
| 547 | this.ringtone = ringtone; |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 548 | savedCallAudioState = callAudioState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 549 | |
| 550 | if (retval) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 551 | LogUtil.d( |
| 552 | "StatusBarNotifier.checkForChangeAndSaveData", "data changed. Showing notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 553 | } |
| 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 Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 562 | if (call.isConferenceCall()) { |
| 563 | return CallerInfoUtils.getConferenceString( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 564 | context, call.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | String preferredName = |
| 568 | ContactDisplayUtils.getPreferredDisplayName( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 569 | contactInfo.namePrimary, contactInfo.nameAlternative, contactsPreferences); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 570 | 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 Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 592 | private static Bitmap getLargeIconToDisplay( |
| 593 | Context context, ContactCacheEntry contactInfo, DialerCall call) { |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 594 | Trace.beginSection("StatusBarNotifier.getLargeIconToDisplay"); |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 595 | Resources resources = context.getResources(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 596 | Bitmap largeIcon = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 597 | if (contactInfo.photo != null && (contactInfo.photo instanceof BitmapDrawable)) { |
| 598 | largeIcon = ((BitmapDrawable) contactInfo.photo).getBitmap(); |
| 599 | } |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 600 | if (contactInfo.photo == null) { |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 601 | 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 Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 603 | @ContactType |
| 604 | int contactType = |
| 605 | LetterTileDrawable.getContactTypeFromPrimitives( |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 606 | call.isVoiceMailNumber(), |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 607 | call.isSpam(), |
| 608 | contactInfo.isBusiness, |
| 609 | call.getNumberPresentation(), |
| 610 | call.isConferenceCall() && !call.hasProperty(Details.PROPERTY_GENERIC_CONFERENCE)); |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 611 | LetterTileDrawable lettertile = new LetterTileDrawable(resources); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 612 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 613 | 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 Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 621 | if (call.isSpam()) { |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 622 | Drawable drawable = resources.getDrawable(R.drawable.blocked_contact, context.getTheme()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 623 | largeIcon = DrawableConverter.drawableToBitmap(drawable); |
| 624 | } |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 625 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 626 | return largeIcon; |
| 627 | } |
| 628 | |
| 629 | private Bitmap getRoundedIcon(Bitmap bitmap) { |
| 630 | if (bitmap == null) { |
| 631 | return null; |
| 632 | } |
| 633 | final int height = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 634 | (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_height); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 635 | final int width = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 636 | (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_width); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 637 | 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 Erfanian | 2827dd1 | 2017-10-26 09:37:50 -0700 | [diff] [blame] | 644 | @VisibleForTesting |
| 645 | public int getIconToDisplay(DialerCall call) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 646 | // 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. |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 653 | if (call.getState() == DialerCallState.ONHOLD) { |
Eric Erfanian | 2827dd1 | 2017-10-26 09:37:50 -0700 | [diff] [blame] | 654 | return R.drawable.quantum_ic_phone_paused_vd_theme_24; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 655 | } else if (call.getVideoTech().getSessionModificationState() |
calderwoodra | 1dc2cea | 2017-09-20 16:30:41 -0700 | [diff] [blame] | 656 | == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST |
| 657 | || call.isVideoCall()) { |
linyuh | 8dc242d | 2018-03-28 13:09:47 -0700 | [diff] [blame] | 658 | return R.drawable.quantum_ic_videocam_vd_white_24; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 659 | } else if (call.hasProperty(PROPERTY_HIGH_DEF_AUDIO) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 660 | && MotorolaUtils.shouldShowHdIconInNotification(context)) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 661 | // 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 Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 664 | return R.drawable.ic_hd_call; |
Eric Erfanian | 2827dd1 | 2017-10-26 09:37:50 -0700 | [diff] [blame] | 665 | } else if (call.hasProperty(Details.PROPERTY_HAS_CDMA_VOICE_PRIVACY)) { |
| 666 | return R.drawable.quantum_ic_phone_locked_vd_theme_24; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 667 | } |
yueg | 48f93f4 | 2018-03-09 16:49:38 -0800 | [diff] [blame] | 668 | // If ReturnToCall is enabled, use the static icon. The animated one will show in the bubble. |
| 669 | if (ReturnToCallController.isEnabled(context)) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 670 | return R.drawable.quantum_ic_call_vd_theme_24; |
| 671 | } else { |
| 672 | return R.drawable.on_going_call; |
| 673 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | /** Returns the message to use with the notification. */ |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 677 | private CharSequence getContentString(DialerCall call, @UserType long userType) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 678 | boolean isIncomingOrWaiting = |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 679 | call.getState() == DialerCallState.INCOMING |
| 680 | || call.getState() == DialerCallState.CALL_WAITING; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 681 | |
| 682 | if (isIncomingOrWaiting |
| 683 | && call.getNumberPresentation() == TelecomManager.PRESENTATION_ALLOWED) { |
| 684 | |
| 685 | if (!TextUtils.isEmpty(call.getChildNumber())) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 686 | return context.getString(R.string.child_number, call.getChildNumber()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 687 | } else if (!TextUtils.isEmpty(call.getCallSubject()) && call.isCallSubjectSupported()) { |
| 688 | return call.getCallSubject(); |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | int resId = R.string.notification_ongoing_call; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 693 | String wifiBrand = context.getString(R.string.notification_call_wifi_brand); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 694 | if (call.hasProperty(Details.PROPERTY_WIFI)) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 695 | resId = R.string.notification_ongoing_call_wifi_template; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | if (isIncomingOrWaiting) { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 699 | if (call.isSpam()) { |
| 700 | resId = R.string.notification_incoming_spam_call; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 701 | } else if (shouldShowEnrichedCallNotification(call.getEnrichedCallSession())) { |
| 702 | resId = getECIncomingCallText(call.getEnrichedCallSession()); |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 703 | } else if (call.hasProperty(Details.PROPERTY_WIFI)) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 704 | resId = R.string.notification_incoming_call_wifi_template; |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 705 | } else if (call.getAccountHandle() != null && hasMultiplePhoneAccounts(call)) { |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 706 | return getMultiSimIncomingText(call); |
yueg | 45e4573 | 2017-10-09 14:35:06 -0700 | [diff] [blame] | 707 | } else if (call.isVideoCall()) { |
| 708 | resId = R.string.notification_incoming_video_call; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 709 | } else { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 710 | resId = R.string.notification_incoming_call; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 711 | } |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 712 | } else if (call.getState() == DialerCallState.ONHOLD) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 713 | resId = R.string.notification_on_hold; |
calderwoodra | 1dc2cea | 2017-09-20 16:30:41 -0700 | [diff] [blame] | 714 | } 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; |
wangqi | bb94ca6 | 2018-04-27 14:34:04 -0700 | [diff] [blame] | 719 | } else if (DialerCallState.isDialing(call.getState())) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 720 | resId = R.string.notification_dialing; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 721 | } else if (call.getVideoTech().getSessionModificationState() |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 722 | == SessionModificationState.RECEIVED_UPGRADE_TO_VIDEO_REQUEST) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 723 | 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); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 730 | wifiBrand = context.getString(R.string.notification_call_wifi_work_brand); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | if (resId == R.string.notification_incoming_call_wifi_template |
| 734 | || resId == R.string.notification_ongoing_call_wifi_template) { |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 735 | // TODO(a bug): Potentially apply this template logic everywhere. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 736 | return context.getString(resId, wifiBrand); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 737 | } |
| 738 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 739 | return context.getString(resId); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 740 | } |
| 741 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 742 | private boolean shouldShowEnrichedCallNotification(Session session) { |
| 743 | if (session == null) { |
| 744 | return false; |
| 745 | } |
| 746 | return session.getMultimediaData().hasData() || session.getMultimediaData().isImportant(); |
| 747 | } |
| 748 | |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 749 | 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 Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 774 | } else if (hasSubject) { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 775 | resId = R.string.important_notification_incoming_call_with_message; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 776 | } else { |
| 777 | resId = R.string.important_notification_incoming_call; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 778 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 779 | if (context.getString(resId).length() > 50) { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 780 | 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 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 805 | if (context.getString(resId).length() > 50) { |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 806 | resId = R.string.notification_incoming_call_attachments; |
| 807 | } |
| 808 | return resId; |
| 809 | } |
| 810 | |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 811 | private CharSequence getMultiSimIncomingText(DialerCall call) { |
| 812 | PhoneAccount phoneAccount = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 813 | context.getSystemService(TelecomManager.class).getPhoneAccount(call.getAccountHandle()); |
twyen | e931c12 | 2018-03-19 14:47:28 -0700 | [diff] [blame] | 814 | if (phoneAccount == null) { |
| 815 | return context.getString(R.string.notification_incoming_call); |
| 816 | } |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 817 | SpannableString string = |
| 818 | new SpannableString( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 819 | context.getString( |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 820 | 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 Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 832 | /** 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) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 851 | Spannable spannable = new SpannableString(context.getText(stringRes)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 852 | 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( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 857 | new ForegroundColorSpan(context.getColor(colorRes)), 0, spannable.length(), 0); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 858 | } |
| 859 | return spannable; |
| 860 | } |
| 861 | |
| 862 | private void addAnswerAction(Notification.Builder builder) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 863 | LogUtil.d( |
| 864 | "StatusBarNotifier.addAnswerAction", |
| 865 | "will show \"answer\" action in the incoming call Notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 866 | PendingIntent answerVoicePendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 867 | createNotificationPendingIntent(context, ACTION_ANSWER_VOICE_INCOMING_CALL); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 868 | builder.addAction( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 869 | new Notification.Action.Builder( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 870 | Icon.createWithResource(context, R.drawable.quantum_ic_call_white_24), |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 871 | getActionText( |
| 872 | R.string.notification_action_answer, R.color.notification_action_accept), |
| 873 | answerVoicePendingIntent) |
| 874 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 875 | } |
| 876 | |
erfanian | 1e4ef18 | 2018-06-11 11:05:51 -0700 | [diff] [blame^] | 877 | 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 Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 915 | private void addDismissAction(Notification.Builder builder) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 916 | LogUtil.d( |
| 917 | "StatusBarNotifier.addDismissAction", |
| 918 | "will show \"decline\" action in the incoming call Notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 919 | PendingIntent declinePendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 920 | createNotificationPendingIntent(context, ACTION_DECLINE_INCOMING_CALL); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 921 | builder.addAction( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 922 | new Notification.Action.Builder( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 923 | Icon.createWithResource(context, R.drawable.quantum_ic_close_white_24), |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 924 | getActionText( |
| 925 | R.string.notification_action_dismiss, R.color.notification_action_dismiss), |
| 926 | declinePendingIntent) |
| 927 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | private void addHangupAction(Notification.Builder builder) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 931 | LogUtil.d( |
| 932 | "StatusBarNotifier.addHangupAction", |
| 933 | "will show \"hang-up\" action in the ongoing active call Notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 934 | PendingIntent hangupPendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 935 | createNotificationPendingIntent(context, ACTION_HANG_UP_ONGOING_CALL); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 936 | builder.addAction( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 937 | new Notification.Action.Builder( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 938 | Icon.createWithResource(context, R.drawable.quantum_ic_call_end_white_24), |
| 939 | context.getText(R.string.notification_action_end_call), |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 940 | hangupPendingIntent) |
| 941 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 942 | } |
| 943 | |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 944 | 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 = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 962 | createNotificationPendingIntent(context, ACTION_TURN_ON_SPEAKER); |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 963 | builder.addAction( |
| 964 | new Notification.Action.Builder( |
wangqi | 6ca8c72 | 2018-03-29 10:19:58 -0700 | [diff] [blame] | 965 | Icon.createWithResource(context, R.drawable.quantum_ic_volume_up_vd_theme_24), |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 966 | context.getText(R.string.notification_action_speaker_on), |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 967 | 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 = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 976 | createNotificationPendingIntent(context, ACTION_TURN_OFF_SPEAKER); |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 977 | builder.addAction( |
| 978 | new Notification.Action.Builder( |
wangqi | 6ca8c72 | 2018-03-29 10:19:58 -0700 | [diff] [blame] | 979 | Icon.createWithResource(context, R.drawable.quantum_ic_phone_in_talk_vd_theme_24), |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 980 | context.getText(R.string.notification_action_speaker_off), |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 981 | speakerOffPendingIntent) |
| 982 | .build()); |
| 983 | } |
| 984 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 985 | private void addVideoCallAction(Notification.Builder builder) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 986 | LogUtil.i( |
| 987 | "StatusBarNotifier.addVideoCallAction", |
| 988 | "will show \"video\" action in the incoming call Notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 989 | PendingIntent answerVideoPendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 990 | createNotificationPendingIntent(context, ACTION_ANSWER_VIDEO_INCOMING_CALL); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 991 | builder.addAction( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 992 | new Notification.Action.Builder( |
linyuh | 8dc242d | 2018-03-28 13:09:47 -0700 | [diff] [blame] | 993 | Icon.createWithResource(context, R.drawable.quantum_ic_videocam_vd_white_24), |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 994 | getActionText( |
| 995 | R.string.notification_action_answer_video, |
| 996 | R.color.notification_action_answer_video), |
| 997 | answerVideoPendingIntent) |
| 998 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | private void addAcceptUpgradeRequestAction(Notification.Builder builder) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1002 | LogUtil.i( |
| 1003 | "StatusBarNotifier.addAcceptUpgradeRequestAction", |
| 1004 | "will show \"accept upgrade\" action in the incoming call Notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1005 | PendingIntent acceptVideoPendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1006 | createNotificationPendingIntent(context, ACTION_ACCEPT_VIDEO_UPGRADE_REQUEST); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1007 | builder.addAction( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1008 | new Notification.Action.Builder( |
linyuh | 8dc242d | 2018-03-28 13:09:47 -0700 | [diff] [blame] | 1009 | Icon.createWithResource(context, R.drawable.quantum_ic_videocam_vd_white_24), |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1010 | getActionText( |
| 1011 | R.string.notification_action_accept, R.color.notification_action_accept), |
| 1012 | acceptVideoPendingIntent) |
| 1013 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | private void addDismissUpgradeRequestAction(Notification.Builder builder) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1017 | LogUtil.i( |
| 1018 | "StatusBarNotifier.addDismissUpgradeRequestAction", |
| 1019 | "will show \"dismiss upgrade\" action in the incoming call Notification"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1020 | PendingIntent declineVideoPendingIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1021 | createNotificationPendingIntent(context, ACTION_DECLINE_VIDEO_UPGRADE_REQUEST); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1022 | builder.addAction( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1023 | new Notification.Action.Builder( |
linyuh | 8dc242d | 2018-03-28 13:09:47 -0700 | [diff] [blame] | 1024 | Icon.createWithResource(context, R.drawable.quantum_ic_videocam_vd_white_24), |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1025 | getActionText( |
| 1026 | R.string.notification_action_dismiss, R.color.notification_action_dismiss), |
| 1027 | declineVideoPendingIntent) |
| 1028 | .build()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | /** Adds fullscreen intent to the builder. */ |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 1032 | private void configureFullScreenIntent(Notification.Builder builder, PendingIntent intent) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1033 | // 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 Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1038 | LogUtil.d("StatusBarNotifier.configureFullScreenIntent", "setting fullScreenIntent: " + intent); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1039 | builder.setFullScreenIntent(intent, true); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | private Notification.Builder getNotificationBuilder() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1043 | final Notification.Builder builder = new Notification.Builder(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1044 | builder.setOngoing(true); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1045 | builder.setOnlyAlertOnce(true); |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 1046 | // This will be ignored on O+ and handled by the channel |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1047 | // noinspection deprecation |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 1048 | builder.setPriority(Notification.PRIORITY_HIGH); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1049 | |
| 1050 | return builder; |
| 1051 | } |
| 1052 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1053 | private PendingIntent createLaunchPendingIntent(boolean isFullScreen) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1054 | Intent intent = |
| 1055 | InCallActivity.getIntent( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1056 | context, false /* showDialpad */, false /* newOutgoingCall */, isFullScreen); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1057 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1058 | int requestCode = InCallActivity.PendingIntentRequestCodes.NON_FULL_SCREEN; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1059 | if (isFullScreen) { |
| 1060 | // Use a unique request code so that the pending intent isn't clobbered by the |
| 1061 | // non-full screen pending intent. |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1062 | requestCode = InCallActivity.PendingIntentRequestCodes.FULL_SCREEN; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1063 | } |
| 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). |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1070 | return PendingIntent.getActivity(context, requestCode, intent, 0); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | private void setStatusBarCallListener(StatusBarCallListener listener) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1074 | if (statusBarCallListener != null) { |
| 1075 | statusBarCallListener.cleanup(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1076 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1077 | statusBarCallListener = listener; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1078 | } |
| 1079 | |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 1080 | private boolean hasMultiplePhoneAccounts(DialerCall call) { |
| 1081 | if (call.getCallCapableAccounts() == null) { |
| 1082 | return false; |
| 1083 | } |
| 1084 | return call.getCallCapableAccounts().size() > 1; |
twyen | d1d1d0c | 2017-10-05 17:34:43 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 1087 | @Override |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 1088 | @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 | } |
yueg | b26c1ae | 2017-09-18 16:59:16 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1106 | private class StatusBarCallListener implements DialerCallListener { |
| 1107 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1108 | private DialerCall dialerCall; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1109 | |
| 1110 | StatusBarCallListener(DialerCall dialerCall) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1111 | this.dialerCall = dialerCall; |
| 1112 | this.dialerCall.addListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | void cleanup() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1116 | dialerCall.removeListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | @Override |
| 1120 | public void onDialerCallDisconnect() {} |
| 1121 | |
| 1122 | @Override |
| 1123 | public void onDialerCallUpdate() { |
| 1124 | if (CallList.getInstance().getIncomingCall() == null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1125 | dialerRingtoneManager.stopCallWaitingTone(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1126 | } |
| 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 Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 1144 | @Override |
| 1145 | public void onInternationalCallOnWifi() {} |
| 1146 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1147 | @Override |
| 1148 | public void onEnrichedCallSessionUpdate() {} |
| 1149 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1150 | /** |
| 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 Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1155 | public void onDialerCallSessionModificationStateChange() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1156 | if (dialerCall.getVideoTech().getSessionModificationState() |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 1157 | == SessionModificationState.NO_REQUEST) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1158 | cleanup(); |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 1159 | updateNotification(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | } |
| 1163 | } |