blob: a0af392fc6d5fdce67c441108f37f9d1ae89fc7e [file] [log] [blame]
Prerepa Viswanadham5c728992015-05-28 00:12:37 -07001/*
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
Chenjie Yu89083392018-01-11 14:53:31 -080039 private long mTimestamp;
40 private int mSleepTimeMs;
41 private int mIdleTimeMs;
42 private int [] mTxTimeMs = new int[TX_POWER_LEVELS];
43 private int mRxTimeMs;
44 private int mEnergyUsed;
Prerepa Viswanadham5c728992015-05-28 00:12:37 -070045
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;
Amit Mahajan938dcc82016-01-28 15:30:39 -080051 if (txTimeMs != null) {
52 System.arraycopy(txTimeMs, 0, mTxTimeMs, 0, Math.min(txTimeMs.length, TX_POWER_LEVELS));
53 }
Prerepa Viswanadham5c728992015-05-28 00:12:37 -070054 mRxTimeMs = rxTimeMs;
55 mEnergyUsed = energyUsed;
56 }
57
58 @Override
59 public String toString() {
60 return "ModemActivityInfo{"
61 + " mTimestamp=" + mTimestamp
62 + " mSleepTimeMs=" + mSleepTimeMs
Adam Lesinski21f76aa2016-01-25 12:27:06 -080063 + " mIdleTimeMs=" + mIdleTimeMs
Prerepa Viswanadham5c728992015-05-28 00:12:37 -070064 + " mTxTimeMs[]=" + Arrays.toString(mTxTimeMs)
65 + " mRxTimeMs=" + mRxTimeMs
66 + " mEnergyUsed=" + mEnergyUsed
67 + "}";
68 }
69
70 public int describeContents() {
71 return 0;
72 }
73
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070074 public static final @android.annotation.NonNull Parcelable.Creator<ModemActivityInfo> CREATOR =
Prerepa Viswanadham5c728992015-05-28 00:12:37 -070075 new Parcelable.Creator<ModemActivityInfo>() {
76 public ModemActivityInfo createFromParcel(Parcel in) {
77 long timestamp = in.readLong();
78 int sleepTimeMs = in.readInt();
79 int idleTimeMs = in.readInt();
80 int[] txTimeMs = new int[TX_POWER_LEVELS];
81 for (int i = 0; i < TX_POWER_LEVELS; i++) {
82 txTimeMs[i] = in.readInt();
83 }
84 int rxTimeMs = in.readInt();
85 int energyUsed = in.readInt();
86 return new ModemActivityInfo(timestamp, sleepTimeMs, idleTimeMs,
87 txTimeMs, rxTimeMs, energyUsed);
88 }
89
90 public ModemActivityInfo[] newArray(int size) {
91 return new ModemActivityInfo[size];
92 }
93 };
94
95 public void writeToParcel(Parcel dest, int flags) {
96 dest.writeLong(mTimestamp);
97 dest.writeInt(mSleepTimeMs);
98 dest.writeInt(mIdleTimeMs);
99 for (int i = 0; i < TX_POWER_LEVELS; i++) {
100 dest.writeInt(mTxTimeMs[i]);
101 }
102 dest.writeInt(mRxTimeMs);
103 dest.writeInt(mEnergyUsed);
104 }
105
106 /**
107 * @return timestamp of record creation
108 */
109 public long getTimestamp() {
110 return mTimestamp;
111 }
112
Chenjie Yu89083392018-01-11 14:53:31 -0800113 public void setTimestamp(long timestamp) {
114 mTimestamp = timestamp;
115 }
116
Prerepa Viswanadham5c728992015-05-28 00:12:37 -0700117 /**
118 * @return tx time in ms. It's an array of tx times
119 * with each index...
120 */
121 public int [] getTxTimeMillis() {
122 return mTxTimeMs;
123 }
124
Chenjie Yu89083392018-01-11 14:53:31 -0800125 public void setTxTimeMillis(int[] txTimeMs) {
126 mTxTimeMs = txTimeMs;
127 }
128
Prerepa Viswanadham5c728992015-05-28 00:12:37 -0700129 /**
130 * @return sleep time in ms.
131 */
132 public int getSleepTimeMillis() {
133 return mSleepTimeMs;
134 }
135
Chenjie Yu89083392018-01-11 14:53:31 -0800136 public void setSleepTimeMillis(int sleepTimeMillis) {
137 mSleepTimeMs = sleepTimeMillis;
138 }
139
Prerepa Viswanadham5c728992015-05-28 00:12:37 -0700140 /**
141 * @return idle time in ms.
142 */
143 public int getIdleTimeMillis() {
144 return mIdleTimeMs;
145 }
146
Chenjie Yu89083392018-01-11 14:53:31 -0800147 public void setIdleTimeMillis(int idleTimeMillis) {
148 mIdleTimeMs = idleTimeMillis;
149 }
150
Prerepa Viswanadham5c728992015-05-28 00:12:37 -0700151 /**
152 * @return rx time in ms.
153 */
154 public int getRxTimeMillis() {
155 return mRxTimeMs;
156 }
157
Chenjie Yu89083392018-01-11 14:53:31 -0800158 public void setRxTimeMillis(int rxTimeMillis) {
159 mRxTimeMs = rxTimeMillis;
160 }
161
Prerepa Viswanadham5c728992015-05-28 00:12:37 -0700162 /**
163 * product of current(mA), voltage(V) and time(ms)
164 * @return energy used
165 */
166 public int getEnergyUsed () {
167 return mEnergyUsed;
168 }
169
Chenjie Yu89083392018-01-11 14:53:31 -0800170 public void setEnergyUsed(int energyUsed) {
171 mEnergyUsed = energyUsed;
172 }
173
Prerepa Viswanadham5c728992015-05-28 00:12:37 -0700174 /**
175 * @return if the record is valid
176 */
177 public boolean isValid() {
Nathan Harold98a40d32016-04-19 17:17:59 -0700178 for (int txVal : getTxTimeMillis()) {
179 if(txVal < 0) {
180 return false;
181 }
Prerepa Viswanadham5c728992015-05-28 00:12:37 -0700182 }
Nathan Harold98a40d32016-04-19 17:17:59 -0700183
184 return ((getIdleTimeMillis() >= 0) && (getSleepTimeMillis() >= 0)
185 && (getRxTimeMillis() >= 0) && (getEnergyUsed() >= 0) && !isEmpty());
186 }
187
188 private boolean isEmpty() {
189 for (int txVal : getTxTimeMillis()) {
190 if(txVal != 0) {
191 return false;
192 }
193 }
194
195 return ((getIdleTimeMillis() == 0) && (getSleepTimeMillis() == 0)
196 && (getRxTimeMillis() == 0) && (getEnergyUsed() == 0));
Prerepa Viswanadham5c728992015-05-28 00:12:37 -0700197 }
198}