• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.IntDef;
20 import android.annotation.SystemApi;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import android.util.SparseArray;
24 
25 import com.android.internal.util.MessageUtils;
26 
27 import java.lang.annotation.Retention;
28 import java.lang.annotation.RetentionPolicy;
29 
30 /**
31  * An event recorded by NetworkMonitor when sending a probe for finding captive portals.
32  * {@hide}
33  */
34 @SystemApi
35 public final class ValidationProbeEvent implements Parcelable {
36 
37     public static final int PROBE_DNS   = 0;
38     public static final int PROBE_HTTP  = 1;
39     public static final int PROBE_HTTPS = 2;
40     public static final int PROBE_PAC   = 3;
41 
42     public static final int DNS_FAILURE = 0;
43     public static final int DNS_SUCCESS = 1;
44 
45     /** {@hide} */
46     @IntDef(value = {PROBE_DNS, PROBE_HTTP, PROBE_HTTPS, PROBE_PAC})
47     @Retention(RetentionPolicy.SOURCE)
48     public @interface ProbeType {}
49 
50     /** {@hide} */
51     @IntDef(value = {DNS_FAILURE, DNS_SUCCESS})
52     @Retention(RetentionPolicy.SOURCE)
53     public @interface ReturnCode {}
54 
55     public final int netId;
56     public final long durationMs;
57     public final @ProbeType int probeType;
58     public final @ReturnCode int returnCode;
59 
60     /** @hide */
ValidationProbeEvent( int netId, long durationMs, @ProbeType int probeType, @ReturnCode int returnCode)61     public ValidationProbeEvent(
62             int netId, long durationMs, @ProbeType int probeType, @ReturnCode int returnCode) {
63         this.netId = netId;
64         this.durationMs = durationMs;
65         this.probeType = probeType;
66         this.returnCode = returnCode;
67     }
68 
ValidationProbeEvent(Parcel in)69     private ValidationProbeEvent(Parcel in) {
70         netId = in.readInt();
71         durationMs = in.readLong();
72         probeType = in.readInt();
73         returnCode = in.readInt();
74     }
75 
76     @Override
writeToParcel(Parcel out, int flags)77     public void writeToParcel(Parcel out, int flags) {
78         out.writeInt(netId);
79         out.writeLong(durationMs);
80         out.writeInt(probeType);
81         out.writeInt(returnCode);
82     }
83 
84     @Override
describeContents()85     public int describeContents() {
86         return 0;
87     }
88 
89     public static final Parcelable.Creator<ValidationProbeEvent> CREATOR
90         = new Parcelable.Creator<ValidationProbeEvent>() {
91         public ValidationProbeEvent createFromParcel(Parcel in) {
92             return new ValidationProbeEvent(in);
93         }
94 
95         public ValidationProbeEvent[] newArray(int size) {
96             return new ValidationProbeEvent[size];
97         }
98     };
99 
100     /** @hide */
getProbeName(int probeType)101     public static String getProbeName(int probeType) {
102         return Decoder.constants.get(probeType, "PROBE_???");
103     }
104 
logEvent(int netId, long durationMs, int probeType, int returnCode)105     public static void logEvent(int netId, long durationMs, int probeType, int returnCode) {
106     }
107 
108     @Override
toString()109     public String toString() {
110         return String.format("ValidationProbeEvent(%d, %s:%d, %dms)",
111                 netId, getProbeName(probeType), returnCode, durationMs);
112     }
113 
114     final static class Decoder {
115         static final SparseArray<String> constants = MessageUtils.findMessageNames(
116                 new Class[]{ValidationProbeEvent.class}, new String[]{"PROBE_"});
117     }
118 }
119