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