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