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.net.wifi;
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 wifi stack state. Timestamp the record with elapsed
25  * real-time.
26  * @hide
27  */
28 public final class WifiActivityEnergyInfo implements Parcelable {
29     /**
30      * @hide
31      */
32     public long mTimestamp;
33 
34     /**
35      * @hide
36      */
37     public int mStackState;
38 
39     /**
40      * @hide
41      */
42     public long mControllerTxTimeMs;
43 
44     /**
45      * @hide
46      */
47     public long mControllerRxTimeMs;
48 
49     /**
50      * @hide
51      */
52     public long mControllerIdleTimeMs;
53 
54     /**
55      * @hide
56      */
57     public long mControllerEnergyUsed;
58 
59     public static final int STACK_STATE_INVALID = 0;
60     public static final int STACK_STATE_STATE_ACTIVE = 1;
61     public static final int STACK_STATE_STATE_SCANNING = 2;
62     public static final int STACK_STATE_STATE_IDLE = 3;
63 
WifiActivityEnergyInfo(long timestamp, int stackState, long txTime, long rxTime, long idleTime, long energyUsed)64     public WifiActivityEnergyInfo(long timestamp, int stackState,
65                                   long txTime, long rxTime, long idleTime, long energyUsed) {
66         mTimestamp = timestamp;
67         mStackState = stackState;
68         mControllerTxTimeMs = txTime;
69         mControllerRxTimeMs = rxTime;
70         mControllerIdleTimeMs = idleTime;
71         mControllerEnergyUsed = energyUsed;
72     }
73 
74     @Override
toString()75     public String toString() {
76         return "WifiActivityEnergyInfo{"
77             + " timestamp=" + mTimestamp
78             + " mStackState=" + mStackState
79             + " mControllerTxTimeMs=" + mControllerTxTimeMs
80             + " mControllerRxTimeMs=" + mControllerRxTimeMs
81             + " mControllerIdleTimeMs=" + mControllerIdleTimeMs
82             + " mControllerEnergyUsed=" + mControllerEnergyUsed
83             + " }";
84     }
85 
86     public static final Parcelable.Creator<WifiActivityEnergyInfo> CREATOR =
87             new Parcelable.Creator<WifiActivityEnergyInfo>() {
88         public WifiActivityEnergyInfo createFromParcel(Parcel in) {
89             long timestamp = in.readLong();
90             int stackState = in.readInt();
91             long txTime = in.readLong();
92             long rxTime = in.readLong();
93             long idleTime = in.readLong();
94             long energyUsed = in.readLong();
95             return new WifiActivityEnergyInfo(timestamp, stackState,
96                     txTime, rxTime, idleTime, energyUsed);
97         }
98         public WifiActivityEnergyInfo[] newArray(int size) {
99             return new WifiActivityEnergyInfo[size];
100         }
101     };
102 
writeToParcel(Parcel out, int flags)103     public void writeToParcel(Parcel out, int flags) {
104         out.writeLong(mTimestamp);
105         out.writeInt(mStackState);
106         out.writeLong(mControllerTxTimeMs);
107         out.writeLong(mControllerRxTimeMs);
108         out.writeLong(mControllerIdleTimeMs);
109         out.writeLong(mControllerEnergyUsed);
110     }
111 
describeContents()112     public int describeContents() {
113         return 0;
114     }
115 
116     /**
117      * @return bt stack reported state
118      */
getStackState()119     public int getStackState() {
120         return mStackState;
121     }
122 
123     /**
124      * @return tx time in ms
125      */
getControllerTxTimeMillis()126     public long getControllerTxTimeMillis() {
127         return mControllerTxTimeMs;
128     }
129 
130     /**
131      * @return rx time in ms
132      */
getControllerRxTimeMillis()133     public long getControllerRxTimeMillis() {
134         return mControllerRxTimeMs;
135     }
136 
137     /**
138      * @return idle time in ms
139      */
getControllerIdleTimeMillis()140     public long getControllerIdleTimeMillis() {
141         return mControllerIdleTimeMs;
142     }
143 
144     /**
145      * product of current(mA), voltage(V) and time(ms)
146      * @return energy used
147      */
getControllerEnergyUsed()148     public long getControllerEnergyUsed() {
149         return mControllerEnergyUsed;
150     }
151     /**
152      * @return timestamp(wall clock) of record creation
153      */
getTimeStamp()154     public long getTimeStamp() {
155         return mTimestamp;
156     }
157 
158     /**
159      * @return if the record is valid
160      */
isValid()161     public boolean isValid() {
162         return ((mControllerTxTimeMs !=0) ||
163                 (mControllerRxTimeMs !=0) ||
164                 (mControllerIdleTimeMs !=0));
165     }
166 }
167