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

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

Snap for 13488884 from 6800a830 to 25Q3-release

Change-Id: Ic5bb10eadd28c32bd60c8e95181aab9a68a45aee
parents 24c93732 6800a830
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.app.displaylib

import android.hardware.display.DisplayManager
import android.os.Handler
import android.view.IWindowManager
import dagger.Binds
import dagger.BindsInstance
import dagger.Component
@@ -40,6 +41,7 @@ interface DisplayLibComponent {
    interface Factory {
        fun create(
            @BindsInstance displayManager: DisplayManager,
            @BindsInstance windowManager: IWindowManager,
            @BindsInstance bgHandler: Handler,
            @BindsInstance bgApplicationScope: CoroutineScope,
            @BindsInstance backgroundCoroutineDispatcher: CoroutineDispatcher,
@@ -47,11 +49,17 @@ interface DisplayLibComponent {
    }

    val displayRepository: DisplayRepository
    val displaysWithDecorationsRepository: DisplaysWithDecorationsRepository
}

@Module
interface DisplayLibModule {
    @Binds fun bindDisplayManagerImpl(impl: DisplayRepositoryImpl): DisplayRepository

    @Binds
    fun bindDisplaysWithDecorationsRepositoryImpl(
        impl: DisplaysWithDecorationsRepositoryImpl
    ): DisplaysWithDecorationsRepository
}

/**
@@ -63,10 +71,17 @@ interface DisplayLibModule {
 */
fun createDisplayLibComponent(
    displayManager: DisplayManager,
    windowManager: IWindowManager,
    bgHandler: Handler,
    bgApplicationScope: CoroutineScope,
    backgroundCoroutineDispatcher: CoroutineDispatcher,
): DisplayLibComponent {
    return DaggerDisplayLibComponent.factory()
        .create(displayManager, bgHandler, bgApplicationScope, backgroundCoroutineDispatcher)
        .create(
            displayManager,
            windowManager,
            bgHandler,
            bgApplicationScope,
            backgroundCoroutineDispatcher,
        )
}
+119 −0
Original line number Diff line number Diff line
/*
 * 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.app.displaylib

import android.content.res.Configuration
import android.graphics.Rect
import android.view.IDisplayWindowListener
import android.view.IWindowManager
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.scan
import kotlinx.coroutines.flow.stateIn

/** Provides the displays with decorations. */
interface DisplaysWithDecorationsRepository {
    /** A [StateFlow] that maintains a set of display IDs that should have system decorations. */
    val displayIdsWithSystemDecorations: StateFlow<Set<Int>>
}

@Singleton
class DisplaysWithDecorationsRepositoryImpl
@Inject
constructor(
    private val windowManager: IWindowManager,
    bgApplicationScope: CoroutineScope,
    displayRepository: DisplayRepository,
) : DisplaysWithDecorationsRepository {

    private val decorationEvents: Flow<Event> = callbackFlow {
        val callback =
            object : IDisplayWindowListener.Stub() {
                override fun onDisplayAddSystemDecorations(displayId: Int) {
                    trySend(Event.Add(displayId))
                }

                override fun onDisplayRemoveSystemDecorations(displayId: Int) {
                    trySend(Event.Remove(displayId))
                }

                override fun onDesktopModeEligibleChanged(displayId: Int) {}

                override fun onDisplayAdded(p0: Int) {}

                override fun onDisplayConfigurationChanged(p0: Int, p1: Configuration?) {}

                override fun onDisplayRemoved(p0: Int) {}

                override fun onFixedRotationStarted(p0: Int, p1: Int) {}

                override fun onFixedRotationFinished(p0: Int) {}

                override fun onKeepClearAreasChanged(
                    p0: Int,
                    p1: MutableList<Rect>?,
                    p2: MutableList<Rect>?,
                ) {}
            }
        windowManager.registerDisplayWindowListener(callback)
        awaitClose { windowManager.unregisterDisplayWindowListener(callback) }
    }

    private val initialDisplayIdsWithDecorations: Set<Int> =
        displayRepository.displayIds.value
            .filter { windowManager.shouldShowSystemDecors(it) }
            .toSet()

    /**
     * A [StateFlow] that maintains a set of display IDs that should have system decorations.
     *
     * Updates to the set are triggered by:
     * - Removing displays via [displayRemovalEvent] emissions.
     *
     * The set is initialized with displays that qualify for system decorations based on
     * [WindowManager.shouldShowSystemDecors].
     */
    override val displayIdsWithSystemDecorations: StateFlow<Set<Int>> =
        merge(decorationEvents, displayRepository.displayRemovalEvent.map { Event.Remove(it) })
            .scan(initialDisplayIdsWithDecorations) { displayIds: Set<Int>, event: Event ->
                when (event) {
                    is Event.Add -> displayIds + event.displayId
                    is Event.Remove -> displayIds - event.displayId
                }
            }
            .distinctUntilChanged()
            .stateIn(
                scope = bgApplicationScope,
                started = SharingStarted.WhileSubscribed(),
                initialValue = initialDisplayIdsWithDecorations,
            )

    private sealed class Event(val displayId: Int) {
        class Add(displayId: Int) : Event(displayId)

        class Remove(displayId: Int) : Event(displayId)
    }
}
+12 −12
Original line number Diff line number Diff line
@@ -481,6 +481,13 @@ internal abstract class Computations : CurrentFrameInput, LastFrameState, Static
                                guaranteeState.updatedSpringParameters(lastBreakpoint)
                        }

                        springState =
                            springState.calculateUpdatedState(
                                nextBreakpointCrossTime - lastAnimationTime,
                                springParameters,
                            )
                        lastAnimationTime = nextBreakpointCrossTime

                        val mappingBefore = mappings[segmentIndex]
                        val beforeBreakpoint = mappingBefore.map(nextBreakpoint.position)
                        val mappingAfter = mappings[segmentIndex + directionOffset]
@@ -498,18 +505,7 @@ internal abstract class Computations : CurrentFrameInput, LastFrameState, Static
                                    "  after: $afterBreakpoint (mapping: $mappingAfter)",
                            )
                        }

                        if (!hasJumped && delta != 0f) {
                            hasJumped = true
                            springState = springState.nudge(velocityDelta = directMappedVelocity)
                        }

                        springState =
                            springState.calculateUpdatedState(
                                nextBreakpointCrossTime - lastAnimationTime,
                                springParameters,
                            )
                        lastAnimationTime = nextBreakpointCrossTime
                        hasJumped = hasJumped || delta != 0f

                        if (deltaIsFinite) {
                            springState = springState.nudge(displacementDelta = -delta)
@@ -534,6 +530,10 @@ internal abstract class Computations : CurrentFrameInput, LastFrameState, Static
                            }
                    }

                    if (hasJumped) {
                        springState = springState.nudge(velocityDelta = directMappedVelocity)
                    }

                    val tightened = guarantee.updatedSpringParameters(segment.entryBreakpoint)

                    DiscontinuityAnimation(springState, tightened, lastAnimationTime)
