blob: 7f8c50cd4ce5d9109e9b143d79a9cf7c87eb579b [file] [log] [blame]
Andrii Kulian446e8242017-10-26 15:17:29 -07001/*
2 * Copyright 2017 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
17package android.app.servertransaction;
18
19import android.annotation.IntDef;
Bryce Leed946f862018-01-16 15:59:47 -080020import android.os.Parcel;
Andrii Kulian446e8242017-10-26 15:17:29 -070021
Bryce Leed946f862018-01-16 15:59:47 -080022import java.io.PrintWriter;
Andrii Kulian446e8242017-10-26 15:17:29 -070023import java.lang.annotation.Retention;
24import java.lang.annotation.RetentionPolicy;
25
26/**
27 * Request for lifecycle state that an activity should reach.
28 * @hide
29 */
30public abstract class ActivityLifecycleItem extends ClientTransactionItem {
Bryce Leed946f862018-01-16 15:59:47 -080031 private String mDescription;
Andrii Kulian446e8242017-10-26 15:17:29 -070032
Jeff Sharkeyce8db992017-12-13 20:05:05 -070033 @IntDef(prefix = { "UNDEFINED", "PRE_", "ON_" }, value = {
34 UNDEFINED,
35 PRE_ON_CREATE,
36 ON_CREATE,
37 ON_START,
38 ON_RESUME,
39 ON_PAUSE,
40 ON_STOP,
41 ON_DESTROY,
42 ON_RESTART
43 })
Andrii Kulian446e8242017-10-26 15:17:29 -070044 @Retention(RetentionPolicy.SOURCE)
Andrii Kulian88e05cb2017-12-05 17:21:10 -080045 public @interface LifecycleState{}
Andrii Kulian446e8242017-10-26 15:17:29 -070046 public static final int UNDEFINED = -1;
Andrii Kulian88e05cb2017-12-05 17:21:10 -080047 public static final int PRE_ON_CREATE = 0;
48 public static final int ON_CREATE = 1;
49 public static final int ON_START = 2;
50 public static final int ON_RESUME = 3;
51 public static final int ON_PAUSE = 4;
52 public static final int ON_STOP = 5;
53 public static final int ON_DESTROY = 6;
54 public static final int ON_RESTART = 7;
Andrii Kulian446e8242017-10-26 15:17:29 -070055
56 /** A final lifecycle state that an activity should reach. */
57 @LifecycleState
58 public abstract int getTargetState();
Bryce Leed946f862018-01-16 15:59:47 -080059
60
61 protected ActivityLifecycleItem() {
62 }
63
64 protected ActivityLifecycleItem(Parcel in) {
65 mDescription = in.readString();
66 }
67
68 @Override
69 public void writeToParcel(Parcel dest, int flags) {
70 dest.writeString(mDescription);
71 }
72
73 /**
74 * Sets a description that can be retrieved later for debugging purposes.
75 * @param description Description to set.
76 * @return The {@link ActivityLifecycleItem}.
77 */
78 public ActivityLifecycleItem setDescription(String description) {
79 mDescription = description;
80 return this;
81 }
82
83 /**
84 * Retrieves description if set through {@link #setDescription(String)}.
85 */
86 public String getDescription() {
87 return mDescription;
88 }
89
90 void dump(PrintWriter pw, String prefix) {
91 pw.println(prefix + "target state:" + getTargetState());
92 pw.println(prefix + "description: " + mDescription);
93 }
Bryce Leef52974c2018-02-14 15:12:01 -080094
95 @Override
96 public void recycle() {
97 setDescription(null);
98 }
Andrii Kulian446e8242017-10-26 15:17:29 -070099}