1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 package com.android.systemui.keyguard.shared.model 17 18 import android.util.Log 19 import com.android.compose.animation.scene.SceneKey 20 import com.android.systemui.keyguard.shared.model.KeyguardState.UNDEFINED 21 import com.android.systemui.scene.shared.flag.SceneContainerFlag 22 23 /** 24 * Represents an edge either between two Keyguard Transition Framework states (KTF) or a KTF state 25 * and a scene container scene. Passing [null] in either [from] or [to] indicates a wildcard. 26 */ 27 sealed class Edge { 28 verifyValidKeyguardStatesnull29 fun verifyValidKeyguardStates() { 30 when (this) { 31 is StateToState -> verifyValidKeyguardStates(from, to) 32 is SceneToState -> verifyValidKeyguardStates(null, to) 33 is StateToScene -> verifyValidKeyguardStates(from, null) 34 } 35 } 36 verifyValidKeyguardStatesnull37 private fun verifyValidKeyguardStates(from: KeyguardState?, to: KeyguardState?) { 38 val mappedFrom = from?.mapToSceneContainerState() 39 val mappedTo = to?.mapToSceneContainerState() 40 41 val fromChanged = from != mappedFrom 42 val toChanged = to != mappedTo 43 44 if (SceneContainerFlag.isEnabled) { 45 if (fromChanged && toChanged) { 46 // TODO:(b/330311871) As we come close to having all current edges converted these 47 // error messages can be converted to throw such that future developers fail early 48 // when they introduce invalid edges. 49 Log.e( 50 TAG, 51 """ 52 The edge ${from?.name} => ${to?.name} was automatically converted to 53 ${mappedFrom?.name} => ${mappedTo?.name} but does not exist anymore in KTF. 54 Please remove or port this edge to scene container.""" 55 .trimIndent(), 56 ) 57 } else if (fromChanged || toChanged) { 58 Log.w( 59 TAG, 60 """ 61 The edge ${from?.name} => ${to?.name} was automatically converted to 62 ${mappedFrom?.name} => ${mappedTo?.name} it probably exists but needs explicit 63 conversion. Please remove or port this edge to scene container.""" 64 .trimIndent(), 65 ) 66 } 67 } else { 68 if (from == UNDEFINED || to == UNDEFINED) { 69 Log.e( 70 TAG, 71 "UNDEFINED should not be used when scene container is disabled", 72 ) 73 } 74 } 75 } 76 isSceneWildcardEdgenull77 fun isSceneWildcardEdge(): Boolean { 78 return when (this) { 79 is StateToState -> false 80 is SceneToState -> to == null 81 is StateToScene -> from == null 82 } 83 } 84 85 data class StateToState(val from: KeyguardState?, val to: KeyguardState?) : Edge() { 86 87 init { <lambda>null88 check(!(from == null && to == null)) { "to and from can't both be null" } 89 } 90 } 91 92 data class StateToScene(val from: KeyguardState? = null, val to: SceneKey) : Edge() 93 94 data class SceneToState(val from: SceneKey, val to: KeyguardState? = null) : Edge() 95 96 companion object { 97 private const val TAG = "Edge" 98 99 @JvmStatic 100 @JvmOverloads createnull101 fun create(from: KeyguardState? = null, to: KeyguardState? = null) = StateToState(from, to) 102 103 @JvmStatic 104 @JvmOverloads 105 fun create(from: KeyguardState? = null, to: SceneKey) = StateToScene(from, to) 106 107 @JvmStatic 108 @JvmOverloads 109 fun create(from: SceneKey, to: KeyguardState? = null) = SceneToState(from, to) 110 111 /** 112 * This edge is a placeholder for when an edge needs to be passed but there is no edge for 113 * this flag configuration available. Usually for Scene <-> Scene edges with scene container 114 * enabled where these edges are managed by STL separately. 115 */ 116 val INVALID = StateToState(UNDEFINED, UNDEFINED) 117 } 118 } 119