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