blob: 71c666d41094cb284509dc8d7b5c56f39c017ef8 [file] [log] [blame]
Santos Cordon8e8b8d22013-12-19 14:14:05 -08001/*
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 Gilad9f2bed32013-12-12 17:43:26 -080017package com.android.telecomm;
18
Santos Cordon8e8b8d22013-12-19 14:14:05 -080019import android.content.Context;
20
Ben Gilad9f2bed32013-12-12 17:43:26 -080021import com.android.telecomm.exceptions.CallServiceUnavailableException;
22import com.android.telecomm.exceptions.RestrictedCallException;
Santos Cordon8e8b8d22013-12-19 14:14:05 -080023import com.google.common.collect.Lists;
Ben Gilad9f2bed32013-12-12 17:43:26 -080024
25import java.util.ArrayList;
26import java.util.List;
27
Ben Giladdd8c6082013-12-30 14:44:08 -080028/**
29 * Singleton.
30 *
31 * NOTE(gilad): by design most APIs are package private, use the relevant adapter/s to allow
32 * access from other packages specifically refraining from passing the CallsManager instance
33 * beyond the com.android.telecomm package boundary.
34 */
Santos Cordon8e8b8d22013-12-19 14:14:05 -080035public final class CallsManager {
Ben Gilad9f2bed32013-12-12 17:43:26 -080036
Santos Cordon8e8b8d22013-12-19 14:14:05 -080037 private static final CallsManager INSTANCE = new CallsManager();
Ben Gilad9f2bed32013-12-12 17:43:26 -080038
Santos Cordon8e8b8d22013-12-19 14:14:05 -080039 /**
40 * May be unnecessary per off-line discussions (between santoscordon and gilad) since the set
41 * of CallsManager APIs that need to be exposed to the dialer (or any application firing call
42 * intents) may be empty.
43 */
44 private DialerAdapter mDialerAdapter;
Ben Gilad9f2bed32013-12-12 17:43:26 -080045
Santos Cordon8e8b8d22013-12-19 14:14:05 -080046 private InCallAdapter mInCallAdapter;
Ben Gilad9f2bed32013-12-12 17:43:26 -080047
Santos Cordon8e8b8d22013-12-19 14:14:05 -080048 private Switchboard mSwitchboard;
Ben Gilad9f2bed32013-12-12 17:43:26 -080049
Santos Cordon8e8b8d22013-12-19 14:14:05 -080050 private CallLogManager mCallLogManager;
Ben Gilad9f2bed32013-12-12 17:43:26 -080051
Santos Cordon8e8b8d22013-12-19 14:14:05 -080052 private VoicemailManager mVoicemailManager;
Ben Gilad9f2bed32013-12-12 17:43:26 -080053
Santos Cordon8e8b8d22013-12-19 14:14:05 -080054 private List<OutgoingCallFilter> mOutgoingCallFilters = Lists.newArrayList();
Ben Gilad9f2bed32013-12-12 17:43:26 -080055
Santos Cordon8e8b8d22013-12-19 14:14:05 -080056 private List<IncomingCallFilter> mIncomingCallFilters = Lists.newArrayList();
Ben Gilad9f2bed32013-12-12 17:43:26 -080057
Santos Cordon8e8b8d22013-12-19 14:14:05 -080058 static CallsManager getInstance() {
59 return INSTANCE;
Ben Gilad9f2bed32013-12-12 17:43:26 -080060 }
61
Santos Cordon8e8b8d22013-12-19 14:14:05 -080062 /**
63 * Private constructor initializes main components of telecomm.
64 */
65 private CallsManager() {
66 mSwitchboard = new Switchboard();
67 }
68
69 /**
70 * Attempts to issue/connect the specified call. From an (arbitrary) application standpoint,
71 * all that is required to initiate this flow is to fire either of the CALL, CALL_PRIVILEGED,
72 * and CALL_EMERGENCY intents. These are listened to by CallActivity.java which then invokes
73 * this method.
74 *
75 * @param handle The handle to dial.
76 * @param contactInfo Information about the entity being called.
77 * @param context The application context.
78 */
79 void processOutgoingCallIntent(String handle, ContactInfo contactInfo, Context context)
80 throws RestrictedCallException, CallServiceUnavailableException {
81
82 for (OutgoingCallFilter policy : mOutgoingCallFilters) {
83 policy.validate(handle, contactInfo);
84 }
85
86 // No objection to issue the call, proceed with trying to put it through.
87 mSwitchboard.placeOutgoingCall(handle, contactInfo, context);
88 }
Ben Gilad9f2bed32013-12-12 17:43:26 -080089}