Home | History | Annotate | Download | only in telephony
      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 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;
     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             + " mIdleTimeMs=" + mIdleTimeMs
     64             + " mTxTimeMs[]=" + Arrays.toString(mTxTimeMs)
     65             + " mRxTimeMs=" + mRxTimeMs
     66             + " mEnergyUsed=" + mEnergyUsed
     67             + "}";
     68     }
     69 
     70     public int describeContents() {
     71         return 0;
     72     }
     73 
     74     public static final Parcelable.Creator<ModemActivityInfo> CREATOR =
     75             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 
    113     public void setTimestamp(long timestamp) {
    114         mTimestamp = timestamp;
    115     }
    116 
    117     /**
    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 
    125     public void setTxTimeMillis(int[] txTimeMs) {
    126         mTxTimeMs = txTimeMs;
    127     }
    128 
    129     /**
    130      * @return sleep time in ms.
    131      */
    132     public int getSleepTimeMillis() {
    133         return mSleepTimeMs;
    134     }
    135 
    136     public void setSleepTimeMillis(int sleepTimeMillis) {
    137         mSleepTimeMs = sleepTimeMillis;
    138     }
    139 
    140     /**
    141      * @return idle time in ms.
    142      */
    143     public int getIdleTimeMillis() {
    144         return mIdleTimeMs;
    145     }
    146 
    147     public void setIdleTimeMillis(int idleTimeMillis) {
    148         mIdleTimeMs = idleTimeMillis;
    149     }
    150 
    151     /**
    152      * @return rx time in ms.
    153      */
    154     public int getRxTimeMillis() {
    155         return mRxTimeMs;
    156     }
    157 
    158     public void setRxTimeMillis(int rxTimeMillis) {
    159         mRxTimeMs = rxTimeMillis;
    160     }
    161 
    162     /**
    163      * product of current(mA), voltage(V) and time(ms)
    164      * @return energy used
    165      */
    166     public int getEnergyUsed () {
    167         return mEnergyUsed;
    168     }
    169 
    170     public void setEnergyUsed(int energyUsed) {
    171         mEnergyUsed = energyUsed;
    172     }
    173 
    174     /**
    175      * @return if the record is valid
    176      */
    177     public boolean isValid() {
    178         for (int txVal : getTxTimeMillis()) {
    179             if(txVal < 0) {
    180                 return false;
    181             }
    182         }
    183 
    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));
    197     }
    198 }
    199