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