blob: be82a2d5325bb429723f4772d85c2b9f126eaa4c [file] [log] [blame]
Xiyuan Xia1b30f792016-01-06 08:50:30 -08001/*
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
17package com.android.systemui;
18
yoshiki iguchiac2ffdd2019-03-20 19:17:35 +090019import android.annotation.NonNull;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080020import android.content.Context;
Heemin Seog8277c312020-04-27 10:12:14 -070021import android.content.res.Resources;
Lucas Dupin787f9a02019-04-24 14:56:52 -070022import android.os.Handler;
23import android.os.Looper;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080024import android.util.Log;
25import android.view.ViewGroup;
26
Dave Mankoffa4a71362019-08-27 14:40:05 -040027import com.android.internal.annotations.VisibleForTesting;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080028import com.android.internal.widget.LockPatternUtils;
Lucas Dupin787f9a02019-04-24 14:56:52 -070029import com.android.keyguard.KeyguardUpdateMonitor;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080030import com.android.keyguard.ViewMediatorCallback;
Dave Mankofff4736812019-10-18 17:25:50 -040031import com.android.systemui.dagger.DaggerSystemUIRootComponent;
32import com.android.systemui.dagger.DependencyProvider;
33import com.android.systemui.dagger.SystemUIRootComponent;
Jorim Jaggi241ae102016-11-02 21:57:33 -070034import com.android.systemui.keyguard.DismissCallbackRegistry;
Dave Mankoffc195ea82019-06-28 16:33:25 -040035import com.android.systemui.plugins.FalsingManager;
Beverly8fdb5332019-02-04 14:29:49 -050036import com.android.systemui.plugins.statusbar.StatusBarStateController;
Satakshid2010f22019-10-29 10:57:43 -070037import com.android.systemui.screenshot.ScreenshotNotificationSmartActionsProvider;
Julia Reynoldsa8a6c172020-01-28 08:26:46 -050038import com.android.systemui.statusbar.NotificationListener;
Lucas Dupin20403372019-02-14 19:59:18 -080039import com.android.systemui.statusbar.NotificationMediaManager;
Selim Cinek820ba2d2019-06-18 18:59:09 -070040import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator;
Lucas Dupin9e3fa102017-11-08 17:16:55 -080041import com.android.systemui.statusbar.phone.DozeParameters;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080042import com.android.systemui.statusbar.phone.KeyguardBouncer;
Selim Cinek820ba2d2019-06-18 18:59:09 -070043import com.android.systemui.statusbar.phone.KeyguardBypassController;
Xiaohui Cheneb04a992016-03-22 14:58:03 -070044import com.android.systemui.statusbar.phone.NotificationIconAreaController;
Eliot Courtneye77edea2017-11-15 14:25:21 +090045import com.android.systemui.statusbar.phone.StatusBar;
Lucas Dupinc8f16e82019-09-17 18:24:50 -040046import com.android.systemui.statusbar.policy.KeyguardStateController;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080047
Satakshiaaf69532019-11-07 17:54:24 -080048import java.util.concurrent.Executor;
49
Jason Monk27d01a622018-12-10 15:57:09 -050050import dagger.Module;
51import dagger.Provides;
52
Xiyuan Xia1b30f792016-01-06 08:50:30 -080053/**
54 * Class factory to provide customizable SystemUI components.
55 */
56public class SystemUIFactory {
57 private static final String TAG = "SystemUIFactory";
58
59 static SystemUIFactory mFactory;
Fabian Kozynski1cb4aae2019-11-25 14:27:00 -050060 private SystemUIRootComponent mRootComponent;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080061
Jason Monk27d01a622018-12-10 15:57:09 -050062 public static <T extends SystemUIFactory> T getInstance() {
63 return (T) mFactory;
Xiyuan Xia1b30f792016-01-06 08:50:30 -080064 }
65
66 public static void createFromConfig(Context context) {
Dave Mankoffa4a71362019-08-27 14:40:05 -040067 if (mFactory != null) {
68 return;
69 }
70
Xiyuan Xia1b30f792016-01-06 08:50:30 -080071 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 Monk27d01a622018-12-10 15:57:09 -050080 mFactory.init(context);
Xiyuan Xia1b30f792016-01-06 08:50:30 -080081 } catch (Throwable t) {
82 Log.w(TAG, "Error creating SystemUIFactory component: " + clsName, t);
83 throw new RuntimeException(t);
84 }
85 }
86
Dave Mankoffa4a71362019-08-27 14:40:05 -040087 @VisibleForTesting
88 static void cleanup() {
89 mFactory = null;
90 }
91
Xiyuan Xia1b30f792016-01-06 08:50:30 -080092 public SystemUIFactory() {}
93
Govinda Wasserman2e86fb62019-08-13 11:35:44 -040094 private void init(Context context) {
Hyunyoung Song8f9d34c2019-08-30 14:47:43 -070095 mRootComponent = buildSystemUIRootComponent(context);
96
Govinda Wasserman2e86fb62019-08-13 11:35:44 -040097 // Every other part of our codebase currently relies on Dependency, so we
98 // really need to ensure the Dependency gets initialized early on.
Dave Mankoffeb593ae2019-09-04 11:31:55 -040099
100 Dependency dependency = new Dependency();
101 mRootComponent.createDependency().createSystemUI(dependency);
102 dependency.start();
yoshiki iguchiac2ffdd2019-03-20 19:17:35 +0900103 }
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 Monk27d01a622018-12-10 15:57:09 -0500111 }
112
Govinda Wasserman2e86fb62019-08-13 11:35:44 -0400113 protected SystemUIRootComponent buildSystemUIRootComponent(Context context) {
114 return DaggerSystemUIRootComponent.builder()
Dave Mankofff4736812019-10-18 17:25:50 -0400115 .dependencyProvider(new DependencyProvider())
Govinda Wasserman2e86fb62019-08-13 11:35:44 -0400116 .contextHolder(new ContextHolder(context))
117 .build();
118 }
119
Jason Monk27d01a622018-12-10 15:57:09 -0500120 public SystemUIRootComponent getRootComponent() {
121 return mRootComponent;
122 }
123
Heemin Seog8277c312020-04-27 10:12:14 -0700124 /** 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
Satakshid2010f22019-10-29 10:57:43 -0700134 /**
135 * Creates an instance of ScreenshotNotificationSmartActionsProvider.
136 * This method is overridden in vendor specific implementation of Sys UI.
137 */
138 public ScreenshotNotificationSmartActionsProvider
Satakshiaaf69532019-11-07 17:54:24 -0800139 createScreenshotNotificationSmartActionsProvider(Context context,
140 Executor executor,
141 Handler uiHandler) {
Satakshid2010f22019-10-29 10:57:43 -0700142 return new ScreenshotNotificationSmartActionsProvider();
143 }
144
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800145 public KeyguardBouncer createKeyguardBouncer(Context context, ViewMediatorCallback callback,
Hyunyoung Song8f9d34c2019-08-30 14:47:43 -0700146 LockPatternUtils lockPatternUtils, ViewGroup container,
Lucas Dupin15a6b6c2018-04-16 14:50:20 +0800147 DismissCallbackRegistry dismissCallbackRegistry,
Dave Mankoffc195ea82019-06-28 16:33:25 -0400148 KeyguardBouncer.BouncerExpansionCallback expansionCallback,
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400149 KeyguardStateController keyguardStateController, FalsingManager falsingManager,
150 KeyguardBypassController bypassController) {
Jorim Jaggi241ae102016-11-02 21:57:33 -0700151 return new KeyguardBouncer(context, callback, lockPatternUtils, container,
Dave Mankoffc195ea82019-06-28 16:33:25 -0400152 dismissCallbackRegistry, falsingManager,
Lucas Dupinc8f16e82019-09-17 18:24:50 -0400153 expansionCallback, keyguardStateController,
Dave Mankoffe2294692019-08-14 11:53:13 -0400154 Dependency.get(KeyguardUpdateMonitor.class), bypassController,
Lucas Dupin055ef942019-08-15 11:41:52 -0700155 new Handler(Looper.getMainLooper()));
Xiyuan Xia1b30f792016-01-06 08:50:30 -0800156 }
Xiaohui Chen5da71352016-02-22 10:04:41 -0800157
Xiaohui Cheneb04a992016-03-22 14:58:03 -0700158 public NotificationIconAreaController createNotificationIconAreaController(Context context,
Selim Cinek820ba2d2019-06-18 18:59:09 -0700159 StatusBar statusBar,
160 NotificationWakeUpCoordinator wakeUpCoordinator,
161 KeyguardBypassController keyguardBypassController,
Selim Cinek5dc581a2019-06-19 17:24:59 -0700162 StatusBarStateController statusBarStateController) {
Julia Reynolds12ad7ca2019-01-28 09:29:16 -0500163 return new NotificationIconAreaController(context, statusBar, statusBarStateController,
Selim Cinek5dc581a2019-06-19 17:24:59 -0700164 wakeUpCoordinator, keyguardBypassController,
Dave Mankoff2aff6c32019-10-14 17:40:37 -0400165 Dependency.get(NotificationMediaManager.class),
Julia Reynoldsa8a6c172020-01-28 08:26:46 -0500166 Dependency.get(NotificationListener.class),
Dave Mankoff2aff6c32019-10-14 17:40:37 -0400167 Dependency.get(DozeParameters.class));
Xiaohui Cheneb04a992016-03-22 14:58:03 -0700168 }
169
Jason Monk27d01a622018-12-10 15:57:09 -0500170 @Module
Govinda Wasserman2e86fb62019-08-13 11:35:44 -0400171 public static class ContextHolder {
Jason Monk27d01a622018-12-10 15:57:09 -0500172 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 Xia1b30f792016-01-06 08:50:30 -0800183}