Home | History | Annotate | Download | only in app
      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_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 
     65     public static final int INVALID_DELAY = -1;
     66     public int result;
     67     public boolean timeout;
     68     public ComponentName who;
     69     public long totalTime;
     70     public @LaunchState int launchState;
     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);
     85         dest.writeLong(totalTime);
     86         dest.writeInt(launchState);
     87     }
     88 
     89     public static final @android.annotation.NonNull Parcelable.Creator<WaitResult> CREATOR
     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);
    106         totalTime = source.readLong();
    107         launchState = source.readInt();
    108     }
    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);
    115         pw.println(prefix + "  totalTime=" + totalTime);
    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         }
    130     }
    131 }