diff options
| author | 2022-06-28 13:46:49 -0400 | |
|---|---|---|
| committer | 2022-06-28 14:36:04 -0400 | |
| commit | 06736028df21cf514f24b29e67317c45951a018f (patch) | |
| tree | 5355066edcee6848244be515b6f0cdb1a67ebf41 | |
| parent | 6dfbb419d7872f1191e0bfa581901e3b2a2f3fc4 (diff) | |
Dagger Providers for CoroutineScope + Dispatchers
Fixes: 237408543
Test: mp droid
Change-Id: Ia37d7aecd07dd8a3d5827aee8bffe23109f3403f
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java | 2 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt | 41 |
2 files changed, 43 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java index 366ef2651a92..a1065b08482e 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java @@ -83,6 +83,7 @@ import com.android.systemui.unfold.SysUIUnfoldModule; import com.android.systemui.user.UserModule; import com.android.systemui.util.concurrency.SysUIConcurrencyModule; import com.android.systemui.util.dagger.UtilModule; +import com.android.systemui.util.kotlin.CoroutinesModule; import com.android.systemui.util.sensors.SensorModule; import com.android.systemui.util.settings.SettingsUtilModule; import com.android.systemui.util.time.SystemClock; @@ -115,6 +116,7 @@ import dagger.Provides; AssistModule.class, BiometricsModule.class, ClockModule.class, + CoroutinesModule.class, DreamModule.class, ControlsModule.class, DemoModeModule.class, diff --git a/packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt b/packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt new file mode 100644 index 000000000000..05d087e232ba --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt @@ -0,0 +1,41 @@ +package com.android.systemui.util.kotlin + +import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.dagger.qualifiers.Application +import com.android.systemui.dagger.qualifiers.Background +import com.android.systemui.dagger.qualifiers.Main +import dagger.Module +import dagger.Provides +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers + +/** Providers for various coroutines-related constructs. */ +@Module +object CoroutinesModule { + @Provides + @SysUISingleton + @Application + fun applicationScope( + @Main dispatcher: CoroutineDispatcher, + ): CoroutineScope = CoroutineScope(dispatcher) + + @Provides + @SysUISingleton + @Main + fun mainDispatcher(): CoroutineDispatcher = Dispatchers.Main.immediate + + /** + * Provide a [CoroutineDispatcher] backed by a thread pool containing at most X threads, where + * X is the number of CPU cores available. + * + * Because there are multiple threads at play, there is no serialization order guarantee. You + * should use a [kotlinx.coroutines.channels.Channel] for serialization if necessary. + * + * @see Dispatchers.Default + */ + @Provides + @SysUISingleton + @Background + fun bgDispatcher(): CoroutineDispatcher = Dispatchers.Default +} |