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

Commit 352ab97e authored by Chris Göllner's avatar Chris Göllner
Browse files

Status Bar - Fix privacy dot being in the wrong corner after fold/unfold

When unfolding and folding, the PrivacyDotViewController will be reused
and #initialize will be called with new views.

For the views to be in the correct position, their gravity has to be
set.
The fix is to make sure the gravity is updated when we have new views.

Fixes: 339335643
Test: Unit tests in this CL
Test: Manually
Flag: com.android.systemui.privacy_dot_unfold_wrong_corner_fix
Change-Id: Id37da91b04cf5fa956f3d6d7f254e9c2634a2563
parent f008fd09
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -983,6 +983,16 @@ flag {
  }
}

flag {
  namespace: "systemui"
  name: "privacy_dot_unfold_wrong_corner_fix"
  description: "Fixes an issue where the privacy dot is at the wrong corner after unfolding/folding."
  bug: "339335643"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "validate_keyboard_shortcut_helper_icon_uri"
  namespace: "systemui"
+54 −2
Original line number Diff line number Diff line
@@ -18,14 +18,19 @@ package com.android.systemui.statusbar.events

import android.graphics.Point
import android.graphics.Rect
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.testing.TestableLooper.RunWithLooper
import android.view.Display
import android.view.DisplayAdjustments
import android.view.View
import android.widget.FrameLayout
import android.widget.FrameLayout.LayoutParams.UNSPECIFIED_GRAVITY
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.res.R
import com.android.systemui.statusbar.FakeStatusBarStateController
import com.android.systemui.statusbar.phone.StatusBarContentInsetsProvider
import com.android.systemui.statusbar.policy.FakeConfigurationController
@@ -291,13 +296,60 @@ class PrivacyDotViewControllerTest : SysuiTestCase() {
        assertThat(controller.currentViewState.designatedCorner).isEqualTo(bottomRightView)
    }

    @Test
    @EnableFlags(Flags.FLAG_PRIVACY_DOT_UNFOLD_WRONG_CORNER_FIX)
    fun initialize_newViews_fixFlagEnabled_gravityIsUpdated() {
        val newTopLeftView = initDotView()
        val newTopRightView = initDotView()
        val newBottomLeftView = initDotView()
        val newBottomRightView = initDotView()
        setRotation(ROTATION_LANDSCAPE) // Bottom right used in landscape

        val controller = createAndInitializeController()
        // Re-init with different views, but same rotation
        controller.initialize(
            newTopLeftView,
            newTopRightView,
            newBottomLeftView,
            newBottomRightView
        )

        assertThat((newBottomRightView.layoutParams as FrameLayout.LayoutParams).gravity)
            .isNotEqualTo(UNSPECIFIED_GRAVITY)
    }

    @Test
    @DisableFlags(Flags.FLAG_PRIVACY_DOT_UNFOLD_WRONG_CORNER_FIX)
    fun initialize_newViews_fixFlagDisabled_gravityIsNotUpdated() {
        val newTopLeftView = initDotView()
        val newTopRightView = initDotView()
        val newBottomLeftView = initDotView()
        val newBottomRightView = initDotView()
        setRotation(ROTATION_LANDSCAPE) // Bottom right used in landscape

        val controller = createAndInitializeController()
        // Re-init with different views, but same rotation
        controller.initialize(
            newTopLeftView,
            newTopRightView,
            newBottomLeftView,
            newBottomRightView
        )

        assertThat((newBottomRightView.layoutParams as FrameLayout.LayoutParams).gravity)
            .isEqualTo(UNSPECIFIED_GRAVITY)
    }

    private fun setRotation(rotation: Int) {
        whenever(mockDisplay.rotation).thenReturn(rotation)
    }

    private fun initDotView(): View =
        View(context).also {
    private fun initDotView(): View {
        val privacyDot = View(context).also { it.id = R.id.privacy_dot }
        return FrameLayout(context).also {
            it.layoutParams = FrameLayout.LayoutParams(/* width = */ 0, /* height = */ 0)
            it.addView(privacyDot)
        }
    }

    private fun enableRtl() {
+5 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.widget.FrameLayout
import androidx.core.animation.Animator
import com.android.app.animation.Interpolators
import com.android.internal.annotations.GuardedBy
import com.android.systemui.Flags.privacyDotUnfoldWrongCornerFix
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Main
@@ -505,7 +506,9 @@ open class PrivacyDotViewController @Inject constructor(
            return
        }

        if (state.rotation != currentViewState.rotation) {
        val designatedCornerChanged = state.designatedCorner != currentViewState.designatedCorner
        val rotationChanged = state.rotation != currentViewState.rotation
        if (rotationChanged || (designatedCornerChanged && privacyDotUnfoldWrongCornerFix())) {
            // A rotation has started, hide the views to avoid flicker
            updateRotations(state.rotation, state.paddingTop)
        }
@@ -515,7 +518,7 @@ open class PrivacyDotViewController @Inject constructor(
            views.forEach { it.requestLayout() }
        }

        if (state.designatedCorner != currentViewState.designatedCorner) {
        if (designatedCornerChanged) {
            currentViewState.designatedCorner?.contentDescription = null
            state.designatedCorner?.contentDescription = state.contentDescription