Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 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 | |
paulhu | 79b380c | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
| 22 | import android.annotation.TestApi; |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 23 | import android.annotation.UnsupportedAppUsage; |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 24 | import android.os.Parcel; |
| 25 | import android.os.Parcelable; |
paulhu | f32da69 | 2019-04-18 15:24:48 +0800 | [diff] [blame] | 26 | import android.text.TextUtils; |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 27 | |
Pierre Imai | bc9cc50 | 2016-03-29 14:50:51 +0900 | [diff] [blame] | 28 | /** |
Hugo Benichi | 7643423 | 2016-07-07 11:28:54 +0900 | [diff] [blame] | 29 | * An event recorded when a DhcpClient state machine transitions to a new state. |
Pierre Imai | bc9cc50 | 2016-03-29 14:50:51 +0900 | [diff] [blame] | 30 | * {@hide} |
| 31 | */ |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 32 | @SystemApi |
| 33 | @TestApi |
| 34 | public final class DhcpClientEvent implements IpConnectivityLog.Event { |
Hugo Benichi | 7643423 | 2016-07-07 11:28:54 +0900 | [diff] [blame] | 35 | |
| 36 | // Names for recording DhcpClient pseudo-state transitions. |
Hugo Benichi | 7643423 | 2016-07-07 11:28:54 +0900 | [diff] [blame] | 37 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 38 | /** @hide */ |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 39 | public final String msg; |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 40 | /** @hide */ |
Hugo Benichi | 176ed01 | 2016-07-01 10:06:56 +0900 | [diff] [blame] | 41 | public final int durationMs; |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 42 | |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 43 | @UnsupportedAppUsage |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 44 | private DhcpClientEvent(String msg, int durationMs) { |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 45 | this.msg = msg; |
Hugo Benichi | 176ed01 | 2016-07-01 10:06:56 +0900 | [diff] [blame] | 46 | this.durationMs = durationMs; |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 47 | } |
| 48 | |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 49 | private DhcpClientEvent(Parcel in) { |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 50 | this.msg = in.readString(); |
Hugo Benichi | 176ed01 | 2016-07-01 10:06:56 +0900 | [diff] [blame] | 51 | this.durationMs = in.readInt(); |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 52 | } |
| 53 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 54 | /** |
| 55 | * Utility to create an instance of {@link ApfProgramEvent}. |
| 56 | */ |
paulhu | 79b380c | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 57 | public static final class Builder { |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 58 | private String mMsg; |
| 59 | private int mDurationMs; |
| 60 | |
| 61 | /** |
| 62 | * Set the message of the event. |
| 63 | */ |
paulhu | 79b380c | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 64 | @NonNull |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 65 | public Builder setMsg(String msg) { |
| 66 | mMsg = msg; |
| 67 | return this; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Set the duration of the event in milliseconds. |
| 72 | */ |
paulhu | 79b380c | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 73 | @NonNull |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 74 | public Builder setDurationMs(int durationMs) { |
| 75 | mDurationMs = durationMs; |
| 76 | return this; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Create a new {@link DhcpClientEvent}. |
| 81 | */ |
paulhu | 79b380c | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 82 | @NonNull |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 83 | public DhcpClientEvent build() { |
| 84 | return new DhcpClientEvent(mMsg, mDurationMs); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | /** @hide */ |
Hugo Benichi | 176ed01 | 2016-07-01 10:06:56 +0900 | [diff] [blame] | 89 | @Override |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 90 | public void writeToParcel(Parcel out, int flags) { |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 91 | out.writeString(msg); |
Hugo Benichi | 176ed01 | 2016-07-01 10:06:56 +0900 | [diff] [blame] | 92 | out.writeInt(durationMs); |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 93 | } |
| 94 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 95 | /** @hide */ |
Hugo Benichi | 176ed01 | 2016-07-01 10:06:56 +0900 | [diff] [blame] | 96 | @Override |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 97 | public int describeContents() { |
| 98 | return 0; |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 99 | } |
| 100 | |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 101 | @NonNull |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 102 | @Override |
| 103 | public String toString() { |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 104 | return String.format("DhcpClientEvent(%s, %dms)", msg, durationMs); |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 105 | } |
| 106 | |
paulhu | f32da69 | 2019-04-18 15:24:48 +0800 | [diff] [blame] | 107 | @Override |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 108 | public boolean equals(@Nullable Object obj) { |
paulhu | f32da69 | 2019-04-18 15:24:48 +0800 | [diff] [blame] | 109 | 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 VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 115 | /** @hide */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 116 | public static final @android.annotation.NonNull Parcelable.Creator<DhcpClientEvent> CREATOR |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 117 | = 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 Benichi | cfddd68 | 2016-05-31 16:28:06 +0900 | [diff] [blame] | 126 | } |