Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 1 | /* |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 2 | * Copyright (C) 2015 The Android Open Source Project |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 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 |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 14 | * limitations under the License |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 17 | package com.android.server.telecom; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 18 | |
Yorke Lee | 8a736a8 | 2014-08-30 17:19:16 -0700 | [diff] [blame] | 19 | import android.app.Notification; |
| 20 | import android.app.NotificationManager; |
Selim Cinek | b59795b | 2018-03-24 02:21:38 -0700 | [diff] [blame] | 21 | import android.app.Person; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Tyler Gunn | 9d52d39 | 2017-07-31 09:48:16 -0700 | [diff] [blame] | 23 | import android.os.VibrationEffect; |
Brad Ebinger | 953e1af | 2016-10-05 15:45:22 -0700 | [diff] [blame] | 24 | import android.telecom.Log; |
Joseph Pirozzo | ee4089c | 2017-12-13 16:38:10 -0800 | [diff] [blame] | 25 | import android.telecom.TelecomManager; |
John Spurlock | 44b1810 | 2014-07-18 19:10:16 -0400 | [diff] [blame] | 26 | import android.media.AudioAttributes; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 27 | import android.media.AudioManager; |
Michael Wright | 76888bb | 2018-03-08 00:12:36 +0000 | [diff] [blame] | 28 | import android.media.Ringtone; |
Yorke Lee | 8a736a8 | 2014-08-30 17:19:16 -0700 | [diff] [blame] | 29 | import android.net.Uri; |
| 30 | import android.os.Bundle; |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 31 | import android.os.Vibrator; |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 32 | |
| 33 | import com.android.internal.annotations.VisibleForTesting; |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 34 | |
Tyler Gunn | 296489e | 2018-01-16 21:40:43 -0800 | [diff] [blame] | 35 | import java.util.ArrayList; |
| 36 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 37 | /** |
| 38 | * Controls the ringtone player. |
| 39 | */ |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 40 | @VisibleForTesting |
Hall Liu | e792b33 | 2016-04-19 14:23:09 -0700 | [diff] [blame] | 41 | public class Ringer { |
Michael Wright | 76888bb | 2018-03-08 00:12:36 +0000 | [diff] [blame] | 42 | @VisibleForTesting |
| 43 | public VibrationEffect mDefaultVibrationEffect; |
Tyler Gunn | 9d52d39 | 2017-07-31 09:48:16 -0700 | [diff] [blame] | 44 | |
| 45 | private static final long[] PULSE_PATTERN = {0,12,250,12,500, // priming + interval |
| 46 | 50,50,50,50,50,50,50,50,50,50,50,50,50,50, // ease-in |
| 47 | 300, // Peak |
| 48 | 1000}; // pause before repetition |
| 49 | |
| 50 | private static final int[] PULSE_AMPLITUDE = {0,255,0,255,0, // priming + interval |
| 51 | 77,77,78,79,81,84,87,93,101,114,133,162,205,255, // ease-in (min amplitude = 30%) |
| 52 | 255, // Peak |
| 53 | 0}; // pause before repetition |
| 54 | |
Tyler Gunn | 4d8cd29 | 2018-03-06 11:04:26 -0800 | [diff] [blame] | 55 | private static final long[] SIMPLE_VIBRATION_PATTERN = { |
| 56 | 0, // No delay before starting |
| 57 | 1000, // How long to vibrate |
| 58 | 1000, // How long to wait before vibrating again |
| 59 | }; |
| 60 | |
| 61 | private static final int[] SIMPLE_VIBRATION_AMPLITUDE = { |
| 62 | 0, // No delay before starting |
| 63 | 255, // Vibrate full amplitude |
| 64 | 0, // No amplitude while waiting |
| 65 | }; |
| 66 | |
Tyler Gunn | 9d52d39 | 2017-07-31 09:48:16 -0700 | [diff] [blame] | 67 | /** |
| 68 | * Indicates that vibration should be repeated at element 5 in the {@link #PULSE_AMPLITUDE} and |
| 69 | * {@link #PULSE_PATTERN} arrays. This means repetition will happen for the main ease-in/peak |
| 70 | * pattern, but the priming + interval part will not be repeated. |
| 71 | */ |
| 72 | private static final int REPEAT_VIBRATION_AT = 5; |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 73 | |
Tyler Gunn | 4d8cd29 | 2018-03-06 11:04:26 -0800 | [diff] [blame] | 74 | private static final int REPEAT_SIMPLE_VIBRATION_AT = 1; |
| 75 | |
John Spurlock | 44b1810 | 2014-07-18 19:10:16 -0400 | [diff] [blame] | 76 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 77 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
Jean-Michel Trivi | 29e52ae | 2014-07-20 13:23:45 -0700 | [diff] [blame] | 78 | .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) |
John Spurlock | 44b1810 | 2014-07-18 19:10:16 -0400 | [diff] [blame] | 79 | .build(); |
| 80 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 81 | /** |
| 82 | * Used to keep ordering of unanswered incoming calls. There can easily exist multiple incoming |
| 83 | * calls and explicit ordering is useful for maintaining the proper state of the ringer. |
| 84 | */ |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 85 | |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 86 | private final SystemSettingsUtil mSystemSettingsUtil; |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 87 | private final InCallTonePlayer.Factory mPlayerFactory; |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 88 | private final AsyncRingtonePlayer mRingtonePlayer; |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 89 | private final Context mContext; |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 90 | private final Vibrator mVibrator; |
Santos Cordon | f0f99f3 | 2016-02-18 16:13:57 -0800 | [diff] [blame] | 91 | private final InCallController mInCallController; |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 92 | |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 93 | private InCallTonePlayer mCallWaitingPlayer; |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 94 | private RingtoneFactory mRingtoneFactory; |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 95 | |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 96 | /** |
Tyler Gunn | 68d2f86 | 2017-01-10 15:00:23 -0800 | [diff] [blame] | 97 | * Call objects that are ringing, vibrating or call-waiting. These are used only for logging |
| 98 | * purposes. |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 99 | */ |
| 100 | private Call mRingingCall; |
Tyler Gunn | 68d2f86 | 2017-01-10 15:00:23 -0800 | [diff] [blame] | 101 | private Call mVibratingCall; |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 102 | private Call mCallWaitingCall; |
| 103 | |
| 104 | /** |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 105 | * Used to track the status of {@link #mVibrator} in the case of simultaneous incoming calls. |
| 106 | */ |
| 107 | private boolean mIsVibrating = false; |
| 108 | |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 109 | /** Initializes the Ringer. */ |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 110 | @VisibleForTesting |
| 111 | public Ringer( |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 112 | InCallTonePlayer.Factory playerFactory, |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 113 | Context context, |
| 114 | SystemSettingsUtil systemSettingsUtil, |
| 115 | AsyncRingtonePlayer asyncRingtonePlayer, |
| 116 | RingtoneFactory ringtoneFactory, |
Santos Cordon | f0f99f3 | 2016-02-18 16:13:57 -0800 | [diff] [blame] | 117 | Vibrator vibrator, |
| 118 | InCallController inCallController) { |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 119 | |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 120 | mSystemSettingsUtil = systemSettingsUtil; |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 121 | mPlayerFactory = playerFactory; |
| 122 | mContext = context; |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 123 | // We don't rely on getSystemService(Context.VIBRATOR_SERVICE) to make sure this |
| 124 | // vibrator object will be isolated from others. |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 125 | mVibrator = vibrator; |
| 126 | mRingtonePlayer = asyncRingtonePlayer; |
| 127 | mRingtoneFactory = ringtoneFactory; |
Santos Cordon | f0f99f3 | 2016-02-18 16:13:57 -0800 | [diff] [blame] | 128 | mInCallController = inCallController; |
Tyler Gunn | 9d52d39 | 2017-07-31 09:48:16 -0700 | [diff] [blame] | 129 | |
Tyler Gunn | 4d8cd29 | 2018-03-06 11:04:26 -0800 | [diff] [blame] | 130 | if (mContext.getResources().getBoolean(R.bool.use_simple_vibration_pattern)) { |
Michael Wright | 76888bb | 2018-03-08 00:12:36 +0000 | [diff] [blame] | 131 | mDefaultVibrationEffect = VibrationEffect.createWaveform(SIMPLE_VIBRATION_PATTERN, |
Tyler Gunn | 4d8cd29 | 2018-03-06 11:04:26 -0800 | [diff] [blame] | 132 | SIMPLE_VIBRATION_AMPLITUDE, REPEAT_SIMPLE_VIBRATION_AT); |
| 133 | } else { |
Michael Wright | 76888bb | 2018-03-08 00:12:36 +0000 | [diff] [blame] | 134 | mDefaultVibrationEffect = VibrationEffect.createWaveform(PULSE_PATTERN, |
| 135 | PULSE_AMPLITUDE, REPEAT_VIBRATION_AT); |
Tyler Gunn | 4d8cd29 | 2018-03-06 11:04:26 -0800 | [diff] [blame] | 136 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Hall Liu | 136f4c9 | 2017-04-04 13:35:18 -0700 | [diff] [blame] | 139 | public boolean startRinging(Call foregroundCall, boolean isHfpDeviceAttached) { |
Hall Liu | 5648f36 | 2016-02-02 15:12:04 -0800 | [diff] [blame] | 140 | if (foregroundCall == null) { |
| 141 | Log.wtf(this, "startRinging called with null foreground call."); |
Hall Liu | 6a5995e | 2016-09-08 16:00:14 -0700 | [diff] [blame] | 142 | return false; |
Hall Liu | 5648f36 | 2016-02-02 15:12:04 -0800 | [diff] [blame] | 143 | } |
| 144 | |
Hall Liu | 136f4c9 | 2017-04-04 13:35:18 -0700 | [diff] [blame] | 145 | AudioManager audioManager = |
| 146 | (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); |
| 147 | boolean isVolumeOverZero = audioManager.getStreamVolume(AudioManager.STREAM_RING) > 0; |
| 148 | boolean shouldRingForContact = shouldRingForContact(foregroundCall.getContactUri()); |
| 149 | boolean isRingtonePresent = !(mRingtoneFactory.getRingtone(foregroundCall) == null); |
| 150 | boolean isSelfManaged = foregroundCall.isSelfManaged(); |
Sailesh Nepal | c07b8e1 | 2016-01-23 16:43:10 -0800 | [diff] [blame] | 151 | |
Hall Liu | 136f4c9 | 2017-04-04 13:35:18 -0700 | [diff] [blame] | 152 | boolean isRingerAudible = isVolumeOverZero && shouldRingForContact && isRingtonePresent; |
Joseph Pirozzo | ee4089c | 2017-12-13 16:38:10 -0800 | [diff] [blame] | 153 | boolean hasExternalRinger = hasExternalRinger(foregroundCall); |
Hall Liu | 136f4c9 | 2017-04-04 13:35:18 -0700 | [diff] [blame] | 154 | // Acquire audio focus under any of the following conditions: |
| 155 | // 1. Should ring for contact and there's an HFP device attached |
| 156 | // 2. Volume is over zero, we should ring for the contact, and there's a audible ringtone |
| 157 | // present. |
| 158 | // 3. The call is self-managed. |
| 159 | boolean shouldAcquireAudioFocus = |
| 160 | isRingerAudible || (isHfpDeviceAttached && shouldRingForContact) || isSelfManaged; |
| 161 | |
| 162 | // Don't do call waiting operations or vibration unless these are false. |
| 163 | boolean isTheaterModeOn = mSystemSettingsUtil.isTheaterModeOn(mContext); |
| 164 | boolean letDialerHandleRinging = mInCallController.doesConnectedDialerSupportRinging(); |
Joseph Pirozzo | ee4089c | 2017-12-13 16:38:10 -0800 | [diff] [blame] | 165 | boolean endEarly = isTheaterModeOn || letDialerHandleRinging || isSelfManaged || |
| 166 | hasExternalRinger; |
Hall Liu | 136f4c9 | 2017-04-04 13:35:18 -0700 | [diff] [blame] | 167 | |
| 168 | if (endEarly) { |
| 169 | if (letDialerHandleRinging) { |
| 170 | Log.addEvent(foregroundCall, LogUtils.Events.SKIP_RINGING); |
| 171 | } |
| 172 | Log.i(this, "Ending early -- isTheaterModeOn=%s, letDialerHandleRinging=%s, " + |
Joseph Pirozzo | ee4089c | 2017-12-13 16:38:10 -0800 | [diff] [blame] | 173 | "isSelfManaged=%s, hasExternalRinger=%s", isTheaterModeOn, |
| 174 | letDialerHandleRinging, isSelfManaged, hasExternalRinger); |
Hall Liu | 136f4c9 | 2017-04-04 13:35:18 -0700 | [diff] [blame] | 175 | return shouldAcquireAudioFocus; |
Tyler Gunn | 638f180 | 2017-04-03 15:49:48 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 178 | stopCallWaiting(); |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 179 | |
Michael Wright | 76888bb | 2018-03-08 00:12:36 +0000 | [diff] [blame] | 180 | VibrationEffect effect; |
Hall Liu | 6a5995e | 2016-09-08 16:00:14 -0700 | [diff] [blame] | 181 | if (isRingerAudible) { |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 182 | mRingingCall = foregroundCall; |
Brad Ebinger | 953e1af | 2016-10-05 15:45:22 -0700 | [diff] [blame] | 183 | Log.addEvent(foregroundCall, LogUtils.Events.START_RINGER); |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 184 | // Because we wait until a contact info query to complete before processing a |
| 185 | // call (for the purposes of direct-to-voicemail), the information about custom |
| 186 | // ringtones should be available by the time this code executes. We can safely |
| 187 | // request the custom ringtone from the call and expect it to be current. |
Brad Ebinger | c9286f4 | 2016-03-10 16:02:54 -0800 | [diff] [blame] | 188 | mRingtonePlayer.play(mRingtoneFactory, foregroundCall); |
Michael Wright | 76888bb | 2018-03-08 00:12:36 +0000 | [diff] [blame] | 189 | effect = getVibrationEffectForCall(mRingtoneFactory, foregroundCall); |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 190 | } else { |
Hall Liu | 136f4c9 | 2017-04-04 13:35:18 -0700 | [diff] [blame] | 191 | Log.i(this, "startRinging: skipping because ringer would not be audible. " + |
| 192 | "isVolumeOverZero=%s, shouldRingForContact=%s, isRingtonePresent=%s", |
| 193 | isVolumeOverZero, shouldRingForContact, isRingtonePresent); |
Michael Wright | 76888bb | 2018-03-08 00:12:36 +0000 | [diff] [blame] | 194 | effect = mDefaultVibrationEffect; |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Hall Liu | 136f4c9 | 2017-04-04 13:35:18 -0700 | [diff] [blame] | 197 | if (shouldVibrate(mContext, foregroundCall) && !mIsVibrating && shouldRingForContact) { |
Michael Wright | 76888bb | 2018-03-08 00:12:36 +0000 | [diff] [blame] | 198 | mVibrator.vibrate(effect, VIBRATION_ATTRIBUTES); |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 199 | mIsVibrating = true; |
Tyler Gunn | 68d2f86 | 2017-01-10 15:00:23 -0800 | [diff] [blame] | 200 | } else if (mIsVibrating) { |
| 201 | Log.addEvent(foregroundCall, LogUtils.Events.SKIP_VIBRATION, "already vibrating"); |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 202 | } |
Hall Liu | 6a5995e | 2016-09-08 16:00:14 -0700 | [diff] [blame] | 203 | |
Hall Liu | 136f4c9 | 2017-04-04 13:35:18 -0700 | [diff] [blame] | 204 | return shouldAcquireAudioFocus; |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Michael Wright | 76888bb | 2018-03-08 00:12:36 +0000 | [diff] [blame] | 207 | private VibrationEffect getVibrationEffectForCall(RingtoneFactory factory, Call call) { |
| 208 | VibrationEffect effect = null; |
| 209 | Ringtone ringtone = factory.getRingtone(call); |
| 210 | Uri ringtoneUri = ringtone != null ? ringtone.getUri() : null; |
| 211 | if (ringtoneUri != null) { |
| 212 | effect = VibrationEffect.get(ringtoneUri, mContext); |
| 213 | } |
| 214 | |
| 215 | if (effect == null) { |
| 216 | effect = mDefaultVibrationEffect; |
| 217 | } |
| 218 | return effect; |
| 219 | } |
| 220 | |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 221 | public void startCallWaiting(Call call) { |
| 222 | if (mSystemSettingsUtil.isTheaterModeOn(mContext)) { |
| 223 | return; |
| 224 | } |
| 225 | |
Santos Cordon | f0f99f3 | 2016-02-18 16:13:57 -0800 | [diff] [blame] | 226 | if (mInCallController.doesConnectedDialerSupportRinging()) { |
Brad Ebinger | 953e1af | 2016-10-05 15:45:22 -0700 | [diff] [blame] | 227 | Log.addEvent(call, LogUtils.Events.SKIP_RINGING); |
Sailesh Nepal | c07b8e1 | 2016-01-23 16:43:10 -0800 | [diff] [blame] | 228 | return; |
| 229 | } |
| 230 | |
Tyler Gunn | 638f180 | 2017-04-03 15:49:48 -0700 | [diff] [blame] | 231 | if (call.isSelfManaged()) { |
| 232 | Log.addEvent(call, LogUtils.Events.SKIP_RINGING, "Self-managed"); |
| 233 | return; |
| 234 | } |
| 235 | |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 236 | Log.v(this, "Playing call-waiting tone."); |
| 237 | |
| 238 | stopRinging(); |
| 239 | |
| 240 | if (mCallWaitingPlayer == null) { |
Brad Ebinger | 953e1af | 2016-10-05 15:45:22 -0700 | [diff] [blame] | 241 | Log.addEvent(call, LogUtils.Events.START_CALL_WAITING_TONE); |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 242 | mCallWaitingCall = call; |
| 243 | mCallWaitingPlayer = |
| 244 | mPlayerFactory.createPlayer(InCallTonePlayer.TONE_CALL_WAITING); |
| 245 | mCallWaitingPlayer.startTone(); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | public void stopRinging() { |
| 250 | if (mRingingCall != null) { |
Brad Ebinger | 953e1af | 2016-10-05 15:45:22 -0700 | [diff] [blame] | 251 | Log.addEvent(mRingingCall, LogUtils.Events.STOP_RINGER); |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 252 | mRingingCall = null; |
| 253 | } |
| 254 | |
| 255 | mRingtonePlayer.stop(); |
| 256 | |
| 257 | if (mIsVibrating) { |
Tyler Gunn | 68d2f86 | 2017-01-10 15:00:23 -0800 | [diff] [blame] | 258 | Log.addEvent(mVibratingCall, LogUtils.Events.STOP_VIBRATOR); |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 259 | mVibrator.cancel(); |
| 260 | mIsVibrating = false; |
Tyler Gunn | 68d2f86 | 2017-01-10 15:00:23 -0800 | [diff] [blame] | 261 | mVibratingCall = null; |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
| 265 | public void stopCallWaiting() { |
| 266 | Log.v(this, "stop call waiting."); |
| 267 | if (mCallWaitingPlayer != null) { |
| 268 | if (mCallWaitingCall != null) { |
Brad Ebinger | 953e1af | 2016-10-05 15:45:22 -0700 | [diff] [blame] | 269 | Log.addEvent(mCallWaitingCall, LogUtils.Events.STOP_CALL_WAITING_TONE); |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 270 | mCallWaitingCall = null; |
Yorke Lee | 8a736a8 | 2014-08-30 17:19:16 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 273 | mCallWaitingPlayer.stopTone(); |
| 274 | mCallWaitingPlayer = null; |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 275 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Yorke Lee | 8a736a8 | 2014-08-30 17:19:16 -0700 | [diff] [blame] | 278 | private boolean shouldRingForContact(Uri contactUri) { |
| 279 | final NotificationManager manager = |
| 280 | (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
Tyler Gunn | 296489e | 2018-01-16 21:40:43 -0800 | [diff] [blame] | 281 | final Bundle peopleExtras = new Bundle(); |
Yorke Lee | 8a736a8 | 2014-08-30 17:19:16 -0700 | [diff] [blame] | 282 | if (contactUri != null) { |
Selim Cinek | b59795b | 2018-03-24 02:21:38 -0700 | [diff] [blame] | 283 | ArrayList<Person> personList = new ArrayList<>(); |
| 284 | personList.add(new Person.Builder().setUri(contactUri.toString()).build()); |
Tyler Gunn | 296489e | 2018-01-16 21:40:43 -0800 | [diff] [blame] | 285 | peopleExtras.putParcelableArrayList(Notification.EXTRA_PEOPLE_LIST, personList); |
Yorke Lee | 8a736a8 | 2014-08-30 17:19:16 -0700 | [diff] [blame] | 286 | } |
Tyler Gunn | 296489e | 2018-01-16 21:40:43 -0800 | [diff] [blame] | 287 | return manager.matchesCallFilter(peopleExtras); |
Yorke Lee | 8a736a8 | 2014-08-30 17:19:16 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Joseph Pirozzo | ee4089c | 2017-12-13 16:38:10 -0800 | [diff] [blame] | 290 | private boolean hasExternalRinger(Call foregroundCall) { |
| 291 | Bundle intentExtras = foregroundCall.getIntentExtras(); |
| 292 | if (intentExtras != null) { |
| 293 | return intentExtras.getBoolean(TelecomManager.EXTRA_CALL_EXTERNAL_RINGER, false); |
| 294 | } else { |
| 295 | return false; |
| 296 | } |
| 297 | } |
| 298 | |
Tyler Gunn | 68d2f86 | 2017-01-10 15:00:23 -0800 | [diff] [blame] | 299 | private boolean shouldVibrate(Context context, Call call) { |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 300 | AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
John Spurlock | 1522691 | 2014-11-25 08:38:47 -0500 | [diff] [blame] | 301 | int ringerMode = audioManager.getRingerModeInternal(); |
Tyler Gunn | 68d2f86 | 2017-01-10 15:00:23 -0800 | [diff] [blame] | 302 | boolean shouldVibrate; |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 303 | if (getVibrateWhenRinging(context)) { |
Tyler Gunn | 68d2f86 | 2017-01-10 15:00:23 -0800 | [diff] [blame] | 304 | shouldVibrate = ringerMode != AudioManager.RINGER_MODE_SILENT; |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 305 | } else { |
Tyler Gunn | 68d2f86 | 2017-01-10 15:00:23 -0800 | [diff] [blame] | 306 | shouldVibrate = ringerMode == AudioManager.RINGER_MODE_VIBRATE; |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 307 | } |
Tyler Gunn | 68d2f86 | 2017-01-10 15:00:23 -0800 | [diff] [blame] | 308 | |
| 309 | // Technically this should be in the calling method, but it seemed a little odd to pass |
| 310 | // around a whole bunch of state just for logging purposes. |
| 311 | if (shouldVibrate) { |
| 312 | Log.addEvent(call, LogUtils.Events.START_VIBRATOR, |
| 313 | "hasVibrator=%b, userRequestsVibrate=%b, ringerMode=%d, isVibrating=%b", |
| 314 | mVibrator.hasVibrator(), mSystemSettingsUtil.canVibrateWhenRinging(context), |
| 315 | ringerMode, mIsVibrating); |
| 316 | } else { |
| 317 | Log.addEvent(call, LogUtils.Events.SKIP_VIBRATION, |
| 318 | "hasVibrator=%b, userRequestsVibrate=%b, ringerMode=%d, isVibrating=%b", |
| 319 | mVibrator.hasVibrator(), mSystemSettingsUtil.canVibrateWhenRinging(context), |
| 320 | ringerMode, mIsVibrating); |
| 321 | } |
| 322 | |
| 323 | return shouldVibrate; |
Evan Charlton | 198fde8 | 2014-04-07 10:53:11 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | private boolean getVibrateWhenRinging(Context context) { |
| 327 | if (!mVibrator.hasVibrator()) { |
| 328 | return false; |
| 329 | } |
Brad Ebinger | d931a01 | 2015-10-21 12:54:08 -0700 | [diff] [blame] | 330 | return mSystemSettingsUtil.canVibrateWhenRinging(context); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 331 | } |
| 332 | } |