summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dave Mankoff <mankoff@google.com> 2022-04-21 20:48:54 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-04-21 20:48:54 +0000
commit6584dbb6e6026a2698f31cea41f8e66698f67a54 (patch)
treec6c47411b5d9c073b02e86efcf84f563a1d827d1
parentfbcba3720545d1f12985a92a6123f85f5516bf51 (diff)
parent9ce5df5cdf796dd0d6481c78d6d83b2abd7a6deb (diff)
Merge "Cleanup GlobalModule." into tm-dev
-rw-r--r--packages/SystemUI/src/com/android/systemui/dagger/AndroidInternalsModule.java14
-rw-r--r--packages/SystemUI/src/com/android/systemui/dagger/DependencyProvider.java1
-rw-r--r--packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/dagger/GlobalModule.java50
-rw-r--r--packages/SystemUI/src/com/android/systemui/dagger/qualifiers/Application.java35
-rw-r--r--packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java15
6 files changed, 83 insertions, 40 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/AndroidInternalsModule.java b/packages/SystemUI/src/com/android/systemui/dagger/AndroidInternalsModule.java
index 48c54bca69ee..09928829b195 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/AndroidInternalsModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/AndroidInternalsModule.java
@@ -19,9 +19,13 @@ package com.android.systemui.dagger;
import android.content.Context;
import com.android.internal.logging.MetricsLogger;
+import com.android.internal.logging.UiEventLogger;
+import com.android.internal.logging.UiEventLoggerImpl;
import com.android.internal.util.NotificationMessagingUtil;
import com.android.internal.widget.LockPatternUtils;
+import javax.inject.Singleton;
+
import dagger.Module;
import dagger.Provides;
@@ -32,14 +36,14 @@ import dagger.Provides;
public class AndroidInternalsModule {
/** */
@Provides
- @SysUISingleton
+ @Singleton
public LockPatternUtils provideLockPatternUtils(Context context) {
return new LockPatternUtils(context);
}
/** */
@Provides
- @SysUISingleton
+ @Singleton
public MetricsLogger provideMetricsLogger() {
return new MetricsLogger();
}
@@ -50,4 +54,10 @@ public class AndroidInternalsModule {
return new NotificationMessagingUtil(context);
}
+ /** Provides an instance of {@link com.android.internal.logging.UiEventLogger} */
+ @Provides
+ @Singleton
+ static UiEventLogger provideUiEventLogger() {
+ return new UiEventLoggerImpl();
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/DependencyProvider.java b/packages/SystemUI/src/com/android/systemui/dagger/DependencyProvider.java
index 31ad36fb21d8..19e98f26cacb 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/DependencyProvider.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/DependencyProvider.java
@@ -27,7 +27,6 @@ import dagger.Module;
*/
@Deprecated
@Module(includes = {
- AndroidInternalsModule.class,
BroadcastDispatcherModule.class,
LeakModule.class,
NightDisplayListenerModule.class,
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java b/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
index e512b7cf3a20..5b6ddd8471da 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
@@ -90,6 +90,7 @@ import com.android.internal.util.LatencyTracker;
import com.android.systemui.Prefs;
import com.android.systemui.dagger.qualifiers.DisplayId;
import com.android.systemui.dagger.qualifiers.Main;
+import com.android.systemui.dagger.qualifiers.TestHarness;
import com.android.systemui.shared.system.PackageManagerWrapper;
import java.util.Optional;
@@ -445,6 +446,13 @@ public class FrameworkServicesModule {
@Provides
@Singleton
+ @TestHarness
+ static boolean provideIsTestHarness() {
+ return ActivityManager.isRunningInUserTestHarness();
+ }
+
+ @Provides
+ @Singleton
static TrustManager provideTrustManager(Context context) {
return context.getSystemService(TrustManager.class);
}
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/GlobalModule.java b/packages/SystemUI/src/com/android/systemui/dagger/GlobalModule.java
index 620feec8fbb8..ca725c0e39ff 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/GlobalModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/GlobalModule.java
@@ -16,23 +16,15 @@
package com.android.systemui.dagger;
-import android.app.ActivityManager;
import android.content.Context;
import android.util.DisplayMetrics;
+import android.view.Display;
-import com.android.internal.logging.UiEventLogger;
-import com.android.internal.logging.UiEventLoggerImpl;
-import com.android.systemui.dagger.qualifiers.TestHarness;
-import com.android.systemui.dagger.qualifiers.UiBackground;
+import com.android.systemui.dagger.qualifiers.Application;
import com.android.systemui.plugins.PluginsModule;
import com.android.systemui.unfold.UnfoldTransitionModule;
import com.android.systemui.util.concurrency.GlobalConcurrencyModule;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-
-import javax.inject.Singleton;
-
import dagger.Module;
import dagger.Provides;
@@ -52,43 +44,29 @@ import dagger.Provides;
* Please use discretion when adding things to the global scope.
*/
@Module(includes = {
+ AndroidInternalsModule.class,
FrameworkServicesModule.class,
GlobalConcurrencyModule.class,
UnfoldTransitionModule.class,
PluginsModule.class,
})
public class GlobalModule {
-
- /** */
- @Provides
- public DisplayMetrics provideDisplayMetrics(Context context) {
- DisplayMetrics displayMetrics = new DisplayMetrics();
- context.getDisplay().getMetrics(displayMetrics);
- return displayMetrics;
- }
-
- /** Provides an instance of {@link com.android.internal.logging.UiEventLogger} */
- @Provides
- @Singleton
- static UiEventLogger provideUiEventLogger() {
- return new UiEventLoggerImpl();
- }
-
+ /**
+ * TODO(b/229228871): This should be the default. No undecorated context should be available.
+ */
@Provides
- @TestHarness
- static boolean provideIsTestHarness() {
- return ActivityManager.isRunningInUserTestHarness();
+ @Application
+ public Context provideApplicationContext(Context context) {
+ return context.getApplicationContext();
}
/**
- * Provide an Executor specifically for running UI operations on a separate thread.
- *
- * Keep submitted runnables short and to the point, just as with any other UI code.
+ * @deprecated Deprecdated because {@link Display#getMetrics} is deprecated.
*/
@Provides
- @Singleton
- @UiBackground
- public static Executor provideUiBackgroundExecutor() {
- return Executors.newSingleThreadExecutor();
+ public DisplayMetrics provideDisplayMetrics(Context context) {
+ DisplayMetrics displayMetrics = new DisplayMetrics();
+ context.getDisplay().getMetrics(displayMetrics);
+ return displayMetrics;
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/qualifiers/Application.java b/packages/SystemUI/src/com/android/systemui/dagger/qualifiers/Application.java
new file mode 100644
index 000000000000..21e53a5b51d0
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/dagger/qualifiers/Application.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.dagger.qualifiers;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import android.content.Context;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+
+import javax.inject.Qualifier;
+
+/**
+ * Used to qualify a context as {@link Context#getApplicationContext}
+ */
+@Qualifier
+@Documented
+@Retention(RUNTIME)
+public @interface Application {
+}
diff --git a/packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java b/packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java
index 323db5cfd249..bc9e5963c22d 100644
--- a/packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java
+++ b/packages/SystemUI/src/com/android/systemui/util/concurrency/GlobalConcurrencyModule.java
@@ -21,9 +21,11 @@ import android.os.Handler;
import android.os.Looper;
import com.android.systemui.dagger.qualifiers.Main;
+import com.android.systemui.dagger.qualifiers.UiBackground;
import java.util.Optional;
import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
import javax.inject.Named;
import javax.inject.Singleton;
@@ -73,6 +75,18 @@ public abstract class GlobalConcurrencyModule {
}
/**
+ * Provide an Executor specifically for running UI operations on a separate thread.
+ *
+ * Keep submitted runnables short and to the point, just as with any other UI code.
+ */
+ @Provides
+ @Singleton
+ @UiBackground
+ public static Executor provideUiBackgroundExecutor() {
+ return Executors.newSingleThreadExecutor();
+ }
+
+ /**
* Provide a Main-Thread Executor.
*/
@Provides
@@ -92,7 +106,6 @@ public abstract class GlobalConcurrencyModule {
return new ExecutorImpl(looper);
}
-
/** */
@Binds
@Singleton