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 | |
| 19 | import android.annotation.SystemApi; |
| 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 | |
| 26 | /** |
| 27 | * {@hide} |
| 28 | */ |
| 29 | @SystemApi |
| 30 | public final class ValidationProbeEvent extends IpConnectivityEvent implements Parcelable { |
| 31 | |
Lorenzo Colitti | c5be12e | 2016-04-19 21:57:31 +0900 | [diff] [blame] | 32 | public static final int PROBE_DNS = 0; |
| 33 | public static final int PROBE_HTTP = 1; |
| 34 | public static final int PROBE_HTTPS = 2; |
| 35 | public static final int PROBE_PAC = 3; |
| 36 | |
| 37 | public static final int DNS_FAILURE = 0; |
| 38 | public static final int DNS_SUCCESS = 1; |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +0900 | [diff] [blame] | 39 | |
| 40 | public final int netId; |
| 41 | public final long durationMs; |
| 42 | public final int probeType; |
| 43 | public final int returnCode; |
| 44 | |
| 45 | private ValidationProbeEvent(int netId, long durationMs, int probeType, int returnCode) { |
| 46 | this.netId = netId; |
| 47 | this.durationMs = durationMs; |
| 48 | this.probeType = probeType; |
| 49 | this.returnCode = returnCode; |
| 50 | } |
| 51 | |
| 52 | private ValidationProbeEvent(Parcel in) { |
| 53 | netId = in.readInt(); |
| 54 | durationMs = in.readLong(); |
| 55 | probeType = in.readInt(); |
| 56 | returnCode = in.readInt(); |
| 57 | } |
| 58 | |
| 59 | public void writeToParcel(Parcel out, int flags) { |
| 60 | out.writeInt(netId); |
| 61 | out.writeLong(durationMs); |
| 62 | out.writeInt(probeType); |
| 63 | out.writeInt(returnCode); |
| 64 | } |
| 65 | |
| 66 | public int describeContents() { |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | public static final Parcelable.Creator<ValidationProbeEvent> CREATOR |
| 71 | = new Parcelable.Creator<ValidationProbeEvent>() { |
| 72 | public ValidationProbeEvent createFromParcel(Parcel in) { |
| 73 | return new ValidationProbeEvent(in); |
| 74 | } |
| 75 | |
| 76 | public ValidationProbeEvent[] newArray(int size) { |
| 77 | return new ValidationProbeEvent[size]; |
| 78 | } |
| 79 | }; |
| 80 | |
Lorenzo Colitti | c5be12e | 2016-04-19 21:57:31 +0900 | [diff] [blame] | 81 | /** @hide */ |
| 82 | public static String getProbeName(int probeType) { |
| 83 | return Decoder.constants.get(probeType, "PROBE_???"); |
| 84 | } |
| 85 | |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +0900 | [diff] [blame] | 86 | public static void logEvent(int netId, long durationMs, int probeType, int returnCode) { |
Hugo Benichi | 61cbccc | 2016-04-26 16:56:21 +0900 | [diff] [blame] | 87 | logEvent(new ValidationProbeEvent(netId, durationMs, probeType, returnCode)); |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public String toString() { |
| 92 | return String.format("ValidationProbeEvent(%d, %s:%d, %dms)", |
Lorenzo Colitti | c5be12e | 2016-04-19 21:57:31 +0900 | [diff] [blame] | 93 | netId, getProbeName(probeType), returnCode, durationMs); |
Hugo Benichi | 5df9d72 | 2016-04-25 17:16:35 +0900 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | final static class Decoder { |
| 97 | static final SparseArray<String> constants = MessageUtils.findMessageNames( |
| 98 | new Class[]{ValidationProbeEvent.class}, new String[]{"PROBE_"}); |
Hugo Benichi | cc92c6e | 2016-04-21 15:02:38 +0900 | [diff] [blame] | 99 | } |
| 100 | }; |