Loading packages/SystemUI/src/com/android/systemui/lifecycle/RepeatWhenAttached.kt +15 −10 Original line number Diff line number Diff line Loading @@ -24,12 +24,13 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleRegistry import androidx.lifecycle.lifecycleScope import com.android.app.tracing.coroutines.createCoroutineTracingContext import com.android.app.tracing.coroutines.launch import com.android.systemui.util.Assert import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.DisposableHandle import kotlinx.coroutines.launch /** * Runs the given [block] every time the [View] becomes attached (or immediately after calling this Loading Loading @@ -66,7 +67,8 @@ fun View.repeatWhenAttached( // dispatcher to use. We don't want it to run on the Dispatchers.Default thread pool as // default behavior. Instead, we want it to run on the view's UI thread since the user will // presumably want to call view methods that require being called from said UI thread. val lifecycleCoroutineContext = Dispatchers.Main + coroutineContext val lifecycleCoroutineContext = Dispatchers.Main + createCoroutineTracingContext() + coroutineContext var lifecycleOwner: ViewLifecycleOwner? = null val onAttachListener = object : View.OnAttachStateChangeListener { Loading Loading @@ -97,8 +99,7 @@ fun View.repeatWhenAttached( ) } return object : DisposableHandle { override fun dispose() { return DisposableHandle { Assert.isMainThread() lifecycleOwner?.onDestroy() Loading @@ -106,7 +107,6 @@ fun View.repeatWhenAttached( view.removeOnAttachStateChangeListener(onAttachListener) } } } private fun createLifecycleOwnerAndRun( view: View, Loading @@ -115,7 +115,12 @@ private fun createLifecycleOwnerAndRun( ): ViewLifecycleOwner { return ViewLifecycleOwner(view).apply { onCreate() lifecycleScope.launch(coroutineContext) { block(view) } lifecycleScope.launch( "ViewLifecycleOwner(${view::class.java.simpleName})", coroutineContext ) { block(view) } } } Loading packages/SystemUI/src/com/android/systemui/unfold/FoldLightRevealOverlayAnimation.kt +3 −2 Original line number Diff line number Diff line Loading @@ -91,7 +91,8 @@ constructor( ) controller.init() applicationScope.launch(bgHandler.asCoroutineDispatcher()) { val bgDispatcher = bgHandler.asCoroutineDispatcher("@UnfoldBg Handler") applicationScope.launch(bgDispatcher) { powerInteractor.screenPowerState.collect { if (it == ScreenPowerState.SCREEN_ON) { readyCallback = null Loading @@ -99,7 +100,7 @@ constructor( } } applicationScope.launch(bgHandler.asCoroutineDispatcher()) { applicationScope.launch(bgDispatcher) { deviceStateRepository.state .map { it == DeviceStateRepository.DeviceState.FOLDED } .distinctUntilChanged() Loading Loading
packages/SystemUI/src/com/android/systemui/lifecycle/RepeatWhenAttached.kt +15 −10 Original line number Diff line number Diff line Loading @@ -24,12 +24,13 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleRegistry import androidx.lifecycle.lifecycleScope import com.android.app.tracing.coroutines.createCoroutineTracingContext import com.android.app.tracing.coroutines.launch import com.android.systemui.util.Assert import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.DisposableHandle import kotlinx.coroutines.launch /** * Runs the given [block] every time the [View] becomes attached (or immediately after calling this Loading Loading @@ -66,7 +67,8 @@ fun View.repeatWhenAttached( // dispatcher to use. We don't want it to run on the Dispatchers.Default thread pool as // default behavior. Instead, we want it to run on the view's UI thread since the user will // presumably want to call view methods that require being called from said UI thread. val lifecycleCoroutineContext = Dispatchers.Main + coroutineContext val lifecycleCoroutineContext = Dispatchers.Main + createCoroutineTracingContext() + coroutineContext var lifecycleOwner: ViewLifecycleOwner? = null val onAttachListener = object : View.OnAttachStateChangeListener { Loading Loading @@ -97,8 +99,7 @@ fun View.repeatWhenAttached( ) } return object : DisposableHandle { override fun dispose() { return DisposableHandle { Assert.isMainThread() lifecycleOwner?.onDestroy() Loading @@ -106,7 +107,6 @@ fun View.repeatWhenAttached( view.removeOnAttachStateChangeListener(onAttachListener) } } } private fun createLifecycleOwnerAndRun( view: View, Loading @@ -115,7 +115,12 @@ private fun createLifecycleOwnerAndRun( ): ViewLifecycleOwner { return ViewLifecycleOwner(view).apply { onCreate() lifecycleScope.launch(coroutineContext) { block(view) } lifecycleScope.launch( "ViewLifecycleOwner(${view::class.java.simpleName})", coroutineContext ) { block(view) } } } Loading
packages/SystemUI/src/com/android/systemui/unfold/FoldLightRevealOverlayAnimation.kt +3 −2 Original line number Diff line number Diff line Loading @@ -91,7 +91,8 @@ constructor( ) controller.init() applicationScope.launch(bgHandler.asCoroutineDispatcher()) { val bgDispatcher = bgHandler.asCoroutineDispatcher("@UnfoldBg Handler") applicationScope.launch(bgDispatcher) { powerInteractor.screenPowerState.collect { if (it == ScreenPowerState.SCREEN_ON) { readyCallback = null Loading @@ -99,7 +100,7 @@ constructor( } } applicationScope.launch(bgHandler.asCoroutineDispatcher()) { applicationScope.launch(bgDispatcher) { deviceStateRepository.state .map { it == DeviceStateRepository.DeviceState.FOLDED } .distinctUntilChanged() Loading