Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 18 | |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 19 | import android.annotation.SdkConstant; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 20 | import android.app.Service; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 21 | import android.content.ComponentName; |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 22 | import android.content.Intent; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 23 | import android.net.Uri; |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame^] | 24 | import android.os.Bundle; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 25 | import android.os.Handler; |
| 26 | import android.os.IBinder; |
| 27 | import android.os.Looper; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 28 | import android.os.Message; |
Andrew Lee | 1418576 | 2014-07-25 09:41:56 -0700 | [diff] [blame] | 29 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 30 | import com.android.internal.os.SomeArgs; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 31 | import com.android.internal.telecom.IConnectionService; |
| 32 | import com.android.internal.telecom.IConnectionServiceAdapter; |
| 33 | import com.android.internal.telecom.RemoteServiceCallback; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 34 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 35 | import java.util.ArrayList; |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 36 | import java.util.Collection; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 37 | import java.util.Collections; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 38 | import java.util.List; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 39 | import java.util.Map; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 40 | import java.util.UUID; |
mike dooley | 95e8070 | 2014-09-18 14:07:52 -0700 | [diff] [blame] | 41 | import java.util.concurrent.ConcurrentHashMap; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 44 | * {@code ConnectionService} is an abstract service that should be implemented by any app which can |
| 45 | * make phone calls and want those calls to be integrated into the built-in phone app. |
| 46 | * Once implemented, the {@code ConnectionService} needs two additional steps before it will be |
| 47 | * integrated into the phone app: |
| 48 | * <p> |
| 49 | * 1. <i>Registration in AndroidManifest.xml</i> |
| 50 | * <br/> |
| 51 | * <pre> |
| 52 | * <service android:name="com.example.package.MyConnectionService" |
| 53 | * android:label="@string/some_label_for_my_connection_service" |
Yorke Lee | 249c12e | 2015-05-13 15:59:29 -0700 | [diff] [blame] | 54 | * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"> |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 55 | * <intent-filter> |
| 56 | * <action android:name="android.telecom.ConnectionService" /> |
| 57 | * </intent-filter> |
| 58 | * </service> |
| 59 | * </pre> |
| 60 | * <p> |
| 61 | * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i> |
| 62 | * <br/> |
| 63 | * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information. |
| 64 | * <p> |
| 65 | * Once registered and enabled by the user in the dialer settings, telecom will bind to a |
| 66 | * {@code ConnectionService} implementation when it wants that {@code ConnectionService} to place |
| 67 | * a call or the service has indicated that is has an incoming call through |
| 68 | * {@link TelecomManager#addNewIncomingCall}. The {@code ConnectionService} can then expect a call |
| 69 | * to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection} wherein it |
| 70 | * should provide a new instance of a {@link Connection} object. It is through this |
| 71 | * {@link Connection} object that telecom receives state updates and the {@code ConnectionService} |
| 72 | * receives call-commands such as answer, reject, hold and disconnect. |
| 73 | * <p> |
| 74 | * When there are no more live calls, telecom will unbind from the {@code ConnectionService}. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 75 | */ |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 76 | public abstract class ConnectionService extends Service { |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 77 | /** |
| 78 | * The {@link Intent} that must be declared as handled by the service. |
| 79 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 80 | @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 81 | public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService"; |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 82 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 83 | // Flag controlling whether PII is emitted into the logs |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 84 | private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 85 | |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 86 | private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1; |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 87 | private static final int MSG_CREATE_CONNECTION = 2; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 88 | private static final int MSG_ABORT = 3; |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 89 | private static final int MSG_ANSWER = 4; |
| 90 | private static final int MSG_REJECT = 5; |
| 91 | private static final int MSG_DISCONNECT = 6; |
| 92 | private static final int MSG_HOLD = 7; |
| 93 | private static final int MSG_UNHOLD = 8; |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 94 | private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9; |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 95 | private static final int MSG_PLAY_DTMF_TONE = 10; |
| 96 | private static final int MSG_STOP_DTMF_TONE = 11; |
| 97 | private static final int MSG_CONFERENCE = 12; |
| 98 | private static final int MSG_SPLIT_FROM_CONFERENCE = 13; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 99 | private static final int MSG_ON_POST_DIAL_CONTINUE = 14; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 100 | private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 101 | private static final int MSG_ANSWER_VIDEO = 17; |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 102 | private static final int MSG_MERGE_CONFERENCE = 18; |
| 103 | private static final int MSG_SWAP_CONFERENCE = 19; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 104 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 105 | private static Connection sNullConnection; |
| 106 | |
mike dooley | 95e8070 | 2014-09-18 14:07:52 -0700 | [diff] [blame] | 107 | private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>(); |
| 108 | private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>(); |
| 109 | private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>(); |
| 110 | private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 111 | private final RemoteConnectionManager mRemoteConnectionManager = |
| 112 | new RemoteConnectionManager(this); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 113 | private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 114 | private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 115 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 116 | private boolean mAreAccountsInitialized = false; |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 117 | private Conference sNullConference; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 118 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 119 | private final IBinder mBinder = new IConnectionService.Stub() { |
| 120 | @Override |
| 121 | public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter) { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 122 | mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, adapter).sendToTarget(); |
| 123 | } |
| 124 | |
| 125 | public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter) { |
| 126 | mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, adapter).sendToTarget(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | @Override |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 130 | public void createConnection( |
| 131 | PhoneAccountHandle connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 132 | String id, |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 133 | ConnectionRequest request, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 134 | boolean isIncoming, |
| 135 | boolean isUnknown) { |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 136 | SomeArgs args = SomeArgs.obtain(); |
| 137 | args.arg1 = connectionManagerPhoneAccount; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 138 | args.arg2 = id; |
| 139 | args.arg3 = request; |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 140 | args.argi1 = isIncoming ? 1 : 0; |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 141 | args.argi2 = isUnknown ? 1 : 0; |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 142 | mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void abort(String callId) { |
| 147 | mHandler.obtainMessage(MSG_ABORT, callId).sendToTarget(); |
| 148 | } |
| 149 | |
| 150 | @Override |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 151 | public void answerVideo(String callId, int videoState) { |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 152 | SomeArgs args = SomeArgs.obtain(); |
| 153 | args.arg1 = callId; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 154 | args.argi1 = videoState; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 155 | mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget(); |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public void answer(String callId) { |
| 160 | mHandler.obtainMessage(MSG_ANSWER, callId).sendToTarget(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public void reject(String callId) { |
| 165 | mHandler.obtainMessage(MSG_REJECT, callId).sendToTarget(); |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void disconnect(String callId) { |
| 170 | mHandler.obtainMessage(MSG_DISCONNECT, callId).sendToTarget(); |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public void hold(String callId) { |
| 175 | mHandler.obtainMessage(MSG_HOLD, callId).sendToTarget(); |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public void unhold(String callId) { |
| 180 | mHandler.obtainMessage(MSG_UNHOLD, callId).sendToTarget(); |
| 181 | } |
| 182 | |
| 183 | @Override |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 184 | public void onCallAudioStateChanged(String callId, CallAudioState callAudioState) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 185 | SomeArgs args = SomeArgs.obtain(); |
| 186 | args.arg1 = callId; |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 187 | args.arg2 = callAudioState; |
| 188 | mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | @Override |
| 192 | public void playDtmfTone(String callId, char digit) { |
| 193 | mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, digit, 0, callId).sendToTarget(); |
| 194 | } |
| 195 | |
| 196 | @Override |
| 197 | public void stopDtmfTone(String callId) { |
| 198 | mHandler.obtainMessage(MSG_STOP_DTMF_TONE, callId).sendToTarget(); |
| 199 | } |
| 200 | |
| 201 | @Override |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 202 | public void conference(String callId1, String callId2) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 203 | SomeArgs args = SomeArgs.obtain(); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 204 | args.arg1 = callId1; |
| 205 | args.arg2 = callId2; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 206 | mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget(); |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public void splitFromConference(String callId) { |
| 211 | mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, callId).sendToTarget(); |
| 212 | } |
| 213 | |
| 214 | @Override |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 215 | public void mergeConference(String callId) { |
| 216 | mHandler.obtainMessage(MSG_MERGE_CONFERENCE, callId).sendToTarget(); |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public void swapConference(String callId) { |
| 221 | mHandler.obtainMessage(MSG_SWAP_CONFERENCE, callId).sendToTarget(); |
| 222 | } |
| 223 | |
| 224 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 225 | public void onPostDialContinue(String callId, boolean proceed) { |
| 226 | SomeArgs args = SomeArgs.obtain(); |
| 227 | args.arg1 = callId; |
| 228 | args.argi1 = proceed ? 1 : 0; |
| 229 | mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget(); |
| 230 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | private final Handler mHandler = new Handler(Looper.getMainLooper()) { |
| 234 | @Override |
| 235 | public void handleMessage(Message msg) { |
| 236 | switch (msg.what) { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 237 | case MSG_ADD_CONNECTION_SERVICE_ADAPTER: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 238 | mAdapter.addAdapter((IConnectionServiceAdapter) msg.obj); |
| 239 | onAdapterAttached(); |
| 240 | break; |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 241 | case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: |
| 242 | mAdapter.removeAdapter((IConnectionServiceAdapter) msg.obj); |
| 243 | break; |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 244 | case MSG_CREATE_CONNECTION: { |
| 245 | SomeArgs args = (SomeArgs) msg.obj; |
| 246 | try { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 247 | final PhoneAccountHandle connectionManagerPhoneAccount = |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 248 | (PhoneAccountHandle) args.arg1; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 249 | final String id = (String) args.arg2; |
| 250 | final ConnectionRequest request = (ConnectionRequest) args.arg3; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 251 | final boolean isIncoming = args.argi1 == 1; |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 252 | final boolean isUnknown = args.argi2 == 1; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 253 | if (!mAreAccountsInitialized) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 254 | Log.d(this, "Enqueueing pre-init request %s", id); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 255 | mPreInitializationConnectionRequests.add(new Runnable() { |
| 256 | @Override |
| 257 | public void run() { |
| 258 | createConnection( |
| 259 | connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 260 | id, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 261 | request, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 262 | isIncoming, |
| 263 | isUnknown); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 264 | } |
| 265 | }); |
| 266 | } else { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 267 | createConnection( |
| 268 | connectionManagerPhoneAccount, |
| 269 | id, |
| 270 | request, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 271 | isIncoming, |
| 272 | isUnknown); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 273 | } |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 274 | } finally { |
| 275 | args.recycle(); |
| 276 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 277 | break; |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 278 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 279 | case MSG_ABORT: |
| 280 | abort((String) msg.obj); |
| 281 | break; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 282 | case MSG_ANSWER: |
| 283 | answer((String) msg.obj); |
| 284 | break; |
| 285 | case MSG_ANSWER_VIDEO: { |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 286 | SomeArgs args = (SomeArgs) msg.obj; |
| 287 | try { |
| 288 | String callId = (String) args.arg1; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 289 | int videoState = args.argi1; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 290 | answerVideo(callId, videoState); |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 291 | } finally { |
| 292 | args.recycle(); |
| 293 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 294 | break; |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 295 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 296 | case MSG_REJECT: |
| 297 | reject((String) msg.obj); |
| 298 | break; |
| 299 | case MSG_DISCONNECT: |
| 300 | disconnect((String) msg.obj); |
| 301 | break; |
| 302 | case MSG_HOLD: |
| 303 | hold((String) msg.obj); |
| 304 | break; |
| 305 | case MSG_UNHOLD: |
| 306 | unhold((String) msg.obj); |
| 307 | break; |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 308 | case MSG_ON_CALL_AUDIO_STATE_CHANGED: { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 309 | SomeArgs args = (SomeArgs) msg.obj; |
| 310 | try { |
| 311 | String callId = (String) args.arg1; |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 312 | CallAudioState audioState = (CallAudioState) args.arg2; |
| 313 | onCallAudioStateChanged(callId, new CallAudioState(audioState)); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 314 | } finally { |
| 315 | args.recycle(); |
| 316 | } |
| 317 | break; |
| 318 | } |
| 319 | case MSG_PLAY_DTMF_TONE: |
| 320 | playDtmfTone((String) msg.obj, (char) msg.arg1); |
| 321 | break; |
| 322 | case MSG_STOP_DTMF_TONE: |
| 323 | stopDtmfTone((String) msg.obj); |
| 324 | break; |
| 325 | case MSG_CONFERENCE: { |
| 326 | SomeArgs args = (SomeArgs) msg.obj; |
| 327 | try { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 328 | String callId1 = (String) args.arg1; |
| 329 | String callId2 = (String) args.arg2; |
| 330 | conference(callId1, callId2); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 331 | } finally { |
| 332 | args.recycle(); |
| 333 | } |
| 334 | break; |
| 335 | } |
| 336 | case MSG_SPLIT_FROM_CONFERENCE: |
| 337 | splitFromConference((String) msg.obj); |
| 338 | break; |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 339 | case MSG_MERGE_CONFERENCE: |
| 340 | mergeConference((String) msg.obj); |
| 341 | break; |
| 342 | case MSG_SWAP_CONFERENCE: |
| 343 | swapConference((String) msg.obj); |
| 344 | break; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 345 | case MSG_ON_POST_DIAL_CONTINUE: { |
| 346 | SomeArgs args = (SomeArgs) msg.obj; |
| 347 | try { |
| 348 | String callId = (String) args.arg1; |
| 349 | boolean proceed = (args.argi1 == 1); |
| 350 | onPostDialContinue(callId, proceed); |
| 351 | } finally { |
| 352 | args.recycle(); |
| 353 | } |
| 354 | break; |
| 355 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 356 | default: |
| 357 | break; |
| 358 | } |
| 359 | } |
| 360 | }; |
| 361 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 362 | private final Conference.Listener mConferenceListener = new Conference.Listener() { |
| 363 | @Override |
| 364 | public void onStateChanged(Conference conference, int oldState, int newState) { |
| 365 | String id = mIdByConference.get(conference); |
| 366 | switch (newState) { |
| 367 | case Connection.STATE_ACTIVE: |
| 368 | mAdapter.setActive(id); |
| 369 | break; |
| 370 | case Connection.STATE_HOLDING: |
| 371 | mAdapter.setOnHold(id); |
| 372 | break; |
| 373 | case Connection.STATE_DISCONNECTED: |
| 374 | // handled by onDisconnected |
| 375 | break; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | @Override |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 380 | public void onDisconnected(Conference conference, DisconnectCause disconnectCause) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 381 | String id = mIdByConference.get(conference); |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 382 | mAdapter.setDisconnected(id, disconnectCause); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | @Override |
| 386 | public void onConnectionAdded(Conference conference, Connection connection) { |
| 387 | } |
| 388 | |
| 389 | @Override |
| 390 | public void onConnectionRemoved(Conference conference, Connection connection) { |
| 391 | } |
| 392 | |
| 393 | @Override |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 394 | public void onConferenceableConnectionsChanged( |
| 395 | Conference conference, List<Connection> conferenceableConnections) { |
| 396 | mAdapter.setConferenceableConnections( |
| 397 | mIdByConference.get(conference), |
| 398 | createConnectionIdList(conferenceableConnections)); |
| 399 | } |
| 400 | |
| 401 | @Override |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 402 | public void onDestroyed(Conference conference) { |
| 403 | removeConference(conference); |
| 404 | } |
| 405 | |
| 406 | @Override |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 407 | public void onConnectionCapabilitiesChanged( |
| 408 | Conference conference, |
| 409 | int connectionCapabilities) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 410 | String id = mIdByConference.get(conference); |
| 411 | Log.d(this, "call capabilities: conference: %s", |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 412 | Connection.capabilitiesToString(connectionCapabilities)); |
| 413 | mAdapter.setConnectionCapabilities(id, connectionCapabilities); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 414 | } |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 415 | |
| 416 | @Override |
| 417 | public void onVideoStateChanged(Conference c, int videoState) { |
| 418 | String id = mIdByConference.get(c); |
| 419 | Log.d(this, "onVideoStateChanged set video state %d", videoState); |
| 420 | mAdapter.setVideoState(id, videoState); |
| 421 | } |
| 422 | |
| 423 | @Override |
| 424 | public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) { |
| 425 | String id = mIdByConference.get(c); |
| 426 | Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c, |
| 427 | videoProvider); |
| 428 | mAdapter.setVideoProvider(id, videoProvider); |
| 429 | } |
Andrew Lee | 0f51da3 | 2015-04-16 13:11:55 -0700 | [diff] [blame] | 430 | |
| 431 | @Override |
Andrew Lee | edc625f | 2015-04-14 13:38:12 -0700 | [diff] [blame] | 432 | public void onStatusHintsChanged(Conference conference, StatusHints statusHints) { |
| 433 | String id = mIdByConference.get(conference); |
| 434 | mAdapter.setStatusHints(id, statusHints); |
| 435 | } |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame^] | 436 | |
| 437 | @Override |
| 438 | public void onExtrasChanged(Conference conference, Bundle extras) { |
| 439 | String id = mIdByConference.get(conference); |
| 440 | mAdapter.setExtras(id, extras); |
| 441 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 442 | }; |
| 443 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 444 | private final Connection.Listener mConnectionListener = new Connection.Listener() { |
| 445 | @Override |
| 446 | public void onStateChanged(Connection c, int state) { |
| 447 | String id = mIdByConnection.get(c); |
Ihab Awad | 42b30e1 | 2014-05-22 09:49:34 -0700 | [diff] [blame] | 448 | Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state)); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 449 | switch (state) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 450 | case Connection.STATE_ACTIVE: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 451 | mAdapter.setActive(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 452 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 453 | case Connection.STATE_DIALING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 454 | mAdapter.setDialing(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 455 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 456 | case Connection.STATE_DISCONNECTED: |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 457 | // Handled in onDisconnected() |
| 458 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 459 | case Connection.STATE_HOLDING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 460 | mAdapter.setOnHold(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 461 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 462 | case Connection.STATE_NEW: |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 463 | // Nothing to tell Telecom |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 464 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 465 | case Connection.STATE_RINGING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 466 | mAdapter.setRinging(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 467 | break; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | @Override |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 472 | public void onDisconnected(Connection c, DisconnectCause disconnectCause) { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 473 | String id = mIdByConnection.get(c); |
Andrew Lee | 2678639 | 2014-09-16 18:14:59 -0700 | [diff] [blame] | 474 | Log.d(this, "Adapter set disconnected %s", disconnectCause); |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 475 | mAdapter.setDisconnected(id, disconnectCause); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | @Override |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 479 | public void onVideoStateChanged(Connection c, int videoState) { |
| 480 | String id = mIdByConnection.get(c); |
| 481 | Log.d(this, "Adapter set video state %d", videoState); |
| 482 | mAdapter.setVideoState(id, videoState); |
| 483 | } |
| 484 | |
| 485 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 486 | public void onAddressChanged(Connection c, Uri address, int presentation) { |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 487 | String id = mIdByConnection.get(c); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 488 | mAdapter.setAddress(id, address, presentation); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | @Override |
| 492 | public void onCallerDisplayNameChanged( |
| 493 | Connection c, String callerDisplayName, int presentation) { |
| 494 | String id = mIdByConnection.get(c); |
| 495 | mAdapter.setCallerDisplayName(id, callerDisplayName, presentation); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | @Override |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 499 | public void onDestroyed(Connection c) { |
| 500 | removeConnection(c); |
| 501 | } |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 502 | |
| 503 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 504 | public void onPostDialWait(Connection c, String remaining) { |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 505 | String id = mIdByConnection.get(c); |
| 506 | Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 507 | mAdapter.onPostDialWait(id, remaining); |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | @Override |
Nancy Chen | 27d1c2d | 2014-12-15 16:12:50 -0800 | [diff] [blame] | 511 | public void onPostDialChar(Connection c, char nextChar) { |
| 512 | String id = mIdByConnection.get(c); |
| 513 | Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar); |
| 514 | mAdapter.onPostDialChar(id, nextChar); |
| 515 | } |
| 516 | |
| 517 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 518 | public void onRingbackRequested(Connection c, boolean ringback) { |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 519 | String id = mIdByConnection.get(c); |
| 520 | Log.d(this, "Adapter onRingback %b", ringback); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 521 | mAdapter.setRingbackRequested(id, ringback); |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 522 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 523 | |
| 524 | @Override |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 525 | public void onConnectionCapabilitiesChanged(Connection c, int capabilities) { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 526 | String id = mIdByConnection.get(c); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 527 | Log.d(this, "capabilities: parcelableconnection: %s", |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 528 | Connection.capabilitiesToString(capabilities)); |
| 529 | mAdapter.setConnectionCapabilities(id, capabilities); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 532 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 533 | public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) { |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 534 | String id = mIdByConnection.get(c); |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 535 | Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c, |
| 536 | videoProvider); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 537 | mAdapter.setVideoProvider(id, videoProvider); |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 538 | } |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 539 | |
| 540 | @Override |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 541 | public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) { |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 542 | String id = mIdByConnection.get(c); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 543 | mAdapter.setIsVoipAudioMode(id, isVoip); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 544 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 545 | |
| 546 | @Override |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 547 | public void onStatusHintsChanged(Connection c, StatusHints statusHints) { |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 548 | String id = mIdByConnection.get(c); |
| 549 | mAdapter.setStatusHints(id, statusHints); |
| 550 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 551 | |
| 552 | @Override |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 553 | public void onConferenceablesChanged( |
Tyler Gunn | df2cbc8 | 2015-04-20 09:13:01 -0700 | [diff] [blame] | 554 | Connection connection, List<Conferenceable> conferenceables) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 555 | mAdapter.setConferenceableConnections( |
| 556 | mIdByConnection.get(connection), |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 557 | createIdList(conferenceables)); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 558 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 559 | |
| 560 | @Override |
| 561 | public void onConferenceChanged(Connection connection, Conference conference) { |
| 562 | String id = mIdByConnection.get(connection); |
| 563 | if (id != null) { |
| 564 | String conferenceId = null; |
| 565 | if (conference != null) { |
| 566 | conferenceId = mIdByConference.get(conference); |
| 567 | } |
| 568 | mAdapter.setIsConferenced(id, conferenceId); |
| 569 | } |
| 570 | } |
Anthony Lee | 17455a3 | 2015-04-24 15:25:29 -0700 | [diff] [blame] | 571 | |
| 572 | @Override |
| 573 | public void onConferenceMergeFailed(Connection connection) { |
| 574 | String id = mIdByConnection.get(connection); |
| 575 | if (id != null) { |
| 576 | mAdapter.onConferenceMergeFailed(id); |
| 577 | } |
| 578 | } |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame^] | 579 | |
| 580 | @Override |
| 581 | public void onExtrasChanged(Connection connection, Bundle extras) { |
| 582 | String id = mIdByConnection.get(connection); |
| 583 | if (id != null) { |
| 584 | mAdapter.setExtras(id, extras); |
| 585 | } |
| 586 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 587 | }; |
| 588 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 589 | /** {@inheritDoc} */ |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 590 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 591 | public final IBinder onBind(Intent intent) { |
| 592 | return mBinder; |
| 593 | } |
| 594 | |
Santos Cordon | 29f2f2e | 2014-09-11 19:50:24 -0700 | [diff] [blame] | 595 | /** {@inheritDoc} */ |
| 596 | @Override |
| 597 | public boolean onUnbind(Intent intent) { |
| 598 | endAllConnections(); |
| 599 | return super.onUnbind(intent); |
| 600 | } |
| 601 | |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 602 | /** |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 603 | * This can be used by telecom to either create a new outgoing call or attach to an existing |
| 604 | * incoming call. In either case, telecom will cycle through a set of services and call |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 605 | * createConnection util a connection service cancels the process or completes it successfully. |
| 606 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 607 | private void createConnection( |
| 608 | final PhoneAccountHandle callManagerAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 609 | final String callId, |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 610 | final ConnectionRequest request, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 611 | boolean isIncoming, |
| 612 | boolean isUnknown) { |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 613 | Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " + |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 614 | "isIncoming: %b, isUnknown: %b", callManagerAccount, callId, request, isIncoming, |
| 615 | isUnknown); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 616 | |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 617 | Connection connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request) |
| 618 | : isIncoming ? onCreateIncomingConnection(callManagerAccount, request) |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 619 | : onCreateOutgoingConnection(callManagerAccount, request); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 620 | Log.d(this, "createConnection, connection: %s", connection); |
| 621 | if (connection == null) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 622 | connection = Connection.createFailedConnection( |
| 623 | new DisconnectCause(DisconnectCause.ERROR)); |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 624 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 625 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 626 | if (connection.getState() != Connection.STATE_DISCONNECTED) { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 627 | addConnection(callId, connection); |
| 628 | } |
| 629 | |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 630 | Uri address = connection.getAddress(); |
| 631 | String number = address == null ? "null" : address.getSchemeSpecificPart(); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 632 | Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s", |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 633 | Connection.toLogSafePhoneNumber(number), |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 634 | Connection.stateToString(connection.getState()), |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 635 | Connection.capabilitiesToString(connection.getConnectionCapabilities())); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 636 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 637 | Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 638 | mAdapter.handleCreateConnectionComplete( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 639 | callId, |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 640 | request, |
| 641 | new ParcelableConnection( |
| 642 | request.getAccountHandle(), |
| 643 | connection.getState(), |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 644 | connection.getConnectionCapabilities(), |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 645 | connection.getAddress(), |
| 646 | connection.getAddressPresentation(), |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 647 | connection.getCallerDisplayName(), |
| 648 | connection.getCallerDisplayNamePresentation(), |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 649 | connection.getVideoProvider() == null ? |
| 650 | null : connection.getVideoProvider().getInterface(), |
Sailesh Nepal | 8b9d3ca | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 651 | connection.getVideoState(), |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 652 | connection.isRingbackRequested(), |
Sailesh Nepal | 8b9d3ca | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 653 | connection.getAudioModeIsVoip(), |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 654 | connection.getStatusHints(), |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 655 | connection.getDisconnectCause(), |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame^] | 656 | createIdList(connection.getConferenceables()), |
| 657 | connection.getExtras())); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 660 | private void abort(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 661 | Log.d(this, "abort %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 662 | findConnectionForAction(callId, "abort").onAbort(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 665 | private void answerVideo(String callId, int videoState) { |
| 666 | Log.d(this, "answerVideo %s", callId); |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 667 | findConnectionForAction(callId, "answer").onAnswer(videoState); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 670 | private void answer(String callId) { |
| 671 | Log.d(this, "answer %s", callId); |
| 672 | findConnectionForAction(callId, "answer").onAnswer(); |
| 673 | } |
| 674 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 675 | private void reject(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 676 | Log.d(this, "reject %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 677 | findConnectionForAction(callId, "reject").onReject(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 680 | private void disconnect(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 681 | Log.d(this, "disconnect %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 682 | if (mConnectionById.containsKey(callId)) { |
| 683 | findConnectionForAction(callId, "disconnect").onDisconnect(); |
| 684 | } else { |
| 685 | findConferenceForAction(callId, "disconnect").onDisconnect(); |
| 686 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 689 | private void hold(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 690 | Log.d(this, "hold %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 691 | if (mConnectionById.containsKey(callId)) { |
| 692 | findConnectionForAction(callId, "hold").onHold(); |
| 693 | } else { |
| 694 | findConferenceForAction(callId, "hold").onHold(); |
| 695 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 696 | } |
| 697 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 698 | private void unhold(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 699 | Log.d(this, "unhold %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 700 | if (mConnectionById.containsKey(callId)) { |
| 701 | findConnectionForAction(callId, "unhold").onUnhold(); |
| 702 | } else { |
| 703 | findConferenceForAction(callId, "unhold").onUnhold(); |
| 704 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 707 | private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) { |
| 708 | Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 709 | if (mConnectionById.containsKey(callId)) { |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 710 | findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState( |
| 711 | callAudioState); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 712 | } else { |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 713 | findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState( |
| 714 | callAudioState); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 715 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 718 | private void playDtmfTone(String callId, char digit) { |
| 719 | Log.d(this, "playDtmfTone %s %c", callId, digit); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 720 | if (mConnectionById.containsKey(callId)) { |
| 721 | findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit); |
| 722 | } else { |
| 723 | findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit); |
| 724 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | private void stopDtmfTone(String callId) { |
| 728 | Log.d(this, "stopDtmfTone %s", callId); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 729 | if (mConnectionById.containsKey(callId)) { |
| 730 | findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone(); |
| 731 | } else { |
| 732 | findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone(); |
| 733 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 734 | } |
| 735 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 736 | private void conference(String callId1, String callId2) { |
| 737 | Log.d(this, "conference %s, %s", callId1, callId2); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 738 | |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 739 | // Attempt to get second connection or conference. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 740 | Connection connection2 = findConnectionForAction(callId2, "conference"); |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 741 | Conference conference2 = getNullConference(); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 742 | if (connection2 == getNullConnection()) { |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 743 | conference2 = findConferenceForAction(callId2, "conference"); |
| 744 | if (conference2 == getNullConference()) { |
| 745 | Log.w(this, "Connection2 or Conference2 missing in conference request %s.", |
| 746 | callId2); |
| 747 | return; |
| 748 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 749 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 750 | |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 751 | // Attempt to get first connection or conference and perform merge. |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 752 | Connection connection1 = findConnectionForAction(callId1, "conference"); |
| 753 | if (connection1 == getNullConnection()) { |
| 754 | Conference conference1 = findConferenceForAction(callId1, "addConnection"); |
| 755 | if (conference1 == getNullConference()) { |
| 756 | Log.w(this, |
| 757 | "Connection1 or Conference1 missing in conference request %s.", |
| 758 | callId1); |
| 759 | } else { |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 760 | // Call 1 is a conference. |
| 761 | if (connection2 != getNullConnection()) { |
| 762 | // Call 2 is a connection so merge via call 1 (conference). |
| 763 | conference1.onMerge(connection2); |
| 764 | } else { |
| 765 | // Call 2 is ALSO a conference; this should never happen. |
| 766 | Log.wtf(this, "There can only be one conference and an attempt was made to " + |
| 767 | "merge two conferences."); |
| 768 | return; |
| 769 | } |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 770 | } |
| 771 | } else { |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 772 | // Call 1 is a connection. |
| 773 | if (conference2 != getNullConference()) { |
| 774 | // Call 2 is a conference, so merge via call 2. |
| 775 | conference2.onMerge(connection1); |
| 776 | } else { |
| 777 | // Call 2 is a connection, so merge together. |
| 778 | onConference(connection1, connection2); |
| 779 | } |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 780 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 783 | private void splitFromConference(String callId) { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 784 | Log.d(this, "splitFromConference(%s)", callId); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 785 | |
| 786 | Connection connection = findConnectionForAction(callId, "splitFromConference"); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 787 | if (connection == getNullConnection()) { |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 788 | Log.w(this, "Connection missing in conference request %s.", callId); |
| 789 | return; |
| 790 | } |
| 791 | |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 792 | Conference conference = connection.getConference(); |
| 793 | if (conference != null) { |
| 794 | conference.onSeparate(connection); |
| 795 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 798 | private void mergeConference(String callId) { |
| 799 | Log.d(this, "mergeConference(%s)", callId); |
| 800 | Conference conference = findConferenceForAction(callId, "mergeConference"); |
| 801 | if (conference != null) { |
| 802 | conference.onMerge(); |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | private void swapConference(String callId) { |
| 807 | Log.d(this, "swapConference(%s)", callId); |
| 808 | Conference conference = findConferenceForAction(callId, "swapConference"); |
| 809 | if (conference != null) { |
| 810 | conference.onSwap(); |
| 811 | } |
| 812 | } |
| 813 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 814 | private void onPostDialContinue(String callId, boolean proceed) { |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 815 | Log.d(this, "onPostDialContinue(%s)", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 816 | findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed); |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 817 | } |
| 818 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 819 | private void onAdapterAttached() { |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 820 | if (mAreAccountsInitialized) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 821 | // No need to query again if we already did it. |
| 822 | return; |
| 823 | } |
| 824 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 825 | mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 826 | @Override |
| 827 | public void onResult( |
| 828 | final List<ComponentName> componentNames, |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 829 | final List<IBinder> services) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 830 | mHandler.post(new Runnable() { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 831 | @Override |
| 832 | public void run() { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 833 | for (int i = 0; i < componentNames.size() && i < services.size(); i++) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 834 | mRemoteConnectionManager.addConnectionService( |
| 835 | componentNames.get(i), |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 836 | IConnectionService.Stub.asInterface(services.get(i))); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 837 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 838 | onAccountsInitialized(); |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 839 | Log.d(this, "remote connection services found: " + services); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 840 | } |
| 841 | }); |
| 842 | } |
| 843 | |
| 844 | @Override |
| 845 | public void onError() { |
| 846 | mHandler.post(new Runnable() { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 847 | @Override |
| 848 | public void run() { |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 849 | mAreAccountsInitialized = true; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 850 | } |
| 851 | }); |
| 852 | } |
| 853 | }); |
| 854 | } |
| 855 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 856 | /** |
| 857 | * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 858 | * incoming request. This is used by {@code ConnectionService}s that are registered with |
| 859 | * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage |
| 860 | * SIM-based incoming calls. |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 861 | * |
| 862 | * @param connectionManagerPhoneAccount See description at |
| 863 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 864 | * @param request Details about the incoming call. |
| 865 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 866 | * not handle the call. |
| 867 | */ |
| 868 | public final RemoteConnection createRemoteIncomingConnection( |
| 869 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 870 | ConnectionRequest request) { |
| 871 | return mRemoteConnectionManager.createRemoteConnection( |
| 872 | connectionManagerPhoneAccount, request, true); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 876 | * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 877 | * outgoing request. This is used by {@code ConnectionService}s that are registered with |
| 878 | * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the |
| 879 | * SIM-based {@code ConnectionService} to place its outgoing calls. |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 880 | * |
| 881 | * @param connectionManagerPhoneAccount See description at |
| 882 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 883 | * @param request Details about the incoming call. |
| 884 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 885 | * not handle the call. |
| 886 | */ |
| 887 | public final RemoteConnection createRemoteOutgoingConnection( |
| 888 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 889 | ConnectionRequest request) { |
| 890 | return mRemoteConnectionManager.createRemoteConnection( |
| 891 | connectionManagerPhoneAccount, request, false); |
| 892 | } |
| 893 | |
| 894 | /** |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 895 | * Indicates to the relevant {@code RemoteConnectionService} that the specified |
| 896 | * {@link RemoteConnection}s should be merged into a conference call. |
| 897 | * <p> |
| 898 | * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will |
| 899 | * be invoked. |
| 900 | * |
| 901 | * @param remoteConnection1 The first of the remote connections to conference. |
| 902 | * @param remoteConnection2 The second of the remote connections to conference. |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 903 | */ |
| 904 | public final void conferenceRemoteConnections( |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 905 | RemoteConnection remoteConnection1, |
| 906 | RemoteConnection remoteConnection2) { |
| 907 | mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 911 | * Adds a new conference call. When a conference call is created either as a result of an |
| 912 | * explicit request via {@link #onConference} or otherwise, the connection service should supply |
| 913 | * an instance of {@link Conference} by invoking this method. A conference call provided by this |
| 914 | * method will persist until {@link Conference#destroy} is invoked on the conference instance. |
| 915 | * |
| 916 | * @param conference The new conference object. |
| 917 | */ |
| 918 | public final void addConference(Conference conference) { |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 919 | Log.d(this, "addConference: conference=%s", conference); |
| 920 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 921 | String id = addConferenceInternal(conference); |
| 922 | if (id != null) { |
| 923 | List<String> connectionIds = new ArrayList<>(2); |
| 924 | for (Connection connection : conference.getConnections()) { |
| 925 | if (mIdByConnection.containsKey(connection)) { |
| 926 | connectionIds.add(mIdByConnection.get(connection)); |
| 927 | } |
| 928 | } |
| 929 | ParcelableConference parcelableConference = new ParcelableConference( |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 930 | conference.getPhoneAccountHandle(), |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 931 | conference.getState(), |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 932 | conference.getConnectionCapabilities(), |
Tyler Gunn | cd5d33c | 2015-01-12 09:02:01 -0800 | [diff] [blame] | 933 | connectionIds, |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 934 | conference.getVideoProvider() == null ? |
| 935 | null : conference.getVideoProvider().getInterface(), |
| 936 | conference.getVideoState(), |
Andrew Lee | 3e3e2f2 | 2015-04-16 13:48:43 -0700 | [diff] [blame] | 937 | conference.getConnectTimeMillis(), |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame^] | 938 | conference.getStatusHints(), |
| 939 | conference.getExtras()); |
Andrew Lee | 0f51da3 | 2015-04-16 13:11:55 -0700 | [diff] [blame] | 940 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 941 | mAdapter.addConferenceCall(id, parcelableConference); |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 942 | mAdapter.setVideoProvider(id, conference.getVideoProvider()); |
| 943 | mAdapter.setVideoState(id, conference.getVideoState()); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 944 | |
| 945 | // Go through any child calls and set the parent. |
| 946 | for (Connection connection : conference.getConnections()) { |
| 947 | String connectionId = mIdByConnection.get(connection); |
| 948 | if (connectionId != null) { |
| 949 | mAdapter.setIsConferenced(connectionId, id); |
| 950 | } |
| 951 | } |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | /** |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 956 | * Adds a connection created by the {@link ConnectionService} and informs telecom of the new |
| 957 | * connection. |
| 958 | * |
| 959 | * @param phoneAccountHandle The phone account handle for the connection. |
| 960 | * @param connection The connection to add. |
| 961 | */ |
| 962 | public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle, |
| 963 | Connection connection) { |
| 964 | |
| 965 | String id = addExistingConnectionInternal(connection); |
| 966 | if (id != null) { |
| 967 | List<String> emptyList = new ArrayList<>(0); |
| 968 | |
| 969 | ParcelableConnection parcelableConnection = new ParcelableConnection( |
| 970 | phoneAccountHandle, |
| 971 | connection.getState(), |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 972 | connection.getConnectionCapabilities(), |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 973 | connection.getAddress(), |
| 974 | connection.getAddressPresentation(), |
| 975 | connection.getCallerDisplayName(), |
| 976 | connection.getCallerDisplayNamePresentation(), |
| 977 | connection.getVideoProvider() == null ? |
| 978 | null : connection.getVideoProvider().getInterface(), |
| 979 | connection.getVideoState(), |
| 980 | connection.isRingbackRequested(), |
| 981 | connection.getAudioModeIsVoip(), |
| 982 | connection.getStatusHints(), |
| 983 | connection.getDisconnectCause(), |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame^] | 984 | emptyList, |
| 985 | connection.getExtras()); |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 986 | mAdapter.addExistingConnection(id, parcelableConnection); |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 991 | * Returns all the active {@code Connection}s for which this {@code ConnectionService} |
| 992 | * has taken responsibility. |
| 993 | * |
| 994 | * @return A collection of {@code Connection}s created by this {@code ConnectionService}. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 995 | */ |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 996 | public final Collection<Connection> getAllConnections() { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 997 | return mConnectionById.values(); |
| 998 | } |
| 999 | |
| 1000 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1001 | * Create a {@code Connection} given an incoming request. This is used to attach to existing |
| 1002 | * incoming calls. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1003 | * |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1004 | * @param connectionManagerPhoneAccount See description at |
| 1005 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 1006 | * @param request Details about the incoming call. |
| 1007 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 1008 | * not handle the call. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1009 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1010 | public Connection onCreateIncomingConnection( |
| 1011 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 1012 | ConnectionRequest request) { |
| 1013 | return null; |
| 1014 | } |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 1015 | |
| 1016 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1017 | * Create a {@code Connection} given an outgoing request. This is used to initiate new |
| 1018 | * outgoing calls. |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 1019 | * |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1020 | * @param connectionManagerPhoneAccount The connection manager account to use for managing |
| 1021 | * this call. |
| 1022 | * <p> |
| 1023 | * If this parameter is not {@code null}, it means that this {@code ConnectionService} |
| 1024 | * has registered one or more {@code PhoneAccount}s having |
| 1025 | * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain |
| 1026 | * one of these {@code PhoneAccount}s, while the {@code request} will contain another |
| 1027 | * (usually but not always distinct) {@code PhoneAccount} to be used for actually |
| 1028 | * making the connection. |
| 1029 | * <p> |
| 1030 | * If this parameter is {@code null}, it means that this {@code ConnectionService} is |
| 1031 | * being asked to make a direct connection. The |
| 1032 | * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be |
| 1033 | * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for |
| 1034 | * making the connection. |
| 1035 | * @param request Details about the outgoing call. |
| 1036 | * @return The {@code Connection} object to satisfy this call, or the result of an invocation |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1037 | * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call. |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 1038 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1039 | public Connection onCreateOutgoingConnection( |
| 1040 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 1041 | ConnectionRequest request) { |
| 1042 | return null; |
| 1043 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1044 | |
| 1045 | /** |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 1046 | * Create a {@code Connection} for a new unknown call. An unknown call is a call originating |
| 1047 | * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming |
| 1048 | * call created using |
| 1049 | * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}. |
| 1050 | * |
| 1051 | * @param connectionManagerPhoneAccount |
| 1052 | * @param request |
| 1053 | * @return |
Yorke Lee | 770ed6e | 2014-10-06 18:58:52 -0700 | [diff] [blame] | 1054 | * |
| 1055 | * @hide |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 1056 | */ |
| 1057 | public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount, |
| 1058 | ConnectionRequest request) { |
| 1059 | return null; |
| 1060 | } |
| 1061 | |
| 1062 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1063 | * Conference two specified connections. Invoked when the user has made a request to merge the |
| 1064 | * specified connections into a conference call. In response, the connection service should |
| 1065 | * create an instance of {@link Conference} and pass it into {@link #addConference}. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1066 | * |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1067 | * @param connection1 A connection to merge into a conference call. |
| 1068 | * @param connection2 A connection to merge into a conference call. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1069 | */ |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1070 | public void onConference(Connection connection1, Connection connection2) {} |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1071 | |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 1072 | /** |
| 1073 | * Indicates that a remote conference has been created for existing {@link RemoteConnection}s. |
| 1074 | * When this method is invoked, this {@link ConnectionService} should create its own |
| 1075 | * representation of the conference call and send it to telecom using {@link #addConference}. |
| 1076 | * <p> |
| 1077 | * This is only relevant to {@link ConnectionService}s which are registered with |
| 1078 | * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. |
| 1079 | * |
| 1080 | * @param conference The remote conference call. |
| 1081 | */ |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 1082 | public void onRemoteConferenceAdded(RemoteConference conference) {} |
| 1083 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1084 | /** |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 1085 | * Called when an existing connection is added remotely. |
| 1086 | * @param connection The existing connection which was added. |
| 1087 | */ |
| 1088 | public void onRemoteExistingConnectionAdded(RemoteConnection connection) {} |
| 1089 | |
| 1090 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1091 | * @hide |
| 1092 | */ |
| 1093 | public boolean containsConference(Conference conference) { |
| 1094 | return mIdByConference.containsKey(conference); |
| 1095 | } |
| 1096 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 1097 | /** {@hide} */ |
| 1098 | void addRemoteConference(RemoteConference remoteConference) { |
| 1099 | onRemoteConferenceAdded(remoteConference); |
| 1100 | } |
| 1101 | |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 1102 | /** {@hide} */ |
| 1103 | void addRemoteExistingConnection(RemoteConnection remoteConnection) { |
| 1104 | onRemoteExistingConnectionAdded(remoteConnection); |
| 1105 | } |
| 1106 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 1107 | private void onAccountsInitialized() { |
| 1108 | mAreAccountsInitialized = true; |
| 1109 | for (Runnable r : mPreInitializationConnectionRequests) { |
| 1110 | r.run(); |
| 1111 | } |
| 1112 | mPreInitializationConnectionRequests.clear(); |
| 1113 | } |
| 1114 | |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 1115 | /** |
| 1116 | * Adds an existing connection to the list of connections, identified by a new UUID. |
| 1117 | * |
| 1118 | * @param connection The connection. |
| 1119 | * @return The UUID of the connection (e.g. the call-id). |
| 1120 | */ |
| 1121 | private String addExistingConnectionInternal(Connection connection) { |
| 1122 | String id = UUID.randomUUID().toString(); |
| 1123 | addConnection(id, connection); |
| 1124 | return id; |
| 1125 | } |
| 1126 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1127 | private void addConnection(String callId, Connection connection) { |
| 1128 | mConnectionById.put(callId, connection); |
| 1129 | mIdByConnection.put(connection, callId); |
| 1130 | connection.addConnectionListener(mConnectionListener); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1131 | connection.setConnectionService(this); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
Anthony Lee | 30e6584 | 2014-11-06 16:30:53 -0800 | [diff] [blame] | 1134 | /** {@hide} */ |
| 1135 | protected void removeConnection(Connection connection) { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 1136 | String id = mIdByConnection.get(connection); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1137 | connection.unsetConnectionService(this); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1138 | connection.removeConnectionListener(mConnectionListener); |
| 1139 | mConnectionById.remove(mIdByConnection.get(connection)); |
| 1140 | mIdByConnection.remove(connection); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 1141 | mAdapter.removeCall(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1144 | private String addConferenceInternal(Conference conference) { |
| 1145 | if (mIdByConference.containsKey(conference)) { |
| 1146 | Log.w(this, "Re-adding an existing conference: %s.", conference); |
| 1147 | } else if (conference != null) { |
| 1148 | String id = UUID.randomUUID().toString(); |
| 1149 | mConferenceById.put(id, conference); |
| 1150 | mIdByConference.put(conference, id); |
| 1151 | conference.addListener(mConferenceListener); |
| 1152 | return id; |
| 1153 | } |
| 1154 | |
| 1155 | return null; |
| 1156 | } |
| 1157 | |
| 1158 | private void removeConference(Conference conference) { |
| 1159 | if (mIdByConference.containsKey(conference)) { |
| 1160 | conference.removeListener(mConferenceListener); |
| 1161 | |
| 1162 | String id = mIdByConference.get(conference); |
| 1163 | mConferenceById.remove(id); |
| 1164 | mIdByConference.remove(conference); |
| 1165 | mAdapter.removeCall(id); |
| 1166 | } |
| 1167 | } |
| 1168 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1169 | private Connection findConnectionForAction(String callId, String action) { |
| 1170 | if (mConnectionById.containsKey(callId)) { |
| 1171 | return mConnectionById.get(callId); |
| 1172 | } |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 1173 | Log.w(this, "%s - Cannot find Connection %s", action, callId); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1174 | return getNullConnection(); |
| 1175 | } |
| 1176 | |
| 1177 | static synchronized Connection getNullConnection() { |
| 1178 | if (sNullConnection == null) { |
| 1179 | sNullConnection = new Connection() {}; |
| 1180 | } |
| 1181 | return sNullConnection; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1182 | } |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 1183 | |
| 1184 | private Conference findConferenceForAction(String conferenceId, String action) { |
| 1185 | if (mConferenceById.containsKey(conferenceId)) { |
| 1186 | return mConferenceById.get(conferenceId); |
| 1187 | } |
| 1188 | Log.w(this, "%s - Cannot find conference %s", action, conferenceId); |
| 1189 | return getNullConference(); |
| 1190 | } |
| 1191 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 1192 | private List<String> createConnectionIdList(List<Connection> connections) { |
| 1193 | List<String> ids = new ArrayList<>(); |
| 1194 | for (Connection c : connections) { |
| 1195 | if (mIdByConnection.containsKey(c)) { |
| 1196 | ids.add(mIdByConnection.get(c)); |
| 1197 | } |
| 1198 | } |
| 1199 | Collections.sort(ids); |
| 1200 | return ids; |
| 1201 | } |
| 1202 | |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1203 | /** |
| 1204 | * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of |
Tyler Gunn | df2cbc8 | 2015-04-20 09:13:01 -0700 | [diff] [blame] | 1205 | * {@link Conferenceable}s passed in. |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1206 | * |
Tyler Gunn | df2cbc8 | 2015-04-20 09:13:01 -0700 | [diff] [blame] | 1207 | * @param conferenceables The {@link Conferenceable} connections and conferences. |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1208 | * @return List of string conference and call Ids. |
| 1209 | */ |
Tyler Gunn | df2cbc8 | 2015-04-20 09:13:01 -0700 | [diff] [blame] | 1210 | private List<String> createIdList(List<Conferenceable> conferenceables) { |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1211 | List<String> ids = new ArrayList<>(); |
Tyler Gunn | df2cbc8 | 2015-04-20 09:13:01 -0700 | [diff] [blame] | 1212 | for (Conferenceable c : conferenceables) { |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1213 | // Only allow Connection and Conference conferenceables. |
| 1214 | if (c instanceof Connection) { |
| 1215 | Connection connection = (Connection) c; |
| 1216 | if (mIdByConnection.containsKey(connection)) { |
| 1217 | ids.add(mIdByConnection.get(connection)); |
| 1218 | } |
| 1219 | } else if (c instanceof Conference) { |
| 1220 | Conference conference = (Conference) c; |
| 1221 | if (mIdByConference.containsKey(conference)) { |
| 1222 | ids.add(mIdByConference.get(conference)); |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | Collections.sort(ids); |
| 1227 | return ids; |
| 1228 | } |
| 1229 | |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 1230 | private Conference getNullConference() { |
| 1231 | if (sNullConference == null) { |
| 1232 | sNullConference = new Conference(null) {}; |
| 1233 | } |
| 1234 | return sNullConference; |
| 1235 | } |
Santos Cordon | 29f2f2e | 2014-09-11 19:50:24 -0700 | [diff] [blame] | 1236 | |
| 1237 | private void endAllConnections() { |
| 1238 | // Unbound from telecomm. We should end all connections and conferences. |
| 1239 | for (Connection connection : mIdByConnection.keySet()) { |
| 1240 | // only operate on top-level calls. Conference calls will be removed on their own. |
| 1241 | if (connection.getConference() == null) { |
| 1242 | connection.onDisconnect(); |
| 1243 | } |
| 1244 | } |
| 1245 | for (Conference conference : mIdByConference.keySet()) { |
| 1246 | conference.onDisconnect(); |
| 1247 | } |
| 1248 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 1249 | } |