Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 1 | package com.android.telecomm; |
| 2 | |
| 3 | import com.android.telecomm.exceptions.CallServiceUnavailableException; |
| 4 | import com.android.telecomm.exceptions.RestrictedCallException; |
| 5 | |
| 6 | import java.util.ArrayList; |
| 7 | import java.util.List; |
| 8 | |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame^] | 9 | /** |
| 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 Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 16 | public class CallsManager { |
| 17 | |
| 18 | private static final CallsManager INSTANCE = new CallsManager(); |
| 19 | |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame^] | 20 | /** |
| 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 Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 25 | 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 Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 48 | static CallsManager getInstance() { |
| 49 | return INSTANCE; |
| 50 | } |
| 51 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 52 | // 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 Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame^] | 60 | /** |
| 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 Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 67 | throws RestrictedCallException, CallServiceUnavailableException { |
| 68 | |
| 69 | for (OutgoingCallFilter policy : outgoingCallFilters) { |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame^] | 70 | policy.validate(handle, contactInfo); |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | // No objection to issue the call, proceed with trying to put it through. |
Ben Gilad | dd8c608 | 2013-12-30 14:44:08 -0800 | [diff] [blame^] | 74 | switchboard.placeOutgoingCall(handle, contactInfo); |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 75 | } |
| 76 | } |