Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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 | |
| 17 | package com.android.telecomm; |
| 18 | |
| 19 | import android.content.ComponentName; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 20 | import android.content.Intent; |
| 21 | import android.content.pm.PackageManager; |
| 22 | import android.content.pm.ResolveInfo; |
| 23 | import android.content.pm.ServiceInfo; |
Evan Charlton | 0958f53 | 2014-01-10 16:58:02 -0800 | [diff] [blame] | 24 | import android.os.Handler; |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 25 | import android.os.IBinder; |
Evan Charlton | 0958f53 | 2014-01-10 16:58:02 -0800 | [diff] [blame] | 26 | import android.os.Looper; |
Santos Cordon | cb83fb6 | 2014-01-06 10:57:57 -0800 | [diff] [blame] | 27 | import android.os.RemoteException; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 28 | import android.telecomm.ICallService; |
Santos Cordon | cb83fb6 | 2014-01-06 10:57:57 -0800 | [diff] [blame] | 29 | import android.telecomm.ICallServiceLookupResponse; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 30 | import android.telecomm.ICallServiceProvider; |
| 31 | import android.util.Log; |
| 32 | |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 33 | import com.google.common.base.Preconditions; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 34 | import com.google.common.collect.Lists; |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 35 | import com.google.common.collect.Maps; |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 36 | import com.google.common.collect.Sets; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 37 | |
| 38 | import java.util.List; |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 39 | import java.util.Map; |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 40 | import java.util.Set; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Finds {@link ICallService} and {@link ICallServiceProvider} implementations on the device. |
| 44 | * Uses binder APIs to find ICallServiceProviders and calls method on ICallServiceProvider to |
| 45 | * find ICallService implementations. |
| 46 | * TODO(santoscordon): Add performance timing to async calls. |
| 47 | */ |
| 48 | final class CallServiceFinder { |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 49 | |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 50 | private static final String TAG = CallServiceFinder.class.getSimpleName(); |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 51 | |
| 52 | /** |
Evan Charlton | 0958f53 | 2014-01-10 16:58:02 -0800 | [diff] [blame] | 53 | * The longest period in milliseconds each lookup cycle is allowed to span over, see |
| 54 | * {@link #mLookupTerminator}. |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 55 | * TODO(gilad): Likely requires tuning. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 56 | */ |
Evan Charlton | 0958f53 | 2014-01-10 16:58:02 -0800 | [diff] [blame] | 57 | private static final int LOOKUP_TIMEOUT_MS = 100; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 58 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 59 | private final Switchboard mSwitchboard; |
| 60 | |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 61 | private final OutgoingCallsManager mOutgoingCallsManager; |
| 62 | |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 63 | /** |
| 64 | * Determines whether or not a lookup cycle is already running. |
| 65 | */ |
| 66 | private boolean mIsLookupInProgress = false; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 67 | |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 68 | /** |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 69 | * The current lookup-cycle ID. Incremented upon initiateLookup calls. |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 70 | * TODO(gilad): If at all useful, consider porting the cycle ID concept to switchboard and |
| 71 | * have it centralized/shared between the two finders. |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 72 | */ |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 73 | private int mLookupId = 0; |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 74 | |
| 75 | /** |
Ben Gilad | 03292d4 | 2014-01-16 15:06:16 -0800 | [diff] [blame] | 76 | * The set of bound call-services. Only populated via initiateLookup scenarios. Entries should |
| 77 | * only be removed upon unbinding. |
| 78 | * TODO(gilad): Add the necessary logic to keep this set up to date. |
| 79 | */ |
| 80 | private Set<ICallService> mCallServiceRegistry = Sets.newHashSet(); |
| 81 | |
| 82 | /** |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 83 | * The set of bound call-service providers. Only populated via initiateLookup scenarios. |
| 84 | * Providers should only be removed upon unbinding. |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 85 | * TODO(santoscordon): This can be removed once this class starts using CallServiceWrapper |
| 86 | * since we'll be able to unbind the providers within registerProvider(). |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 87 | */ |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 88 | private Set<CallServiceProviderWrapper> mProviderRegistry = Sets.newHashSet(); |
| 89 | |
| 90 | /** |
| 91 | * Map of {@link CallServiceProviderWrapper}s keyed by their ComponentName. Used as a long-lived |
| 92 | * cache in order to simplify management of service-wrapper construction/destruction. |
| 93 | */ |
| 94 | private Map<ComponentName, CallServiceProviderWrapper> mProviderCache = Maps.newHashMap(); |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * Stores the names of the providers to bind to in one lookup cycle. The set size represents |
| 98 | * the number of call-service providers this finder expects to hear back from upon initiating |
| 99 | * call-service lookups, see initiateLookup. Whenever all providers respond before the lookup |
| 100 | * timeout occurs, the complete set of (available) call services is passed to the switchboard |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 101 | * for further processing of outgoing calls etc. When the timeout occurs before all responses |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 102 | * are received, the partial (potentially empty) set gets passed (to the switchboard) instead. |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 103 | * Entries are removed from this set as providers register. |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 104 | */ |
| 105 | private Set<ComponentName> mUnregisteredProviders; |
| 106 | |
| 107 | /** |
| 108 | * Used to interrupt lookup cycles that didn't terminate naturally within the allowed |
| 109 | * period, see LOOKUP_TIMEOUT. |
| 110 | */ |
Evan Charlton | 0958f53 | 2014-01-10 16:58:02 -0800 | [diff] [blame] | 111 | private final Runnable mLookupTerminator = new Runnable() { |
| 112 | @Override |
| 113 | public void run() { |
| 114 | terminateLookup(); |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | /** Used to run code (e.g. messages, Runnables) on the main (UI) thread. */ |
| 119 | private final Handler mHandler = new Handler(Looper.getMainLooper()); |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 120 | |
| 121 | /** |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 122 | * Persists the specified parameters. |
| 123 | * |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 124 | * @param switchboard The switchboard for this finder to work against. |
| 125 | * @param outgoingCallsManager Manager in charge of placing outgoing calls. |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 126 | */ |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 127 | CallServiceFinder(Switchboard switchboard, OutgoingCallsManager outgoingCallsManager) { |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 128 | mSwitchboard = switchboard; |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 129 | mOutgoingCallsManager = outgoingCallsManager; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /** |
Evan Charlton | 0958f53 | 2014-01-10 16:58:02 -0800 | [diff] [blame] | 133 | * Initiates a lookup cycle for call-service providers. Must be called from the UI thread. |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 134 | * TODO(gilad): Expand this comment to describe the lookup flow in more detail. |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 135 | */ |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 136 | void initiateLookup() { |
Evan Charlton | 0958f53 | 2014-01-10 16:58:02 -0800 | [diff] [blame] | 137 | ThreadUtil.checkOnMainThread(); |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 138 | if (mIsLookupInProgress) { |
| 139 | // At most one active lookup is allowed at any given time, bail out. |
| 140 | return; |
| 141 | } |
| 142 | |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 143 | List<ComponentName> providerNames = getProviderNames(); |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 144 | if (providerNames.isEmpty()) { |
| 145 | Log.i(TAG, "No ICallServiceProvider implementations found."); |
| 146 | updateSwitchboard(); |
| 147 | return; |
| 148 | } |
| 149 | |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 150 | mLookupId++; |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 151 | mIsLookupInProgress = true; |
| 152 | mUnregisteredProviders = Sets.newHashSet(); |
| 153 | |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 154 | for (ComponentName name : providerNames) { |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 155 | // Bind to each of the providers that were found. Some of the providers may already be |
| 156 | // bound, and in those cases the provider wrapper will still invoke registerProvider() |
| 157 | // allowing us to treat bound and unbound providers the same. |
| 158 | getProvider(name).bind(); |
| 159 | mUnregisteredProviders.add(name); |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | int providerCount = providerNames.size(); |
| 163 | int unregisteredProviderCount = mUnregisteredProviders.size(); |
| 164 | |
Ben Gilad | b59769e | 2014-01-16 11:41:10 -0800 | [diff] [blame] | 165 | Log.i(TAG, "Found " + providerCount + " implementations of ICallServiceProvider, " |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 166 | + unregisteredProviderCount + " of which are not currently registered."); |
| 167 | |
| 168 | if (unregisteredProviderCount == 0) { |
| 169 | // All known (provider) implementations are already registered, pass control |
| 170 | // back to the switchboard. |
| 171 | updateSwitchboard(); |
| 172 | } else { |
Evan Charlton | 0958f53 | 2014-01-10 16:58:02 -0800 | [diff] [blame] | 173 | // Schedule a lookup terminator to run after LOOKUP_TIMEOUT_MS milliseconds. |
| 174 | mHandler.removeCallbacks(mLookupTerminator); |
| 175 | mHandler.postDelayed(mLookupTerminator, LOOKUP_TIMEOUT_MS); |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | /** |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 180 | * Returns the all-inclusive list of call-service-provider names. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 181 | * |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 182 | * @return The list containing the (component) names of all known ICallServiceProvider |
| 183 | * implementations or the empty list upon no available providers. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 184 | */ |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 185 | private List<ComponentName> getProviderNames() { |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 186 | // The list of provider names to return to the caller, may be populated below. |
| 187 | List<ComponentName> providerNames = Lists.newArrayList(); |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 188 | |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 189 | PackageManager packageManager = TelecommApp.getInstance().getPackageManager(); |
| 190 | Intent intent = new Intent(CallServiceProviderWrapper.CALL_SERVICE_PROVIDER_ACTION); |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 191 | for (ResolveInfo entry : packageManager.queryIntentServices(intent, 0)) { |
| 192 | ServiceInfo serviceInfo = entry.serviceInfo; |
| 193 | if (serviceInfo != null) { |
| 194 | // The entry resolves to a proper service, add it to the list of provider names. |
| 195 | providerNames.add( |
| 196 | new ComponentName(serviceInfo.packageName, serviceInfo.name)); |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 197 | } |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 198 | } |
| 199 | |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 200 | return providerNames; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /** |
Santos Cordon | cb83fb6 | 2014-01-06 10:57:57 -0800 | [diff] [blame] | 204 | * Queries the supplied provider asynchronously for its CallServices and passes the list through |
| 205 | * to {@link #registerCallServices} which will relinquish control back to switchboard. |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 206 | * |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 207 | * @param providerName The component name of the relevant provider. |
| 208 | * @param provider The provider object to register. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 209 | */ |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 210 | void registerProvider( |
| 211 | final ComponentName providerName, final CallServiceProviderWrapper provider) { |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 212 | |
Santos Cordon | cb83fb6 | 2014-01-06 10:57:57 -0800 | [diff] [blame] | 213 | // Query the provider for {@link ICallService} implementations. |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 214 | provider.lookupCallServices(new ICallServiceLookupResponse.Stub() { |
| 215 | @Override |
| 216 | public void setCallServices(final List<IBinder> binderList) { |
| 217 | // TODO(santoscordon): Do we need Binder.clear/restoreCallingIdentity()? |
| 218 | mHandler.post(new Runnable() { |
| 219 | @Override public void run() { |
| 220 | Set<ICallService> callServices = Sets.newHashSet(); |
| 221 | for (IBinder binder : binderList) { |
| 222 | callServices.add(ICallService.Stub.asInterface(binder)); |
Evan Charlton | 18cc42f | 2014-01-28 14:44:11 -0800 | [diff] [blame] | 223 | } |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 224 | registerCallServices(providerName, provider, callServices); |
| 225 | } |
| 226 | }); |
| 227 | } |
| 228 | }); |
Santos Cordon | cb83fb6 | 2014-01-06 10:57:57 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Registers the {@link CallService}s for the specified provider and performs the necessary |
| 233 | * bookkeeping to potentially return control to the switchboard before the timeout for the |
| 234 | * current lookup cycle. |
Santos Cordon | cb83fb6 | 2014-01-06 10:57:57 -0800 | [diff] [blame] | 235 | * |
Santos Cordon | cb83fb6 | 2014-01-06 10:57:57 -0800 | [diff] [blame] | 236 | * @param providerName The component name of the relevant provider. |
| 237 | * @param provider The provider associated with callServices. |
| 238 | * @param callServices The {@link CallService}s to register. |
| 239 | */ |
Evan Charlton | 18cc42f | 2014-01-28 14:44:11 -0800 | [diff] [blame] | 240 | private void registerCallServices( |
Santos Cordon | cb83fb6 | 2014-01-06 10:57:57 -0800 | [diff] [blame] | 241 | ComponentName providerName, |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 242 | CallServiceProviderWrapper provider, |
Evan Charlton | 18cc42f | 2014-01-28 14:44:11 -0800 | [diff] [blame] | 243 | Set<ICallService> callServices) { |
| 244 | ThreadUtil.checkOnMainThread(); |
Santos Cordon | cb83fb6 | 2014-01-06 10:57:57 -0800 | [diff] [blame] | 245 | |
Santos Cordon | cb83fb6 | 2014-01-06 10:57:57 -0800 | [diff] [blame] | 246 | if (mUnregisteredProviders.remove(providerName)) { |
| 247 | mProviderRegistry.add(provider); |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 248 | |
| 249 | // Add all the call services from this provider to the call-service registry. |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 250 | for (ICallService callService : callServices) { |
| 251 | try { |
| 252 | CallServiceAdapter adapter = new CallServiceAdapter(mOutgoingCallsManager); |
| 253 | callService.setCallServiceAdapter(adapter); |
| 254 | mCallServiceRegistry.add(callService); |
| 255 | } catch (RemoteException e) { |
| 256 | Log.e(TAG, "Failed to set call-service adapter."); |
| 257 | } |
| 258 | } |
Ben Gilad | 03292d4 | 2014-01-16 15:06:16 -0800 | [diff] [blame] | 259 | |
Santos Cordon | cb83fb6 | 2014-01-06 10:57:57 -0800 | [diff] [blame] | 260 | if (mUnregisteredProviders.size() < 1) { |
| 261 | terminateLookup(); // No other providers to wait for. |
| 262 | } |
| 263 | } else { |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 264 | Log.i(TAG, "Unexpected list of call services in lookup " + mLookupId + " from " + |
| 265 | providerName); |
Santos Cordon | cb83fb6 | 2014-01-06 10:57:57 -0800 | [diff] [blame] | 266 | } |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Unregisters the specified provider. |
| 271 | * |
| 272 | * @param providerName The component name of the relevant provider. |
| 273 | */ |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 274 | void unregisterProvider(ComponentName providerName) { |
Evan Charlton | 18cc42f | 2014-01-28 14:44:11 -0800 | [diff] [blame] | 275 | ThreadUtil.checkOnMainThread(); |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 276 | mProviderRegistry.remove(providerName); |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Timeouts the current lookup cycle, see LookupTerminator. |
| 281 | */ |
| 282 | private void terminateLookup() { |
Evan Charlton | 0958f53 | 2014-01-10 16:58:02 -0800 | [diff] [blame] | 283 | mHandler.removeCallbacks(mLookupTerminator); |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 284 | mUnregisteredProviders.clear(); |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame] | 285 | |
| 286 | updateSwitchboard(); |
| 287 | mIsLookupInProgress = false; |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Updates the switchboard passing the relevant call services (as opposed |
| 292 | * to call-service providers). |
| 293 | */ |
| 294 | private void updateSwitchboard() { |
Evan Charlton | 0958f53 | 2014-01-10 16:58:02 -0800 | [diff] [blame] | 295 | ThreadUtil.checkOnMainThread(); |
Ben Gilad | 03292d4 | 2014-01-16 15:06:16 -0800 | [diff] [blame] | 296 | mSwitchboard.setCallServices(mCallServiceRegistry); |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 297 | } |
Santos Cordon | 63aeb16 | 2014-02-10 09:20:40 -0800 | [diff] [blame] | 298 | |
| 299 | /** |
| 300 | * Returns the call-service provider wrapper for the specified componentName. Creates a new one |
| 301 | * if none is found in the cache. |
| 302 | * |
| 303 | * @param ComponentName The component name of the provider. |
| 304 | */ |
| 305 | private CallServiceProviderWrapper getProvider(ComponentName componentName) { |
| 306 | Preconditions.checkNotNull(componentName); |
| 307 | |
| 308 | CallServiceProviderWrapper provider = mProviderCache.get(componentName); |
| 309 | if (provider == null) { |
| 310 | provider = new CallServiceProviderWrapper(componentName, this); |
| 311 | mProviderCache.put(componentName, provider); |
| 312 | } |
| 313 | |
| 314 | return provider; |
| 315 | } |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 316 | } |