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