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