blob: 5f9f50708a49711330ea761784dd8fa55a3b666a [file] [log] [blame]
Pierre Imai55618be2016-02-19 15:25:54 +09001/*
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.net.metrics;
18
paulhu79b380c2019-03-15 17:17:02 +080019import android.annotation.NonNull;
Aurimas Liutikas4d1699d2019-08-28 13:01:05 -070020import android.annotation.Nullable;
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090021import android.annotation.SystemApi;
22import android.annotation.TestApi;
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010023import android.annotation.UnsupportedAppUsage;
Pierre Imai55618be2016-02-19 15:25:54 +090024import android.os.Parcel;
25import android.os.Parcelable;
paulhuf32da692019-04-18 15:24:48 +080026import android.text.TextUtils;
Pierre Imai55618be2016-02-19 15:25:54 +090027
Pierre Imaibc9cc502016-03-29 14:50:51 +090028/**
Hugo Benichi76434232016-07-07 11:28:54 +090029 * An event recorded when a DhcpClient state machine transitions to a new state.
Pierre Imaibc9cc502016-03-29 14:50:51 +090030 * {@hide}
31 */
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090032@SystemApi
33@TestApi
34public final class DhcpClientEvent implements IpConnectivityLog.Event {
Hugo Benichi76434232016-07-07 11:28:54 +090035
36 // Names for recording DhcpClient pseudo-state transitions.
Hugo Benichi76434232016-07-07 11:28:54 +090037
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090038 /** @hide */
Hugo Benichi627b4242016-04-15 16:56:28 +090039 public final String msg;
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090040 /** @hide */
Hugo Benichi176ed012016-07-01 10:06:56 +090041 public final int durationMs;
Pierre Imai55618be2016-02-19 15:25:54 +090042
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010043 @UnsupportedAppUsage
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090044 private DhcpClientEvent(String msg, int durationMs) {
Hugo Benichi627b4242016-04-15 16:56:28 +090045 this.msg = msg;
Hugo Benichi176ed012016-07-01 10:06:56 +090046 this.durationMs = durationMs;
Pierre Imai55618be2016-02-19 15:25:54 +090047 }
48
Hugo Benichi627b4242016-04-15 16:56:28 +090049 private DhcpClientEvent(Parcel in) {
Hugo Benichi627b4242016-04-15 16:56:28 +090050 this.msg = in.readString();
Hugo Benichi176ed012016-07-01 10:06:56 +090051 this.durationMs = in.readInt();
Pierre Imai55618be2016-02-19 15:25:54 +090052 }
53
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090054 /**
55 * Utility to create an instance of {@link ApfProgramEvent}.
56 */
paulhu79b380c2019-03-15 17:17:02 +080057 public static final class Builder {
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090058 private String mMsg;
59 private int mDurationMs;
60
61 /**
62 * Set the message of the event.
63 */
paulhu79b380c2019-03-15 17:17:02 +080064 @NonNull
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090065 public Builder setMsg(String msg) {
66 mMsg = msg;
67 return this;
68 }
69
70 /**
71 * Set the duration of the event in milliseconds.
72 */
paulhu79b380c2019-03-15 17:17:02 +080073 @NonNull
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090074 public Builder setDurationMs(int durationMs) {
75 mDurationMs = durationMs;
76 return this;
77 }
78
79 /**
80 * Create a new {@link DhcpClientEvent}.
81 */
paulhu79b380c2019-03-15 17:17:02 +080082 @NonNull
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090083 public DhcpClientEvent build() {
84 return new DhcpClientEvent(mMsg, mDurationMs);
85 }
86 }
87
88 /** @hide */
Hugo Benichi176ed012016-07-01 10:06:56 +090089 @Override
Pierre Imai55618be2016-02-19 15:25:54 +090090 public void writeToParcel(Parcel out, int flags) {
Hugo Benichi627b4242016-04-15 16:56:28 +090091 out.writeString(msg);
Hugo Benichi176ed012016-07-01 10:06:56 +090092 out.writeInt(durationMs);
Hugo Benichi627b4242016-04-15 16:56:28 +090093 }
94
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090095 /** @hide */
Hugo Benichi176ed012016-07-01 10:06:56 +090096 @Override
Hugo Benichi627b4242016-04-15 16:56:28 +090097 public int describeContents() {
98 return 0;
Pierre Imai55618be2016-02-19 15:25:54 +090099 }
100
Aurimas Liutikas4d1699d2019-08-28 13:01:05 -0700101 @NonNull
Hugo Benichi5df9d722016-04-25 17:16:35 +0900102 @Override
103 public String toString() {
Hugo Benichi948a8592017-03-16 16:33:47 +0900104 return String.format("DhcpClientEvent(%s, %dms)", msg, durationMs);
Hugo Benichi5df9d722016-04-25 17:16:35 +0900105 }
106
paulhuf32da692019-04-18 15:24:48 +0800107 @Override
Aurimas Liutikas4d1699d2019-08-28 13:01:05 -0700108 public boolean equals(@Nullable Object obj) {
paulhuf32da692019-04-18 15:24:48 +0800109 if (obj == null || !(obj.getClass().equals(DhcpClientEvent.class))) return false;
110 final DhcpClientEvent other = (DhcpClientEvent) obj;
111 return TextUtils.equals(msg, other.msg)
112 && durationMs == other.durationMs;
113 }
114
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +0900115 /** @hide */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700116 public static final @android.annotation.NonNull Parcelable.Creator<DhcpClientEvent> CREATOR
Pierre Imai55618be2016-02-19 15:25:54 +0900117 = new Parcelable.Creator<DhcpClientEvent>() {
118 public DhcpClientEvent createFromParcel(Parcel in) {
119 return new DhcpClientEvent(in);
120 }
121
122 public DhcpClientEvent[] newArray(int size) {
123 return new DhcpClientEvent[size];
124 }
125 };
Hugo Benichicfddd682016-05-31 16:28:06 +0900126}