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 19 import android.annotation.IntDef; 20 import android.content.ComponentName; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.io.PrintWriter; 25 import java.lang.annotation.Retention; 26 import java.lang.annotation.RetentionPolicy; 27 28 /** 29 * Information returned after waiting for an activity start. 30 * 31 * @hide 32 */ 33 public class WaitResult implements Parcelable { 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_UNKNOWN, 44 LAUNCH_STATE_COLD, 45 LAUNCH_STATE_WARM, 46 LAUNCH_STATE_HOT, 47 LAUNCH_STATE_RELAUNCH 48 }) 49 public @interface LaunchState { 50 } 51 52 /** 53 * Not considered as a launch event, e.g. the activity is already on top. 54 */ 55 public static final int LAUNCH_STATE_UNKNOWN = 0; 56 57 /** 58 * Cold launch sequence: a new process has started. 59 */ 60 public static final int LAUNCH_STATE_COLD = 1; 61 62 /** 63 * Warm launch sequence: process reused, but activity has to be created. 64 */ 65 public static final int LAUNCH_STATE_WARM = 2; 66 67 /** 68 * Hot launch sequence: process reused, activity brought-to-top. 69 */ 70 public static final int LAUNCH_STATE_HOT = 3; 71 72 /** 73 * Relaunch launch sequence: process reused, but activity has to be destroyed and created. 74 * E.g. the current device configuration is different from the background activity that will be 75 * brought to foreground, and the activity doesn't declare to handle the change. 76 */ 77 public static final int LAUNCH_STATE_RELAUNCH = 4; 78 79 public static final int INVALID_DELAY = -1; 80 public int result; 81 public boolean timeout; 82 public ComponentName who; 83 public long totalTime; 84 public @LaunchState int launchState; 85 WaitResult()86 public WaitResult() { 87 } 88 89 @Override describeContents()90 public int describeContents() { 91 return 0; 92 } 93 94 @Override writeToParcel(Parcel dest, int flags)95 public void writeToParcel(Parcel dest, int flags) { 96 dest.writeInt(result); 97 dest.writeInt(timeout ? 1 : 0); 98 ComponentName.writeToParcel(who, dest); 99 dest.writeLong(totalTime); 100 dest.writeInt(launchState); 101 } 102 103 public static final @android.annotation.NonNull Parcelable.Creator<WaitResult> CREATOR 104 = new Parcelable.Creator<WaitResult>() { 105 @Override 106 public WaitResult createFromParcel(Parcel source) { 107 return new WaitResult(source); 108 } 109 110 @Override 111 public WaitResult[] newArray(int size) { 112 return new WaitResult[size]; 113 } 114 }; 115 WaitResult(Parcel source)116 private WaitResult(Parcel source) { 117 result = source.readInt(); 118 timeout = source.readInt() != 0; 119 who = ComponentName.readFromParcel(source); 120 totalTime = source.readLong(); 121 launchState = source.readInt(); 122 } 123 dump(PrintWriter pw, String prefix)124 public void dump(PrintWriter pw, String prefix) { 125 pw.println(prefix + "WaitResult:"); 126 pw.println(prefix + " result=" + result); 127 pw.println(prefix + " timeout=" + timeout); 128 pw.println(prefix + " who=" + who); 129 pw.println(prefix + " totalTime=" + totalTime); 130 pw.println(prefix + " launchState=" + launchState); 131 } 132 launchStateToString(@aunchState int type)133 public static String launchStateToString(@LaunchState int type) { 134 switch (type) { 135 case LAUNCH_STATE_COLD: 136 return "COLD"; 137 case LAUNCH_STATE_WARM: 138 return "WARM"; 139 case LAUNCH_STATE_HOT: 140 return "HOT"; 141 case LAUNCH_STATE_RELAUNCH: 142 return "RELAUNCH"; 143 default: 144 return "UNKNOWN (" + type + ")"; 145 } 146 } 147 }