blob: df065bf1bf8d684581b1f569f41f75b5b2316063 [file] [log] [blame]
Prerepa Viswanadham8caac742014-07-22 17:00:09 -07001/*
2 * Copyright (C) 2014 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
17package android.bluetooth;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
Adam Lesinski50e47602015-12-04 17:04:54 -080022import java.util.Arrays;
23
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070024/**
25 * Record of energy and activity information from controller and
26 * underlying bt stack state.Timestamp the record with system
27 * time
Jack Hea355e5e2017-08-22 16:06:54 -070028 *
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070029 * @hide
30 */
31public final class BluetoothActivityEnergyInfo implements Parcelable {
Adam Lesinski488caeb2015-03-09 15:23:42 -070032 private final long mTimestamp;
Adam Lesinski50e47602015-12-04 17:04:54 -080033 private int mBluetoothStackState;
34 private long mControllerTxTimeMs;
35 private long mControllerRxTimeMs;
36 private long mControllerIdleTimeMs;
37 private long mControllerEnergyUsed;
38 private UidTraffic[] mUidTraffic;
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070039
40 public static final int BT_STACK_STATE_INVALID = 0;
41 public static final int BT_STACK_STATE_STATE_ACTIVE = 1;
42 public static final int BT_STACK_STATE_STATE_SCANNING = 2;
43 public static final int BT_STACK_STATE_STATE_IDLE = 3;
44
Adam Lesinski488caeb2015-03-09 15:23:42 -070045 public BluetoothActivityEnergyInfo(long timestamp, int stackState,
Jack Hea355e5e2017-08-22 16:06:54 -070046 long txTime, long rxTime, long idleTime, long energyUsed) {
Adam Lesinski488caeb2015-03-09 15:23:42 -070047 mTimestamp = timestamp;
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070048 mBluetoothStackState = stackState;
49 mControllerTxTimeMs = txTime;
50 mControllerRxTimeMs = rxTime;
51 mControllerIdleTimeMs = idleTime;
52 mControllerEnergyUsed = energyUsed;
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070053 }
54
Adam Lesinski50e47602015-12-04 17:04:54 -080055 @SuppressWarnings("unchecked")
56 BluetoothActivityEnergyInfo(Parcel in) {
57 mTimestamp = in.readLong();
58 mBluetoothStackState = in.readInt();
59 mControllerTxTimeMs = in.readLong();
60 mControllerRxTimeMs = in.readLong();
61 mControllerIdleTimeMs = in.readLong();
62 mControllerEnergyUsed = in.readLong();
63 mUidTraffic = in.createTypedArray(UidTraffic.CREATOR);
64 }
65
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070066 @Override
67 public String toString() {
68 return "BluetoothActivityEnergyInfo{"
Jack Hea355e5e2017-08-22 16:06:54 -070069 + " mTimestamp=" + mTimestamp
70 + " mBluetoothStackState=" + mBluetoothStackState
71 + " mControllerTxTimeMs=" + mControllerTxTimeMs
72 + " mControllerRxTimeMs=" + mControllerRxTimeMs
73 + " mControllerIdleTimeMs=" + mControllerIdleTimeMs
74 + " mControllerEnergyUsed=" + mControllerEnergyUsed
75 + " mUidTraffic=" + Arrays.toString(mUidTraffic)
76 + " }";
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070077 }
78
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070079 public static final @android.annotation.NonNull Parcelable.Creator<BluetoothActivityEnergyInfo> CREATOR =
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070080 new Parcelable.Creator<BluetoothActivityEnergyInfo>() {
Jack Hea355e5e2017-08-22 16:06:54 -070081 public BluetoothActivityEnergyInfo createFromParcel(Parcel in) {
82 return new BluetoothActivityEnergyInfo(in);
83 }
Adam Lesinski50e47602015-12-04 17:04:54 -080084
Jack Hea355e5e2017-08-22 16:06:54 -070085 public BluetoothActivityEnergyInfo[] newArray(int size) {
86 return new BluetoothActivityEnergyInfo[size];
87 }
88 };
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070089
Jack He2992cd02017-08-22 21:21:23 -070090
91 @Override
Adam Lesinski50e47602015-12-04 17:04:54 -080092 @SuppressWarnings("unchecked")
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070093 public void writeToParcel(Parcel out, int flags) {
Adam Lesinski488caeb2015-03-09 15:23:42 -070094 out.writeLong(mTimestamp);
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070095 out.writeInt(mBluetoothStackState);
Adam Lesinski8a351372015-06-15 17:19:07 -070096 out.writeLong(mControllerTxTimeMs);
97 out.writeLong(mControllerRxTimeMs);
98 out.writeLong(mControllerIdleTimeMs);
99 out.writeLong(mControllerEnergyUsed);
Adam Lesinski50e47602015-12-04 17:04:54 -0800100 out.writeTypedArray(mUidTraffic, flags);
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700101 }
102
Jack He2992cd02017-08-22 21:21:23 -0700103 @Override
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700104 public int describeContents() {
105 return 0;
106 }
107
108 /**
109 * @return bt stack reported state
110 */
111 public int getBluetoothStackState() {
112 return mBluetoothStackState;
113 }
114
115 /**
116 * @return tx time in ms
117 */
Adam Lesinski8a351372015-06-15 17:19:07 -0700118 public long getControllerTxTimeMillis() {
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700119 return mControllerTxTimeMs;
120 }
121
122 /**
123 * @return rx time in ms
124 */
Adam Lesinski8a351372015-06-15 17:19:07 -0700125 public long getControllerRxTimeMillis() {
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700126 return mControllerRxTimeMs;
127 }
128
129 /**
130 * @return idle time in ms
131 */
Adam Lesinski8a351372015-06-15 17:19:07 -0700132 public long getControllerIdleTimeMillis() {
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700133 return mControllerIdleTimeMs;
134 }
135
136 /**
137 * product of current(mA), voltage(V) and time(ms)
Jack Hea355e5e2017-08-22 16:06:54 -0700138 *
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700139 * @return energy used
140 */
Adam Lesinski8a351372015-06-15 17:19:07 -0700141 public long getControllerEnergyUsed() {
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700142 return mControllerEnergyUsed;
143 }
Adam Lesinski488caeb2015-03-09 15:23:42 -0700144
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700145 /**
Adam Lesinski488caeb2015-03-09 15:23:42 -0700146 * @return timestamp(real time elapsed in milliseconds since boot) of record creation.
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700147 */
148 public long getTimeStamp() {
Adam Lesinski488caeb2015-03-09 15:23:42 -0700149 return mTimestamp;
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700150 }
151
Adam Lesinski50e47602015-12-04 17:04:54 -0800152 public UidTraffic[] getUidTraffic() {
153 return mUidTraffic;
154 }
155
156 public void setUidTraffic(UidTraffic[] traffic) {
157 mUidTraffic = traffic;
158 }
159
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700160 /**
161 * @return if the record is valid
162 */
163 public boolean isValid() {
Jack He2992cd02017-08-22 21:21:23 -0700164 return ((mControllerTxTimeMs >= 0) && (mControllerRxTimeMs >= 0)
165 && (mControllerIdleTimeMs >= 0));
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700166 }
167}