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.net.metrics;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.compat.annotation.UnsupportedAppUsage;
23 import android.os.Build;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 import android.text.TextUtils;
27 
28 /**
29  * An event recorded when a DhcpClient state machine transitions to a new state.
30  * {@hide}
31  * @deprecated The event may not be sent in Android S and above. The events
32  * are logged by a single caller in the system using signature permissions
33  * and that caller is migrating to statsd.
34  */
35 @Deprecated
36 @SystemApi
37 public final class DhcpClientEvent implements IpConnectivityLog.Event {
38 
39     // Names for recording DhcpClient pseudo-state transitions.
40 
41     /** @hide */
42     public final String msg;
43     /** @hide */
44     public final int durationMs;
45 
46     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
DhcpClientEvent(String msg, int durationMs)47     private DhcpClientEvent(String msg, int durationMs) {
48         this.msg = msg;
49         this.durationMs = durationMs;
50     }
51 
DhcpClientEvent(Parcel in)52     private DhcpClientEvent(Parcel in) {
53         this.msg = in.readString();
54         this.durationMs = in.readInt();
55     }
56 
57     /**
58      * Utility to create an instance of {@link ApfProgramEvent}.
59      */
60     public static final class Builder {
61         private String mMsg;
62         private int mDurationMs;
63 
64         /**
65          * Set the message of the event.
66          */
67         @NonNull
setMsg(String msg)68         public Builder setMsg(String msg) {
69             mMsg = msg;
70             return this;
71         }
72 
73         /**
74          * Set the duration of the event in milliseconds.
75          */
76         @NonNull
setDurationMs(int durationMs)77         public Builder setDurationMs(int durationMs) {
78             mDurationMs = durationMs;
79             return this;
80         }
81 
82         /**
83          * Create a new {@link DhcpClientEvent}.
84          */
85         @NonNull
build()86         public DhcpClientEvent build() {
87             return new DhcpClientEvent(mMsg, mDurationMs);
88         }
89     }
90 
91     /** @hide */
92     @Override
writeToParcel(Parcel out, int flags)93     public void writeToParcel(Parcel out, int flags) {
94         out.writeString(msg);
95         out.writeInt(durationMs);
96     }
97 
98     /** @hide */
99     @Override
describeContents()100     public int describeContents() {
101         return 0;
102     }
103 
104     @NonNull
105     @Override
toString()106     public String toString() {
107         return String.format("DhcpClientEvent(%s, %dms)", msg, durationMs);
108     }
109 
110     @Override
equals(@ullable Object obj)111     public boolean equals(@Nullable Object obj) {
112         if (obj == null || !(obj.getClass().equals(DhcpClientEvent.class))) return false;
113         final DhcpClientEvent other = (DhcpClientEvent) obj;
114         return TextUtils.equals(msg, other.msg)
115                 && durationMs == other.durationMs;
116     }
117 
118     /** @hide */
119     public static final @android.annotation.NonNull Parcelable.Creator<DhcpClientEvent> CREATOR
120         = new Parcelable.Creator<DhcpClientEvent>() {
121         public DhcpClientEvent createFromParcel(Parcel in) {
122             return new DhcpClientEvent(in);
123         }
124 
125         public DhcpClientEvent[] newArray(int size) {
126             return new DhcpClientEvent[size];
127         }
128     };
129 }
130