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

Commit 75dd2c79 authored by Nick Chameyev's avatar Nick Chameyev Committed by Android (Google) Code Review
Browse files

Merge "Temporary hide notifications when folding/unfolding" into main

parents 942ae37a 8ea0f4cd
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -37,6 +37,13 @@ flag {
    bug: "278765923"
}

flag {
    name: "notifications_hide_on_display_switch"
    namespace: "systemui"
    description: "Temporary hides notifications when folding/unfolding to reduce unfold latency"
    bug: "293824309"
}

flag {
    name: "notification_lifetime_extension_refactor"
    namespace: "systemui"
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.systemui.common

import com.android.systemui.common.domain.interactor.ConfigurationInteractor
import com.android.systemui.common.domain.interactor.ConfigurationInteractorImpl
import com.android.systemui.common.ui.data.repository.ConfigurationRepository
import com.android.systemui.common.ui.data.repository.ConfigurationRepositoryImpl
import dagger.Binds
import dagger.Module

@Module
abstract class CommonModule {
    @Binds abstract fun bindRepository(impl: ConfigurationRepositoryImpl): ConfigurationRepository

    @Binds abstract fun bindInteractor(impl: ConfigurationInteractorImpl): ConfigurationInteractor
}
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.systemui.common.domain.interactor

import android.content.res.Configuration
import android.graphics.Rect
import android.view.Surface
import com.android.systemui.common.ui.data.repository.ConfigurationRepository
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map

interface ConfigurationInteractor {
    /**
     * Returns screen size adjusted to rotation, so returned screen sizes are stable across all
     * rotations, could be useful if you need to react to screen resize (e.g. fold/unfold on
     * foldable devices)
     */
    val naturalMaxBounds: Flow<Rect>
}

class ConfigurationInteractorImpl
@Inject
constructor(private val repository: ConfigurationRepository) : ConfigurationInteractor {

    override val naturalMaxBounds: Flow<Rect>
        get() = repository.configurationValues.map { it.naturalScreenBounds }.distinctUntilChanged()

    /**
     * Returns screen size adjusted to rotation, so returned screen size is stable across all
     * rotations
     */
    private val Configuration.naturalScreenBounds: Rect
        get() {
            val rotation = windowConfiguration.displayRotation
            val maxBounds = windowConfiguration.maxBounds
            return if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
                Rect(0, 0, maxBounds.width(), maxBounds.height())
            } else {
                Rect(0, 0, maxBounds.height(), maxBounds.width())
            }
        }
}
+0 −21
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.systemui.common.ui.data

import com.android.systemui.common.ui.data.repository.ConfigurationRepositoryModule
import dagger.Module

@Module(includes = [ConfigurationRepositoryModule::class]) object CommonUiDataLayerModule
+18 −3
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import android.content.res.Configuration
import android.view.DisplayInfo
import androidx.annotation.DimenRes
import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging
import com.android.systemui.common.coroutine.ConflatedCallbackFlow
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.policy.ConfigurationController
@@ -49,6 +49,7 @@ interface ConfigurationRepository {
    val onConfigurationChange: Flow<Unit>

    val scaleForResolution: Flow<Float>
    val configurationValues: Flow<Configuration>

    fun getResolutionScale(): Float

@@ -68,7 +69,7 @@ constructor(
    private val displayInfo = MutableStateFlow(DisplayInfo())

    override val onAnyConfigurationChange: Flow<Unit> =
        ConflatedCallbackFlow.conflatedCallbackFlow {
        conflatedCallbackFlow {
            val callback =
                object : ConfigurationController.ConfigurationListener {
                    override fun onUiModeChanged() {
@@ -92,7 +93,7 @@ constructor(
        }

    override val onConfigurationChange: Flow<Unit> =
        ConflatedCallbackFlow.conflatedCallbackFlow {
        conflatedCallbackFlow {
            val callback =
                object : ConfigurationController.ConfigurationListener {
                    override fun onConfigChanged(newConfig: Configuration) {
@@ -103,6 +104,20 @@ constructor(
            awaitClose { configurationController.removeCallback(callback) }
        }

    override val configurationValues: Flow<Configuration> =
            conflatedCallbackFlow {
                val callback =
                        object : ConfigurationController.ConfigurationListener {
                            override fun onConfigChanged(newConfig: Configuration) {
                                trySend(newConfig)
                            }
                        }

                trySend(context.resources.configuration)
                configurationController.addCallback(callback)
                awaitClose { configurationController.removeCallback(callback) }
            }

    override val scaleForResolution: StateFlow<Float> =
        onConfigurationChange
            .mapLatest { getResolutionScale() }
Loading