• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 import java.util.Arrays;
23 
24 /**
25  * Record of energy and activity information from controller and
26  * underlying bt stack state.Timestamp the record with system
27  * time
28  *
29  * @hide
30  */
31 public final class BluetoothActivityEnergyInfo implements Parcelable {
32     private final long mTimestamp;
33     private int mBluetoothStackState;
34     private long mControllerTxTimeMs;
35     private long mControllerRxTimeMs;
36     private long mControllerIdleTimeMs;
37     private long mControllerEnergyUsed;
38     private UidTraffic[] mUidTraffic;
39 
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 
BluetoothActivityEnergyInfo(long timestamp, int stackState, long txTime, long rxTime, long idleTime, long energyUsed)45     public BluetoothActivityEnergyInfo(long timestamp, int stackState,
46             long txTime, long rxTime, long idleTime, long energyUsed) {
47         mTimestamp = timestamp;
48         mBluetoothStackState = stackState;
49         mControllerTxTimeMs = txTime;
50         mControllerRxTimeMs = rxTime;
51         mControllerIdleTimeMs = idleTime;
52         mControllerEnergyUsed = energyUsed;
53     }
54 
55     @SuppressWarnings("unchecked")
BluetoothActivityEnergyInfo(Parcel in)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 
66     @Override
toString()67     public String toString() {
68         return "BluetoothActivityEnergyInfo{"
69                 + " mTimestamp=" + mTimestamp
70                 + " mBluetoothStackState=" + mBluetoothStackState
71                 + " mControllerTxTimeMs=" + mControllerTxTimeMs
72                 + " mControllerRxTimeMs=" + mControllerRxTimeMs
73                 + " mControllerIdleTimeMs=" + mControllerIdleTimeMs
74                 + " mControllerEnergyUsed=" + mControllerEnergyUsed
75                 + " mUidTraffic=" + Arrays.toString(mUidTraffic)
76                 + " }";
77     }
78 
79     public static final @android.annotation.NonNull Parcelable.Creator<BluetoothActivityEnergyInfo> CREATOR =
80             new Parcelable.Creator<BluetoothActivityEnergyInfo>() {
81                 public BluetoothActivityEnergyInfo createFromParcel(Parcel in) {
82                     return new BluetoothActivityEnergyInfo(in);
83                 }
84 
85                 public BluetoothActivityEnergyInfo[] newArray(int size) {
86                     return new BluetoothActivityEnergyInfo[size];
87                 }
88             };
89 
90 
91     @Override
92     @SuppressWarnings("unchecked")
writeToParcel(Parcel out, int flags)93     public void writeToParcel(Parcel out, int flags) {
94         out.writeLong(mTimestamp);
95         out.writeInt(mBluetoothStackState);
96         out.writeLong(mControllerTxTimeMs);
97         out.writeLong(mControllerRxTimeMs);
98         out.writeLong(mControllerIdleTimeMs);
99         out.writeLong(mControllerEnergyUsed);
100         out.writeTypedArray(mUidTraffic, flags);
101     }
102 
103     @Override
describeContents()104     public int describeContents() {
105         return 0;
106     }
107 
108     /**
109      * @return bt stack reported state
110      */
getBluetoothStackState()111     public int getBluetoothStackState() {
112         return mBluetoothStackState;
113     }
114 
115     /**
116      * @return tx time in ms
117      */
getControllerTxTimeMillis()118     public long getControllerTxTimeMillis() {
119         return mControllerTxTimeMs;
120     }
121 
122     /**
123      * @return rx time in ms
124      */
getControllerRxTimeMillis()125     public long getControllerRxTimeMillis() {
126         return mControllerRxTimeMs;
127     }
128 
129     /**
130      * @return idle time in ms
131      */
getControllerIdleTimeMillis()132     public long getControllerIdleTimeMillis() {
133         return mControllerIdleTimeMs;
134     }
135 
136     /**
137      * product of current(mA), voltage(V) and time(ms)
138      *
139      * @return energy used
140      */
getControllerEnergyUsed()141     public long getControllerEnergyUsed() {
142         return mControllerEnergyUsed;
143     }
144 
145     /**
146      * @return timestamp(real time elapsed in milliseconds since boot) of record creation.
147      */
getTimeStamp()148     public long getTimeStamp() {
149         return mTimestamp;
150     }
151 
getUidTraffic()152     public UidTraffic[] getUidTraffic() {
153         return mUidTraffic;
154     }
155 
setUidTraffic(UidTraffic[] traffic)156     public void setUidTraffic(UidTraffic[] traffic) {
157         mUidTraffic = traffic;
158     }
159 
160     /**
161      * @return if the record is valid
162      */
isValid()163     public boolean isValid() {
164         return ((mControllerTxTimeMs >= 0) && (mControllerRxTimeMs >= 0)
165                 && (mControllerIdleTimeMs >= 0));
166     }
167 }
168