Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.bluetooth; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 22 | import java.util.Arrays; |
| 23 | |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 24 | /** |
| 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 | */ |
| 30 | public final class BluetoothActivityEnergyInfo implements Parcelable { |
Adam Lesinski | 488caeb | 2015-03-09 15:23:42 -0700 | [diff] [blame] | 31 | private final long mTimestamp; |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 32 | private int mBluetoothStackState; |
| 33 | private long mControllerTxTimeMs; |
| 34 | private long mControllerRxTimeMs; |
| 35 | private long mControllerIdleTimeMs; |
| 36 | private long mControllerEnergyUsed; |
| 37 | private UidTraffic[] mUidTraffic; |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 38 | |
| 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 Lesinski | 488caeb | 2015-03-09 15:23:42 -0700 | [diff] [blame] | 44 | public BluetoothActivityEnergyInfo(long timestamp, int stackState, |
Adam Lesinski | 8a35137 | 2015-06-15 17:19:07 -0700 | [diff] [blame] | 45 | long txTime, long rxTime, long idleTime, long energyUsed) { |
Adam Lesinski | 488caeb | 2015-03-09 15:23:42 -0700 | [diff] [blame] | 46 | mTimestamp = timestamp; |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 47 | mBluetoothStackState = stackState; |
| 48 | mControllerTxTimeMs = txTime; |
| 49 | mControllerRxTimeMs = rxTime; |
| 50 | mControllerIdleTimeMs = idleTime; |
| 51 | mControllerEnergyUsed = energyUsed; |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 54 | @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 Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 65 | @Override |
| 66 | public String toString() { |
| 67 | return "BluetoothActivityEnergyInfo{" |
Adam Lesinski | 488caeb | 2015-03-09 15:23:42 -0700 | [diff] [blame] | 68 | + " mTimestamp=" + mTimestamp |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 69 | + " mBluetoothStackState=" + mBluetoothStackState |
| 70 | + " mControllerTxTimeMs=" + mControllerTxTimeMs |
| 71 | + " mControllerRxTimeMs=" + mControllerRxTimeMs |
| 72 | + " mControllerIdleTimeMs=" + mControllerIdleTimeMs |
| 73 | + " mControllerEnergyUsed=" + mControllerEnergyUsed |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 74 | + " mUidTraffic=" + Arrays.toString(mUidTraffic) |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 75 | + " }"; |
| 76 | } |
| 77 | |
| 78 | public static final Parcelable.Creator<BluetoothActivityEnergyInfo> CREATOR = |
| 79 | new Parcelable.Creator<BluetoothActivityEnergyInfo>() { |
| 80 | public BluetoothActivityEnergyInfo createFromParcel(Parcel in) { |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 81 | return new BluetoothActivityEnergyInfo(in); |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 82 | } |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 83 | |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 84 | public BluetoothActivityEnergyInfo[] newArray(int size) { |
| 85 | return new BluetoothActivityEnergyInfo[size]; |
| 86 | } |
| 87 | }; |
| 88 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 89 | @SuppressWarnings("unchecked") |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 90 | public void writeToParcel(Parcel out, int flags) { |
Adam Lesinski | 488caeb | 2015-03-09 15:23:42 -0700 | [diff] [blame] | 91 | out.writeLong(mTimestamp); |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 92 | out.writeInt(mBluetoothStackState); |
Adam Lesinski | 8a35137 | 2015-06-15 17:19:07 -0700 | [diff] [blame] | 93 | out.writeLong(mControllerTxTimeMs); |
| 94 | out.writeLong(mControllerRxTimeMs); |
| 95 | out.writeLong(mControllerIdleTimeMs); |
| 96 | out.writeLong(mControllerEnergyUsed); |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 97 | out.writeTypedArray(mUidTraffic, flags); |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 98 | } |
| 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 Lesinski | 8a35137 | 2015-06-15 17:19:07 -0700 | [diff] [blame] | 114 | public long getControllerTxTimeMillis() { |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 115 | return mControllerTxTimeMs; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @return rx time in ms |
| 120 | */ |
Adam Lesinski | 8a35137 | 2015-06-15 17:19:07 -0700 | [diff] [blame] | 121 | public long getControllerRxTimeMillis() { |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 122 | return mControllerRxTimeMs; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @return idle time in ms |
| 127 | */ |
Adam Lesinski | 8a35137 | 2015-06-15 17:19:07 -0700 | [diff] [blame] | 128 | public long getControllerIdleTimeMillis() { |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 129 | return mControllerIdleTimeMs; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * product of current(mA), voltage(V) and time(ms) |
| 134 | * @return energy used |
| 135 | */ |
Adam Lesinski | 8a35137 | 2015-06-15 17:19:07 -0700 | [diff] [blame] | 136 | public long getControllerEnergyUsed() { |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 137 | return mControllerEnergyUsed; |
| 138 | } |
Adam Lesinski | 488caeb | 2015-03-09 15:23:42 -0700 | [diff] [blame] | 139 | |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 140 | /** |
Adam Lesinski | 488caeb | 2015-03-09 15:23:42 -0700 | [diff] [blame] | 141 | * @return timestamp(real time elapsed in milliseconds since boot) of record creation. |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 142 | */ |
| 143 | public long getTimeStamp() { |
Adam Lesinski | 488caeb | 2015-03-09 15:23:42 -0700 | [diff] [blame] | 144 | return mTimestamp; |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Adam Lesinski | 50e4760 | 2015-12-04 17:04:54 -0800 | [diff] [blame] | 147 | public UidTraffic[] getUidTraffic() { |
| 148 | return mUidTraffic; |
| 149 | } |
| 150 | |
| 151 | public void setUidTraffic(UidTraffic[] traffic) { |
| 152 | mUidTraffic = traffic; |
| 153 | } |
| 154 | |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 155 | /** |
| 156 | * @return if the record is valid |
| 157 | */ |
| 158 | public boolean isValid() { |
Adam Lesinski | 010bf37 | 2016-04-11 12:18:18 -0700 | [diff] [blame] | 159 | return ((mControllerTxTimeMs >=0) && |
| 160 | (mControllerRxTimeMs >=0) && |
| 161 | (mControllerIdleTimeMs >=0)); |
Prerepa Viswanadham | 8caac74 | 2014-07-22 17:00:09 -0700 | [diff] [blame] | 162 | } |
| 163 | } |