blob: 2dfcfea108a25729244328f956fba37ff3d0200e [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;
Evan Charltona05805b2014-03-05 08:21:46 -080023import android.telecomm.TelecommConstants;
Santos Cordon8e8b8d22013-12-19 14:14:05 -080024
Santos Cordon5b7b9b32014-03-26 14:00:22 -070025import com.google.common.base.Preconditions;
26import com.google.common.collect.ImmutableCollection;
27import com.google.common.collect.ImmutableList;
28import com.google.common.collect.Sets;
29
30import java.util.Collection;
Ben Gilad0407fb22014-01-09 16:18:41 -080031import java.util.Set;
Ben Gilad9f2bed32013-12-12 17:43:26 -080032
Santos Cordon8e8b8d22013-12-19 14:14:05 -080033/**
Sailesh Nepalc92c4362014-07-04 18:33:21 -070034 * Switchboard is responsible for gathering the {@link ConnectionServiceWrapper}s through
Santos Cordon5b7b9b32014-03-26 14:00:22 -070035 * which to place outgoing calls
Santos Cordon8e8b8d22013-12-19 14:14:05 -080036 */
Ben Giladd17443c2014-01-06 11:04:15 -080037final class Switchboard {
Santos Cordon766d04f2014-05-06 10:28:25 -070038 private final static Switchboard sInstance = new Switchboard();
Ben Gilad2313e622014-02-06 12:02:25 -080039
Santos Cordon493e8f22014-02-19 03:15:12 -080040 /** Used to retrieve incoming call details. */
Santos Cordon80d9bdc2014-02-13 18:28:46 -080041 private final IncomingCallsManager mIncomingCallsManager;
42
Sailesh Nepal905dfba2014-07-14 08:20:41 -070043 private final ConnectionServiceRepository mConnectionServiceRepository;
Santos Cordon681663d2014-01-30 04:32:15 -080044
Santos Cordon766d04f2014-05-06 10:28:25 -070045 /** Singleton accessor. */
46 static Switchboard getInstance() {
47 return sInstance;
48 }
49
Santos Cordonc195e362014-02-11 17:05:31 -080050 /**
Santos Cordon681663d2014-01-30 04:32:15 -080051 * Persists the specified parameters and initializes Switchboard.
52 */
Santos Cordon766d04f2014-05-06 10:28:25 -070053 private Switchboard() {
Santos Cordonc499c1c2014-04-14 17:13:14 -070054 ThreadUtil.checkOnMainThread();
55
Santos Cordon74d420b2014-05-07 14:38:47 -070056 mIncomingCallsManager = new IncomingCallsManager();
Sailesh Nepal905dfba2014-07-14 08:20:41 -070057 mConnectionServiceRepository =
58 new ConnectionServiceRepository(mIncomingCallsManager);
Santos Cordon681663d2014-01-30 04:32:15 -080059 }
Ben Giladd17443c2014-01-06 11:04:15 -080060
Sailesh Nepal905dfba2014-07-14 08:20:41 -070061 ConnectionServiceRepository getConnectionServiceRepository() {
62 return mConnectionServiceRepository;
Santos Cordon682fe6b2014-05-20 08:56:39 -070063 }
Ben Giladbb167cd2014-02-25 16:24:05 -080064
Ben Gilad0407fb22014-01-09 16:18:41 -080065 /**
Santos Cordon74d420b2014-05-07 14:38:47 -070066 * Retrieves details about the incoming call through the incoming call manager.
Santos Cordon80d9bdc2014-02-13 18:28:46 -080067 *
68 * @param call The call object.
Santos Cordon80d9bdc2014-02-13 18:28:46 -080069 */
Sailesh Nepal905dfba2014-07-14 08:20:41 -070070 void retrieveIncomingCall(Call call) {
Sailesh Nepalf1c191d2014-03-07 18:17:39 -080071 Log.d(this, "retrieveIncomingCall");
Sailesh Nepal905dfba2014-07-14 08:20:41 -070072 ConnectionServiceWrapper service = mConnectionServiceRepository.getService(
73 call.getPhoneAccount().getComponentName());
Sailesh Nepalc92c4362014-07-04 18:33:21 -070074 call.setConnectionService(service);
Sailesh Nepal905dfba2014-07-14 08:20:41 -070075 mIncomingCallsManager.retrieveIncomingCall(call);
Santos Cordon80d9bdc2014-02-13 18:28:46 -080076 }
Ben Gilad9f2bed32013-12-12 17:43:26 -080077}