blob: 29890b668aa8b0f23e723a9e460aaef79e60e2ed [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 Cordone3d76ab2014-01-28 17:25:20 -080038 private final Switchboard mSwitchboard;
39
40 /** Used to control the in-call app. */
41 private final InCallController mInCallController;
42
Santos Cordon8e8b8d22013-12-19 14:14:05 -080043 /**
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 Gilad9f2bed32013-12-12 17:43:26 -080049
Santos Cordon8e8b8d22013-12-19 14:14:05 -080050 private InCallAdapter mInCallAdapter;
Ben Gilad9f2bed32013-12-12 17:43:26 -080051
Santos Cordon8e8b8d22013-12-19 14:14:05 -080052 private CallLogManager mCallLogManager;
Ben Gilad9f2bed32013-12-12 17:43:26 -080053
Santos Cordon8e8b8d22013-12-19 14:14:05 -080054 private VoicemailManager mVoicemailManager;
Ben Gilad9f2bed32013-12-12 17:43:26 -080055
Santos Cordon8e8b8d22013-12-19 14:14:05 -080056 private List<OutgoingCallFilter> mOutgoingCallFilters = Lists.newArrayList();
Ben Gilad9f2bed32013-12-12 17:43:26 -080057
Santos Cordon8e8b8d22013-12-19 14:14:05 -080058 private List<IncomingCallFilter> mIncomingCallFilters = Lists.newArrayList();
Ben Gilad9f2bed32013-12-12 17:43:26 -080059
Santos Cordon8e8b8d22013-12-19 14:14:05 -080060 static CallsManager getInstance() {
61 return INSTANCE;
Ben Gilad9f2bed32013-12-12 17:43:26 -080062 }
63
Santos Cordon8e8b8d22013-12-19 14:14:05 -080064 /**
65 * Private constructor initializes main components of telecomm.
66 */
67 private CallsManager() {
68 mSwitchboard = new Switchboard();
Santos Cordone3d76ab2014-01-28 17:25:20 -080069 mInCallController = new InCallController(this);
Santos Cordon8e8b8d22013-12-19 14:14:05 -080070 }
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 Cordone3d76ab2014-01-28 17:25:20 -080092
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 Gilad9f2bed32013-12-12 17:43:26 -0800125}