Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.app.servertransaction; |
| 18 | |
| 19 | import android.annotation.IntDef; |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 20 | import android.os.Parcel; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 21 | |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 22 | import java.io.PrintWriter; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 23 | import java.lang.annotation.Retention; |
| 24 | import java.lang.annotation.RetentionPolicy; |
| 25 | |
| 26 | /** |
| 27 | * Request for lifecycle state that an activity should reach. |
| 28 | * @hide |
| 29 | */ |
| 30 | public abstract class ActivityLifecycleItem extends ClientTransactionItem { |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 31 | private String mDescription; |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 32 | |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 33 | @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 Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 44 | @Retention(RetentionPolicy.SOURCE) |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 45 | public @interface LifecycleState{} |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 46 | public static final int UNDEFINED = -1; |
Andrii Kulian | 88e05cb | 2017-12-05 17:21:10 -0800 | [diff] [blame] | 47 | 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 Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 55 | |
| 56 | /** A final lifecycle state that an activity should reach. */ |
| 57 | @LifecycleState |
| 58 | public abstract int getTargetState(); |
Bryce Lee | d946f86 | 2018-01-16 15:59:47 -0800 | [diff] [blame] | 59 | |
| 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 Lee | f52974c | 2018-02-14 15:12:01 -0800 | [diff] [blame] | 94 | |
| 95 | @Override |
| 96 | public void recycle() { |
| 97 | setDescription(null); |
| 98 | } |
Andrii Kulian | 446e824 | 2017-10-26 15:17:29 -0700 | [diff] [blame] | 99 | } |