Merge "Clean up launched flag "privacy_dot_unfold_wrong_corner_fix"" into main
diff --git a/packages/SystemUI/aconfig/systemui.aconfig b/packages/SystemUI/aconfig/systemui.aconfig
index 197dc6a..3767a27 100644
--- a/packages/SystemUI/aconfig/systemui.aconfig
+++ b/packages/SystemUI/aconfig/systemui.aconfig
@@ -1048,16 +1048,6 @@
 }
 
 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"
   description: "Adds a check that the caller can access the content URI of an icon in the shortcut helper."
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/events/PrivacyDotViewControllerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/events/PrivacyDotViewControllerTest.kt
index f126432..663c341 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/events/PrivacyDotViewControllerTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/events/PrivacyDotViewControllerTest.kt
@@ -18,8 +18,6 @@
 
 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
@@ -28,7 +26,6 @@
 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
@@ -297,8 +294,7 @@
     }
 
     @Test
-    @EnableFlags(Flags.FLAG_PRIVACY_DOT_UNFOLD_WRONG_CORNER_FIX)
-    fun initialize_newViews_fixFlagEnabled_gravityIsUpdated() {
+    fun initialize_newViews_gravityIsUpdated() {
         val newTopLeftView = initDotView()
         val newTopRightView = initDotView()
         val newBottomLeftView = initDotView()
@@ -318,28 +314,6 @@
             .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)
     }
@@ -347,7 +321,7 @@
     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.layoutParams = FrameLayout.LayoutParams(/* width= */ 0, /* height= */ 0)
             it.addView(privacyDot)
         }
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/PrivacyDotViewController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/PrivacyDotViewController.kt
index 9eb9ed5..2930de2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/events/PrivacyDotViewController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/PrivacyDotViewController.kt
@@ -26,7 +26,6 @@
 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
@@ -45,10 +44,10 @@
 import com.android.systemui.util.leak.RotationUtils.ROTATION_SEASCAPE
 import com.android.systemui.util.leak.RotationUtils.ROTATION_UPSIDE_DOWN
 import com.android.systemui.util.leak.RotationUtils.Rotation
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.launch
 import java.util.concurrent.Executor
 import javax.inject.Inject
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.launch
 
 /**
  * Understands how to keep the persistent privacy dot in the corner of the screen in
@@ -61,12 +60,13 @@
  * Views will match the status bar top padding and status bar height so that the dot can appear to
  * reside directly after the status bar system contents (basically after the battery).
  *
- * NOTE: any operation that modifies views directly must run on the provided executor, because
- * these views are owned by ScreenDecorations and it runs in its own thread
+ * NOTE: any operation that modifies views directly must run on the provided executor, because these
+ * views are owned by ScreenDecorations and it runs in its own thread
  */
-
 @SysUISingleton
