blob: 751c35f8a1443c5a7c63d140fa1c81b0cc3c6cdf [file] [log] [blame]
Hugo Benichicc92c6e2016-04-21 15:02:38 +09001/*
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;
Hugo Benichi5df9d722016-04-25 17:16:35 +090022import android.util.SparseArray;
23
24import com.android.internal.util.MessageUtils;
Hugo Benichicc92c6e2016-04-21 15:02:38 +090025
26/**
27 * {@hide}
28 */
29@SystemApi
30public final class ValidationProbeEvent extends IpConnectivityEvent implements Parcelable {
31
Lorenzo Colittic5be12e2016-04-19 21:57:31 +090032 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 Benichicc92c6e2016-04-21 15:02:38 +090039
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 Colittic5be12e2016-04-19 21:57:31 +090081 /** @hide */
82 public static String getProbeName(int probeType) {
83 return Decoder.constants.get(probeType, "PROBE_???");
84 }
85
Hugo Benichicc92c6e2016-04-21 15:02:38 +090086 public static void logEvent(int netId, long durationMs, int probeType, int returnCode) {
Hugo Benichi61cbccc2016-04-26 16:56:21 +090087 logEvent(new ValidationProbeEvent(netId, durationMs, probeType, returnCode));
Hugo Benichi5df9d722016-04-25 17:16:35 +090088 }
89
90 @Override
91 public String toString() {
92 return String.format("ValidationProbeEvent(%d, %s:%d, %dms)",
Lorenzo Colittic5be12e2016-04-19 21:57:31 +090093 netId, getProbeName(probeType), returnCode, durationMs);
Hugo Benichi5df9d722016-04-25 17:16:35 +090094 }
95
96 final static class Decoder {
97 static final SparseArray<String> constants = MessageUtils.findMessageNames(
98 new Class[]{ValidationProbeEvent.class}, new String[]{"PROBE_"});
Hugo Benichicc92c6e2016-04-21 15:02:38 +090099 }
100};