blob: 3008115e063b7357d442319c2e9eee74f5803811 [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
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090019import android.annotation.SystemApi;
20import android.annotation.TestApi;
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010021import android.annotation.UnsupportedAppUsage;
Pierre Imai55618be2016-02-19 15:25:54 +090022import android.os.Parcel;
23import android.os.Parcelable;
24
Pierre Imaibc9cc502016-03-29 14:50:51 +090025/**
Hugo Benichi76434232016-07-07 11:28:54 +090026 * An event recorded when a DhcpClient state machine transitions to a new state.
Pierre Imaibc9cc502016-03-29 14:50:51 +090027 * {@hide}
28 */
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090029@SystemApi
30@TestApi
31public final class DhcpClientEvent implements IpConnectivityLog.Event {
Hugo Benichi76434232016-07-07 11:28:54 +090032
33 // Names for recording DhcpClient pseudo-state transitions.
Hugo Benichi76434232016-07-07 11:28:54 +090034
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090035 /** @hide */
Hugo Benichi627b4242016-04-15 16:56:28 +090036 public final String msg;
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090037 /** @hide */
Hugo Benichi176ed012016-07-01 10:06:56 +090038 public final int durationMs;
Pierre Imai55618be2016-02-19 15:25:54 +090039
Mathew Inwoodfa3a7462018-08-08 14:52:47 +010040 @UnsupportedAppUsage
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090041 private DhcpClientEvent(String msg, int durationMs) {
Hugo Benichi627b4242016-04-15 16:56:28 +090042 this.msg = msg;
Hugo Benichi176ed012016-07-01 10:06:56 +090043 this.durationMs = durationMs;
Pierre Imai55618be2016-02-19 15:25:54 +090044 }
45
Hugo Benichi627b4242016-04-15 16:56:28 +090046 private DhcpClientEvent(Parcel in) {
Hugo Benichi627b4242016-04-15 16:56:28 +090047 this.msg = in.readString();
Hugo Benichi176ed012016-07-01 10:06:56 +090048 this.durationMs = in.readInt();
Pierre Imai55618be2016-02-19 15:25:54 +090049 }
50
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090051 /**
52 * Utility to create an instance of {@link ApfProgramEvent}.
53 */
54 public static class Builder {
55 private String mMsg;
56 private int mDurationMs;
57
58 /**
59 * Set the message of the event.
60 */
61 public Builder setMsg(String msg) {
62 mMsg = msg;
63 return this;
64 }
65
66 /**
67 * Set the duration of the event in milliseconds.
68 */
69 public Builder setDurationMs(int durationMs) {
70 mDurationMs = durationMs;
71 return this;
72 }
73
74 /**
75 * Create a new {@link DhcpClientEvent}.
76 */
77 public DhcpClientEvent build() {
78 return new DhcpClientEvent(mMsg, mDurationMs);
79 }
80 }
81
82 /** @hide */
Hugo Benichi176ed012016-07-01 10:06:56 +090083 @Override
Pierre Imai55618be2016-02-19 15:25:54 +090084 public void writeToParcel(Parcel out, int flags) {
Hugo Benichi627b4242016-04-15 16:56:28 +090085 out.writeString(msg);
Hugo Benichi176ed012016-07-01 10:06:56 +090086 out.writeInt(durationMs);
Hugo Benichi627b4242016-04-15 16:56:28 +090087 }
88
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090089 /** @hide */
Hugo Benichi176ed012016-07-01 10:06:56 +090090 @Override
Hugo Benichi627b4242016-04-15 16:56:28 +090091 public int describeContents() {
92 return 0;
Pierre Imai55618be2016-02-19 15:25:54 +090093 }
94
Hugo Benichi5df9d722016-04-25 17:16:35 +090095 @Override
96 public String toString() {
Hugo Benichi948a8592017-03-16 16:33:47 +090097 return String.format("DhcpClientEvent(%s, %dms)", msg, durationMs);
Hugo Benichi5df9d722016-04-25 17:16:35 +090098 }
99
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +0900100 /** @hide */
Pierre Imai55618be2016-02-19 15:25:54 +0900101 public static final Parcelable.Creator<DhcpClientEvent> CREATOR
102 = new Parcelable.Creator<DhcpClientEvent>() {
103 public DhcpClientEvent createFromParcel(Parcel in) {
104 return new DhcpClientEvent(in);
105 }
106
107 public DhcpClientEvent[] newArray(int size) {
108 return new DhcpClientEvent[size];
109 }
110 };
Hugo Benichicfddd682016-05-31 16:28:06 +0900111}