-open class PrivacyDotViewController @Inject constructor(
+open class PrivacyDotViewController
+@Inject
+constructor(
     @Main private val mainExecutor: Executor,
     @Application scope: CoroutineScope,
     private val stateController: StatusBarStateController,
@@ -90,6 +90,7 @@
             field = value
             scheduleUpdate()
         }
+
     private val lock = Object()
     private var cancelRunnable: Runnable? = null
 
@@ -106,46 +107,48 @@
         get() = field
 
     init {
-        contentInsetsProvider.addCallback(object : StatusBarContentInsetsChangedListener {
-            override fun onStatusBarContentInsetsChanged() {
-                dlog("onStatusBarContentInsetsChanged: ")
-                setNewLayoutRects()
+        contentInsetsProvider.addCallback(
+            object : StatusBarContentInsetsChangedListener {
+                override fun onStatusBarContentInsetsChanged() {
+                    dlog("onStatusBarContentInsetsChanged: ")
+                    setNewLayoutRects()
+                }
             }
-        })
+        )
 
-        configurationController.addCallback(object : ConfigurationController.ConfigurationListener {
-            override fun onLayoutDirectionChanged(isRtl: Boolean) {
-                uiExecutor?.execute {
-                    // If rtl changed, hide all dotes until the next state resolves
-                    setCornerVisibilities(View.INVISIBLE)
+        configurationController.addCallback(
+            object : ConfigurationController.ConfigurationListener {
+                override fun onLayoutDirectionChanged(isRtl: Boolean) {
+                    uiExecutor?.execute {
+                        // If rtl changed, hide all dotes until the next state resolves
+                        setCornerVisibilities(View.INVISIBLE)
 
-                    synchronized(this) {
-                        val corner = selectDesignatedCorner(nextViewState.rotation, isRtl)
-                        nextViewState = nextViewState.copy(
-                                layoutRtl = isRtl,
-                                designatedCorner = corner
-                        )
+                        synchronized(this) {
+                            val corner = selectDesignatedCorner(nextViewState.rotation, isRtl)
+                            nextViewState =
+                                nextViewState.copy(layoutRtl = isRtl, designatedCorner = corner)
+                        }
                     }
                 }
             }
-        })
+        )
 
-        stateController.addCallback(object : StatusBarStateController.StateListener {
-            override fun onExpandedChanged(isExpanded: Boolean) {
-                updateStatusBarState()
-            }
+        stateController.addCallback(
+            object : StatusBarStateController.StateListener {
+                override fun onExpandedChanged(isExpanded: Boolean) {
+                    updateStatusBarState()
+                }
 
-            override fun onStateChanged(newState: Int) {
-                updateStatusBarState()
+                override fun onStateChanged(newState: Int) {
+                    updateStatusBarState()
+                }
             }
-        })
+        )
 
         scope.launch {
             shadeInteractor?.isQsExpanded?.collect { isQsExpanded ->
                 dlog("setQsExpanded $isQsExpanded")
-                synchronized(lock) {
-                    nextViewState = nextViewState.copy(qsExpanded = isQsExpanded)
-                }
+                synchronized(lock) { nextViewState = nextViewState.copy(qsExpanded = isQsExpanded) }
             }
         }
     }
@@ -179,11 +182,13 @@
         val paddingTop = contentInsetsProvider.getStatusBarPaddingTop(rot)
 
         synchronized(lock) {
-            nextViewState = nextViewState.copy(
+            nextViewState =
+                nextViewState.copy(
                     rotation = rot,
                     paddingTop = paddingTop,
                     designatedCorner = newCorner,
-                    cornerIndex = index)
+                    cornerIndex = index
+                )
         }
     }
 
@@ -192,14 +197,14 @@
         dot.clearAnimation()
         if (animate) {
             dot.animate()
-                    .setDuration(DURATION)
-                    .setInterpolator(Interpolators.ALPHA_OUT)
-                    .alpha(0f)
-                    .withEndAction {
-                        dot.visibility = View.INVISIBLE
-                        showingListener?.onPrivacyDotHidden(dot)
-                    }
-                    .start()
+                .setDuration(DURATION)
+                .setInterpolator(Interpolators.ALPHA_OUT)
+                .alpha(0f)
+                .withEndAction {
+                    dot.visibility = View.INVISIBLE
+                    showingListener?.onPrivacyDotHidden(dot)
+                }
+                .start()
         } else {
             dot.visibility = View.INVISIBLE
             showingListener?.onPrivacyDotHidden(dot)
@@ -213,10 +218,10 @@
             dot.visibility = View.VISIBLE
             dot.alpha = 0f
             dot.animate()
-                    .alpha(1f)
-                    .setDuration(DURATION)
-                    .setInterpolator(Interpolators.ALPHA_IN)
-                    .start()
+                .alpha(1f)
+                .setDuration(DURATION)
+                .setInterpolator(Interpolators.ALPHA_IN)
+                .start()
         } else {
             dot.visibility = View.VISIBLE
             dot.alpha = 1f
@@ -241,9 +246,9 @@
             }
 
             // Set the dot's view gravity to hug the status bar
-            (corner.requireViewById<View>(R.id.privacy_dot)
-                    .layoutParams as FrameLayout.LayoutParams)
-                        .gravity = rotatedCorner.innerGravity()
+            (corner.requireViewById<View>(R.id.privacy_dot).layoutParams
+                    as FrameLayout.LayoutParams)
+                .gravity = rotatedCorner.innerGravity()
         }
     }
 
@@ -353,10 +358,7 @@
                 clearAnimation()
                 visibility = View.VISIBLE
                 alpha = 0f
-                animate()
-                    .alpha(1.0f)
-                    .setDuration(300)
-                    .start()
+                animate().alpha(1.0f).setDuration(300).start()
             }
         }
     }
