blob: 834bf4452b2b7c1174842ce1d0765b37f18f3fdd [file] [log] [blame]
Santos Cordon8e8b8d22013-12-19 14:14:05 -08001/*
2 * Copyright 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 Cordon5b7b9b32014-03-26 14:00:22 -070019import android.content.ComponentName;
Evan Charltona05805b2014-03-05 08:21:46 -080020import android.os.Bundle;
Ben Gilad2313e622014-02-06 12:02:25 -080021import android.os.Handler;
Santos Cordonc499c1c2014-04-14 17:13:14 -070022import android.os.Message;
Sailesh Nepal810735e2014-03-18 18:15:46 -070023import android.telecomm.CallInfo;
Ben Giladc5b22692014-02-18 20:03:22 -080024import android.telecomm.CallServiceDescriptor;
Evan Charltona05805b2014-03-05 08:21:46 -080025import android.telecomm.TelecommConstants;
Santos Cordon8e8b8d22013-12-19 14:14:05 -080026
Santos Cordon74d420b2014-05-07 14:38:47 -070027import com.android.telecomm.BaseRepository.LookupCallback;
Santos Cordon5b7b9b32014-03-26 14:00:22 -070028import com.google.common.base.Preconditions;
29import com.google.common.collect.ImmutableCollection;
30import com.google.common.collect.ImmutableList;
31import com.google.common.collect.Sets;
32
33import java.util.Collection;
Ben Gilad0407fb22014-01-09 16:18:41 -080034import java.util.Set;
Ben Gilad9f2bed32013-12-12 17:43:26 -080035
Santos Cordon8e8b8d22013-12-19 14:14:05 -080036/**
Sailesh Nepal18386a82014-03-19 10:22:40 -070037 * Switchboard is responsible for:
Santos Cordon5b7b9b32014-03-26 14:00:22 -070038 * - gathering the {@link CallServiceWrapper}s and {@link CallServiceSelectorWrapper}s through
39 * which to place outgoing calls
Santos Cordon8e8b8d22013-12-19 14:14:05 -080040 */
Ben Giladd17443c2014-01-06 11:04:15 -080041final class Switchboard {
Santos Cordon766d04f2014-05-06 10:28:25 -070042 private final static Switchboard sInstance = new Switchboard();
Ben Gilad2313e622014-02-06 12:02:25 -080043
Santos Cordon493e8f22014-02-19 03:15:12 -080044 /** Used to retrieve incoming call details. */
Santos Cordon80d9bdc2014-02-13 18:28:46 -080045 private final IncomingCallsManager mIncomingCallsManager;
46
Santos Cordonc195e362014-02-11 17:05:31 -080047 private final CallServiceRepository mCallServiceRepository;
Santos Cordon681663d2014-01-30 04:32:15 -080048
Santos Cordonc195e362014-02-11 17:05:31 -080049 private final CallServiceSelectorRepository mSelectorRepository;
Ben Gilad2313e622014-02-06 12:02:25 -080050
Santos Cordon766d04f2014-05-06 10:28:25 -070051 /** Singleton accessor. */
52 static Switchboard getInstance() {
53 return sInstance;
54 }
55
Santos Cordonc195e362014-02-11 17:05:31 -080056 /**
Santos Cordon681663d2014-01-30 04:32:15 -080057 * Persists the specified parameters and initializes Switchboard.
58 */
Santos Cordon766d04f2014-05-06 10:28:25 -070059 private Switchboard() {
Santos Cordonc499c1c2014-04-14 17:13:14 -070060 ThreadUtil.checkOnMainThread();
61
Santos Cordon74d420b2014-05-07 14:38:47 -070062 mIncomingCallsManager = new IncomingCallsManager();
Santos Cordon682fe6b2014-05-20 08:56:39 -070063 mSelectorRepository = new CallServiceSelectorRepository();
Santos Cordon493e8f22014-02-19 03:15:12 -080064 mCallServiceRepository =
Santos Cordon682fe6b2014-05-20 08:56:39 -070065 new CallServiceRepository(mIncomingCallsManager);
Santos Cordon681663d2014-01-30 04:32:15 -080066 }
Ben Giladd17443c2014-01-06 11:04:15 -080067
Santos Cordon682fe6b2014-05-20 08:56:39 -070068 CallServiceRepository getCallServiceRepository() {
69 return mCallServiceRepository;
70 }
Ben Giladbb167cd2014-02-25 16:24:05 -080071
Santos Cordon682fe6b2014-05-20 08:56:39 -070072 CallServiceSelectorRepository getSelectorRepository() {
73 return mSelectorRepository;
Ben Gilad0407fb22014-01-09 16:18:41 -080074 }
Ben Gilad9f2bed32013-12-12 17:43:26 -080075
Ben Gilad0407fb22014-01-09 16:18:41 -080076 /**
Santos Cordon74d420b2014-05-07 14:38:47 -070077 * Retrieves details about the incoming call through the incoming call manager.
Santos Cordon80d9bdc2014-02-13 18:28:46 -080078 *
79 * @param call The call object.
Ben Giladc5b22692014-02-18 20:03:22 -080080 * @param descriptor The relevant call-service descriptor.
Evan Charltona05805b2014-03-05 08:21:46 -080081 * @param extras The optional extras passed via
Santos Cordon5b7b9b32014-03-26 14:00:22 -070082 * {@link TelecommConstants#EXTRA_INCOMING_CALL_EXTRAS}
Santos Cordon80d9bdc2014-02-13 18:28:46 -080083 */
Evan Charltona05805b2014-03-05 08:21:46 -080084 void retrieveIncomingCall(Call call, CallServiceDescriptor descriptor, Bundle extras) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080085 Log.d(this, "retrieveIncomingCall");
Santos Cordon74d420b2014-05-07 14:38:47 -070086 CallServiceWrapper callService = mCallServiceRepository.getService(descriptor);
Santos Cordon493e8f22014-02-19 03:15:12 -080087 call.setCallService(callService);
Evan Charltona05805b2014-03-05 08:21:46 -080088 mIncomingCallsManager.retrieveIncomingCall(call, extras);
Santos Cordon80d9bdc2014-02-13 18:28:46 -080089 }
Ben Gilad9f2bed32013-12-12 17:43:26 -080090}