blob: 84f6060d3aed616844740c23e6b4143aaca0aaa4 [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
28 * @hide
29 */
30public final class BluetoothActivityEnergyInfo implements Parcelable {
Adam Lesinski488caeb2015-03-09 15:23:42 -070031 private final long mTimestamp;
Adam Lesinski50e47602015-12-04 17:04:54 -080032 private int mBluetoothStackState;
33 private long mControllerTxTimeMs;
34 private long mControllerRxTimeMs;
35 private long mControllerIdleTimeMs;
36 private long mControllerEnergyUsed;
37 private UidTraffic[] mUidTraffic;
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070038
39 public static final int BT_STACK_STATE_INVALID = 0;
40 public static final int BT_STACK_STATE_STATE_ACTIVE = 1;
41 public static final int BT_STACK_STATE_STATE_SCANNING = 2;
42 public static final int BT_STACK_STATE_STATE_IDLE = 3;
43
Adam Lesinski488caeb2015-03-09 15:23:42 -070044 public BluetoothActivityEnergyInfo(long timestamp, int stackState,
Adam Lesinski8a351372015-06-15 17:19:07 -070045 long txTime, long rxTime, long idleTime, long energyUsed) {
Adam Lesinski488caeb2015-03-09 15:23:42 -070046 mTimestamp = timestamp;
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070047 mBluetoothStackState = stackState;
48 mControllerTxTimeMs = txTime;
49 mControllerRxTimeMs = rxTime;
50 mControllerIdleTimeMs = idleTime;
51 mControllerEnergyUsed = energyUsed;
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070052 }
53
Adam Lesinski50e47602015-12-04 17:04:54 -080054 @SuppressWarnings("unchecked")
55 BluetoothActivityEnergyInfo(Parcel in) {
56 mTimestamp = in.readLong();
57 mBluetoothStackState = in.readInt();
58 mControllerTxTimeMs = in.readLong();
59 mControllerRxTimeMs = in.readLong();
60 mControllerIdleTimeMs = in.readLong();
61 mControllerEnergyUsed = in.readLong();
62 mUidTraffic = in.createTypedArray(UidTraffic.CREATOR);
63 }
64
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070065 @Override
66 public String toString() {
67 return "BluetoothActivityEnergyInfo{"
Adam Lesinski488caeb2015-03-09 15:23:42 -070068 + " mTimestamp=" + mTimestamp
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070069 + " mBluetoothStackState=" + mBluetoothStackState
70 + " mControllerTxTimeMs=" + mControllerTxTimeMs
71 + " mControllerRxTimeMs=" + mControllerRxTimeMs
72 + " mControllerIdleTimeMs=" + mControllerIdleTimeMs
73 + " mControllerEnergyUsed=" + mControllerEnergyUsed
Adam Lesinski50e47602015-12-04 17:04:54 -080074 + " mUidTraffic=" + Arrays.toString(mUidTraffic)
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070075 + " }";
76 }
77
78 public static final Parcelable.Creator<BluetoothActivityEnergyInfo> CREATOR =
79 new Parcelable.Creator<BluetoothActivityEnergyInfo>() {
80 public BluetoothActivityEnergyInfo createFromParcel(Parcel in) {
Adam Lesinski50e47602015-12-04 17:04:54 -080081 return new BluetoothActivityEnergyInfo(in);
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070082 }
Adam Lesinski50e47602015-12-04 17:04:54 -080083
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070084 public BluetoothActivityEnergyInfo[] newArray(int size) {
85 return new BluetoothActivityEnergyInfo[size];
86 }
87 };
88
Adam Lesinski50e47602015-12-04 17:04:54 -080089 @SuppressWarnings("unchecked")
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070090 public void writeToParcel(Parcel out, int flags) {
Adam Lesinski488caeb2015-03-09 15:23:42 -070091 out.writeLong(mTimestamp);
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070092 out.writeInt(mBluetoothStackState);
Adam Lesinski8a351372015-06-15 17:19:07 -070093 out.writeLong(mControllerTxTimeMs);
94 out.writeLong(mControllerRxTimeMs);
95 out.writeLong(mControllerIdleTimeMs);
96 out.writeLong(mControllerEnergyUsed);
Adam Lesinski50e47602015-12-04 17:04:54 -080097 out.writeTypedArray(mUidTraffic, flags);
Prerepa Viswanadham8caac742014-07-22 17:00:09 -070098 }
99
100 public int describeContents() {
101 return 0;
102 }
103
104 /**
105 * @return bt stack reported state
106 */
107 public int getBluetoothStackState() {
108 return mBluetoothStackState;
109 }
110
111 /**
112 * @return tx time in ms
113 */
Adam Lesinski8a351372015-06-15 17:19:07 -0700114 public long getControllerTxTimeMillis() {
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700115 return mControllerTxTimeMs;
116 }
117
118 /**
119 * @return rx time in ms
120 */
Adam Lesinski8a351372015-06-15 17:19:07 -0700121 public long getControllerRxTimeMillis() {
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700122 return mControllerRxTimeMs;
123 }
124
125 /**
126 * @return idle time in ms
127 */
Adam Lesinski8a351372015-06-15 17:19:07 -0700128 public long getControllerIdleTimeMillis() {
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700129 return mControllerIdleTimeMs;
130 }
131
132 /**
133 * product of current(mA), voltage(V) and time(ms)
134 * @return energy used
135 */
Adam Lesinski8a351372015-06-15 17:19:07 -0700136 public long getControllerEnergyUsed() {
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700137 return mControllerEnergyUsed;
138 }
Adam Lesinski488caeb2015-03-09 15:23:42 -0700139
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700140 /**
Adam Lesinski488caeb2015-03-09 15:23:42 -0700141 * @return timestamp(real time elapsed in milliseconds since boot) of record creation.
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700142 */
143 public long getTimeStamp() {
Adam Lesinski488caeb2015-03-09 15:23:42 -0700144 return mTimestamp;
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700145 }
146
Adam Lesinski50e47602015-12-04 17:04:54 -0800147 public UidTraffic[] getUidTraffic() {
148 return mUidTraffic;
149 }
150
151 public void setUidTraffic(UidTraffic[] traffic) {
152 mUidTraffic = traffic;
153 }
154
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700155 /**
156 * @return if the record is valid
157 */
158 public boolean isValid() {
Adam Lesinski010bf372016-04-11 12:18:18 -0700159 return ((mControllerTxTimeMs >=0) &&
160 (mControllerRxTimeMs >=0) &&
161 (mControllerIdleTimeMs >=0));
Prerepa Viswanadham8caac742014-07-22 17:00:09 -0700162 }
163}