Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013, 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 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 17 | package com.android.telecomm; |
| 18 | |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 19 | import com.google.common.base.Preconditions; |
Evan Charlton | ac1aa9e | 2014-01-03 13:47:12 -0800 | [diff] [blame] | 20 | import com.google.common.collect.Lists; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 21 | import com.google.common.collect.Sets; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 22 | |
Ben Gilad | 2313e62 | 2014-02-06 12:02:25 -0800 | [diff] [blame] | 23 | import android.os.Handler; |
| 24 | import android.os.Looper; |
Ben Gilad | c5b2269 | 2014-02-18 20:03:22 -0800 | [diff] [blame] | 25 | import android.telecomm.CallServiceDescriptor; |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 26 | import android.telecomm.ICallServiceSelector; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 27 | |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 28 | import java.util.Collection; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 29 | import java.util.List; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 30 | import java.util.Set; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 31 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 32 | /** |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 33 | * Switchboard is responsible for (1) gathering the {@link CallServiceWrapper}s and |
| 34 | * {@link ICallServiceSelector}s through which to place outgoing calls, (2) starting outgoing calls |
| 35 | * (via {@link OutgoingCallsManager} and (3) switching active calls between call services. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 36 | */ |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 37 | final class Switchboard { |
Ben Gilad | 2495d57 | 2014-01-09 17:26:19 -0800 | [diff] [blame] | 38 | |
Ben Gilad | 2313e62 | 2014-02-06 12:02:25 -0800 | [diff] [blame] | 39 | /** |
| 40 | * The frequency of invoking tick in milliseconds. |
| 41 | * TODO(gilad): May require tuning. |
| 42 | */ |
| 43 | private final static int TICK_FREQUENCY = 250; |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 44 | |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 45 | private final CallsManager mCallsManager; |
Ben Gilad | 2313e62 | 2014-02-06 12:02:25 -0800 | [diff] [blame] | 46 | |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 47 | /** Used to place outgoing calls. */ |
| 48 | private final OutgoingCallsManager mOutgoingCallsManager; |
| 49 | |
Santos Cordon | 80d9bdc | 2014-02-13 18:28:46 -0800 | [diff] [blame] | 50 | /** Used to confirm incoming calls. */ |
| 51 | private final IncomingCallsManager mIncomingCallsManager; |
| 52 | |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 53 | private final CallServiceRepository mCallServiceRepository; |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 54 | |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 55 | private final CallServiceSelectorRepository mSelectorRepository; |
Ben Gilad | 2313e62 | 2014-02-06 12:02:25 -0800 | [diff] [blame] | 56 | |
| 57 | /** Used to schedule tasks on the main (UI) thread. */ |
| 58 | private final Handler mHandler = new Handler(Looper.getMainLooper()); |
| 59 | |
| 60 | /** |
| 61 | * Executes a single tick task and potentially schedules the next such that polling continues |
| 62 | * as long as necessary. |
| 63 | * NOTE(gilad): by design no two tick invocations should ever overlap. |
| 64 | */ |
| 65 | private final Runnable mTicker = new Runnable() { |
| 66 | @Override |
| 67 | public void run() { |
| 68 | tick(); |
| 69 | if (isTicking()) { |
| 70 | scheduleNextTick(); |
| 71 | } |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | private final Set<Call> mNewOutgoingCalls = Sets.newLinkedHashSet(); |
| 76 | |
| 77 | private final Set<Call> mPendingOutgoingCalls = Sets.newLinkedHashSet(); |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 78 | |
Ben Gilad | 03292d4 | 2014-01-16 15:06:16 -0800 | [diff] [blame] | 79 | /** |
Ben Gilad | bb167cd | 2014-02-25 16:24:05 -0800 | [diff] [blame] | 80 | * The set of currently available call-service implementations, see |
Ben Gilad | 3758723 | 2014-02-19 16:03:44 -0800 | [diff] [blame] | 81 | * {@link CallServiceRepository}. Populated during call-service lookup cycles as part of the |
| 82 | * {@link #placeOutgoingCall} flow and cleared upon zero-remaining new/pending outgoing calls. |
Ben Gilad | 03292d4 | 2014-01-16 15:06:16 -0800 | [diff] [blame] | 83 | */ |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 84 | private Set<CallServiceWrapper> mCallServices; |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 85 | |
Ben Gilad | 03292d4 | 2014-01-16 15:06:16 -0800 | [diff] [blame] | 86 | /** |
| 87 | * The set of currently available call-service-selector implementations, |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 88 | * see {@link CallServiceSelectorRepository}. |
Ben Gilad | 03292d4 | 2014-01-16 15:06:16 -0800 | [diff] [blame] | 89 | * TODO(gilad): Null out once the active-call count goes to zero. |
| 90 | */ |
| 91 | private Set<ICallServiceSelector> mSelectors; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 92 | |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 93 | /** |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 94 | * The current lookup-cycle ID used with the repositories. Incremented with each invocation |
Ben Gilad | 3758723 | 2014-02-19 16:03:44 -0800 | [diff] [blame] | 95 | * of {@link #placeOutgoingCall} and passed to the repositories via initiateLookup(). |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 96 | */ |
| 97 | private int mLookupId = 0; |
| 98 | |
| 99 | /** |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 100 | * Persists the specified parameters and initializes Switchboard. |
| 101 | */ |
Santos Cordon | 6242b13 | 2014-02-07 16:24:42 -0800 | [diff] [blame] | 102 | Switchboard(CallsManager callsManager) { |
| 103 | mCallsManager = callsManager; |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 104 | mOutgoingCallsManager = new OutgoingCallsManager(this); |
Santos Cordon | 80d9bdc | 2014-02-13 18:28:46 -0800 | [diff] [blame] | 105 | mIncomingCallsManager = new IncomingCallsManager(this); |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 106 | mCallServiceRepository = new CallServiceRepository(this, mOutgoingCallsManager); |
| 107 | mSelectorRepository = new CallServiceSelectorRepository(this); |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 108 | } |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 109 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 110 | /** |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 111 | * Starts the process of placing an outgoing call by searching for available call services |
| 112 | * through which the call can be placed. After a lookup for those services completes, execution |
| 113 | * returns to {@link #setCallServices} where the process of placing the call continues. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 114 | * |
Ben Gilad | 13329fd | 2014-02-11 17:20:29 -0800 | [diff] [blame] | 115 | * @param call The yet-to-be-connected outgoing-call object. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 116 | */ |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 117 | void placeOutgoingCall(Call call) { |
Evan Charlton | 0958f53 | 2014-01-10 16:58:02 -0800 | [diff] [blame] | 118 | ThreadUtil.checkOnMainThread(); |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 119 | |
Ben Gilad | bb167cd | 2014-02-25 16:24:05 -0800 | [diff] [blame] | 120 | // Reset prior to initiating the next lookup. One case to consider is (1) placeOutgoingCall |
| 121 | // is invoked with call A, (2) the call-service lookup completes, but the one for selectors |
| 122 | // does not, (3) placeOutgoingCall is invoked again with call B, (4) mCallServices below is |
| 123 | // reset, (5) the selector lookup completes but the call-services are missing. This should |
| 124 | // be okay since the call-service lookup completed. Specifically the already-available call |
| 125 | // services are cached and will be provided in response to the second lookup cycle. |
| 126 | mCallServices = null; |
| 127 | mSelectors = null; |
| 128 | |
Sailesh Nepal | b6141ae | 2014-02-18 08:45:26 -0800 | [diff] [blame] | 129 | mNewOutgoingCalls.add(call); |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 130 | |
Ben Gilad | ebd9b66 | 2014-02-19 16:03:44 -0800 | [diff] [blame] | 131 | // Initiate a lookup every time to account for newly-installed apps and/or updated settings. |
Sailesh Nepal | b6141ae | 2014-02-18 08:45:26 -0800 | [diff] [blame] | 132 | mLookupId++; |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 133 | mCallServiceRepository.initiateLookup(mLookupId); |
| 134 | mSelectorRepository.initiateLookup(mLookupId); |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 135 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 136 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 137 | /** |
Santos Cordon | 80d9bdc | 2014-02-13 18:28:46 -0800 | [diff] [blame] | 138 | * Confirms with incoming call manager that an incoming call exists for the specified call |
| 139 | * service and call token. The incoming call manager will invoke either |
| 140 | * {@link #handleSuccessfulIncomingCall} or {@link #handleFailedIncomingCall} depending |
| 141 | * on the result. |
| 142 | * |
| 143 | * @param call The call object. |
Ben Gilad | c5b2269 | 2014-02-18 20:03:22 -0800 | [diff] [blame] | 144 | * @param descriptor The relevant call-service descriptor. |
Santos Cordon | 80d9bdc | 2014-02-13 18:28:46 -0800 | [diff] [blame] | 145 | * @param callToken The token used by the call service to identify the incoming call. |
| 146 | */ |
Ben Gilad | c5b2269 | 2014-02-18 20:03:22 -0800 | [diff] [blame] | 147 | void confirmIncomingCall(Call call, CallServiceDescriptor descriptor, String callToken) { |
| 148 | CallServiceWrapper callService = mCallServiceRepository.getCallService(descriptor); |
Santos Cordon | 80d9bdc | 2014-02-13 18:28:46 -0800 | [diff] [blame] | 149 | mIncomingCallsManager.confirmIncomingCall(call, callService, callToken); |
| 150 | } |
| 151 | |
| 152 | /** |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 153 | * Persists the specified set of call services and attempts to place any pending outgoing |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 154 | * calls. Intended to be invoked by {@link CallServiceRepository} exclusively. |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 155 | * |
Ben Gilad | 03292d4 | 2014-01-16 15:06:16 -0800 | [diff] [blame] | 156 | * @param callServices The potentially-partial set of call services. Partial since the lookup |
| 157 | * process is time-boxed, such that some providers/call-services may be slow to respond and |
| 158 | * hence effectively omitted from the specified list. |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 159 | */ |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 160 | void setCallServices(Set<CallServiceWrapper> callServices) { |
Evan Charlton | 0958f53 | 2014-01-10 16:58:02 -0800 | [diff] [blame] | 161 | ThreadUtil.checkOnMainThread(); |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 162 | |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 163 | mCallServices = callServices; |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 164 | processNewOutgoingCalls(); |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Persists the specified list of selectors and attempts to connect any pending outgoing |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 169 | * calls. Intended to be invoked by {@link CallServiceSelectorRepository} exclusively. |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 170 | * |
Ben Gilad | 03292d4 | 2014-01-16 15:06:16 -0800 | [diff] [blame] | 171 | * @param selectors The potentially-partial set of selectors. Partial since the lookup |
| 172 | * procedure is time-boxed such that some selectors may be slow to respond and hence |
| 173 | * effectively omitted from the specified set. |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 174 | */ |
Ben Gilad | 03292d4 | 2014-01-16 15:06:16 -0800 | [diff] [blame] | 175 | void setSelectors(Set<ICallServiceSelector> selectors) { |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 176 | // TODO(santoscordon): This should take in CallServiceSelectorWrapper instead of the direct |
| 177 | // ICallServiceSelector implementation. Copy what we have for CallServiceWrapper. |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 178 | ThreadUtil.checkOnMainThread(); |
| 179 | |
Ben Gilad | 134cf09 | 2014-01-16 18:26:12 -0800 | [diff] [blame] | 180 | // TODO(gilad): Add logic to include the built-in selectors (e.g. for dealing with |
| 181 | // emergency calls) and order the entire set prior to the assignment below. If the |
| 182 | // built-in selectors can be implemented in a manner that does not require binding, |
| 183 | // that's probably preferred. May want to use a LinkedHashSet for the sorted set. |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 184 | mSelectors = selectors; |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 185 | processNewOutgoingCalls(); |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /** |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 189 | * Handles the case where an outgoing call has been successfully placed, |
| 190 | * see {@link OutgoingCallProcessor}. |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 191 | */ |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 192 | void handleSuccessfulOutgoingCall(Call call) { |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 193 | mCallsManager.handleSuccessfulOutgoingCall(call); |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 194 | |
| 195 | // Process additional (new) calls, if any. |
| 196 | processNewOutgoingCalls(); |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Handles the case where an outgoing call could not be proceed by any of the |
| 201 | * selector/call-service implementations, see {@link OutgoingCallProcessor}. |
| 202 | */ |
| 203 | void handleFailedOutgoingCall(Call call) { |
| 204 | // TODO(gilad): More here. |
| 205 | |
| 206 | // Process additional (new) calls, if any. |
| 207 | processNewOutgoingCalls(); |
| 208 | } |
| 209 | |
| 210 | /** |
Santos Cordon | 80d9bdc | 2014-02-13 18:28:46 -0800 | [diff] [blame] | 211 | * Handles the case where we received confirmation of an incoming call. Hands the resulting |
| 212 | * call to {@link CallsManager} as the final step in the incoming sequence. At that point, |
| 213 | * {@link CallsManager} should bring up the incoming-call UI. |
| 214 | */ |
| 215 | void handleSuccessfulIncomingCall(Call call) { |
| 216 | mCallsManager.handleSuccessfulIncomingCall(call); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Handles the case where we failed to confirm an incoming call after receiving an incoming-call |
| 221 | * intent via {@link TelecommReceiver}. |
| 222 | * |
| 223 | * @param call The call. |
| 224 | */ |
| 225 | void handleFailedIncomingCall(Call call) { |
| 226 | // At the moment there is nothing to do if an incoming call is not confirmed. We may at a |
| 227 | // future date bind to the in-call app optimistically during the incoming-call sequence and |
| 228 | // this method could tell {@link CallsManager} to unbind from the in-call app if the |
| 229 | // incoming call was not confirmed. It's worth keeping this method for parity with the |
| 230 | // outgoing call sequence. |
| 231 | } |
| 232 | |
| 233 | /** |
Ben Gilad | 2313e62 | 2014-02-06 12:02:25 -0800 | [diff] [blame] | 234 | * @return True if ticking should continue (or be resumed) and false otherwise. |
| 235 | */ |
| 236 | private boolean isTicking() { |
| 237 | // TODO(gilad): return true every time at least one outgoing call is pending (i.e. waiting |
| 238 | // to be connected by a call service) and also when at least one active call is switch-able |
| 239 | // between call services, see {@link ICallServiceSelector#isSwitchable}. |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * Schedules the next tick invocation. |
| 245 | */ |
| 246 | private void scheduleNextTick() { |
| 247 | mHandler.postDelayed(mTicker, TICK_FREQUENCY); |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Performs the set of tasks that needs to be executed on polling basis. |
| 252 | * TODO(gilad): Check for stale pending calls that may need to be terminated etc, see |
| 253 | * mNewOutgoingCalls and mPendingOutgoingCalls. |
| 254 | * TODO(gilad): Also intended to trigger the call switching/hand-off logic when applicable. |
| 255 | */ |
| 256 | private void tick() { |
| 257 | // TODO(gilad): More here. |
Santos Cordon | c195e36 | 2014-02-11 17:05:31 -0800 | [diff] [blame] | 258 | // TODO(santoscordon): Clear mCallServices if there exist no more new or pending outgoing |
| 259 | // calls. |
Ben Gilad | 2313e62 | 2014-02-06 12:02:25 -0800 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /** |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 263 | * Attempts to process the next new outgoing calls that have not yet been expired. |
| 264 | */ |
| 265 | private void processNewOutgoingCalls() { |
| 266 | if (isNullOrEmpty(mCallServices) || isNullOrEmpty(mSelectors)) { |
| 267 | // At least one call service and one selector are required to process outgoing calls. |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | if (!mNewOutgoingCalls.isEmpty()) { |
| 272 | Call call = mNewOutgoingCalls.iterator().next(); |
| 273 | mNewOutgoingCalls.remove(call); |
| 274 | mPendingOutgoingCalls.add(call); |
| 275 | |
| 276 | // Specifically only attempt to place one call at a time such that call services |
| 277 | // can be freed from needing to deal with concurrent requests. |
| 278 | processNewOutgoingCall(call); |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 279 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 282 | /** |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 283 | * Attempts to place the specified call. |
| 284 | * |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 285 | * @param call The call to place. |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 286 | */ |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 287 | private void processNewOutgoingCall(Call call) { |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 288 | Preconditions.checkNotNull(mCallServices); |
| 289 | Preconditions.checkNotNull(mSelectors); |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 290 | |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 291 | // Convert to (duplicate-free) list to aid index-based iteration, see the comment under |
| 292 | // setSelectors regarding using LinkedHashSet instead. |
| 293 | List<ICallServiceSelector> selectors = Lists.newArrayList(); |
| 294 | selectors.addAll(mSelectors); |
| 295 | |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 296 | mOutgoingCallsManager.placeCall(call, mCallServices, selectors); |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Determines whether or not the specified collection is either null or empty. |
| 301 | * |
| 302 | * @param collection Either null or the collection object to be evaluated. |
| 303 | * @return True if the collection is null or empty. |
| 304 | */ |
| 305 | @SuppressWarnings("rawtypes") |
| 306 | private boolean isNullOrEmpty(Collection collection) { |
| 307 | return collection == null || collection.isEmpty(); |
| 308 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 309 | } |