• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static com.android.systemui.Dependency.ALLOW_NOTIFICATION_LONG_PRESS_NAME;
20 import static com.android.systemui.Dependency.LEAK_REPORT_EMAIL_NAME;
21 
22 import android.annotation.Nullable;
23 import android.app.AlarmManager;
24 import android.content.Context;
25 import android.os.Handler;
26 import android.os.Looper;
27 import android.util.Log;
28 import android.view.ViewGroup;
29 
30 import com.android.internal.colorextraction.ColorExtractor.GradientColors;
31 import com.android.internal.util.function.TriConsumer;
32 import com.android.internal.widget.LockPatternUtils;
33 import com.android.keyguard.KeyguardUpdateMonitor;
34 import com.android.keyguard.ViewMediatorCallback;
35 import com.android.systemui.assist.AssistManager;
36 import com.android.systemui.classifier.FalsingManagerFactory;
37 import com.android.systemui.dock.DockManager;
38 import com.android.systemui.fragments.FragmentService;
39 import com.android.systemui.keyguard.DismissCallbackRegistry;
40 import com.android.systemui.plugins.statusbar.StatusBarStateController;
41 import com.android.systemui.power.EnhancedEstimates;
42 import com.android.systemui.power.EnhancedEstimatesImpl;
43 import com.android.systemui.statusbar.KeyguardIndicationController;
44 import com.android.systemui.statusbar.NotificationListener;
45 import com.android.systemui.statusbar.NotificationLockscreenUserManager;
46 import com.android.systemui.statusbar.NotificationLockscreenUserManagerImpl;
47 import com.android.systemui.statusbar.NotificationMediaManager;
48 import com.android.systemui.statusbar.ScrimView;
49 import com.android.systemui.statusbar.notification.NotificationEntryManager;
50 import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider;
51 import com.android.systemui.statusbar.notification.collection.NotificationData;
52 import com.android.systemui.statusbar.phone.DozeParameters;
53 import com.android.systemui.statusbar.phone.KeyguardBouncer;
54 import com.android.systemui.statusbar.phone.KeyguardEnvironmentImpl;
55 import com.android.systemui.statusbar.phone.LockIcon;
56 import com.android.systemui.statusbar.phone.LockscreenWallpaper;
57 import com.android.systemui.statusbar.phone.NotificationIconAreaController;
58 import com.android.systemui.statusbar.phone.ScrimController;
59 import com.android.systemui.statusbar.phone.ScrimState;
60 import com.android.systemui.statusbar.phone.ShadeController;
61 import com.android.systemui.statusbar.phone.StatusBar;
62 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
63 import com.android.systemui.statusbar.policy.DeviceProvisionedController;
64 import com.android.systemui.util.InjectionInflationController;
65 import com.android.systemui.util.leak.GarbageMonitor;
66 import com.android.systemui.volume.VolumeDialogComponent;
67 
68 import java.util.function.Consumer;
69 
70 import javax.inject.Named;
71 import javax.inject.Singleton;
72 
73 import dagger.Component;
74 import dagger.Module;
75 import dagger.Provides;
76 
77 /**
78  * Class factory to provide customizable SystemUI components.
79  */
80 @Module
81 public class SystemUIFactory {
82     private static final String TAG = "SystemUIFactory";
83 
84     static SystemUIFactory mFactory;
85     private SystemUIRootComponent mRootComponent;
86 
getInstance()87     public static <T extends SystemUIFactory> T getInstance() {
88         return (T) mFactory;
89     }
90 
createFromConfig(Context context)91     public static void createFromConfig(Context context) {
92         final String clsName = context.getString(R.string.config_systemUIFactoryComponent);
93         if (clsName == null || clsName.length() == 0) {
94             throw new RuntimeException("No SystemUIFactory component configured");
95         }
96 
97         try {
98             Class<?> cls = null;
99             cls = context.getClassLoader().loadClass(clsName);
100             mFactory = (SystemUIFactory) cls.newInstance();
101             mFactory.init(context);
102         } catch (Throwable t) {
103             Log.w(TAG, "Error creating SystemUIFactory component: " + clsName, t);
104             throw new RuntimeException(t);
105         }
106     }
107 
SystemUIFactory()108     public SystemUIFactory() {}
109 
init(Context context)110     protected void init(Context context) {
111         mRootComponent = DaggerSystemUIFactory_SystemUIRootComponent.builder()
112                 .systemUIFactory(this)
113                 .dependencyProvider(new com.android.systemui.DependencyProvider())
114                 .contextHolder(new ContextHolder(context))
115                 .build();
116     }
117 
getRootComponent()118     public SystemUIRootComponent getRootComponent() {
119         return mRootComponent;
120     }
121 
createStatusBarKeyguardViewManager(Context context, ViewMediatorCallback viewMediatorCallback, LockPatternUtils lockPatternUtils)122     public StatusBarKeyguardViewManager createStatusBarKeyguardViewManager(Context context,
123             ViewMediatorCallback viewMediatorCallback, LockPatternUtils lockPatternUtils) {
124         return new StatusBarKeyguardViewManager(context, viewMediatorCallback, lockPatternUtils);
125     }
126 
createKeyguardBouncer(Context context, ViewMediatorCallback callback, LockPatternUtils lockPatternUtils, ViewGroup container, DismissCallbackRegistry dismissCallbackRegistry, KeyguardBouncer.BouncerExpansionCallback expansionCallback)127     public KeyguardBouncer createKeyguardBouncer(Context context, ViewMediatorCallback callback,
128             LockPatternUtils lockPatternUtils,  ViewGroup container,
129             DismissCallbackRegistry dismissCallbackRegistry,
130             KeyguardBouncer.BouncerExpansionCallback expansionCallback) {
131         return new KeyguardBouncer(context, callback, lockPatternUtils, container,
132                 dismissCallbackRegistry, FalsingManagerFactory.getInstance(context),
133                 expansionCallback, KeyguardUpdateMonitor.getInstance(context),
134                 new Handler(Looper.getMainLooper()));
135     }
136 
createScrimController(ScrimView scrimBehind, ScrimView scrimInFront, LockscreenWallpaper lockscreenWallpaper, TriConsumer<ScrimState, Float, GradientColors> scrimStateListener, Consumer<Integer> scrimVisibleListener, DozeParameters dozeParameters, AlarmManager alarmManager)137     public ScrimController createScrimController(ScrimView scrimBehind, ScrimView scrimInFront,
138             LockscreenWallpaper lockscreenWallpaper,
139             TriConsumer<ScrimState, Float, GradientColors> scrimStateListener,
140             Consumer<Integer> scrimVisibleListener, DozeParameters dozeParameters,
141             AlarmManager alarmManager) {
142         return new ScrimController(scrimBehind, scrimInFront, scrimStateListener,
143                 scrimVisibleListener, dozeParameters, alarmManager);
144     }
145 
createNotificationIconAreaController(Context context, StatusBar statusBar, StatusBarStateController statusBarStateController)146     public NotificationIconAreaController createNotificationIconAreaController(Context context,
147             StatusBar statusBar, StatusBarStateController statusBarStateController) {
148         return new NotificationIconAreaController(context, statusBar, statusBarStateController,
149                 Dependency.get(NotificationMediaManager.class));
150     }
151 
createKeyguardIndicationController(Context context, ViewGroup indicationArea, LockIcon lockIcon)152     public KeyguardIndicationController createKeyguardIndicationController(Context context,
153             ViewGroup indicationArea, LockIcon lockIcon) {
154         return new KeyguardIndicationController(context, indicationArea, lockIcon);
155     }
156 
createVolumeDialogComponent(SystemUI systemUi, Context context)157     public VolumeDialogComponent createVolumeDialogComponent(SystemUI systemUi, Context context) {
158         return new VolumeDialogComponent(systemUi, context);
159     }
160 
161     @Singleton
162     @Provides
provideKeyguardEnvironment(Context context)163     public NotificationData.KeyguardEnvironment provideKeyguardEnvironment(Context context) {
164         return new KeyguardEnvironmentImpl();
165     }
166 
167     @Singleton
168     @Provides
provideNotificationLockscreenUserManager( Context context)169     public NotificationLockscreenUserManager provideNotificationLockscreenUserManager(
170             Context context) {
171         return new NotificationLockscreenUserManagerImpl(context);
172     }
173 
174     @Singleton
175     @Provides
provideAssistManager(DeviceProvisionedController controller, Context context)176     public AssistManager provideAssistManager(DeviceProvisionedController controller,
177             Context context) {
178         return new AssistManager(controller, context);
179     }
180 
181     @Singleton
182     @Provides
183     @Nullable
provideDockManager(Context context)184     public DockManager provideDockManager(Context context) {
185         return null;
186     }
187 
188     @Singleton
189     @Provides
provideNotificationEntryManager(Context context)190     public NotificationEntryManager provideNotificationEntryManager(Context context) {
191         return new NotificationEntryManager(context);
192     }
193 
194     @Singleton
195     @Provides
provideEnhancedEstimates(Context context)196     public EnhancedEstimates provideEnhancedEstimates(Context context) {
197         return new EnhancedEstimatesImpl();
198     }
199 
200     @Singleton
201     @Provides
202     @Named(LEAK_REPORT_EMAIL_NAME)
203     @Nullable
provideLeakReportEmail()204     public String provideLeakReportEmail() {
205         return null;
206     }
207 
208     @Singleton
209     @Provides
provideNotificationListener(Context context)210     public NotificationListener provideNotificationListener(Context context) {
211         return new NotificationListener(context);
212     }
213 
214     @Singleton
215     @Provides
provideNotificationInterruptionStateProvider( Context context)216     public NotificationInterruptionStateProvider provideNotificationInterruptionStateProvider(
217             Context context) {
218         return new NotificationInterruptionStateProvider(context);
219     }
220 
221     @Singleton
222     @Provides
223     @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME)
provideAllowNotificationLongPress()224     public boolean provideAllowNotificationLongPress() {
225         return true;
226     }
227 
228     @Singleton
229     @Provides
provideShadeController(Context context)230     public ShadeController provideShadeController(Context context) {
231         return SysUiServiceProvider.getComponent(context, StatusBar.class);
232     }
233 
234     @Module
235     protected static class ContextHolder {
236         private Context mContext;
237 
ContextHolder(Context context)238         public ContextHolder(Context context) {
239             mContext = context;
240         }
241 
242         @Provides
provideContext()243         public Context provideContext() {
244             return mContext;
245         }
246     }
247 
248     @Singleton
249     @Component(modules = {SystemUIFactory.class, DependencyProvider.class, DependencyBinder.class,
250             ContextHolder.class})
251     public interface SystemUIRootComponent {
252         @Singleton
createDependency()253         Dependency.DependencyInjector createDependency();
254 
255         @Singleton
getStatusBarInjector()256         StatusBar.StatusBarInjector getStatusBarInjector();
257 
258         /**
259          * FragmentCreator generates all Fragments that need injection.
260          */
261         @Singleton
createFragmentCreator()262         FragmentService.FragmentCreator createFragmentCreator();
263 
264         /**
265          * ViewCreator generates all Views that need injection.
266          */
createViewCreator()267         InjectionInflationController.ViewCreator createViewCreator();
268 
269         @Singleton
createGarbageMonitor()270         GarbageMonitor createGarbageMonitor();
271     }
272 }
273