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 */ 16 package com.android.internal.os; 17 18 import android.os.BatteryStats.Uid; 19 20 /** 21 * Contains power usage of an application, system service, or hardware type. 22 */ 23 public 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 BatterySipper(DrainType drainType, Uid uid, double[] values)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 getValues()72 public double[] getValues() { 73 return values; 74 } 75 computeMobilemspp()76 public void computeMobilemspp() { 77 long packets = mobileRxPackets+mobileTxPackets; 78 mobilemspp = packets > 0 ? (mobileActive / (double)packets) : 0; 79 } 80 81 @Override compareTo(BatterySipper other)82 public int compareTo(BatterySipper other) { 83 // Over-counted always goes to the bottom. 84 if (drainType != other.drainType) { 85 if (drainType == DrainType.OVERCOUNTED) { 86 // This is "larger" 87 return 1; 88 } else if (other.drainType == DrainType.OVERCOUNTED) { 89 return -1; 90 } 91 } 92 // Return the flipped value because we want the items in descending order 93 return Double.compare(other.value, value); 94 } 95 96 /** 97 * Gets a list of packages associated with the current user 98 */ getPackages()99 public String[] getPackages() { 100 return mPackages; 101 } 102 getUid()103 public int getUid() { 104 // Bail out if the current sipper is not an App sipper. 105 if (uidObj == null) { 106 return 0; 107 } 108 return uidObj.getUid(); 109 } 110 } 111