diff options
| -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 +} |