BatterySipper.java revision 77b987f1a1bb6028a871de01065b94c4cfff0b5c
1/*
2 * Copyright (C) 2009 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 */
16package com.android.internal.os;
17
18import android.os.BatteryStats.Uid;
19
20/**
21 * Contains power usage of an application, system service, or hardware type.
22 */
23public class BatterySipper implements Comparable<BatterySipper> {
24    public int userId;
25    public Uid uidObj;
26    public double value;
27    public double[] values;
28    public DrainType drainType;
29    public long usageTime;
30    public long cpuTime;
31    public long gpsTime;
32    public long wifiRunningTime;
33    public long cpuFgTime;
34    public long wakeLockTime;
35    public long mobileRxPackets;
36    public long mobileTxPackets;
37    public long mobileActive;
38    public int mobileActiveCount;
39    public double mobilemspp;         // milliseconds per packet
40    public long wifiRxPackets;
41    public long wifiTxPackets;
42    public long mobileRxBytes;
43    public long mobileTxBytes;
44    public long wifiRxBytes;
45    public long wifiTxBytes;
46    public double percent;
47    public double noCoveragePercent;
48    public String[] mPackages;
49    public String packageWithHighestDrain;
50
51    public enum DrainType {
52        IDLE,
53        CELL,
54        PHONE,
55        WIFI,
56        BLUETOOTH,
57        SCREEN,
58        APP,
59        USER,
60        UNACCOUNTED,
61        OVERCOUNTED
62    }
63
64    public BatterySipper(DrainType drainType, Uid uid, double[] values) {
65        this.values = values;
66        if (values != null) value = values[0];
67        this.drainType = drainType;
68        uidObj = uid;
69    }
70
71    public double[] getValues() {
72        return values;
73    }
74
75    public void computeMobilemspp() {
76        long packets = mobileRxPackets+mobileTxPackets;
77        mobilemspp = packets > 0 ? (mobileActive / (double)packets) : 0;
78    }
79
80    @Override
81    public int compareTo(BatterySipper other) {
82        // Return the flipped value because we want the items in descending order
83        return Double.compare(other.value, value);
84    }
85
86    /**
87     * Gets a list of packages associated with the current user
88     */
89    public String[] getPackages() {
90        return mPackages;
91    }
92
93    public int getUid() {
94        // Bail out if the current sipper is not an App sipper.
95        if (uidObj == null) {
96            return 0;
97        }
98        return uidObj.getUid();
99    }
100}
101