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

Commit 7808efbb authored by Jordan Silva's avatar Jordan Silva Committed by Android (Google) Code Review
Browse files

Merge "Fix crash when restoring data from phone to tablet with responsive grid" into main

parents fd309ca3 ce396d8a
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -40,13 +40,28 @@ class HotseatSpecsProvider(groupOfSpecs: List<ResponsiveSpecGroup<HotseatSpec>>)
        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)
    }

+21 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.launcher3.responsive

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 @@ class ResponsiveSpecGroup<T : IResponsiveSpec>(
            } 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"