Home | History | Annotate | Download | only in net
      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 
     19 import android.annotation.SystemApi;
     20 import android.os.Parcel;
     21 import android.os.Parcelable;
     22 
     23 /** {@hide} */
     24 @SystemApi
     25 public final class ConnectivityMetricsEvent implements Parcelable {
     26 
     27     /**  The time when this event was collected, as returned by System.currentTimeMillis(). */
     28     final public long timestamp;
     29 
     30     /** The subsystem that generated the event. One of the COMPONENT_TAG_xxx constants. */
     31     final public int componentTag;
     32 
     33     /** The subsystem-specific event ID. */
     34     final public int eventTag;
     35 
     36     /** Opaque event-specific data. */
     37     final public Parcelable data;
     38 
     39     public ConnectivityMetricsEvent(long timestamp, int componentTag,
     40                                     int eventTag, Parcelable data) {
     41         this.timestamp = timestamp;
     42         this.componentTag = componentTag;
     43         this.eventTag = eventTag;
     44         this.data = data;
     45     }
     46 
     47     /** Implement the Parcelable interface */
     48     public static final Parcelable.Creator<ConnectivityMetricsEvent> CREATOR
     49             = new Parcelable.Creator<ConnectivityMetricsEvent> (){
     50         public ConnectivityMetricsEvent createFromParcel(Parcel source) {
     51             final long timestamp = source.readLong();
     52             final int componentTag = source.readInt();
     53             final int eventTag = source.readInt();
     54             final Parcelable data = source.readParcelable(null);
     55             return new ConnectivityMetricsEvent(timestamp, componentTag,
     56                     eventTag, data);
     57         }
     58 
     59         public ConnectivityMetricsEvent[] newArray(int size) {
     60             return new ConnectivityMetricsEvent[size];
     61         }
     62     };
     63 
     64     /** Implement the Parcelable interface */
     65     @Override
     66     public int describeContents() {
     67         return 0;
     68     }
     69 
     70     /** Implement the Parcelable interface */
     71     @Override
     72     public void writeToParcel(Parcel dest, int flags) {
     73         dest.writeLong(timestamp);
     74         dest.writeInt(componentTag);
     75         dest.writeInt(eventTag);
     76         dest.writeParcelable(data, 0);
     77     }
     78 
     79     public String toString() {
     80         return String.format("ConnectivityMetricsEvent(%tT.%tL, %d, %d): %s",
     81                 timestamp, timestamp, componentTag, eventTag, data);
     82     }
     83 
     84     /** {@hide} */
     85     @SystemApi
     86     public final static class Reference implements Parcelable {
     87 
     88         private long mValue;
     89 
     90         public Reference(long ref) {
     91             this.mValue = ref;
     92         }
     93 
     94         /** Implement the Parcelable interface */
     95         public static final Parcelable.Creator<Reference> CREATOR
     96                 = new Parcelable.Creator<Reference> (){
     97             public Reference createFromParcel(Parcel source) {
     98                 return new Reference(source.readLong());
     99             }
    100 
    101             public Reference[] newArray(int size) {
    102                 return new Reference[size];
    103             }
    104         };
    105 
    106         /** Implement the Parcelable interface */
    107         @Override
    108         public int describeContents() {
    109             return 0;
    110         }
    111 
    112         /** Implement the Parcelable interface */
    113         @Override
    114         public void writeToParcel(Parcel dest, int flags) {
    115             dest.writeLong(mValue);
    116         }
    117 
    118         public void readFromParcel(Parcel in) {
    119             mValue = in.readLong();
    120         }
    121 
    122         public long getValue() {
    123             return mValue;
    124         }
    125 
    126         public void setValue(long val) {
    127             mValue = val;
    128         }
    129     }
    130 }
    131