Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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; |
| 18 | |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
| 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 24 | import java.io.PrintWriter; |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 25 | import java.lang.annotation.Retention; |
| 26 | import java.lang.annotation.RetentionPolicy; |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 27 | |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Information returned after waiting for an activity start. |
| 30 | * |
| 31 | * @hide |
| 32 | */ |
| 33 | public class WaitResult implements Parcelable { |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * The state at which a launch sequence had started. |
| 37 | * |
| 38 | * @see <a href="https://developer.android.com/topic/performance/vitals/launch-time"App startup |
| 39 | * time</a> |
| 40 | */ |
| 41 | @Retention(RetentionPolicy.SOURCE) |
| 42 | @IntDef(prefix = {"LAUNCH_STATE_"}, value = { |
| 43 | LAUNCH_STATE_COLD, |
| 44 | LAUNCH_STATE_WARM, |
| 45 | LAUNCH_STATE_HOT |
| 46 | }) |
| 47 | public @interface LaunchState { |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Cold launch sequence: a new process has started. |
| 52 | */ |
| 53 | public static final int LAUNCH_STATE_COLD = 1; |
| 54 | |
| 55 | /** |
| 56 | * Warm launch sequence: process reused, but activity has to be created. |
| 57 | */ |
| 58 | public static final int LAUNCH_STATE_WARM = 2; |
| 59 | |
| 60 | /** |
| 61 | * Hot launch sequence: process reused, activity brought-to-top. |
| 62 | */ |
| 63 | public static final int LAUNCH_STATE_HOT = 3; |
| 64 | |
Vishnu Nair | 132ee83 | 2018-09-28 15:00:05 -0700 | [diff] [blame] | 65 | public static final int INVALID_DELAY = -1; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 66 | public int result; |
| 67 | public boolean timeout; |
| 68 | public ComponentName who; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 69 | public long totalTime; |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 70 | public @LaunchState int launchState; |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 71 | |
| 72 | public WaitResult() { |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public int describeContents() { |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public void writeToParcel(Parcel dest, int flags) { |
| 82 | dest.writeInt(result); |
| 83 | dest.writeInt(timeout ? 1 : 0); |
| 84 | ComponentName.writeToParcel(who, dest); |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 85 | dest.writeLong(totalTime); |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 86 | dest.writeInt(launchState); |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 89 | public static final @android.annotation.NonNull Parcelable.Creator<WaitResult> CREATOR |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 90 | = new Parcelable.Creator<WaitResult>() { |
| 91 | @Override |
| 92 | public WaitResult createFromParcel(Parcel source) { |
| 93 | return new WaitResult(source); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public WaitResult[] newArray(int size) { |
| 98 | return new WaitResult[size]; |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | private WaitResult(Parcel source) { |
| 103 | result = source.readInt(); |
| 104 | timeout = source.readInt() != 0; |
| 105 | who = ComponentName.readFromParcel(source); |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 106 | totalTime = source.readLong(); |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 107 | launchState = source.readInt(); |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 108 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 109 | |
| 110 | public void dump(PrintWriter pw, String prefix) { |
| 111 | pw.println(prefix + "WaitResult:"); |
| 112 | pw.println(prefix + " result=" + result); |
| 113 | pw.println(prefix + " timeout=" + timeout); |
| 114 | pw.println(prefix + " who=" + who); |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 115 | pw.println(prefix + " totalTime=" + totalTime); |
Vishnu Nair | bb9ab4b | 2018-12-13 10:29:46 -0800 | [diff] [blame] | 116 | pw.println(prefix + " launchState=" + launchState); |
| 117 | } |
| 118 | |
| 119 | public static String launchStateToString(@LaunchState int type) { |
| 120 | switch (type) { |
| 121 | case LAUNCH_STATE_COLD: |
| 122 | return "COLD"; |
| 123 | case LAUNCH_STATE_WARM: |
| 124 | return "WARM"; |
| 125 | case LAUNCH_STATE_HOT: |
| 126 | return "HOT"; |
| 127 | default: |
| 128 | return "UNKNOWN (" + type + ")"; |
| 129 | } |
Bryce Lee | 4a19438 | 2017-04-04 14:32:48 -0700 | [diff] [blame] | 130 | } |
Sudheer Shanka | fc46e9b | 2016-10-21 17:55:27 -0700 | [diff] [blame] | 131 | } |