Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.telecom.components; |
| 18 | |
Tyler Gunn | eaaf074 | 2016-09-15 15:36:38 -0700 | [diff] [blame] | 19 | import android.app.Notification; |
| 20 | import android.app.NotificationManager; |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 21 | import android.app.Service; |
| 22 | import android.bluetooth.BluetoothAdapter; |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 23 | import android.content.Context; |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 24 | import android.content.Intent; |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 25 | import android.media.IAudioService; |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 26 | import android.os.IBinder; |
Brad Ebinger | 63a89f2 | 2015-12-08 17:57:59 -0800 | [diff] [blame] | 27 | import android.os.PowerManager; |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 28 | import android.os.ServiceManager; |
Tyler Gunn | 4905666 | 2017-01-10 16:18:46 -0800 | [diff] [blame] | 29 | import android.service.notification.ZenModeConfig; |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 30 | |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 31 | import com.android.internal.telephony.CallerInfoAsyncQuery; |
Brad Ebinger | 7ade5e2 | 2016-04-05 18:43:50 -0700 | [diff] [blame] | 32 | import com.android.server.telecom.AsyncRingtonePlayer; |
Hall Liu | 7948f5b | 2016-03-15 17:39:28 -0700 | [diff] [blame] | 33 | import com.android.server.telecom.BluetoothAdapterProxy; |
Hall Liu | b3979ee | 2015-11-11 16:21:25 -0800 | [diff] [blame] | 34 | import com.android.server.telecom.BluetoothPhoneServiceImpl; |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 35 | import com.android.server.telecom.CallerInfoAsyncQueryFactory; |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 36 | import com.android.server.telecom.CallsManager; |
| 37 | import com.android.server.telecom.HeadsetMediaButton; |
| 38 | import com.android.server.telecom.HeadsetMediaButtonFactory; |
| 39 | import com.android.server.telecom.InCallWakeLockControllerFactory; |
Hall Liu | e091ab9 | 2015-12-18 17:05:30 -0800 | [diff] [blame] | 40 | import com.android.server.telecom.CallAudioManager; |
Tyler Gunn | eaaf074 | 2016-09-15 15:36:38 -0700 | [diff] [blame] | 41 | import com.android.server.telecom.InterruptionFilterProxy; |
Hall Liu | b3979ee | 2015-11-11 16:21:25 -0800 | [diff] [blame] | 42 | import com.android.server.telecom.PhoneAccountRegistrar; |
Brad Ebinger | 6ab66c3 | 2016-07-15 19:27:51 -0700 | [diff] [blame] | 43 | import com.android.server.telecom.PhoneNumberUtilsAdapter; |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 44 | import com.android.server.telecom.PhoneNumberUtilsAdapterImpl; |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 45 | import com.android.server.telecom.ProximitySensorManagerFactory; |
| 46 | import com.android.server.telecom.InCallWakeLockController; |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 47 | import com.android.server.telecom.Log; |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 48 | import com.android.server.telecom.ProximitySensorManager; |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 49 | import com.android.server.telecom.TelecomSystem; |
Brad Ebinger | 63a89f2 | 2015-12-08 17:57:59 -0800 | [diff] [blame] | 50 | import com.android.server.telecom.TelecomWakeLock; |
Hall Liu | 6d4b66d | 2016-04-01 16:31:13 -0700 | [diff] [blame] | 51 | import com.android.server.telecom.Timeouts; |
Anju Mathapati | bddd51b | 2015-10-10 02:28:16 -0700 | [diff] [blame] | 52 | import com.android.server.telecom.ViceNotifier; |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 53 | import com.android.server.telecom.ui.MissedCallNotifierImpl; |
Anju Mathapati | bddd51b | 2015-10-10 02:28:16 -0700 | [diff] [blame] | 54 | import com.android.server.telecom.ui.ViceNotificationImpl; |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Implementation of the ITelecom interface. |
| 58 | */ |
| 59 | public class TelecomService extends Service implements TelecomSystem.Component { |
| 60 | |
| 61 | @Override |
| 62 | public IBinder onBind(Intent intent) { |
| 63 | Log.d(this, "onBind"); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 64 | initializeTelecomSystem(this); |
| 65 | synchronized (getTelecomSystem().getLock()) { |
| 66 | return getTelecomSystem().getTelecomServiceImpl().getBinder(); |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 67 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 68 | } |
| 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 Gunn | eaaf074 | 2016-09-15 15:36:38 -0700 | [diff] [blame] | 82 | final NotificationManager notificationManager = |
| 83 | (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); |
| 84 | |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 85 | TelecomSystem.setInstance( |
| 86 | new TelecomSystem( |
| 87 | context, |
Tony Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 88 | new MissedCallNotifierImpl.MissedCallNotifierImplFactory() { |
| 89 | @Override |
| 90 | public MissedCallNotifierImpl makeMissedCallNotifierImpl( |
| 91 | Context context, |
Brad Ebinger | 6ab66c3 | 2016-07-15 19:27:51 -0700 | [diff] [blame] | 92 | PhoneAccountRegistrar phoneAccountRegistrar, |
| 93 | PhoneNumberUtilsAdapter phoneNumberUtilsAdapter) { |
Tony Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 94 | return new MissedCallNotifierImpl(context, |
Brad Ebinger | 6ab66c3 | 2016-07-15 19:27:51 -0700 | [diff] [blame] | 95 | phoneAccountRegistrar, phoneNumberUtilsAdapter); |
Tony Mak | a993094 | 2016-01-15 10:57:14 +0000 | [diff] [blame] | 96 | } |
| 97 | }, |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 98 | new CallerInfoAsyncQueryFactory() { |
| 99 | @Override |
| 100 | public CallerInfoAsyncQuery startQuery(int token, Context context, |
| 101 | String number, |
| 102 | CallerInfoAsyncQuery.OnQueryCompleteListener listener, |
| 103 | Object cookie) { |
Santos Cordon | 3188b36 | 2015-05-22 13:01:10 -0700 | [diff] [blame] | 104 | Log.i(TelecomSystem.getInstance(), |
| 105 | "CallerInfoAsyncQuery.startQuery number=%s cookie=%s", |
| 106 | Log.pii(number), cookie); |
Ihab Awad | abcbce4 | 2015-04-07 14:04:01 -0700 | [diff] [blame] | 107 | return CallerInfoAsyncQuery.startQuery( |
| 108 | token, context, number, listener, cookie); |
| 109 | } |
| 110 | }, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 111 | new HeadsetMediaButtonFactory() { |
| 112 | @Override |
Ihab Awad | 731369c | 2015-05-19 09:23:21 -0700 | [diff] [blame] | 113 | public HeadsetMediaButton create( |
| 114 | Context context, |
| 115 | CallsManager callsManager, |
| 116 | TelecomSystem.SyncRoot lock) { |
| 117 | return new HeadsetMediaButton(context, callsManager, lock); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 118 | } |
| 119 | }, |
| 120 | new ProximitySensorManagerFactory() { |
| 121 | @Override |
| 122 | public ProximitySensorManager create( |
| 123 | Context context, |
| 124 | CallsManager callsManager) { |
Brad Ebinger | 63a89f2 | 2015-12-08 17:57:59 -0800 | [diff] [blame] | 125 | return new ProximitySensorManager( |
| 126 | new TelecomWakeLock( |
| 127 | context, |
| 128 | PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, |
| 129 | ProximitySensorManager.class.getSimpleName()), |
| 130 | callsManager); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 131 | } |
| 132 | }, |
| 133 | new InCallWakeLockControllerFactory() { |
| 134 | @Override |
| 135 | public InCallWakeLockController create(Context context, |
| 136 | CallsManager callsManager) { |
Brad Ebinger | 63a89f2 | 2015-12-08 17:57:59 -0800 | [diff] [blame] | 137 | return new InCallWakeLockController( |
| 138 | new TelecomWakeLock(context, |
| 139 | PowerManager.FULL_WAKE_LOCK, |
| 140 | InCallWakeLockController.class.getSimpleName()), |
| 141 | callsManager); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 142 | } |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 143 | }, |
| 144 | new CallAudioManager.AudioServiceFactory() { |
| 145 | @Override |
| 146 | public IAudioService getAudioService() { |
| 147 | return IAudioService.Stub.asInterface( |
| 148 | ServiceManager.getService(Context.AUDIO_SERVICE)); |
| 149 | } |
Hall Liu | b3979ee | 2015-11-11 16:21:25 -0800 | [diff] [blame] | 150 | }, |
| 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 Liu | 7948f5b | 2016-03-15 17:39:28 -0700 | [diff] [blame] | 158 | callsManager, new BluetoothAdapterProxy(), |
| 159 | phoneAccountRegistrar); |
Hall Liu | b3979ee | 2015-11-11 16:21:25 -0800 | [diff] [blame] | 160 | } |
Brad Ebinger | 7ade5e2 | 2016-04-05 18:43:50 -0700 | [diff] [blame] | 161 | }, |
Hall Liu | 6d4b66d | 2016-04-01 16:31:13 -0700 | [diff] [blame] | 162 | new Timeouts.Adapter(), |
Anju Mathapati | bddd51b | 2015-10-10 02:28:16 -0700 | [diff] [blame] | 163 | 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 Kansara | 1d77ec9 | 2016-12-07 01:42:37 +0530 | [diff] [blame] | 171 | }, |
Tyler Gunn | eaaf074 | 2016-09-15 15:36:38 -0700 | [diff] [blame] | 172 | 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 Gunn | 4905666 | 2017-01-10 16:18:46 -0800 | [diff] [blame] | 183 | |
| 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 Gunn | eaaf074 | 2016-09-15 15:36:38 -0700 | [diff] [blame] | 192 | } |
Hall Liu | 8fb1fb7 | 2015-10-22 15:24:40 -0700 | [diff] [blame] | 193 | )); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 194 | } |
| 195 | if (BluetoothAdapter.getDefaultAdapter() != null) { |
| 196 | context.startService(new Intent(context, BluetoothPhoneService.class)); |
| 197 | } |
Ihab Awad | 78a5e6b | 2015-02-06 10:13:05 -0800 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public TelecomSystem getTelecomSystem() { |
| 202 | return TelecomSystem.getInstance(); |
| 203 | } |
| 204 | } |