blob: ce8674f1dc29fd99631f8a93bd3c909065020af4 [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
Ben Gilad9f2bed32013-12-12 17:43:26 -080025import java.util.List;
26
Ben Giladdd8c6082013-12-30 14:44:08 -080027/**
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 Cordon8e8b8d22013-12-19 14:14:05 -080034public final class CallsManager {
Ben Gilad9f2bed32013-12-12 17:43:26 -080035
Santos Cordon8e8b8d22013-12-19 14:14:05 -080036 private static final CallsManager INSTANCE = new CallsManager();
Ben Gilad9f2bed32013-12-12 17:43:26 -080037
Santos Cordon8e8b8d22013-12-19 14:14:05 -080038 /**
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 Gilad9f2bed32013-12-12 17:43:26 -080044
Santos Cordon8e8b8d22013-12-19 14:14:05 -080045 private InCallAdapter mInCallAdapter;
Ben Gilad9f2bed32013-12-12 17:43:26 -080046
Santos Cordon8e8b8d22013-12-19 14:14:05 -080047 private Switchboard mSwitchboard;
Ben Gilad9f2bed32013-12-12 17:43:26 -080048
Santos Cordon8e8b8d22013-12-19 14:14:05 -080049 private CallLogManager mCallLogManager;
Ben Gilad9f2bed32013-12-12 17:43:26 -080050
Santos Cordon8e8b8d22013-12-19 14:14:05 -080051 private VoicemailManager mVoicemailManager;
Ben Gilad9f2bed32013-12-12 17:43:26 -080052
Santos Cordon8e8b8d22013-12-19 14:14:05 -080053 private List<OutgoingCallFilter> mOutgoingCallFilters = Lists.newArrayList();
Ben Gilad9f2bed32013-12-12 17:43:26 -080054
Santos Cordon8e8b8d22013-12-19 14:14:05 -080055 private List<IncomingCallFilter> mIncomingCallFilters = Lists.newArrayList();
Ben Gilad9f2bed32013-12-12 17:43:26 -080056
Santos Cordon8e8b8d22013-12-19 14:14:05 -080057 static CallsManager getInstance() {
58 return INSTANCE;
Ben Gilad9f2bed32013-12-12 17:43:26 -080059 }
60
Santos Cordon8e8b8d22013-12-19 14:14:05 -080061 /**
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 Gilad9f2bed32013-12-12 17:43:26 -080088}