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