launcher3: Expose coroutine contexts from concurrency module.
UiContext, LightweightContext, ThreadPoolContext, and BackgroundContext are provided from the provided implementations. This is for convenience usage at call sites to quickly create a coroutine scope matched to a particular context. Bug: 407593767 Test: N/A Flag: NONE - new module Change-Id: Id4127db3586e903d83605bac8fd61e33c9a29db5
This commit is contained in:
1 parent
ee79e0f5d2
commit
5c99ccb5b1
6 files changed
+169
No files matched your search
@@ -24,6 +24,10 @@ java_library {
|
||||
"src/com/android/launcher3/concurrent/annotations/LightweightBackground.kt",
|
||||
"src/com/android/launcher3/concurrent/annotations/ThreadPool.kt",
|
||||
"src/com/android/launcher3/concurrent/annotations/Ui.kt",
|
||||
"src/com/android/launcher3/concurrent/annotations/UiContext.kt",
|
||||
"src/com/android/launcher3/concurrent/annotations/BackgroundContext.kt",
|
||||
"src/com/android/launcher3/concurrent/annotations/LightweightBackgroundContext.kt",
|
||||
"src/com/android/launcher3/concurrent/annotations/ThreadPoolContext.kt",
|
||||
],
|
||||
sdk_version: "current",
|
||||
min_sdk_version: min_launcher3_sdk_version,
|
||||
@@ -49,5 +53,6 @@ java_library {
|
||||
"guava",
|
||||
"jsr330",
|
||||
"launcher-executor-qualifiers",
|
||||
"kotlinx-coroutines-android",
|
||||
],
|
||||
}
|
||||
@@ -22,16 +22,24 @@ import com.android.launcher3.concurrent.annotations.LightweightBackgroundPriorit
|
||||
import com.android.launcher3.concurrent.annotations.ThreadPool
|
||||
import com.android.launcher3.concurrent.annotations.Ui
|
||||
|
||||
import com.android.launcher3.concurrent.annotations.UiContext
|
||||
import com.android.launcher3.concurrent.annotations.LightweightBackgroundContext
|
||||
import com.android.launcher3.concurrent.annotations.BackgroundContext
|
||||
import com.android.launcher3.concurrent.annotations.ThreadPoolContext
|
||||
|
||||
import com.google.common.util.concurrent.ListeningExecutorService
|
||||
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.concurrent.ExecutorService
|
||||
import javax.inject.Singleton
|
||||
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
|
||||
/**
|
||||
* Module that stipulates the executors that are usable by common launcher
|
||||
* modules.
|
||||
@@ -127,4 +135,50 @@ interface ExecutorsModule {
|
||||
@Ui listeningExecutorService: ListeningExecutorService
|
||||
): ExecutorService
|
||||
// end UI executors
|
||||
|
||||
// The following methods provide the CoroutineContext for the executors.
|
||||
companion object {
|
||||
|
||||
@Provides
|
||||
@UiContext
|
||||
fun provideUiContext(
|
||||
@Ui executor: Executor
|
||||
): CoroutineContext {
|
||||
return executor.asCoroutineDispatcher()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@LightweightBackgroundContext(LightweightBackgroundPriority.DATA)
|
||||
fun provideDataLightweightContext(
|
||||
@LightweightBackground(LightweightBackgroundPriority.DATA)
|
||||
executor: Executor
|
||||
): CoroutineContext {
|
||||
return executor.asCoroutineDispatcher()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@LightweightBackgroundContext(LightweightBackgroundPriority.UI)
|
||||
fun provideUiLightweightContext(
|
||||
@LightweightBackground(LightweightBackgroundPriority.UI)
|
||||
executor: Executor
|
||||
): CoroutineContext {
|
||||
return executor.asCoroutineDispatcher()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@BackgroundContext
|
||||
fun provideBackgroundContext(
|
||||
@Background executor: Executor
|
||||
): CoroutineContext {
|
||||
return executor.asCoroutineDispatcher()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@ThreadPoolContext
|
||||
fun provideThreadPoolContext(
|
||||
@ThreadPool executor: Executor
|
||||
): CoroutineContext {
|
||||
return executor.asCoroutineDispatcher()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.launcher3.concurrent.annotations
|
||||
|
||||
import javax.inject.Qualifier
|
||||
|
||||
/**
|
||||
* Qualifier for the [kotlinx.coroutines.CoroutineContext] of the [Background]
|
||||
* qualifier.
|
||||
*/
|
||||
@Qualifier
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class BackgroundContext
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.launcher3.concurrent.annotations
|
||||
|
||||
import javax.inject.Qualifier
|
||||
|
||||
/**
|
||||
* Qualifier for the [kotlinx.coroutines.CoroutineContext] of the
|
||||
* [LightweightBackground] qualifier.
|
||||
*/
|
||||
@Qualifier
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class LightweightBackgroundContext(
|
||||
val priority: LightweightBackgroundPriority = LightweightBackgroundPriority.DATA
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.launcher3.concurrent.annotations
|
||||
|
||||
import javax.inject.Qualifier
|
||||
|
||||
/**
|
||||
* Qualifier for the [kotlinx.coroutines.CoroutineContext] of the [ThreadPool]
|
||||
* qualifier.
|
||||
*/
|
||||
@Qualifier
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class ThreadPoolContext
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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.launcher3.concurrent.annotations
|
||||
|
||||
import javax.inject.Qualifier
|
||||
|
||||
/**
|
||||
* Qualifier for the [kotlinx.coroutines.CoroutineContext] of the
|
||||
* [Ui] qualifier.
|
||||
*/
|
||||
@Qualifier
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class UiContext
|
||||
Reference in new issue
Block a user