blob: a5fdcf7cbef895e8249026c7b8e90463e239e6c4 [file] [log] [blame]
Ben Gilad9f2bed32013-12-12 17:43:26 -08001package com.android.telecomm;
2
3import com.android.telecomm.exceptions.CallServiceUnavailableException;
4import com.android.telecomm.exceptions.RestrictedCallException;
5
6import java.util.ArrayList;
7import java.util.List;
8
Ben Giladdd8c6082013-12-30 14:44:08 -08009/**
10 * Singleton.
11 *
12 * NOTE(gilad): by design most APIs are package private, use the relevant adapter/s to allow
13 * access from other packages specifically refraining from passing the CallsManager instance
14 * beyond the com.android.telecomm package boundary.
15 */
Ben Gilad9f2bed32013-12-12 17:43:26 -080016public class CallsManager {
17
18 private static final CallsManager INSTANCE = new CallsManager();
19
Ben Giladdd8c6082013-12-30 14:44:08 -080020 /**
21 * May be unnecessary per off-line discussions (between santoscordon and gilad) since the set
22 * of CallsManager APIs that need to be exposed to the dialer (or any application firing call
23 * intents) may be empty.
24 */
Ben Gilad9f2bed32013-12-12 17:43:26 -080025 private DialerAdapter dialerAdapter;
26
27 private InCallAdapter inCallAdapter;
28
29 private Switchboard switchboard;
30
31 private CallLogManager callLogManager;
32
33 private VoicemailManager voicemailManager;
34
35 private List<OutgoingCallFilter> outgoingCallFilters =
36 new ArrayList<OutgoingCallFilter>();
37
38 private List<IncomingCallFilter> incomingCallFilters =
39 new ArrayList<IncomingCallFilter>();
40
41 // Singleton, private constructor (see getInstance).
42 private CallsManager() {
43 switchboard = new Switchboard();
44 callLogManager = new CallLogManager();
45 voicemailManager = new VoicemailManager(); // As necessary etc.
46 }
47
Ben Gilad9f2bed32013-12-12 17:43:26 -080048 static CallsManager getInstance() {
49 return INSTANCE;
50 }
51
Ben Gilad9f2bed32013-12-12 17:43:26 -080052 // TODO(gilad): Circle back to how we'd want to do this.
53 void addCallService(CallService callService) {
54 if (callService != null) {
55 switchboard.addCallService(callService);
56 callService.setCallServiceAdapter(new CallServiceAdapter(this));
57 }
58 }
59
Ben Giladdd8c6082013-12-30 14:44:08 -080060 /**
61 * Attempts to issue/connect the specified call. From an (arbitrary) application standpoint,
62 * all that is required to initiate this flow is to fire either of the CALL, CALL_PRIVILEGED,
63 * and CALL_EMERGENCY intents. These are listened to by CallActivity.java which then invokes
64 * this method.
65 */
66 void processOutgoingCallIntent(String handle, ContactInfo contactInfo)
Ben Gilad9f2bed32013-12-12 17:43:26 -080067 throws RestrictedCallException, CallServiceUnavailableException {
68
69 for (OutgoingCallFilter policy : outgoingCallFilters) {
Ben Giladdd8c6082013-12-30 14:44:08 -080070 policy.validate(handle, contactInfo);
Ben Gilad9f2bed32013-12-12 17:43:26 -080071 }
72
73 // No objection to issue the call, proceed with trying to put it through.
Ben Giladdd8c6082013-12-30 14:44:08 -080074 switchboard.placeOutgoingCall(handle, contactInfo);
Ben Gilad9f2bed32013-12-12 17:43:26 -080075 }
76}