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