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