Fix crash when restoring data from phone to tablet with responsive grid
This issue happens when restoring the data from a phone to a tablet or vice-versa. When Launcher is restoring the data, it allows the device to load a disabled or invalid grid temporarly for the migration. This leads to a crash when the responsive grid is enabled.
The hotseat spec has only WIDTH or HEIGHT specs in a certain posture. When the user restores the data from a phone to a tablet, the Launcher loads a handheld spec that doesn't have HEIGHT specs for the hotseat in landscape (spec_handheld_hotseat_[grid].xml). However, the tablet, in landscape, tries to retrieve the hotseat HEIGHT spec.
It also prevent crash when responsive grid is used with multi window mode. isVerticalBarLayout becomes false. Then, the responsive grid tries to load a hotseat spec that doesn't exist (using DimensionType.HEIGHT). Phones have hotseat specs only for DimensionType.WIDTH.
Bug: 315548992
Fix: 315069300
Fix: 315377544
Flag: ACONFIG com.android.launcher3.enable_responsive_workspace TEAMFOOD
Test: v2/android-crystalball-eng/health/microbench/systemui/main/systemui-notification-3-jank-suite
Test: atest CtsWindowManagerDeviceDisplay:android.server.wm.display.MultiDisplaySystemDecorationTests#testSendPrimaryHomeIntentActivityOnDisplayWithDecorations -- --abi x86_64
Change-Id: Ibd6537e0528868da9a1b7672c43b5455fa6a8184
diff --git a/src/com/android/launcher3/responsive/HotseatSpecsProvider.kt b/src/com/android/launcher3/responsive/HotseatSpecsProvider.kt
index ebbff51..7502a43 100644
--- a/src/com/android/launcher3/responsive/HotseatSpecsProvider.kt
+++ b/src/com/android/launcher3/responsive/HotseatSpecsProvider.kt
@@ -40,13 +40,28 @@
return specsGroup
}
+ private fun getSpecIgnoringDimensionType(
+ availableSize: Int,
+ specsGroup: ResponsiveSpecGroup<HotseatSpec>
+ ): HotseatSpec? {
+ val specWidth = specsGroup.widthSpecs.firstOrNull { availableSize <= it.maxAvailableSize }
+ val specHeight = specsGroup.heightSpecs.firstOrNull { availableSize <= it.maxAvailableSize }
+ return specWidth ?: specHeight
+ }
+
fun getCalculatedSpec(
aspectRatio: Float,
dimensionType: DimensionType,
- availableSpace: Int
+ availableSpace: Int,
): CalculatedHotseatSpec {
val specsGroup = getSpecsByAspectRatio(aspectRatio)
- val spec = specsGroup.getSpec(dimensionType, availableSpace)
+
+ // TODO(b/315548992): Ignore the dimension type to prevent crash before launcher
+ // data migration is finished. The restore process allows the initialization of
+ // an invalid or disabled grid until the data is restored and migrated.
+ val spec = getSpecIgnoringDimensionType(availableSpace, specsGroup)
+ check(spec != null) { "No available spec found within $availableSpace. $specsGroup" }
+ // val spec = specsGroup.getSpec(dimensionType, availableSpace)
return CalculatedHotseatSpec(availableSpace, spec)
}
diff --git a/src/com/android/launcher3/responsive/ResponsiveSpecGroup.kt b/src/com/android/launcher3/responsive/ResponsiveSpecGroup.kt
index b233d7c..a758be8 100644
--- a/src/com/android/launcher3/responsive/ResponsiveSpecGroup.kt
+++ b/src/com/android/launcher3/responsive/ResponsiveSpecGroup.kt
@@ -18,6 +18,7 @@
import android.content.res.TypedArray
import com.android.launcher3.R
+import com.android.launcher3.responsive.ResponsiveSpec.Companion.ResponsiveSpecType
import com.android.launcher3.responsive.ResponsiveSpec.DimensionType
/**
@@ -54,10 +55,29 @@
} else {
heightSpecs.firstOrNull { availableSize <= it.maxAvailableSize }
}
- check(spec != null) { "No available $type spec found within $availableSize." }
+ check(spec != null) { "No available $type spec found within $availableSize. $this" }
return spec
}
+ override fun toString(): String {
+ fun printSpec(spec: IResponsiveSpec) =
+ when (spec.specType) {
+ ResponsiveSpecType.AllApps,
+ ResponsiveSpecType.Folder,
+ ResponsiveSpecType.Workspace -> (spec as ResponsiveSpec).toString()
+ ResponsiveSpecType.Hotseat -> (spec as HotseatSpec).toString()
+ ResponsiveSpecType.Cell -> (spec as CellSpec).toString()
+ }
+
+ val widthSpecsString = widthSpecs.joinToString(", ") { printSpec(it) }
+ val heightSpecsString = heightSpecs.joinToString(", ") { printSpec(it) }
+ return "ResponsiveSpecGroup(" +
+ "aspectRatio=${aspectRatio}, " +
+ "widthSpecs=[${widthSpecsString}], " +
+ "heightSpecs=[${heightSpecsString}]" +
+ ")"
+ }
+
companion object {
const val XML_GROUP_NAME = "specs"