• 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 /**
23  * Record of energy and activity information from controller and
24  * underlying bt stack state.Timestamp the record with system
25  * time
26  * @hide
27  */
28 public final class BluetoothActivityEnergyInfo implements Parcelable {
29     private final int mBluetoothStackState;
30     private final int mControllerTxTimeMs;
31     private final int mControllerRxTimeMs;
32     private final int mControllerIdleTimeMs;
33     private final int mControllerEnergyUsed;
34     private final long timestamp;
35 
36     public static final int BT_STACK_STATE_INVALID = 0;
37     public static final int BT_STACK_STATE_STATE_ACTIVE = 1;
38     public static final int BT_STACK_STATE_STATE_SCANNING = 2;
39     public static final int BT_STACK_STATE_STATE_IDLE = 3;
40 
BluetoothActivityEnergyInfo(int stackState, int txTime, int rxTime, int idleTime, int energyUsed)41     public BluetoothActivityEnergyInfo(int stackState, int txTime, int rxTime,
42             int idleTime, int energyUsed) {
43         mBluetoothStackState = stackState;
44         mControllerTxTimeMs = txTime;
45         mControllerRxTimeMs = rxTime;
46         mControllerIdleTimeMs = idleTime;
47         mControllerEnergyUsed = energyUsed;
48         timestamp = System.currentTimeMillis();
49     }
50 
51     @Override
toString()52     public String toString() {
53         return "BluetoothActivityEnergyInfo{"
54             + " timestamp=" + timestamp
55             + " mBluetoothStackState=" + mBluetoothStackState
56             + " mControllerTxTimeMs=" + mControllerTxTimeMs
57             + " mControllerRxTimeMs=" + mControllerRxTimeMs
58             + " mControllerIdleTimeMs=" + mControllerIdleTimeMs
59             + " mControllerEnergyUsed=" + mControllerEnergyUsed
60             + " }";
61     }
62 
63     public static final Parcelable.Creator<BluetoothActivityEnergyInfo> CREATOR =
64             new Parcelable.Creator<BluetoothActivityEnergyInfo>() {
65         public BluetoothActivityEnergyInfo createFromParcel(Parcel in) {
66             int stackState = in.readInt();
67             int txTime = in.readInt();
68             int rxTime = in.readInt();
69             int idleTime = in.readInt();
70             int energyUsed = in.readInt();
71             return new BluetoothActivityEnergyInfo(stackState, txTime, rxTime,
72                     idleTime, energyUsed);
73         }
74         public BluetoothActivityEnergyInfo[] newArray(int size) {
75             return new BluetoothActivityEnergyInfo[size];
76         }
77     };
78 
writeToParcel(Parcel out, int flags)79     public void writeToParcel(Parcel out, int flags) {
80         out.writeInt(mBluetoothStackState);
81         out.writeInt(mControllerTxTimeMs);
82         out.writeInt(mControllerRxTimeMs);
83         out.writeInt(mControllerIdleTimeMs);
84         out.writeInt(mControllerEnergyUsed);
85     }
86 
describeContents()87     public int describeContents() {
88         return 0;
89     }
90 
91     /**
92      * @return bt stack reported state
93      */
getBluetoothStackState()94     public int getBluetoothStackState() {
95         return mBluetoothStackState;
96     }
97 
98     /**
99      * @return tx time in ms
100      */
getControllerTxTimeMillis()101     public int getControllerTxTimeMillis() {
102         return mControllerTxTimeMs;
103     }
104 
105     /**
106      * @return rx time in ms
107      */
getControllerRxTimeMillis()108     public int getControllerRxTimeMillis() {
109         return mControllerRxTimeMs;
110     }
111 
112     /**
113      * @return idle time in ms
114      */
getControllerIdleTimeMillis()115     public int getControllerIdleTimeMillis() {
116         return mControllerIdleTimeMs;
117     }
118 
119     /**
120      * product of current(mA), voltage(V) and time(ms)
121      * @return energy used
122      */
getControllerEnergyUsed()123     public int getControllerEnergyUsed() {
124         return mControllerEnergyUsed;
125     }
126     /**
127      * @return timestamp(wall clock) of record creation
128      */
getTimeStamp()129     public long getTimeStamp() {
130         return timestamp;
131     }
132 
133     /**
134      * @return if the record is valid
135      */
isValid()136     public boolean isValid() {
137         return ((getControllerTxTimeMillis() !=0) ||
138                 (getControllerRxTimeMillis() !=0) ||
139                 (getControllerIdleTimeMillis() !=0));
140     }
141 }
142