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 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 17 | package com.android.telecomm; |
| 18 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 21 | import com.android.telecomm.exceptions.RestrictedCallException; |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 22 | import com.google.common.collect.Lists; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 23 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 24 | import java.util.List; |
| 25 | |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame] | 26 | /** |
| 27 | * Singleton. |
| 28 | * |
| 29 | * NOTE(gilad): by design most APIs are package private, use the relevant adapter/s to allow |
| 30 | * access from other packages specifically refraining from passing the CallsManager instance |
| 31 | * beyond the com.android.telecomm package boundary. |
| 32 | */ |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 33 | public final class CallsManager { |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 34 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 35 | private static final CallsManager INSTANCE = new CallsManager(); |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 36 | |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 37 | private final Switchboard mSwitchboard; |
| 38 | |
| 39 | /** Used to control the in-call app. */ |
| 40 | private final InCallController mInCallController; |
| 41 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 42 | /** |
| 43 | * May be unnecessary per off-line discussions (between santoscordon and gilad) since the set |
| 44 | * of CallsManager APIs that need to be exposed to the dialer (or any application firing call |
| 45 | * intents) may be empty. |
| 46 | */ |
| 47 | private DialerAdapter mDialerAdapter; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 48 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 49 | private InCallAdapter mInCallAdapter; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 50 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 51 | private CallLogManager mCallLogManager; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 52 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 53 | private VoicemailManager mVoicemailManager; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 54 | |
Ben Gilad | 8bdaa46 | 2014-02-05 12:53:19 -0800 | [diff] [blame] | 55 | private List<OutgoingCallValidator> mOutgoingCallValidators = Lists.newArrayList(); |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 56 | |
Ben Gilad | 8bdaa46 | 2014-02-05 12:53:19 -0800 | [diff] [blame] | 57 | private List<IncomingCallValidator> mIncomingCallValidators = Lists.newArrayList(); |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 58 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 59 | static CallsManager getInstance() { |
| 60 | return INSTANCE; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 61 | } |
| 62 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 63 | /** |
Ben Gilad | 8bdaa46 | 2014-02-05 12:53:19 -0800 | [diff] [blame] | 64 | * Initializes the required Telecomm components. |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 65 | */ |
| 66 | private CallsManager() { |
| 67 | mSwitchboard = new Switchboard(); |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 68 | mInCallController = new InCallController(this); |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Attempts to issue/connect the specified call. From an (arbitrary) application standpoint, |
| 73 | * all that is required to initiate this flow is to fire either of the CALL, CALL_PRIVILEGED, |
| 74 | * and CALL_EMERGENCY intents. These are listened to by CallActivity.java which then invokes |
| 75 | * this method. |
| 76 | * |
| 77 | * @param handle The handle to dial. |
| 78 | * @param contactInfo Information about the entity being called. |
| 79 | * @param context The application context. |
| 80 | */ |
| 81 | void processOutgoingCallIntent(String handle, ContactInfo contactInfo, Context context) |
Ben Gilad | 8bdaa46 | 2014-02-05 12:53:19 -0800 | [diff] [blame] | 82 | throws RestrictedCallException { |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 83 | |
Ben Gilad | 8bdaa46 | 2014-02-05 12:53:19 -0800 | [diff] [blame] | 84 | for (OutgoingCallValidator validator : mOutgoingCallValidators) { |
| 85 | validator.validate(handle, contactInfo); |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | // No objection to issue the call, proceed with trying to put it through. |
| 89 | mSwitchboard.placeOutgoingCall(handle, contactInfo, context); |
| 90 | } |
Santos Cordon | e3d76ab | 2014-01-28 17:25:20 -0800 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * Instructs Telecomm to answer the specified call. Intended to be invoked by the in-call |
| 94 | * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by |
| 95 | * the user opting to answer said call. |
| 96 | * |
| 97 | * @param callId The ID of the call. |
| 98 | */ |
| 99 | void answerCall(String callId) { |
| 100 | // TODO(santoscordon): fill in and check that it is in the ringing state. |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Instructs Telecomm to reject the specified call. Intended to be invoked by the in-call |
| 105 | * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by |
| 106 | * the user opting to reject said call. |
| 107 | * |
| 108 | * @param callId The ID of the call. |
| 109 | */ |
| 110 | void rejectCall(String callId) { |
| 111 | // TODO(santoscordon): fill in and check that it is in the ringing state. |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Instructs Telecomm to disconnect the specified call. Intended to be invoked by the |
| 116 | * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by |
| 117 | * the user hitting the end-call button. |
| 118 | * |
| 119 | * @param callId The ID of the call. |
| 120 | */ |
| 121 | void disconnectCall(String callId) { |
| 122 | // TODO(santoscordon): fill in and check that the call is in the active state. |
| 123 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 124 | } |