Merge "job: make charging constraint update criteria customizable" into main
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java
index 9d88af9..451a71b 100644
--- a/core/java/android/view/SurfaceControl.java
+++ b/core/java/android/view/SurfaceControl.java
@@ -2671,7 +2671,7 @@
          *
          * @param minAlpha               The min alpha the {@link SurfaceControl} is required to
          *                               have to be considered inside the threshold.
-         * @param minFractionRendered    The min fraction of the SurfaceControl that was resented
+         * @param minFractionRendered    The min fraction of the SurfaceControl that was presented
          *                               to the user to be considered inside the threshold.
          * @param stabilityRequirementMs The time in milliseconds required for the
          *                               {@link SurfaceControl} to be in the threshold.
diff --git a/libs/WindowManager/Shell/tests/flicker/pip/csuiteDefaultTemplate.xml b/libs/WindowManager/Shell/tests/flicker/pip/csuiteDefaultTemplate.xml
index ca182fa..6df6539 100644
--- a/libs/WindowManager/Shell/tests/flicker/pip/csuiteDefaultTemplate.xml
+++ b/libs/WindowManager/Shell/tests/flicker/pip/csuiteDefaultTemplate.xml
@@ -57,6 +57,17 @@
         <option name="test-file-name" value="WMShellFlickerTestsPipAppsCSuite.apk"/>
         <option name="test-file-name" value="FlickerTestApp.apk"/>
     </target_preparer>
+
+    <!-- Needed for installing apk's from Play Store -->
+    <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">
+        <option name="aapt-version" value="AAPT2"/>
+        <option name="throw-if-not-found" value="false"/>
+        <option name="install-arg" value="-d"/>
+        <option name="install-arg" value="-g"/>
+        <option name="install-arg" value="-r"/>
+        <option name="test-file-name" value="pstash://com.netflix.mediaclient"/>
+    </target_preparer>
+
     <!-- Enable mocking GPS location by the test app -->
     <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
         <option name="run-command"
@@ -94,28 +105,8 @@
     <metrics_collector class="com.android.tradefed.device.metric.FilePullerLogCollector">
         <option name="pull-pattern-keys" value="perfetto_file_path"/>
         <option name="directory-keys"
-                value="/data/user/0/com.android.wm.shell.flicker/files"/>
-        <option name="directory-keys"
-                value="/data/user/0/com.android.wm.shell.flicker.bubbles/files"/>
-        <option name="directory-keys"
-                value="/data/user/0/com.android.wm.shell.flicker.pip/files"/>
-        <option name="directory-keys"
                 value="/data/user/0/com.android.wm.shell.flicker.pip.apps/files"/>
-        <option name="directory-keys"
-                value="/data/user/0/com.android.wm.shell.flicker.splitscreen/files"/>
-        <option name="directory-keys"
-                value="/data/user/0/com.android.wm.shell.flicker.service/files"/>
         <option name="collect-on-run-ended-only" value="true"/>
         <option name="clean-up" value="true"/>
     </metrics_collector>
-
-    <!-- Needed for installing apk's from Play Store -->
-    <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">
-        <option name="aapt-version" value="AAPT2"/>
-        <option name="throw-if-not-found" value="false"/>
-        <option name="install-arg" value="-d"/>
-        <option name="install-arg" value="-g"/>
-        <option name="install-arg" value="-r"/>
-        <option name="test-file-name" value="pstash://com.netflix.mediaclient"/>
-    </target_preparer>
 </configuration>
