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 | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 38 | /** |
| 39 | * May be unnecessary per off-line discussions (between santoscordon and gilad) since the set |
| 40 | * of CallsManager APIs that need to be exposed to the dialer (or any application firing call |
| 41 | * intents) may be empty. |
| 42 | */ |
| 43 | private DialerAdapter mDialerAdapter; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 44 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 45 | private InCallAdapter mInCallAdapter; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 46 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 47 | private Switchboard mSwitchboard; |
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 CallLogManager mCallLogManager; |
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 VoicemailManager mVoicemailManager; |
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 List<OutgoingCallFilter> mOutgoingCallFilters = Lists.newArrayList(); |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 54 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 55 | private List<IncomingCallFilter> mIncomingCallFilters = Lists.newArrayList(); |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 56 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 57 | static CallsManager getInstance() { |
| 58 | return INSTANCE; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Santos Cordon | 8e8b8d2 | 2013-12-19 14:14:05 -0800 | [diff] [blame] | 61 | /** |
| 62 | * Private constructor initializes main components of telecomm. |
| 63 | */ |
| 64 | private CallsManager() { |
| 65 | mSwitchboard = new Switchboard(); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Attempts to issue/connect the specified call. From an (arbitrary) application standpoint, |
| 70 | * all that is required to initiate this flow is to fire either of the CALL, CALL_PRIVILEGED, |
| 71 | * and CALL_EMERGENCY intents. These are listened to by CallActivity.java which then invokes |
| 72 | * this method. |
| 73 | * |
| 74 | * @param handle The handle to dial. |
| 75 | * @param contactInfo Information about the entity being called. |
| 76 | * @param context The application context. |
| 77 | */ |
| 78 | void processOutgoingCallIntent(String handle, ContactInfo contactInfo, Context context) |
| 79 | throws RestrictedCallException, CallServiceUnavailableException { |
| 80 | |
| 81 | for (OutgoingCallFilter policy : mOutgoingCallFilters) { |
| 82 | policy.validate(handle, contactInfo); |
| 83 | } |
| 84 | |
| 85 | // No objection to issue the call, proceed with trying to put it through. |
| 86 | mSwitchboard.placeOutgoingCall(handle, contactInfo, context); |
| 87 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 88 | } |