102b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak/* 202b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak * Copyright (C) 2016 The Android Open Source Project 302b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak * 402b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak * Licensed under the Apache License, Version 2.0 (the "License"); 502b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak * you may not use this file except in compliance with the License. 602b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak * You may obtain a copy of the License at 702b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak * 802b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak * http://www.apache.org/licenses/LICENSE-2.0 902b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak * 1002b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak * Unless required by applicable law or agreed to in writing, software 1102b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak * distributed under the License is distributed on an "AS IS" BASIS, 1202b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1302b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak * See the License for the specific language governing permissions and 1402b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak * limitations under the License. 1502b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak */ 1602b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak 1702b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiakpackage android.net; 1802b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak 19f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiakimport android.annotation.SystemApi; 2002b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiakimport android.os.Parcel; 2102b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiakimport android.os.Parcelable; 2202b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak 2350d1c044b5ce4b6fef532dc6e083cef903f554b2Jeff Sharkey/** {@hide} */ 24f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak@SystemApi 2550d1c044b5ce4b6fef532dc6e083cef903f554b2Jeff Sharkeypublic final class ConnectivityMetricsEvent implements Parcelable { 2602b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak 2702b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak /** The time when this event was collected, as returned by System.currentTimeMillis(). */ 2802b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak final public long timestamp; 2902b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak 3002b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak /** The subsystem that generated the event. One of the COMPONENT_TAG_xxx constants. */ 3102b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak final public int componentTag; 3202b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak 3302b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak /** The subsystem-specific event ID. */ 3402b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak final public int eventTag; 3502b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak 3602b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak /** Opaque event-specific data. */ 3702b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak final public Parcelable data; 3802b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak 3902b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak public ConnectivityMetricsEvent(long timestamp, int componentTag, 4002b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak int eventTag, Parcelable data) { 4102b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak this.timestamp = timestamp; 4202b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak this.componentTag = componentTag; 4302b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak this.eventTag = eventTag; 4402b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak this.data = data; 4502b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak } 4602b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak 4702b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak /** Implement the Parcelable interface */ 4802b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak public static final Parcelable.Creator<ConnectivityMetricsEvent> CREATOR 4902b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak = new Parcelable.Creator<ConnectivityMetricsEvent> (){ 5002b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak public ConnectivityMetricsEvent createFromParcel(Parcel source) { 5102b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak final long timestamp = source.readLong(); 5202b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak final int componentTag = source.readInt(); 5302b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak final int eventTag = source.readInt(); 5402b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak final Parcelable data = source.readParcelable(null); 5502b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak return new ConnectivityMetricsEvent(timestamp, componentTag, 5602b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak eventTag, data); 5702b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak } 5802b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak 5902b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak public ConnectivityMetricsEvent[] newArray(int size) { 6002b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak return new ConnectivityMetricsEvent[size]; 6102b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak } 6202b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak }; 6302b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak 6402b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak /** Implement the Parcelable interface */ 6502b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak @Override 6602b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak public int describeContents() { 6702b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak return 0; 6802b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak } 6902b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak 7002b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak /** Implement the Parcelable interface */ 7102b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak @Override 7202b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak public void writeToParcel(Parcel dest, int flags) { 7302b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak dest.writeLong(timestamp); 7402b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak dest.writeInt(componentTag); 7502b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak dest.writeInt(eventTag); 7602b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak dest.writeParcelable(data, 0); 7702b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak } 7802b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak 7902b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak public String toString() { 805df9d729f6c78215f287701d7e136dfc922e2bd3Hugo Benichi return String.format("ConnectivityMetricsEvent(%tT.%tL, %d, %d): %s", 815df9d729f6c78215f287701d7e136dfc922e2bd3Hugo Benichi timestamp, timestamp, componentTag, eventTag, data); 8202b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak } 83d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak 84d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak /** {@hide} */ 85f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak @SystemApi 86f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak public final static class Reference implements Parcelable { 87d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak 88f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak private long mValue; 89d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak 90d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak public Reference(long ref) { 91f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak this.mValue = ref; 92d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak } 93d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak 94d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak /** Implement the Parcelable interface */ 95d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak public static final Parcelable.Creator<Reference> CREATOR 96d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak = new Parcelable.Creator<Reference> (){ 97d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak public Reference createFromParcel(Parcel source) { 98d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak return new Reference(source.readLong()); 99d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak } 100d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak 101d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak public Reference[] newArray(int size) { 102d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak return new Reference[size]; 103d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak } 104d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak }; 105d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak 106d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak /** Implement the Parcelable interface */ 107d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak @Override 108d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak public int describeContents() { 109d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak return 0; 110d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak } 111d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak 112d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak /** Implement the Parcelable interface */ 113d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak @Override 114d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak public void writeToParcel(Parcel dest, int flags) { 115f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak dest.writeLong(mValue); 116d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak } 117d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak 118d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak public void readFromParcel(Parcel in) { 119f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak mValue = in.readLong(); 120f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak } 121f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak 122f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak public long getValue() { 123f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak return mValue; 124f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak } 125f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak 126f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak public void setValue(long val) { 127f6f24c03f39016ee927e8bdbcff75a53841829c8Pavel Zhamaitsiak mValue = val; 128d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak } 129d1cb256b3efd2c00f1c44541b5589c2ea17b3cb8Pavel Zhamaitsiak } 13002b3e6bfc5bbd5f1a8ce1ce68976e59142073b6fPavel Zhamaitsiak} 131