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 | |
yoshiki iguchi | ac2ffdd | 2019-03-20 19:17:35 +0900 | [diff] [blame] | 19 | import android.annotation.NonNull; |
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 | |
Dave Mankoff | a4a7136 | 2019-08-27 14:40:05 -0400 | [diff] [blame] | 26 | import com.android.internal.annotations.VisibleForTesting; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 27 | import com.android.internal.widget.LockPatternUtils; |
Lucas Dupin | 787f9a0 | 2019-04-24 14:56:52 -0700 | [diff] [blame] | 28 | import com.android.keyguard.KeyguardUpdateMonitor; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 29 | import com.android.keyguard.ViewMediatorCallback; |
Dave Mankoff | f473681 | 2019-10-18 17:25:50 -0400 | [diff] [blame^] | 30 | import com.android.systemui.dagger.DaggerSystemUIRootComponent; |
| 31 | import com.android.systemui.dagger.DependencyProvider; |
| 32 | import com.android.systemui.dagger.SystemUIRootComponent; |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 33 | import com.android.systemui.keyguard.DismissCallbackRegistry; |
Dave Mankoff | c195ea8 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 34 | import com.android.systemui.plugins.FalsingManager; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 35 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 36 | import com.android.systemui.statusbar.KeyguardIndicationController; |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 37 | import com.android.systemui.statusbar.NotificationMediaManager; |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 38 | import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator; |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 39 | import com.android.systemui.statusbar.phone.DozeParameters; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 40 | import com.android.systemui.statusbar.phone.KeyguardBouncer; |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 41 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 42 | import com.android.systemui.statusbar.phone.LockIcon; |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 43 | import com.android.systemui.statusbar.phone.NotificationIconAreaController; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 44 | import com.android.systemui.statusbar.phone.StatusBar; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 45 | import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 46 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 47 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 48 | import dagger.Module; |
| 49 | import dagger.Provides; |
| 50 | |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 51 | /** |
| 52 | * Class factory to provide customizable SystemUI components. |
| 53 | */ |
| 54 | public class SystemUIFactory { |
| 55 | private static final String TAG = "SystemUIFactory"; |
| 56 | |
| 57 | static SystemUIFactory mFactory; |
Govinda Wasserman | 2e86fb6 | 2019-08-13 11:35:44 -0400 | [diff] [blame] | 58 | protected SystemUIRootComponent mRootComponent; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 59 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 60 | public static <T extends SystemUIFactory> T getInstance() { |
| 61 | return (T) mFactory; |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | public static void createFromConfig(Context context) { |
Dave Mankoff | a4a7136 | 2019-08-27 14:40:05 -0400 | [diff] [blame] | 65 | if (mFactory != null) { |
| 66 | return; |
| 67 | } |
| 68 | |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 69 | final String clsName = context.getString(R.string.config_systemUIFactoryComponent); |
| 70 | if (clsName == null || clsName.length() == 0) { |
| 71 | throw new RuntimeException("No SystemUIFactory component configured"); |
| 72 | } |
| 73 | |
| 74 | try { |
| 75 | Class<?> cls = null; |
| 76 | cls = context.getClassLoader().loadClass(clsName); |
| 77 | mFactory = (SystemUIFactory) cls.newInstance(); |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 78 | mFactory.init(context); |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 79 | } catch (Throwable t) { |
| 80 | Log.w(TAG, "Error creating SystemUIFactory component: " + clsName, t); |
| 81 | throw new RuntimeException(t); |
| 82 | } |
| 83 | } |
| 84 | |
Dave Mankoff | a4a7136 | 2019-08-27 14:40:05 -0400 | [diff] [blame] | 85 | @VisibleForTesting |
| 86 | static void cleanup() { |
| 87 | mFactory = null; |
| 88 | } |
| 89 | |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 90 | public SystemUIFactory() {} |
| 91 | |
Govinda Wasserman | 2e86fb6 | 2019-08-13 11:35:44 -0400 | [diff] [blame] | 92 | private void init(Context context) { |
Hyunyoung Song | 8f9d34c | 2019-08-30 14:47:43 -0700 | [diff] [blame] | 93 | mRootComponent = buildSystemUIRootComponent(context); |
| 94 | |
Govinda Wasserman | 2e86fb6 | 2019-08-13 11:35:44 -0400 | [diff] [blame] | 95 | // Every other part of our codebase currently relies on Dependency, so we |
| 96 | // really need to ensure the Dependency gets initialized early on. |
Dave Mankoff | eb593ae | 2019-09-04 11:31:55 -0400 | [diff] [blame] | 97 | |
| 98 | Dependency dependency = new Dependency(); |
| 99 | mRootComponent.createDependency().createSystemUI(dependency); |
| 100 | dependency.start(); |
yoshiki iguchi | ac2ffdd | 2019-03-20 19:17:35 +0900 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | protected void initWithRootComponent(@NonNull SystemUIRootComponent rootComponent) { |
| 104 | if (mRootComponent != null) { |
| 105 | throw new RuntimeException("Root component can be set only once."); |
| 106 | } |
| 107 | |
| 108 | mRootComponent = rootComponent; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 109 | } |
| 110 | |
Govinda Wasserman | 2e86fb6 | 2019-08-13 11:35:44 -0400 | [diff] [blame] | 111 | protected SystemUIRootComponent buildSystemUIRootComponent(Context context) { |
| 112 | return DaggerSystemUIRootComponent.builder() |
Dave Mankoff | f473681 | 2019-10-18 17:25:50 -0400 | [diff] [blame^] | 113 | .dependencyProvider(new DependencyProvider()) |
Govinda Wasserman | 2e86fb6 | 2019-08-13 11:35:44 -0400 | [diff] [blame] | 114 | .contextHolder(new ContextHolder(context)) |
| 115 | .build(); |
| 116 | } |
| 117 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 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, |
Hyunyoung Song | 8f9d34c | 2019-08-30 14:47:43 -0700 | [diff] [blame] | 128 | LockPatternUtils lockPatternUtils, ViewGroup container, |
Lucas Dupin | 15a6b6c | 2018-04-16 14:50:20 +0800 | [diff] [blame] | 129 | DismissCallbackRegistry dismissCallbackRegistry, |
Dave Mankoff | c195ea8 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 130 | KeyguardBouncer.BouncerExpansionCallback expansionCallback, |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 131 | KeyguardStateController keyguardStateController, FalsingManager falsingManager, |
| 132 | KeyguardBypassController bypassController) { |
Jorim Jaggi | 241ae10 | 2016-11-02 21:57:33 -0700 | [diff] [blame] | 133 | return new KeyguardBouncer(context, callback, lockPatternUtils, container, |
Dave Mankoff | c195ea8 | 2019-06-28 16:33:25 -0400 | [diff] [blame] | 134 | dismissCallbackRegistry, falsingManager, |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 135 | expansionCallback, keyguardStateController, |
Dave Mankoff | e229469 | 2019-08-14 11:53:13 -0400 | [diff] [blame] | 136 | Dependency.get(KeyguardUpdateMonitor.class), bypassController, |
Lucas Dupin | 055ef94 | 2019-08-15 11:41:52 -0700 | [diff] [blame] | 137 | new Handler(Looper.getMainLooper())); |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 138 | } |
Xiaohui Chen | 5da7135 | 2016-02-22 10:04:41 -0800 | [diff] [blame] | 139 | |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 140 | public NotificationIconAreaController createNotificationIconAreaController(Context context, |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 141 | StatusBar statusBar, |
| 142 | NotificationWakeUpCoordinator wakeUpCoordinator, |
| 143 | KeyguardBypassController keyguardBypassController, |
Selim Cinek | 5dc581a | 2019-06-19 17:24:59 -0700 | [diff] [blame] | 144 | StatusBarStateController statusBarStateController) { |
Julia Reynolds | 12ad7ca | 2019-01-28 09:29:16 -0500 | [diff] [blame] | 145 | return new NotificationIconAreaController(context, statusBar, statusBarStateController, |
Selim Cinek | 5dc581a | 2019-06-19 17:24:59 -0700 | [diff] [blame] | 146 | wakeUpCoordinator, keyguardBypassController, |
Dave Mankoff | 2aff6c3 | 2019-10-14 17:40:37 -0400 | [diff] [blame] | 147 | Dependency.get(NotificationMediaManager.class), |
| 148 | Dependency.get(DozeParameters.class)); |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Zachary Iqbal | f50284c | 2017-01-22 18:54:46 -0800 | [diff] [blame] | 151 | public KeyguardIndicationController createKeyguardIndicationController(Context context, |
| 152 | ViewGroup indicationArea, LockIcon lockIcon) { |
| 153 | return new KeyguardIndicationController(context, indicationArea, lockIcon); |
| 154 | } |
| 155 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 156 | @Module |
Govinda Wasserman | 2e86fb6 | 2019-08-13 11:35:44 -0400 | [diff] [blame] | 157 | public static class ContextHolder { |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 158 | private Context mContext; |
| 159 | |
| 160 | public ContextHolder(Context context) { |
| 161 | mContext = context; |
| 162 | } |
| 163 | |
| 164 | @Provides |
| 165 | public Context provideContext() { |
| 166 | return mContext; |
| 167 | } |
| 168 | } |
Xiyuan Xia | 1b30f79 | 2016-01-06 08:50:30 -0800 | [diff] [blame] | 169 | } |