blob: b33df50dec01b8d5f37bd736bc6b287b3a6b6845 [file] [log] [blame]
Santos Cordon8e8b8d22013-12-19 14:14:05 -08001/*
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 Gilad9f2bed32013-12-12 17:43:26 -080017package com.android.telecomm;
18
Evan Charltonac1aa9e2014-01-03 13:47:12 -080019import com.google.common.collect.Lists;
Santos Cordon8e8b8d22013-12-19 14:14:05 -080020
21import android.content.Context;
22import android.os.RemoteException;
23import android.telecomm.ICallService;
24import android.util.Log;
25
Ben Gilad9f2bed32013-12-12 17:43:26 -080026import com.android.telecomm.exceptions.CallServiceUnavailableException;
27import com.android.telecomm.exceptions.OutgoingCallException;
28
Ben Gilad9f2bed32013-12-12 17:43:26 -080029import java.util.List;
30
Santos Cordon8e8b8d22013-12-19 14:14:05 -080031/**
32 * Switchboard is responsible for (1) selecting the {@link ICallService} through which to make
33 * outgoing calls and (2) switching active calls between transports (each ICallService is
34 * considered a different transport type).
35 * TODO(santoscordon): Need to add comments on the switchboard optimizer once that it is place.
36 */
Ben Giladd17443c2014-01-06 11:04:15 -080037final class Switchboard {
Santos Cordon8e8b8d22013-12-19 14:14:05 -080038 /** Used to identify log entries by this class */
39 private static final String TAG = Switchboard.class.getSimpleName();
Ben Gilad9f2bed32013-12-12 17:43:26 -080040
Ben Giladd17443c2014-01-06 11:04:15 -080041 private CallServiceFinder callServiceFinder = new CallServiceFinder();
42
Santos Cordon8e8b8d22013-12-19 14:14:05 -080043 /**
44 * Places an outgoing call to the handle passed in. Method asynchronously collects
45 * {@link ICallService} implementations and passes them along with the handle and contactInfo
46 * to {@link #placeOutgoingCallInternal} to actually place the call.
47 *
Ben Giladd17443c2014-01-06 11:04:15 -080048 * @param handle The handle to dial. Marked as final so it can be used in the inner class.
49 * @param contactInfo Information about the entity being called. Marked as final so it can
50 * be used in the inner class.
Santos Cordon8e8b8d22013-12-19 14:14:05 -080051 * @param context The application context.
52 */
Ben Giladd17443c2014-01-06 11:04:15 -080053 void placeOutgoingCall(String handle, ContactInfo contactInfo, Context context) {
54 callServiceFinder.initiateLookup(context);
Ben Gilad9f2bed32013-12-12 17:43:26 -080055
Ben Giladd17443c2014-01-06 11:04:15 -080056 // TODO(gilad): Persist the necessary parameters to attempt putting the call through
57 // once the call services become available (likely using some sort of closure).
Ben Gilad9f2bed32013-12-12 17:43:26 -080058 }
59
Santos Cordon8e8b8d22013-12-19 14:14:05 -080060 /**
61 * Places an outgoing call to the handle passed in. Given a list of {@link ICallServices},
62 * select one and place a call to the handle.
63 * TODO(santoscordon): How does the CallService selection process work?
Ben Giladd17443c2014-01-06 11:04:15 -080064 * TODO(gilad): Wire this logic from CallServiceFinder.updateSwitchboard.
Santos Cordon8e8b8d22013-12-19 14:14:05 -080065 *
66 * @param handle The handle to dial.
67 * @param contactInfo Information about the entity being called.
68 * @param callServices The list of available {@link ICallService}s.
69 */
Ben Giladd17443c2014-01-06 11:04:15 -080070// private void placeOutgoingCallInternal(
71// String handle,
72// ContactInfo contactInfo,
73// List<ICallService> callServices) throws CallServiceUnavailableException {
74//
75// Log.i(TAG, "Placing and outgoing call.");
76//
77// if (callServices.isEmpty()) {
78// // No call services, bail out.
79// // TODO(contacts-team): Add logging?
80// // TODO(santoscordon): Does this actually go anywhere considering this method is now
81// // asynchronous?
82// throw new CallServiceUnavailableException("No CallService found.");
83// }
84//
85// List<ICallService> compatibleCallServices = Lists.newArrayList();
86// for (ICallService service : callServices) {
87// // TODO(santoscordon): This code needs to be updated to an asynchronous response
88// // callback from isCompatibleWith().
89// /* if (service.isCompatibleWith(handle)) {
90// // NOTE(android-contacts): If we end up taking the liberty to issue
91// // calls not using the explicit user input (in case one is provided)
92// // and instead pull an alternative method of communication from the
93// // specified user-info object, it may be desirable to give precedence
94// // to services that can in fact respect the user's intent.
95// compatibleCallServices.add(service);
96// }
97// */
98// }
99//
100// if (compatibleCallServices.isEmpty()) {
101// // None of the available call services is suitable for making this call.
102// // TODO(contacts-team): Same here re logging.
103// throw new CallServiceUnavailableException("No compatible CallService found.");
104// }
105//
106// // NOTE(android-team): At this point we can also prompt the user for
107// // preference, i.e. instead of the logic just below.
108// if (compatibleCallServices.size() > 1) {
109// compatibleCallServices = sort(compatibleCallServices);
110// }
111// for (ICallService service : compatibleCallServices) {
112// try {
113// service.call(handle);
114// return;
115// } catch (RemoteException e) {
116// // TODO(santoscordon): Need some proxy for ICallService so that we don't have to
117// // avoid RemoteExceptionHandling everywhere. Take a look at how InputMethodService
118// // handles this.
119// }
120// // catch (OutgoingCallException ignored) {
121// // TODO(santoscordon): Figure out how OutgoingCallException falls into this. Should
122// // RemoteExceptions also be converted to OutgoingCallExceptions thrown by call()?
123// }
124// }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800125
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800126 /**
Ben Giladd17443c2014-01-06 11:04:15 -0800127 * Sorts a list of {@link ICallService} ordered by the preferred service for dialing the call.
Santos Cordon8e8b8d22013-12-19 14:14:05 -0800128 *
129 * @param callServices The list to order.
130 */
131 private List<ICallService> sort(List<ICallService> callServices) {
132 // TODO(android-contacts): Sort by reliability, cost, and ultimately
133 // the desirability to issue a given call over each of the specified
134 // call services.
135 return callServices;
Ben Gilad9f2bed32013-12-12 17:43:26 -0800136 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800137}