ModemActivityInfo.java revision 938dcc88fd19425db4fc604c69a022760738028b
1/* 2 * Copyright (C) 2015 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 17package android.telephony; 18 19import android.os.Parcel; 20import android.os.Parcelable; 21 22import java.util.Arrays; 23 24/** 25 * Reports modem activity information 26 * @hide 27 */ 28public class ModemActivityInfo implements Parcelable { 29 /** 30 * Tx power index 31 * index 0 = tx_power < 0dBm 32 * index 1 = 0dBm < tx_power < 5dBm 33 * index 2 = 5dBm < tx_power < 15dBm 34 * index 3 = 15dBm < tx_power < 20dBm 35 * index 4 = tx_power > 20dBm 36 */ 37 public static final int TX_POWER_LEVELS = 5; 38 39 private final long mTimestamp; 40 private final int mSleepTimeMs; 41 private final int mIdleTimeMs; 42 private final int [] mTxTimeMs = new int[TX_POWER_LEVELS]; 43 private final int mRxTimeMs; 44 private final int mEnergyUsed; 45 46 public ModemActivityInfo(long timestamp, int sleepTimeMs, int idleTimeMs, 47 int[] txTimeMs, int rxTimeMs, int energyUsed) { 48 mTimestamp = timestamp; 49 mSleepTimeMs = sleepTimeMs; 50 mIdleTimeMs = idleTimeMs; 51 if (txTimeMs != null) { 52 System.arraycopy(txTimeMs, 0, mTxTimeMs, 0, Math.min(txTimeMs.length, TX_POWER_LEVELS)); 53 } 54 mRxTimeMs = rxTimeMs; 55 mEnergyUsed = energyUsed; 56 } 57 58 @Override 59 public String toString() { 60 return "ModemActivityInfo{" 61 + " mTimestamp=" + mTimestamp 62 + " mSleepTimeMs=" + mSleepTimeMs 63 + " mTxTimeMs[]=" + Arrays.toString(mTxTimeMs) 64 + " mRxTimeMs=" + mRxTimeMs 65 + " mEnergyUsed=" + mEnergyUsed 66 + "}"; 67 } 68 69 public int describeContents() { 70 return 0; 71 } 72 73 public static final Parcelable.Creator<ModemActivityInfo> CREATOR = 74 new Parcelable.Creator<ModemActivityInfo>() { 75 public ModemActivityInfo createFromParcel(Parcel in) { 76 long timestamp = in.readLong(); 77 int sleepTimeMs = in.readInt(); 78 int idleTimeMs = in.readInt(); 79 int[] txTimeMs = new int[TX_POWER_LEVELS]; 80 for (int i = 0; i < TX_POWER_LEVELS; i++) { 81 txTimeMs[i] = in.readInt(); 82 } 83 int rxTimeMs = in.readInt(); 84 int energyUsed = in.readInt(); 85 return new ModemActivityInfo(timestamp, sleepTimeMs, idleTimeMs, 86 txTimeMs, rxTimeMs, energyUsed); 87 } 88 89 public ModemActivityInfo[] newArray(int size) { 90 return new ModemActivityInfo[size]; 91 } 92 }; 93 94 public void writeToParcel(Parcel dest, int flags) { 95 dest.writeLong(mTimestamp); 96 dest.writeInt(mSleepTimeMs); 97 dest.writeInt(mIdleTimeMs); 98 for (int i = 0; i < TX_POWER_LEVELS; i++) { 99 dest.writeInt(mTxTimeMs[i]); 100 } 101 dest.writeInt(mRxTimeMs); 102 dest.writeInt(mEnergyUsed); 103 } 104 105 /** 106 * @return timestamp of record creation 107 */ 108 public long getTimestamp() { 109 return mTimestamp; 110 } 111 112 /** 113 * @return tx time in ms. It's an array of tx times 114 * with each index... 115 */ 116 public int [] getTxTimeMillis() { 117 return mTxTimeMs; 118 } 119 120 /** 121 * @return sleep time in ms. 122 */ 123 public int getSleepTimeMillis() { 124 return mSleepTimeMs; 125 } 126 127 /** 128 * @return idle time in ms. 129 */ 130 public int getIdleTimeMillis() { 131 return mIdleTimeMs; 132 } 133 134 /** 135 * @return rx time in ms. 136 */ 137 public int getRxTimeMillis() { 138 return mRxTimeMs; 139 } 140 141 /** 142 * product of current(mA), voltage(V) and time(ms) 143 * @return energy used 144 */ 145 public int getEnergyUsed () { 146 return mEnergyUsed; 147 } 148 149 /** 150 * @return if the record is valid 151 */ 152 public boolean isValid() { 153 int totalTxTimeMs = 0; 154 int txTime [] = getTxTimeMillis(); 155 for (int i = 0; i < TX_POWER_LEVELS; i++) { 156 totalTxTimeMs += txTime[i]; 157 } 158 return ((getIdleTimeMillis() != 0) || (totalTxTimeMs != 0) 159 || (getSleepTimeMillis() != 0) || (getIdleTimeMillis() != 0)); 160 } 161} 162