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