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 | |
Evan Charlton | ac1aa9e | 2014-01-03 13:47:12 -0800 | [diff] [blame] | 19 | import com.google.common.collect.Lists; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 20 | |
| 21 | import android.content.Context; |
| 22 | import android.os.RemoteException; |
| 23 | import android.telecomm.ICallService; |
| 24 | import android.util.Log; |
| 25 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 26 | import com.android.telecomm.exceptions.CallServiceUnavailableException; |
| 27 | import com.android.telecomm.exceptions.OutgoingCallException; |
| 28 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 29 | import java.util.List; |
| 30 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 31 | /** |
| 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 Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame^] | 37 | final class Switchboard { |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 38 | /** Used to identify log entries by this class */ |
| 39 | private static final String TAG = Switchboard.class.getSimpleName(); |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 40 | |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame^] | 41 | private CallServiceFinder callServiceFinder = new CallServiceFinder(); |
| 42 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 43 | /** |
| 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 Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame^] | 48 | * @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 Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 51 | * @param context The application context. |
| 52 | */ |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame^] | 53 | void placeOutgoingCall(String handle, ContactInfo contactInfo, Context context) { |
| 54 | callServiceFinder.initiateLookup(context); |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 55 | |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame^] | 56 | // 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 Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 60 | /** |
| 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 Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame^] | 64 | * TODO(gilad): Wire this logic from CallServiceFinder.updateSwitchboard. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 65 | * |
| 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 Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame^] | 70 | // 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 Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 125 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 126 | /** |
Ben Gilad | d17443c | 2014-01-06 11:04:15 -0800 | [diff] [blame^] | 127 | * Sorts a list of {@link ICallService} ordered by the preferred service for dialing the call. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 128 | * |
| 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 Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 136 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 137 | } |