Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +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 | |
Hugo Benichi | 4b6dfc2 | 2016-04-15 12:15:47 +0900 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 22 | import android.util.SparseArray; |
| 23 | |
| 24 | import com.android.internal.util.MessageUtils; |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * {@hide} |
| 28 | */ |
Hugo Benichi | 4b6dfc2 | 2016-04-15 12:15:47 +0900 | [diff] [blame] | 29 | @SystemApi |
Hugo Benichi | cfddd68 | 2016-05-31 16:28:06 +0900 | [diff] [blame^] | 30 | public final class IpManagerEvent implements Parcelable { |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 31 | |
| 32 | public static final int PROVISIONING_OK = 1; |
| 33 | public static final int PROVISIONING_FAIL = 2; |
| 34 | public static final int COMPLETE_LIFECYCLE = 3; |
| 35 | |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 36 | public final String ifName; |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 37 | public final int eventType; |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 38 | public final long durationMs; |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 39 | |
Hugo Benichi | cfddd68 | 2016-05-31 16:28:06 +0900 | [diff] [blame^] | 40 | /** {@hide} */ |
| 41 | public IpManagerEvent(String ifName, int eventType, long duration) { |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 42 | this.ifName = ifName; |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 43 | this.eventType = eventType; |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 44 | this.durationMs = duration; |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 45 | } |
| 46 | |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 47 | private IpManagerEvent(Parcel in) { |
| 48 | this.ifName = in.readString(); |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 49 | this.eventType = in.readInt(); |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 50 | this.durationMs = in.readLong(); |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | public void writeToParcel(Parcel out, int flags) { |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 54 | out.writeString(ifName); |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 55 | out.writeInt(eventType); |
Hugo Benichi | 627b424 | 2016-04-15 16:56:28 +0900 | [diff] [blame] | 56 | out.writeLong(durationMs); |
| 57 | } |
| 58 | |
| 59 | public int describeContents() { |
| 60 | return 0; |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | public static final Parcelable.Creator<IpManagerEvent> CREATOR |
| 64 | = new Parcelable.Creator<IpManagerEvent>() { |
| 65 | public IpManagerEvent createFromParcel(Parcel in) { |
| 66 | return new IpManagerEvent(in); |
| 67 | } |
| 68 | |
| 69 | public IpManagerEvent[] newArray(int size) { |
| 70 | return new IpManagerEvent[size]; |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | public static void logEvent(int eventType, String ifName, long durationMs) { |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public String toString() { |
| 79 | return String.format("IpManagerEvent(%s, %s, %dms)", |
| 80 | ifName, Decoder.constants.get(eventType), durationMs); |
| 81 | } |
| 82 | |
| 83 | final static class Decoder { |
| 84 | static final SparseArray<String> constants = MessageUtils.findMessageNames( |
| 85 | new Class[]{IpManagerEvent.class}, new String[]{"PROVISIONING_", "COMPLETE_"}); |
Erik Kline | 5b25a0f | 2016-04-12 15:31:13 +0900 | [diff] [blame] | 86 | } |
Hugo Benichi | cfddd68 | 2016-05-31 16:28:06 +0900 | [diff] [blame^] | 87 | } |