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 
19 import android.app.AlarmManager;
20 import android.content.Context;
21 import android.util.ArrayMap;
22 import android.util.Log;
23 import android.view.ViewGroup;
24 
25 import com.android.internal.logging.MetricsLogger;
26 import com.android.internal.util.function.TriConsumer;
27 import com.android.internal.widget.LockPatternUtils;
28 import com.android.internal.colorextraction.ColorExtractor.GradientColors;
29 import com.android.keyguard.ViewMediatorCallback;
30 import com.android.systemui.Dependency.DependencyProvider;
31 import com.android.systemui.classifier.FalsingManager;
32 import com.android.systemui.keyguard.DismissCallbackRegistry;
33 import com.android.systemui.qs.QSTileHost;
34 import com.android.systemui.statusbar.KeyguardIndicationController;
35 import com.android.systemui.statusbar.NotificationBlockingHelperManager;
36 import com.android.systemui.statusbar.NotificationEntryManager;
37 import com.android.systemui.statusbar.NotificationGutsManager;
38 import com.android.systemui.statusbar.NotificationListener;
39 import com.android.systemui.statusbar.NotificationLockscreenUserManager;
40 import com.android.systemui.statusbar.NotificationLogger;
41 import com.android.systemui.statusbar.NotificationMediaManager;
42 import com.android.systemui.statusbar.NotificationRemoteInputManager;
43 import com.android.systemui.statusbar.NotificationViewHierarchyManager;
44 import com.android.systemui.statusbar.ScrimView;
45 import com.android.systemui.statusbar.SmartReplyController;
46 import com.android.systemui.statusbar.notification.VisualStabilityManager;
47 import com.android.systemui.statusbar.phone.DozeParameters;
48 import com.android.systemui.statusbar.phone.KeyguardBouncer;
49 import com.android.systemui.statusbar.phone.KeyguardDismissUtil;
50 import com.android.systemui.statusbar.phone.LockIcon;
51 import com.android.systemui.statusbar.phone.LockscreenWallpaper;
52 import com.android.systemui.statusbar.phone.NotificationGroupManager;
53 import com.android.systemui.statusbar.phone.NotificationIconAreaController;
54 import com.android.systemui.statusbar.phone.ScrimController;
55 import com.android.systemui.statusbar.phone.ScrimState;
56 import com.android.systemui.statusbar.phone.StatusBar;
57 import com.android.systemui.statusbar.phone.StatusBarIconController;
58 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
59 import com.android.systemui.statusbar.policy.RemoteInputQuickSettingsDisabler;
60 import com.android.systemui.statusbar.policy.SmartReplyConstants;
61 
62 import java.util.function.Consumer;
63 
64 /**
65  * Class factory to provide customizable SystemUI components.
66  */
67 public class SystemUIFactory {
68     private static final String TAG = "SystemUIFactory";
69 
70     static SystemUIFactory mFactory;
71 
getInstance()72     public static SystemUIFactory getInstance() {
73         return mFactory;
74     }
75 
createFromConfig(Context context)76     public static void createFromConfig(Context context) {
77         final String clsName = context.getString(R.string.config_systemUIFactoryComponent);
78         if (clsName == null || clsName.length() == 0) {
79             throw new RuntimeException("No SystemUIFactory component configured");
80         }
81 
82         try {
83             Class<?> cls = null;
84             cls = context.getClassLoader().loadClass(clsName);
85             mFactory = (SystemUIFactory) cls.newInstance();
86         } catch (Throwable t) {
87             Log.w(TAG, "Error creating SystemUIFactory component: " + clsName, t);
88             throw new RuntimeException(t);
89         }
90     }
91 
SystemUIFactory()92     public SystemUIFactory() {}
93 
createStatusBarKeyguardViewManager(Context context, ViewMediatorCallback viewMediatorCallback, LockPatternUtils lockPatternUtils)94     public StatusBarKeyguardViewManager createStatusBarKeyguardViewManager(Context context,
95             ViewMediatorCallback viewMediatorCallback, LockPatternUtils lockPatternUtils) {
96         return new StatusBarKeyguardViewManager(context, viewMediatorCallback, lockPatternUtils);
97     }
98 
createKeyguardBouncer(Context context, ViewMediatorCallback callback, LockPatternUtils lockPatternUtils, ViewGroup container, DismissCallbackRegistry dismissCallbackRegistry, KeyguardBouncer.BouncerExpansionCallback expansionCallback)99     public KeyguardBouncer createKeyguardBouncer(Context context, ViewMediatorCallback callback,
100             LockPatternUtils lockPatternUtils,  ViewGroup container,
101             DismissCallbackRegistry dismissCallbackRegistry,
102             KeyguardBouncer.BouncerExpansionCallback expansionCallback) {
103         return new KeyguardBouncer(context, callback, lockPatternUtils, container,
104                 dismissCallbackRegistry, FalsingManager.getInstance(context), expansionCallback);
105     }
106 
createScrimController(ScrimView scrimBehind, ScrimView scrimInFront, LockscreenWallpaper lockscreenWallpaper, TriConsumer<ScrimState, Float, GradientColors> scrimStateListener, Consumer<Integer> scrimVisibleListener, DozeParameters dozeParameters, AlarmManager alarmManager)107     public ScrimController createScrimController(ScrimView scrimBehind, ScrimView scrimInFront,
108             LockscreenWallpaper lockscreenWallpaper,
109             TriConsumer<ScrimState, Float, GradientColors> scrimStateListener,
110             Consumer<Integer> scrimVisibleListener, DozeParameters dozeParameters,
111             AlarmManager alarmManager) {
112         return new ScrimController(scrimBehind, scrimInFront, scrimStateListener,
113                 scrimVisibleListener, dozeParameters, alarmManager);
114     }
115 
createNotificationIconAreaController(Context context, StatusBar statusBar)116     public NotificationIconAreaController createNotificationIconAreaController(Context context,
117             StatusBar statusBar) {
118         return new NotificationIconAreaController(context, statusBar);
119     }
120 
createKeyguardIndicationController(Context context, ViewGroup indicationArea, LockIcon lockIcon)121     public KeyguardIndicationController createKeyguardIndicationController(Context context,
122             ViewGroup indicationArea, LockIcon lockIcon) {
123         return new KeyguardIndicationController(context, indicationArea, lockIcon);
124     }
125 
createQSTileHost(Context context, StatusBar statusBar, StatusBarIconController iconController)126     public QSTileHost createQSTileHost(Context context, StatusBar statusBar,
127             StatusBarIconController iconController) {
128         return new QSTileHost(context, statusBar, iconController);
129     }
130 
injectDependencies(ArrayMap<Object, DependencyProvider> providers, Context context)131     public void injectDependencies(ArrayMap<Object, DependencyProvider> providers,
132             Context context) {
133         providers.put(NotificationLockscreenUserManager.class,
134                 () -> new NotificationLockscreenUserManager(context));
135         providers.put(VisualStabilityManager.class, VisualStabilityManager::new);
136         providers.put(NotificationGroupManager.class, NotificationGroupManager::new);
137         providers.put(NotificationMediaManager.class, () -> new NotificationMediaManager(context));
138         providers.put(NotificationGutsManager.class, () -> new NotificationGutsManager(context));
139         providers.put(NotificationBlockingHelperManager.class,
140                 () -> new NotificationBlockingHelperManager(context));
141         providers.put(NotificationRemoteInputManager.class,
142                 () -> new NotificationRemoteInputManager(context));
143         providers.put(SmartReplyConstants.class,
144                 () -> new SmartReplyConstants(Dependency.get(Dependency.MAIN_HANDLER), context));
145         providers.put(NotificationListener.class, () -> new NotificationListener(context));
146         providers.put(NotificationLogger.class, NotificationLogger::new);
147         providers.put(NotificationViewHierarchyManager.class,
148                 () -> new NotificationViewHierarchyManager(context));
149         providers.put(NotificationEntryManager.class, () -> new NotificationEntryManager(context));
150         providers.put(KeyguardDismissUtil.class, KeyguardDismissUtil::new);
151         providers.put(SmartReplyController.class, () -> new SmartReplyController());
152         providers.put(RemoteInputQuickSettingsDisabler.class,
153                 () -> new RemoteInputQuickSettingsDisabler(context));
154     }
155 }
156