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