Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -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 | |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 17 | package com.android.server.telecom; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 18 | |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Sailesh Nepal | ce704b9 | 2014-03-17 18:31:43 -0700 | [diff] [blame] | 20 | import android.net.Uri; |
Evan Charlton | a05805b | 2014-03-05 08:21:46 -0800 | [diff] [blame] | 21 | import android.os.Bundle; |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 22 | import android.os.Handler; |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 23 | import android.os.Looper; |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 24 | import android.os.Message; |
Rekha Kumar | d240fe8 | 2015-04-01 21:45:57 -0700 | [diff] [blame] | 25 | import android.os.SystemProperties; |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 26 | import android.os.Trace; |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 27 | import android.provider.CallLog.Calls; |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 28 | import android.telecom.CallAudioState; |
Tyler Gunn | d92e737 | 2015-01-09 15:59:45 -0800 | [diff] [blame] | 29 | import android.telecom.Conference; |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 30 | import android.telecom.Connection; |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 31 | import android.telecom.DisconnectCause; |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 32 | import android.telecom.GatewayInfo; |
| 33 | import android.telecom.ParcelableConference; |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 34 | import android.telecom.ParcelableConnection; |
Tyler Gunn | 5b452df | 2014-10-01 15:02:58 -0700 | [diff] [blame] | 35 | import android.telecom.PhoneAccount; |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 36 | import android.telecom.PhoneAccountHandle; |
Tyler Gunn | 5b452df | 2014-10-01 15:02:58 -0700 | [diff] [blame] | 37 | import android.telecom.TelecomManager; |
Andrew Lee | 4550623 | 2014-10-22 17:54:33 -0700 | [diff] [blame] | 38 | import android.telecom.VideoProfile; |
Nancy Chen | a469f76 | 2014-12-09 18:29:20 -0800 | [diff] [blame] | 39 | import android.telephony.PhoneNumberUtils; |
Sailesh Nepal | 8aa6a00 | 2014-09-12 10:52:49 -0700 | [diff] [blame] | 40 | import android.telephony.TelephonyManager; |
Yorke Lee | 8d3f269 | 2015-05-08 11:44:39 -0700 | [diff] [blame] | 41 | import android.text.TextUtils; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 42 | |
Ihab Awad | a365390 | 2015-01-23 13:44:46 -0800 | [diff] [blame] | 43 | import com.android.internal.annotations.VisibleForTesting; |
Rekha Kumar | d240fe8 | 2015-04-01 21:45:57 -0700 | [diff] [blame] | 44 | import com.android.internal.telephony.PhoneConstants; |
| 45 | import com.android.internal.telephony.TelephonyProperties; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 46 | import com.android.internal.util.IndentingPrintWriter; |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 47 | |
Santos Cordon | 4bc0245 | 2014-11-19 15:51:12 -0800 | [diff] [blame] | 48 | import java.util.Collection; |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 49 | import java.util.Collections; |
Ihab Awad | 5b28132 | 2014-09-25 18:25:29 -0700 | [diff] [blame] | 50 | import java.util.HashSet; |
Santos Cordon | 7cdb909 | 2014-07-24 21:33:33 -0700 | [diff] [blame] | 51 | import java.util.List; |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 52 | import java.util.Objects; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 53 | import java.util.Set; |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 54 | import java.util.concurrent.ConcurrentHashMap; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 55 | |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 56 | /** |
| 57 | * Singleton. |
| 58 | * |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 59 | * NOTE: by design most APIs are package private, use the relevant adapter/s to allow |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 60 | * access from other packages specifically refraining from passing the CallsManager instance |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 61 | * beyond the com.android.server.telecom package boundary. |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 62 | */ |
Ihab Awad | aa383cc | 2015-03-22 22:12:28 -0700 | [diff] [blame] | 63 | @VisibleForTesting |
Tyler Gunn | 86014fc | 2015-06-12 14:31:25 -0700 | [diff] [blame] | 64 | public class CallsManager extends Call.ListenerBase implements VideoProviderProxy.Listener { |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 65 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 66 | // TODO: Consider renaming this CallsManagerPlugin. |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 67 | interface CallsManagerListener { |
| 68 | void onCallAdded(Call call); |
| 69 | void onCallRemoved(Call call); |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 70 | void onCallStateChanged(Call call, int oldState, int newState); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 71 | void onConnectionServiceChanged( |
Sailesh Nepal | 8c85dee | 2014-04-07 22:21:40 -0700 | [diff] [blame] | 72 | Call call, |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 73 | ConnectionServiceWrapper oldService, |
| 74 | ConnectionServiceWrapper newService); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 75 | void onIncomingCallAnswered(Call call); |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 76 | void onIncomingCallRejected(Call call, boolean rejectWithMessage, String textMessage); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 77 | void onForegroundCallChanged(Call oldForegroundCall, Call newForegroundCall); |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 78 | void onCallAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState); |
Andrew Lee | 5be64bc | 2014-09-08 18:35:15 -0700 | [diff] [blame] | 79 | void onRingbackRequested(Call call, boolean ringback); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 80 | void onIsConferencedChanged(Call call); |
Andrew Lee | 5be64bc | 2014-09-08 18:35:15 -0700 | [diff] [blame] | 81 | void onIsVoipAudioModeChanged(Call call); |
Andrew Lee | 4a79660 | 2014-07-11 17:23:03 -0700 | [diff] [blame] | 82 | void onVideoStateChanged(Call call); |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 83 | void onCanAddCallChanged(boolean canAddCall); |
Tyler Gunn | 86014fc | 2015-06-12 14:31:25 -0700 | [diff] [blame] | 84 | void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile); |
Ravindra | 205cb78 | 2015-10-07 16:57:53 +0530 | [diff] [blame] | 85 | void onMergeFailed(Call call); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 88 | private static final String TAG = "CallsManager"; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 89 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 90 | private static final int MAXIMUM_LIVE_CALLS = 1; |
| 91 | private static final int MAXIMUM_HOLD_CALLS = 1; |
| 92 | private static final int MAXIMUM_RINGING_CALLS = 1; |
Roshan Pius | 4de4a89 | 2015-08-24 11:06:58 -0700 | [diff] [blame] | 93 | private static final int MAXIMUM_DIALING_CALLS = 1; |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 94 | private static final int MAXIMUM_OUTGOING_CALLS = 1; |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 95 | private static final int MAXIMUM_TOP_LEVEL_CALLS = 2; |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 96 | private static final int MAXIMUM_DSDA_LIVE_CALLS = 2; |
| 97 | private static final int MAXIMUM_DSDA_HOLD_CALLS = 2; |
| 98 | private static final int MAXIMUM_DSDA_TOP_LEVEL_CALLS = 4; |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 99 | |
| 100 | private static final int[] OUTGOING_CALL_STATES = |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 101 | {CallState.CONNECTING, CallState.SELECT_PHONE_ACCOUNT, CallState.DIALING}; |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 102 | |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 103 | private static final int[] LIVE_CALL_STATES = |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 104 | {CallState.CONNECTING, CallState.SELECT_PHONE_ACCOUNT, CallState.DIALING, |
| 105 | CallState.ACTIVE}; |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 106 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 107 | /** |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 108 | * The main call repository. Keeps an instance of all live calls. New incoming and outgoing |
| 109 | * calls are added to the map and removed when the calls move to the disconnected state. |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 110 | * |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 111 | * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is |
| 112 | * load factor before resizing, 1 means we only expect a single thread to |
| 113 | * access the map so make only a single shard |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 114 | */ |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 115 | private final Set<Call> mCalls = Collections.newSetFromMap( |
| 116 | new ConcurrentHashMap<Call, Boolean>(8, 0.9f, 1)); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 117 | |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 118 | private final ConnectionServiceRepository mConnectionServiceRepository; |
| 119 | private final DtmfLocalTonePlayer mDtmfLocalTonePlayer; |
| 120 | private final InCallController mInCallController; |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 121 | private final CallAudioManager mCallAudioManager; |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 122 | private RespondViaSmsManager mRespondViaSmsManager; |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 123 | private final Ringer mRinger; |
Santos Cordon | 61e6f35 | 2014-12-03 02:53:34 -0800 | [diff] [blame] | 124 | private final InCallWakeLockController mInCallWakeLockController; |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 125 | // For this set initial table size to 16 because we add 13 listeners in |
| 126 | // the CallsManager constructor. |
| 127 | private final Set<CallsManagerListener> mListeners = Collections.newSetFromMap( |
| 128 | new ConcurrentHashMap<CallsManagerListener, Boolean>(16, 0.9f, 1)); |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 129 | private final HeadsetMediaButton mHeadsetMediaButton; |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 130 | private final WiredHeadsetManager mWiredHeadsetManager; |
Santos Cordon | a04bdca | 2015-03-04 16:57:55 -0800 | [diff] [blame] | 131 | private final DockManager mDockManager; |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 132 | private final TtyManager mTtyManager; |
Yorke Lee | d134687 | 2014-07-28 14:38:45 -0700 | [diff] [blame] | 133 | private final ProximitySensorManager mProximitySensorManager; |
Yorke Lee | f86db2e | 2014-09-12 17:56:48 -0700 | [diff] [blame] | 134 | private final PhoneStateBroadcaster mPhoneStateBroadcaster; |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 135 | private final CallLogManager mCallLogManager; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 136 | private final Context mContext; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 137 | private final TelecomSystem.SyncRoot mLock; |
| 138 | private final ContactsAsyncHelper mContactsAsyncHelper; |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 139 | private final CallerInfoAsyncQueryFactory mCallerInfoAsyncQueryFactory; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 140 | private final PhoneAccountRegistrar mPhoneAccountRegistrar; |
| 141 | private final MissedCallNotifier mMissedCallNotifier; |
Ihab Awad | 5b28132 | 2014-09-25 18:25:29 -0700 | [diff] [blame] | 142 | private final Set<Call> mLocallyDisconnectingCalls = new HashSet<>(); |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 143 | private final Set<Call> mPendingCallsToDisconnect = new HashSet<>(); |
| 144 | /* Handler tied to thread in which CallManager was initialized. */ |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 145 | private final Handler mHandler = new Handler(Looper.getMainLooper()); |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 146 | |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 147 | private boolean mCanAddCall = true; |
| 148 | |
Sailesh Nepal | 84fa5f8 | 2014-04-02 11:01:11 -0700 | [diff] [blame] | 149 | /** |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 150 | * The call the user is currently interacting with. This is the call that should have audio |
| 151 | * focus and be visible in the in-call UI. |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 152 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 153 | private Call mForegroundCall; |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 154 | |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 155 | private static final int LCH_PLAY_DTMF = 100; |
| 156 | private static final int LCH_STOP_DTMF = 101; |
| 157 | private static final int PHONE_START_DSDA_INCALL_TONE = 102; |
| 158 | private static final int LCH_DTMF_PERIODICITY = 3000; |
| 159 | private static final int LCH_DTMF_PERIOD = 500; |
| 160 | private static final String sSupervisoryCallHoldToneConfig = |
| 161 | SystemProperties.get("persist.radio.sch_tone", "none"); |
| 162 | |
| 163 | private static InCallTonePlayer.Factory mPlayerFactory; |
| 164 | private String mLchSub = null; |
| 165 | |
| 166 | private InCallTonePlayer mLocalCallReminderTonePlayer = null; |
| 167 | private InCallTonePlayer mSupervisoryCallHoldTonePlayer = null; |
| 168 | private String mSubInConversation = null; |
| 169 | |
Nancy Chen | a469f76 | 2014-12-09 18:29:20 -0800 | [diff] [blame] | 170 | private Runnable mStopTone; |
| 171 | |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 172 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 173 | * Initializes the required Telecom components. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 174 | */ |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 175 | CallsManager( |
| 176 | Context context, |
| 177 | TelecomSystem.SyncRoot lock, |
| 178 | ContactsAsyncHelper contactsAsyncHelper, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 179 | CallerInfoAsyncQueryFactory callerInfoAsyncQueryFactory, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 180 | MissedCallNotifier missedCallNotifier, |
| 181 | PhoneAccountRegistrar phoneAccountRegistrar, |
| 182 | HeadsetMediaButtonFactory headsetMediaButtonFactory, |
| 183 | ProximitySensorManagerFactory proximitySensorManagerFactory, |
| 184 | InCallWakeLockControllerFactory inCallWakeLockControllerFactory) { |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 185 | mContext = context; |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 186 | mLock = lock; |
| 187 | mContactsAsyncHelper = contactsAsyncHelper; |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 188 | mCallerInfoAsyncQueryFactory = callerInfoAsyncQueryFactory; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 189 | mPhoneAccountRegistrar = phoneAccountRegistrar; |
| 190 | mMissedCallNotifier = missedCallNotifier; |
| 191 | StatusBarNotifier statusBarNotifier = new StatusBarNotifier(context, this); |
| 192 | mWiredHeadsetManager = new WiredHeadsetManager(context); |
Santos Cordon | a04bdca | 2015-03-04 16:57:55 -0800 | [diff] [blame] | 193 | mDockManager = new DockManager(context); |
| 194 | mCallAudioManager = new CallAudioManager( |
Ihab Awad | b60f006 | 2015-05-26 16:20:32 -0700 | [diff] [blame] | 195 | context, mLock, statusBarNotifier, mWiredHeadsetManager, mDockManager, this); |
Vinit Deshpande | 73ff372 | 2015-04-14 17:58:09 -0700 | [diff] [blame] | 196 | InCallTonePlayer.Factory playerFactory = new InCallTonePlayer.Factory(mCallAudioManager, lock); |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 197 | mPlayerFactory = playerFactory; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 198 | mRinger = new Ringer(mCallAudioManager, this, playerFactory, context); |
Ihab Awad | 731369c | 2015-05-19 09:23:21 -0700 | [diff] [blame] | 199 | mHeadsetMediaButton = headsetMediaButtonFactory.create(context, this, mLock); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 200 | mTtyManager = new TtyManager(context, mWiredHeadsetManager); |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 201 | mProximitySensorManager = proximitySensorManagerFactory.create(context, this); |
| 202 | mPhoneStateBroadcaster = new PhoneStateBroadcaster(this); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 203 | mCallLogManager = new CallLogManager(context); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 204 | mInCallController = new InCallController(context, mLock, this); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 205 | mDtmfLocalTonePlayer = new DtmfLocalTonePlayer(context); |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 206 | mConnectionServiceRepository = |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 207 | new ConnectionServiceRepository(mPhoneAccountRegistrar, mContext, mLock, this); |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 208 | mInCallWakeLockController = inCallWakeLockControllerFactory.create(context, this); |
Santos Cordon | ae19306 | 2014-05-21 21:21:49 -0700 | [diff] [blame] | 209 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 210 | mListeners.add(statusBarNotifier); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 211 | mListeners.add(mCallLogManager); |
Yorke Lee | f86db2e | 2014-09-12 17:56:48 -0700 | [diff] [blame] | 212 | mListeners.add(mPhoneStateBroadcaster); |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 213 | mListeners.add(mInCallController); |
Santos Cordon | ae19306 | 2014-05-21 21:21:49 -0700 | [diff] [blame] | 214 | mListeners.add(mRinger); |
Santos Cordon | c7b8eba | 2014-04-01 15:26:28 -0700 | [diff] [blame] | 215 | mListeners.add(new RingbackPlayer(this, playerFactory)); |
| 216 | mListeners.add(new InCallToneMonitor(playerFactory, this)); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 217 | mListeners.add(mCallAudioManager); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 218 | mListeners.add(missedCallNotifier); |
Santos Cordon | 92a2d81 | 2014-04-30 15:19:01 -0700 | [diff] [blame] | 219 | mListeners.add(mDtmfLocalTonePlayer); |
Santos Cordon | 8128998 | 2014-06-03 16:03:08 -0700 | [diff] [blame] | 220 | mListeners.add(mHeadsetMediaButton); |
Yorke Lee | d134687 | 2014-07-28 14:38:45 -0700 | [diff] [blame] | 221 | mListeners.add(mProximitySensorManager); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 222 | |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 223 | mMissedCallNotifier.updateOnStartup( |
| 224 | mLock, this, mContactsAsyncHelper, mCallerInfoAsyncQueryFactory); |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 225 | } |
| 226 | |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 227 | public void setRespondViaSmsManager(RespondViaSmsManager respondViaSmsManager) { |
| 228 | if (mRespondViaSmsManager != null) { |
| 229 | mListeners.remove(mRespondViaSmsManager); |
| 230 | } |
| 231 | mRespondViaSmsManager = respondViaSmsManager; |
| 232 | mListeners.add(respondViaSmsManager); |
| 233 | } |
| 234 | |
| 235 | public RespondViaSmsManager getRespondViaSmsManager() { |
| 236 | return mRespondViaSmsManager; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 239 | @Override |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 240 | public void onSuccessfulOutgoingCall(Call call, int callState) { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 241 | Log.v(this, "onSuccessfulOutgoingCall, %s", call); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 242 | |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 243 | setCallState(call, callState, "successful outgoing call"); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 244 | if (!mCalls.contains(call)) { |
| 245 | // Call was not added previously in startOutgoingCall due to it being a potential MMI |
| 246 | // code, so add it now. |
| 247 | addCall(call); |
| 248 | } |
| 249 | |
| 250 | // The call's ConnectionService has been updated. |
| 251 | for (CallsManagerListener listener : mListeners) { |
| 252 | listener.onConnectionServiceChanged(call, null, call.getConnectionService()); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 253 | } |
Santos Cordon | 6cb7ba9 | 2014-05-23 14:09:32 -0700 | [diff] [blame] | 254 | |
| 255 | markCallAsDialing(call); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | @Override |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 259 | public void onFailedOutgoingCall(Call call, DisconnectCause disconnectCause) { |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 260 | Log.v(this, "onFailedOutgoingCall, call: %s", call); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 261 | |
Andrew Lee | e6288a7 | 2014-10-01 13:50:02 -0700 | [diff] [blame] | 262 | markCallAsRemoved(call); |
Sailesh Nepal | 5a73b03 | 2014-06-25 15:53:21 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | @Override |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 266 | public void onSuccessfulIncomingCall(Call incomingCall) { |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 267 | Log.d(this, "onSuccessfulIncomingCall"); |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 268 | setCallState(incomingCall, CallState.RINGING, "successful incoming call"); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 269 | |
David Ng | ca0c678 | 2015-11-30 17:00:46 -0800 | [diff] [blame] | 270 | if (hasMaximumRingingCalls(incomingCall.getTargetPhoneAccount().getId()) || hasMaximumDialingCalls() ) { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 271 | incomingCall.reject(false, null); |
| 272 | // since the call was not added to the list of calls, we have to call the missed |
| 273 | // call notifier and the call logger manually. |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 274 | mMissedCallNotifier.showMissedCallNotification(incomingCall); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 275 | mCallLogManager.logCall(incomingCall, Calls.MISSED_TYPE); |
| 276 | } else { |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 277 | if (TelephonyManager.getDefault().getMultiSimConfiguration() |
| 278 | == TelephonyManager.MultiSimVariants.DSDA) { |
| 279 | incomingCall.mIsActiveSub = true; |
| 280 | } |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 281 | addCall(incomingCall); |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 282 | setActiveSubscription(incomingCall.getTargetPhoneAccount().getId()); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 283 | } |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public void onFailedIncomingCall(Call call) { |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 288 | setCallState(call, CallState.DISCONNECTED, "failed incoming call"); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 289 | call.removeListener(this); |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 290 | } |
| 291 | |
Ihab Awad | cb387ac | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 292 | @Override |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 293 | public void onSuccessfulUnknownCall(Call call, int callState) { |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 294 | setCallState(call, callState, "successful unknown call"); |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 295 | Log.i(this, "onSuccessfulUnknownCall for call %s", call); |
| 296 | addCall(call); |
| 297 | } |
| 298 | |
| 299 | @Override |
| 300 | public void onFailedUnknownCall(Call call) { |
| 301 | Log.i(this, "onFailedUnknownCall for call %s", call); |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 302 | setCallState(call, CallState.DISCONNECTED, "failed unknown call"); |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 303 | call.removeListener(this); |
| 304 | } |
| 305 | |
| 306 | @Override |
Andrew Lee | 5be64bc | 2014-09-08 18:35:15 -0700 | [diff] [blame] | 307 | public void onRingbackRequested(Call call, boolean ringback) { |
Ihab Awad | cb387ac | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 308 | for (CallsManagerListener listener : mListeners) { |
Andrew Lee | 5be64bc | 2014-09-08 18:35:15 -0700 | [diff] [blame] | 309 | listener.onRingbackRequested(call, ringback); |
Ihab Awad | cb387ac | 2014-05-28 16:49:38 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 313 | @Override |
| 314 | public void onPostDialWait(Call call, String remaining) { |
| 315 | mInCallController.onPostDialWait(call, remaining); |
| 316 | } |
| 317 | |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 318 | @Override |
Nancy Chen | a469f76 | 2014-12-09 18:29:20 -0800 | [diff] [blame] | 319 | public void onPostDialChar(final Call call, char nextChar) { |
| 320 | if (PhoneNumberUtils.is12Key(nextChar)) { |
| 321 | // Play tone if it is one of the dialpad digits, canceling out the previously queued |
| 322 | // up stopTone runnable since playing a new tone automatically stops the previous tone. |
| 323 | if (mStopTone != null) { |
| 324 | mHandler.removeCallbacks(mStopTone); |
| 325 | } |
| 326 | |
| 327 | mDtmfLocalTonePlayer.playTone(call, nextChar); |
| 328 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 329 | // TODO: Create a LockedRunnable class that does the synchronization automatically. |
Nancy Chen | a469f76 | 2014-12-09 18:29:20 -0800 | [diff] [blame] | 330 | mStopTone = new Runnable() { |
| 331 | @Override |
| 332 | public void run() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 333 | synchronized (mLock) { |
| 334 | // Set a timeout to stop the tone in case there isn't another tone to follow. |
| 335 | mDtmfLocalTonePlayer.stopTone(call); |
| 336 | } |
Nancy Chen | a469f76 | 2014-12-09 18:29:20 -0800 | [diff] [blame] | 337 | } |
| 338 | }; |
| 339 | mHandler.postDelayed( |
| 340 | mStopTone, |
| 341 | Timeouts.getDelayBetweenDtmfTonesMillis(mContext.getContentResolver())); |
| 342 | } else if (nextChar == 0 || nextChar == TelecomManager.DTMF_CHARACTER_WAIT || |
| 343 | nextChar == TelecomManager.DTMF_CHARACTER_PAUSE) { |
| 344 | // Stop the tone if a tone is playing, removing any other stopTone callbacks since |
| 345 | // the previous tone is being stopped anyway. |
| 346 | if (mStopTone != null) { |
| 347 | mHandler.removeCallbacks(mStopTone); |
| 348 | } |
| 349 | mDtmfLocalTonePlayer.stopTone(call); |
| 350 | } else { |
| 351 | Log.w(this, "onPostDialChar: invalid value %d", nextChar); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | @Override |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 356 | public void onParentChanged(Call call) { |
Santos Cordon | 66fe882 | 2014-10-10 16:10:58 -0700 | [diff] [blame] | 357 | // parent-child relationship affects which call should be foreground, so do an update. |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 358 | updateCallsManagerState(); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 359 | for (CallsManagerListener listener : mListeners) { |
| 360 | listener.onIsConferencedChanged(call); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | @Override |
| 365 | public void onChildrenChanged(Call call) { |
Santos Cordon | 66fe882 | 2014-10-10 16:10:58 -0700 | [diff] [blame] | 366 | // parent-child relationship affects which call should be foreground, so do an update. |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 367 | updateCallsManagerState(); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 368 | for (CallsManagerListener listener : mListeners) { |
| 369 | listener.onIsConferencedChanged(call); |
| 370 | } |
| 371 | } |
| 372 | |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 373 | @Override |
Andrew Lee | 5be64bc | 2014-09-08 18:35:15 -0700 | [diff] [blame] | 374 | public void onIsVoipAudioModeChanged(Call call) { |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 375 | for (CallsManagerListener listener : mListeners) { |
Andrew Lee | 5be64bc | 2014-09-08 18:35:15 -0700 | [diff] [blame] | 376 | listener.onIsVoipAudioModeChanged(call); |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | |
Andrew Lee | 4a79660 | 2014-07-11 17:23:03 -0700 | [diff] [blame] | 380 | @Override |
| 381 | public void onVideoStateChanged(Call call) { |
| 382 | for (CallsManagerListener listener : mListeners) { |
| 383 | listener.onVideoStateChanged(call); |
| 384 | } |
| 385 | } |
| 386 | |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 387 | @Override |
| 388 | public boolean onCanceledViaNewOutgoingCallBroadcast(final Call call) { |
| 389 | mPendingCallsToDisconnect.add(call); |
| 390 | mHandler.postDelayed(new Runnable() { |
| 391 | @Override |
| 392 | public void run() { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 393 | synchronized (mLock) { |
| 394 | if (mPendingCallsToDisconnect.remove(call)) { |
| 395 | Log.i(this, "Delayed disconnection of call: %s", call); |
| 396 | call.disconnect(); |
| 397 | } |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | }, Timeouts.getNewOutgoingCallCancelMillis(mContext.getContentResolver())); |
| 401 | |
| 402 | return true; |
| 403 | } |
| 404 | |
Tyler Gunn | 86014fc | 2015-06-12 14:31:25 -0700 | [diff] [blame] | 405 | /** |
| 406 | * Handles changes to the {@link Connection.VideoProvider} for a call. Adds the |
| 407 | * {@link CallsManager} as a listener for the {@link VideoProviderProxy} which is created |
| 408 | * in {@link Call#setVideoProvider(IVideoProvider)}. This allows the {@link CallsManager} to |
| 409 | * respond to callbacks from the {@link VideoProviderProxy}. |
| 410 | * |
| 411 | * @param call The call. |
| 412 | */ |
| 413 | @Override |
| 414 | public void onVideoCallProviderChanged(Call call) { |
| 415 | VideoProviderProxy videoProviderProxy = call.getVideoProviderProxy(); |
| 416 | |
| 417 | if (videoProviderProxy == null) { |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | videoProviderProxy.addListener(this); |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Handles session modification requests received via the {@link TelecomVideoCallCallback} for |
| 426 | * a call. Notifies listeners of the {@link CallsManager.CallsManagerListener} of the session |
| 427 | * modification request. |
| 428 | * |
| 429 | * @param call The call. |
| 430 | * @param videoProfile The {@link VideoProfile}. |
| 431 | */ |
| 432 | @Override |
| 433 | public void onSessionModifyRequestReceived(Call call, VideoProfile videoProfile) { |
| 434 | int videoState = videoProfile != null ? videoProfile.getVideoState() : |
| 435 | VideoProfile.STATE_AUDIO_ONLY; |
| 436 | Log.v(TAG, "onSessionModifyRequestReceived : videoProfile = " + VideoProfile |
| 437 | .videoStateToString(videoState)); |
| 438 | |
| 439 | for (CallsManagerListener listener : mListeners) { |
| 440 | listener.onSessionModifyRequestReceived(call, videoProfile); |
| 441 | } |
| 442 | } |
| 443 | |
Santos Cordon | 4bc0245 | 2014-11-19 15:51:12 -0800 | [diff] [blame] | 444 | Collection<Call> getCalls() { |
| 445 | return Collections.unmodifiableCollection(mCalls); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | Call getForegroundCall() { |
| 449 | return mForegroundCall; |
| 450 | } |
| 451 | |
Santos Cordon | ae19306 | 2014-05-21 21:21:49 -0700 | [diff] [blame] | 452 | Ringer getRinger() { |
| 453 | return mRinger; |
| 454 | } |
| 455 | |
Santos Cordon | f3671a6 | 2014-05-29 21:51:53 -0700 | [diff] [blame] | 456 | InCallController getInCallController() { |
| 457 | return mInCallController; |
| 458 | } |
| 459 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 460 | boolean hasEmergencyCall() { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 461 | for (Call call : mCalls) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 462 | if (call.isEmergencyCall()) { |
| 463 | return true; |
| 464 | } |
| 465 | } |
| 466 | return false; |
| 467 | } |
| 468 | |
Roshan Pius | 669f90b | 2015-09-02 16:21:39 -0700 | [diff] [blame] | 469 | boolean hasOnlyDisconnectedCalls() { |
| 470 | for (Call call : mCalls) { |
| 471 | if (!call.isDisconnected()) { |
| 472 | return false; |
| 473 | } |
| 474 | } |
| 475 | return true; |
| 476 | } |
| 477 | |
Andrew Lee | 4550623 | 2014-10-22 17:54:33 -0700 | [diff] [blame] | 478 | boolean hasVideoCall() { |
| 479 | for (Call call : mCalls) { |
Tyler Gunn | 467b64f | 2015-06-09 13:48:47 -0700 | [diff] [blame] | 480 | if (VideoProfile.isVideo(call.getVideoState())) { |
Andrew Lee | 4550623 | 2014-10-22 17:54:33 -0700 | [diff] [blame] | 481 | return true; |
| 482 | } |
| 483 | } |
| 484 | return false; |
| 485 | } |
| 486 | |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 487 | CallAudioState getAudioState() { |
| 488 | return mCallAudioManager.getCallAudioState(); |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Sailesh Nepal | b88795a | 2014-07-15 14:53:27 -0700 | [diff] [blame] | 491 | boolean isTtySupported() { |
| 492 | return mTtyManager.isTtySupported(); |
| 493 | } |
| 494 | |
| 495 | int getCurrentTtyMode() { |
| 496 | return mTtyManager.getCurrentTtyMode(); |
| 497 | } |
| 498 | |
Santos Cordon | 68d1a6b | 2014-09-19 12:25:58 -0700 | [diff] [blame] | 499 | void addListener(CallsManagerListener listener) { |
| 500 | mListeners.add(listener); |
| 501 | } |
| 502 | |
| 503 | void removeListener(CallsManagerListener listener) { |
| 504 | mListeners.remove(listener); |
| 505 | } |
| 506 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 507 | /** |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 508 | * Starts the process to attach the call to a connection service. |
Santos Cordon | 80d9bdc | 2014-02-13 18:28:46 -0800 | [diff] [blame] | 509 | * |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 510 | * @param phoneAccountHandle The phone account which contains the component name of the |
| 511 | * connection service to use for this call. |
Evan Charlton | a05805b | 2014-03-05 08:21:46 -0800 | [diff] [blame] | 512 | * @param extras The optional extras Bundle passed with the intent used for the incoming call. |
Santos Cordon | 80d9bdc | 2014-02-13 18:28:46 -0800 | [diff] [blame] | 513 | */ |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 514 | void processIncomingCallIntent(PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
Sailesh Nepal | f1c191d | 2014-03-07 18:17:39 -0800 | [diff] [blame] | 515 | Log.d(this, "processIncomingCallIntent"); |
Yorke Lee | 69fa897 | 2015-06-08 11:25:32 -0700 | [diff] [blame] | 516 | Uri handle = extras.getParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS); |
| 517 | if (handle == null) { |
| 518 | // Required for backwards compatibility |
| 519 | handle = extras.getParcelable(TelephonyManager.EXTRA_INCOMING_NUMBER); |
| 520 | } |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 521 | Call call = new Call( |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 522 | mContext, |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 523 | this, |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 524 | mLock, |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 525 | mConnectionServiceRepository, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 526 | mContactsAsyncHelper, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 527 | mCallerInfoAsyncQueryFactory, |
Sailesh Nepal | 8aa6a00 | 2014-09-12 10:52:49 -0700 | [diff] [blame] | 528 | handle, |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 529 | null /* gatewayInfo */, |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 530 | null /* connectionManagerPhoneAccount */, |
Evan Charlton | 8917637 | 2014-07-19 18:23:09 -0700 | [diff] [blame] | 531 | phoneAccountHandle, |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 532 | true /* isIncoming */, |
| 533 | false /* isConference */); |
| 534 | |
Andrew Lee | 1b90665 | 2015-06-01 11:44:55 -0700 | [diff] [blame] | 535 | call.setIntentExtras(extras); |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 536 | // TODO: Move this to be a part of addCall() |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 537 | call.addListener(this); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 538 | call.startCreateConnection(mPhoneAccountRegistrar); |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 539 | } |
| 540 | |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 541 | void addNewUnknownCall(PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
| 542 | Uri handle = extras.getParcelable(TelecomManager.EXTRA_UNKNOWN_CALL_HANDLE); |
| 543 | Log.i(this, "addNewUnknownCall with handle: %s", Log.pii(handle)); |
| 544 | Call call = new Call( |
| 545 | mContext, |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 546 | this, |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 547 | mLock, |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 548 | mConnectionServiceRepository, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 549 | mContactsAsyncHelper, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 550 | mCallerInfoAsyncQueryFactory, |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 551 | handle, |
| 552 | null /* gatewayInfo */, |
| 553 | null /* connectionManagerPhoneAccount */, |
| 554 | phoneAccountHandle, |
| 555 | // Use onCreateIncomingConnection in TelephonyConnectionService, so that we attach |
| 556 | // to the existing connection instead of trying to create a new one. |
| 557 | true /* isIncoming */, |
| 558 | false /* isConference */); |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 559 | call.setIsUnknown(true); |
Andrew Lee | 1b90665 | 2015-06-01 11:44:55 -0700 | [diff] [blame] | 560 | call.setIntentExtras(extras); |
Yorke Lee | 9250e5f | 2014-10-01 13:39:09 -0700 | [diff] [blame] | 561 | call.addListener(this); |
| 562 | call.startCreateConnection(mPhoneAccountRegistrar); |
| 563 | } |
| 564 | |
Yorke Lee | 8d3f269 | 2015-05-08 11:44:39 -0700 | [diff] [blame] | 565 | private boolean areHandlesEqual(Uri handle1, Uri handle2) { |
| 566 | if (handle1 == null || handle2 == null) { |
| 567 | return handle1 == handle2; |
| 568 | } |
| 569 | |
| 570 | if (!TextUtils.equals(handle1.getScheme(), handle2.getScheme())) { |
| 571 | return false; |
| 572 | } |
| 573 | |
| 574 | final String number1 = PhoneNumberUtils.normalizeNumber(handle1.getSchemeSpecificPart()); |
| 575 | final String number2 = PhoneNumberUtils.normalizeNumber(handle2.getSchemeSpecificPart()); |
| 576 | return TextUtils.equals(number1, number2); |
| 577 | } |
| 578 | |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 579 | private Call getNewOutgoingCall(Uri handle) { |
| 580 | // First check to see if we can reuse any of the calls that are waiting to disconnect. |
| 581 | // See {@link Call#abort} and {@link #onCanceledViaNewOutgoingCall} for more information. |
Yorke Lee | 5997951 | 2014-12-02 01:03:40 -0800 | [diff] [blame] | 582 | Call reusedCall = null; |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 583 | for (Call pendingCall : mPendingCallsToDisconnect) { |
Yorke Lee | 8d3f269 | 2015-05-08 11:44:39 -0700 | [diff] [blame] | 584 | if (reusedCall == null && areHandlesEqual(pendingCall.getHandle(), handle)) { |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 585 | mPendingCallsToDisconnect.remove(pendingCall); |
| 586 | Log.i(this, "Reusing disconnected call %s", pendingCall); |
Yorke Lee | 5997951 | 2014-12-02 01:03:40 -0800 | [diff] [blame] | 587 | reusedCall = pendingCall; |
| 588 | } else { |
Yorke Lee | 8d3f269 | 2015-05-08 11:44:39 -0700 | [diff] [blame] | 589 | Log.i(this, "Not reusing disconnected call %s", pendingCall); |
Yorke Lee | 5997951 | 2014-12-02 01:03:40 -0800 | [diff] [blame] | 590 | pendingCall.disconnect(); |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 591 | } |
| 592 | } |
Yorke Lee | 5997951 | 2014-12-02 01:03:40 -0800 | [diff] [blame] | 593 | if (reusedCall != null) { |
| 594 | return reusedCall; |
| 595 | } |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 596 | |
| 597 | // Create a call with original handle. The handle may be changed when the call is attached |
| 598 | // to a connection service, but in most cases will remain the same. |
| 599 | return new Call( |
| 600 | mContext, |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 601 | this, |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 602 | mLock, |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 603 | mConnectionServiceRepository, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 604 | mContactsAsyncHelper, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 605 | mCallerInfoAsyncQueryFactory, |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 606 | handle, |
| 607 | null /* gatewayInfo */, |
| 608 | null /* connectionManagerPhoneAccount */, |
| 609 | null /* phoneAccountHandle */, |
| 610 | false /* isIncoming */, |
| 611 | false /* isConference */); |
| 612 | } |
| 613 | |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 614 | /** |
| 615 | * Kicks off the first steps to creating an outgoing call so that InCallUI can launch. |
| 616 | * |
Nancy Chen | a9d91da | 2014-08-12 14:31:06 -0700 | [diff] [blame] | 617 | * @param handle Handle to connect the call with. |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 618 | * @param phoneAccountHandle The phone account which contains the component name of the |
| 619 | * connection service to use for this call. |
| 620 | * @param extras The optional extras Bundle passed with the intent used for the incoming call. |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 621 | */ |
Nancy Chen | a9d91da | 2014-08-12 14:31:06 -0700 | [diff] [blame] | 622 | Call startOutgoingCall(Uri handle, PhoneAccountHandle phoneAccountHandle, Bundle extras) { |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 623 | Call call = getNewOutgoingCall(handle); |
Nancy Chen | 1c5926f | 2014-09-17 14:44:14 -0700 | [diff] [blame] | 624 | |
Garik Badalyan | 7e1524a | 2015-08-25 11:08:18 -0700 | [diff] [blame] | 625 | if (extras!=null) { |
| 626 | call.setVideoState(extras.getInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, |
| 627 | VideoProfile.STATE_AUDIO_ONLY)); |
| 628 | } |
| 629 | |
Suchand Ghosh | 97f3cb1 | 2014-09-22 12:13:47 +0530 | [diff] [blame] | 630 | boolean isAddParticipant = ((extras != null) && (extras.getBoolean( |
| 631 | TelephonyProperties.ADD_PARTICIPANT_KEY, false))); |
| 632 | boolean isSkipSchemaOrConfUri = ((extras != null) && (extras.getBoolean( |
| 633 | TelephonyProperties.EXTRA_SKIP_SCHEMA_PARSING, false) || |
| 634 | extras.getBoolean(TelephonyProperties.EXTRA_DIAL_CONFERENCE_URI, false))); |
| 635 | |
| 636 | if (isAddParticipant) { |
| 637 | String number = handle.getSchemeSpecificPart(); |
| 638 | if (!isSkipSchemaOrConfUri) { |
| 639 | number = PhoneNumberUtils.stripSeparators(number); |
| 640 | } |
| 641 | addParticipant(number); |
| 642 | mInCallController.bringToForeground(false); |
| 643 | return null; |
| 644 | } |
| 645 | |
| 646 | // Force tel scheme for ims conf uri/skip schema calls to avoid selection of sip accounts |
| 647 | String scheme = (isSkipSchemaOrConfUri? PhoneAccount.SCHEME_TEL: handle.getScheme()); |
| 648 | |
| 649 | Log.d(this, "startOutgoingCall :: isAddParticipant=" + isAddParticipant |
| 650 | + " isSkipSchemaOrConfUri=" + isSkipSchemaOrConfUri + " scheme=" + scheme); |
| 651 | |
Nancy Chen | 1c5926f | 2014-09-17 14:44:14 -0700 | [diff] [blame] | 652 | List<PhoneAccountHandle> accounts = |
Suchand Ghosh | 97f3cb1 | 2014-09-22 12:13:47 +0530 | [diff] [blame] | 653 | mPhoneAccountRegistrar.getCallCapablePhoneAccounts(scheme, false); |
Nancy Chen | 1c5926f | 2014-09-17 14:44:14 -0700 | [diff] [blame] | 654 | |
Ihab Awad | 7e2c7f3 | 2014-11-03 09:49:45 -0800 | [diff] [blame] | 655 | Log.v(this, "startOutgoingCall found accounts = " + accounts); |
| 656 | |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 657 | if (mForegroundCall != null && TelephonyManager.getDefault().getMultiSimConfiguration() |
| 658 | != TelephonyManager.MultiSimVariants.DSDA) { |
Roshan Pius | 1a37383 | 2015-08-07 11:39:05 -0700 | [diff] [blame] | 659 | Call ongoingCall = mForegroundCall; |
Nancy Chen | bc95db9 | 2014-11-24 13:19:18 -0800 | [diff] [blame] | 660 | // If there is an ongoing call, use the same phone account to place this new call. |
Roshan Pius | 1a37383 | 2015-08-07 11:39:05 -0700 | [diff] [blame] | 661 | // If the ongoing call is a conference call, we fetch the phone account from the |
| 662 | // child calls because we don't have targetPhoneAccount set on Conference calls. |
| 663 | // TODO: Set targetPhoneAccount for all conference calls (b/23035408). |
| 664 | if (ongoingCall.getTargetPhoneAccount() == null && |
| 665 | !ongoingCall.getChildCalls().isEmpty()) { |
| 666 | ongoingCall = ongoingCall.getChildCalls().get(0); |
| 667 | } |
| 668 | if (ongoingCall.getTargetPhoneAccount() != null) { |
| 669 | phoneAccountHandle = ongoingCall.getTargetPhoneAccount(); |
| 670 | } |
Nancy Chen | bc95db9 | 2014-11-24 13:19:18 -0800 | [diff] [blame] | 671 | } |
| 672 | |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 673 | // Only dial with the requested phoneAccount if it is still valid. Otherwise treat this call |
| 674 | // as if a phoneAccount was not specified (does the default behavior instead). |
Tyler Gunn | 8e0fef4 | 2014-09-08 18:34:44 -0700 | [diff] [blame] | 675 | // Note: We will not attempt to dial with a requested phoneAccount if it is disabled. |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 676 | if (phoneAccountHandle != null) { |
Nancy Chen | 309198e | 2014-09-15 18:02:49 -0700 | [diff] [blame] | 677 | if (!accounts.contains(phoneAccountHandle)) { |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 678 | phoneAccountHandle = null; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | if (phoneAccountHandle == null) { |
Tyler Gunn | 8425357 | 2014-09-02 14:50:05 -0700 | [diff] [blame] | 683 | // No preset account, check if default exists that supports the URI scheme for the |
| 684 | // handle. |
Santos Cordon | 6a21264 | 2015-05-08 16:35:23 -0700 | [diff] [blame] | 685 | phoneAccountHandle = |
Suchand Ghosh | 97f3cb1 | 2014-09-22 12:13:47 +0530 | [diff] [blame] | 686 | mPhoneAccountRegistrar.getOutgoingPhoneAccountForScheme(scheme); |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Nancy Chen | 1c5926f | 2014-09-17 14:44:14 -0700 | [diff] [blame] | 689 | call.setTargetPhoneAccount(phoneAccountHandle); |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 690 | |
Tyler Gunn | 5b452df | 2014-10-01 15:02:58 -0700 | [diff] [blame] | 691 | boolean isPotentialInCallMMICode = isPotentialInCallMMICode(handle); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 692 | |
| 693 | // Do not support any more live calls. Our options are to move a call to hold, disconnect |
| 694 | // a call, or cancel this call altogether. |
Tyler Gunn | 6ffe531 | 2015-08-12 08:19:20 -0700 | [diff] [blame] | 695 | if (!isPotentialInCallMMICode && !makeRoomForOutgoingCall(call, call.isEmergencyCall())) { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 696 | // just cancel at this point. |
Yorke Lee | 5997951 | 2014-12-02 01:03:40 -0800 | [diff] [blame] | 697 | Log.i(this, "No remaining room for outgoing call: %s", call); |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 698 | if (mCalls.contains(call)) { |
| 699 | // This call can already exist if it is a reused call, |
| 700 | // See {@link #getNewOutgoingCall}. |
| 701 | call.disconnect(); |
| 702 | } |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 703 | return null; |
| 704 | } |
| 705 | |
Nancy Chen | 8d92f45 | 2014-10-20 21:43:44 -0700 | [diff] [blame] | 706 | boolean needsAccountSelection = phoneAccountHandle == null && accounts.size() > 1 && |
Tyler Gunn | 6ffe531 | 2015-08-12 08:19:20 -0700 | [diff] [blame] | 707 | !call.isEmergencyCall(); |
Nancy Chen | 8d92f45 | 2014-10-20 21:43:44 -0700 | [diff] [blame] | 708 | |
| 709 | if (needsAccountSelection) { |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 710 | // This is the state where the user is expected to select an account |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 711 | call.setState(CallState.SELECT_PHONE_ACCOUNT, "needs account selection"); |
Pawit Pornkitprasan | 1b2fd28 | 2015-03-15 08:33:32 +0700 | [diff] [blame] | 712 | // Create our own instance to modify (since extras may be Bundle.EMPTY) |
| 713 | extras = new Bundle(extras); |
Nancy Chen | 1c5926f | 2014-09-17 14:44:14 -0700 | [diff] [blame] | 714 | extras.putParcelableList(android.telecom.Call.AVAILABLE_PHONE_ACCOUNTS, accounts); |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 715 | } else { |
Roshan Pius | 781d025 | 2015-06-25 14:13:07 -0700 | [diff] [blame] | 716 | call.setState( |
| 717 | CallState.CONNECTING, |
| 718 | phoneAccountHandle == null ? "no-handle" : phoneAccountHandle.toString()); |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 719 | } |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 720 | |
Andrew Lee | 1b90665 | 2015-06-01 11:44:55 -0700 | [diff] [blame] | 721 | call.setIntentExtras(extras); |
Nancy Chen | 1c5926f | 2014-09-17 14:44:14 -0700 | [diff] [blame] | 722 | |
Tyler Gunn | 504eb83 | 2014-10-13 14:15:27 -0700 | [diff] [blame] | 723 | // Do not add the call if it is a potential MMI code. |
Nancy Chen | 8d92f45 | 2014-10-20 21:43:44 -0700 | [diff] [blame] | 724 | if ((isPotentialMMICode(handle) || isPotentialInCallMMICode) && !needsAccountSelection) { |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 725 | call.addListener(this); |
Santos Cordon | cf5b291 | 2014-11-05 21:57:54 -0800 | [diff] [blame] | 726 | } else if (!mCalls.contains(call)) { |
| 727 | // We check if mCalls already contains the call because we could potentially be reusing |
| 728 | // a call which was previously added (See {@link #getNewOutgoingCall}). |
Tyler Gunn | 5b452df | 2014-10-01 15:02:58 -0700 | [diff] [blame] | 729 | addCall(call); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 730 | } |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 731 | |
| 732 | return call; |
| 733 | } |
| 734 | |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 735 | /** |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 736 | * Attempts to issue/connect the specified call. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 737 | * |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 738 | * @param handle Handle to connect the call with. |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 739 | * @param gatewayInfo Optional gateway information that can be used to route the call to the |
Nancy Chen | 53ceedc | 2014-07-08 18:56:51 -0700 | [diff] [blame] | 740 | * actual dialed handle via a gateway provider. May be null. |
Sai Cheemalapati | b7157e9 | 2014-06-11 17:51:55 -0700 | [diff] [blame] | 741 | * @param speakerphoneOn Whether or not to turn the speakerphone on once the call connects. |
Tyler Gunn | c4abd91 | 2014-07-08 14:22:10 -0700 | [diff] [blame] | 742 | * @param videoState The desired video state for the outgoing call. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 743 | */ |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 744 | void placeOutgoingCall(Call call, Uri handle, GatewayInfo gatewayInfo, boolean speakerphoneOn, |
| 745 | int videoState) { |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 746 | if (call == null) { |
| 747 | // don't do anything if the call no longer exists |
| 748 | Log.i(this, "Canceling unknown call."); |
Santos Cordon | b7af09e | 2014-08-06 04:30:01 -0700 | [diff] [blame] | 749 | return; |
| 750 | } |
| 751 | |
Nancy Chen | 201b437 | 2014-09-08 14:18:24 -0700 | [diff] [blame] | 752 | final Uri uriHandle = (gatewayInfo == null) ? handle : gatewayInfo.getGatewayAddress(); |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 753 | |
| 754 | if (gatewayInfo == null) { |
Santos Cordon | b58f453 | 2014-05-29 11:59:06 -0700 | [diff] [blame] | 755 | Log.i(this, "Creating a new outgoing call with handle: %s", Log.piiHandle(uriHandle)); |
Yorke Lee | 3350163 | 2014-03-17 19:24:12 -0700 | [diff] [blame] | 756 | } else { |
| 757 | Log.i(this, "Creating a new outgoing call with gateway handle: %s, original handle: %s", |
| 758 | Log.pii(uriHandle), Log.pii(handle)); |
| 759 | } |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 760 | |
Nancy Chen | 0d3076c | 2014-07-30 14:45:44 -0700 | [diff] [blame] | 761 | call.setHandle(uriHandle); |
| 762 | call.setGatewayInfo(gatewayInfo); |
Tyler Gunn | d373c20 | 2015-05-20 08:21:03 -0700 | [diff] [blame] | 763 | // Auto-enable speakerphone if the originating intent specified to do so, or if the call |
Nivedita Sarkar | dae2c65 | 2015-08-31 10:55:51 -0700 | [diff] [blame] | 764 | // is a video call or if the phone is docked. |
| 765 | call.setStartWithSpeakerphoneOn(speakerphoneOn || isSpeakerphoneAutoEnabled(videoState) |
| 766 | || mDockManager.isDocked()); |
Tyler Gunn | c4abd91 | 2014-07-08 14:22:10 -0700 | [diff] [blame] | 767 | call.setVideoState(videoState); |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 768 | |
Tyler Gunn | 6ffe531 | 2015-08-12 08:19:20 -0700 | [diff] [blame] | 769 | if (call.isEmergencyCall()) { |
Ihab Awad | 69eb0f5 | 2014-07-18 11:20:37 -0700 | [diff] [blame] | 770 | // Emergency -- CreateConnectionProcessor will choose accounts automatically |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 771 | call.setTargetPhoneAccount(null); |
Nancy Chen | 53ceedc | 2014-07-08 18:56:51 -0700 | [diff] [blame] | 772 | } |
Nancy Chen | d9de92c | 2014-07-21 16:09:13 -0700 | [diff] [blame] | 773 | |
Tyler Gunn | 6ffe531 | 2015-08-12 08:19:20 -0700 | [diff] [blame] | 774 | if (call.getTargetPhoneAccount() != null || call.isEmergencyCall()) { |
David Ng | ca0c678 | 2015-11-30 17:00:46 -0800 | [diff] [blame] | 775 | if (!call.isEmergencyCall()) { |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 776 | updateLchStatus(call.getTargetPhoneAccount().getId()); |
| 777 | } |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 778 | // If the account has been set, proceed to place the outgoing call. |
| 779 | // Otherwise the connection will be initiated when the account is set by the user. |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 780 | call.startCreateConnection(mPhoneAccountRegistrar); |
Nancy Chen | d9de92c | 2014-07-21 16:09:13 -0700 | [diff] [blame] | 781 | } |
Yorke Lee | f98fb57 | 2014-03-05 10:56:55 -0800 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | /** |
Suchand Ghosh | 97f3cb1 | 2014-09-22 12:13:47 +0530 | [diff] [blame] | 785 | * Attempts to add participant in a call. |
| 786 | * |
| 787 | * @param number number to connect the call with. |
| 788 | */ |
| 789 | private void addParticipant(String number) { |
| 790 | Log.i(this, "addParticipant number ="+number); |
| 791 | if (getForegroundCall() == null) { |
| 792 | // don't do anything if the call no longer exists |
| 793 | Log.i(this, "Canceling unknown call."); |
| 794 | return; |
| 795 | } else { |
| 796 | getForegroundCall().addParticipantWithConference(number); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | |
| 801 | /** |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 802 | * Attempts to start a conference call for the specified call. |
| 803 | * |
Santos Cordon | 12d6182 | 2014-07-29 16:02:20 -0700 | [diff] [blame] | 804 | * @param call The call to conference. |
| 805 | * @param otherCall The other call to conference with. |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 806 | */ |
Santos Cordon | 12d6182 | 2014-07-29 16:02:20 -0700 | [diff] [blame] | 807 | void conference(Call call, Call otherCall) { |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 808 | call.conferenceWith(otherCall); |
Santos Cordon | a161070 | 2014-06-04 20:22:56 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 812 | * Instructs Telecom to answer the specified call. Intended to be invoked by the in-call |
| 813 | * app through {@link InCallAdapter} after Telecom notifies it of an incoming call followed by |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 814 | * the user opting to answer said call. |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 815 | * |
| 816 | * @param call The call to answer. |
| 817 | * @param videoState The video state in which to answer the call. |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 818 | */ |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 819 | void answerCall(Call call, int videoState) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 820 | if (!mCalls.contains(call)) { |
| 821 | Log.i(this, "Request to answer a non-existent call %s", call); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 822 | } else { |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 823 | Call activeCall = getFirstCallWithState(call.getTargetPhoneAccount() |
| 824 | .getId(), CallState.ACTIVE, CallState.DIALING); |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 825 | // If the foreground call is not the ringing call and it is currently isActive() or |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 826 | // STATE_DIALING, put it on hold before answering the call. |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 827 | if (activeCall != null && activeCall != call && |
| 828 | (activeCall.isActive() || |
| 829 | activeCall.getState() == CallState.DIALING)) { |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 830 | if (0 == (mForegroundCall.getConnectionCapabilities() |
| 831 | & Connection.CAPABILITY_HOLD)) { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 832 | // This call does not support hold. If it is from a different connection |
| 833 | // service, then disconnect it, otherwise allow the connection service to |
| 834 | // figure out the right states. |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 835 | if (activeCall.getConnectionService() != call.getConnectionService()) { |
| 836 | activeCall.disconnect(); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 837 | } |
| 838 | } else { |
Andrew Lee | e94a8f1 | 2014-12-19 16:19:51 -0800 | [diff] [blame] | 839 | Call heldCall = getHeldCall(); |
| 840 | if (heldCall != null) { |
| 841 | Log.v(this, "Disconnecting held call %s before holding active call.", |
| 842 | heldCall); |
| 843 | heldCall.disconnect(); |
| 844 | } |
| 845 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 846 | Log.v(this, "Holding active/dialing call %s before answering incoming call %s.", |
| 847 | mForegroundCall, call); |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 848 | activeCall.hold(); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 849 | } |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 850 | // TODO: Wait until we get confirmation of the active call being |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 851 | // on-hold before answering the new call. |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 852 | // TODO: Import logic from CallManager.acceptCall() |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 855 | for (CallsManagerListener listener : mListeners) { |
| 856 | listener.onIncomingCallAnswered(call); |
| 857 | } |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 858 | updateLchStatus(call.getTargetPhoneAccount().getId()); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 859 | // We do not update the UI until we get confirmation of the answer() through |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 860 | // {@link #markCallAsActive}. |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 861 | call.answer(videoState); |
Tyler Gunn | d373c20 | 2015-05-20 08:21:03 -0700 | [diff] [blame] | 862 | if (isSpeakerphoneAutoEnabled(videoState)) { |
Rekha Kumar | d240fe8 | 2015-04-01 21:45:57 -0700 | [diff] [blame] | 863 | call.setStartWithSpeakerphoneOn(true); |
| 864 | } |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 865 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 866 | } |
| 867 | |
Tyler Gunn | d373c20 | 2015-05-20 08:21:03 -0700 | [diff] [blame] | 868 | /** |
| 869 | * Determines if the speakerphone should be automatically enabled for the call. Speakerphone |
| 870 | * should be enabled if the call is a video call and bluetooth or the wired headset are not in |
| 871 | * use. |
| 872 | * |
| 873 | * @param videoState The video state of the call. |
| 874 | * @return {@code true} if the speakerphone should be enabled. |
| 875 | */ |
| 876 | private boolean isSpeakerphoneAutoEnabled(int videoState) { |
Etan Cohen | 7bcbb34 | 2015-06-25 15:39:21 -0700 | [diff] [blame] | 877 | return VideoProfile.isVideo(videoState) && |
Tyler Gunn | d373c20 | 2015-05-20 08:21:03 -0700 | [diff] [blame] | 878 | !mWiredHeadsetManager.isPluggedIn() && |
| 879 | !mCallAudioManager.isBluetoothDeviceAvailable() && |
| 880 | isSpeakerEnabledForVideoCalls(); |
| 881 | } |
| 882 | |
| 883 | /** |
| 884 | * Determines if the speakerphone should be automatically enabled for video calls. |
| 885 | * |
| 886 | * @return {@code true} if the speakerphone should automatically be enabled. |
| 887 | */ |
Rekha Kumar | d240fe8 | 2015-04-01 21:45:57 -0700 | [diff] [blame] | 888 | private static boolean isSpeakerEnabledForVideoCalls() { |
| 889 | return (SystemProperties.getInt(TelephonyProperties.PROPERTY_VIDEOCALL_AUDIO_OUTPUT, |
| 890 | PhoneConstants.AUDIO_OUTPUT_DEFAULT) == |
| 891 | PhoneConstants.AUDIO_OUTPUT_ENABLE_SPEAKER); |
| 892 | } |
| 893 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 894 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 895 | * Instructs Telecom to reject the specified call. Intended to be invoked by the in-call |
| 896 | * app through {@link InCallAdapter} after Telecom notifies it of an incoming call followed by |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 897 | * the user opting to reject said call. |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 898 | */ |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 899 | void rejectCall(Call call, boolean rejectWithMessage, String textMessage) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 900 | if (!mCalls.contains(call)) { |
| 901 | Log.i(this, "Request to reject a non-existent call %s", call); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 902 | } else { |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 903 | for (CallsManagerListener listener : mListeners) { |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 904 | listener.onIncomingCallRejected(call, rejectWithMessage, textMessage); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 905 | } |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 906 | setActiveSubscription(getConversationSub()); |
Ihab Awad | ff7493a | 2014-06-10 13:47:44 -0700 | [diff] [blame] | 907 | call.reject(rejectWithMessage, textMessage); |
Santos Cordon | 61d0f70 | 2014-02-19 02:52:23 -0800 | [diff] [blame] | 908 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 912 | * Instructs Telecom to play the specified DTMF tone within the specified call. |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 913 | * |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 914 | * @param digit The DTMF digit to play. |
| 915 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 916 | void playDtmfTone(Call call, char digit) { |
| 917 | if (!mCalls.contains(call)) { |
| 918 | Log.i(this, "Request to play DTMF in a non-existent call %s", call); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 919 | } else { |
| 920 | call.playDtmfTone(digit); |
Santos Cordon | 92a2d81 | 2014-04-30 15:19:01 -0700 | [diff] [blame] | 921 | mDtmfLocalTonePlayer.playTone(call, digit); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 922 | } |
| 923 | } |
| 924 | |
| 925 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 926 | * Instructs Telecom to stop the currently playing DTMF tone, if any. |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 927 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 928 | void stopDtmfTone(Call call) { |
| 929 | if (!mCalls.contains(call)) { |
| 930 | Log.i(this, "Request to stop DTMF in a non-existent call %s", call); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 931 | } else { |
| 932 | call.stopDtmfTone(); |
Santos Cordon | 92a2d81 | 2014-04-30 15:19:01 -0700 | [diff] [blame] | 933 | mDtmfLocalTonePlayer.stopTone(call); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | |
| 937 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 938 | * Instructs Telecom to continue (or not) the current post-dial DTMF string, if any. |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 939 | */ |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 940 | void postDialContinue(Call call, boolean proceed) { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 941 | if (!mCalls.contains(call)) { |
| 942 | Log.i(this, "Request to continue post-dial string in a non-existent call %s", call); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 943 | } else { |
Evan Charlton | 352105c | 2014-06-03 14:10:54 -0700 | [diff] [blame] | 944 | call.postDialContinue(proceed); |
Ihab Awad | 74549ec | 2014-03-10 15:33:25 -0700 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | |
| 948 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 949 | * Instructs Telecom to disconnect the specified call. Intended to be invoked by the |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 950 | * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by |
| 951 | * the user hitting the end-call button. |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 952 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 953 | void disconnectCall(Call call) { |
Santos Cordon | 682fe6b | 2014-05-20 08:56:39 -0700 | [diff] [blame] | 954 | Log.v(this, "disconnectCall %s", call); |
| 955 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 956 | if (!mCalls.contains(call)) { |
| 957 | Log.w(this, "Unknown call (%s) asked to disconnect", call); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 958 | } else { |
Ihab Awad | 5b28132 | 2014-09-25 18:25:29 -0700 | [diff] [blame] | 959 | mLocallyDisconnectingCalls.add(call); |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 960 | call.disconnect(); |
| 961 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 962 | } |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 963 | |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 964 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 965 | * Instructs Telecom to disconnect all calls. |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 966 | */ |
| 967 | void disconnectAllCalls() { |
| 968 | Log.v(this, "disconnectAllCalls"); |
| 969 | |
| 970 | for (Call call : mCalls) { |
| 971 | disconnectCall(call); |
| 972 | } |
| 973 | } |
| 974 | |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 975 | |
Tyler Gunn | 61b9210 | 2014-08-19 07:42:20 -0700 | [diff] [blame] | 976 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 977 | * Instructs Telecom to put the specified call on hold. Intended to be invoked by the |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 978 | * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by |
| 979 | * the user hitting the hold button during an active call. |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 980 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 981 | void holdCall(Call call) { |
| 982 | if (!mCalls.contains(call)) { |
| 983 | Log.w(this, "Unknown call (%s) asked to be put on hold", call); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 984 | } else { |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 985 | Log.d(this, "Putting call on hold: (%s)", call); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 986 | call.hold(); |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | /** |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 991 | * Instructs Telecom to release the specified call from hold. Intended to be invoked by |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 992 | * the in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered |
| 993 | * by the user hitting the hold button during a held call. |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 994 | */ |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 995 | void unholdCall(Call call) { |
| 996 | if (!mCalls.contains(call)) { |
| 997 | Log.w(this, "Unknown call (%s) asked to be removed from hold", call); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 998 | } else { |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 999 | Log.d(this, "unholding call: (%s)", call); |
Sai Cheemalapati | 45b3e3f | 2014-08-15 09:33:00 -0700 | [diff] [blame] | 1000 | for (Call c : mCalls) { |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1001 | PhoneAccountHandle ph = call.getTargetPhoneAccount(); |
| 1002 | PhoneAccountHandle ph1 = c.getTargetPhoneAccount(); |
Tyler Gunn | e44adb4 | 2015-01-02 10:55:35 -0800 | [diff] [blame] | 1003 | // Only attempt to hold parent calls and not the individual children. |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1004 | // if 'c' is not for same subscription as call, then don't disturb 'c' |
| 1005 | if (c != null && c.isAlive() && c != call && c.getParentCall() == null |
| 1006 | && (ph != null && ph1 != null && |
| 1007 | isSamePhAccIdOrSipId(ph.getId(), ph1.getId()))) { |
Sai Cheemalapati | 45b3e3f | 2014-08-15 09:33:00 -0700 | [diff] [blame] | 1008 | c.hold(); |
| 1009 | } |
| 1010 | } |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 1011 | call.unhold(); |
| 1012 | } |
| 1013 | } |
| 1014 | |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1015 | /** |
| 1016 | * Returns true if the ids are same or one of the ids is sip id. |
| 1017 | */ |
| 1018 | private boolean isSamePhAccIdOrSipId(String id1, String id2) { |
| 1019 | boolean ret = ((id1 != null && id2 != null) && |
| 1020 | (id1.equals(id2) || id1.contains("sip") || id2.contains("sip"))); |
| 1021 | Log.d(this, "isSamePhAccIdOrSipId: id1 = " + id1 + " id2 = " + id2 + " ret = " + ret); |
| 1022 | return ret; |
| 1023 | } |
| 1024 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 1025 | /** Called by the in-call UI to change the mute state. */ |
| 1026 | void mute(boolean shouldMute) { |
| 1027 | mCallAudioManager.mute(shouldMute); |
| 1028 | } |
| 1029 | |
| 1030 | /** |
| 1031 | * Called by the in-call UI to change the audio route, for example to change from earpiece to |
| 1032 | * speaker phone. |
| 1033 | */ |
| 1034 | void setAudioRoute(int route) { |
| 1035 | mCallAudioManager.setAudioRoute(route); |
| 1036 | } |
| 1037 | |
Yorke Lee | d134687 | 2014-07-28 14:38:45 -0700 | [diff] [blame] | 1038 | /** Called by the in-call UI to turn the proximity sensor on. */ |
| 1039 | void turnOnProximitySensor() { |
| 1040 | mProximitySensorManager.turnOn(); |
| 1041 | } |
| 1042 | |
| 1043 | /** |
| 1044 | * Called by the in-call UI to turn the proximity sensor off. |
| 1045 | * @param screenOnImmediately If true, the screen will be turned on immediately. Otherwise, |
| 1046 | * the screen will be kept off until the proximity sensor goes negative. |
| 1047 | */ |
| 1048 | void turnOffProximitySensor(boolean screenOnImmediately) { |
| 1049 | mProximitySensorManager.turnOff(screenOnImmediately); |
| 1050 | } |
| 1051 | |
Nancy Chen | f5e5d3c | 2014-10-21 18:45:56 -0700 | [diff] [blame] | 1052 | void phoneAccountSelected(Call call, PhoneAccountHandle account, boolean setDefault) { |
Nancy Chen | 53ceedc | 2014-07-08 18:56:51 -0700 | [diff] [blame] | 1053 | if (!mCalls.contains(call)) { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1054 | Log.i(this, "Attempted to add account to unknown call %s", call); |
Nancy Chen | 53ceedc | 2014-07-08 18:56:51 -0700 | [diff] [blame] | 1055 | } else { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1056 | // TODO: There is an odd race condition here. Since NewOutgoingCallIntentBroadcaster and |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 1057 | // the SELECT_PHONE_ACCOUNT sequence run in parallel, if the user selects an account before the |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1058 | // NEW_OUTGOING_CALL sequence finishes, we'll start the call immediately without |
| 1059 | // respecting a rewritten number or a canceled number. This is unlikely since |
| 1060 | // NEW_OUTGOING_CALL sequence, in practice, runs a lot faster than the user selecting |
| 1061 | // a phone account from the in-call UI. |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1062 | Log.i(this, "phoneAccountSelected , id = %s", account.getId()); |
| 1063 | updateLchStatus(account.getId()); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1064 | call.setTargetPhoneAccount(account); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1065 | |
| 1066 | // Note: emergency calls never go through account selection dialog so they never |
| 1067 | // arrive here. |
| 1068 | if (makeRoomForOutgoingCall(call, false /* isEmergencyCall */)) { |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1069 | call.startCreateConnection(mPhoneAccountRegistrar); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1070 | } else { |
| 1071 | call.disconnect(); |
| 1072 | } |
Nancy Chen | f5e5d3c | 2014-10-21 18:45:56 -0700 | [diff] [blame] | 1073 | |
| 1074 | if (setDefault) { |
| 1075 | mPhoneAccountRegistrar.setUserSelectedOutgoingPhoneAccount(account); |
| 1076 | } |
Nancy Chen | 53ceedc | 2014-07-08 18:56:51 -0700 | [diff] [blame] | 1077 | } |
| 1078 | } |
| 1079 | |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 1080 | /** Called when the audio state changes. */ |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 1081 | void onCallAudioStateChanged(CallAudioState oldAudioState, CallAudioState newAudioState) { |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 1082 | Log.v(this, "onAudioStateChanged, audioState: %s -> %s", oldAudioState, newAudioState); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1083 | for (CallsManagerListener listener : mListeners) { |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 1084 | listener.onCallAudioStateChanged(oldAudioState, newAudioState); |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1085 | } |
Sailesh Nepal | 6aca10a | 2014-03-24 16:11:02 -0700 | [diff] [blame] | 1086 | } |
| 1087 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1088 | void markCallAsRinging(Call call) { |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 1089 | setCallState(call, CallState.RINGING, "ringing set explicitly"); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1092 | void markCallAsDialing(Call call) { |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 1093 | setCallState(call, CallState.DIALING, "dialing set explicitly"); |
Nivedita Sarkar | dae2c65 | 2015-08-31 10:55:51 -0700 | [diff] [blame] | 1094 | maybeMoveToEarpiece(call); |
Santos Cordon | d6782cd | 2015-04-16 09:57:50 -0700 | [diff] [blame] | 1095 | maybeMoveToSpeakerPhone(call); |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1096 | setActiveSubscription(call.getTargetPhoneAccount().getId()); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 1097 | } |
| 1098 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1099 | void markCallAsActive(Call call) { |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 1100 | setCallState(call, CallState.ACTIVE, "active set explicitly"); |
Santos Cordon | d6782cd | 2015-04-16 09:57:50 -0700 | [diff] [blame] | 1101 | maybeMoveToSpeakerPhone(call); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1104 | void markCallAsOnHold(Call call) { |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 1105 | setCallState(call, CallState.ON_HOLD, "on-hold set explicitly"); |
Yorke Lee | cdf3ebd | 2014-03-12 18:31:41 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 1108 | /** |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1109 | * Marks the specified call as STATE_DISCONNECTED and notifies the in-call app. If this was the |
| 1110 | * last live call, then also disconnect from the in-call controller. |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 1111 | * |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 1112 | * @param disconnectCause The disconnect cause, see {@link android.telecom.DisconnectCause}. |
Santos Cordon | 049b7b6 | 2014-01-30 05:34:26 -0800 | [diff] [blame] | 1113 | */ |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1114 | void markCallAsDisconnected(Call call, DisconnectCause disconnectCause) { |
Suresh Koleti | ef56431 | 2015-08-24 19:31:55 +0530 | [diff] [blame] | 1115 | // Show MT call in call log as a missed call if immediately disconnected |
| 1116 | // before creating a connection. |
| 1117 | if (!mCalls.contains(call) && (DisconnectCause.MISSED == disconnectCause.getCode())) { |
| 1118 | addCall(call); |
| 1119 | mMissedCallNotifier.showMissedCallNotification(call); |
| 1120 | } |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1121 | call.setDisconnectCause(disconnectCause); |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1122 | int prevState = call.getState(); |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 1123 | setCallState(call, CallState.DISCONNECTED, "disconnected set explicitly"); |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1124 | String activeSub = getActiveSubscription(); |
| 1125 | String conversationSub = getConversationSub(); |
| 1126 | String lchSub = IsAnySubInLch(); |
| 1127 | |
| 1128 | PhoneAccount phAcc = |
| 1129 | getPhoneAccountRegistrar().getPhoneAccount(call.getTargetPhoneAccount()); |
| 1130 | if (activeSub != null && (call.getTargetPhoneAccount() != null && |
| 1131 | call.getTargetPhoneAccount().getId().equals(activeSub)) && |
| 1132 | (phAcc != null) && (phAcc.isSet(PhoneAccount.LCH)) && |
| 1133 | (conversationSub != null) && |
| 1134 | (!conversationSub.equals(activeSub))) { |
| 1135 | Log.d(this,"Set active sub to conversation sub"); |
| 1136 | setActiveSubscription(conversationSub); |
| 1137 | } else if ((conversationSub == null) && (lchSub != null) && |
| 1138 | ((prevState == CallState.CONNECTING) || (prevState == |
| 1139 | CallState.SELECT_PHONE_ACCOUNT)) && |
| 1140 | (call.getState() == CallState.DISCONNECTED)) { |
| 1141 | Log.d(this,"remove sub with call from LCH"); |
| 1142 | updateLchStatus(lchSub); |
| 1143 | setActiveSubscription(lchSub); |
| 1144 | manageDsdaInCallTones(false); |
| 1145 | } |
| 1146 | |
| 1147 | if ((call.getTargetPhoneAccount() != null) && (phAcc != null) && |
| 1148 | (phAcc.isSet(PhoneAccount.LCH))) { |
| 1149 | Call activecall = getFirstCallWithState(call.getTargetPhoneAccount().getId(), |
| 1150 | CallState.RINGING, CallState.DIALING, CallState.ACTIVE, CallState.ON_HOLD); |
| 1151 | Log.d(this,"activecall: " + activecall); |
| 1152 | if (activecall == null) { |
| 1153 | phAcc.unSetBit(PhoneAccount.LCH); |
| 1154 | manageDsdaInCallTones(false); |
| 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | private String IsAnySubInLch() { |
| 1160 | for (PhoneAccountHandle ph : getPhoneAccountRegistrar().getSimPhoneAccounts()) { |
| 1161 | PhoneAccount phAcc = getPhoneAccountRegistrar().getPhoneAccount(ph); |
| 1162 | if ((phAcc != null) && (phAcc.isSet(PhoneAccount.LCH))) { |
| 1163 | Log.d(this, "Sub in LCH: " + ph.getId()); |
| 1164 | return ph.getId(); |
| 1165 | } |
| 1166 | } |
| 1167 | return null; |
Sailesh Nepal | 6ab6fb7 | 2014-04-01 20:03:19 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 1170 | /** |
Ihab Awad | a02bef5 | 2014-08-13 18:18:42 -0700 | [diff] [blame] | 1171 | * Removes an existing disconnected call, and notifies the in-call app. |
| 1172 | */ |
| 1173 | void markCallAsRemoved(Call call) { |
| 1174 | removeCall(call); |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1175 | if (!hasAnyCalls()) { |
| 1176 | updateLchStatus(null); |
| 1177 | setActiveSubscription(null); |
| 1178 | manageDsdaInCallTones(false); |
| 1179 | } |
Ihab Awad | 5b28132 | 2014-09-25 18:25:29 -0700 | [diff] [blame] | 1180 | if (mLocallyDisconnectingCalls.contains(call)) { |
| 1181 | mLocallyDisconnectingCalls.remove(call); |
| 1182 | if (mForegroundCall != null && mForegroundCall.getState() == CallState.ON_HOLD) { |
| 1183 | mForegroundCall.unhold(); |
| 1184 | } |
| 1185 | } |
Ihab Awad | a02bef5 | 2014-08-13 18:18:42 -0700 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | /** |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1189 | * Cleans up any calls currently associated with the specified connection service when the |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 1190 | * service binder disconnects unexpectedly. |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 1191 | * |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1192 | * @param service The connection service that disconnected. |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 1193 | */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1194 | void handleConnectionServiceDeath(ConnectionServiceWrapper service) { |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 1195 | if (service != null) { |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 1196 | for (Call call : mCalls) { |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 1197 | if (call.getConnectionService() == service) { |
Yorke Lee | 2af16b6 | 2014-11-11 17:36:57 -0800 | [diff] [blame] | 1198 | if (call.getState() != CallState.DISCONNECTED) { |
| 1199 | markCallAsDisconnected(call, new DisconnectCause(DisconnectCause.ERROR)); |
| 1200 | } |
| 1201 | markCallAsRemoved(call); |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 1202 | } |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 1203 | } |
| 1204 | } |
| 1205 | } |
| 1206 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1207 | boolean hasAnyCalls() { |
| 1208 | return !mCalls.isEmpty(); |
| 1209 | } |
| 1210 | |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 1211 | boolean hasActiveOrHoldingCall() { |
Santos Cordon | 23baed3 | 2014-06-27 14:45:39 -0700 | [diff] [blame] | 1212 | return getFirstCallWithState(CallState.ACTIVE, CallState.ON_HOLD) != null; |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 1213 | } |
| 1214 | |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1215 | boolean hasActiveOrHoldingCall(String sub) { |
| 1216 | return (getFirstCallWithState(sub, CallState.ACTIVE, CallState.ON_HOLD) != null); |
| 1217 | } |
| 1218 | |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 1219 | boolean hasRingingCall() { |
Santos Cordon | 23baed3 | 2014-06-27 14:45:39 -0700 | [diff] [blame] | 1220 | return getFirstCallWithState(CallState.RINGING) != null; |
Santos Cordon | c7e85d4 | 2014-05-22 02:51:48 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1223 | boolean onMediaButton(int type) { |
| 1224 | if (hasAnyCalls()) { |
| 1225 | if (HeadsetMediaButton.SHORT_PRESS == type) { |
| 1226 | Call ringingCall = getFirstCallWithState(CallState.RINGING); |
| 1227 | if (ringingCall == null) { |
| 1228 | mCallAudioManager.toggleMute(); |
| 1229 | return true; |
| 1230 | } else { |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 1231 | ringingCall.answer(ringingCall.getVideoState()); |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1232 | return true; |
| 1233 | } |
| 1234 | } else if (HeadsetMediaButton.LONG_PRESS == type) { |
| 1235 | Log.d(this, "handleHeadsetHook: longpress -> hangup"); |
| 1236 | Call callToHangup = getFirstCallWithState( |
| 1237 | CallState.RINGING, CallState.DIALING, CallState.ACTIVE, CallState.ON_HOLD); |
| 1238 | if (callToHangup != null) { |
| 1239 | callToHangup.disconnect(); |
| 1240 | return true; |
| 1241 | } |
| 1242 | } |
| 1243 | } |
| 1244 | return false; |
| 1245 | } |
| 1246 | |
| 1247 | /** |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1248 | * Returns true if telecom supports adding another top-level call. |
Santos Cordon | 10838c2 | 2014-06-11 17:36:04 -0700 | [diff] [blame] | 1249 | */ |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1250 | boolean canAddCall() { |
Andrew Lee | 113ad62 | 2014-12-01 18:33:10 -0800 | [diff] [blame] | 1251 | if (getFirstCallWithState(OUTGOING_CALL_STATES) != null) { |
| 1252 | return false; |
| 1253 | } |
| 1254 | |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1255 | int count = 0; |
| 1256 | for (Call call : mCalls) { |
| 1257 | if (call.isEmergencyCall()) { |
| 1258 | // We never support add call if one of the calls is an emergency call. |
| 1259 | return false; |
Roshan Pius | d954409 | 2015-07-31 11:31:52 -0700 | [diff] [blame] | 1260 | } else if (!call.getChildCalls().isEmpty() && !call.can(Connection.CAPABILITY_HOLD)) { |
| 1261 | // This is to deal with CDMA conference calls. CDMA conference calls do not |
| 1262 | // allow the addition of another call when it is already in a 3 way conference. |
| 1263 | // So, we detect that it is a CDMA conference call by checking if the call has |
| 1264 | // some children and it does not support the CAPABILILTY_HOLD |
| 1265 | // TODO: This maybe cleaner if the lower layers can explicitly signal to telecom |
| 1266 | // about this limitation (b/22880180). |
| 1267 | return false; |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1268 | } else if (call.getParentCall() == null) { |
| 1269 | count++; |
| 1270 | } |
Santos Cordon | 10838c2 | 2014-06-11 17:36:04 -0700 | [diff] [blame] | 1271 | |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1272 | // We do not check states for canAddCall. We treat disconnected calls the same |
| 1273 | // and wait until they are removed instead. If we didn't count disconnected calls, |
| 1274 | // we could put InCallServices into a state where they are showing two calls but |
| 1275 | // also support add-call. Technically it's right, but overall looks better (UI-wise) |
| 1276 | // and acts better if we wait until the call is removed. |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1277 | if (TelephonyManager.getDefault().getMultiSimConfiguration() |
| 1278 | == TelephonyManager.MultiSimVariants.DSDA) { |
| 1279 | if (count >= MAXIMUM_DSDA_TOP_LEVEL_CALLS) { |
| 1280 | return false; |
| 1281 | } |
| 1282 | } else if (count >= MAXIMUM_TOP_LEVEL_CALLS) { |
Santos Cordon | 10838c2 | 2014-06-11 17:36:04 -0700 | [diff] [blame] | 1283 | return false; |
| 1284 | } |
| 1285 | } |
| 1286 | return true; |
| 1287 | } |
| 1288 | |
Ihab Awad | a365390 | 2015-01-23 13:44:46 -0800 | [diff] [blame] | 1289 | @VisibleForTesting |
P.Y. Laligand | d35be75 | 2015-03-06 14:12:43 -0800 | [diff] [blame] | 1290 | public Call getRingingCall() { |
Santos Cordon | 68d1a6b | 2014-09-19 12:25:58 -0700 | [diff] [blame] | 1291 | return getFirstCallWithState(CallState.RINGING); |
| 1292 | } |
| 1293 | |
| 1294 | Call getActiveCall() { |
| 1295 | return getFirstCallWithState(CallState.ACTIVE); |
| 1296 | } |
| 1297 | |
Nancy Chen | 05a9e40 | 2014-09-26 14:14:32 -0700 | [diff] [blame] | 1298 | Call getDialingCall() { |
| 1299 | return getFirstCallWithState(CallState.DIALING); |
Santos Cordon | 68d1a6b | 2014-09-19 12:25:58 -0700 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | Call getHeldCall() { |
| 1303 | return getFirstCallWithState(CallState.ON_HOLD); |
| 1304 | } |
| 1305 | |
Santos Cordon | c0ca76e | 2014-10-21 15:54:19 -0700 | [diff] [blame] | 1306 | int getNumHeldCalls() { |
| 1307 | int count = 0; |
| 1308 | for (Call call : mCalls) { |
| 1309 | if (call.getParentCall() == null && call.getState() == CallState.ON_HOLD) { |
| 1310 | count++; |
| 1311 | } |
| 1312 | } |
| 1313 | return count; |
| 1314 | } |
| 1315 | |
Shriram Ganesh | d7dd727 | 2015-12-11 15:52:15 -0800 | [diff] [blame^] | 1316 | int getNumTopLevelCalls() { |
| 1317 | int count = 0; |
| 1318 | for (Call call : mCalls) { |
| 1319 | if (call.getParentCall() == null) { |
| 1320 | count++; |
| 1321 | } |
| 1322 | } |
| 1323 | return count; |
| 1324 | } |
| 1325 | |
Roshan Pius | 93c9c01 | 2015-08-28 11:10:56 -0700 | [diff] [blame] | 1326 | Call getOutgoingCall() { |
| 1327 | return getFirstCallWithState(OUTGOING_CALL_STATES); |
| 1328 | } |
| 1329 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1330 | Call getFirstCallWithState(int... states) { |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1331 | return getFirstCallWithState((Call) null, states); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Santos Cordon | 10838c2 | 2014-06-11 17:36:04 -0700 | [diff] [blame] | 1334 | /** |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1335 | * Returns the first call that it finds with the given states. The states are treated as having |
| 1336 | * priority order so that any call with the first state will be returned before any call with |
| 1337 | * states listed later in the parameter list. |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1338 | * |
| 1339 | * @param callToSkip Call that this method should skip while searching |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1340 | */ |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1341 | Call getFirstCallWithState(Call callToSkip, int... states) { |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 1342 | for (int currentState : states) { |
Santos Cordon | 23baed3 | 2014-06-27 14:45:39 -0700 | [diff] [blame] | 1343 | // check the foreground first |
| 1344 | if (mForegroundCall != null && mForegroundCall.getState() == currentState) { |
| 1345 | return mForegroundCall; |
| 1346 | } |
| 1347 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1348 | for (Call call : mCalls) { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1349 | if (Objects.equals(callToSkip, call)) { |
| 1350 | continue; |
| 1351 | } |
| 1352 | |
| 1353 | // Only operate on top-level calls |
| 1354 | if (call.getParentCall() != null) { |
| 1355 | continue; |
| 1356 | } |
| 1357 | |
Santos Cordon | deb8c89 | 2014-05-30 01:38:03 -0700 | [diff] [blame] | 1358 | if (currentState == call.getState()) { |
| 1359 | return call; |
| 1360 | } |
| 1361 | } |
| 1362 | } |
| 1363 | return null; |
| 1364 | } |
| 1365 | |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1366 | /** |
| 1367 | * Returns the first call that it finds with the given states for given subscription. |
| 1368 | * the states are treated as having priority order so that any call with the first |
| 1369 | * state will be returned before any call with states listed later in the parameter list. |
| 1370 | * |
| 1371 | * @param subId check calls only on this subscription |
| 1372 | * @param callToSkip Call that this method should skip while searching |
| 1373 | */ |
| 1374 | Call getFirstCallWithState(String subId, Call callToSkip, int... states) { |
| 1375 | for (int currentState : states) { |
| 1376 | // check the foreground first |
| 1377 | if (mForegroundCall != null && mForegroundCall.getState() == currentState |
| 1378 | && mForegroundCall.getTargetPhoneAccount() != null |
| 1379 | && isSamePhAccIdOrSipId(mForegroundCall.getTargetPhoneAccount().getId(), subId)) { |
| 1380 | return mForegroundCall; |
| 1381 | } |
| 1382 | |
| 1383 | for (Call call : mCalls) { |
| 1384 | if (Objects.equals(callToSkip, call)) { |
| 1385 | continue; |
| 1386 | } |
| 1387 | |
| 1388 | // Only operate on top-level calls |
| 1389 | if (call.getParentCall() != null) { |
| 1390 | continue; |
| 1391 | } |
| 1392 | |
| 1393 | if (currentState == call.getState() && call.getTargetPhoneAccount() != null |
| 1394 | && isSamePhAccIdOrSipId(call.getTargetPhoneAccount().getId(), subId)) { |
| 1395 | return call; |
| 1396 | } |
| 1397 | } |
| 1398 | } |
| 1399 | return null; |
| 1400 | } |
| 1401 | |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1402 | Call createConferenceCall( |
| 1403 | PhoneAccountHandle phoneAccount, |
| 1404 | ParcelableConference parcelableConference) { |
Tyler Gunn | d92e737 | 2015-01-09 15:59:45 -0800 | [diff] [blame] | 1405 | |
| 1406 | // If the parceled conference specifies a connect time, use it; otherwise default to 0, |
| 1407 | // which is the default value for new Calls. |
| 1408 | long connectTime = |
| 1409 | parcelableConference.getConnectTimeMillis() == |
| 1410 | Conference.CONNECT_TIME_NOT_SPECIFIED ? 0 : |
| 1411 | parcelableConference.getConnectTimeMillis(); |
| 1412 | |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1413 | Call call = new Call( |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1414 | mContext, |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 1415 | this, |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 1416 | mLock, |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1417 | mConnectionServiceRepository, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1418 | mContactsAsyncHelper, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 1419 | mCallerInfoAsyncQueryFactory, |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1420 | null /* handle */, |
| 1421 | null /* gatewayInfo */, |
| 1422 | null /* connectionManagerPhoneAccount */, |
| 1423 | phoneAccount, |
| 1424 | false /* isIncoming */, |
Tyler Gunn | d92e737 | 2015-01-09 15:59:45 -0800 | [diff] [blame] | 1425 | true /* isConference */, |
| 1426 | connectTime); |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1427 | |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 1428 | setCallState(call, Call.getStateFromConnectionState(parcelableConference.getState()), |
| 1429 | "new conference call"); |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 1430 | call.setConnectionCapabilities(parcelableConference.getConnectionCapabilities()); |
Rekha Kumar | d240fe8 | 2015-04-01 21:45:57 -0700 | [diff] [blame] | 1431 | call.setVideoState(parcelableConference.getVideoState()); |
| 1432 | call.setVideoProvider(parcelableConference.getVideoProvider()); |
Andrew Lee | 57412d3 | 2015-04-14 13:38:44 -0700 | [diff] [blame] | 1433 | call.setStatusHints(parcelableConference.getStatusHints()); |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 1434 | call.setExtras(parcelableConference.getExtras()); |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1435 | |
| 1436 | // TODO: Move this to be a part of addCall() |
| 1437 | call.addListener(this); |
| 1438 | addCall(call); |
| 1439 | return call; |
| 1440 | } |
| 1441 | |
Yorke Lee | f86db2e | 2014-09-12 17:56:48 -0700 | [diff] [blame] | 1442 | /** |
| 1443 | * @return the call state currently tracked by {@link PhoneStateBroadcaster} |
| 1444 | */ |
| 1445 | int getCallState() { |
| 1446 | return mPhoneStateBroadcaster.getCallState(); |
| 1447 | } |
Nancy Chen | bc9ef17 | 2014-08-15 17:11:57 -0700 | [diff] [blame] | 1448 | |
Santos Cordon | 4b2c119 | 2014-03-19 18:15:38 -0700 | [diff] [blame] | 1449 | /** |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1450 | * Retrieves the {@link PhoneAccountRegistrar}. |
| 1451 | * |
| 1452 | * @return The {@link PhoneAccountRegistrar}. |
| 1453 | */ |
| 1454 | PhoneAccountRegistrar getPhoneAccountRegistrar() { |
| 1455 | return mPhoneAccountRegistrar; |
| 1456 | } |
| 1457 | |
| 1458 | /** |
| 1459 | * Retrieves the {@link MissedCallNotifier} |
| 1460 | * @return The {@link MissedCallNotifier}. |
| 1461 | */ |
| 1462 | MissedCallNotifier getMissedCallNotifier() { |
| 1463 | return mMissedCallNotifier; |
| 1464 | } |
| 1465 | |
| 1466 | /** |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 1467 | * Adds the specified call to the main list of live calls. |
| 1468 | * |
| 1469 | * @param call The call to add. |
| 1470 | */ |
| 1471 | private void addCall(Call call) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1472 | Trace.beginSection("addCall"); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 1473 | Log.v(this, "addCall(%s)", call); |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 1474 | call.addListener(this); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1475 | mCalls.add(call); |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 1476 | |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 1477 | // TODO: Update mForegroundCall prior to invoking |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 1478 | // onCallAdded for calls which immediately take the foreground (like the first call). |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1479 | for (CallsManagerListener listener : mListeners) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1480 | if (Log.SYSTRACE_DEBUG) { |
| 1481 | Trace.beginSection(listener.getClass().toString() + " addCall"); |
| 1482 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1483 | listener.onCallAdded(call); |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1484 | if (Log.SYSTRACE_DEBUG) { |
| 1485 | Trace.endSection(); |
| 1486 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1487 | } |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1488 | updateCallsManagerState(); |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1489 | Trace.endSection(); |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 1490 | } |
| 1491 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1492 | private void removeCall(Call call) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1493 | Trace.beginSection("removeCall"); |
Santos Cordon | c499c1c | 2014-04-14 17:13:14 -0700 | [diff] [blame] | 1494 | Log.v(this, "removeCall(%s)", call); |
Sailesh Nepal | 4857f47 | 2014-04-07 22:26:27 -0700 | [diff] [blame] | 1495 | |
Santos Cordon | 672321e | 2014-08-21 14:38:58 -0700 | [diff] [blame] | 1496 | call.setParentCall(null); // need to clean up parent relationship before destroying. |
Santos Cordon | 766d04f | 2014-05-06 10:28:25 -0700 | [diff] [blame] | 1497 | call.removeListener(this); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1498 | call.clearConnectionService(); |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1499 | |
| 1500 | boolean shouldNotify = false; |
| 1501 | if (mCalls.contains(call)) { |
| 1502 | mCalls.remove(call); |
| 1503 | shouldNotify = true; |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1504 | } |
Ben Gilad | a0d9f75 | 2014-02-26 11:49:03 -0800 | [diff] [blame] | 1505 | |
Santos Cordon | 2685dab | 2015-04-17 17:12:09 -0700 | [diff] [blame] | 1506 | call.destroy(); |
| 1507 | |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1508 | // Only broadcast changes for calls that are being tracked. |
| 1509 | if (shouldNotify) { |
| 1510 | for (CallsManagerListener listener : mListeners) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1511 | if (Log.SYSTRACE_DEBUG) { |
| 1512 | Trace.beginSection(listener.getClass().toString() + " onCallRemoved"); |
| 1513 | } |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1514 | listener.onCallRemoved(call); |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1515 | if (Log.SYSTRACE_DEBUG) { |
| 1516 | Trace.endSection(); |
| 1517 | } |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1518 | } |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1519 | updateCallsManagerState(); |
Yorke Lee | 604a90f | 2014-10-20 12:13:32 -0700 | [diff] [blame] | 1520 | } |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1521 | Trace.endSection(); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1522 | } |
Evan Charlton | 5c670a9 | 2014-03-06 14:58:20 -0800 | [diff] [blame] | 1523 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1524 | /** |
Santos Cordon | 1ae2b85 | 2014-03-19 03:03:10 -0700 | [diff] [blame] | 1525 | * Sets the specified state on the specified call. |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1526 | * |
| 1527 | * @param call The call. |
| 1528 | * @param newState The new state of the call. |
| 1529 | */ |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 1530 | private void setCallState(Call call, int newState, String tag) { |
Jay Shrauner | acb91eb | 2014-08-08 16:04:53 -0700 | [diff] [blame] | 1531 | if (call == null) { |
| 1532 | return; |
| 1533 | } |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 1534 | int oldState = call.getState(); |
Nancy Chen | 308ab8b | 2014-09-02 16:18:30 -0700 | [diff] [blame] | 1535 | Log.i(this, "setCallState %s -> %s, call: %s", CallState.toString(oldState), |
| 1536 | CallState.toString(newState), call); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1537 | if (newState != oldState) { |
| 1538 | // Unfortunately, in the telephony world the radio is king. So if the call notifies |
| 1539 | // us that the call is in a particular state, we allow it even if it doesn't make |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 1540 | // sense (e.g., STATE_ACTIVE -> STATE_RINGING). |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 1541 | // TODO: Consider putting a stop to the above and turning CallState |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1542 | // into a well-defined state machine. |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 1543 | // TODO: Define expected state transitions here, and log when an |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1544 | // unexpected transition occurs. |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 1545 | call.setState(newState, tag); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1546 | |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1547 | Trace.beginSection("onCallStateChanged"); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1548 | // Only broadcast state change for calls that are being tracked. |
Sailesh Nepal | e59bb19 | 2014-04-01 18:33:59 -0700 | [diff] [blame] | 1549 | if (mCalls.contains(call)) { |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1550 | for (CallsManagerListener listener : mListeners) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1551 | if (Log.SYSTRACE_DEBUG) { |
| 1552 | Trace.beginSection(listener.getClass().toString() + " onCallStateChanged"); |
| 1553 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1554 | listener.onCallStateChanged(call, oldState, newState); |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1555 | if (Log.SYSTRACE_DEBUG) { |
| 1556 | Trace.endSection(); |
| 1557 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1558 | } |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1559 | updateCallsManagerState(); |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 1560 | } |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1561 | Trace.endSection(); |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 1562 | } |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1563 | manageDsdaInCallTones(false); |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | /** |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1567 | * Checks which call should be visible to the user and have audio focus. |
Evan Charlton | 5c670a9 | 2014-03-06 14:58:20 -0800 | [diff] [blame] | 1568 | */ |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1569 | private void updateForegroundCall() { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1570 | Trace.beginSection("updateForegroundCall"); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1571 | Call newForegroundCall = null; |
Santos Cordon | df39986 | 2014-08-06 04:39:15 -0700 | [diff] [blame] | 1572 | // TODO: Foreground-ness needs to be explicitly set. No call, regardless |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1573 | // of its state will be foreground by default and instead the connection service should |
| 1574 | // be notified when its calls enter and exit foreground state. Foreground will mean that |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 1575 | // the call should play audio and listen to microphone if it wants. |
| 1576 | |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1577 | if (TelephonyManager.getDefault().getMultiSimConfiguration() |
| 1578 | == TelephonyManager.MultiSimVariants.DSDA) { |
| 1579 | String lchSub = getLchSub(); |
| 1580 | for (Call call : mCalls) { |
| 1581 | // Only top-level calls can be in foreground |
| 1582 | if (call.getParentCall() != null) { |
| 1583 | continue; |
| 1584 | } |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1585 | |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1586 | PhoneAccountHandle ph = call.getTargetPhoneAccount(); |
| 1587 | if (ph != null && ph.getId().equals(lchSub)) continue; |
| 1588 | // Active calls have priority. |
| 1589 | if (call.isActive()) { |
| 1590 | newForegroundCall = call; |
| 1591 | break; |
| 1592 | } |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 1593 | |
Shriram Ganesh | 8ad27bd | 2015-11-03 17:12:59 -0800 | [diff] [blame] | 1594 | // If only call in call list is held call it's also a foreground call |
Shriram Ganesh | d7dd727 | 2015-12-11 15:52:15 -0800 | [diff] [blame^] | 1595 | if (getNumTopLevelCalls() == 1 && call.getState() == CallState.ON_HOLD) { |
Shriram Ganesh | 8ad27bd | 2015-11-03 17:12:59 -0800 | [diff] [blame] | 1596 | newForegroundCall = call; |
| 1597 | } |
| 1598 | |
Shriram Ganesh | 7425449 | 2015-10-26 10:36:19 -0700 | [diff] [blame] | 1599 | if ((call.isAlive() && call.getState() != CallState.ON_HOLD) |
| 1600 | || call.getState() == CallState.RINGING) { |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1601 | newForegroundCall = call; |
| 1602 | // Don't break in case there's an active call that has priority. |
| 1603 | } |
| 1604 | } |
| 1605 | // if active sub doesn't have any calls, then consider calls on all subs, |
| 1606 | // which ever call is active set that as foreground call. give more priority |
| 1607 | // to ringing call on LCH sub over active call. |
| 1608 | if (newForegroundCall == null) { |
| 1609 | newForegroundCall = getFirstCallWithState(CallState.RINGING); |
| 1610 | if (newForegroundCall == null) { |
| 1611 | newForegroundCall = getFirstCallWithState(CallState.ACTIVE); |
| 1612 | } |
| 1613 | } |
| 1614 | } else { |
| 1615 | for (Call call : mCalls) { |
| 1616 | // Only top-level calls can be in foreground |
| 1617 | if (call.getParentCall() != null) { |
| 1618 | continue; |
| 1619 | } |
| 1620 | |
| 1621 | // Active calls have priority. |
| 1622 | if (call.isActive()) { |
| 1623 | newForegroundCall = call; |
| 1624 | break; |
| 1625 | } |
| 1626 | |
Shriram Ganesh | 8ad27bd | 2015-11-03 17:12:59 -0800 | [diff] [blame] | 1627 | // If only call in call list is held call it's also a foreground call |
Shriram Ganesh | d7dd727 | 2015-12-11 15:52:15 -0800 | [diff] [blame^] | 1628 | if (getNumTopLevelCalls() == 1 && call.getState() == CallState.ON_HOLD) { |
Shriram Ganesh | 8ad27bd | 2015-11-03 17:12:59 -0800 | [diff] [blame] | 1629 | newForegroundCall = call; |
| 1630 | } |
| 1631 | |
Shriram Ganesh | 7425449 | 2015-10-26 10:36:19 -0700 | [diff] [blame] | 1632 | if ((call.isAlive() && call.getState() != CallState.ON_HOLD) |
| 1633 | || call.getState() == CallState.RINGING) { |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1634 | newForegroundCall = call; |
| 1635 | // Don't break in case there's an active call that has priority. |
| 1636 | } |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 1637 | } |
| 1638 | } |
Santos Cordon | 4e9fffe | 2014-03-04 18:13:41 -0800 | [diff] [blame] | 1639 | |
Shriram Ganesh | 8ad27bd | 2015-11-03 17:12:59 -0800 | [diff] [blame] | 1640 | /* In the case where there are 2 calls, when the Hold button is pressed for active |
| 1641 | * call, as an intermediate state we would have both calls in held state before |
| 1642 | * the background call is moved to active state. In such an intermediate stage |
| 1643 | * updating the newForegroundCall to null causes issues with abandoning audio |
| 1644 | * focus. Skip updating the foreground call with null in such cases. */ |
| 1645 | if (newForegroundCall == null && getFirstCallWithState(CallState.ON_HOLD) != null) { |
| 1646 | Log.v(this, "Skip updating foreground call in intermediate stage"); |
| 1647 | newForegroundCall = mForegroundCall; |
| 1648 | } |
| 1649 | |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1650 | if (newForegroundCall != mForegroundCall) { |
Santos Cordon | 40f78c2 | 2014-04-07 02:11:42 -0700 | [diff] [blame] | 1651 | Log.v(this, "Updating foreground call, %s -> %s.", mForegroundCall, newForegroundCall); |
Sailesh Nepal | 810735e | 2014-03-18 18:15:46 -0700 | [diff] [blame] | 1652 | Call oldForegroundCall = mForegroundCall; |
| 1653 | mForegroundCall = newForegroundCall; |
Ihab Awad | 5b28132 | 2014-09-25 18:25:29 -0700 | [diff] [blame] | 1654 | |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1655 | for (CallsManagerListener listener : mListeners) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1656 | if (Log.SYSTRACE_DEBUG) { |
| 1657 | Trace.beginSection(listener.getClass().toString() + " updateForegroundCall"); |
| 1658 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1659 | listener.onForegroundCallChanged(oldForegroundCall, mForegroundCall); |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1660 | if (Log.SYSTRACE_DEBUG) { |
| 1661 | Trace.endSection(); |
| 1662 | } |
Santos Cordon | a56f276 | 2014-03-24 15:55:53 -0700 | [diff] [blame] | 1663 | } |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 1664 | } |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1665 | Trace.endSection(); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 1666 | } |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 1667 | |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1668 | private void updateCanAddCall() { |
| 1669 | boolean newCanAddCall = canAddCall(); |
| 1670 | if (newCanAddCall != mCanAddCall) { |
| 1671 | mCanAddCall = newCanAddCall; |
| 1672 | for (CallsManagerListener listener : mListeners) { |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1673 | if (Log.SYSTRACE_DEBUG) { |
| 1674 | Trace.beginSection(listener.getClass().toString() + " updateCanAddCall"); |
| 1675 | } |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1676 | listener.onCanAddCallChanged(mCanAddCall); |
Yorke Lee | e4a9c41 | 2014-11-14 16:59:42 -0800 | [diff] [blame] | 1677 | if (Log.SYSTRACE_DEBUG) { |
| 1678 | Trace.endSection(); |
| 1679 | } |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1680 | } |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | private void updateCallsManagerState() { |
| 1685 | updateForegroundCall(); |
| 1686 | updateCanAddCall(); |
| 1687 | } |
| 1688 | |
Yorke Lee | b701f6d | 2014-08-12 14:04:19 -0700 | [diff] [blame] | 1689 | private boolean isPotentialMMICode(Uri handle) { |
| 1690 | return (handle != null && handle.getSchemeSpecificPart() != null |
| 1691 | && handle.getSchemeSpecificPart().contains("#")); |
| 1692 | } |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1693 | |
Tyler Gunn | 5b452df | 2014-10-01 15:02:58 -0700 | [diff] [blame] | 1694 | /** |
| 1695 | * Determines if a dialed number is potentially an In-Call MMI code. In-Call MMI codes are |
| 1696 | * MMI codes which can be dialed when one or more calls are in progress. |
| 1697 | * <P> |
| 1698 | * Checks for numbers formatted similar to the MMI codes defined in: |
| 1699 | * {@link com.android.internal.telephony.gsm.GSMPhone#handleInCallMmiCommands(String)} |
| 1700 | * and |
| 1701 | * {@link com.android.internal.telephony.imsphone.ImsPhone#handleInCallMmiCommands(String)} |
| 1702 | * |
| 1703 | * @param handle The URI to call. |
| 1704 | * @return {@code True} if the URI represents a number which could be an in-call MMI code. |
| 1705 | */ |
| 1706 | private boolean isPotentialInCallMMICode(Uri handle) { |
| 1707 | if (handle != null && handle.getSchemeSpecificPart() != null && |
| 1708 | handle.getScheme().equals(PhoneAccount.SCHEME_TEL)) { |
| 1709 | |
| 1710 | String dialedNumber = handle.getSchemeSpecificPart(); |
| 1711 | return (dialedNumber.equals("0") || |
| 1712 | (dialedNumber.startsWith("1") && dialedNumber.length() <= 2) || |
| 1713 | (dialedNumber.startsWith("2") && dialedNumber.length() <= 2) || |
| 1714 | dialedNumber.equals("3") || |
| 1715 | dialedNumber.equals("4") || |
| 1716 | dialedNumber.equals("5")); |
| 1717 | } |
| 1718 | return false; |
| 1719 | } |
| 1720 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1721 | private int getNumCallsWithState(int... states) { |
| 1722 | int count = 0; |
| 1723 | for (int state : states) { |
| 1724 | for (Call call : mCalls) { |
Santos Cordon | 91bd74c | 2014-11-07 16:10:22 -0800 | [diff] [blame] | 1725 | if (call.getParentCall() == null && call.getState() == state) { |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1726 | count++; |
| 1727 | } |
| 1728 | } |
| 1729 | } |
| 1730 | return count; |
| 1731 | } |
| 1732 | |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1733 | private int getNumCallsWithState(String subId, int... states) { |
| 1734 | int count = 0; |
| 1735 | for (int state : states) { |
| 1736 | for (Call call : mCalls) { |
| 1737 | if (call.getParentCall() == null && call.getState() == state |
| 1738 | && call.getTargetPhoneAccount() != null |
| 1739 | && isSamePhAccIdOrSipId(call.getTargetPhoneAccount().getId(), subId)) { |
| 1740 | count++; |
| 1741 | } |
| 1742 | } |
| 1743 | } |
| 1744 | return count; |
| 1745 | } |
| 1746 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1747 | private boolean hasMaximumLiveCalls() { |
| 1748 | return MAXIMUM_LIVE_CALLS <= getNumCallsWithState(LIVE_CALL_STATES); |
| 1749 | } |
| 1750 | |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1751 | private boolean hasMaximumLiveCalls(String subId) { |
| 1752 | return MAXIMUM_LIVE_CALLS <= getNumCallsWithState(subId, LIVE_CALL_STATES); |
| 1753 | } |
| 1754 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1755 | private boolean hasMaximumHoldingCalls() { |
| 1756 | return MAXIMUM_HOLD_CALLS <= getNumCallsWithState(CallState.ON_HOLD); |
| 1757 | } |
| 1758 | |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1759 | private boolean hasMaximumHoldingCalls(String subId) { |
| 1760 | return MAXIMUM_HOLD_CALLS <= getNumCallsWithState(subId, CallState.ON_HOLD); |
| 1761 | } |
| 1762 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1763 | private boolean hasMaximumRingingCalls() { |
| 1764 | return MAXIMUM_RINGING_CALLS <= getNumCallsWithState(CallState.RINGING); |
| 1765 | } |
| 1766 | |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1767 | private boolean hasMaximumRingingCalls(String subId) { |
| 1768 | return MAXIMUM_RINGING_CALLS <= getNumCallsWithState(subId, CallState.RINGING); |
| 1769 | } |
| 1770 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1771 | private boolean hasMaximumOutgoingCalls() { |
| 1772 | return MAXIMUM_OUTGOING_CALLS <= getNumCallsWithState(OUTGOING_CALL_STATES); |
| 1773 | } |
| 1774 | |
Roshan Pius | 4de4a89 | 2015-08-24 11:06:58 -0700 | [diff] [blame] | 1775 | private boolean hasMaximumDialingCalls() { |
| 1776 | return MAXIMUM_DIALING_CALLS <= getNumCallsWithState(CallState.DIALING); |
| 1777 | } |
| 1778 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1779 | private boolean makeRoomForOutgoingCall(Call call, boolean isEmergency) { |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1780 | if (TelephonyManager.getDefault().getMultiSimConfiguration() |
| 1781 | == TelephonyManager.MultiSimVariants.DSDA) { |
| 1782 | return makeRoomForOutgoingCallForDsda(call, isEmergency); |
| 1783 | } |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1784 | if (hasMaximumLiveCalls()) { |
| 1785 | // NOTE: If the amount of live calls changes beyond 1, this logic will probably |
| 1786 | // have to change. |
| 1787 | Call liveCall = getFirstCallWithState(call, LIVE_CALL_STATES); |
Anju Mathapati | c88574c | 2014-12-16 14:46:19 +0530 | [diff] [blame] | 1788 | Log.i(this, "makeRoomForOutgoingCall call = " + call + " livecall = " + |
| 1789 | liveCall); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1790 | |
Santos Cordon | d176650 | 2014-09-26 15:45:39 -0700 | [diff] [blame] | 1791 | if (call == liveCall) { |
| 1792 | // If the call is already the foreground call, then we are golden. |
Santos Cordon | 9269451 | 2015-04-23 14:47:28 -0700 | [diff] [blame] | 1793 | // This can happen after the user selects an account in the SELECT_PHONE_ACCOUNT |
Santos Cordon | d176650 | 2014-09-26 15:45:39 -0700 | [diff] [blame] | 1794 | // state since the call was already populated into the list. |
| 1795 | return true; |
| 1796 | } |
| 1797 | |
Andrew Lee | e659518 | 2014-09-23 18:43:05 -0700 | [diff] [blame] | 1798 | if (hasMaximumOutgoingCalls()) { |
Yorke Lee | 867907d | 2015-06-03 12:24:43 -0700 | [diff] [blame] | 1799 | Call outgoingCall = getFirstCallWithState(OUTGOING_CALL_STATES); |
| 1800 | if (isEmergency && !outgoingCall.isEmergencyCall()) { |
| 1801 | // Disconnect the current outgoing call if it's not an emergency call. If the |
| 1802 | // user tries to make two outgoing calls to different emergency call numbers, |
| 1803 | // we will try to connect the first outgoing call. |
| 1804 | outgoingCall.disconnect(); |
| 1805 | return true; |
| 1806 | } |
| 1807 | if (outgoingCall.getState() == CallState.SELECT_PHONE_ACCOUNT) { |
| 1808 | // If there is an orphaned call in the {@link CallState#SELECT_PHONE_ACCOUNT} |
| 1809 | // state, just disconnect it since the user has explicitly started a new call. |
| 1810 | outgoingCall.disconnect(); |
| 1811 | return true; |
Andrew Lee | e659518 | 2014-09-23 18:43:05 -0700 | [diff] [blame] | 1812 | } |
| 1813 | return false; |
| 1814 | } |
| 1815 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1816 | if (hasMaximumHoldingCalls()) { |
| 1817 | // There is no more room for any more calls, unless it's an emergency. |
| 1818 | if (isEmergency) { |
| 1819 | // Kill the current active call, this is easier then trying to disconnect a |
| 1820 | // holding call and hold an active call. |
| 1821 | liveCall.disconnect(); |
| 1822 | return true; |
| 1823 | } |
| 1824 | return false; // No more room! |
| 1825 | } |
| 1826 | |
| 1827 | // We have room for at least one more holding call at this point. |
| 1828 | |
Tyler Gunn | e4cd916 | 2015-08-11 15:36:04 -0700 | [diff] [blame] | 1829 | // TODO: Remove once b/23035408 has been corrected. |
| 1830 | // If the live call is a conference, it will not have a target phone account set. This |
| 1831 | // means the check to see if the live call has the same target phone account as the new |
| 1832 | // call will not cause us to bail early. As a result, we'll end up holding the |
| 1833 | // ongoing conference call. However, the ConnectionService is already doing that. This |
| 1834 | // has caused problems with some carriers. As a workaround until b/23035408 is |
| 1835 | // corrected, we will try and get the target phone account for one of the conference's |
| 1836 | // children and use that instead. |
| 1837 | PhoneAccountHandle liveCallPhoneAccount = liveCall.getTargetPhoneAccount(); |
| 1838 | if (liveCallPhoneAccount == null && liveCall.isConference() && |
| 1839 | !liveCall.getChildCalls().isEmpty()) { |
| 1840 | liveCallPhoneAccount = getFirstChildPhoneAccount(liveCall); |
| 1841 | Log.i(this, "makeRoomForOutgoingCall: using child call PhoneAccount = " + |
| 1842 | liveCallPhoneAccount); |
| 1843 | } |
| 1844 | |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1845 | // First thing, if we are trying to make a call with the same phone account as the live |
| 1846 | // call, then allow it so that the connection service can make its own decision about |
| 1847 | // how to handle the new call relative to the current one. |
Tyler Gunn | e4cd916 | 2015-08-11 15:36:04 -0700 | [diff] [blame] | 1848 | if (Objects.equals(liveCallPhoneAccount, call.getTargetPhoneAccount())) { |
| 1849 | Log.i(this, "makeRoomForOutgoingCall: phoneAccount matches."); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1850 | return true; |
| 1851 | } else if (call.getTargetPhoneAccount() == null) { |
| 1852 | // Without a phone account, we can't say reliably that the call will fail. |
| 1853 | // If the user chooses the same phone account as the live call, then it's |
| 1854 | // still possible that the call can be made (like with CDMA calls not supporting |
| 1855 | // hold but they still support adding a call by going immediately into conference |
| 1856 | // mode). Return true here and we'll run this code again after user chooses an |
| 1857 | // account. |
| 1858 | return true; |
| 1859 | } |
| 1860 | |
| 1861 | // Try to hold the live call before attempting the new outgoing call. |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 1862 | if (liveCall.can(Connection.CAPABILITY_HOLD)) { |
Tyler Gunn | e4cd916 | 2015-08-11 15:36:04 -0700 | [diff] [blame] | 1863 | Log.i(this, "makeRoomForOutgoingCall: holding live call."); |
Santos Cordon | f193ba4 | 2014-09-12 06:37:39 -0700 | [diff] [blame] | 1864 | liveCall.hold(); |
| 1865 | return true; |
| 1866 | } |
| 1867 | |
| 1868 | // The live call cannot be held so we're out of luck here. There's no room. |
| 1869 | return false; |
| 1870 | } |
| 1871 | return true; |
| 1872 | } |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1873 | |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 1874 | private boolean makeRoomForOutgoingCallForDsda(Call call, boolean isEmergency) { |
| 1875 | if (isEmergency || (call.getState() == CallState.SELECT_PHONE_ACCOUNT)) { |
| 1876 | return true; |
| 1877 | } |
| 1878 | |
| 1879 | PhoneAccountHandle phAcc = call.getTargetPhoneAccount(); |
| 1880 | if (phAcc == null) { |
| 1881 | if (getNumCallsWithState(LIVE_CALL_STATES) == MAXIMUM_DSDA_LIVE_CALLS |
| 1882 | && getNumCallsWithState(CallState.ON_HOLD) == MAXIMUM_DSDA_HOLD_CALLS) { |
| 1883 | return false; |
| 1884 | } else { |
| 1885 | return true; |
| 1886 | } |
| 1887 | } |
| 1888 | if (hasMaximumLiveCalls(phAcc.getId())) { |
| 1889 | // NOTE: If the amount of live calls changes beyond 1, this logic will probably |
| 1890 | // have to change. |
| 1891 | Call liveCall = getFirstCallWithState(phAcc.getId(), call, LIVE_CALL_STATES); |
| 1892 | |
| 1893 | if (hasMaximumHoldingCalls(phAcc.getId())) { |
| 1894 | // There is no more room for any more calls, unless it's an emergency. |
| 1895 | return false; // No more room! |
| 1896 | } |
| 1897 | if (Objects.equals(liveCall.getTargetPhoneAccount(), call.getTargetPhoneAccount())) { |
| 1898 | return true; |
| 1899 | } |
| 1900 | // Try to hold the live call before attempting the new outgoing call. |
| 1901 | if (liveCall.can(Connection.CAPABILITY_HOLD)) { |
| 1902 | liveCall.hold(); |
| 1903 | return true; |
| 1904 | } |
| 1905 | |
| 1906 | // The live call cannot be held so we're out of luck here. There's no room. |
| 1907 | return false; |
| 1908 | } |
| 1909 | return true; |
| 1910 | } |
| 1911 | |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1912 | /** |
Tyler Gunn | e4cd916 | 2015-08-11 15:36:04 -0700 | [diff] [blame] | 1913 | * Given a call, find the first non-null phone account handle of its children. |
| 1914 | * |
| 1915 | * @param parentCall The parent call. |
| 1916 | * @return The first non-null phone account handle of the children, or {@code null} if none. |
| 1917 | */ |
| 1918 | private PhoneAccountHandle getFirstChildPhoneAccount(Call parentCall) { |
| 1919 | for (Call childCall : parentCall.getChildCalls()) { |
| 1920 | PhoneAccountHandle childPhoneAccount = childCall.getTargetPhoneAccount(); |
| 1921 | if (childPhoneAccount != null) { |
| 1922 | return childPhoneAccount; |
| 1923 | } |
| 1924 | } |
| 1925 | return null; |
| 1926 | } |
| 1927 | |
| 1928 | /** |
Santos Cordon | d6782cd | 2015-04-16 09:57:50 -0700 | [diff] [blame] | 1929 | * Checks to see if the call should be on speakerphone and if so, set it. |
| 1930 | */ |
| 1931 | private void maybeMoveToSpeakerPhone(Call call) { |
| 1932 | if (call.getStartWithSpeakerphoneOn()) { |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 1933 | setAudioRoute(CallAudioState.ROUTE_SPEAKER); |
Santos Cordon | d6782cd | 2015-04-16 09:57:50 -0700 | [diff] [blame] | 1934 | call.setStartWithSpeakerphoneOn(false); |
| 1935 | } |
| 1936 | } |
| 1937 | |
Nivedita Sarkar | dae2c65 | 2015-08-31 10:55:51 -0700 | [diff] [blame] | 1938 | private void maybeMoveToEarpiece(Call call) { |
| 1939 | if (!call.getStartWithSpeakerphoneOn() && !mWiredHeadsetManager.isPluggedIn() && |
| 1940 | !mCallAudioManager.isBluetoothDeviceAvailable()) { |
| 1941 | setAudioRoute(CallAudioState.ROUTE_EARPIECE); |
| 1942 | } |
| 1943 | } |
| 1944 | |
Santos Cordon | d6782cd | 2015-04-16 09:57:50 -0700 | [diff] [blame] | 1945 | /** |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 1946 | * Creates a new call for an existing connection. |
| 1947 | * |
| 1948 | * @param callId The id of the new call. |
| 1949 | * @param connection The connection information. |
| 1950 | * @return The new call. |
| 1951 | */ |
| 1952 | Call createCallForExistingConnection(String callId, ParcelableConnection connection) { |
| 1953 | Call call = new Call( |
| 1954 | mContext, |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 1955 | this, |
Ihab Awad | e6dbc9d | 2015-03-26 10:33:44 -0700 | [diff] [blame] | 1956 | mLock, |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 1957 | mConnectionServiceRepository, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1958 | mContactsAsyncHelper, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 1959 | mCallerInfoAsyncQueryFactory, |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 1960 | connection.getHandle() /* handle */, |
| 1961 | null /* gatewayInfo */, |
| 1962 | null /* connectionManagerPhoneAccount */, |
| 1963 | connection.getPhoneAccount(), /* targetPhoneAccountHandle */ |
| 1964 | false /* isIncoming */, |
Roshan Pius | 084ab08 | 2015-07-15 12:17:04 -0700 | [diff] [blame] | 1965 | false /* isConference */, |
| 1966 | connection.getConnectTimeMillis() /* connectTimeMillis */); |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 1967 | |
Santos Cordon | 5fa4e4f | 2015-06-10 14:56:01 -0700 | [diff] [blame] | 1968 | setCallState(call, Call.getStateFromConnectionState(connection.getState()), |
| 1969 | "existing connection"); |
Ihab Awad | 07bc5ee | 2014-11-12 13:42:52 -0800 | [diff] [blame] | 1970 | call.setConnectionCapabilities(connection.getConnectionCapabilities()); |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 1971 | call.setCallerDisplayName(connection.getCallerDisplayName(), |
| 1972 | connection.getCallerDisplayNamePresentation()); |
| 1973 | |
| 1974 | call.addListener(this); |
| 1975 | addCall(call); |
| 1976 | |
| 1977 | return call; |
| 1978 | } |
| 1979 | |
| 1980 | /** |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1981 | * Dumps the state of the {@link CallsManager}. |
| 1982 | * |
| 1983 | * @param pw The {@code IndentingPrintWriter} to write the state to. |
| 1984 | */ |
| 1985 | public void dump(IndentingPrintWriter pw) { |
| 1986 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1987 | if (mCalls != null) { |
| 1988 | pw.println("mCalls: "); |
| 1989 | pw.increaseIndent(); |
| 1990 | for (Call call : mCalls) { |
| 1991 | pw.println(call); |
| 1992 | } |
| 1993 | pw.decreaseIndent(); |
| 1994 | } |
Tyler Gunn | 9787e0e | 2014-10-14 14:36:12 -0700 | [diff] [blame] | 1995 | pw.println("mForegroundCall: " + (mForegroundCall == null ? "none" : mForegroundCall)); |
| 1996 | |
| 1997 | if (mCallAudioManager != null) { |
| 1998 | pw.println("mCallAudioManager:"); |
| 1999 | pw.increaseIndent(); |
| 2000 | mCallAudioManager.dump(pw); |
| 2001 | pw.decreaseIndent(); |
| 2002 | } |
| 2003 | |
| 2004 | if (mTtyManager != null) { |
| 2005 | pw.println("mTtyManager:"); |
| 2006 | pw.increaseIndent(); |
| 2007 | mTtyManager.dump(pw); |
| 2008 | pw.decreaseIndent(); |
| 2009 | } |
| 2010 | |
| 2011 | if (mInCallController != null) { |
| 2012 | pw.println("mInCallController:"); |
| 2013 | pw.increaseIndent(); |
| 2014 | mInCallController.dump(pw); |
| 2015 | pw.decreaseIndent(); |
| 2016 | } |
| 2017 | |
| 2018 | if (mConnectionServiceRepository != null) { |
| 2019 | pw.println("mConnectionServiceRepository:"); |
| 2020 | pw.increaseIndent(); |
| 2021 | mConnectionServiceRepository.dump(pw); |
| 2022 | pw.decreaseIndent(); |
| 2023 | } |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 2024 | } |
Sandeep Kunta | 39b7767 | 2014-09-01 17:22:57 +0530 | [diff] [blame] | 2025 | |
| 2026 | private final Handler mLchHandler = new LchHandler(); |
| 2027 | private final class LchHandler extends Handler { |
| 2028 | @Override |
| 2029 | public void handleMessage(Message msg) { |
| 2030 | switch (msg.what) { |
| 2031 | case PHONE_START_DSDA_INCALL_TONE: |
| 2032 | Log.d(this, "Start DSDA incall tones..."); |
| 2033 | startDsdaInCallTones(); |
| 2034 | break; |
| 2035 | case LCH_PLAY_DTMF: |
| 2036 | playLchDtmf(); |
| 2037 | break; |
| 2038 | case LCH_STOP_DTMF: |
| 2039 | stopLchDtmf(); |
| 2040 | break; |
| 2041 | } |
| 2042 | } |
| 2043 | } |
| 2044 | |
| 2045 | public void switchToOtherActiveSub(String subId) { |
| 2046 | if (TelephonyManager.getDefault().getMultiSimConfiguration() |
| 2047 | != TelephonyManager.MultiSimVariants.DSDA) { |
| 2048 | return; |
| 2049 | } |
| 2050 | Log.d(this, "switchToOtherActiveSub sub:" + subId); |
| 2051 | setActiveSubscription(subId); |
| 2052 | updateLchStatus(subId); |
| 2053 | manageDsdaInCallTones(true); |
| 2054 | updateForegroundCall(); |
| 2055 | } |
| 2056 | |
| 2057 | public synchronized void setActiveSubscription(String subId) { |
| 2058 | Log.d(this, "setActiveSubscription = " + subId); |
| 2059 | if (TelephonyManager.getDefault().getMultiSimConfiguration() |
| 2060 | != TelephonyManager.MultiSimVariants.DSDA) { |
| 2061 | return; |
| 2062 | } |
| 2063 | boolean changed = false; |
| 2064 | for (PhoneAccountHandle ph : getPhoneAccountRegistrar().getSimPhoneAccounts()) { |
| 2065 | PhoneAccount phAcc = getPhoneAccountRegistrar().getPhoneAccount(ph); |
| 2066 | if (subId != null && subId.equals(ph.getId()) |
| 2067 | && (phAcc != null) && !phAcc.isSet(PhoneAccount.ACTIVE)) { |
| 2068 | changed = true; |
| 2069 | phAcc.setBit(PhoneAccount.ACTIVE); |
| 2070 | } else if (subId != null && !subId.equals(ph.getId()) |
| 2071 | && (phAcc != null) && phAcc.isSet(PhoneAccount.ACTIVE)) { |
| 2072 | changed = true; |
| 2073 | phAcc.unSetBit(PhoneAccount.ACTIVE); |
| 2074 | } else if ((subId == null) && (phAcc != null) && phAcc.isSet(PhoneAccount.ACTIVE)) { |
| 2075 | phAcc.unSetBit(PhoneAccount.ACTIVE); |
| 2076 | } |
| 2077 | } |
| 2078 | if (!changed) { |
| 2079 | Log.d(this, "setActiveSubscription not changed "); |
| 2080 | return; |
| 2081 | } else { |
| 2082 | Log.d(this, "setActiveSubscription changed " ); |
| 2083 | for (Call call : mCalls) { |
| 2084 | PhoneAccountHandle ph = call.getTargetPhoneAccount(); |
| 2085 | if (ph != null) { |
| 2086 | call.mIsActiveSub = ph.getId().equals(subId) ? true : false; |
| 2087 | } |
| 2088 | for (CallsManagerListener listener : mListeners) { |
| 2089 | listener.onCallStateChanged(call, call.getState(), call.getState()); |
| 2090 | } |
| 2091 | } |
| 2092 | } |
| 2093 | } |
| 2094 | |
| 2095 | public String getActiveSubscription() { |
| 2096 | for (PhoneAccountHandle ph : getPhoneAccountRegistrar().getSimPhoneAccounts()) { |
| 2097 | if (getPhoneAccountRegistrar() |
| 2098 | .getPhoneAccount(ph).isSet(PhoneAccount.ACTIVE)) { |
| 2099 | Log.d(this, "getActiveSubscription: " + ph.getId()); |
| 2100 | return ph.getId(); |
| 2101 | } |
| 2102 | } |
| 2103 | return null; |
| 2104 | } |
| 2105 | |
| 2106 | private String getConversationSub() { |
| 2107 | for (PhoneAccountHandle ph : getPhoneAccountRegistrar().getSimPhoneAccounts()) { |
| 2108 | PhoneAccount phAcc = getPhoneAccountRegistrar().getPhoneAccount(ph); |
| 2109 | if (phAcc != null && !phAcc.isSet(PhoneAccount.LCH) && |
| 2110 | (getFirstCallWithState(ph.getId(), CallState.ACTIVE, CallState.DIALING, |
| 2111 | CallState.ON_HOLD) != null)) { |
| 2112 | Log.d(this, "getConversationSub: " + ph.getId()); |
| 2113 | return ph.getId(); |
| 2114 | } |
| 2115 | } |
| 2116 | return null; |
| 2117 | } |
| 2118 | |
| 2119 | void manageDsdaInCallTones(boolean isSubSwitch) { |
| 2120 | Log.d(this, " entered manageDsdaInCallTones "); |
| 2121 | |
| 2122 | // If there is no background active subscription available, stop playing the tones. |
| 2123 | // Do not start/stop LCH/SCH tones when phone is in RINGING state. |
| 2124 | if (getLchSub() != null && !hasRingingCall()) { |
| 2125 | //If sub switch happens re-start the tones with a delay of 100msec. |
| 2126 | if (isSubSwitch) { |
| 2127 | Log.d(this, " manageDsdaInCallTones: re-start playing tones, lch sub = " |
| 2128 | + getLchSub()); |
| 2129 | reStartDsdaInCallTones(); |
| 2130 | } else { |
| 2131 | Log.d(this, " entered manageDsdaInCallTones "); |
| 2132 | startDsdaInCallTones(); |
| 2133 | } |
| 2134 | } else if (getLchSub() == null) { |
| 2135 | // if there is no sub in Lch state, then stop playing the tones |
| 2136 | stopMSimInCallTones(); |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | private void reStartDsdaInCallTones() { |
| 2141 | Log.d(this, " reStartDsdaInCallTones"); |
| 2142 | stopMSimInCallTones(); |
| 2143 | /* Remove any pending PHONE_START_DSDA_INCALL_TONE messages from queue */ |
| 2144 | mLchHandler.removeMessages(PHONE_START_DSDA_INCALL_TONE); |
| 2145 | Message message = Message.obtain(mLchHandler, PHONE_START_DSDA_INCALL_TONE); |
| 2146 | mLchHandler.sendMessageDelayed(message, 100); |
| 2147 | } |
| 2148 | |
| 2149 | /** |
| 2150 | * Returns the first call that it finds with the given states for given subscription. |
| 2151 | * The states are treated as having priority order so that any call with the first |
| 2152 | * state will be returned before any call with states listed later in the parameter list. |
| 2153 | */ |
| 2154 | Call getFirstCallWithState(String sub, int... states) { |
| 2155 | for (int currentState : states) { |
| 2156 | // check the foreground first |
| 2157 | if (mForegroundCall != null && mForegroundCall.getState() == currentState |
| 2158 | && (mForegroundCall.getTargetPhoneAccount() != null) |
| 2159 | && isSamePhAccIdOrSipId(mForegroundCall.getTargetPhoneAccount().getId(), |
| 2160 | sub)) { |
| 2161 | return mForegroundCall; |
| 2162 | } |
| 2163 | |
| 2164 | for (Call call : mCalls) { |
| 2165 | if ((currentState == call.getState()) && |
| 2166 | (call.getTargetPhoneAccount() != null) && |
| 2167 | (isSamePhAccIdOrSipId(call.getTargetPhoneAccount().getId(), sub))) { |
| 2168 | return call; |
| 2169 | } |
| 2170 | } |
| 2171 | } |
| 2172 | return null; |
| 2173 | } |
| 2174 | |
| 2175 | private String getLchSub() { |
| 2176 | for (PhoneAccountHandle ph : getPhoneAccountRegistrar().getSimPhoneAccounts()) { |
| 2177 | PhoneAccount phAcc = getPhoneAccountRegistrar().getPhoneAccount(ph); |
| 2178 | if (phAcc != null && phAcc.isSet(PhoneAccount.LCH)) { |
| 2179 | return ph.getId(); |
| 2180 | } |
| 2181 | } |
| 2182 | return null; |
| 2183 | } |
| 2184 | |
| 2185 | private void playLchDtmf() { |
| 2186 | if (mLchSub != null || mLchHandler.hasMessages(LCH_PLAY_DTMF)) { |
| 2187 | // Ignore any redundant requests to start playing tones |
| 2188 | return; |
| 2189 | } |
| 2190 | mLchSub = getLchSub(); |
| 2191 | Log.d(this, " playLchDtmf... lch sub " + mLchSub); |
| 2192 | if (mLchSub == null) return; |
| 2193 | removeAnyPendingDtmfMsgs(); |
| 2194 | char c = mContext.getResources() |
| 2195 | .getString(R.string.lch_dtmf_key).charAt(0); |
| 2196 | Call call = getNonRingingLiveCall(mLchSub); |
| 2197 | if (call == null) { |
| 2198 | mLchSub = null; |
| 2199 | return; |
| 2200 | } |
| 2201 | call.playDtmfTone(c); |
| 2202 | // Keep playing LCH DTMF tone to remote party on LCH call, with periodicity |
| 2203 | // "LCH_DTMF_PERIODICITY" until call moves out of LCH. |
| 2204 | mLchHandler.sendMessageDelayed(Message.obtain(mLchHandler, LCH_PLAY_DTMF), |
| 2205 | LCH_DTMF_PERIODICITY); |
| 2206 | mLchHandler.sendMessageDelayed(Message.obtain(mLchHandler, LCH_STOP_DTMF), LCH_DTMF_PERIOD); |
| 2207 | } |
| 2208 | |
| 2209 | private Call getNonRingingLiveCall(String subId) { |
| 2210 | return getFirstCallWithState(subId, CallState.DIALING, |
| 2211 | CallState.ACTIVE, CallState.ON_HOLD); |
| 2212 | } |
| 2213 | |
| 2214 | private void stopLchDtmf() { |
| 2215 | if (mLchSub != null) { |
| 2216 | // Ignore any redundant requests to stop playing tones |
| 2217 | Call call = getNonRingingLiveCall(mLchSub); |
| 2218 | Log.d(this, " stopLchDtmf... call: " + call + " mLchSub:" + mLchSub); |
| 2219 | if (call == null) { |
| 2220 | mLchSub = null; |
| 2221 | return; |
| 2222 | } |
| 2223 | call.stopDtmfTone(); |
| 2224 | } |
| 2225 | mLchSub = null; |
| 2226 | } |
| 2227 | |
| 2228 | private void startDsdaInCallTones() { |
| 2229 | if (mLocalCallReminderTonePlayer == null) { |
| 2230 | Log.d(this, " Play local call hold reminder tone "); |
| 2231 | mLocalCallReminderTonePlayer = |
| 2232 | mPlayerFactory.createPlayer(InCallTonePlayer.TONE_HOLD_RECALL); |
| 2233 | mLocalCallReminderTonePlayer.start(); |
| 2234 | } |
| 2235 | if (sSupervisoryCallHoldToneConfig.equals("inband")) { |
| 2236 | // if "persist.radio.sch_tone" is set to "inband", play inband supervisory |
| 2237 | // call hold tone. if set to "dtmf", play the SCH tones |
| 2238 | // over DTMF, don't play SCH tones for anyother value. |
| 2239 | if (mSupervisoryCallHoldTonePlayer == null) { |
| 2240 | Log.d(this, " startDsdaInCallTones: Supervisory call hold tone "); |
| 2241 | mSupervisoryCallHoldTonePlayer = |
| 2242 | mPlayerFactory.createPlayer(InCallTonePlayer.TONE_SUPERVISORY_CH); |
| 2243 | mSupervisoryCallHoldTonePlayer.start(); |
| 2244 | } |
| 2245 | } else if (sSupervisoryCallHoldToneConfig.equals("dtmf")) { |
| 2246 | Log.d(this, " startDsdaInCallTones: Supervisory call hold tone over dtmf "); |
| 2247 | playLchDtmf(); |
| 2248 | } |
| 2249 | } |
| 2250 | |
| 2251 | private void removeAnyPendingDtmfMsgs() { |
| 2252 | mLchHandler.removeMessages(LCH_PLAY_DTMF); |
| 2253 | mLchHandler.removeMessages(LCH_STOP_DTMF); |
| 2254 | } |
| 2255 | |
| 2256 | protected void stopMSimInCallTones() { |
| 2257 | if (mLocalCallReminderTonePlayer != null) { |
| 2258 | Log.d(this, " stopMSimInCallTones: local call hold reminder tone "); |
| 2259 | mLocalCallReminderTonePlayer.stopTone(); |
| 2260 | mLocalCallReminderTonePlayer = null; |
| 2261 | } |
| 2262 | if (mSupervisoryCallHoldTonePlayer != null) { |
| 2263 | Log.d(this, " stopMSimInCallTones: Supervisory call hold tone "); |
| 2264 | mSupervisoryCallHoldTonePlayer.stopTone(); |
| 2265 | mSupervisoryCallHoldTonePlayer = null; |
| 2266 | } |
| 2267 | if (sSupervisoryCallHoldToneConfig.equals("dtmf")) { |
| 2268 | Log.d(this, " stopMSimInCallTones: stop SCH Dtmf call hold tone "); |
| 2269 | stopLchDtmf(); |
| 2270 | /* Remove any previous dtmf nssages from queue */ |
| 2271 | removeAnyPendingDtmfMsgs(); |
| 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | /** |
| 2276 | * Update the local call hold state for all subscriptions |
| 2277 | * 1 -- if call on local hold, 0 -- if call is not on local hold |
| 2278 | * |
| 2279 | * @param subInConversation is the sub user is currently active in subsription. |
| 2280 | * so if this sub is in LCH, then bring that sub out of LCH. |
| 2281 | */ |
| 2282 | private void updateLchStatus(String subInConversation) { |
| 2283 | Call removeFromLch = null; |
| 2284 | Log.d(this, "updateLchStatus subInConversation: " + subInConversation); |
| 2285 | if (subInConversation != null && subInConversation.contains("sip")) { |
| 2286 | return; |
| 2287 | } |
| 2288 | for (PhoneAccountHandle ph : getPhoneAccountRegistrar().getSimPhoneAccounts()) { |
| 2289 | String sub = ph.getId(); |
| 2290 | if (sub != null && sub.contains("sip")) { |
| 2291 | Log.d(this, "update lch. Skipping account: " + sub); |
| 2292 | continue; |
| 2293 | } |
| 2294 | PhoneAccount phAcc = getPhoneAccountRegistrar().getPhoneAccount(ph); |
| 2295 | boolean lchState = false; |
| 2296 | if (subInConversation != null && hasActiveOrHoldingCall(sub) && |
| 2297 | !sub.equals(subInConversation)) { |
| 2298 | // if sub is not conversation sub and if it has an active |
| 2299 | // voice call then update lchStatus as Active |
| 2300 | lchState = true; |
| 2301 | } |
| 2302 | // Update state only if the new state is different |
| 2303 | if ((phAcc != null) && (lchState != phAcc.isSet(PhoneAccount.LCH))) { |
| 2304 | Call call = getNonRingingLiveCall(sub); |
| 2305 | Log.d(this, " setLocal Call Hold to = " + lchState + " sub:" + sub); |
| 2306 | |
| 2307 | if (call != null) { |
| 2308 | if (call.getChildCalls().size() > 1) { |
| 2309 | // Since for a conference call corresponding telephonyconnection doesn't |
| 2310 | // exist, so send lch request on its child call |
| 2311 | call = call.getChildCalls().get(0); |
| 2312 | } |
| 2313 | if (lchState) { |
| 2314 | call.setLocalCallHold(true); |
| 2315 | } else { |
| 2316 | removeFromLch = call; |
| 2317 | } |
| 2318 | } |
| 2319 | if (lchState) { |
| 2320 | phAcc.setBit(PhoneAccount.LCH); |
| 2321 | } else { |
| 2322 | phAcc.unSetBit(PhoneAccount.LCH); |
| 2323 | } |
| 2324 | } |
| 2325 | } |
| 2326 | if (removeFromLch != null) { |
| 2327 | // Ensure to send LCH disable request at last, to make sure that during switch |
| 2328 | // subscription, both subscriptions not to be in active(non-LCH) at any moment. |
| 2329 | removeFromLch.setLocalCallHold(false); |
| 2330 | } |
| 2331 | } |
cqiang | 72e3120 | 2015-09-14 17:04:19 +0800 | [diff] [blame] | 2332 | |
| 2333 | void resetCdmaConnectionTime(Call call) { |
| 2334 | call.setConnectTimeMillis(System.currentTimeMillis()); |
| 2335 | if (mCalls.contains(call)) { |
| 2336 | for (CallsManagerListener listener : mListeners) { |
| 2337 | listener.onCallStateChanged(call, CallState.ACTIVE, CallState.ACTIVE); |
| 2338 | } |
| 2339 | updateForegroundCall(); |
| 2340 | } |
| 2341 | } |
Ravindra | 205cb78 | 2015-10-07 16:57:53 +0530 | [diff] [blame] | 2342 | |
| 2343 | void onMergeFailed(Call call) { |
| 2344 | if (mCalls.contains(call)) { |
| 2345 | for (CallsManagerListener listener : mListeners) { |
| 2346 | listener.onMergeFailed(call); |
| 2347 | } |
| 2348 | } |
| 2349 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 2350 | } |