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