Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +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 | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +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; |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +0900 | [diff] [blame] | 25 | |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 26 | import java.lang.annotation.Retention; |
| 27 | import java.lang.annotation.RetentionPolicy; |
| 28 | |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +0900 | [diff] [blame] | 29 | /** |
| 30 | * {@hide} |
| 31 | */ |
Hugo Benichi | cfddd68 | 2016-05-31 16:28:06 +0900 | [diff] [blame] | 32 | public final class NetworkEvent implements Parcelable { |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +0900 | [diff] [blame] | 33 | |
| 34 | public static final int NETWORK_CONNECTED = 1; |
| 35 | public static final int NETWORK_VALIDATED = 2; |
| 36 | public static final int NETWORK_VALIDATION_FAILED = 3; |
| 37 | public static final int NETWORK_CAPTIVE_PORTAL_FOUND = 4; |
| 38 | public static final int NETWORK_LINGER = 5; |
| 39 | public static final int NETWORK_UNLINGER = 6; |
| 40 | public static final int NETWORK_DISCONNECTED = 7; |
| 41 | |
Hugo Benichi | 147aa6d | 2016-11-15 23:23:24 +0900 | [diff] [blame] | 42 | public static final int NETWORK_FIRST_VALIDATION_SUCCESS = 8; |
Hugo Benichi | 147aa6d | 2016-11-15 23:23:24 +0900 | [diff] [blame] | 43 | public static final int NETWORK_REVALIDATION_SUCCESS = 9; |
Hugo Benichi | 147aa6d | 2016-11-15 23:23:24 +0900 | [diff] [blame] | 44 | public static final int NETWORK_FIRST_VALIDATION_PORTAL_FOUND = 10; |
Hugo Benichi | 147aa6d | 2016-11-15 23:23:24 +0900 | [diff] [blame] | 45 | public static final int NETWORK_REVALIDATION_PORTAL_FOUND = 11; |
| 46 | |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 47 | @IntDef(value = { |
| 48 | NETWORK_CONNECTED, |
| 49 | NETWORK_VALIDATED, |
| 50 | NETWORK_VALIDATION_FAILED, |
| 51 | NETWORK_CAPTIVE_PORTAL_FOUND, |
| 52 | NETWORK_LINGER, |
| 53 | NETWORK_UNLINGER, |
| 54 | NETWORK_DISCONNECTED, |
Hugo Benichi | 147aa6d | 2016-11-15 23:23:24 +0900 | [diff] [blame] | 55 | NETWORK_FIRST_VALIDATION_SUCCESS, |
| 56 | NETWORK_REVALIDATION_SUCCESS, |
| 57 | NETWORK_FIRST_VALIDATION_PORTAL_FOUND, |
| 58 | NETWORK_REVALIDATION_PORTAL_FOUND, |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 59 | }) |
| 60 | @Retention(RetentionPolicy.SOURCE) |
| 61 | public @interface EventType {} |
| 62 | |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 63 | public final @EventType int eventType; |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +0900 | [diff] [blame] | 64 | public final long durationMs; |
| 65 | |
Hugo Benichi | 97bfd27 | 2017-11-11 08:06:43 +0900 | [diff] [blame] | 66 | public NetworkEvent(@EventType int eventType, long durationMs) { |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +0900 | [diff] [blame] | 67 | this.eventType = eventType; |
| 68 | this.durationMs = durationMs; |
| 69 | } |
| 70 | |
Hugo Benichi | 97bfd27 | 2017-11-11 08:06:43 +0900 | [diff] [blame] | 71 | public NetworkEvent(@EventType int eventType) { |
| 72 | this(eventType, 0); |
Hugo Benichi | cfddd68 | 2016-05-31 16:28:06 +0900 | [diff] [blame] | 73 | } |
| 74 | |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +0900 | [diff] [blame] | 75 | private NetworkEvent(Parcel in) { |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +0900 | [diff] [blame] | 76 | eventType = in.readInt(); |
| 77 | durationMs = in.readLong(); |
| 78 | } |
| 79 | |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 80 | @Override |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +0900 | [diff] [blame] | 81 | public void writeToParcel(Parcel out, int flags) { |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +0900 | [diff] [blame] | 82 | out.writeInt(eventType); |
| 83 | out.writeLong(durationMs); |
| 84 | } |
| 85 | |
Hugo Benichi | cf6b12f | 2016-07-04 11:28:05 +0900 | [diff] [blame] | 86 | @Override |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +0900 | [diff] [blame] | 87 | public int describeContents() { |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | public static final Parcelable.Creator<NetworkEvent> CREATOR |
| 92 | = new Parcelable.Creator<NetworkEvent>() { |
| 93 | public NetworkEvent createFromParcel(Parcel in) { |
| 94 | return new NetworkEvent(in); |
| 95 | } |
| 96 | |
| 97 | public NetworkEvent[] newArray(int size) { |
| 98 | return new NetworkEvent[size]; |
| 99 | } |
| 100 | }; |
| 101 | |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 102 | @Override |
| 103 | public String toString() { |
Hugo Benichi | 97bfd27 | 2017-11-11 08:06:43 +0900 | [diff] [blame] | 104 | return String.format("NetworkEvent(%s, %dms)", |
| 105 | Decoder.constants.get(eventType), durationMs); |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | final static class Decoder { |
| 109 | static final SparseArray<String> constants = MessageUtils.findMessageNames( |
| 110 | new Class[]{NetworkEvent.class}, new String[]{"NETWORK_"}); |
| 111 | } |
Hugo Benichi | cfddd68 | 2016-05-31 16:28:06 +0900 | [diff] [blame] | 112 | } |