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

Commit 74407ffe authored by Maryam Dehaini's avatar Maryam Dehaini
Browse files

Update touchable region on appHandle state and status bar bounds

changes

Addresses the following issues:
1. In order for View#setSnapshotBinding to recognize that the
   AppHandlesViewModel#touchableExclusionRegion state has changed, state
   must be accessed from view model during binding rather than passing in
   the state itself.
2. Status bar's touchable region should be updated when the status bar
   bounds change (i.e. device is rotated) even if app handle bounds
   remain the same.
Bug: 412444139
Test: manual testing
Flag: com.android.window.flags.enable_remove_status_bar_input_layer

Change-Id: I33ee13a79979cce7e2569d452459d77ac40ef776
parent 4e94ade0
Loading
Loading
Loading
Loading
+30 −4
Original line number Diff line number Diff line
@@ -19,9 +19,12 @@ package com.android.systemui.statusbar.pipeline.shared.ui.binder
import android.graphics.Rect
import android.graphics.Region
import android.window.DesktopExperienceFlags
import com.android.systemui.common.ui.view.onLayoutChanged
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.lifecycle.setSnapshotBinding
import com.android.systemui.statusbar.layout.ui.viewmodel.AppHandlesViewModel
import com.android.systemui.statusbar.phone.PhoneStatusBarView
import kotlinx.coroutines.DisposableHandle
import kotlinx.coroutines.awaitCancellation

/** Binds a [PhoneStatusBarView] to [AppHandlesViewModel]'s touch exclusion region. */
@@ -31,16 +34,39 @@ object HomeStatusBarTouchExclusionRegionBinder {
     * Reports the updated touchable region to the [PhoneStatusBarView] calculated from the touch
     * exclusion region provided.
     */
    fun bind(view: PhoneStatusBarView, touchExclusionRegion: Region) {
    fun bind(view: PhoneStatusBarView, appHandlesViewModel: AppHandlesViewModel): DisposableHandle {
        if (!DesktopExperienceFlags.ENABLE_REMOVE_STATUS_BAR_INPUT_LAYER.isTrue) {
            return
            return DisposableHandle {}
        }

        // Update touchable regions when touchableExclusionRegion changes
        view.repeatWhenAttached {
            view.setSnapshotBinding {
                view.updateTouchableRegion(calculateTouchableRegion(view, touchExclusionRegion))
                view.updateTouchableRegion(
                    calculateTouchableRegion(view, appHandlesViewModel.touchableExclusionRegion)
                )
            }
            awaitCancellation()
        }

        // Update touchable region when status bar bounds change
        return view.onLayoutChanged {
            _,
            left,
            top,
            right,
            bottom,
            oldLeft,
            oldTop,
            oldRight,
            oldBottom ->
            if (top == oldTop && left == oldLeft && right == oldRight && bottom == oldBottom) {
                return@onLayoutChanged
            }
            view.updateTouchableRegion(
                calculateTouchableRegion(view, appHandlesViewModel.touchableExclusionRegion)
            )
        }
    }

    private fun calculateTouchableRegion(
@@ -52,7 +78,7 @@ object HomeStatusBarTouchExclusionRegionBinder {
        val touchableRegion =
            Region.obtain().apply {
                set(outBounds)
                op(touchExclusionRegion, android.graphics.Region.Op.DIFFERENCE)
                op(touchExclusionRegion, Region.Op.DIFFERENCE)
            }
        return touchableRegion
    }
+8 −4
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ import com.android.systemui.statusbar.systemstatusicons.ui.viewmodel.SystemStatu
import com.android.systemui.statusbar.ui.viewmodel.StatusBarRegionSamplingViewModel
import javax.inject.Inject
import javax.inject.Named
import kotlinx.coroutines.DisposableHandle
import kotlinx.coroutines.awaitCancellation

/** Factory to simplify the dependency management for [StatusBarRoot] */
@@ -204,6 +205,7 @@ fun StatusBarRoot(
        rememberViewModel("AppHandleBounds") {
            statusBarViewModel.appHandlesViewModelFactory.create(displayId)
        }
    lateinit var touchableExclusionRegionDisposableHandle: DisposableHandle

    // Let the DesktopStatusBar compose all the UI if [isDesktopStatusBarEnabled] is true.
    if (StatusBarForDesktop.isEnabled && statusBarViewModel.isDesktopStatusBarEnabled) {
@@ -228,9 +230,10 @@ fun StatusBarRoot(
                )
            }

            touchableExclusionRegionDisposableHandle =
                HomeStatusBarTouchExclusionRegionBinder.bind(
                    phoneStatusBarView,
                appHandlesViewModel.touchableExclusionRegion,
                    appHandlesViewModel,
                )

            if (StatusBarChipsModernization.isEnabled) {
@@ -351,6 +354,7 @@ fun StatusBarRoot(
            phoneStatusBarView
        },
        modifier = modifier,
        onRelease = { touchableExclusionRegionDisposableHandle.dispose() },
    )
}