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 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
| 20 | import android.annotation.TestApi; |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 21 | import android.annotation.UnsupportedAppUsage; |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
| 24 | |
Pierre Imai | bc9cc50 | 2016-03-29 14:50:51 +0900 | [diff] [blame] | 25 | /** |
Hugo Benichi | 7643423 | 2016-07-07 11:28:54 +0900 | [diff] [blame] | 26 | * 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] | 27 | * {@hide} |
| 28 | */ |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 29 | @SystemApi |
| 30 | @TestApi |
| 31 | public final class DhcpClientEvent implements IpConnectivityLog.Event { |
Hugo Benichi | 7643423 | 2016-07-07 11:28:54 +0900 | [diff] [blame] | 32 | |
| 33 | // Names for recording DhcpClient pseudo-state transitions. |
Hugo Benichi | 7643423 | 2016-07-07 11:28:54 +0900 | [diff] [blame] | 34 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 35 | /** @hide */ |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 36 | public final String msg; |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 37 | /** @hide */ |
Hugo Benichi | 176ed01 | 2016-07-01 10:06:56 +0900 | [diff] [blame] | 38 | public final int durationMs; |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 39 | |
Mathew Inwood | fa3a746 | 2018-08-08 14:52:47 +0100 | [diff] [blame] | 40 | @UnsupportedAppUsage |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 41 | private DhcpClientEvent(String msg, int durationMs) { |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 42 | this.msg = msg; |
Hugo Benichi | 176ed01 | 2016-07-01 10:06:56 +0900 | [diff] [blame] | 43 | this.durationMs = durationMs; |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 44 | } |
| 45 | |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 46 | private DhcpClientEvent(Parcel in) { |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 47 | this.msg = in.readString(); |
Hugo Benichi | 176ed01 | 2016-07-01 10:06:56 +0900 | [diff] [blame] | 48 | this.durationMs = in.readInt(); |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 49 | } |
| 50 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 51 | /** |
| 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 Benichi | 176ed01 | 2016-07-01 10:06:56 +0900 | [diff] [blame] | 83 | @Override |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 84 | public void writeToParcel(Parcel out, int flags) { |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 85 | out.writeString(msg); |
Hugo Benichi | 176ed01 | 2016-07-01 10:06:56 +0900 | [diff] [blame] | 86 | out.writeInt(durationMs); |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 87 | } |
| 88 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 89 | /** @hide */ |
Hugo Benichi | 176ed01 | 2016-07-01 10:06:56 +0900 | [diff] [blame] | 90 | @Override |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 91 | public int describeContents() { |
| 92 | return 0; |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 93 | } |
| 94 | |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 95 | @Override |
| 96 | public String toString() { |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 97 | return String.format("DhcpClientEvent(%s, %dms)", msg, durationMs); |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 98 | } |
| 99 | |
Remi NGUYEN VAN | 7b84fb3 | 2019-01-19 21:13:24 +0900 | [diff] [blame] | 100 | /** @hide */ |
Pierre Imai | 55618be | 2016-02-19 15:25:54 +0900 | [diff] [blame] | 101 | 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 Benichi | cfddd68 | 2016-05-31 16:28:06 +0900 | [diff] [blame] | 111 | } |