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 | |
Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 20 | import android.annotation.SdkConstant; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 21 | import android.app.Service; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 22 | import android.content.ComponentName; |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 23 | import android.content.Intent; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 24 | import android.net.Uri; |
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 | /** |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 44 | * A {@link android.app.Service} that provides telephone connections to processes running on an |
| 45 | * Android device. |
Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 46 | * @hide |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 47 | */ |
Tyler Gunn | 711d876fd | 2014-09-19 11:17:02 -0700 | [diff] [blame] | 48 | @SystemApi |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 49 | public abstract class ConnectionService extends Service { |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 50 | /** |
| 51 | * The {@link Intent} that must be declared as handled by the service. |
| 52 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 53 | @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 54 | public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService"; |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 55 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 56 | // Flag controlling whether PII is emitted into the logs |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 57 | private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 58 | |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 59 | private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1; |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 60 | private static final int MSG_CREATE_CONNECTION = 2; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 61 | private static final int MSG_ABORT = 3; |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 62 | private static final int MSG_ANSWER = 4; |
| 63 | private static final int MSG_REJECT = 5; |
| 64 | private static final int MSG_DISCONNECT = 6; |
| 65 | private static final int MSG_HOLD = 7; |
| 66 | private static final int MSG_UNHOLD = 8; |
| 67 | private static final int MSG_ON_AUDIO_STATE_CHANGED = 9; |
| 68 | private static final int MSG_PLAY_DTMF_TONE = 10; |
| 69 | private static final int MSG_STOP_DTMF_TONE = 11; |
| 70 | private static final int MSG_CONFERENCE = 12; |
| 71 | private static final int MSG_SPLIT_FROM_CONFERENCE = 13; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 72 | private static final int MSG_ON_POST_DIAL_CONTINUE = 14; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 73 | private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 74 | private static final int MSG_ANSWER_VIDEO = 17; |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 75 | private static final int MSG_MERGE_CONFERENCE = 18; |
| 76 | private static final int MSG_SWAP_CONFERENCE = 19; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 77 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 78 | private static Connection sNullConnection; |
| 79 | |
mike dooley | 95e8070 | 2014-09-18 14:07:52 -0700 | [diff] [blame^] | 80 | private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>(); |
| 81 | private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>(); |
| 82 | private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>(); |
| 83 | private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 84 | private final RemoteConnectionManager mRemoteConnectionManager = |
| 85 | new RemoteConnectionManager(this); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 86 | private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 87 | private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 88 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 89 | private boolean mAreAccountsInitialized = false; |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 90 | private Conference sNullConference; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 91 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 92 | private final IBinder mBinder = new IConnectionService.Stub() { |
| 93 | @Override |
| 94 | public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter) { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 95 | mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, adapter).sendToTarget(); |
| 96 | } |
| 97 | |
| 98 | public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter) { |
| 99 | mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, adapter).sendToTarget(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 103 | public void createConnection( |
| 104 | PhoneAccountHandle connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 105 | String id, |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 106 | ConnectionRequest request, |
| 107 | boolean isIncoming) { |
| 108 | SomeArgs args = SomeArgs.obtain(); |
| 109 | args.arg1 = connectionManagerPhoneAccount; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 110 | args.arg2 = id; |
| 111 | args.arg3 = request; |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 112 | args.argi1 = isIncoming ? 1 : 0; |
| 113 | mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public void abort(String callId) { |
| 118 | mHandler.obtainMessage(MSG_ABORT, callId).sendToTarget(); |
| 119 | } |
| 120 | |
| 121 | @Override |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 122 | /** @hide */ |
| 123 | public void answerVideo(String callId, int videoState) { |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 124 | SomeArgs args = SomeArgs.obtain(); |
| 125 | args.arg1 = callId; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 126 | args.argi1 = videoState; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 127 | mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget(); |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public void answer(String callId) { |
| 132 | mHandler.obtainMessage(MSG_ANSWER, callId).sendToTarget(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public void reject(String callId) { |
| 137 | mHandler.obtainMessage(MSG_REJECT, callId).sendToTarget(); |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public void disconnect(String callId) { |
| 142 | mHandler.obtainMessage(MSG_DISCONNECT, callId).sendToTarget(); |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void hold(String callId) { |
| 147 | mHandler.obtainMessage(MSG_HOLD, callId).sendToTarget(); |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public void unhold(String callId) { |
| 152 | mHandler.obtainMessage(MSG_UNHOLD, callId).sendToTarget(); |
| 153 | } |
| 154 | |
| 155 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 156 | public void onAudioStateChanged(String callId, AudioState audioState) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 157 | SomeArgs args = SomeArgs.obtain(); |
| 158 | args.arg1 = callId; |
| 159 | args.arg2 = audioState; |
| 160 | mHandler.obtainMessage(MSG_ON_AUDIO_STATE_CHANGED, args).sendToTarget(); |
| 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public void playDtmfTone(String callId, char digit) { |
| 165 | mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, digit, 0, callId).sendToTarget(); |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void stopDtmfTone(String callId) { |
| 170 | mHandler.obtainMessage(MSG_STOP_DTMF_TONE, callId).sendToTarget(); |
| 171 | } |
| 172 | |
| 173 | @Override |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 174 | public void conference(String callId1, String callId2) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 175 | SomeArgs args = SomeArgs.obtain(); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 176 | args.arg1 = callId1; |
| 177 | args.arg2 = callId2; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 178 | mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget(); |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public void splitFromConference(String callId) { |
| 183 | mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, callId).sendToTarget(); |
| 184 | } |
| 185 | |
| 186 | @Override |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 187 | public void mergeConference(String callId) { |
| 188 | mHandler.obtainMessage(MSG_MERGE_CONFERENCE, callId).sendToTarget(); |
| 189 | } |
| 190 | |
| 191 | @Override |
| 192 | public void swapConference(String callId) { |
| 193 | mHandler.obtainMessage(MSG_SWAP_CONFERENCE, callId).sendToTarget(); |
| 194 | } |
| 195 | |
| 196 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 197 | public void onPostDialContinue(String callId, boolean proceed) { |
| 198 | SomeArgs args = SomeArgs.obtain(); |
| 199 | args.arg1 = callId; |
| 200 | args.argi1 = proceed ? 1 : 0; |
| 201 | mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget(); |
| 202 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | private final Handler mHandler = new Handler(Looper.getMainLooper()) { |
| 206 | @Override |
| 207 | public void handleMessage(Message msg) { |
| 208 | switch (msg.what) { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 209 | case MSG_ADD_CONNECTION_SERVICE_ADAPTER: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 210 | mAdapter.addAdapter((IConnectionServiceAdapter) msg.obj); |
| 211 | onAdapterAttached(); |
| 212 | break; |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 213 | case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: |
| 214 | mAdapter.removeAdapter((IConnectionServiceAdapter) msg.obj); |
| 215 | break; |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 216 | case MSG_CREATE_CONNECTION: { |
| 217 | SomeArgs args = (SomeArgs) msg.obj; |
| 218 | try { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 219 | final PhoneAccountHandle connectionManagerPhoneAccount = |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 220 | (PhoneAccountHandle) args.arg1; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 221 | final String id = (String) args.arg2; |
| 222 | final ConnectionRequest request = (ConnectionRequest) args.arg3; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 223 | final boolean isIncoming = args.argi1 == 1; |
| 224 | if (!mAreAccountsInitialized) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 225 | Log.d(this, "Enqueueing pre-init request %s", id); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 226 | mPreInitializationConnectionRequests.add(new Runnable() { |
| 227 | @Override |
| 228 | public void run() { |
| 229 | createConnection( |
| 230 | connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 231 | id, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 232 | request, |
| 233 | isIncoming); |
| 234 | } |
| 235 | }); |
| 236 | } else { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 237 | createConnection( |
| 238 | connectionManagerPhoneAccount, |
| 239 | id, |
| 240 | request, |
| 241 | isIncoming); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 242 | } |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 243 | } finally { |
| 244 | args.recycle(); |
| 245 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 246 | break; |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 247 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 248 | case MSG_ABORT: |
| 249 | abort((String) msg.obj); |
| 250 | break; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 251 | case MSG_ANSWER: |
| 252 | answer((String) msg.obj); |
| 253 | break; |
| 254 | case MSG_ANSWER_VIDEO: { |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 255 | SomeArgs args = (SomeArgs) msg.obj; |
| 256 | try { |
| 257 | String callId = (String) args.arg1; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 258 | int videoState = args.argi1; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 259 | answerVideo(callId, videoState); |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 260 | } finally { |
| 261 | args.recycle(); |
| 262 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 263 | break; |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 264 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 265 | case MSG_REJECT: |
| 266 | reject((String) msg.obj); |
| 267 | break; |
| 268 | case MSG_DISCONNECT: |
| 269 | disconnect((String) msg.obj); |
| 270 | break; |
| 271 | case MSG_HOLD: |
| 272 | hold((String) msg.obj); |
| 273 | break; |
| 274 | case MSG_UNHOLD: |
| 275 | unhold((String) msg.obj); |
| 276 | break; |
| 277 | case MSG_ON_AUDIO_STATE_CHANGED: { |
| 278 | SomeArgs args = (SomeArgs) msg.obj; |
| 279 | try { |
| 280 | String callId = (String) args.arg1; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 281 | AudioState audioState = (AudioState) args.arg2; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 282 | onAudioStateChanged(callId, audioState); |
| 283 | } finally { |
| 284 | args.recycle(); |
| 285 | } |
| 286 | break; |
| 287 | } |
| 288 | case MSG_PLAY_DTMF_TONE: |
| 289 | playDtmfTone((String) msg.obj, (char) msg.arg1); |
| 290 | break; |
| 291 | case MSG_STOP_DTMF_TONE: |
| 292 | stopDtmfTone((String) msg.obj); |
| 293 | break; |
| 294 | case MSG_CONFERENCE: { |
| 295 | SomeArgs args = (SomeArgs) msg.obj; |
| 296 | try { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 297 | String callId1 = (String) args.arg1; |
| 298 | String callId2 = (String) args.arg2; |
| 299 | conference(callId1, callId2); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 300 | } finally { |
| 301 | args.recycle(); |
| 302 | } |
| 303 | break; |
| 304 | } |
| 305 | case MSG_SPLIT_FROM_CONFERENCE: |
| 306 | splitFromConference((String) msg.obj); |
| 307 | break; |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 308 | case MSG_MERGE_CONFERENCE: |
| 309 | mergeConference((String) msg.obj); |
| 310 | break; |
| 311 | case MSG_SWAP_CONFERENCE: |
| 312 | swapConference((String) msg.obj); |
| 313 | break; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 314 | case MSG_ON_POST_DIAL_CONTINUE: { |
| 315 | SomeArgs args = (SomeArgs) msg.obj; |
| 316 | try { |
| 317 | String callId = (String) args.arg1; |
| 318 | boolean proceed = (args.argi1 == 1); |
| 319 | onPostDialContinue(callId, proceed); |
| 320 | } finally { |
| 321 | args.recycle(); |
| 322 | } |
| 323 | break; |
| 324 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 325 | default: |
| 326 | break; |
| 327 | } |
| 328 | } |
| 329 | }; |
| 330 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 331 | private final Conference.Listener mConferenceListener = new Conference.Listener() { |
| 332 | @Override |
| 333 | public void onStateChanged(Conference conference, int oldState, int newState) { |
| 334 | String id = mIdByConference.get(conference); |
| 335 | switch (newState) { |
| 336 | case Connection.STATE_ACTIVE: |
| 337 | mAdapter.setActive(id); |
| 338 | break; |
| 339 | case Connection.STATE_HOLDING: |
| 340 | mAdapter.setOnHold(id); |
| 341 | break; |
| 342 | case Connection.STATE_DISCONNECTED: |
| 343 | // handled by onDisconnected |
| 344 | break; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | @Override |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 349 | public void onDisconnected(Conference conference, DisconnectCause disconnectCause) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 350 | String id = mIdByConference.get(conference); |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 351 | mAdapter.setDisconnected(id, disconnectCause); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | @Override |
| 355 | public void onConnectionAdded(Conference conference, Connection connection) { |
| 356 | } |
| 357 | |
| 358 | @Override |
| 359 | public void onConnectionRemoved(Conference conference, Connection connection) { |
| 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public void onDestroyed(Conference conference) { |
| 364 | removeConference(conference); |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public void onCapabilitiesChanged(Conference conference, int capabilities) { |
| 369 | String id = mIdByConference.get(conference); |
| 370 | Log.d(this, "call capabilities: conference: %s", |
| 371 | PhoneCapabilities.toString(capabilities)); |
| 372 | mAdapter.setCallCapabilities(id, capabilities); |
| 373 | } |
| 374 | }; |
| 375 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 376 | private final Connection.Listener mConnectionListener = new Connection.Listener() { |
| 377 | @Override |
| 378 | public void onStateChanged(Connection c, int state) { |
| 379 | String id = mIdByConnection.get(c); |
Ihab Awad | 42b30e1 | 2014-05-22 09:49:34 -0700 | [diff] [blame] | 380 | Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state)); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 381 | switch (state) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 382 | case Connection.STATE_ACTIVE: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 383 | mAdapter.setActive(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 384 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 385 | case Connection.STATE_DIALING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 386 | mAdapter.setDialing(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 387 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 388 | case Connection.STATE_DISCONNECTED: |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 389 | // Handled in onDisconnected() |
| 390 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 391 | case Connection.STATE_HOLDING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 392 | mAdapter.setOnHold(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 393 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 394 | case Connection.STATE_NEW: |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 395 | // Nothing to tell Telecom |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 396 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 397 | case Connection.STATE_RINGING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 398 | mAdapter.setRinging(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 399 | break; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | @Override |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 404 | public void onDisconnected(Connection c, DisconnectCause disconnectCause) { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 405 | String id = mIdByConnection.get(c); |
Andrew Lee | 2678639 | 2014-09-16 18:14:59 -0700 | [diff] [blame] | 406 | Log.d(this, "Adapter set disconnected %s", disconnectCause); |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 407 | mAdapter.setDisconnected(id, disconnectCause); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | @Override |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 411 | public void onVideoStateChanged(Connection c, int videoState) { |
| 412 | String id = mIdByConnection.get(c); |
| 413 | Log.d(this, "Adapter set video state %d", videoState); |
| 414 | mAdapter.setVideoState(id, videoState); |
| 415 | } |
| 416 | |
| 417 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 418 | public void onAddressChanged(Connection c, Uri address, int presentation) { |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 419 | String id = mIdByConnection.get(c); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 420 | mAdapter.setAddress(id, address, presentation); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | @Override |
| 424 | public void onCallerDisplayNameChanged( |
| 425 | Connection c, String callerDisplayName, int presentation) { |
| 426 | String id = mIdByConnection.get(c); |
| 427 | mAdapter.setCallerDisplayName(id, callerDisplayName, presentation); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | @Override |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 431 | public void onDestroyed(Connection c) { |
| 432 | removeConnection(c); |
| 433 | } |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 434 | |
| 435 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 436 | public void onPostDialWait(Connection c, String remaining) { |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 437 | String id = mIdByConnection.get(c); |
| 438 | Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 439 | mAdapter.onPostDialWait(id, remaining); |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 443 | public void onRingbackRequested(Connection c, boolean ringback) { |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 444 | String id = mIdByConnection.get(c); |
| 445 | Log.d(this, "Adapter onRingback %b", ringback); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 446 | mAdapter.setRingbackRequested(id, ringback); |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 447 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 448 | |
| 449 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 450 | public void onCallCapabilitiesChanged(Connection c, int capabilities) { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 451 | String id = mIdByConnection.get(c); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 452 | Log.d(this, "capabilities: parcelableconnection: %s", |
| 453 | PhoneCapabilities.toString(capabilities)); |
| 454 | mAdapter.setCallCapabilities(id, capabilities); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 457 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 458 | public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) { |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 459 | String id = mIdByConnection.get(c); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 460 | mAdapter.setVideoProvider(id, videoProvider); |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 461 | } |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 462 | |
| 463 | @Override |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 464 | public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) { |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 465 | String id = mIdByConnection.get(c); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 466 | mAdapter.setIsVoipAudioMode(id, isVoip); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 467 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 468 | |
| 469 | @Override |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 470 | public void onStatusHintsChanged(Connection c, StatusHints statusHints) { |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 471 | String id = mIdByConnection.get(c); |
| 472 | mAdapter.setStatusHints(id, statusHints); |
| 473 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 474 | |
| 475 | @Override |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 476 | public void onConferenceableConnectionsChanged( |
| 477 | Connection connection, List<Connection> conferenceableConnections) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 478 | mAdapter.setConferenceableConnections( |
| 479 | mIdByConnection.get(connection), |
| 480 | createConnectionIdList(conferenceableConnections)); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 481 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 482 | |
| 483 | @Override |
| 484 | public void onConferenceChanged(Connection connection, Conference conference) { |
| 485 | String id = mIdByConnection.get(connection); |
| 486 | if (id != null) { |
| 487 | String conferenceId = null; |
| 488 | if (conference != null) { |
| 489 | conferenceId = mIdByConference.get(conference); |
| 490 | } |
| 491 | mAdapter.setIsConferenced(id, conferenceId); |
| 492 | } |
| 493 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 494 | }; |
| 495 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 496 | /** {@inheritDoc} */ |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 497 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 498 | public final IBinder onBind(Intent intent) { |
| 499 | return mBinder; |
| 500 | } |
| 501 | |
Santos Cordon | 29f2f2e | 2014-09-11 19:50:24 -0700 | [diff] [blame] | 502 | /** {@inheritDoc} */ |
| 503 | @Override |
| 504 | public boolean onUnbind(Intent intent) { |
| 505 | endAllConnections(); |
| 506 | return super.onUnbind(intent); |
| 507 | } |
| 508 | |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 509 | /** |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 510 | * This can be used by telecom to either create a new outgoing call or attach to an existing |
| 511 | * 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] | 512 | * createConnection util a connection service cancels the process or completes it successfully. |
| 513 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 514 | private void createConnection( |
| 515 | final PhoneAccountHandle callManagerAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 516 | final String callId, |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 517 | final ConnectionRequest request, |
| 518 | boolean isIncoming) { |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 519 | Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " + |
| 520 | "isIncoming: %b", callManagerAccount, callId, request, isIncoming); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 521 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 522 | Connection connection = isIncoming |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 523 | ? onCreateIncomingConnection(callManagerAccount, request) |
| 524 | : onCreateOutgoingConnection(callManagerAccount, request); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 525 | Log.d(this, "createConnection, connection: %s", connection); |
| 526 | if (connection == null) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 527 | connection = Connection.createFailedConnection( |
| 528 | new DisconnectCause(DisconnectCause.ERROR)); |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 529 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 530 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 531 | if (connection.getState() != Connection.STATE_DISCONNECTED) { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 532 | addConnection(callId, connection); |
| 533 | } |
| 534 | |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 535 | Uri address = connection.getAddress(); |
| 536 | String number = address == null ? "null" : address.getSchemeSpecificPart(); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 537 | Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s", |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 538 | Connection.toLogSafePhoneNumber(number), |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 539 | Connection.stateToString(connection.getState()), |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 540 | PhoneCapabilities.toString(connection.getCallCapabilities())); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 541 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 542 | Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 543 | mAdapter.handleCreateConnectionComplete( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 544 | callId, |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 545 | request, |
| 546 | new ParcelableConnection( |
| 547 | request.getAccountHandle(), |
| 548 | connection.getState(), |
| 549 | connection.getCallCapabilities(), |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 550 | connection.getAddress(), |
| 551 | connection.getAddressPresentation(), |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 552 | connection.getCallerDisplayName(), |
| 553 | connection.getCallerDisplayNamePresentation(), |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 554 | connection.getVideoProvider() == null ? |
| 555 | null : connection.getVideoProvider().getInterface(), |
Sailesh Nepal | 8b9d3ca | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 556 | connection.getVideoState(), |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 557 | connection.isRingbackRequested(), |
Sailesh Nepal | 8b9d3ca | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 558 | connection.getAudioModeIsVoip(), |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 559 | connection.getStatusHints(), |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 560 | connection.getDisconnectCause(), |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 561 | createConnectionIdList(connection.getConferenceableConnections()))); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 564 | private void abort(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 565 | Log.d(this, "abort %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 566 | findConnectionForAction(callId, "abort").onAbort(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 569 | private void answerVideo(String callId, int videoState) { |
| 570 | Log.d(this, "answerVideo %s", callId); |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 571 | findConnectionForAction(callId, "answer").onAnswer(videoState); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 574 | private void answer(String callId) { |
| 575 | Log.d(this, "answer %s", callId); |
| 576 | findConnectionForAction(callId, "answer").onAnswer(); |
| 577 | } |
| 578 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 579 | private void reject(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 580 | Log.d(this, "reject %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 581 | findConnectionForAction(callId, "reject").onReject(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 584 | private void disconnect(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 585 | Log.d(this, "disconnect %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 586 | if (mConnectionById.containsKey(callId)) { |
| 587 | findConnectionForAction(callId, "disconnect").onDisconnect(); |
| 588 | } else { |
| 589 | findConferenceForAction(callId, "disconnect").onDisconnect(); |
| 590 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 593 | private void hold(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 594 | Log.d(this, "hold %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 595 | if (mConnectionById.containsKey(callId)) { |
| 596 | findConnectionForAction(callId, "hold").onHold(); |
| 597 | } else { |
| 598 | findConferenceForAction(callId, "hold").onHold(); |
| 599 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 602 | private void unhold(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 603 | Log.d(this, "unhold %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 604 | if (mConnectionById.containsKey(callId)) { |
| 605 | findConnectionForAction(callId, "unhold").onUnhold(); |
| 606 | } else { |
| 607 | findConferenceForAction(callId, "unhold").onUnhold(); |
| 608 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 611 | private void onAudioStateChanged(String callId, AudioState audioState) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 612 | Log.d(this, "onAudioStateChanged %s %s", callId, audioState); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 613 | if (mConnectionById.containsKey(callId)) { |
| 614 | findConnectionForAction(callId, "onAudioStateChanged").setAudioState(audioState); |
| 615 | } else { |
| 616 | findConferenceForAction(callId, "onAudioStateChanged").setAudioState(audioState); |
| 617 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 620 | private void playDtmfTone(String callId, char digit) { |
| 621 | Log.d(this, "playDtmfTone %s %c", callId, digit); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 622 | if (mConnectionById.containsKey(callId)) { |
| 623 | findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit); |
| 624 | } else { |
| 625 | findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit); |
| 626 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | private void stopDtmfTone(String callId) { |
| 630 | Log.d(this, "stopDtmfTone %s", callId); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 631 | if (mConnectionById.containsKey(callId)) { |
| 632 | findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone(); |
| 633 | } else { |
| 634 | findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone(); |
| 635 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 638 | private void conference(String callId1, String callId2) { |
| 639 | Log.d(this, "conference %s, %s", callId1, callId2); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 640 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 641 | Connection connection1 = findConnectionForAction(callId1, "conference"); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 642 | if (connection1 == getNullConnection()) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 643 | Log.w(this, "Connection1 missing in conference request %s.", callId1); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 644 | return; |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 647 | Connection connection2 = findConnectionForAction(callId2, "conference"); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 648 | if (connection2 == getNullConnection()) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 649 | Log.w(this, "Connection2 missing in conference request %s.", callId2); |
| 650 | return; |
| 651 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 652 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 653 | onConference(connection1, connection2); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 656 | private void splitFromConference(String callId) { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 657 | Log.d(this, "splitFromConference(%s)", callId); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 658 | |
| 659 | Connection connection = findConnectionForAction(callId, "splitFromConference"); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 660 | if (connection == getNullConnection()) { |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 661 | Log.w(this, "Connection missing in conference request %s.", callId); |
| 662 | return; |
| 663 | } |
| 664 | |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 665 | Conference conference = connection.getConference(); |
| 666 | if (conference != null) { |
| 667 | conference.onSeparate(connection); |
| 668 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 671 | private void mergeConference(String callId) { |
| 672 | Log.d(this, "mergeConference(%s)", callId); |
| 673 | Conference conference = findConferenceForAction(callId, "mergeConference"); |
| 674 | if (conference != null) { |
| 675 | conference.onMerge(); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | private void swapConference(String callId) { |
| 680 | Log.d(this, "swapConference(%s)", callId); |
| 681 | Conference conference = findConferenceForAction(callId, "swapConference"); |
| 682 | if (conference != null) { |
| 683 | conference.onSwap(); |
| 684 | } |
| 685 | } |
| 686 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 687 | private void onPostDialContinue(String callId, boolean proceed) { |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 688 | Log.d(this, "onPostDialContinue(%s)", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 689 | findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed); |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 692 | private void onAdapterAttached() { |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 693 | if (mAreAccountsInitialized) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 694 | // No need to query again if we already did it. |
| 695 | return; |
| 696 | } |
| 697 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 698 | mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 699 | @Override |
| 700 | public void onResult( |
| 701 | final List<ComponentName> componentNames, |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 702 | final List<IBinder> services) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 703 | mHandler.post(new Runnable() { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 704 | @Override |
| 705 | public void run() { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 706 | for (int i = 0; i < componentNames.size() && i < services.size(); i++) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 707 | mRemoteConnectionManager.addConnectionService( |
| 708 | componentNames.get(i), |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 709 | IConnectionService.Stub.asInterface(services.get(i))); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 710 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 711 | onAccountsInitialized(); |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 712 | Log.d(this, "remote connection services found: " + services); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 713 | } |
| 714 | }); |
| 715 | } |
| 716 | |
| 717 | @Override |
| 718 | public void onError() { |
| 719 | mHandler.post(new Runnable() { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 720 | @Override |
| 721 | public void run() { |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 722 | mAreAccountsInitialized = true; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 723 | } |
| 724 | }); |
| 725 | } |
| 726 | }); |
| 727 | } |
| 728 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 729 | /** |
| 730 | * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an |
| 731 | * incoming request. This is used to attach to existing incoming calls. |
| 732 | * |
| 733 | * @param connectionManagerPhoneAccount See description at |
| 734 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 735 | * @param request Details about the incoming call. |
| 736 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 737 | * not handle the call. |
| 738 | */ |
| 739 | public final RemoteConnection createRemoteIncomingConnection( |
| 740 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 741 | ConnectionRequest request) { |
| 742 | return mRemoteConnectionManager.createRemoteConnection( |
| 743 | connectionManagerPhoneAccount, request, true); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 747 | * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an |
| 748 | * outgoing request. This is used to initiate new outgoing calls. |
| 749 | * |
| 750 | * @param connectionManagerPhoneAccount See description at |
| 751 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 752 | * @param request Details about the incoming call. |
| 753 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 754 | * not handle the call. |
| 755 | */ |
| 756 | public final RemoteConnection createRemoteOutgoingConnection( |
| 757 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 758 | ConnectionRequest request) { |
| 759 | return mRemoteConnectionManager.createRemoteConnection( |
| 760 | connectionManagerPhoneAccount, request, false); |
| 761 | } |
| 762 | |
| 763 | /** |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 764 | * Adds two {@code RemoteConnection}s to some {@code RemoteConference}. |
| 765 | */ |
| 766 | public final void conferenceRemoteConnections( |
| 767 | RemoteConnection a, |
| 768 | RemoteConnection b) { |
| 769 | mRemoteConnectionManager.conferenceRemoteConnections(a, b); |
| 770 | } |
| 771 | |
| 772 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 773 | * Adds a new conference call. When a conference call is created either as a result of an |
| 774 | * explicit request via {@link #onConference} or otherwise, the connection service should supply |
| 775 | * an instance of {@link Conference} by invoking this method. A conference call provided by this |
| 776 | * method will persist until {@link Conference#destroy} is invoked on the conference instance. |
| 777 | * |
| 778 | * @param conference The new conference object. |
| 779 | */ |
| 780 | public final void addConference(Conference conference) { |
| 781 | String id = addConferenceInternal(conference); |
| 782 | if (id != null) { |
| 783 | List<String> connectionIds = new ArrayList<>(2); |
| 784 | for (Connection connection : conference.getConnections()) { |
| 785 | if (mIdByConnection.containsKey(connection)) { |
| 786 | connectionIds.add(mIdByConnection.get(connection)); |
| 787 | } |
| 788 | } |
| 789 | ParcelableConference parcelableConference = new ParcelableConference( |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 790 | conference.getPhoneAccountHandle(), |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 791 | conference.getState(), |
| 792 | conference.getCapabilities(), |
| 793 | connectionIds); |
| 794 | mAdapter.addConferenceCall(id, parcelableConference); |
| 795 | |
| 796 | // Go through any child calls and set the parent. |
| 797 | for (Connection connection : conference.getConnections()) { |
| 798 | String connectionId = mIdByConnection.get(connection); |
| 799 | if (connectionId != null) { |
| 800 | mAdapter.setIsConferenced(connectionId, id); |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 807 | * Returns all the active {@code Connection}s for which this {@code ConnectionService} |
| 808 | * has taken responsibility. |
| 809 | * |
| 810 | * @return A collection of {@code Connection}s created by this {@code ConnectionService}. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 811 | */ |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 812 | public final Collection<Connection> getAllConnections() { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 813 | return mConnectionById.values(); |
| 814 | } |
| 815 | |
| 816 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 817 | * Create a {@code Connection} given an incoming request. This is used to attach to existing |
| 818 | * incoming calls. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 819 | * |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 820 | * @param connectionManagerPhoneAccount See description at |
| 821 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 822 | * @param request Details about the incoming call. |
| 823 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 824 | * not handle the call. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 825 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 826 | public Connection onCreateIncomingConnection( |
| 827 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 828 | ConnectionRequest request) { |
| 829 | return null; |
| 830 | } |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 831 | |
| 832 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 833 | * Create a {@code Connection} given an outgoing request. This is used to initiate new |
| 834 | * outgoing calls. |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 835 | * |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 836 | * @param connectionManagerPhoneAccount The connection manager account to use for managing |
| 837 | * this call. |
| 838 | * <p> |
| 839 | * If this parameter is not {@code null}, it means that this {@code ConnectionService} |
| 840 | * has registered one or more {@code PhoneAccount}s having |
| 841 | * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain |
| 842 | * one of these {@code PhoneAccount}s, while the {@code request} will contain another |
| 843 | * (usually but not always distinct) {@code PhoneAccount} to be used for actually |
| 844 | * making the connection. |
| 845 | * <p> |
| 846 | * If this parameter is {@code null}, it means that this {@code ConnectionService} is |
| 847 | * being asked to make a direct connection. The |
| 848 | * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be |
| 849 | * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for |
| 850 | * making the connection. |
| 851 | * @param request Details about the outgoing call. |
| 852 | * @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] | 853 | * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call. |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 854 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 855 | public Connection onCreateOutgoingConnection( |
| 856 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 857 | ConnectionRequest request) { |
| 858 | return null; |
| 859 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 860 | |
| 861 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 862 | * Conference two specified connections. Invoked when the user has made a request to merge the |
| 863 | * specified connections into a conference call. In response, the connection service should |
| 864 | * create an instance of {@link Conference} and pass it into {@link #addConference}. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 865 | * |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 866 | * @param connection1 A connection to merge into a conference call. |
| 867 | * @param connection2 A connection to merge into a conference call. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 868 | */ |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 869 | public void onConference(Connection connection1, Connection connection2) {} |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 870 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 871 | public void onRemoteConferenceAdded(RemoteConference conference) {} |
| 872 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 873 | /** |
| 874 | * @hide |
| 875 | */ |
| 876 | public boolean containsConference(Conference conference) { |
| 877 | return mIdByConference.containsKey(conference); |
| 878 | } |
| 879 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 880 | /** {@hide} */ |
| 881 | void addRemoteConference(RemoteConference remoteConference) { |
| 882 | onRemoteConferenceAdded(remoteConference); |
| 883 | } |
| 884 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 885 | private void onAccountsInitialized() { |
| 886 | mAreAccountsInitialized = true; |
| 887 | for (Runnable r : mPreInitializationConnectionRequests) { |
| 888 | r.run(); |
| 889 | } |
| 890 | mPreInitializationConnectionRequests.clear(); |
| 891 | } |
| 892 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 893 | private void addConnection(String callId, Connection connection) { |
| 894 | mConnectionById.put(callId, connection); |
| 895 | mIdByConnection.put(connection, callId); |
| 896 | connection.addConnectionListener(mConnectionListener); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 897 | connection.setConnectionService(this); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | private void removeConnection(Connection connection) { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 901 | String id = mIdByConnection.get(connection); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 902 | connection.unsetConnectionService(this); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 903 | connection.removeConnectionListener(mConnectionListener); |
| 904 | mConnectionById.remove(mIdByConnection.get(connection)); |
| 905 | mIdByConnection.remove(connection); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 906 | mAdapter.removeCall(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 907 | } |
| 908 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 909 | private String addConferenceInternal(Conference conference) { |
| 910 | if (mIdByConference.containsKey(conference)) { |
| 911 | Log.w(this, "Re-adding an existing conference: %s.", conference); |
| 912 | } else if (conference != null) { |
| 913 | String id = UUID.randomUUID().toString(); |
| 914 | mConferenceById.put(id, conference); |
| 915 | mIdByConference.put(conference, id); |
| 916 | conference.addListener(mConferenceListener); |
| 917 | return id; |
| 918 | } |
| 919 | |
| 920 | return null; |
| 921 | } |
| 922 | |
| 923 | private void removeConference(Conference conference) { |
| 924 | if (mIdByConference.containsKey(conference)) { |
| 925 | conference.removeListener(mConferenceListener); |
| 926 | |
| 927 | String id = mIdByConference.get(conference); |
| 928 | mConferenceById.remove(id); |
| 929 | mIdByConference.remove(conference); |
| 930 | mAdapter.removeCall(id); |
| 931 | } |
| 932 | } |
| 933 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 934 | private Connection findConnectionForAction(String callId, String action) { |
| 935 | if (mConnectionById.containsKey(callId)) { |
| 936 | return mConnectionById.get(callId); |
| 937 | } |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 938 | Log.w(this, "%s - Cannot find Connection %s", action, callId); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 939 | return getNullConnection(); |
| 940 | } |
| 941 | |
| 942 | static synchronized Connection getNullConnection() { |
| 943 | if (sNullConnection == null) { |
| 944 | sNullConnection = new Connection() {}; |
| 945 | } |
| 946 | return sNullConnection; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 947 | } |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 948 | |
| 949 | private Conference findConferenceForAction(String conferenceId, String action) { |
| 950 | if (mConferenceById.containsKey(conferenceId)) { |
| 951 | return mConferenceById.get(conferenceId); |
| 952 | } |
| 953 | Log.w(this, "%s - Cannot find conference %s", action, conferenceId); |
| 954 | return getNullConference(); |
| 955 | } |
| 956 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 957 | private List<String> createConnectionIdList(List<Connection> connections) { |
| 958 | List<String> ids = new ArrayList<>(); |
| 959 | for (Connection c : connections) { |
| 960 | if (mIdByConnection.containsKey(c)) { |
| 961 | ids.add(mIdByConnection.get(c)); |
| 962 | } |
| 963 | } |
| 964 | Collections.sort(ids); |
| 965 | return ids; |
| 966 | } |
| 967 | |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 968 | private Conference getNullConference() { |
| 969 | if (sNullConference == null) { |
| 970 | sNullConference = new Conference(null) {}; |
| 971 | } |
| 972 | return sNullConference; |
| 973 | } |
Santos Cordon | 29f2f2e | 2014-09-11 19:50:24 -0700 | [diff] [blame] | 974 | |
| 975 | private void endAllConnections() { |
| 976 | // Unbound from telecomm. We should end all connections and conferences. |
| 977 | for (Connection connection : mIdByConnection.keySet()) { |
| 978 | // only operate on top-level calls. Conference calls will be removed on their own. |
| 979 | if (connection.getConference() == null) { |
| 980 | connection.onDisconnect(); |
| 981 | } |
| 982 | } |
| 983 | for (Conference conference : mIdByConference.keySet()) { |
| 984 | conference.onDisconnect(); |
| 985 | } |
| 986 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 987 | } |