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