@@ -405,15 +407,21 @@
 
     private fun widthForCorner(corner: Int, left: Int, right: Int): Int {
         return when (corner) {
-            TOP_LEFT, BOTTOM_LEFT -> left
-            TOP_RIGHT, BOTTOM_RIGHT -> right
+            TOP_LEFT,
+            BOTTOM_LEFT -> left
+            TOP_RIGHT,
+            BOTTOM_RIGHT -> right
             else -> throw IllegalArgumentException("Unknown corner")
         }
     }
 
     fun initialize(topLeft: View, topRight: View, bottomLeft: View, bottomRight: View) {
-        if (this::tl.isInitialized && this::tr.isInitialized &&
-                this::bl.isInitialized && this::br.isInitialized) {
+        if (
+            this::tl.isInitialized &&
+                this::tr.isInitialized &&
+                this::bl.isInitialized &&
+                this::br.isInitialized
+        ) {
             if (tl == topLeft && tr == topRight && bl == bottomLeft && br == bottomRight) {
                 return
             }
@@ -430,19 +438,17 @@
 
         val index = dc.cornerIndex()
 
-        mainExecutor.execute {
-            animationScheduler.addCallback(systemStatusAnimationCallback)
-        }
+        mainExecutor.execute { animationScheduler.addCallback(systemStatusAnimationCallback) }
 
         val left = contentInsetsProvider.getStatusBarContentAreaForRotation(ROTATION_SEASCAPE)
         val top = contentInsetsProvider.getStatusBarContentAreaForRotation(ROTATION_NONE)
         val right = contentInsetsProvider.getStatusBarContentAreaForRotation(ROTATION_LANDSCAPE)
-        val bottom = contentInsetsProvider
-                .getStatusBarContentAreaForRotation(ROTATION_UPSIDE_DOWN)
+        val bottom = contentInsetsProvider.getStatusBarContentAreaForRotation(ROTATION_UPSIDE_DOWN)
         val paddingTop = contentInsetsProvider.getStatusBarPaddingTop()
 
         synchronized(lock) {
-            nextViewState = nextViewState.copy(
+            nextViewState =
+                nextViewState.copy(
                     viewInitialized = true,
                     designatedCorner = dc,
                     cornerIndex = index,
@@ -452,14 +458,12 @@
                     upsideDownRect = bottom,
                     paddingTop = paddingTop,
                     layoutRtl = rtl
-            )
+                )
         }
     }
 
     private fun updateStatusBarState() {
-        synchronized(lock) {
-            nextViewState = nextViewState.copy(shadeExpanded = isShadeInQs())
-        }
+        synchronized(lock) { nextViewState = nextViewState.copy(shadeExpanded = isShadeInQs()) }
     }
 
     /**
@@ -469,16 +473,14 @@
     @GuardedBy("lock")
     private fun isShadeInQs(): Boolean {
         return (stateController.isExpanded && stateController.state == SHADE) ||
-                (stateController.state == SHADE_LOCKED)
+            (stateController.state == SHADE_LOCKED)
     }
 
     private fun scheduleUpdate() {
         dlog("scheduleUpdate: ")
 
         cancelRunnable?.run()
-        cancelRunnable = uiExecutor?.executeDelayed({
-            processNextViewState()
-        }, 100)
+        cancelRunnable = uiExecutor?.executeDelayed({ processNextViewState() }, 100)
     }
 
     @UiThread
@@ -486,9 +488,7 @@
         dlog("processNextViewState: ")
 
         val newState: ViewState
-        synchronized(lock) {
-            newState = nextViewState.copy()
-        }
+        synchronized(lock) { newState = nextViewState.copy() }
 
         resolveState(newState)
     }
@@ -508,7 +508,7 @@
 
         val designatedCornerChanged = state.designatedCorner != currentViewState.designatedCorner
         val rotationChanged = state.rotation != currentViewState.rotation
-        if (rotationChanged || (designatedCornerChanged && privacyDotUnfoldWrongCornerFix())) {
+        if (rotationChanged || designatedCornerChanged) {
             // A rotation has started, hide the views to avoid flicker
             updateRotations(state.rotation, state.paddingTop)
         }
@@ -545,27 +545,29 @@
     }
 
     private val systemStatusAnimationCallback: SystemStatusAnimationCallback =
-            object : SystemStatusAnimationCallback {
-        override fun onSystemStatusAnimationTransitionToPersistentDot(
-            contentDescr: String?
-        ): Animator? {
-            synchronized(lock) {
-                nextViewState = nextViewState.copy(
-                        systemPrivacyEventIsActive = true,
-                        contentDescription = contentDescr)
+        object : SystemStatusAnimationCallback {
+            override fun onSystemStatusAnimationTransitionToPersistentDot(
+                contentDescr: String?
+            ): Animator? {
+                synchronized(lock) {
+                    nextViewState =
+                        nextViewState.copy(
+                            systemPrivacyEventIsActive = true,
+                            contentDescription = contentDescr
+                        )
+                }
+
+                return null
             }
 
-            return null
-        }
+            override fun onHidePersistentDot(): Animator? {
+                synchronized(lock) {
+                    nextViewState = nextViewState.copy(systemPrivacyEventIsActive = false)
+                }
 
-        override fun onHidePersistentDot(): Animator? {
-            synchronized(lock) {
-                nextViewState = nextViewState.copy(systemPrivacyEventIsActive = false)
+                return null
             }
-
-            return null
         }
-    }
 
     private fun View?.cornerIndex(): Int {
         if (this != null) {
@@ -579,8 +581,7 @@
         val left = contentInsetsProvider.getStatusBarContentAreaForRotation(ROTATION_SEASCAPE)
         val top = contentInsetsProvider.getStatusBarContentAreaForRotation(ROTATION_NONE)
         val right = contentInsetsProvider.getStatusBarContentAreaForRotation(ROTATION_LANDSCAPE)
-        val bottom = contentInsetsProvider
-                .getStatusBarContentAreaForRotation(ROTATION_UPSIDE_DOWN)
+        val bottom = contentInsetsProvider.getStatusBarContentAreaForRotation(ROTATION_UPSIDE_DOWN)
 
         return listOf(left, top, right, bottom)
     }
@@ -589,17 +590,19 @@
         val rects = getLayoutRects()
 
         synchronized(lock) {
-            nextViewState = nextViewState.copy(
+            nextViewState =
+                nextViewState.copy(
                     seascapeRect = rects[0],
                     portraitRect = rects[1],
                     landscapeRect = rects[2],
                     upsideDownRect = rects[3]
-            )
+                )
         }
     }
 
     interface ShowingListener {
         fun onPrivacyDotShown(v: View?)
+
         fun onPrivacyDotHidden(v: View?)
     }
 }
@@ -647,22 +650,18 @@
 
 data class ViewState(
     val viewInitialized: Boolean = false,
-
     val systemPrivacyEventIsActive: Boolean = false,
     val shadeExpanded: Boolean = false,
     val qsExpanded: Boolean = false,
-
     val portraitRect: Rect? = null,
     val landscapeRect: Rect? = null,
     val upsideDownRect: Rect? = null,
     val seascapeRect: Rect? = null,
     val layoutRtl: Boolean = false,
-
     val rotation: Int = 0,
     val paddingTop: Int = 0,
     val cornerIndex: Int = -1,
     val designatedCorner: View? = null,
-
     val contentDescription: String? = null
 ) {
     fun shouldShowDot(): Boolean {
@@ -671,11 +670,11 @@
 
     fun needsLayout(other: ViewState): Boolean {
         return rotation != other.rotation ||
-                layoutRtl != other.layoutRtl ||
-                portraitRect != other.portraitRect ||
-                landscapeRect != other.landscapeRect ||
-                upsideDownRect != other.upsideDownRect ||
-                seascapeRect != other.seascapeRect
+            layoutRtl != other.layoutRtl ||
+            portraitRect != other.portraitRect ||
+            landscapeRect != other.landscapeRect ||
+            upsideDownRect != other.upsideDownRect ||
+            seascapeRect != other.seascapeRect
     }
 
     fun contentRectForRotation(@Rotation rot: Int): Rect {