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