DhcpClientEvent.java revision 948a85948dcccea4aaa9d70a74405308581b0925
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
17package android.net.metrics;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22/**
23 * An event recorded when a DhcpClient state machine transitions to a new state.
24 * {@hide}
25 */
26public final class DhcpClientEvent implements Parcelable {
27
28    // Names for recording DhcpClient pseudo-state transitions.
29    /** {@hide} Represents transitions from DhcpInitState to DhcpBoundState */
30    public static final String INITIAL_BOUND = "InitialBoundState";
31    /** {@hide} Represents transitions from and to DhcpBoundState via DhcpRenewingState */
32    public static final String RENEWING_BOUND = "RenewingBoundState";
33
34    public final String msg;
35    public final int durationMs;
36
37    public DhcpClientEvent(String msg, int durationMs) {
38        this.msg = msg;
39        this.durationMs = durationMs;
40    }
41
42    private DhcpClientEvent(Parcel in) {
43        this.msg = in.readString();
44        this.durationMs = in.readInt();
45    }
46
47    @Override
48    public void writeToParcel(Parcel out, int flags) {
49        out.writeString(msg);
50        out.writeInt(durationMs);
51    }
52
53    @Override
54    public int describeContents() {
55        return 0;
56    }
57
58    @Override
59    public String toString() {
60        return String.format("DhcpClientEvent(%s, %dms)", msg, durationMs);
61    }
62
63    public static final Parcelable.Creator<DhcpClientEvent> CREATOR
64        = new Parcelable.Creator<DhcpClientEvent>() {
65        public DhcpClientEvent createFromParcel(Parcel in) {
66            return new DhcpClientEvent(in);
67        }
68
69        public DhcpClientEvent[] newArray(int size) {
70            return new DhcpClientEvent[size];
71        }
72    };
73}
74