1 /*
2  * Copyright 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 
17 package androidx.xr.runtime.internal
18 
19 import androidx.annotation.RestrictTo
20 import kotlin.time.ComparableTimeMark
21 
22 /** Describes the lifecycle a runtime implementation. */
23 @Suppress("NotCloseable")
24 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
25 public interface LifecycleManager {
26     /**
27      * Executes the [Runtime] initialization logic. It is necessary to call [resume] after calling
28      * this method to start the runtime's execution logic.
29      */
createnull30     public fun create()
31 
32     /** The current state of the runtime configuration. */
33     public val config: Config
34 
35     /**
36      * Sets or changes the configuration to use, which will affect the availability of properties or
37      * features in other managers. It is necessary to have called [create] before calling this
38      * method.
39      */
40     public fun configure(config: Config)
41 
42     /**
43      * Resumes execution from a paused or init state. It is necessary to have called [create] before
44      * calling this method.
45      */
46     public fun resume()
47 
48     /**
49      * Updates the state of the system. The call is blocking and will return once the underlying
50      * implementation has been updated or a platform-specific timeout has been reached. This method
51      * can only be called when the runtime is resumed.
52      *
53      * @return the timemark of the latest state. This value is to be used for comparison with other
54      *   timemarks and not to be used for absolute time calculations.
55      */
56     public suspend fun update(): ComparableTimeMark
57 
58     /** Pauses execution while retaining the state in memory. */
59     public fun pause()
60 
61     /**
62      * Stops the execution and releases all resources. It is not valid to call any other method
63      * after calling [stop]. The runtime must not be resumed when this method is called.
64      */
65     public fun stop()
66 }
67