blob: d65be9bded4fbe2fb0581946ff4cf2b6f3282364 [file] [log] [blame]
Sudheer Shankafc46e9b2016-10-21 17:55:27 -07001/*
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
17package android.app;
18
Vishnu Nairbb9ab4b2018-12-13 10:29:46 -080019import android.annotation.IntDef;
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070020import android.content.ComponentName;
21import android.os.Parcel;
22import android.os.Parcelable;
23
Bryce Lee4a194382017-04-04 14:32:48 -070024import java.io.PrintWriter;
Vishnu Nairbb9ab4b2018-12-13 10:29:46 -080025import java.lang.annotation.Retention;
26import java.lang.annotation.RetentionPolicy;
Bryce Lee4a194382017-04-04 14:32:48 -070027
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070028/**
29 * Information returned after waiting for an activity start.
30 *
31 * @hide
32 */
33public class WaitResult implements Parcelable {
Vishnu Nairbb9ab4b2018-12-13 10:29:46 -080034
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 Nair132ee832018-09-28 15:00:05 -070065 public static final int INVALID_DELAY = -1;
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070066 public int result;
67 public boolean timeout;
68 public ComponentName who;
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070069 public long totalTime;
Vishnu Nairbb9ab4b2018-12-13 10:29:46 -080070 public @LaunchState int launchState;
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070071
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 Shankafc46e9b2016-10-21 17:55:27 -070085 dest.writeLong(totalTime);
Vishnu Nairbb9ab4b2018-12-13 10:29:46 -080086 dest.writeInt(launchState);
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070087 }
88
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070089 public static final @android.annotation.NonNull Parcelable.Creator<WaitResult> CREATOR
Sudheer Shankafc46e9b2016-10-21 17:55:27 -070090 = 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 Shankafc46e9b2016-10-21 17:55:27 -0700106 totalTime = source.readLong();
Vishnu Nairbb9ab4b2018-12-13 10:29:46 -0800107 launchState = source.readInt();
Sudheer Shankafc46e9b2016-10-21 17:55:27 -0700108 }
Bryce Lee4a194382017-04-04 14:32:48 -0700109
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 Lee4a194382017-04-04 14:32:48 -0700115 pw.println(prefix + " totalTime=" + totalTime);
Vishnu Nairbb9ab4b2018-12-13 10:29:46 -0800116 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 Lee4a194382017-04-04 14:32:48 -0700130 }
Sudheer Shankafc46e9b2016-10-21 17:55:27 -0700131}