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 |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame^] | 363 | public void onConferenceableConnectionsChanged( |
| 364 | Conference conference, List<Connection> conferenceableConnections) { |
| 365 | mAdapter.setConferenceableConnections( |
| 366 | mIdByConference.get(conference), |
| 367 | createConnectionIdList(conferenceableConnections)); |
| 368 | } |
| 369 | |
| 370 | @Override |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 371 | public void onDestroyed(Conference conference) { |
| 372 | removeConference(conference); |
| 373 | } |
| 374 | |
| 375 | @Override |
| 376 | public void onCapabilitiesChanged(Conference conference, int capabilities) { |
| 377 | String id = mIdByConference.get(conference); |
| 378 | Log.d(this, "call capabilities: conference: %s", |
| 379 | PhoneCapabilities.toString(capabilities)); |
| 380 | mAdapter.setCallCapabilities(id, capabilities); |
| 381 | } |
| 382 | }; |
| 383 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 384 | private final Connection.Listener mConnectionListener = new Connection.Listener() { |
| 385 | @Override |
| 386 | public void onStateChanged(Connection c, int state) { |
| 387 | String id = mIdByConnection.get(c); |
Ihab Awad | 42b30e1 | 2014-05-22 09:49:34 -0700 | [diff] [blame] | 388 | Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state)); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 389 | switch (state) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 390 | case Connection.STATE_ACTIVE: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 391 | mAdapter.setActive(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 392 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 393 | case Connection.STATE_DIALING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 394 | mAdapter.setDialing(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 395 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 396 | case Connection.STATE_DISCONNECTED: |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 397 | // Handled in onDisconnected() |
| 398 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 399 | case Connection.STATE_HOLDING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 400 | mAdapter.setOnHold(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 401 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 402 | case Connection.STATE_NEW: |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 403 | // Nothing to tell Telecom |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 404 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 405 | case Connection.STATE_RINGING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 406 | mAdapter.setRinging(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 407 | break; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | @Override |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 412 | public void onDisconnected(Connection c, DisconnectCause disconnectCause) { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 413 | String id = mIdByConnection.get(c); |
Andrew Lee | 2678639 | 2014-09-16 18:14:59 -0700 | [diff] [blame] | 414 | Log.d(this, "Adapter set disconnected %s", disconnectCause); |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 415 | mAdapter.setDisconnected(id, disconnectCause); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | @Override |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 419 | public void onVideoStateChanged(Connection c, int videoState) { |
| 420 | String id = mIdByConnection.get(c); |
| 421 | Log.d(this, "Adapter set video state %d", videoState); |
| 422 | mAdapter.setVideoState(id, videoState); |
| 423 | } |
| 424 | |
| 425 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 426 | public void onAddressChanged(Connection c, Uri address, int presentation) { |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 427 | String id = mIdByConnection.get(c); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 428 | mAdapter.setAddress(id, address, presentation); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | @Override |
| 432 | public void onCallerDisplayNameChanged( |
| 433 | Connection c, String callerDisplayName, int presentation) { |
| 434 | String id = mIdByConnection.get(c); |
| 435 | mAdapter.setCallerDisplayName(id, callerDisplayName, presentation); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | @Override |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 439 | public void onDestroyed(Connection c) { |
| 440 | removeConnection(c); |
| 441 | } |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 442 | |
| 443 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 444 | public void onPostDialWait(Connection c, String remaining) { |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 445 | String id = mIdByConnection.get(c); |
| 446 | Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 447 | mAdapter.onPostDialWait(id, remaining); |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 451 | public void onRingbackRequested(Connection c, boolean ringback) { |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 452 | String id = mIdByConnection.get(c); |
| 453 | Log.d(this, "Adapter onRingback %b", ringback); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 454 | mAdapter.setRingbackRequested(id, ringback); |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 455 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 456 | |
| 457 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 458 | public void onCallCapabilitiesChanged(Connection c, int capabilities) { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 459 | String id = mIdByConnection.get(c); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 460 | Log.d(this, "capabilities: parcelableconnection: %s", |
| 461 | PhoneCapabilities.toString(capabilities)); |
| 462 | mAdapter.setCallCapabilities(id, capabilities); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 465 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 466 | public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) { |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 467 | String id = mIdByConnection.get(c); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 468 | mAdapter.setVideoProvider(id, videoProvider); |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 469 | } |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 470 | |
| 471 | @Override |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 472 | public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) { |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 473 | String id = mIdByConnection.get(c); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 474 | mAdapter.setIsVoipAudioMode(id, isVoip); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 475 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 476 | |
| 477 | @Override |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 478 | public void onStatusHintsChanged(Connection c, StatusHints statusHints) { |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 479 | String id = mIdByConnection.get(c); |
| 480 | mAdapter.setStatusHints(id, statusHints); |
| 481 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 482 | |
| 483 | @Override |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 484 | public void onConferenceableConnectionsChanged( |
| 485 | Connection connection, List<Connection> conferenceableConnections) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 486 | mAdapter.setConferenceableConnections( |
| 487 | mIdByConnection.get(connection), |
| 488 | createConnectionIdList(conferenceableConnections)); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 489 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 490 | |
| 491 | @Override |
| 492 | public void onConferenceChanged(Connection connection, Conference conference) { |
| 493 | String id = mIdByConnection.get(connection); |
| 494 | if (id != null) { |
| 495 | String conferenceId = null; |
| 496 | if (conference != null) { |
| 497 | conferenceId = mIdByConference.get(conference); |
| 498 | } |
| 499 | mAdapter.setIsConferenced(id, conferenceId); |
| 500 | } |
| 501 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 502 | }; |
| 503 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 504 | /** {@inheritDoc} */ |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 505 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 506 | public final IBinder onBind(Intent intent) { |
| 507 | return mBinder; |
| 508 | } |
| 509 | |
Santos Cordon | 29f2f2e | 2014-09-11 19:50:24 -0700 | [diff] [blame] | 510 | /** {@inheritDoc} */ |
| 511 | @Override |
| 512 | public boolean onUnbind(Intent intent) { |
| 513 | endAllConnections(); |
| 514 | return super.onUnbind(intent); |
| 515 | } |
| 516 | |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 517 | /** |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 518 | * This can be used by telecom to either create a new outgoing call or attach to an existing |
| 519 | * 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] | 520 | * createConnection util a connection service cancels the process or completes it successfully. |
| 521 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 522 | private void createConnection( |
| 523 | final PhoneAccountHandle callManagerAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 524 | final String callId, |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 525 | final ConnectionRequest request, |
| 526 | boolean isIncoming) { |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 527 | Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " + |
| 528 | "isIncoming: %b", callManagerAccount, callId, request, isIncoming); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 529 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 530 | Connection connection = isIncoming |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 531 | ? onCreateIncomingConnection(callManagerAccount, request) |
| 532 | : onCreateOutgoingConnection(callManagerAccount, request); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 533 | Log.d(this, "createConnection, connection: %s", connection); |
| 534 | if (connection == null) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 535 | connection = Connection.createFailedConnection( |
| 536 | new DisconnectCause(DisconnectCause.ERROR)); |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 537 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 538 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 539 | if (connection.getState() != Connection.STATE_DISCONNECTED) { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 540 | addConnection(callId, connection); |
| 541 | } |
| 542 | |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 543 | Uri address = connection.getAddress(); |
| 544 | String number = address == null ? "null" : address.getSchemeSpecificPart(); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 545 | Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s", |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 546 | Connection.toLogSafePhoneNumber(number), |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 547 | Connection.stateToString(connection.getState()), |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 548 | PhoneCapabilities.toString(connection.getCallCapabilities())); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 549 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 550 | Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 551 | mAdapter.handleCreateConnectionComplete( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 552 | callId, |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 553 | request, |
| 554 | new ParcelableConnection( |
| 555 | request.getAccountHandle(), |
| 556 | connection.getState(), |
| 557 | connection.getCallCapabilities(), |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 558 | connection.getAddress(), |
| 559 | connection.getAddressPresentation(), |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 560 | connection.getCallerDisplayName(), |
| 561 | connection.getCallerDisplayNamePresentation(), |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 562 | connection.getVideoProvider() == null ? |
| 563 | null : connection.getVideoProvider().getInterface(), |
Sailesh Nepal | 8b9d3ca | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 564 | connection.getVideoState(), |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 565 | connection.isRingbackRequested(), |
Sailesh Nepal | 8b9d3ca | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 566 | connection.getAudioModeIsVoip(), |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 567 | connection.getStatusHints(), |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 568 | connection.getDisconnectCause(), |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 569 | createConnectionIdList(connection.getConferenceableConnections()))); |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 572 | private void abort(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 573 | Log.d(this, "abort %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 574 | findConnectionForAction(callId, "abort").onAbort(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 577 | private void answerVideo(String callId, int videoState) { |
| 578 | Log.d(this, "answerVideo %s", callId); |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 579 | findConnectionForAction(callId, "answer").onAnswer(videoState); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 582 | private void answer(String callId) { |
| 583 | Log.d(this, "answer %s", callId); |
| 584 | findConnectionForAction(callId, "answer").onAnswer(); |
| 585 | } |
| 586 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 587 | private void reject(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 588 | Log.d(this, "reject %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 589 | findConnectionForAction(callId, "reject").onReject(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 592 | private void disconnect(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 593 | Log.d(this, "disconnect %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 594 | if (mConnectionById.containsKey(callId)) { |
| 595 | findConnectionForAction(callId, "disconnect").onDisconnect(); |
| 596 | } else { |
| 597 | findConferenceForAction(callId, "disconnect").onDisconnect(); |
| 598 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 601 | private void hold(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 602 | Log.d(this, "hold %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 603 | if (mConnectionById.containsKey(callId)) { |
| 604 | findConnectionForAction(callId, "hold").onHold(); |
| 605 | } else { |
| 606 | findConferenceForAction(callId, "hold").onHold(); |
| 607 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 610 | private void unhold(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 611 | Log.d(this, "unhold %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 612 | if (mConnectionById.containsKey(callId)) { |
| 613 | findConnectionForAction(callId, "unhold").onUnhold(); |
| 614 | } else { |
| 615 | findConferenceForAction(callId, "unhold").onUnhold(); |
| 616 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 619 | private void onAudioStateChanged(String callId, AudioState audioState) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 620 | Log.d(this, "onAudioStateChanged %s %s", callId, audioState); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 621 | if (mConnectionById.containsKey(callId)) { |
| 622 | findConnectionForAction(callId, "onAudioStateChanged").setAudioState(audioState); |
| 623 | } else { |
| 624 | findConferenceForAction(callId, "onAudioStateChanged").setAudioState(audioState); |
| 625 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 628 | private void playDtmfTone(String callId, char digit) { |
| 629 | Log.d(this, "playDtmfTone %s %c", callId, digit); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 630 | if (mConnectionById.containsKey(callId)) { |
| 631 | findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit); |
| 632 | } else { |
| 633 | findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit); |
| 634 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | private void stopDtmfTone(String callId) { |
| 638 | Log.d(this, "stopDtmfTone %s", callId); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 639 | if (mConnectionById.containsKey(callId)) { |
| 640 | findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone(); |
| 641 | } else { |
| 642 | findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone(); |
| 643 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 646 | private void conference(String callId1, String callId2) { |
| 647 | Log.d(this, "conference %s, %s", callId1, callId2); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 648 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 649 | Connection connection2 = findConnectionForAction(callId2, "conference"); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 650 | if (connection2 == getNullConnection()) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 651 | Log.w(this, "Connection2 missing in conference request %s.", callId2); |
| 652 | return; |
| 653 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 654 | |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame^] | 655 | Connection connection1 = findConnectionForAction(callId1, "conference"); |
| 656 | if (connection1 == getNullConnection()) { |
| 657 | Conference conference1 = findConferenceForAction(callId1, "addConnection"); |
| 658 | if (conference1 == getNullConference()) { |
| 659 | Log.w(this, |
| 660 | "Connection1 or Conference1 missing in conference request %s.", |
| 661 | callId1); |
| 662 | } else { |
| 663 | conference1.onMerge(connection2); |
| 664 | } |
| 665 | } else { |
| 666 | onConference(connection1, connection2); |
| 667 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 670 | private void splitFromConference(String callId) { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 671 | Log.d(this, "splitFromConference(%s)", callId); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 672 | |
| 673 | Connection connection = findConnectionForAction(callId, "splitFromConference"); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 674 | if (connection == getNullConnection()) { |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 675 | Log.w(this, "Connection missing in conference request %s.", callId); |
| 676 | return; |
| 677 | } |
| 678 | |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 679 | Conference conference = connection.getConference(); |
| 680 | if (conference != null) { |
| 681 | conference.onSeparate(connection); |
| 682 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 685 | private void mergeConference(String callId) { |
| 686 | Log.d(this, "mergeConference(%s)", callId); |
| 687 | Conference conference = findConferenceForAction(callId, "mergeConference"); |
| 688 | if (conference != null) { |
| 689 | conference.onMerge(); |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | private void swapConference(String callId) { |
| 694 | Log.d(this, "swapConference(%s)", callId); |
| 695 | Conference conference = findConferenceForAction(callId, "swapConference"); |
| 696 | if (conference != null) { |
| 697 | conference.onSwap(); |
| 698 | } |
| 699 | } |
| 700 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 701 | private void onPostDialContinue(String callId, boolean proceed) { |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 702 | Log.d(this, "onPostDialContinue(%s)", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 703 | findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed); |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 704 | } |
| 705 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 706 | private void onAdapterAttached() { |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 707 | if (mAreAccountsInitialized) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 708 | // No need to query again if we already did it. |
| 709 | return; |
| 710 | } |
| 711 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 712 | mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 713 | @Override |
| 714 | public void onResult( |
| 715 | final List<ComponentName> componentNames, |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 716 | final List<IBinder> services) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 717 | mHandler.post(new Runnable() { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 718 | @Override |
| 719 | public void run() { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 720 | for (int i = 0; i < componentNames.size() && i < services.size(); i++) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 721 | mRemoteConnectionManager.addConnectionService( |
| 722 | componentNames.get(i), |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 723 | IConnectionService.Stub.asInterface(services.get(i))); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 724 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 725 | onAccountsInitialized(); |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 726 | Log.d(this, "remote connection services found: " + services); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 727 | } |
| 728 | }); |
| 729 | } |
| 730 | |
| 731 | @Override |
| 732 | public void onError() { |
| 733 | mHandler.post(new Runnable() { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 734 | @Override |
| 735 | public void run() { |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 736 | mAreAccountsInitialized = true; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 737 | } |
| 738 | }); |
| 739 | } |
| 740 | }); |
| 741 | } |
| 742 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 743 | /** |
| 744 | * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an |
| 745 | * incoming request. This is used to attach to existing incoming calls. |
| 746 | * |
| 747 | * @param connectionManagerPhoneAccount See description at |
| 748 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 749 | * @param request Details about the incoming call. |
| 750 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 751 | * not handle the call. |
| 752 | */ |
| 753 | public final RemoteConnection createRemoteIncomingConnection( |
| 754 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 755 | ConnectionRequest request) { |
| 756 | return mRemoteConnectionManager.createRemoteConnection( |
| 757 | connectionManagerPhoneAccount, request, true); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 761 | * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an |
| 762 | * outgoing request. This is used to initiate new outgoing calls. |
| 763 | * |
| 764 | * @param connectionManagerPhoneAccount See description at |
| 765 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 766 | * @param request Details about the incoming call. |
| 767 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 768 | * not handle the call. |
| 769 | */ |
| 770 | public final RemoteConnection createRemoteOutgoingConnection( |
| 771 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 772 | ConnectionRequest request) { |
| 773 | return mRemoteConnectionManager.createRemoteConnection( |
| 774 | connectionManagerPhoneAccount, request, false); |
| 775 | } |
| 776 | |
| 777 | /** |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 778 | * Adds two {@code RemoteConnection}s to some {@code RemoteConference}. |
| 779 | */ |
| 780 | public final void conferenceRemoteConnections( |
| 781 | RemoteConnection a, |
| 782 | RemoteConnection b) { |
| 783 | mRemoteConnectionManager.conferenceRemoteConnections(a, b); |
| 784 | } |
| 785 | |
| 786 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 787 | * Adds a new conference call. When a conference call is created either as a result of an |
| 788 | * explicit request via {@link #onConference} or otherwise, the connection service should supply |
| 789 | * an instance of {@link Conference} by invoking this method. A conference call provided by this |
| 790 | * method will persist until {@link Conference#destroy} is invoked on the conference instance. |
| 791 | * |
| 792 | * @param conference The new conference object. |
| 793 | */ |
| 794 | public final void addConference(Conference conference) { |
| 795 | String id = addConferenceInternal(conference); |
| 796 | if (id != null) { |
| 797 | List<String> connectionIds = new ArrayList<>(2); |
| 798 | for (Connection connection : conference.getConnections()) { |
| 799 | if (mIdByConnection.containsKey(connection)) { |
| 800 | connectionIds.add(mIdByConnection.get(connection)); |
| 801 | } |
| 802 | } |
| 803 | ParcelableConference parcelableConference = new ParcelableConference( |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 804 | conference.getPhoneAccountHandle(), |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 805 | conference.getState(), |
| 806 | conference.getCapabilities(), |
| 807 | connectionIds); |
| 808 | mAdapter.addConferenceCall(id, parcelableConference); |
| 809 | |
| 810 | // Go through any child calls and set the parent. |
| 811 | for (Connection connection : conference.getConnections()) { |
| 812 | String connectionId = mIdByConnection.get(connection); |
| 813 | if (connectionId != null) { |
| 814 | mAdapter.setIsConferenced(connectionId, id); |
| 815 | } |
| 816 | } |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 821 | * Returns all the active {@code Connection}s for which this {@code ConnectionService} |
| 822 | * has taken responsibility. |
| 823 | * |
| 824 | * @return A collection of {@code Connection}s created by this {@code ConnectionService}. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 825 | */ |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 826 | public final Collection<Connection> getAllConnections() { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 827 | return mConnectionById.values(); |
| 828 | } |
| 829 | |
| 830 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 831 | * Create a {@code Connection} given an incoming request. This is used to attach to existing |
| 832 | * incoming calls. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 833 | * |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 834 | * @param connectionManagerPhoneAccount See description at |
| 835 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 836 | * @param request Details about the incoming call. |
| 837 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 838 | * not handle the call. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 839 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 840 | public Connection onCreateIncomingConnection( |
| 841 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 842 | ConnectionRequest request) { |
| 843 | return null; |
| 844 | } |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 845 | |
| 846 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 847 | * Create a {@code Connection} given an outgoing request. This is used to initiate new |
| 848 | * outgoing calls. |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 849 | * |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 850 | * @param connectionManagerPhoneAccount The connection manager account to use for managing |
| 851 | * this call. |
| 852 | * <p> |
| 853 | * If this parameter is not {@code null}, it means that this {@code ConnectionService} |
| 854 | * has registered one or more {@code PhoneAccount}s having |
| 855 | * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain |
| 856 | * one of these {@code PhoneAccount}s, while the {@code request} will contain another |
| 857 | * (usually but not always distinct) {@code PhoneAccount} to be used for actually |
| 858 | * making the connection. |
| 859 | * <p> |
| 860 | * If this parameter is {@code null}, it means that this {@code ConnectionService} is |
| 861 | * being asked to make a direct connection. The |
| 862 | * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be |
| 863 | * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for |
| 864 | * making the connection. |
| 865 | * @param request Details about the outgoing call. |
| 866 | * @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] | 867 | * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call. |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 868 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 869 | public Connection onCreateOutgoingConnection( |
| 870 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 871 | ConnectionRequest request) { |
| 872 | return null; |
| 873 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 874 | |
| 875 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 876 | * Conference two specified connections. Invoked when the user has made a request to merge the |
| 877 | * specified connections into a conference call. In response, the connection service should |
| 878 | * create an instance of {@link Conference} and pass it into {@link #addConference}. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 879 | * |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 880 | * @param connection1 A connection to merge into a conference call. |
| 881 | * @param connection2 A connection to merge into a conference call. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 882 | */ |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 883 | public void onConference(Connection connection1, Connection connection2) {} |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 884 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 885 | public void onRemoteConferenceAdded(RemoteConference conference) {} |
| 886 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 887 | /** |
| 888 | * @hide |
| 889 | */ |
| 890 | public boolean containsConference(Conference conference) { |
| 891 | return mIdByConference.containsKey(conference); |
| 892 | } |
| 893 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 894 | /** {@hide} */ |
| 895 | void addRemoteConference(RemoteConference remoteConference) { |
| 896 | onRemoteConferenceAdded(remoteConference); |
| 897 | } |
| 898 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 899 | private void onAccountsInitialized() { |
| 900 | mAreAccountsInitialized = true; |
| 901 | for (Runnable r : mPreInitializationConnectionRequests) { |
| 902 | r.run(); |
| 903 | } |
| 904 | mPreInitializationConnectionRequests.clear(); |
| 905 | } |
| 906 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 907 | private void addConnection(String callId, Connection connection) { |
| 908 | mConnectionById.put(callId, connection); |
| 909 | mIdByConnection.put(connection, callId); |
| 910 | connection.addConnectionListener(mConnectionListener); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 911 | connection.setConnectionService(this); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | private void removeConnection(Connection connection) { |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 915 | String id = mIdByConnection.get(connection); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 916 | connection.unsetConnectionService(this); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 917 | connection.removeConnectionListener(mConnectionListener); |
| 918 | mConnectionById.remove(mIdByConnection.get(connection)); |
| 919 | mIdByConnection.remove(connection); |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 920 | mAdapter.removeCall(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 921 | } |
| 922 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 923 | private String addConferenceInternal(Conference conference) { |
| 924 | if (mIdByConference.containsKey(conference)) { |
| 925 | Log.w(this, "Re-adding an existing conference: %s.", conference); |
| 926 | } else if (conference != null) { |
| 927 | String id = UUID.randomUUID().toString(); |
| 928 | mConferenceById.put(id, conference); |
| 929 | mIdByConference.put(conference, id); |
| 930 | conference.addListener(mConferenceListener); |
| 931 | return id; |
| 932 | } |
| 933 | |
| 934 | return null; |
| 935 | } |
| 936 | |
| 937 | private void removeConference(Conference conference) { |
| 938 | if (mIdByConference.containsKey(conference)) { |
| 939 | conference.removeListener(mConferenceListener); |
| 940 | |
| 941 | String id = mIdByConference.get(conference); |
| 942 | mConferenceById.remove(id); |
| 943 | mIdByConference.remove(conference); |
| 944 | mAdapter.removeCall(id); |
| 945 | } |
| 946 | } |
| 947 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 948 | private Connection findConnectionForAction(String callId, String action) { |
| 949 | if (mConnectionById.containsKey(callId)) { |
| 950 | return mConnectionById.get(callId); |
| 951 | } |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 952 | Log.w(this, "%s - Cannot find Connection %s", action, callId); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 953 | return getNullConnection(); |
| 954 | } |
| 955 | |
| 956 | static synchronized Connection getNullConnection() { |
| 957 | if (sNullConnection == null) { |
| 958 | sNullConnection = new Connection() {}; |
| 959 | } |
| 960 | return sNullConnection; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 961 | } |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 962 | |
| 963 | private Conference findConferenceForAction(String conferenceId, String action) { |
| 964 | if (mConferenceById.containsKey(conferenceId)) { |
| 965 | return mConferenceById.get(conferenceId); |
| 966 | } |
| 967 | Log.w(this, "%s - Cannot find conference %s", action, conferenceId); |
| 968 | return getNullConference(); |
| 969 | } |
| 970 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 971 | private List<String> createConnectionIdList(List<Connection> connections) { |
| 972 | List<String> ids = new ArrayList<>(); |
| 973 | for (Connection c : connections) { |
| 974 | if (mIdByConnection.containsKey(c)) { |
| 975 | ids.add(mIdByConnection.get(c)); |
| 976 | } |
| 977 | } |
| 978 | Collections.sort(ids); |
| 979 | return ids; |
| 980 | } |
| 981 | |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 982 | private Conference getNullConference() { |
| 983 | if (sNullConference == null) { |
| 984 | sNullConference = new Conference(null) {}; |
| 985 | } |
| 986 | return sNullConference; |
| 987 | } |
Santos Cordon | 29f2f2e | 2014-09-11 19:50:24 -0700 | [diff] [blame] | 988 | |
| 989 | private void endAllConnections() { |
| 990 | // Unbound from telecomm. We should end all connections and conferences. |
| 991 | for (Connection connection : mIdByConnection.keySet()) { |
| 992 | // only operate on top-level calls. Conference calls will be removed on their own. |
| 993 | if (connection.getConference() == null) { |
| 994 | connection.onDisconnect(); |
| 995 | } |
| 996 | } |
| 997 | for (Conference conference : mIdByConference.keySet()) { |
| 998 | conference.onDisconnect(); |
| 999 | } |
| 1000 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 1001 | } |