+39 −39
Original line number Diff line number Diff line
@@ -214,25 +214,25 @@
        65,
        60,
        55,
        46.603424,
        42.153717,
        36.203827,
        30.321402,
        25.1608,
        21.651463,
        18.9976,
        17.06427,
        15.6970415,
        14.754084,
        14.11806,
        13.697852,
        13.425745,
        13.253073,
        13.145809,
        13.080716,
        13.042264,
        13.020281,
        13.008238,
        50,
        43.38443,
        36.351646,
        29.990938,
        24.672552,
        21.162388,
        18.574236,
        16.725906,
        15.440355,
        14.566638,
        13.985239,
        13.6060915,
        13.363756,
        13.212058,
        13.11921,
        13.063812,
        13.031747,
        13.013887,
        13.004453,
        13,
        13.75,
        14.5,
@@ -245,26 +245,26 @@
        28.15,
        30.1,
        32.05,
        35.264374,
        44.949898,
        58.693554,
        67.97366,
        76.22729,
        82.931595,
        88.0746,
        91.862114,
        94.56434,
        96.44223,
        97.71758,
        98.56564,
        99.118324,
        99.47132,
        99.69214,
        99.82718,
        99.90767,
        99.954216,
        99.980095,
        99.99374,
        34,
        44.585567,
        58.759357,
        68.21262,
        76.507256,
        83.19111,
        88.2904,
        92.03026,
        94.689606,
        96.532425,
        97.780754,
        98.60885,
        99.14723,
        99.49028,
        99.70432,
        99.83485,
        99.9124,
        99.957054,
        99.98176,
        99.994675,
        100
      ]
    },
+24 −24
Original line number Diff line number Diff line
@@ -133,30 +133,30 @@
        65,
        60,
        55,
        46.603424,
        42.153717,
        36.203827,
        30.321402,
        25.1608,
        20.901463,
        17.4976,
        14.814271,
        12.6970415,
        6.739443,
        1.0775535,
        0.635472,
        0.35061052,
        0.17432979,
        0.07051067,
        0.013341078,
        -0.014990943,
        -0.02636234,
        -0.028412364,
        -0.025858387,
        -0.02147111,
        -0.016770272,
        -0.012503948,
        -0.008967604,
        50,
        43.38443,
        36.351646,
        29.990938,
        24.672552,
        20.412388,
        17.074236,
        14.475905,
        12.440355,
        6.552413,
        0.9461464,
        0.54626375,
        0.29212147,
        0.13740596,
        0.048214816,
        0.0006277391,
        -0.021660766,
        -0.02938723,
        -0.029362231,
        -0.02572238,
        -0.020845085,
        -0.015992891,
        -0.01175198,
        -0.008320414,
        0
      ]
    },
Loading