1b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle/* 2b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * Copyright (C) 2014 The Android Open Source Project 3b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * 4b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * Licensed under the Apache License, Version 2.0 (the "License"); 5b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * you may not use this file except in compliance with the License. 6b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * You may obtain a copy of the License at 7b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * 8b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * http://www.apache.org/licenses/LICENSE-2.0 9b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * 10b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * Unless required by applicable law or agreed to in writing, software 11b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * distributed under the License is distributed on an "AS IS" BASIS, 12b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * See the License for the specific language governing permissions and 14b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * limitations under the License. 15b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle */ 16b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 17b928a3802bfcd3aeed592906ddb3e14c653b213cvandwallepackage android.net.wifi; 18b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 19b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalleimport android.os.Parcel; 20b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalleimport android.os.Parcelable; 21b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 22b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle/** 23b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * Record of energy and activity information from controller and 24488caeb70293b7c70e9ce128fc002a0666340fb0Adam Lesinski * underlying wifi stack state. Timestamp the record with elapsed 25488caeb70293b7c70e9ce128fc002a0666340fb0Adam Lesinski * real-time. 26b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * @hide 27b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle */ 28b928a3802bfcd3aeed592906ddb3e14c653b213cvandwallepublic final class WifiActivityEnergyInfo implements Parcelable { 294b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski /** 304b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski * @hide 314b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski */ 324b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski public long mTimestamp; 334b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski 344b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski /** 354b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski * @hide 364b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski */ 374b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski public int mStackState; 384b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski 394b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski /** 404b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski * @hide 414b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski */ 428a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski public long mControllerTxTimeMs; 434b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski 444b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski /** 454b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski * @hide 464b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski */ 478a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski public long mControllerRxTimeMs; 484b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski 494b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski /** 504b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski * @hide 514b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski */ 528a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski public long mControllerIdleTimeMs; 534b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski 544b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski /** 554b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski * @hide 564b6bd8d36b093d36d9ae80b43e95049c259d7319Adam Lesinski */ 578a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski public long mControllerEnergyUsed; 58b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 59b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle public static final int STACK_STATE_INVALID = 0; 60b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle public static final int STACK_STATE_STATE_ACTIVE = 1; 61b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle public static final int STACK_STATE_STATE_SCANNING = 2; 62b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle public static final int STACK_STATE_STATE_IDLE = 3; 63b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 64488caeb70293b7c70e9ce128fc002a0666340fb0Adam Lesinski public WifiActivityEnergyInfo(long timestamp, int stackState, 658a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski long txTime, long rxTime, long idleTime, long energyUsed) { 66488caeb70293b7c70e9ce128fc002a0666340fb0Adam Lesinski mTimestamp = timestamp; 67b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle mStackState = stackState; 68b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle mControllerTxTimeMs = txTime; 69b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle mControllerRxTimeMs = rxTime; 70b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle mControllerIdleTimeMs = idleTime; 71b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle mControllerEnergyUsed = energyUsed; 72b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle } 73b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 74b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle @Override 75b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle public String toString() { 76b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle return "WifiActivityEnergyInfo{" 77488caeb70293b7c70e9ce128fc002a0666340fb0Adam Lesinski + " timestamp=" + mTimestamp 78b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle + " mStackState=" + mStackState 79b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle + " mControllerTxTimeMs=" + mControllerTxTimeMs 80b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle + " mControllerRxTimeMs=" + mControllerRxTimeMs 81b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle + " mControllerIdleTimeMs=" + mControllerIdleTimeMs 82b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle + " mControllerEnergyUsed=" + mControllerEnergyUsed 83b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle + " }"; 84b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle } 85b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 86b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle public static final Parcelable.Creator<WifiActivityEnergyInfo> CREATOR = 87b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle new Parcelable.Creator<WifiActivityEnergyInfo>() { 88b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle public WifiActivityEnergyInfo createFromParcel(Parcel in) { 89488caeb70293b7c70e9ce128fc002a0666340fb0Adam Lesinski long timestamp = in.readLong(); 90b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle int stackState = in.readInt(); 918a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski long txTime = in.readLong(); 928a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski long rxTime = in.readLong(); 938a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski long idleTime = in.readLong(); 948a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski long energyUsed = in.readLong(); 95488caeb70293b7c70e9ce128fc002a0666340fb0Adam Lesinski return new WifiActivityEnergyInfo(timestamp, stackState, 96488caeb70293b7c70e9ce128fc002a0666340fb0Adam Lesinski txTime, rxTime, idleTime, energyUsed); 97b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle } 98b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle public WifiActivityEnergyInfo[] newArray(int size) { 99b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle return new WifiActivityEnergyInfo[size]; 100b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle } 101b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle }; 102b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 103b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle public void writeToParcel(Parcel out, int flags) { 104488caeb70293b7c70e9ce128fc002a0666340fb0Adam Lesinski out.writeLong(mTimestamp); 105b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle out.writeInt(mStackState); 1068a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski out.writeLong(mControllerTxTimeMs); 1078a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski out.writeLong(mControllerRxTimeMs); 1088a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski out.writeLong(mControllerIdleTimeMs); 1098a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski out.writeLong(mControllerEnergyUsed); 110b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle } 111b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 112b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle public int describeContents() { 113b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle return 0; 114b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle } 115b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 116b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle /** 117b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * @return bt stack reported state 118b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle */ 119b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle public int getStackState() { 120b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle return mStackState; 121b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle } 122b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 123b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle /** 124b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * @return tx time in ms 125b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle */ 1268a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski public long getControllerTxTimeMillis() { 1278a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski return mControllerTxTimeMs; 128b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle } 129b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 130b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle /** 131b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * @return rx time in ms 132b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle */ 1338a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski public long getControllerRxTimeMillis() { 1348a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski return mControllerRxTimeMs; 135b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle } 136b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 137b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle /** 138b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * @return idle time in ms 139b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle */ 1408a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski public long getControllerIdleTimeMillis() { 1418a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski return mControllerIdleTimeMs; 142b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle } 143b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 144b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle /** 145b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * product of current(mA), voltage(V) and time(ms) 146b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * @return energy used 147b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle */ 1488a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski public long getControllerEnergyUsed() { 149b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle return mControllerEnergyUsed; 150b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle } 151b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle /** 152b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * @return timestamp(wall clock) of record creation 153b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle */ 154b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle public long getTimeStamp() { 155488caeb70293b7c70e9ce128fc002a0666340fb0Adam Lesinski return mTimestamp; 156b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle } 157b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle 158b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle /** 159b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle * @return if the record is valid 160b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle */ 161b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle public boolean isValid() { 1628a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski return ((mControllerTxTimeMs !=0) || 1638a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski (mControllerRxTimeMs !=0) || 1648a351373881e2e11c2636d6f9445f9df9accbaceAdam Lesinski (mControllerIdleTimeMs !=0)); 165b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle } 166b928a3802bfcd3aeed592906ddb3e14c653b213cvandwalle} 167