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 | |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 19 | import android.app.AlarmManager; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Lucas Dupin | 787f9a0 | 2019-04-24 14:56:52 -0700 | [diff] [blame] | 21 | import android.os.Handler; |
| 22 | import android.os.Looper; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 23 | import android.util.Log; |
| 24 | import android.view.ViewGroup; |
| 25 | |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 26 | import com.android.internal.colorextraction.ColorExtractor.GradientColors; |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 27 | import com.android.internal.util.function.TriConsumer; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 28 | import com.android.internal.widget.LockPatternUtils; |
Lucas Dupin | 787f9a0 | 2019-04-24 14:56:52 -0700 | [diff] [blame] | 29 | import com.android.keyguard.KeyguardUpdateMonitor; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 30 | import com.android.keyguard.ViewMediatorCallback; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 31 | import com.android.systemui.keyguard.DismissCallbackRegistry; |
Dave Mankoff | 2339f59 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 32 | import com.android.systemui.plugins.FalsingManager; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 33 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 34 | import com.android.systemui.statusbar.KeyguardIndicationController; |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 35 | import com.android.systemui.statusbar.NotificationMediaManager; |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 36 | import com.android.systemui.statusbar.ScrimView; |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 37 | import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 38 | import com.android.systemui.statusbar.phone.DozeParameters; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 39 | import com.android.systemui.statusbar.phone.KeyguardBouncer; |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 40 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 41 | import com.android.systemui.statusbar.phone.LockIcon; |
Jorim Jaggi | e31f6b8 | 2016-07-01 16:15:09 -0700 | [diff] [blame] | 42 | import com.android.systemui.statusbar.phone.LockscreenWallpaper; |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 43 | import com.android.systemui.statusbar.phone.NotificationIconAreaController; |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 44 | import com.android.systemui.statusbar.phone.ScrimController; |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 45 | import com.android.systemui.statusbar.phone.ScrimState; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 46 | import com.android.systemui.statusbar.phone.StatusBar; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 47 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
Lucas Dupin | 7825b94 | 2019-06-03 20:22:39 -0700 | [diff] [blame] | 48 | import com.android.systemui.statusbar.phone.UnlockMethodCache; |
Selim Cinek | 72cd9a7 | 2019-08-09 17:19:57 -0700 | [diff] [blame] | 49 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 50 | import com.android.systemui.volume.VolumeDialogComponent; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 51 | |
Adrian Roos | a5c6322 | 2017-07-27 16:33:39 +0200 | [diff] [blame] | 52 | import java.util.function.Consumer; |
| 53 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 54 | import dagger.Module; |
| 55 | import dagger.Provides; |
| 56 | |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 57 | /** |
| 58 | * Class factory to provide customizable SystemUI components. |
| 59 | */ |
| 60 | public class SystemUIFactory { |
| 61 | private static final String TAG = "SystemUIFactory"; |
| 62 | |
| 63 | static SystemUIFactory mFactory; |
Govinda Wasserman | 3e7ce55 | 2019-08-13 11:35:44 -0400 | [diff] [blame] | 64 | protected SystemUIRootComponent mRootComponent; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 65 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 66 | public static <T extends SystemUIFactory> T getInstance() { |
| 67 | return (T) mFactory; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | public static void createFromConfig(Context context) { |
| 71 | final String clsName = context.getString(R.string.config_systemUIFactoryComponent); |
| 72 | if (clsName == null || clsName.length() == 0) { |
| 73 | throw new RuntimeException("No SystemUIFactory component configured"); |
| 74 | } |
| 75 | |
| 76 | try { |
| 77 | Class<?> cls = null; |
| 78 | cls = context.getClassLoader().loadClass(clsName); |
| 79 | mFactory = (SystemUIFactory) cls.newInstance(); |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 80 | mFactory.init(context); |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 81 | } catch (Throwable t) { |
| 82 | Log.w(TAG, "Error creating SystemUIFactory component: " + clsName, t); |
| 83 | throw new RuntimeException(t); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | public SystemUIFactory() {} |
| 88 | |
Govinda Wasserman | 3e7ce55 | 2019-08-13 11:35:44 -0400 | [diff] [blame] | 89 | private void init(Context context) { |
| 90 | mRootComponent = buildSystemUIRootComponent(context); |
Dave Mankoff | 037d9fc | 2019-08-09 11:08:52 -0400 | [diff] [blame] | 91 | |
| 92 | // Every other part of our codebase currently relies on Dependency, so we |
| 93 | // really need to ensure the Dependency gets initialized early on. |
| 94 | Dependency.initDependencies(mRootComponent); |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 95 | } |
| 96 | |
Govinda Wasserman | 3e7ce55 | 2019-08-13 11:35:44 -0400 | [diff] [blame] | 97 | protected SystemUIRootComponent buildSystemUIRootComponent(Context context) { |
| 98 | return DaggerSystemUIRootComponent.builder() |
| 99 | .dependencyProvider(new com.android.systemui.DependencyProvider()) |
| 100 | .contextHolder(new ContextHolder(context)) |
| 101 | .build(); |
| 102 | } |
| 103 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 104 | public SystemUIRootComponent getRootComponent() { |
| 105 | return mRootComponent; |
| 106 | } |
| 107 | |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 108 | public StatusBarKeyguardViewManager createStatusBarKeyguardViewManager(Context context, |
| 109 | ViewMediatorCallback viewMediatorCallback, LockPatternUtils lockPatternUtils) { |
| 110 | return new StatusBarKeyguardViewManager(context, viewMediatorCallback, lockPatternUtils); |
| 111 | } |
| 112 | |
| 113 | public KeyguardBouncer createKeyguardBouncer(Context context, ViewMediatorCallback callback, |
Dave Mankoff | 037d9fc | 2019-08-09 11:08:52 -0400 | [diff] [blame] | 114 | LockPatternUtils lockPatternUtils, ViewGroup container, |
Lucas Dupin | 15a6b6c | 2018-04-16 14:50:20 +0800 | [diff] [blame] | 115 | DismissCallbackRegistry dismissCallbackRegistry, |
Dave Mankoff | 2339f59 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 116 | KeyguardBouncer.BouncerExpansionCallback expansionCallback, |
Lucas Dupin | d969b76 | 2019-08-15 11:41:52 -0700 | [diff] [blame] | 117 | FalsingManager falsingManager, KeyguardBypassController bypassController) { |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 118 | return new KeyguardBouncer(context, callback, lockPatternUtils, container, |
Dave Mankoff | 2339f59 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 119 | dismissCallbackRegistry, falsingManager, |
Lucas Dupin | 7825b94 | 2019-06-03 20:22:39 -0700 | [diff] [blame] | 120 | expansionCallback, UnlockMethodCache.getInstance(context), |
Lucas Dupin | d969b76 | 2019-08-15 11:41:52 -0700 | [diff] [blame] | 121 | KeyguardUpdateMonitor.getInstance(context), bypassController, |
| 122 | new Handler(Looper.getMainLooper())); |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 123 | } |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 124 | |
shawnlin | 317db37 | 2018-04-09 19:49:48 +0800 | [diff] [blame] | 125 | public ScrimController createScrimController(ScrimView scrimBehind, ScrimView scrimInFront, |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 126 | ScrimView scrimForBubble, |
Yohei Yukawa | 795f010 | 2018-04-13 14:55:30 -0700 | [diff] [blame] | 127 | LockscreenWallpaper lockscreenWallpaper, |
| 128 | TriConsumer<ScrimState, Float, GradientColors> scrimStateListener, |
Selim Cinek | 99e9adf | 2018-03-15 09:17:47 -0700 | [diff] [blame] | 129 | Consumer<Integer> scrimVisibleListener, DozeParameters dozeParameters, |
Selim Cinek | 72cd9a7 | 2019-08-09 17:19:57 -0700 | [diff] [blame] | 130 | AlarmManager alarmManager, KeyguardMonitor keyguardMonitor) { |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 131 | return new ScrimController(scrimBehind, scrimInFront, scrimForBubble, scrimStateListener, |
Selim Cinek | 72cd9a7 | 2019-08-09 17:19:57 -0700 | [diff] [blame] | 132 | scrimVisibleListener, dozeParameters, alarmManager, keyguardMonitor); |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 133 | } |
Muyuan Li | 94ce94e | 2016-02-24 16:20:54 -0800 | [diff] [blame] | 134 | |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 135 | public NotificationIconAreaController createNotificationIconAreaController(Context context, |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 136 | StatusBar statusBar, |
| 137 | NotificationWakeUpCoordinator wakeUpCoordinator, |
| 138 | KeyguardBypassController keyguardBypassController, |
Selim Cinek | 5dc581a | 2019-06-19 17:24:59 -0700 | [diff] [blame] | 139 | StatusBarStateController statusBarStateController) { |
Julia Reynolds | 12ad7ca | 2019-01-28 09:29:16 -0500 | [diff] [blame] | 140 | return new NotificationIconAreaController(context, statusBar, statusBarStateController, |
Selim Cinek | 5dc581a | 2019-06-19 17:24:59 -0700 | [diff] [blame] | 141 | wakeUpCoordinator, keyguardBypassController, |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 142 | Dependency.get(NotificationMediaManager.class)); |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 145 | public KeyguardIndicationController createKeyguardIndicationController(Context context, |
| 146 | ViewGroup indicationArea, LockIcon lockIcon) { |
| 147 | return new KeyguardIndicationController(context, indicationArea, lockIcon); |
| 148 | } |
| 149 | |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 150 | public VolumeDialogComponent createVolumeDialogComponent(SystemUI systemUi, Context context) { |
| 151 | return new VolumeDialogComponent(systemUi, context); |
| 152 | } |
| 153 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 154 | @Module |
Govinda Wasserman | 3e7ce55 | 2019-08-13 11:35:44 -0400 | [diff] [blame] | 155 | public static class ContextHolder { |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 156 | private Context mContext; |
| 157 | |
| 158 | public ContextHolder(Context context) { |
| 159 | mContext = context; |
| 160 | } |
| 161 | |
| 162 | @Provides |
| 163 | public Context provideContext() { |
| 164 | return mContext; |
| 165 | } |
| 166 | } |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 167 | } |