blob: 0712f03f005ade407c043efa58dda755e9f05bd3 [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.RestrictedCallException;
Santos Cordon8e8b8d22013-12-19 14:14:05 -080022import com.google.common.collect.Lists;
Ben Gilad9f2bed32013-12-12 17:43:26 -080023
Ben Gilad9f2bed32013-12-12 17:43:26 -080024import java.util.List;
25
Ben Giladdd8c6082013-12-30 14:44:08 -080026/**
27 * Singleton.
28 *
29 * NOTE(gilad): by design most APIs are package private, use the relevant adapter/s to allow
30 * access from other packages specifically refraining from passing the CallsManager instance
31 * beyond the com.android.telecomm package boundary.
32 */
Santos Cordon8e8b8d22013-12-19 14:14:05 -080033public final class CallsManager {
Ben Gilad9f2bed32013-12-12 17:43:26 -080034
Santos Cordon8e8b8d22013-12-19 14:14:05 -080035 private static final CallsManager INSTANCE = new CallsManager();
Ben Gilad9f2bed32013-12-12 17:43:26 -080036
Santos Cordone3d76ab2014-01-28 17:25:20 -080037 private final Switchboard mSwitchboard;
38
39 /** Used to control the in-call app. */
40 private final InCallController mInCallController;
41
Santos Cordon8e8b8d22013-12-19 14:14:05 -080042 /**
43 * May be unnecessary per off-line discussions (between santoscordon and gilad) since the set
44 * of CallsManager APIs that need to be exposed to the dialer (or any application firing call
45 * intents) may be empty.
46 */
47 private DialerAdapter mDialerAdapter;
Ben Gilad9f2bed32013-12-12 17:43:26 -080048
Santos Cordon8e8b8d22013-12-19 14:14:05 -080049 private InCallAdapter mInCallAdapter;
Ben Gilad9f2bed32013-12-12 17:43:26 -080050
Santos Cordon8e8b8d22013-12-19 14:14:05 -080051 private CallLogManager mCallLogManager;
Ben Gilad9f2bed32013-12-12 17:43:26 -080052
Santos Cordon8e8b8d22013-12-19 14:14:05 -080053 private VoicemailManager mVoicemailManager;
Ben Gilad9f2bed32013-12-12 17:43:26 -080054
Ben Gilad8bdaa462014-02-05 12:53:19 -080055 private List<OutgoingCallValidator> mOutgoingCallValidators = Lists.newArrayList();
Ben Gilad9f2bed32013-12-12 17:43:26 -080056
Ben Gilad8bdaa462014-02-05 12:53:19 -080057 private List<IncomingCallValidator> mIncomingCallValidators = Lists.newArrayList();
Ben Gilad9f2bed32013-12-12 17:43:26 -080058
Santos Cordon8e8b8d22013-12-19 14:14:05 -080059 static CallsManager getInstance() {
60 return INSTANCE;
Ben Gilad9f2bed32013-12-12 17:43:26 -080061 }
62
Santos Cordon8e8b8d22013-12-19 14:14:05 -080063 /**
Ben Gilad8bdaa462014-02-05 12:53:19 -080064 * Initializes the required Telecomm components.
Santos Cordon8e8b8d22013-12-19 14:14:05 -080065 */
66 private CallsManager() {
67 mSwitchboard = new Switchboard();
Santos Cordone3d76ab2014-01-28 17:25:20 -080068 mInCallController = new InCallController(this);
Santos Cordon8e8b8d22013-12-19 14:14:05 -080069 }
70
71 /**
72 * Attempts to issue/connect the specified call. From an (arbitrary) application standpoint,
73 * all that is required to initiate this flow is to fire either of the CALL, CALL_PRIVILEGED,
74 * and CALL_EMERGENCY intents. These are listened to by CallActivity.java which then invokes
75 * this method.
76 *
77 * @param handle The handle to dial.
78 * @param contactInfo Information about the entity being called.
79 * @param context The application context.
80 */
81 void processOutgoingCallIntent(String handle, ContactInfo contactInfo, Context context)
Ben Gilad8bdaa462014-02-05 12:53:19 -080082 throws RestrictedCallException {
Santos Cordon8e8b8d22013-12-19 14:14:05 -080083
Ben Gilad8bdaa462014-02-05 12:53:19 -080084 for (OutgoingCallValidator validator : mOutgoingCallValidators) {
85 validator.validate(handle, contactInfo);
Santos Cordon8e8b8d22013-12-19 14:14:05 -080086 }
87
88 // No objection to issue the call, proceed with trying to put it through.
89 mSwitchboard.placeOutgoingCall(handle, contactInfo, context);
90 }
Santos Cordone3d76ab2014-01-28 17:25:20 -080091
92 /**
93 * Instructs Telecomm to answer the specified call. Intended to be invoked by the in-call
94 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
95 * the user opting to answer said call.
96 *
97 * @param callId The ID of the call.
98 */
99 void answerCall(String callId) {
100 // TODO(santoscordon): fill in and check that it is in the ringing state.
101 }
102
103 /**
104 * Instructs Telecomm to reject the specified call. Intended to be invoked by the in-call
105 * app through {@link InCallAdapter} after Telecomm notifies it of an incoming call followed by
106 * the user opting to reject said call.
107 *
108 * @param callId The ID of the call.
109 */
110 void rejectCall(String callId) {
111 // TODO(santoscordon): fill in and check that it is in the ringing state.
112 }
113
114 /**
115 * Instructs Telecomm to disconnect the specified call. Intended to be invoked by the
116 * in-call app through {@link InCallAdapter} for an ongoing call. This is usually triggered by
117 * the user hitting the end-call button.
118 *
119 * @param callId The ID of the call.
120 */
121 void disconnectCall(String callId) {
122 // TODO(santoscordon): fill in and check that the call is in the active state.
123 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800124}