Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 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. |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 23 | * |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 24 | * @hide |
| 25 | */ |
| 26 | public class UidTraffic implements Cloneable, Parcelable { |
| 27 | private final int mAppUid; |
| 28 | private long mRxBytes; |
| 29 | private long mTxBytes; |
| 30 | |
| 31 | public UidTraffic(int appUid) { |
| 32 | mAppUid = appUid; |
| 33 | } |
| 34 | |
| 35 | public UidTraffic(int appUid, long rx, long tx) { |
| 36 | mAppUid = appUid; |
| 37 | mRxBytes = rx; |
| 38 | mTxBytes = tx; |
| 39 | } |
| 40 | |
| 41 | UidTraffic(Parcel in) { |
| 42 | mAppUid = in.readInt(); |
| 43 | mRxBytes = in.readLong(); |
| 44 | mTxBytes = in.readLong(); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public void writeToParcel(Parcel dest, int flags) { |
| 49 | dest.writeInt(mAppUid); |
| 50 | dest.writeLong(mRxBytes); |
| 51 | dest.writeLong(mTxBytes); |
| 52 | } |
| 53 | |
| 54 | public void setRxBytes(long bytes) { |
| 55 | mRxBytes = bytes; |
| 56 | } |
| 57 | |
| 58 | public void setTxBytes(long bytes) { |
| 59 | mTxBytes = bytes; |
| 60 | } |
| 61 | |
| 62 | public void addRxBytes(long bytes) { |
| 63 | mRxBytes += bytes; |
| 64 | } |
| 65 | |
| 66 | public void addTxBytes(long bytes) { |
| 67 | mTxBytes += bytes; |
| 68 | } |
| 69 | |
| 70 | public int getUid() { |
| 71 | return mAppUid; |
| 72 | } |
| 73 | |
| 74 | public long getRxBytes() { |
| 75 | return mRxBytes; |
| 76 | } |
| 77 | |
| 78 | public long getTxBytes() { |
| 79 | return mTxBytes; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public int describeContents() { |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public UidTraffic clone() { |
| 89 | return new UidTraffic(mAppUid, mRxBytes, mTxBytes); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public String toString() { |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 94 | return "UidTraffic{mAppUid=" + mAppUid + ", mRxBytes=" + mRxBytes + ", mTxBytes=" |
| 95 | + mTxBytes + '}'; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 98 | public static final @android.annotation.NonNull Creator<UidTraffic> CREATOR = new Creator<UidTraffic>() { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 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 | } |