diff --git a/packages/SystemUI/aconfig/systemui.aconfig b/packages/SystemUI/aconfig/systemui.aconfig
index a9027de..069ba6c 100644
--- a/packages/SystemUI/aconfig/systemui.aconfig
+++ b/packages/SystemUI/aconfig/systemui.aconfig
@@ -53,6 +53,14 @@
 }
 
 flag {
+    name: "keyguard_bottom_area_refactor"
+    namespace: "systemui"
+    description: "Bottom area of keyguard refactor move into KeyguardRootView. Includes "
+        "lock icon and others."
+    bug: "290652751"
+}
+
+flag {
     name: "visual_interruptions_refactor"
     namespace: "systemui"
     description: "Enables the refactored version of the code to decide when notifications "
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/BouncerScene.kt b/packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/BouncerScene.kt
index f2b7b32..56970d7 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/BouncerScene.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/bouncer/ui/composable/BouncerScene.kt
@@ -19,6 +19,7 @@
 import android.app.AlertDialog
 import android.app.Dialog
 import android.content.DialogInterface
+import android.content.res.Configuration
 import androidx.compose.animation.Crossfade
 import androidx.compose.animation.core.animateFloatAsState
 import androidx.compose.animation.core.snap
@@ -50,6 +51,7 @@
 import androidx.compose.material3.Icon
 import androidx.compose.material3.MaterialTheme
 import androidx.compose.material3.Text
+import androidx.compose.material3.windowsizeclass.WindowHeightSizeClass
 import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.collectAsState
@@ -63,6 +65,7 @@
 import androidx.compose.ui.graphics.asImageBitmap
 import androidx.compose.ui.graphics.graphicsLayer
 import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.platform.LocalConfiguration
 import androidx.compose.ui.platform.LocalContext
 import androidx.compose.ui.platform.LocalLayoutDirection
 import androidx.compose.ui.res.stringResource
@@ -136,7 +139,7 @@
     modifier: Modifier = Modifier,
 ) {
     val backgroundColor = MaterialTheme.colorScheme.surface
-    val windowSizeClass = LocalWindowSizeClass.current
+    val layout = calculateLayout()
 
     Box(modifier) {
         Canvas(Modifier.element(Bouncer.Elements.Background).fillMaxSize()) {
@@ -146,22 +149,30 @@
         val childModifier = Modifier.element(Bouncer.Elements.Content).fillMaxSize()
         val isFullScreenUserSwitcherEnabled = viewModel.isUserSwitcherVisible
 
-        when {
-            windowSizeClass.widthSizeClass == WindowWidthSizeClass.Expanded ->
+        when (layout) {
+            Layout.STANDARD ->
+                Bouncer(
+                    viewModel = viewModel,
+                    dialogFactory = dialogFactory,
+                    isUserInputAreaVisible = true,
+                    modifier = childModifier,
+                )
+            Layout.SIDE_BY_SIDE ->
                 SideBySide(
                     viewModel = viewModel,
                     dialogFactory = dialogFactory,
+                    isUserSwitcherVisible = isFullScreenUserSwitcherEnabled,
                     modifier = childModifier,
                 )
-            isFullScreenUserSwitcherEnabled &&
-                windowSizeClass.widthSizeClass == WindowWidthSizeClass.Medium ->
+            Layout.STACKED ->
                 Stacked(
                     viewModel = viewModel,
                     dialogFactory = dialogFactory,
+                    isUserSwitcherVisible = isFullScreenUserSwitcherEnabled,
                     modifier = childModifier,
                 )
-            else ->
-                Bouncer(
+            Layout.SPLIT ->
+                Split(
                     viewModel = viewModel,
                     dialogFactory = dialogFactory,
                     modifier = childModifier,
@@ -178,11 +189,10 @@
 private fun Bouncer(
     viewModel: BouncerViewModel,
     dialogFactory: BouncerSceneDialogFactory,
+    isUserInputAreaVisible: Boolean,
     modifier: Modifier = Modifier,
 ) {
     val message: BouncerViewModel.MessageViewModel by viewModel.message.collectAsState()
-    val authMethodViewModel: AuthMethodBouncerViewModel? by
-        viewModel.authMethodViewModel.collectAsState()
     val dialogMessage: String? by viewModel.throttlingDialogMessage.collectAsState()
     var dialog: Dialog? by remember { mutableStateOf(null) }
 
@@ -204,25 +214,11 @@
         }
 
         Box(Modifier.weight(1f)) {
-            when (val nonNullViewModel = authMethodViewModel) {
-                is PinBouncerViewModel ->
-                    PinBouncer(
-                        viewModel = nonNullViewModel,
-                        modifier = Modifier.align(Alignment.Center),
-                    )
-                is PasswordBouncerViewModel ->
-                    PasswordBouncer(
-                        viewModel = nonNullViewModel,
-                        modifier = Modifier.align(Alignment.Center),
-                    )
-                is PatternBouncerViewModel ->
-                    PatternBouncer(
-                        viewModel = nonNullViewModel,
-                        modifier =
-                            Modifier.aspectRatio(1f, matchHeightConstraintsFirst = false)
-                                .align(Alignment.BottomCenter),
-                    )
-                else -> Unit
+            if (isUserInputAreaVisible) {
+                UserInputArea(
+                    viewModel = viewModel,
+                    modifier = Modifier.align(Alignment.Center),
+                )
             }
         }
 
@@ -265,6 +261,40 @@
     }
 }
 
+/**
+ * Renders the user input area, where the user interacts with the UI to enter their credentials.
+ *
+ * For example, this can be the pattern input area, the password text box, or pin pad.
+ */
+@Composable
+private fun UserInputArea(
+    viewModel: BouncerViewModel,
+    modifier: Modifier = Modifier,
+) {
+    val authMethodViewModel: AuthMethodBouncerViewModel? by
+        viewModel.authMethodViewModel.collectAsState()
+
+    when (val nonNullViewModel = authMethodViewModel) {
+        is PinBouncerViewModel ->
+            PinBouncer(
+                viewModel = nonNullViewModel,
+                modifier = modifier,
+            )
+        is PasswordBouncerViewModel ->
+            PasswordBouncer(
+                viewModel = nonNullViewModel,
+                modifier = modifier,
+            )
+        is PatternBouncerViewModel ->
+            PatternBouncer(
+                viewModel = nonNullViewModel,
+                modifier =
+                    Modifier.aspectRatio(1f, matchHeightConstraintsFirst = false).then(modifier)
+            )
+        else -> Unit
+    }
+}
+
 /** Renders the UI of the user switcher that's displayed on large screens next to the bouncer UI. */
 @Composable
 private fun UserSwitcher(
@@ -287,62 +317,57 @@
             )
         }
 
-        UserSwitcherDropdown(
-            items = dropdownItems,
-        )
-    }
-}
+        val (isDropdownExpanded, setDropdownExpanded) = remember { mutableStateOf(false) }
 
-@Composable
-private fun UserSwitcherDropdown(
-    items: List<BouncerViewModel.UserSwitcherDropdownItemViewModel>,
-) {
-    val (isDropdownExpanded, setDropdownExpanded) = remember { mutableStateOf(false) }
+        dropdownItems.firstOrNull()?.let { firstDropdownItem ->
+            Spacer(modifier = Modifier.height(40.dp))
 
-    items.firstOrNull()?.let { firstDropdownItem ->
-        Spacer(modifier = Modifier.height(40.dp))
+            Box {
+                PlatformButton(
+                    modifier =
+                        Modifier
+                            // Remove the built-in padding applied inside PlatformButton:
+                            .padding(vertical = 0.dp)
+                            .width(UserSwitcherDropdownWidth)
+                            .height(UserSwitcherDropdownHeight),
+                    colors =
+                        ButtonDefaults.buttonColors(
+                            containerColor = MaterialTheme.colorScheme.surfaceContainerHighest,
+                            contentColor = MaterialTheme.colorScheme.onSurface,
+                        ),
+                    onClick = { setDropdownExpanded(!isDropdownExpanded) },
+                ) {
+                    val context = LocalContext.current
+                    Text(
+                        text = checkNotNull(firstDropdownItem.text.loadText(context)),
+                        style = MaterialTheme.typography.headlineSmall,
+                        maxLines = 1,
+                        overflow = TextOverflow.Ellipsis,
+                    )
 
-        Box {
-            PlatformButton(
-                modifier =
-                    Modifier
-                        // Remove the built-in padding applied inside PlatformButton:
-                        .padding(vertical = 0.dp)
-                        .width(UserSwitcherDropdownWidth)
-                        .height(UserSwitcherDropdownHeight),
-                colors =
-                    ButtonDefaults.buttonColors(
-                        containerColor = MaterialTheme.colorScheme.surfaceContainerHighest,
-                        contentColor = MaterialTheme.colorScheme.onSurface,
-                    ),
-                onClick = { setDropdownExpanded(!isDropdownExpanded) },
-            ) {
-                val context = LocalContext.current
-                Text(
-                    text = checkNotNull(firstDropdownItem.text.loadText(context)),
-                    style = MaterialTheme.typography.headlineSmall,
-                    maxLines = 1,
-                    overflow = TextOverflow.Ellipsis,
-                )
+                    Spacer(modifier = Modifier.weight(1f))
 
-                Spacer(modifier = Modifier.weight(1f))
+                    Icon(
+                        imageVector = Icons.Default.KeyboardArrowDown,
+                        contentDescription = null,
+                        modifier = Modifier.size(32.dp),
+                    )
+                }
 
-                Icon(
-                    imageVector = Icons.Default.KeyboardArrowDown,
-                    contentDescription = null,
-                    modifier = Modifier.size(32.dp),
+                UserSwitcherDropdownMenu(
+                    isExpanded = isDropdownExpanded,
+                    items = dropdownItems,
+                    onDismissed = { setDropdownExpanded(false) },
                 )
             }
-
-            UserSwitcherDropdownMenu(
-                isExpanded = isDropdownExpanded,
-                items = items,
-                onDismissed = { setDropdownExpanded(false) },
-            )
         }
     }
 }
 
+/**
+ * Renders the dropdowm menu that displays the actual users and/or user actions that can be
+ * selected.
+ */
 @Composable
 private fun UserSwitcherDropdownMenu(
     isExpanded: Boolean,
@@ -396,19 +421,47 @@
 }
 
 /**
- * Arranges the bouncer contents and user switcher contents side-by-side, supporting a double tap
- * anywhere on the background to flip their positions.
+ * Renders the bouncer UI in split mode, with half on one side and half on the other side, swappable
+ * by double-tapping on the side.
  */
 @Composable
-private fun SideBySide(
+private fun Split(
     viewModel: BouncerViewModel,
     dialogFactory: BouncerSceneDialogFactory,
     modifier: Modifier = Modifier,
 ) {
+    SwappableLayout(
+        startContent = { startContentModifier ->
+            Bouncer(
+                viewModel = viewModel,
+                dialogFactory = dialogFactory,
+                isUserInputAreaVisible = false,
+                modifier = startContentModifier,
+            )
+        },
+        endContent = { endContentModifier ->
+            UserInputArea(
+                viewModel = viewModel,
+                modifier = endContentModifier,
+            )
+        },
+        modifier = modifier
+    )
+}
+
+/**
+ * Arranges the given two contents side-by-side, supporting a double tap anywhere on the background
+ * to flip their positions.
+ */
+@Composable
+private fun SwappableLayout(
+    startContent: @Composable (Modifier) -> Unit,
+    endContent: @Composable (Modifier) -> Unit,
+    modifier: Modifier = Modifier,
+) {
     val layoutDirection = LocalLayoutDirection.current
     val isLeftToRight = layoutDirection == LayoutDirection.Ltr
-    val (isUserSwitcherFirst, setUserSwitcherFirst) =
-        rememberSaveable(isLeftToRight) { mutableStateOf(isLeftToRight) }
+    val (isSwapped, setSwapped) = rememberSaveable(isLeftToRight) { mutableStateOf(!isLeftToRight) }
 
     Row(
         modifier =
@@ -416,9 +469,8 @@
                 detectTapGestures(
                     onDoubleTap = { offset ->
                         // Depending on where the user double tapped, switch the elements such that
-                        // the bouncer contents element is closer to the side that was double
-                        // tapped.
-                        setUserSwitcherFirst(offset.x > size.width / 2)
+                        // the endContent is closer to the side that was double tapped.
+                        setSwapped(offset.x < size.width / 2)
                     }
                 )
             },
@@ -426,39 +478,30 @@
         val animatedOffset by
             animateFloatAsState(
                 targetValue =
-                    if (isUserSwitcherFirst) {
-                        // When the user switcher is first, both elements have their natural
-                        // placement so they are not offset in any way.
+                    if (!isSwapped) {
+                        // When startContent is first, both elements have their natural placement so
+                        // they are not offset in any way.
                         0f
                     } else if (isLeftToRight) {
-                        // Since the user switcher is not first, the elements have to be swapped
-                        // horizontally. In the case of LTR locales, this means pushing the user
-                        // switcher to the right, hence the positive number.
+                        // Since startContent is not first, the elements have to be swapped
+                        // horizontally. In the case of LTR locales, this means pushing startContent
+                        // to the right, hence the positive number.
                         1f
                     } else {
-                        // Since the user switcher is not first, the elements have to be swapped
-                        // horizontally. In the case of RTL locale, this means pushing the user
-                        // switcher to the left, hence the negative number.
+                        // Since startContent is not first, the elements have to be swapped
+                        // horizontally. In the case of RTL locales, this means pushing startContent
+                        // to the left, hence the negative number.
                         -1f
                     },
                 label = "offset",
             )
 
-        val userSwitcherModifier =
+        startContent(
             Modifier.fillMaxHeight().weight(1f).graphicsLayer {
                 translationX = size.width * animatedOffset
                 alpha = animatedAlpha(animatedOffset)
             }
-        if (viewModel.isUserSwitcherVisible) {
-            UserSwitcher(
-                viewModel = viewModel,
-                modifier = userSwitcherModifier,
-            )
-        } else {
-            Box(
-                modifier = userSwitcherModifier,
-            )
-        }
+        )
 
         Box(
             modifier =
@@ -469,41 +512,124 @@
                     alpha = animatedAlpha(animatedOffset)
                 }
         ) {
-            Bouncer(
-                viewModel = viewModel,
-                dialogFactory = dialogFactory,
-                modifier = Modifier.widthIn(max = 400.dp).align(Alignment.BottomCenter),
-            )
+            endContent(Modifier.widthIn(max = 400.dp).align(Alignment.BottomCenter))
         }
     }
 }
 
-/** Arranges the bouncer contents and user switcher contents one on top of the other. */
+/**
+ * Arranges the bouncer contents and user switcher contents side-by-side, supporting a double tap
+ * anywhere on the background to flip their positions.
+ */
+@Composable
+private fun SideBySide(
+    viewModel: BouncerViewModel,
+    dialogFactory: BouncerSceneDialogFactory,
+    isUserSwitcherVisible: Boolean,
+    modifier: Modifier = Modifier,
+) {
+    SwappableLayout(
+        startContent = { startContentModifier ->
+            if (isUserSwitcherVisible) {
+                UserSwitcher(
+                    viewModel = viewModel,
+                    modifier = startContentModifier,
+                )
+            } else {
+                Box(
+                    modifier = startContentModifier,
+                )
+            }
+        },
+        endContent = { endContentModifier ->
+            Bouncer(
+                viewModel = viewModel,
+                dialogFactory = dialogFactory,
+                isUserInputAreaVisible = true,
+                modifier = endContentModifier,
+            )
+        },
+        modifier = modifier,
+    )
+}
+
+/** Arranges the bouncer contents and user switcher contents one on top of the other, vertically. */
 @Composable
 private fun Stacked(
     viewModel: BouncerViewModel,
     dialogFactory: BouncerSceneDialogFactory,
+    isUserSwitcherVisible: Boolean,
     modifier: Modifier = Modifier,
 ) {
     Column(
         modifier = modifier,
     ) {
-        UserSwitcher(
-            viewModel = viewModel,
-            modifier = Modifier.fillMaxWidth().weight(1f),
-        )
+        if (isUserSwitcherVisible) {
+            UserSwitcher(
+                viewModel = viewModel,
+                modifier = Modifier.fillMaxWidth().weight(1f),
+            )
+        }
+
         Bouncer(
             viewModel = viewModel,
             dialogFactory = dialogFactory,
+            isUserInputAreaVisible = true,
             modifier = Modifier.fillMaxWidth().weight(1f),
         )
     }
 }
 
+@Composable
+private fun calculateLayout(): Layout {
+    val windowSizeClass = LocalWindowSizeClass.current
+    val width = windowSizeClass.widthSizeClass
+    val height = windowSizeClass.heightSizeClass
+    val isLarge = width > WindowWidthSizeClass.Compact && height > WindowHeightSizeClass.Compact
+    val isTall =
+        when (height) {
+            WindowHeightSizeClass.Expanded -> width < WindowWidthSizeClass.Expanded
+            WindowHeightSizeClass.Medium -> width < WindowWidthSizeClass.Medium
+            else -> false
+        }
+    val isSquare =
+        when (width) {
+            WindowWidthSizeClass.Compact -> height == WindowHeightSizeClass.Compact
+            WindowWidthSizeClass.Medium -> height == WindowHeightSizeClass.Medium
+            WindowWidthSizeClass.Expanded -> height == WindowHeightSizeClass.Expanded
+            else -> false
+        }
+    val isLandscape = LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE
+
+    return when {
+        // Small and tall devices (i.e. phone/folded in portrait) or square device not in landscape
+        // mode (unfolded with hinge along horizontal plane).
+        (!isLarge && isTall) || (isSquare && !isLandscape) -> Layout.STANDARD
+        // Small and wide devices (i.e. phone/folded in landscape).
+        !isLarge -> Layout.SPLIT
+        // Large and tall devices (i.e. tablet in portrait).
+        isTall -> Layout.STACKED
+        // Large and wide/square devices (i.e. tablet in landscape, unfolded).
+        else -> Layout.SIDE_BY_SIDE
+    }
+}
+
 interface BouncerSceneDialogFactory {
     operator fun invoke(): AlertDialog
 }
 
+/** Enumerates all known adaptive layout configurations. */
+private enum class Layout {
+    /** The default UI with the bouncer laid out normally. */
+    STANDARD,
+    /** The bouncer is displayed vertically stacked with the user switcher. */
+    STACKED,
+    /** The bouncer is displayed side-by-side with the user switcher or an empty space. */
+    SIDE_BY_SIDE,
+    /** The bouncer is split in two with both sides shown side-by-side. */
+    SPLIT,
+}
+
 /**
  * Calculates an alpha for the user switcher and bouncer such that it's at `1` when the offset of
  * the two reaches a stopping point but `0` in the middle of the transition.
diff --git a/packages/SystemUI/src/com/android/systemui/aconfig/AConfigModule.kt b/packages/SystemUI/src/com/android/systemui/aconfig/AConfigModule.kt
deleted file mode 100644
index fa61bba..0000000
--- a/packages/SystemUI/src/com/android/systemui/aconfig/AConfigModule.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.aconfig
-
-import com.android.systemui.FeatureFlags
-import com.android.systemui.FeatureFlagsImpl
-import com.android.systemui.dagger.SysUISingleton
-import dagger.Module
-import dagger.Provides
-
-@Module
-abstract class AConfigModule {
-    @Module
-    companion object {
-        @Provides
-        @SysUISingleton
-        fun providesImpl(): FeatureFlags {
-            return FeatureFlagsImpl()
-        }
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractor.kt b/packages/SystemUI/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractor.kt
index 2bb19cd..f513799 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractor.kt
@@ -26,8 +26,6 @@
 import com.android.systemui.biometrics.shared.model.FingerprintSensorType
 import com.android.systemui.biometrics.shared.model.isDefaultOrientation
 import com.android.systemui.dagger.SysUISingleton
-import com.android.systemui.flags.FeatureFlagsClassic
-import com.android.systemui.flags.Flags
 import com.android.systemui.log.SideFpsLogger
 import com.android.systemui.res.R
 import java.util.Optional
@@ -48,7 +46,6 @@
     fingerprintPropertyRepository: FingerprintPropertyRepository,
     windowManager: WindowManager,
     displayStateInteractor: DisplayStateInteractor,
-    featureFlags: FeatureFlagsClassic,
     fingerprintInteractiveToAuthProvider: Optional<FingerprintInteractiveToAuthProvider>,
     private val logger: SideFpsLogger,
 ) {
@@ -65,14 +62,11 @@
     val isAvailable: Flow<Boolean> =
         fingerprintPropertyRepository.sensorType.map { it == FingerprintSensorType.POWER_BUTTON }
 
-    val authenticationDuration: Flow<Long> =
-        flowOf(context.resources?.getInteger(R.integer.config_restToUnlockDuration)?.toLong() ?: 0L)
+    val authenticationDuration: Long =
+        context.resources?.getInteger(R.integer.config_restToUnlockDuration)?.toLong() ?: 0L
 
     val isProlongedTouchRequiredForAuthentication: Flow<Boolean> =
-        if (
-            fingerprintInteractiveToAuthProvider.isEmpty ||
-                !featureFlags.isEnabled(Flags.REST_TO_UNLOCK)
-        ) {
+        if (fingerprintInteractiveToAuthProvider.isEmpty) {
             flowOf(false)
         } else {
             combine(
diff --git a/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalRepository.kt b/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalRepository.kt
index 9cab17e..5c4ee35 100644
--- a/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/communal/data/repository/CommunalRepository.kt
@@ -1,6 +1,6 @@
 package com.android.systemui.communal.data.repository
 
-import com.android.systemui.FeatureFlags
+import com.android.systemui.Flags.communalHub
 import com.android.systemui.communal.shared.model.CommunalSceneKey
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.flags.FeatureFlagsClassic
@@ -29,13 +29,10 @@
 class CommunalRepositoryImpl
 @Inject
 constructor(
-    private val featureFlags: FeatureFlags,
     private val featureFlagsClassic: FeatureFlagsClassic,
 ) : CommunalRepository {
     override val isCommunalEnabled: Boolean
-        get() =
-            featureFlagsClassic.isEnabled(Flags.COMMUNAL_SERVICE_ENABLED) &&
-                featureFlags.communalHub()
+        get() = featureFlagsClassic.isEnabled(Flags.COMMUNAL_SERVICE_ENABLED) && communalHub()
 
     private val _desiredScene: MutableStateFlow<CommunalSceneKey> =
         MutableStateFlow(CommunalSceneKey.Blank)
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java
index 7915088..f3353c7 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIModule.java
@@ -29,7 +29,6 @@
 import com.android.systemui.BootCompleteCacheImpl;
 import com.android.systemui.accessibility.AccessibilityModule;
 import com.android.systemui.accessibility.data.repository.AccessibilityRepositoryModule;
-import com.android.systemui.aconfig.AConfigModule;
 import com.android.systemui.appops.dagger.AppOpsModule;
 import com.android.systemui.assist.AssistModule;
 import com.android.systemui.authentication.AuthenticationModule;
@@ -163,7 +162,6 @@
 @Module(includes = {
         AccessibilityModule.class,
         AccessibilityRepositoryModule.class,
-        AConfigModule.class,
         AppOpsModule.class,
         AssistModule.class,
         AuthenticationModule.class,
diff --git a/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsClassicDebug.java b/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsClassicDebug.java
index 36d789e..87c12b4 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsClassicDebug.java
+++ b/packages/SystemUI/src/com/android/systemui/flags/FeatureFlagsClassicDebug.java
@@ -17,6 +17,7 @@
 package com.android.systemui.flags;
 
 import static com.android.systemui.Flags.exampleFlag;
+import static com.android.systemui.Flags.sysuiTeamfood;
 import static com.android.systemui.flags.FlagManager.ACTION_GET_FLAGS;
 import static com.android.systemui.flags.FlagManager.ACTION_SET_FLAG;
 import static com.android.systemui.flags.FlagManager.EXTRA_FLAGS;
@@ -38,13 +39,10 @@
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
-import com.android.systemui.FeatureFlags;
 import com.android.systemui.dagger.SysUISingleton;
 import com.android.systemui.dagger.qualifiers.Main;
 import com.android.systemui.util.settings.GlobalSettings;
 
-import org.jetbrains.annotations.NotNull;
-
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Map;
@@ -83,7 +81,6 @@
     private final Map<String, Boolean> mBooleanFlagCache = new ConcurrentHashMap<>();
     private final Map<String, String> mStringFlagCache = new ConcurrentHashMap<>();
     private final Map<String, Integer> mIntFlagCache = new ConcurrentHashMap<>();
-    private final FeatureFlags mGantryFlags;
     private final Restarter mRestarter;
 
     private final ServerFlagReader.ChangeListener mOnPropertiesChanged =
@@ -128,7 +125,6 @@
             @Main Resources resources,
             ServerFlagReader serverFlagReader,
             @Named(ALL_FLAGS) Map<String, Flag<?>> allFlags,
-            FeatureFlags gantryFlags,
             Restarter restarter) {
         mFlagManager = flagManager;
         mContext = context;
@@ -137,7 +133,6 @@
         mSystemProperties = systemProperties;
         mServerFlagReader = serverFlagReader;
         mAllFlags = allFlags;
-        mGantryFlags = gantryFlags;
         mRestarter = restarter;
     }
 
@@ -155,16 +150,16 @@
     }
 
     @Override
-    public boolean isEnabled(@NotNull UnreleasedFlag flag) {
+    public boolean isEnabled(@NonNull UnreleasedFlag flag) {
         return isEnabledInternal(flag);
     }
 
     @Override
-    public boolean isEnabled(@NotNull ReleasedFlag flag) {
+    public boolean isEnabled(@NonNull ReleasedFlag flag) {
         return isEnabledInternal(flag);
     }
 
-    private boolean isEnabledInternal(@NotNull BooleanFlag flag) {
+    private boolean isEnabledInternal(@NonNull BooleanFlag flag) {
         String name = flag.getName();
 
         Boolean value = mBooleanFlagCache.get(name);
@@ -266,7 +261,7 @@
                 && !defaultValue
                 && result == null
                 && flag.getTeamfood()) {
-            return mGantryFlags.sysuiTeamfood();
+            return sysuiTeamfood();
         }
 
         return result == null ? mServerFlagReader.readServerOverride(
@@ -539,7 +534,7 @@
     @Override
     public void dump(@NonNull PrintWriter pw, @NonNull String[] args) {
         pw.println("can override: true");
-        pw.println("teamfood: " + mGantryFlags.sysuiTeamfood());
+        pw.println("teamfood: " + sysuiTeamfood());
         pw.println("booleans: " + mBooleanFlagCache.size());
         pw.println("example_flag: " + exampleFlag());
         pw.println("example_shared_flag: " + exampleSharedFlag());
diff --git a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
index c1106b3..49b8ee6 100644
--- a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
+++ b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt
@@ -296,11 +296,6 @@
     @JvmField val MIGRATE_CLOCKS_TO_BLUEPRINT =
             unreleasedFlag("migrate_clocks_to_blueprint")
 
-    /** Migrate KeyguardRootView to use composables. */
-    // TODO(b/301969856): Tracking Bug.
-    @JvmField val KEYGUARD_ROOT_VIEW_USE_COMPOSE =
-        unreleasedFlag("keyguard_root_view_use_compose")
-
     /** Enables preview loading animation in the wallpaper picker. */
     // TODO(b/274443705): Tracking Bug
     @JvmField
@@ -532,10 +527,9 @@
     @Keep
     @JvmField
     val WM_ENABLE_PARTIAL_SCREEN_SHARING_ENTERPRISE_POLICIES =
-        unreleasedFlag(
-            name = "screen_record_enterprise_policies",
+        releasedFlag(
+            name = "enable_screen_record_enterprise_policies",
             namespace = DeviceConfig.NAMESPACE_WINDOW_MANAGER,
-            teamfood = false
         )
 
     // TODO(b/293252410) : Tracking Bug
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/SideFpsProgressBarViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/SideFpsProgressBarViewBinder.kt
index ba4876f..0bee48a 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/SideFpsProgressBarViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/SideFpsProgressBarViewBinder.kt
@@ -22,6 +22,8 @@
 import com.android.systemui.biometrics.SideFpsController
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Application
+import com.android.systemui.flags.FeatureFlagsClassic
+import com.android.systemui.flags.Flags
 import com.android.systemui.keyguard.ui.view.SideFpsProgressBar
 import com.android.systemui.keyguard.ui.viewmodel.SideFpsProgressBarViewModel
 import com.android.systemui.log.SideFpsLogger
@@ -31,6 +33,7 @@
 import java.io.PrintWriter
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Job
 import kotlinx.coroutines.flow.collectLatest
 import kotlinx.coroutines.flow.combine
 import kotlinx.coroutines.launch
@@ -47,15 +50,23 @@
     private val sfpsController: dagger.Lazy<SideFpsController>,
     private val logger: SideFpsLogger,
     private val commandRegistry: CommandRegistry,
+    private val featureFlagsClassic: FeatureFlagsClassic,
 ) : CoreStartable {
 
     override fun start() {
+        if (!featureFlagsClassic.isEnabled(Flags.REST_TO_UNLOCK)) {
+            return
+        }
+        // When the rest to unlock feature is disabled by the user, stop any coroutines that are
+        // not required.
+        var layoutJob: Job? = null
+        var progressJob: Job? = null
         commandRegistry.registerCommand(spfsProgressBarCommand) { SfpsProgressBarCommand() }
         applicationScope.launch {
             viewModel.isProlongedTouchRequiredForAuthentication.collectLatest { enabled ->
                 logger.isProlongedTouchRequiredForAuthenticationChanged(enabled)
                 if (enabled) {
-                    launch {
+                    layoutJob = launch {
                         combine(
                                 viewModel.isVisible,
                                 viewModel.progressBarLocation,
@@ -76,9 +87,13 @@
                                 )
                             }
                     }
-                    launch { viewModel.progress.collectLatest { view.setProgress(it) } }
+                    progressJob = launch {
+                        viewModel.progress.collectLatest { view.setProgress(it) }
+                    }
                 } else {
                     view.hide()
+                    layoutJob?.cancel()
+                    progressJob?.cancel()
                 }
             }
         }
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/SideFpsProgressBarViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/SideFpsProgressBarViewModel.kt
index f8996b7..a0f5baf 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/SideFpsProgressBarViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/SideFpsProgressBarViewModel.kt
@@ -26,6 +26,8 @@
 import com.android.systemui.biometrics.shared.model.isDefaultOrientation
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Application
+import com.android.systemui.flags.FeatureFlagsClassic
+import com.android.systemui.flags.Flags
 import com.android.systemui.keyguard.data.repository.DeviceEntryFingerprintAuthRepository
 import com.android.systemui.keyguard.shared.model.AcquiredFingerprintAuthenticationStatus
 import com.android.systemui.keyguard.shared.model.ErrorFingerprintAuthenticationStatus
@@ -34,13 +36,17 @@
 import com.android.systemui.res.R
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Job
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.MutableStateFlow
 import kotlinx.coroutines.flow.asStateFlow
 import kotlinx.coroutines.flow.collectLatest
 import kotlinx.coroutines.flow.combine
 import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.launchIn
 import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.onCompletion
+import kotlinx.coroutines.flow.onEach
 import kotlinx.coroutines.launch
 
 @SysUISingleton
@@ -52,10 +58,12 @@
     private val sfpsSensorInteractor: SideFpsSensorInteractor,
     displayStateInteractor: DisplayStateInteractor,
     @Application private val applicationScope: CoroutineScope,
+    private val featureFlagsClassic: FeatureFlagsClassic,
 ) {
     private val _progress = MutableStateFlow(0.0f)
     private val _visible = MutableStateFlow(false)
     private var _animator: ValueAnimator? = null
+    private var animatorJob: Job? = null
 
     private fun onFingerprintCaptureCompleted() {
         _visible.value = false
@@ -147,26 +155,32 @@
         sfpsSensorInteractor.isProlongedTouchRequiredForAuthentication
 
     init {
-        applicationScope.launch {
-            combine(
-                    sfpsSensorInteractor.isProlongedTouchRequiredForAuthentication,
-                    sfpsSensorInteractor.authenticationDuration,
-                    ::Pair
-                )
-                .collectLatest { (enabled, authDuration) ->
-                    if (!enabled) return@collectLatest
+        if (featureFlagsClassic.isEnabled(Flags.REST_TO_UNLOCK)) {
+            launchAnimator()
+        }
+    }
 
-                    launch {
-                        fpAuthRepository.authenticationStatus.collectLatest { authStatus ->
+    private fun launchAnimator() {
+        applicationScope.launch {
+            sfpsSensorInteractor.isProlongedTouchRequiredForAuthentication.collectLatest { enabled
+                ->
+                if (!enabled) {
+                    animatorJob?.cancel()
+                    return@collectLatest
+                }
+                animatorJob =
+                    fpAuthRepository.authenticationStatus
+                        .onEach { authStatus ->
                             when (authStatus) {
                                 is AcquiredFingerprintAuthenticationStatus -> {
                                     if (authStatus.fingerprintCaptureStarted) {
-
                                         _visible.value = true
                                         _animator?.cancel()
                                         _animator =
                                             ValueAnimator.ofFloat(0.0f, 1.0f)
-                                                .setDuration(authDuration)
+                                                .setDuration(
+                                                    sfpsSensorInteractor.authenticationDuration
+                                                )
                                                 .apply {
                                                     addUpdateListener {
                                                         _progress.value = it.animatedValue as Float
@@ -196,8 +210,9 @@
                                 else -> Unit
                             }
                         }
-                    }
-                }
+                        .onCompletion { _animator?.cancel() }
+                        .launchIn(applicationScope)
+            }
         }
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/scene/shared/flag/SceneContainerFlags.kt b/packages/SystemUI/src/com/android/systemui/scene/shared/flag/SceneContainerFlags.kt
index 9ba02b1..49bceef 100644
--- a/packages/SystemUI/src/com/android/systemui/scene/shared/flag/SceneContainerFlags.kt
+++ b/packages/SystemUI/src/com/android/systemui/scene/shared/flag/SceneContainerFlags.kt
@@ -17,8 +17,8 @@
 package com.android.systemui.scene.shared.flag
 
 import androidx.annotation.VisibleForTesting
-import com.android.systemui.FeatureFlags
 import com.android.systemui.Flags as AConfigFlags
+import com.android.systemui.Flags.sceneContainer
 import com.android.systemui.compose.ComposeFacade
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.flags.FeatureFlagsClassic
@@ -50,7 +50,6 @@
 @AssistedInject
 constructor(
     private val featureFlagsClassic: FeatureFlagsClassic,
-    featureFlags: FeatureFlags,
     @Assisted private val isComposeAvailable: Boolean,
 ) : SceneContainerFlags {
 
@@ -72,7 +71,7 @@
         listOf(
             AconfigFlagMustBeEnabled(
                 flagName = AConfigFlags.FLAG_SCENE_CONTAINER,
-                flagValue = featureFlags.sceneContainer(),
+                flagValue = sceneContainer(),
             ),
         ) +
             classicFlagTokens.map { flagToken -> FlagMustBeEnabled(flagToken) } +
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractorTest.kt
index 3fbdeec..67d3a20 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/domain/interactor/SideFpsSensorInteractorTest.kt
@@ -37,8 +37,6 @@
 import com.android.systemui.biometrics.shared.model.SensorStrength
 import com.android.systemui.coroutines.collectLastValue
 import com.android.systemui.dump.logcatLogBuffer
-import com.android.systemui.flags.FakeFeatureFlagsClassic
-import com.android.systemui.flags.Flags.REST_TO_UNLOCK
 import com.android.systemui.log.SideFpsLogger
 import com.android.systemui.res.R
 import com.android.systemui.util.mockito.whenever
@@ -94,7 +92,6 @@
         whenever(displayStateInteractor.currentRotation).thenReturn(currentRotation)
 
         contextDisplayInfo.uniqueId = "current-display"
-        val featureFlags = FakeFeatureFlagsClassic().apply { set(REST_TO_UNLOCK, true) }
         whenever(fingerprintInteractiveToAuthProvider.enabledForCurrentUser)
             .thenReturn(isRestToUnlockEnabled)
         underTest =
@@ -103,7 +100,6 @@
                 fingerprintRepository,
                 windowManager,
                 displayStateInteractor,
-                featureFlags,
                 Optional.of(fingerprintInteractiveToAuthProvider),
                 SideFpsLogger(logcatLogBuffer("SfpsLogger"))
             )
@@ -136,7 +132,7 @@
     @Test
     fun authenticationDurationIsAvailableWhenSFPSSensorIsAvailable() =
         testScope.runTest {
-            assertThat(collectLastValue(underTest.authenticationDuration)())
+            assertThat(underTest.authenticationDuration)
                 .isEqualTo(context.resources.getInteger(R.integer.config_restToUnlockDuration))
         }
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/flags/FeatureFlagsClassicDebugTest.kt b/packages/SystemUI/tests/src/com/android/systemui/flags/FeatureFlagsClassicDebugTest.kt
index f51745b..b589a2a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/flags/FeatureFlagsClassicDebugTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/flags/FeatureFlagsClassicDebugTest.kt
@@ -22,7 +22,6 @@
 import android.content.res.Resources
 import android.content.res.Resources.NotFoundException
 import android.test.suitebuilder.annotation.SmallTest
-import com.android.systemui.FakeFeatureFlagsImpl
 import com.android.systemui.SysuiTestCase
 import com.android.systemui.util.mockito.any
 import com.android.systemui.util.mockito.eq
@@ -66,7 +65,6 @@
     private lateinit var broadcastReceiver: BroadcastReceiver
     private lateinit var clearCacheAction: Consumer<String>
     private val serverFlagReader = ServerFlagReaderFake()
-    private val fakeGantryFlags = FakeFeatureFlagsImpl()
 
     private val teamfoodableFlagA = UnreleasedFlag(name = "a", namespace = "test", teamfood = true)
     private val teamfoodableFlagB = ReleasedFlag(name = "b", namespace = "test", teamfood = true)
@@ -74,7 +72,6 @@
     @Before
     fun setup() {
         MockitoAnnotations.initMocks(this)
-        fakeGantryFlags.setFlag("com.android.systemui.sysui_teamfood", false)
         flagMap.put(teamfoodableFlagA.name, teamfoodableFlagA)
         flagMap.put(teamfoodableFlagB.name, teamfoodableFlagB)
         mFeatureFlagsClassicDebug =
@@ -86,7 +83,6 @@
                 resources,
                 serverFlagReader,
                 flagMap,
-                fakeGantryFlags,
                 restarter
             )
         mFeatureFlagsClassicDebug.init()
@@ -134,7 +130,7 @@
 
     @Test
     fun teamFoodFlag_True() {
-        fakeGantryFlags.setFlag("com.android.systemui.sysui_teamfood", true)
+        mSetFlagsRule.enableFlags(com.android.systemui.Flags.FLAG_SYSUI_TEAMFOOD)
         assertThat(mFeatureFlagsClassicDebug.isEnabled(teamfoodableFlagA)).isTrue()
         assertThat(mFeatureFlagsClassicDebug.isEnabled(teamfoodableFlagB)).isTrue()
 
@@ -149,7 +145,7 @@
             .thenReturn(true)
         whenever(flagManager.readFlagValue<Boolean>(eq(teamfoodableFlagB.name), any()))
             .thenReturn(false)
-        fakeGantryFlags.setFlag("com.android.systemui.sysui_teamfood", true)
+        mSetFlagsRule.enableFlags(com.android.systemui.Flags.FLAG_SYSUI_TEAMFOOD)
         assertThat(mFeatureFlagsClassicDebug.isEnabled(teamfoodableFlagA)).isTrue()
         assertThat(mFeatureFlagsClassicDebug.isEnabled(teamfoodableFlagB)).isFalse()
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/scene/shared/flag/SceneContainerFlagsTest.kt b/packages/SystemUI/tests/src/com/android/systemui/scene/shared/flag/SceneContainerFlagsTest.kt
index 0bed4d0..32a38bd 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/scene/shared/flag/SceneContainerFlagsTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/scene/shared/flag/SceneContainerFlagsTest.kt
@@ -76,7 +76,6 @@
         underTest =
             SceneContainerFlagsImpl(
                 featureFlagsClassic = featureFlags,
-                featureFlags = aconfigFlags,
                 isComposeAvailable = testCase.isComposeAvailable,
             )
     }
diff --git a/services/core/java/com/android/server/am/flags.aconfig b/services/core/java/com/android/server/am/flags.aconfig
index cbaf05b..a770b66 100644
--- a/services/core/java/com/android/server/am/flags.aconfig
+++ b/services/core/java/com/android/server/am/flags.aconfig
@@ -22,3 +22,10 @@
     description: "Detect abusive FGS behavior for certain types (camera, mic, media, location)."
     bug: "295545575"
 }
+
+flag {
+    name: "fgs_boot_completed"
+    namespace: "backstage_power"
+    description: "Disable BOOT_COMPLETED broadcast FGS start for certain types"
+    bug: "296558535"
+}
diff --git a/services/core/java/com/android/server/storage/StorageSessionController.java b/services/core/java/com/android/server/storage/StorageSessionController.java
index 4ebd402..5fd787a 100644
--- a/services/core/java/com/android/server/storage/StorageSessionController.java
+++ b/services/core/java/com/android/server/storage/StorageSessionController.java
@@ -126,10 +126,10 @@
                 connection = new StorageUserConnection(mContext, userId, this);
                 mConnections.put(userId, connection);
             }
-            Slog.i(TAG, "Creating and starting session with id: " + sessionId);
-            connection.startSession(sessionId, deviceFd, vol.getPath().getPath(),
-                    vol.getInternalPath().getPath());
         }
+        Slog.i(TAG, "Creating and starting session with id: " + sessionId);
+        connection.startSession(sessionId, deviceFd, vol.getPath().getPath(),
+                vol.getInternalPath().getPath());
     }
 
     /**