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