Home | History | Annotate | Download | only in bluetooth
      1 /*
      2  * Copyright (C) 2015 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 package android.bluetooth;
     17 
     18 import android.os.Parcel;
     19 import android.os.Parcelable;
     20 
     21 /**
     22  * Record of data traffic (in bytes) by an application identified by its UID.
     23  * @hide
     24  */
     25 public class UidTraffic implements Cloneable, Parcelable {
     26     private final int mAppUid;
     27     private long mRxBytes;
     28     private long mTxBytes;
     29 
     30     public UidTraffic(int appUid) {
     31         mAppUid = appUid;
     32     }
     33 
     34     public UidTraffic(int appUid, long rx, long tx) {
     35         mAppUid = appUid;
     36         mRxBytes = rx;
     37         mTxBytes = tx;
     38     }
     39 
     40     UidTraffic(Parcel in) {
     41         mAppUid = in.readInt();
     42         mRxBytes = in.readLong();
     43         mTxBytes = in.readLong();
     44     }
     45 
     46     @Override
     47     public void writeToParcel(Parcel dest, int flags) {
     48         dest.writeInt(mAppUid);
     49         dest.writeLong(mRxBytes);
     50         dest.writeLong(mTxBytes);
     51     }
     52 
     53     public void setRxBytes(long bytes) {
     54         mRxBytes = bytes;
     55     }
     56 
     57     public void setTxBytes(long bytes) {
     58         mTxBytes = bytes;
     59     }
     60 
     61     public void addRxBytes(long bytes) {
     62         mRxBytes += bytes;
     63     }
     64 
     65     public void addTxBytes(long bytes) {
     66         mTxBytes += bytes;
     67     }
     68 
     69     public int getUid() {
     70         return mAppUid;
     71     }
     72 
     73     public long getRxBytes() {
     74         return mRxBytes;
     75     }
     76 
     77     public long getTxBytes() {
     78         return mTxBytes;
     79     }
     80 
     81     @Override
     82     public int describeContents() {
     83         return 0;
     84     }
     85 
     86     @Override
     87     public UidTraffic clone() {
     88         return new UidTraffic(mAppUid, mRxBytes, mTxBytes);
     89     }
     90 
     91     @Override
     92     public String toString() {
     93         return "UidTraffic{" +
     94                 "mAppUid=" + mAppUid +
     95                 ", mRxBytes=" + mRxBytes +
     96                 ", mTxBytes=" + mTxBytes +
     97                 '}';
     98     }
     99 
    100     public static final Creator<UidTraffic> CREATOR = new Creator<UidTraffic>() {
    101         @Override
    102         public UidTraffic createFromParcel(Parcel source) {
    103             return new UidTraffic(source);
    104         }
    105 
    106         @Override
    107         public UidTraffic[] newArray(int size) {
    108             return new UidTraffic[size];
    109         }
    110     };
    111 }
    112