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