Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [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; |
| 18 | |
Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
Hugo Benichi | c867f78 | 2017-11-07 21:42:10 +0900 | [diff] [blame] | 21 | |
Hugo Benichi | df456e1 | 2017-03-22 18:29:58 +0900 | [diff] [blame] | 22 | import com.android.internal.util.BitUtils; |
Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 23 | |
Hugo Benichi | 946b7e4 | 2017-03-15 16:35:26 +0900 | [diff] [blame] | 24 | /** |
| 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 Sharkey | 50d1c04 | 2016-02-29 16:34:46 -0700 | [diff] [blame] | 29 | public final class ConnectivityMetricsEvent implements Parcelable { |
Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 30 | |
Hugo Benichi | 946b7e4 | 2017-03-15 16:35:26 +0900 | [diff] [blame] | 31 | /** Time when this event was collected, as returned by System.currentTimeMillis(). */ |
Hugo Benichi | ec27c4d | 2017-03-15 15:07:42 +0900 | [diff] [blame] | 32 | public long timestamp; |
Hugo Benichi | 946b7e4 | 2017-03-15 16:35:26 +0900 | [diff] [blame] | 33 | /** 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 Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 39 | /** Opaque event-specific data. */ |
Hugo Benichi | ec27c4d | 2017-03-15 15:07:42 +0900 | [diff] [blame] | 40 | public Parcelable data; |
Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 41 | |
Hugo Benichi | ec27c4d | 2017-03-15 15:07:42 +0900 | [diff] [blame] | 42 | public ConnectivityMetricsEvent() { |
| 43 | } |
| 44 | |
Hugo Benichi | 946b7e4 | 2017-03-15 16:35:26 +0900 | [diff] [blame] | 45 | private ConnectivityMetricsEvent(Parcel in) { |
Hugo Benichi | ec27c4d | 2017-03-15 15:07:42 +0900 | [diff] [blame] | 46 | timestamp = in.readLong(); |
Hugo Benichi | 946b7e4 | 2017-03-15 16:35:26 +0900 | [diff] [blame] | 47 | transports = in.readLong(); |
| 48 | netId = in.readInt(); |
| 49 | ifname = in.readString(); |
Hugo Benichi | ec27c4d | 2017-03-15 15:07:42 +0900 | [diff] [blame] | 50 | data = in.readParcelable(null); |
Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /** Implement the Parcelable interface */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 54 | public static final @android.annotation.NonNull Parcelable.Creator<ConnectivityMetricsEvent> CREATOR |
Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 55 | = new Parcelable.Creator<ConnectivityMetricsEvent> (){ |
| 56 | public ConnectivityMetricsEvent createFromParcel(Parcel source) { |
Hugo Benichi | ec27c4d | 2017-03-15 15:07:42 +0900 | [diff] [blame] | 57 | return new ConnectivityMetricsEvent(source); |
Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | public ConnectivityMetricsEvent[] newArray(int size) { |
| 61 | return new ConnectivityMetricsEvent[size]; |
| 62 | } |
| 63 | }; |
| 64 | |
Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 65 | @Override |
| 66 | public int describeContents() { |
| 67 | return 0; |
| 68 | } |
| 69 | |
Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 70 | @Override |
| 71 | public void writeToParcel(Parcel dest, int flags) { |
| 72 | dest.writeLong(timestamp); |
Hugo Benichi | 946b7e4 | 2017-03-15 16:35:26 +0900 | [diff] [blame] | 73 | dest.writeLong(transports); |
| 74 | dest.writeInt(netId); |
| 75 | dest.writeString(ifname); |
Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 76 | dest.writeParcelable(data, 0); |
| 77 | } |
| 78 | |
Hugo Benichi | ec27c4d | 2017-03-15 15:07:42 +0900 | [diff] [blame] | 79 | @Override |
Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 80 | public String toString() { |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 81 | StringBuilder buffer = new StringBuilder("ConnectivityMetricsEvent("); |
| 82 | buffer.append(String.format("%tT.%tL", timestamp, timestamp)); |
Hugo Benichi | f927f0c | 2017-03-17 15:42:40 +0900 | [diff] [blame] | 83 | if (netId != 0) { |
Hugo Benichi | c867f78 | 2017-11-07 21:42:10 +0900 | [diff] [blame] | 84 | buffer.append(", ").append("netId=").append(netId); |
Hugo Benichi | f927f0c | 2017-03-17 15:42:40 +0900 | [diff] [blame] | 85 | } |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 86 | if (ifname != null) { |
| 87 | buffer.append(", ").append(ifname); |
| 88 | } |
Hugo Benichi | df456e1 | 2017-03-22 18:29:58 +0900 | [diff] [blame] | 89 | for (int t : BitUtils.unpackBits(transports)) { |
| 90 | buffer.append(", ").append(NetworkCapabilities.transportNameOf(t)); |
| 91 | } |
Hugo Benichi | 948a859 | 2017-03-16 16:33:47 +0900 | [diff] [blame] | 92 | buffer.append("): ").append(data.toString()); |
| 93 | return buffer.toString(); |
Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 94 | } |
Pavel Zhamaitsiak | 02b3e6b | 2016-02-03 10:39:44 -0800 | [diff] [blame] | 95 | } |