blob: 522add12827e4a355c5e19fc85713d7e81c2c109 [file] [log] [blame]
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -08001/*
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;
18
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080019import android.os.Parcel;
20import android.os.Parcelable;
Hugo Benichic867f782017-11-07 21:42:10 +090021
Hugo Benichidf456e12017-03-22 18:29:58 +090022import com.android.internal.util.BitUtils;
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080023
Hugo Benichi946b7e42017-03-15 16:35:26 +090024/**
25 * Represents a core networking event defined in package android.net.metrics.
26 * Logged by IpConnectivityLog and managed by ConnectivityMetrics service.
27 * {@hide}
28 * */
Jeff Sharkey50d1c042016-02-29 16:34:46 -070029public final class ConnectivityMetricsEvent implements Parcelable {
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080030
Hugo Benichi946b7e42017-03-15 16:35:26 +090031 /** Time when this event was collected, as returned by System.currentTimeMillis(). */
Hugo Benichiec27c4d2017-03-15 15:07:42 +090032 public long timestamp;
Hugo Benichi946b7e42017-03-15 16:35:26 +090033 /** Transports of the network associated with the event, as defined in NetworkCapabilities. */
34 public long transports;
35 /** Network id of the network associated with the event, or 0 if unspecified. */
36 public int netId;
37 /** Name of the network interface associated with the event, or null if unspecified. */
38 public String ifname;
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080039 /** Opaque event-specific data. */
Hugo Benichiec27c4d2017-03-15 15:07:42 +090040 public Parcelable data;
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080041
Hugo Benichiec27c4d2017-03-15 15:07:42 +090042 public ConnectivityMetricsEvent() {
43 }
44
Hugo Benichi946b7e42017-03-15 16:35:26 +090045 private ConnectivityMetricsEvent(Parcel in) {
Hugo Benichiec27c4d2017-03-15 15:07:42 +090046 timestamp = in.readLong();
Hugo Benichi946b7e42017-03-15 16:35:26 +090047 transports = in.readLong();
48 netId = in.readInt();
49 ifname = in.readString();
Hugo Benichiec27c4d2017-03-15 15:07:42 +090050 data = in.readParcelable(null);
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080051 }
52
53 /** Implement the Parcelable interface */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070054 public static final @android.annotation.NonNull Parcelable.Creator<ConnectivityMetricsEvent> CREATOR
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080055 = new Parcelable.Creator<ConnectivityMetricsEvent> (){
56 public ConnectivityMetricsEvent createFromParcel(Parcel source) {
Hugo Benichiec27c4d2017-03-15 15:07:42 +090057 return new ConnectivityMetricsEvent(source);
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080058 }
59
60 public ConnectivityMetricsEvent[] newArray(int size) {
61 return new ConnectivityMetricsEvent[size];
62 }
63 };
64
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080065 @Override
66 public int describeContents() {
67 return 0;
68 }
69
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080070 @Override
71 public void writeToParcel(Parcel dest, int flags) {
72 dest.writeLong(timestamp);
Hugo Benichi946b7e42017-03-15 16:35:26 +090073 dest.writeLong(transports);
74 dest.writeInt(netId);
75 dest.writeString(ifname);
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080076 dest.writeParcelable(data, 0);
77 }
78
Hugo Benichiec27c4d2017-03-15 15:07:42 +090079 @Override
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080080 public String toString() {
Hugo Benichi948a8592017-03-16 16:33:47 +090081 StringBuilder buffer = new StringBuilder("ConnectivityMetricsEvent(");
82 buffer.append(String.format("%tT.%tL", timestamp, timestamp));
Hugo Benichif927f0c2017-03-17 15:42:40 +090083 if (netId != 0) {
Hugo Benichic867f782017-11-07 21:42:10 +090084 buffer.append(", ").append("netId=").append(netId);
Hugo Benichif927f0c2017-03-17 15:42:40 +090085 }
Hugo Benichi948a8592017-03-16 16:33:47 +090086 if (ifname != null) {
87 buffer.append(", ").append(ifname);
88 }
Hugo Benichidf456e12017-03-22 18:29:58 +090089 for (int t : BitUtils.unpackBits(transports)) {
90 buffer.append(", ").append(NetworkCapabilities.transportNameOf(t));
91 }
Hugo Benichi948a8592017-03-16 16:33:47 +090092 buffer.append("): ").append(data.toString());
93 return buffer.toString();
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080094 }
Pavel Zhamaitsiak02b3e6b2016-02-03 10:39:44 -080095}