blob: f6080f84bbc36b1ae163a221d3c7c78671e501a0 [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
Tyler Gunneaaf0742016-09-15 15:36:38 -070019import android.app.Notification;
20import android.app.NotificationManager;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080021import android.app.Service;
22import android.bluetooth.BluetoothAdapter;
Ihab Awad8de76912015-02-17 12:25:52 -080023import android.content.Context;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080024import android.content.Intent;
Hall Liu8fb1fb72015-10-22 15:24:40 -070025import android.media.IAudioService;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080026import android.os.IBinder;
Brad Ebinger63a89f22015-12-08 17:57:59 -080027import android.os.PowerManager;
Hall Liu8fb1fb72015-10-22 15:24:40 -070028import android.os.ServiceManager;
Tyler Gunn49056662017-01-10 16:18:46 -080029import android.service.notification.ZenModeConfig;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080030
Ihab Awadabcbce42015-04-07 14:04:01 -070031import com.android.internal.telephony.CallerInfoAsyncQuery;
Brad Ebinger7ade5e22016-04-05 18:43:50 -070032import com.android.server.telecom.AsyncRingtonePlayer;
Hall Liu7948f5b2016-03-15 17:39:28 -070033import com.android.server.telecom.BluetoothAdapterProxy;
Hall Liub3979ee2015-11-11 16:21:25 -080034import com.android.server.telecom.BluetoothPhoneServiceImpl;
Ihab Awadabcbce42015-04-07 14:04:01 -070035import com.android.server.telecom.CallerInfoAsyncQueryFactory;
Ihab Awad8de76912015-02-17 12:25:52 -080036import com.android.server.telecom.CallsManager;
37import com.android.server.telecom.HeadsetMediaButton;
38import com.android.server.telecom.HeadsetMediaButtonFactory;
39import com.android.server.telecom.InCallWakeLockControllerFactory;
Hall Liue091ab92015-12-18 17:05:30 -080040import com.android.server.telecom.CallAudioManager;
Tyler Gunneaaf0742016-09-15 15:36:38 -070041import com.android.server.telecom.InterruptionFilterProxy;
Hall Liub3979ee2015-11-11 16:21:25 -080042import com.android.server.telecom.PhoneAccountRegistrar;
Brad Ebinger6ab66c32016-07-15 19:27:51 -070043import com.android.server.telecom.PhoneNumberUtilsAdapter;
Brad Ebinger6e8f3d72016-06-20 11:35:42 -070044import com.android.server.telecom.PhoneNumberUtilsAdapterImpl;
Ihab Awad8de76912015-02-17 12:25:52 -080045import com.android.server.telecom.ProximitySensorManagerFactory;
46import com.android.server.telecom.InCallWakeLockController;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080047import com.android.server.telecom.Log;
Ihab Awad8de76912015-02-17 12:25:52 -080048import com.android.server.telecom.ProximitySensorManager;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080049import com.android.server.telecom.TelecomSystem;
Brad Ebinger63a89f22015-12-08 17:57:59 -080050import com.android.server.telecom.TelecomWakeLock;
Hall Liu6d4b66d2016-04-01 16:31:13 -070051import com.android.server.telecom.Timeouts;
Anju Mathapatibddd51b2015-10-10 02:28:16 -070052import com.android.server.telecom.ViceNotifier;
Ihab Awad8de76912015-02-17 12:25:52 -080053import com.android.server.telecom.ui.MissedCallNotifierImpl;
Anju Mathapatibddd51b2015-10-10 02:28:16 -070054import com.android.server.telecom.ui.ViceNotificationImpl;
Ihab Awad78a5e6b2015-02-06 10:13:05 -080055
56/**
57 * Implementation of the ITelecom interface.
58 */
59public class TelecomService extends Service implements TelecomSystem.Component {
60
61 @Override
62 public IBinder onBind(Intent intent) {
63 Log.d(this, "onBind");
Ihab Awad8d5d9dd2015-03-12 11:11:06 -070064 initializeTelecomSystem(this);
65 synchronized (getTelecomSystem().getLock()) {
66 return getTelecomSystem().getTelecomServiceImpl().getBinder();
Ihab Awad78a5e6b2015-02-06 10:13:05 -080067 }
Ihab Awad8d5d9dd2015-03-12 11:11:06 -070068 }
69
70 /**
71 * This method is to be called by components (Activitys, Services, ...) to initialize the
72 * Telecom singleton. It should only be called on the main thread. As such, it is atomic
73 * and needs no synchronization -- it will either perform its initialization, after which
74 * the {@link TelecomSystem#getInstance()} will be initialized, or some other invocation of
75 * this method on the main thread will have happened strictly prior to it, and this method
76 * will be a benign no-op.
77 *
78 * @param context
79 */
80 static void initializeTelecomSystem(Context context) {
81 if (TelecomSystem.getInstance() == null) {
Tyler Gunneaaf0742016-09-15 15:36:38 -070082 final NotificationManager notificationManager =
83 (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
84
Ihab Awad8d5d9dd2015-03-12 11:11:06 -070085 TelecomSystem.setInstance(
86 new TelecomSystem(
87 context,
Tony Maka9930942016-01-15 10:57:14 +000088 new MissedCallNotifierImpl.MissedCallNotifierImplFactory() {
89 @Override
90 public MissedCallNotifierImpl makeMissedCallNotifierImpl(
91 Context context,
Brad Ebinger6ab66c32016-07-15 19:27:51 -070092 PhoneAccountRegistrar phoneAccountRegistrar,
93 PhoneNumberUtilsAdapter phoneNumberUtilsAdapter) {
Tony Maka9930942016-01-15 10:57:14 +000094 return new MissedCallNotifierImpl(context,
Brad Ebinger6ab66c32016-07-15 19:27:51 -070095 phoneAccountRegistrar, phoneNumberUtilsAdapter);
Tony Maka9930942016-01-15 10:57:14 +000096 }
97 },
Ihab Awadabcbce42015-04-07 14:04:01 -070098 new CallerInfoAsyncQueryFactory() {
99 @Override
100 public CallerInfoAsyncQuery startQuery(int token, Context context,
101 String number,
102 CallerInfoAsyncQuery.OnQueryCompleteListener listener,
103 Object cookie) {
Santos Cordon3188b362015-05-22 13:01:10 -0700104 Log.i(TelecomSystem.getInstance(),
105 "CallerInfoAsyncQuery.startQuery number=%s cookie=%s",
106 Log.pii(number), cookie);
Ihab Awadabcbce42015-04-07 14:04:01 -0700107 return CallerInfoAsyncQuery.startQuery(
108 token, context, number, listener, cookie);
109 }
110 },
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700111 new HeadsetMediaButtonFactory() {
112 @Override
Ihab Awad731369c2015-05-19 09:23:21 -0700113 public HeadsetMediaButton create(
114 Context context,
115 CallsManager callsManager,
116 TelecomSystem.SyncRoot lock) {
117 return new HeadsetMediaButton(context, callsManager, lock);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700118 }
119 },
120 new ProximitySensorManagerFactory() {
121 @Override
122 public ProximitySensorManager create(
123 Context context,
124 CallsManager callsManager) {
Brad Ebinger63a89f22015-12-08 17:57:59 -0800125 return new ProximitySensorManager(
126 new TelecomWakeLock(
127 context,
128 PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
129 ProximitySensorManager.class.getSimpleName()),
130 callsManager);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700131 }
132 },
133 new InCallWakeLockControllerFactory() {
134 @Override
135 public InCallWakeLockController create(Context context,
136 CallsManager callsManager) {
Brad Ebinger63a89f22015-12-08 17:57:59 -0800137 return new InCallWakeLockController(
138 new TelecomWakeLock(context,
139 PowerManager.FULL_WAKE_LOCK,
140 InCallWakeLockController.class.getSimpleName()),
141 callsManager);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700142 }
Hall Liu8fb1fb72015-10-22 15:24:40 -0700143 },
144 new CallAudioManager.AudioServiceFactory() {
145 @Override
146 public IAudioService getAudioService() {
147 return IAudioService.Stub.asInterface(
148 ServiceManager.getService(Context.AUDIO_SERVICE));
149 }
Hall Liub3979ee2015-11-11 16:21:25 -0800150 },
151 new BluetoothPhoneServiceImpl.BluetoothPhoneServiceImplFactory() {
152 @Override
153 public BluetoothPhoneServiceImpl makeBluetoothPhoneServiceImpl(
154 Context context, TelecomSystem.SyncRoot lock,
155 CallsManager callsManager,
156 PhoneAccountRegistrar phoneAccountRegistrar) {
157 return new BluetoothPhoneServiceImpl(context, lock,
Hall Liu7948f5b2016-03-15 17:39:28 -0700158 callsManager, new BluetoothAdapterProxy(),
159 phoneAccountRegistrar);
Hall Liub3979ee2015-11-11 16:21:25 -0800160 }
Brad Ebinger7ade5e22016-04-05 18:43:50 -0700161 },
Hall Liu6d4b66d2016-04-01 16:31:13 -0700162 new Timeouts.Adapter(),
Anju Mathapatibddd51b2015-10-10 02:28:16 -0700163 new AsyncRingtonePlayer(),
164 new ViceNotifier() {
165 @Override
166 public ViceNotificationImpl create(Context context,
167 CallsManager callsManager) {
168 return new ViceNotificationImpl(
169 context.getApplicationContext(), callsManager);
170 }
Lalit Kansara1d77ec92016-12-07 01:42:37 +0530171 },
Tyler Gunneaaf0742016-09-15 15:36:38 -0700172 new PhoneNumberUtilsAdapterImpl(),
173 new InterruptionFilterProxy() {
174 @Override
175 public void setInterruptionFilter(int interruptionFilter) {
176 notificationManager.setInterruptionFilter(interruptionFilter);
177 }
178
179 @Override
180 public int getCurrentInterruptionFilter() {
181 return notificationManager.getCurrentInterruptionFilter();
182 }
Tyler Gunn49056662017-01-10 16:18:46 -0800183
184 @Override
185 public String getInterruptionModeInitiator() {
186 ZenModeConfig config = notificationManager.getZenModeConfig();
187 if (config.manualRule != null) {
188 return config.manualRule.enabler;
189 }
190 return null;
191 }
Tyler Gunneaaf0742016-09-15 15:36:38 -0700192 }
Hall Liu8fb1fb72015-10-22 15:24:40 -0700193 ));
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700194 }
195 if (BluetoothAdapter.getDefaultAdapter() != null) {
196 context.startService(new Intent(context, BluetoothPhoneService.class));
197 }
Ihab Awad78a5e6b2015-02-06 10:13:05 -0800198 }
199
200 @Override
201 public TelecomSystem getTelecomSystem() {
202 return TelecomSystem.getInstance();
203 }
204}