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.app.ActivityManager; 20 import android.content.Context; 21 import android.util.DisplayMetrics; 22 23 import com.android.internal.logging.UiEventLogger; 24 import com.android.internal.logging.UiEventLoggerImpl; 25 import com.android.systemui.dagger.qualifiers.TestHarness; 26 import com.android.systemui.plugins.PluginsModule; 27 import com.android.systemui.unfold.UnfoldTransitionModule; 28 import com.android.systemui.util.concurrency.GlobalConcurrencyModule; 29 30 import javax.inject.Singleton; 31 32 import dagger.Module; 33 import dagger.Provides; 34 35 /** 36 * Supplies globally scoped instances that should be available in all versions of SystemUI 37 * 38 * Providers in this module will be accessible to both WMComponent and SysUIComponent scoped 39 * classes. They are in here because they are either needed globally or are inherently universal 40 * to the application. 41 * 42 * Note that just because a class might be used by both WM and SysUI does not necessarily mean that 43 * it should go into this module. If WM and SysUI might need the class for different purposes 44 * or different semantics, it may make sense to ask them to supply their own. Something like 45 * threading and concurrency provide a good example. Both components need 46 * Threads/Handlers/Executors, but they need separate instances of them in many cases. 47 * 48 * Please use discretion when adding things to the global scope. 49 */ 50 @Module(includes = { 51 FrameworkServicesModule.class, 52 GlobalConcurrencyModule.class, 53 UnfoldTransitionModule.class, 54 PluginsModule.class, 55 }) 56 public class GlobalModule { 57 58 /** */ 59 @Provides provideDisplayMetrics(Context context)60 public DisplayMetrics provideDisplayMetrics(Context context) { 61 DisplayMetrics displayMetrics = new DisplayMetrics(); 62 context.getDisplay().getMetrics(displayMetrics); 63 return displayMetrics; 64 } 65 66 /** Provides an instance of {@link com.android.internal.logging.UiEventLogger} */ 67 @Provides 68 @Singleton provideUiEventLogger()69 static UiEventLogger provideUiEventLogger() { 70 return new UiEventLoggerImpl(); 71 } 72 73 @Provides 74 @TestHarness provideIsTestHarness()75 static boolean provideIsTestHarness() { 76 return ActivityManager.isRunningInUserTestHarness(); 77 } 78 } 79