BatterySipper.java revision abc7c499133fe640d6ece2b28d43b52e66cdaa9a
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        FLASHLIGHT,
58        SCREEN,
59        APP,
60        USER,
61        UNACCOUNTED,
62        OVERCOUNTED
63    }
64
65    public BatterySipper(DrainType drainType, Uid uid, double[] values) {
66        this.values = values;
67        if (values != null) value = values[0];
68        this.drainType = drainType;
69        uidObj = uid;
70    }
71
72    public double[] getValues() {
73        return values;
74    }
75
76    public void computeMobilemspp() {
77        long packets = mobileRxPackets+mobileTxPackets;
78        mobilemspp = packets > 0 ? (mobileActive / (double)packets) : 0;
79    }
80
81    @Override
82    public int compareTo(BatterySipper other) {
83        // Return the flipped value because we want the items in descending order
84        return Double.compare(other.value, value);
85    }
86
87    /**
88     * Gets a list of packages associated with the current user
89     */
90    public String[] getPackages() {
91        return mPackages;
92    }
93
94    public int getUid() {
95        // Bail out if the current sipper is not an App sipper.
96        if (uidObj == null) {
97            return 0;
98        }
99        return uidObj.getUid();
100    }
101}
102