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