Merge "Fix floating sheet overlap with 3 button navigation bar" into main
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 6e5844d..f89ff6e 100755
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -82,6 +82,16 @@
 
         <activity
             tools:node="replace"
+            android:name="com.android.wallpaper.picker.customization.ui.CustomizationPickerActivity2"
+            android:label="@string/app_name"
+            android:relinquishTaskIdentity="true"
+            android:resizeableActivity="false"
+            android:theme="@style/WallpaperTheme"
+            android:configChanges="assetsPaths"
+            android:exported="false"/>
+
+        <activity
+            tools:node="replace"
             android:name="com.android.wallpaper.picker.PassThroughCustomizationPickerActivity"
             android:label="@string/app_name"
             android:resizeableActivity="false"
diff --git a/src/com/android/customization/picker/clock/ui/view/ClockViewFactoryImpl.kt b/src/com/android/customization/picker/clock/ui/view/ClockViewFactoryImpl.kt
index d46d2e0..a3f7c51 100644
--- a/src/com/android/customization/picker/clock/ui/view/ClockViewFactoryImpl.kt
+++ b/src/com/android/customization/picker/clock/ui/view/ClockViewFactoryImpl.kt
@@ -18,7 +18,6 @@
 import android.app.WallpaperColors
 import android.app.WallpaperManager
 import android.content.Context
-import android.content.res.Resources
 import android.graphics.Point
 import android.graphics.Rect
 import android.view.View
@@ -26,6 +25,7 @@
 import androidx.annotation.ColorInt
 import androidx.core.text.util.LocalePreferences
 import androidx.lifecycle.LifecycleOwner
+import com.android.internal.policy.SystemBarUtils
 import com.android.systemui.plugins.clocks.ClockController
 import com.android.systemui.plugins.clocks.WeatherData
 import com.android.systemui.shared.clocks.ClockRegistry
@@ -106,9 +106,10 @@
     }
 
     private fun getSmallClockTopMargin() =
