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

Commit 99949506 authored by Massimo Carli's avatar Massimo Carli
Browse files

[4/n] Create first state and handle comp lifecycle

We define the lifecycle for each Compat UI component
using the predicates defind in CompatUISpec.

Define the concept of shared and component specific states.

Flag: com.android.window.flags.app_compat_ui_framework
Bug: 270361630
Fix: 322817374
Test: atest WMShellUnitTests:DefaultCompatUIHandlerTest

Change-Id: I948cc690fd03bd0f16ea0740da9c3a0a5fe24f9a
parent 4b85f98d
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.compatui.api

import android.util.Log

/**
 * The component created after a {@link CompatUISpec} definition
 */
class CompatUIComponent(
    private val spec: CompatUISpec,
    private val id: String
) {

    /**
     * Invoked every time a new CompatUIInfo comes from core
     * @param newInfo The new CompatUIInfo object
     * @param sharedState The state shared between all the component
     */
    fun update(newInfo: CompatUIInfo, state: CompatUIState) {
        // TODO(b/322817374): To be removed when the implementation is provided.
        Log.d("CompatUIComponent", "update() newInfo: $newInfo state:$state")
    }

    fun release() {
        // TODO(b/322817374): To be removed when the implementation is provided.
        Log.d("CompatUIComponent", "release()")
    }
}
 No newline at end of file
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.compatui.api

/**
 * Any object responsible to generate an id for a component.
 */
interface CompatUIComponentIdGenerator {

    /**
     * Generates the unique id for a component given a {@link CompatUIInfo} and component
     * {@link CompatUISpec}.
     * @param compatUIInfo  The object encapsulating information about the current Task.
     * @param spec  The {@link CompatUISpec} for the component.
     */
    fun generateId(compatUIInfo: CompatUIInfo, spec: CompatUISpec): String
}
+24 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.compatui.api

/**
 * Abstraction of all the component specific state. Each
 * component can create its own state implementing this
 * tagging interface.
 */
interface CompatUIComponentState
 No newline at end of file
+22 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.compatui.api

/**
 * Represents the state shared between all the components.
 */
class CompatUISharedState
 No newline at end of file
+24 −3
Original line number Diff line number Diff line
@@ -16,11 +16,32 @@

package com.android.wm.shell.compatui.api

/**
 * Defines the predicates to invoke for understanding if a component can be created or destroyed.
 */
class CompatUILifecyclePredicates(
    // Predicate evaluating to true if the component needs to be created
    val creationPredicate: (CompatUIInfo, CompatUISharedState) -> Boolean,
    // Predicate evaluating to true if the component needs to be destroyed
    val removalPredicate: (
        CompatUIInfo,
        CompatUISharedState,
        CompatUIComponentState?
    ) -> Boolean,
    // Builder for the initial state of the component
    val stateBuilder: (
        CompatUIInfo,
        CompatUISharedState
    ) -> CompatUIComponentState? = { _, _ -> null }
)

/**
 * Describes each compat ui component to the framework.
 */
data class CompatUISpec(
class CompatUISpec(
    // Unique name for the component. It's used for debug and for generating the
    // unique component identifier in the system.
    val name: String
    val name: String,
    // The lifecycle definition
    val lifecycle: CompatUILifecyclePredicates
)
Loading