Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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.systemui; |
| 18 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 19 | import static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 20 | import static com.android.systemui.Dependency.LEAK_REPORT_EMAIL_NAME; |
| 21 | |
| 22 | import android.annotation.Nullable; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 23 | import android.app.AlarmManager; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Lucas Dupin | 787f9a0 | 2019-04-24 14:56:52 -0700 | [diff] [blame] | 25 | import android.os.Handler; |
| 26 | import android.os.Looper; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 27 | import android.util.Log; |
| 28 | import android.view.ViewGroup; |
| 29 | |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 30 | import com.android.internal.colorextraction.ColorExtractor.GradientColors; |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 31 | import com.android.internal.util.function.TriConsumer; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 32 | import com.android.internal.widget.LockPatternUtils; |
Lucas Dupin | 787f9a0 | 2019-04-24 14:56:52 -0700 | [diff] [blame] | 33 | import com.android.keyguard.KeyguardUpdateMonitor; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 34 | import com.android.keyguard.ViewMediatorCallback; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 35 | import com.android.systemui.assist.AssistManager; |
Lucas Dupin | 0df9b7a | 2018-03-15 17:53:17 -0700 | [diff] [blame] | 36 | import com.android.systemui.classifier.FalsingManager; |
Lucas Dupin | d722135 | 2019-04-29 19:43:11 -0700 | [diff] [blame^] | 37 | import com.android.systemui.dock.DockManager; |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 38 | import com.android.systemui.fragments.FragmentService; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 39 | import com.android.systemui.keyguard.DismissCallbackRegistry; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 40 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 41 | import com.android.systemui.power.EnhancedEstimates; |
| 42 | import com.android.systemui.power.EnhancedEstimatesImpl; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 43 | import com.android.systemui.statusbar.KeyguardIndicationController; |
Eliot Courtney | 3985ad5 | 2017-11-17 16:51:52 +0900 | [diff] [blame] | 44 | import com.android.systemui.statusbar.NotificationListener; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 45 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 46 | import com.android.systemui.statusbar.NotificationLockscreenUserManagerImpl; |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 47 | import com.android.systemui.statusbar.NotificationMediaManager; |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 48 | import com.android.systemui.statusbar.ScrimView; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 49 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 50 | import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 51 | import com.android.systemui.statusbar.notification.collection.NotificationData; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 52 | import com.android.systemui.statusbar.phone.DozeParameters; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 53 | import com.android.systemui.statusbar.phone.KeyguardBouncer; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 54 | import com.android.systemui.statusbar.phone.KeyguardEnvironmentImpl; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 55 | import com.android.systemui.statusbar.phone.LockIcon; |
Jorim Jaggi | e31f6b8 | 2016-07-01 16:15:09 -0700 | [diff] [blame] | 56 | import com.android.systemui.statusbar.phone.LockscreenWallpaper; |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 57 | import com.android.systemui.statusbar.phone.NotificationIconAreaController; |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 58 | import com.android.systemui.statusbar.phone.ScrimController; |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 59 | import com.android.systemui.statusbar.phone.ScrimState; |
Ben Lin | 90cd611 | 2019-01-03 18:16:21 -0800 | [diff] [blame] | 60 | import com.android.systemui.statusbar.phone.ShadeController; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 61 | import com.android.systemui.statusbar.phone.StatusBar; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 62 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 63 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 64 | import com.android.systemui.util.InjectionInflationController; |
Jason Monk | 00413ce | 2018-12-21 11:22:30 -0500 | [diff] [blame] | 65 | import com.android.systemui.util.leak.GarbageMonitor; |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 66 | import com.android.systemui.volume.VolumeDialogComponent; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 67 | |
Adrian Roos | a5c6322 | 2017-07-27 16:33:39 +0200 | [diff] [blame] | 68 | import java.util.function.Consumer; |
| 69 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 70 | import javax.inject.Named; |
| 71 | import javax.inject.Singleton; |
| 72 | |
| 73 | import dagger.Component; |
| 74 | import dagger.Module; |
| 75 | import dagger.Provides; |
| 76 | |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 77 | /** |
| 78 | * Class factory to provide customizable SystemUI components. |
| 79 | */ |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 80 | @Module |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 81 | public class SystemUIFactory { |
| 82 | private static final String TAG = "SystemUIFactory"; |
| 83 | |
| 84 | static SystemUIFactory mFactory; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 85 | private SystemUIRootComponent mRootComponent; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 86 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 87 | public static <T extends SystemUIFactory> T getInstance() { |
| 88 | return (T) mFactory; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | public static void createFromConfig(Context context) { |
| 92 | final String clsName = context.getString(R.string.config_systemUIFactoryComponent); |
| 93 | if (clsName == null || clsName.length() == 0) { |
| 94 | throw new RuntimeException("No SystemUIFactory component configured"); |
| 95 | } |
| 96 | |
| 97 | try { |
| 98 | Class<?> cls = null; |
| 99 | cls = context.getClassLoader().loadClass(clsName); |
| 100 | mFactory = (SystemUIFactory) cls.newInstance(); |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 101 | mFactory.init(context); |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 102 | } catch (Throwable t) { |
| 103 | Log.w(TAG, "Error creating SystemUIFactory component: " + clsName, t); |
| 104 | throw new RuntimeException(t); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | public SystemUIFactory() {} |
| 109 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 110 | protected void init(Context context) { |
| 111 | mRootComponent = DaggerSystemUIFactory_SystemUIRootComponent.builder() |
| 112 | .systemUIFactory(this) |
| 113 | .dependencyProvider(new com.android.systemui.DependencyProvider()) |
| 114 | .contextHolder(new ContextHolder(context)) |
| 115 | .build(); |
| 116 | } |
| 117 | |
| 118 | public SystemUIRootComponent getRootComponent() { |
| 119 | return mRootComponent; |
| 120 | } |
| 121 | |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 122 | public StatusBarKeyguardViewManager createStatusBarKeyguardViewManager(Context context, |
| 123 | ViewMediatorCallback viewMediatorCallback, LockPatternUtils lockPatternUtils) { |
| 124 | return new StatusBarKeyguardViewManager(context, viewMediatorCallback, lockPatternUtils); |
| 125 | } |
| 126 | |
| 127 | public KeyguardBouncer createKeyguardBouncer(Context context, ViewMediatorCallback callback, |
Lucas Dupin | 15a6b6c | 2018-04-16 14:50:20 +0800 | [diff] [blame] | 128 | LockPatternUtils lockPatternUtils, ViewGroup container, |
| 129 | DismissCallbackRegistry dismissCallbackRegistry, |
| 130 | KeyguardBouncer.BouncerExpansionCallback expansionCallback) { |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 131 | return new KeyguardBouncer(context, callback, lockPatternUtils, container, |
Lucas Dupin | 787f9a0 | 2019-04-24 14:56:52 -0700 | [diff] [blame] | 132 | dismissCallbackRegistry, FalsingManager.getInstance(context), expansionCallback, |
| 133 | KeyguardUpdateMonitor.getInstance(context), new Handler(Looper.getMainLooper())); |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 134 | } |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 135 | |
shawnlin | 317db37 | 2018-04-09 19:49:48 +0800 | [diff] [blame] | 136 | public ScrimController createScrimController(ScrimView scrimBehind, ScrimView scrimInFront, |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 137 | LockscreenWallpaper lockscreenWallpaper, |
| 138 | TriConsumer<ScrimState, Float, GradientColors> scrimStateListener, |
Selim Cinek | 99e9adf | 2018-03-15 09:17:47 -0700 | [diff] [blame] | 139 | Consumer<Integer> scrimVisibleListener, DozeParameters dozeParameters, |
| 140 | AlarmManager alarmManager) { |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 141 | return new ScrimController(scrimBehind, scrimInFront, scrimStateListener, |
| 142 | scrimVisibleListener, dozeParameters, alarmManager); |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 143 | } |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 144 | |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 145 | public NotificationIconAreaController createNotificationIconAreaController(Context context, |
Julia Reynolds | 12ad7ca | 2019-01-28 09:29:16 -0500 | [diff] [blame] | 146 | StatusBar statusBar, StatusBarStateController statusBarStateController, |
| 147 | NotificationListener listener) { |
| 148 | return new NotificationIconAreaController(context, statusBar, statusBarStateController, |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 149 | listener, Dependency.get(NotificationMediaManager.class)); |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 152 | public KeyguardIndicationController createKeyguardIndicationController(Context context, |
| 153 | ViewGroup indicationArea, LockIcon lockIcon) { |
| 154 | return new KeyguardIndicationController(context, indicationArea, lockIcon); |
| 155 | } |
| 156 | |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 157 | public VolumeDialogComponent createVolumeDialogComponent(SystemUI systemUi, Context context) { |
| 158 | return new VolumeDialogComponent(systemUi, context); |
| 159 | } |
| 160 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 161 | @Singleton |
| 162 | @Provides |
| 163 | public NotificationData.KeyguardEnvironment provideKeyguardEnvironment(Context context) { |
| 164 | return new KeyguardEnvironmentImpl(); |
| 165 | } |
| 166 | |
| 167 | @Singleton |
| 168 | @Provides |
| 169 | public NotificationLockscreenUserManager provideNotificationLockscreenUserManager( |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 170 | Context context) { |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 171 | return new NotificationLockscreenUserManagerImpl(context); |
| 172 | } |
| 173 | |
| 174 | @Singleton |
| 175 | @Provides |
| 176 | public AssistManager provideAssistManager(DeviceProvisionedController controller, |
| 177 | Context context) { |
| 178 | return new AssistManager(controller, context); |
| 179 | } |
| 180 | |
| 181 | @Singleton |
| 182 | @Provides |
Lucas Dupin | d722135 | 2019-04-29 19:43:11 -0700 | [diff] [blame^] | 183 | @Nullable |
| 184 | public DockManager provideDockManager(Context context) { |
| 185 | return null; |
| 186 | } |
| 187 | |
| 188 | @Singleton |
| 189 | @Provides |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 190 | public NotificationEntryManager provideNotificationEntryManager(Context context) { |
| 191 | return new NotificationEntryManager(context); |
| 192 | } |
| 193 | |
| 194 | @Singleton |
| 195 | @Provides |
| 196 | public EnhancedEstimates provideEnhancedEstimates(Context context) { |
| 197 | return new EnhancedEstimatesImpl(); |
| 198 | } |
| 199 | |
| 200 | @Singleton |
| 201 | @Provides |
| 202 | @Named(LEAK_REPORT_EMAIL_NAME) |
| 203 | @Nullable |
| 204 | public String provideLeakReportEmail() { |
| 205 | return null; |
| 206 | } |
| 207 | |
| 208 | @Singleton |
| 209 | @Provides |
| 210 | public NotificationListener provideNotificationListener(Context context) { |
| 211 | return new NotificationListener(context); |
| 212 | } |
| 213 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 214 | @Singleton |
| 215 | @Provides |
| 216 | public NotificationInterruptionStateProvider provideNotificationInterruptionStateProvider( |
| 217 | Context context) { |
| 218 | return new NotificationInterruptionStateProvider(context); |
| 219 | } |
| 220 | |
Gus Prevas | 59ec2ff | 2018-12-28 16:20:28 -0500 | [diff] [blame] | 221 | @Singleton |
| 222 | @Provides |
| 223 | @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) |
| 224 | public boolean provideAllowNotificationLongPress() { |
| 225 | return true; |
| 226 | } |
| 227 | |
Ben Lin | 90cd611 | 2019-01-03 18:16:21 -0800 | [diff] [blame] | 228 | @Singleton |
| 229 | @Provides |
| 230 | public ShadeController provideShadeController(Context context) { |
| 231 | return SysUiServiceProvider.getComponent(context, StatusBar.class); |
| 232 | } |
| 233 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 234 | @Module |
| 235 | protected static class ContextHolder { |
| 236 | private Context mContext; |
| 237 | |
| 238 | public ContextHolder(Context context) { |
| 239 | mContext = context; |
| 240 | } |
| 241 | |
| 242 | @Provides |
| 243 | public Context provideContext() { |
| 244 | return mContext; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | @Singleton |
Jason Monk | 196d639 | 2018-12-20 13:25:34 -0500 | [diff] [blame] | 249 | @Component(modules = {SystemUIFactory.class, DependencyProvider.class, DependencyBinder.class, |
| 250 | ContextHolder.class}) |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 251 | public interface SystemUIRootComponent { |
| 252 | @Singleton |
| 253 | Dependency.DependencyInjector createDependency(); |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 254 | |
Selim Cinek | 9d20bed | 2018-12-26 16:02:34 -0800 | [diff] [blame] | 255 | @Singleton |
| 256 | StatusBar.StatusBarInjector getStatusBarInjector(); |
| 257 | |
Jason Monk | 9424af7 | 2018-12-19 14:17:26 -0500 | [diff] [blame] | 258 | /** |
| 259 | * FragmentCreator generates all Fragments that need injection. |
| 260 | */ |
| 261 | @Singleton |
| 262 | FragmentService.FragmentCreator createFragmentCreator(); |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 263 | |
| 264 | /** |
| 265 | * ViewCreator generates all Views that need injection. |
| 266 | */ |
| 267 | InjectionInflationController.ViewCreator createViewCreator(); |
Jason Monk | 00413ce | 2018-12-21 11:22:30 -0500 | [diff] [blame] | 268 | |
| 269 | @Singleton |
| 270 | GarbageMonitor createGarbageMonitor(); |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 271 | } |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 272 | } |