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