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