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

Commit bab373b4 authored by George Lin's avatar George Lin Committed by Android Build Coastguard Worker
Browse files

Make shape grid manager fail safely

Isntead of crashing the app. We will only hide the options.

Test: Manully tested that the entry are hidden.
Bug: 423907335
Flag: com.android.systemui.shared.new_customization_picker_ui
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:356b5e9d41bb6ce182f70fa25c4dbe338f73a0bd)
Merged-In: I855ecd68a3adbf3c78a588173c605454870b75de
Change-Id: I855ecd68a3adbf3c78a588173c605454870b75de
parent 893e5118
Loading
Loading
Loading
Loading
+24 −18
Original line number Diff line number Diff line
@@ -154,20 +154,23 @@ constructor(
                    }
                }
                .let { list ->
                    val selectedOptionCount = list.count { it.isCurrent }
                    if (list.isEmpty()) {
                        throw IllegalStateException(
                            "Grid option list can not be empty. It needs to have at least one item."
                        Log.e(
                            TAG,
                            "Grid option list can not be empty. It needs to have at least one item.",
                        )
                    }
                    // In this list, exactly one item should have isCurrent true.
                    val isCurrentCount = list.count { it.isCurrent }
                    if (isCurrentCount != 1) {
                        throw IllegalStateException(
                            "Exactly one grid option should have isCurrent = true. Found $isCurrentCount."
                        emptyList()
                    } else if (selectedOptionCount != 1) {
                        Log.e(
                            TAG,
                            "Exactly one grid option should have isCurrent = true. Found $selectedOptionCount.",
                        )
                    }
                        emptyList()
                    } else {
                        list
                    }
                }
                .sortedByDescending { it.rows * it.cols }
        } ?: emptyList()
    }
@@ -204,20 +207,23 @@ constructor(
                                }
                            }
                            .let { list ->
                                val selectedOptionCount = list.count { it.isCurrent }
                                if (list.isEmpty()) {
                                    throw IllegalStateException(
                                        "Shape option list can not be empty. It needs to have at least one item."
                                    Log.e(
                                        TAG,
                                        "Shape option list can not be empty. It needs to have at least one item.",
                                    )
                                }
                                // In this list, exactly one item should have isCurrent true.
                                val isCurrentCount = list.count { it.isCurrent }
                                if (isCurrentCount != 1) {
                                    throw IllegalStateException(
                                        "Exactly one shape option should have isCurrent = true. Found $isCurrentCount."
                                    emptyList()
                                } else if (selectedOptionCount != 1) {
                                    Log.e(
                                        TAG,
                                        "Exactly one shape option should have isCurrent = true. Found $selectedOptionCount.",
                                    )
                                }
                                    emptyList()
                                } else {
                                    list
                                }
                            }
                    } ?: emptyList()
            } else {
                emptyList()