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