• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.dagger;
18 
19 import android.content.Context;
20 import android.util.DisplayMetrics;
21 import android.view.Display;
22 
23 import com.android.systemui.dagger.qualifiers.Application;
24 import com.android.systemui.dagger.qualifiers.Main;
25 import com.android.systemui.plugins.PluginsModule;
26 import com.android.systemui.unfold.UnfoldTransitionModule;
27 import com.android.systemui.util.concurrency.GlobalConcurrencyModule;
28 import com.android.systemui.util.kotlin.GlobalCoroutinesModule;
29 
30 import dagger.Module;
31 import dagger.Provides;
32 
33 /**
34  * Supplies globally scoped instances that should be available in all versions of SystemUI
35  *
36  * Providers in this module will be accessible to both WMComponent and SysUIComponent scoped
37  * classes. They are in here because they are either needed globally or are inherently universal
38  * to the application.
39  *
40  * Note that just because a class might be used by both WM and SysUI does not necessarily mean that
41  * it should go into this module. If WM and SysUI might need the class for different purposes
42  * or different semantics, it may make sense to ask them to supply their own. Something like
43  * threading and concurrency provide a good example. Both components need
44  * Threads/Handlers/Executors, but they need separate instances of them in many cases.
45  *
46  * Please use discretion when adding things to the global scope.
47  */
48 @Module(includes = {
49         AndroidInternalsModule.class,
50         FrameworkServicesModule.class,
51         GlobalConcurrencyModule.class,
52         GlobalCoroutinesModule.class,
53         UnfoldTransitionModule.class,
54         PluginsModule.class,
55 })
56 public class GlobalModule {
57     /**
58      * TODO(b/229228871): This should be the default. No undecorated context should be available.
59      */
60     @Provides
61     @Application
provideApplicationContext(Context context)62     public Context provideApplicationContext(Context context) {
63         return context.getApplicationContext();
64     }
65 
66     /** Provides the default content with the main annotation. */
67     @Provides
68     @Main
provideMainContext(Context context)69     public Context provideMainContext(Context context) {
70         return context;
71     }
72 
73     /**
74      * @deprecated Deprecdated because {@link Display#getMetrics} is deprecated.
75      */
76     @Provides
77     @Deprecated
provideDisplayMetrics(Context context)78     public DisplayMetrics provideDisplayMetrics(Context context) {
79         DisplayMetrics displayMetrics = new DisplayMetrics();
80         context.getDisplay().getMetrics(displayMetrics);
81         return displayMetrics;
82     }
83 }
84