blob: 2ee786a5909161a9664d0d25089bfd2d11b12e9b [file] [log] [blame]
Adam Lesinski50e47602015-12-04 17:04:54 -08001/*
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 */
16package android.bluetooth;
17
18import android.os.Parcel;
19import android.os.Parcelable;
20
21/**
22 * Record of data traffic (in bytes) by an application identified by its UID.
Jack Hea355e5e2017-08-22 16:06:54 -070023 *
Adam Lesinski50e47602015-12-04 17:04:54 -080024 * @hide
25 */
26public 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 He2992cd02017-08-22 21:21:23 -070094 return "UidTraffic{mAppUid=" + mAppUid + ", mRxBytes=" + mRxBytes + ", mTxBytes="
95 + mTxBytes + '}';
Adam Lesinski50e47602015-12-04 17:04:54 -080096 }
97
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070098 public static final @android.annotation.NonNull Creator<UidTraffic> CREATOR = new Creator<UidTraffic>() {
Adam Lesinski50e47602015-12-04 17:04:54 -080099 @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}