-        appContext.resources.getDimensionPixelSize(
-            com.android.systemui.customization.R.dimen.small_clock_padding_top
-        )
+        getStatusBarHeight(appContext) +
+            appContext.resources.getDimensionPixelSize(
+                com.android.systemui.customization.R.dimen.small_clock_padding_top
+            )
 
     private fun getSmallClockStartPadding() =
         appContext.resources.getDimensionPixelSize(
@@ -256,11 +257,18 @@
         const val TEMPERATURE_CELSIUS_PLACEHOLDER = 21
         val WEATHERICON_PLACEHOLDER = WeatherData.WeatherStateIcon.MOSTLY_SUNNY
 
-        private fun getStatusBarHeight(resource: Resources): Int {
+        private fun getStatusBarHeight(context: Context): Int {
+
+            val display = context.displayNoVerify
+            if (display != null) {
+                return SystemBarUtils.getStatusBarHeight(context.resources, display.cutout)
+            }
+
             var result = 0
-            val resourceId: Int = resource.getIdentifier("status_bar_height", "dimen", "android")
+            val resourceId: Int =
+                context.resources.getIdentifier("status_bar_height", "dimen", "android")
             if (resourceId > 0) {
-                result = resource.getDimensionPixelSize(resourceId)
+                result = context.resources.getDimensionPixelSize(resourceId)
             }
             return result
         }
diff --git a/src/com/android/wallpaper/picker/common/preview/ui/binder/ThemePickerWorkspaceCallbackBinder.kt b/src/com/android/wallpaper/picker/common/preview/ui/binder/ThemePickerWorkspaceCallbackBinder.kt
index a80febd..7d40b5b 100644
--- a/src/com/android/wallpaper/picker/common/preview/ui/binder/ThemePickerWorkspaceCallbackBinder.kt
+++ b/src/com/android/wallpaper/picker/common/preview/ui/binder/ThemePickerWorkspaceCallbackBinder.kt
@@ -33,6 +33,7 @@
 import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.MESSAGE_ID_START_CUSTOMIZING_QUICK_AFFORDANCES
 import com.android.wallpaper.customization.ui.util.ThemePickerCustomizationOptionUtil.ThemePickerLockCustomizationOption
 import com.android.wallpaper.customization.ui.viewmodel.ThemePickerCustomizationOptionsViewModel
+import com.android.wallpaper.model.Screen
 import com.android.wallpaper.picker.common.preview.ui.binder.WorkspaceCallbackBinder.Companion.sendMessage
 import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationOptionsViewModel
 import javax.inject.Inject
@@ -48,11 +49,13 @@
     override fun bind(
         workspaceCallback: Message,
         viewModel: CustomizationOptionsViewModel,
+        screen: Screen,
         lifecycleOwner: LifecycleOwner,
     ) {
         defaultWorkspaceCallbackBinder.bind(
             workspaceCallback = workspaceCallback,
             viewModel = viewModel,
+            screen = screen,
             lifecycleOwner = lifecycleOwner,
         )
 
@@ -62,61 +65,63 @@
             )
         }
 
-        lifecycleOwner.lifecycleScope.launch {
-            lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
-                launch {
-                    viewModel.selectedOption.collect {
-                        when (it) {
-                            ThemePickerLockCustomizationOption.SHORTCUTS ->
-                                workspaceCallback.sendMessage(
-                                    MESSAGE_ID_START_CUSTOMIZING_QUICK_AFFORDANCES,
-                                    Bundle().apply {
-                                        putString(
-                                            KEY_INITIALLY_SELECTED_SLOT_ID,
-                                            SLOT_ID_BOTTOM_START,
-                                        )
-                                    }
-                                )
-                            else ->
-                                workspaceCallback.sendMessage(
-                                    MESSAGE_ID_DEFAULT_PREVIEW,
-                                    Bundle.EMPTY,
-                                )
-                        }
-                    }
-                }
-
-                launch {
-                    viewModel.keyguardQuickAffordancePickerViewModel2.selectedSlotId.collect {
-                        workspaceCallback.sendMessage(
-                            MESSAGE_ID_SLOT_SELECTED,
-                            Bundle().apply { putString(KEY_SLOT_ID, it) },
-                        )
-                    }
-                }
-
-                launch {
-                    viewModel.keyguardQuickAffordancePickerViewModel2.selectedQuickAffordances
-                        .collect {
-                            it[SLOT_ID_BOTTOM_START]?.let {
-                                workspaceCallback.sendMessage(
-                                    MESSAGE_ID_PREVIEW_QUICK_AFFORDANCE_SELECTED,
-                                    Bundle().apply {
-                                        putString(KEY_SLOT_ID, SLOT_ID_BOTTOM_START)
-                                        putString(KEY_QUICK_AFFORDANCE_ID, it)
-                                    },
-                                )
-                            }
-                            it[SLOT_ID_BOTTOM_END]?.let {
-                                workspaceCallback.sendMessage(
-                                    MESSAGE_ID_PREVIEW_QUICK_AFFORDANCE_SELECTED,
-                                    Bundle().apply {
-                                        putString(KEY_SLOT_ID, SLOT_ID_BOTTOM_END)
-                                        putString(KEY_QUICK_AFFORDANCE_ID, it)
-                                    },
-                                )
+        if (screen == Screen.LOCK_SCREEN) {
+            lifecycleOwner.lifecycleScope.launch {
+                lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
+                    launch {
+                        viewModel.selectedOption.collect {
+                            when (it) {
+                                ThemePickerLockCustomizationOption.SHORTCUTS ->
+                                    workspaceCallback.sendMessage(
+                                        MESSAGE_ID_START_CUSTOMIZING_QUICK_AFFORDANCES,
+                                        Bundle().apply {
+                                            putString(
+                                                KEY_INITIALLY_SELECTED_SLOT_ID,
+                                                SLOT_ID_BOTTOM_START,
+                                            )
+                                        }
+                                    )
+                                else ->
+                                    workspaceCallback.sendMessage(
+                                        MESSAGE_ID_DEFAULT_PREVIEW,
+                                        Bundle.EMPTY,
+                                    )
                             }
                         }
+                    }
+
+                    launch {
+                        viewModel.keyguardQuickAffordancePickerViewModel2.selectedSlotId.collect {
+                            workspaceCallback.sendMessage(
+                                MESSAGE_ID_SLOT_SELECTED,
+                                Bundle().apply { putString(KEY_SLOT_ID, it) },
+                            )
+                        }
+                    }
+
+                    launch {
+                        viewModel.keyguardQuickAffordancePickerViewModel2.selectedQuickAffordances
+                            .collect {
+                                it[SLOT_ID_BOTTOM_START]?.let {
+                                    workspaceCallback.sendMessage(
+                                        MESSAGE_ID_PREVIEW_QUICK_AFFORDANCE_SELECTED,
+                                        Bundle().apply {
+                                            putString(KEY_SLOT_ID, SLOT_ID_BOTTOM_START)
+                                            putString(KEY_QUICK_AFFORDANCE_ID, it)
+                                        },
+                                    )
+                                }
+                                it[SLOT_ID_BOTTOM_END]?.let {
+                                    workspaceCallback.sendMessage(
+                                        MESSAGE_ID_PREVIEW_QUICK_AFFORDANCE_SELECTED,
+                                        Bundle().apply {
+                                            putString(KEY_SLOT_ID, SLOT_ID_BOTTOM_END)
+                                            putString(KEY_QUICK_AFFORDANCE_ID, it)
+                                        },
+                                    )
+                                }
+                            }
+                    }
                 }
             }
         }