blob: a1c70fab276acf005ac02e0eb7f65382ec160899 [file] [log] [blame]
Ihab Awad78a5e6b2015-02-06 10:13:05 -08001/*
2 * Copyright (C) 2014 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
17package com.android.server.telecom.components;
18
19import android.app.Service;
20import android.bluetooth.BluetoothAdapter;
Ihab Awad8de76912015-02-17 12:25:52 -080021import android.content.Context;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080022import android.content.Intent;
Hall Liu8fb1fb72015-10-22 15:24:40 -070023import android.media.IAudioService;
Brad Ebinger7bba1112017-06-08 13:57:28 -070024import android.media.ToneGenerator;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080025import android.os.IBinder;
Pengquan Meng606ff7f2017-12-20 16:13:04 -080026import android.os.Looper;
Brad Ebinger63a89f22015-12-08 17:57:59 -080027import android.os.PowerManager;
Hall Liu8fb1fb72015-10-22 15:24:40 -070028import android.os.ServiceManager;
Tyler Gunn6c3a2dd2017-08-04 09:28:59 -070029import android.os.SystemClock;
Brad Ebinger953e1af2016-10-05 15:45:22 -070030import android.telecom.Log;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080031
Ihab Awadabcbce42015-04-07 14:04:01 -070032import com.android.internal.telephony.CallerInfoAsyncQuery;
Brad Ebinger7ade5e22016-04-05 18:43:50 -070033import com.android.server.telecom.AsyncRingtonePlayer;
Hall Liu7948f5b2016-03-15 17:39:28 -070034import com.android.server.telecom.BluetoothAdapterProxy;
Hall Liub3979ee2015-11-11 16:21:25 -080035import com.android.server.telecom.BluetoothPhoneServiceImpl;
Ihab Awadabcbce42015-04-07 14:04:01 -070036import com.android.server.telecom.CallerInfoAsyncQueryFactory;
Ihab Awad8de76912015-02-17 12:25:52 -080037import com.android.server.telecom.CallsManager;
Tyler Gunn6c3a2dd2017-08-04 09:28:59 -070038import com.android.server.telecom.ClockProxy;
Pengquan Meng606ff7f2017-12-20 16:13:04 -080039import com.android.server.telecom.ConnectionServiceFocusManager;
Hall Liu2b33df72016-12-06 18:15:39 -080040import com.android.server.telecom.DefaultDialerCache;
Ihab Awad8de76912015-02-17 12:25:52 -080041import com.android.server.telecom.HeadsetMediaButton;
42import com.android.server.telecom.HeadsetMediaButtonFactory;
Brad Ebinger7bba1112017-06-08 13:57:28 -070043import com.android.server.telecom.InCallTonePlayer;
Ihab Awad8de76912015-02-17 12:25:52 -080044import com.android.server.telecom.InCallWakeLockControllerFactory;
Hall Liue091ab92015-12-18 17:05:30 -080045import com.android.server.telecom.CallAudioManager;
Hall Liub3979ee2015-11-11 16:21:25 -080046import com.android.server.telecom.PhoneAccountRegistrar;
Brad Ebinger6e8f3d72016-06-20 11:35:42 -070047import com.android.server.telecom.PhoneNumberUtilsAdapterImpl;
Ihab Awad8de76912015-02-17 12:25:52 -080048import com.android.server.telecom.ProximitySensorManagerFactory;
49import com.android.server.telecom.InCallWakeLockController;
Ihab Awad8de76912015-02-17 12:25:52 -080050import com.android.server.telecom.ProximitySensorManager;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080051import com.android.server.telecom.TelecomSystem;
Brad Ebinger63a89f22015-12-08 17:57:59 -080052import com.android.server.telecom.TelecomWakeLock;
Hall Liu6d4b66d2016-04-01 16:31:13 -070053import com.android.server.telecom.Timeouts;
Tyler Gunn2b17f232017-03-08 08:51:00 -080054import com.android.server.telecom.ui.IncomingCallNotifier;
Ihab Awad8de76912015-02-17 12:25:52 -080055import com.android.server.telecom.ui.MissedCallNotifierImpl;
Tyler Gunndce902a2017-04-04 13:45:32 -070056import com.android.server.telecom.ui.NotificationChannelManager;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080057
58/**
59 * Implementation of the ITelecom interface.
60 */
61public class TelecomService extends Service implements TelecomSystem.Component {
62
63 @Override
64 public IBinder onBind(Intent intent) {
65 Log.d(this, "onBind");
Ihab Awad8d5d9dd2015-03-12 11:11:06 -070066 initializeTelecomSystem(this);
67 synchronized (getTelecomSystem().getLock()) {
68 return getTelecomSystem().getTelecomServiceImpl().getBinder();
Ihab Awad78a5e6b2015-02-06 10:13:05 -080069 }
Ihab Awad8d5d9dd2015-03-12 11:11:06 -070070 }
71
72 /**
73 * This method is to be called by components (Activitys, Services, ...) to initialize the
74 * Telecom singleton. It should only be called on the main thread. As such, it is atomic
75 * and needs no synchronization -- it will either perform its initialization, after which
76 * the {@link TelecomSystem#getInstance()} will be initialized, or some other invocation of
77 * this method on the main thread will have happened strictly prior to it, and this method
78 * will be a benign no-op.
79 *
80 * @param context
81 */
82 static void initializeTelecomSystem(Context context) {
83 if (TelecomSystem.getInstance() == null) {
Tyler Gunndce902a2017-04-04 13:45:32 -070084 NotificationChannelManager notificationChannelManager =
85 new NotificationChannelManager();
86 notificationChannelManager.createChannels(context);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -070087 TelecomSystem.setInstance(
88 new TelecomSystem(
89 context,
Tony Maka9930942016-01-15 10:57:14 +000090 new MissedCallNotifierImpl.MissedCallNotifierImplFactory() {
91 @Override
92 public MissedCallNotifierImpl makeMissedCallNotifierImpl(
93 Context context,
Hall Liu2b33df72016-12-06 18:15:39 -080094 PhoneAccountRegistrar phoneAccountRegistrar,
95 DefaultDialerCache defaultDialerCache) {
Tony Maka9930942016-01-15 10:57:14 +000096 return new MissedCallNotifierImpl(context,
Hall Liu2b33df72016-12-06 18:15:39 -080097 phoneAccountRegistrar, defaultDialerCache);
Tony Maka9930942016-01-15 10:57:14 +000098 }
99 },
Ihab Awadabcbce42015-04-07 14:04:01 -0700100 new CallerInfoAsyncQueryFactory() {
101 @Override
Pengquan Meng606ff7f2017-12-20 16:13:04 -0800102 public CallerInfoAsyncQuery startQuery(
103 int token,
104 Context context,
Ihab Awadabcbce42015-04-07 14:04:01 -0700105 String number,
106 CallerInfoAsyncQuery.OnQueryCompleteListener listener,
107 Object cookie) {
Santos Cordon3188b362015-05-22 13:01:10 -0700108 Log.i(TelecomSystem.getInstance(),
109 "CallerInfoAsyncQuery.startQuery number=%s cookie=%s",
110 Log.pii(number), cookie);
Ihab Awadabcbce42015-04-07 14:04:01 -0700111 return CallerInfoAsyncQuery.startQuery(
112 token, context, number, listener, cookie);
113 }
114 },
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700115 new HeadsetMediaButtonFactory() {
116 @Override
Ihab Awad731369c2015-05-19 09:23:21 -0700117 public HeadsetMediaButton create(
118 Context context,
119 CallsManager callsManager,
120 TelecomSystem.SyncRoot lock) {
121 return new HeadsetMediaButton(context, callsManager, lock);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700122 }
123 },
124 new ProximitySensorManagerFactory() {
125 @Override
126 public ProximitySensorManager create(
127 Context context,
128 CallsManager callsManager) {
Brad Ebinger63a89f22015-12-08 17:57:59 -0800129 return new ProximitySensorManager(
130 new TelecomWakeLock(
131 context,
132 PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
133 ProximitySensorManager.class.getSimpleName()),
134 callsManager);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700135 }
136 },
137 new InCallWakeLockControllerFactory() {
138 @Override
139 public InCallWakeLockController create(Context context,
Pengquan Meng606ff7f2017-12-20 16:13:04 -0800140 CallsManager callsManager) {
Brad Ebinger63a89f22015-12-08 17:57:59 -0800141 return new InCallWakeLockController(
142 new TelecomWakeLock(context,
143 PowerManager.FULL_WAKE_LOCK,
144 InCallWakeLockController.class.getSimpleName()),
145 callsManager);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700146 }
Hall Liu8fb1fb72015-10-22 15:24:40 -0700147 },
148 new CallAudioManager.AudioServiceFactory() {
149 @Override
150 public IAudioService getAudioService() {
151 return IAudioService.Stub.asInterface(
152 ServiceManager.getService(Context.AUDIO_SERVICE));
153 }
Hall Liub3979ee2015-11-11 16:21:25 -0800154 },
155 new BluetoothPhoneServiceImpl.BluetoothPhoneServiceImplFactory() {
156 @Override
157 public BluetoothPhoneServiceImpl makeBluetoothPhoneServiceImpl(
158 Context context, TelecomSystem.SyncRoot lock,
159 CallsManager callsManager,
160 PhoneAccountRegistrar phoneAccountRegistrar) {
161 return new BluetoothPhoneServiceImpl(context, lock,
Hall Liu7948f5b2016-03-15 17:39:28 -0700162 callsManager, new BluetoothAdapterProxy(),
163 phoneAccountRegistrar);
Hall Liub3979ee2015-11-11 16:21:25 -0800164 }
Brad Ebinger7ade5e22016-04-05 18:43:50 -0700165 },
Pengquan Meng606ff7f2017-12-20 16:13:04 -0800166 new ConnectionServiceFocusManager
167 .ConnectionServiceFocusManagerFactory() {
168 @Override
169 public ConnectionServiceFocusManager create(
170 ConnectionServiceFocusManager.CallsManagerRequester requester,
171 Looper looper) {
172 return new ConnectionServiceFocusManager(requester, looper);
173 }
174 },
Hall Liu6d4b66d2016-04-01 16:31:13 -0700175 new Timeouts.Adapter(),
Brad Ebinger6e8f3d72016-06-20 11:35:42 -0700176 new AsyncRingtonePlayer(),
Tyler Gunneaaf0742016-09-15 15:36:38 -0700177 new PhoneNumberUtilsAdapterImpl(),
Brad Ebinger7bba1112017-06-08 13:57:28 -0700178 new IncomingCallNotifier(context),
Tyler Gunn6c3a2dd2017-08-04 09:28:59 -0700179 ToneGenerator::new,
180 new ClockProxy() {
181 @Override
182 public long currentTimeMillis() {
183 return System.currentTimeMillis();
184 }
185
186 @Override
187 public long elapsedRealtime() {
188 return SystemClock.elapsedRealtime();
189 }
190 }));
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700191 }
192 if (BluetoothAdapter.getDefaultAdapter() != null) {
193 context.startService(new Intent(context, BluetoothPhoneService.class));
194 }
Ihab Awad78a5e6b2015-02-06 10:13:05 -0800195 }
196
197 @Override
198 public TelecomSystem getTelecomSystem() {
199 return TelecomSystem.getInstance();
200 }
201}