Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7ee278b authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Merge cherrypicks of ['googleplex-android-review.googlesource.com/26445668',...

Merge cherrypicks of ['googleplex-android-review.googlesource.com/26445668', 'googleplex-android-review.googlesource.com/26443767'] into 24Q2-release.

Change-Id: Id354e60f4c1b6433b88a88aa0d4d47671a32e087
parents 6c09cf04 bf3af7ea
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -334,17 +334,4 @@
    <bool name="config_enable_cellular_on_boot_default">true</bool>
    <java-symbol type="bool" name="config_enable_cellular_on_boot_default" />

    <!-- The network capabilities that would be forced marked as cellular transport regardless it's
         on cellular or satellite-->
    <string-array name="config_force_cellular_transport_capabilities">
        <!-- Added the following three capabilities for now. For the long term solution, the client
             requests satellite network should really include TRANSPORT_SATELLITE in the network
             request. With the following workaround, the clients can continue request network with
             the following capabilities with TRANSPORT_CELLULAR. The network with one of the
             following capabilities would also be marked as cellular. -->
        <item>ims</item>
        <item>eims</item>
        <item>xcap</item>
    </string-array>
    <java-symbol type="array" name="config_force_cellular_transport_capabilities" />
</resources>
+32 −56
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.systemui.unfold

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
import android.annotation.BinderThread
import android.content.Context
@@ -25,6 +23,7 @@ import android.os.Handler
import android.os.SystemProperties
import android.util.Log
import android.view.animation.DecelerateInterpolator
import androidx.core.animation.addListener
import com.android.internal.foldables.FoldLockSettingAvailabilityProvider
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.display.data.repository.DeviceStateRepository
@@ -37,25 +36,17 @@ import com.android.systemui.unfold.FullscreenLightRevealAnimationController.Comp
import com.android.systemui.unfold.dagger.UnfoldBg
import com.android.systemui.util.animation.data.repository.AnimationStatusRepository
import javax.inject.Inject
import kotlin.coroutines.resume
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.android.asCoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withTimeout

@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
class FoldLightRevealOverlayAnimation
@Inject
constructor(
@@ -70,9 +61,6 @@ constructor(

    private val revealProgressValueAnimator: ValueAnimator =
        ValueAnimator.ofFloat(ALPHA_OPAQUE, ALPHA_TRANSPARENT)
    private val areAnimationEnabled: Flow<Boolean>
        get() = animationStatusRepository.areAnimationsEnabled()

    private lateinit var controller: FullscreenLightRevealAnimationController
    @Volatile private var readyCallback: CompletableDeferred<Runnable>? = null

@@ -101,30 +89,33 @@ constructor(

        applicationScope.launch(bgHandler.asCoroutineDispatcher()) {
            deviceStateRepository.state
                .map { it == DeviceStateRepository.DeviceState.FOLDED }
                .map { it != DeviceStateRepository.DeviceState.FOLDED }
                .distinctUntilChanged()
                .flatMapLatest { isFolded ->
                    flow<Nothing> {
                            if (!areAnimationEnabled.first() || !isFolded) {
                                return@flow
                .filter { isUnfolded -> isUnfolded }
                .collect { controller.ensureOverlayRemoved() }
        }

        applicationScope.launch(bgHandler.asCoroutineDispatcher()) {
            deviceStateRepository.state
                .filter {
                    animationStatusRepository.areAnimationsEnabled().first() &&
                        it == DeviceStateRepository.DeviceState.FOLDED
                }
                .collect {
                    try {
                        withTimeout(WAIT_FOR_ANIMATION_TIMEOUT_MS) {
                            readyCallback = CompletableDeferred()
                            val onReady = readyCallback?.await()
                            readyCallback = null
                            controller.addOverlay(ALPHA_OPAQUE, onReady)
                            waitForScreenTurnedOn()
                            }
                            playFoldLightRevealOverlayAnimation()
                        }
                        .catchTimeoutAndLog()
                        .onCompletion {
                            val onReady = readyCallback?.takeIf { it.isCompleted }?.getCompleted()
                            onReady?.run()
                            readyCallback = null
                    } catch (e: TimeoutCancellationException) {
                        Log.e(TAG, "Fold light reveal animation timed out")
                        ensureOverlayRemovedInternal()
                    }
                }
                .collect {}
        }
    }

@@ -137,34 +128,19 @@ constructor(
        powerInteractor.screenPowerState.filter { it == ScreenPowerState.SCREEN_ON }.first()
    }

    private suspend fun playFoldLightRevealOverlayAnimation() {
    private fun ensureOverlayRemovedInternal() {
        revealProgressValueAnimator.cancel()
        controller.ensureOverlayRemoved()
    }

    private fun playFoldLightRevealOverlayAnimation() {
        revealProgressValueAnimator.duration = ANIMATION_DURATION
        revealProgressValueAnimator.interpolator = DecelerateInterpolator()
        revealProgressValueAnimator.addUpdateListener { animation ->
            controller.updateRevealAmount(animation.animatedFraction)
        }
        revealProgressValueAnimator.startAndAwaitCompletion()
    }

    private suspend fun ValueAnimator.startAndAwaitCompletion(): Unit =
        suspendCancellableCoroutine { continuation ->
            val listener =
                object : AnimatorListenerAdapter() {
                    override fun onAnimationEnd(animation: Animator) {
                        continuation.resume(Unit)
                        removeListener(this)
                    }
                }
            addListener(listener)
            continuation.invokeOnCancellation { removeListener(listener) }
            start()
        }

    private fun <T> Flow<T>.catchTimeoutAndLog() = catch { exception ->
        when (exception) {
            is TimeoutCancellationException -> Log.e(TAG, "Fold light reveal animation timed out")
            else -> throw exception
        }
        revealProgressValueAnimator.addListener(onEnd = { controller.ensureOverlayRemoved() })
        revealProgressValueAnimator.start()
    }

    private companion object {