BatterySipper.java revision d45665bf0b26fddf5716a0fd43036848d9301960
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 double mobilemspp;         // milliseconds per packet
39    public long wifiRxPackets;
40    public long wifiTxPackets;
41    public long mobileRxBytes;
42    public long mobileTxBytes;
43    public long wifiRxBytes;
44    public long wifiTxBytes;
45    public double percent;
46    public double noCoveragePercent;
47    public String[] mPackages;
48    public String packageWithHighestDrain;
49
50    public enum DrainType {
51        IDLE,
52        CELL,
53        PHONE,
54        WIFI,
55        BLUETOOTH,
56        SCREEN,
57        APP,
58        USER,
59        UNACCOUNTED,
60        OVERCOUNTED
61    }
62
63    public BatterySipper(DrainType drainType, Uid uid, double[] values) {
64        this.values = values;
65        if (values != null) value = values[0];
66        this.drainType = drainType;
67        uidObj = uid;
68    }
69
70    public double[] getValues() {
71        return values;
72    }
73
74    public void computeMobilemspp() {
75        long packets = mobileRxPackets+mobileTxPackets;
76        mobilemspp = packets > 0 ? (mobileActive / (double)packets) : 0;
77    }
78
79    @Override
80    public int compareTo(BatterySipper other) {
81        // Return the flipped value because we want the items in descending order
82        return Double.compare(other.value, value);
83    }
84
85    /**
86     * Gets a list of packages associated with the current user
87     */
88    public String[] getPackages() {
89        return mPackages;
90    }
91
92    public int getUid() {
93        // Bail out if the current sipper is not an App sipper.
94        if (uidObj == null) {
95            return 0;
96        }
97        return uidObj.getUid();
98    }
99}
100