FileDocCategorySizeDatePackage
BatteryStatsService.javaAPI DocAndroid 1.5 API8713Wed May 06 22:42:00 BST 2009com.android.server.am

BatteryStatsService

public final class BatteryStatsService extends IBatteryStats.Stub
All information we are collecting about things that can happen that impact battery life.

Fields Summary
static com.android.internal.app.IBatteryStats
sService
final com.android.internal.os.BatteryStatsImpl
mStats
android.content.Context
mContext
Constructors Summary
BatteryStatsService(String filename)

        mStats = new BatteryStatsImpl(filename);
    
Methods Summary
protected voiddump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)

        synchronized (mStats) {
            boolean isCheckin = false;
            if (args != null) {
                for (String arg : args) {
                    if ("-c".equals(arg)) {
                        isCheckin = true;
                        break;
                    }
                }
            }
            if (isCheckin) mStats.dumpCheckinLocked(pw, args);
            else mStats.dumpLocked(new PrintWriterPrinter(pw));
        }
    
public voidenforceCallingPermission()

        if (Binder.getCallingPid() == Process.myPid()) {
            return;
        }
        mContext.enforcePermission(android.Manifest.permission.UPDATE_DEVICE_STATS,
                Binder.getCallingPid(), Binder.getCallingUid(), null);
    
public com.android.internal.os.BatteryStatsImplgetActiveStatistics()

return
the current statistics object, which may be modified to reflect events that affect battery usage. You must lock the stats object before doing anything with it.

        return mStats;
    
public longgetAwakeTimeBattery()

        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.BATTERY_STATS, null);
        return mStats.getAwakeTimeBattery();
    
public longgetAwakeTimePlugged()

        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.BATTERY_STATS, null);
        return mStats.getAwakeTimePlugged();
    
public static com.android.internal.app.IBatteryStatsgetService()

        if (sService != null) {
            return sService;
        }
        IBinder b = ServiceManager.getService("batteryinfo");
        sService = asInterface(b);
        return sService;
    
public byte[]getStatistics()

        mContext.enforceCallingPermission(
                android.Manifest.permission.BATTERY_STATS, null);
        //Log.i("foo", "SENDING BATTERY INFO:");
        //mStats.dumpLocked(new LogPrinter(Log.INFO, "foo"));
        Parcel out = Parcel.obtain();
        mStats.writeToParcel(out, 0);
        byte[] data = out.marshall();
        out.recycle();
        return data;
    
public booleanisOnBattery()

        return mStats.isOnBattery();
    
public voidnoteBluetoothOff()

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteBluetoothOffLocked();
        }
    
public voidnoteBluetoothOn()

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteBluetoothOnLocked();
        }
    
public voidnoteFullWifiLockAcquired(int uid)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteFullWifiLockAcquiredLocked(uid);
        }
    
public voidnoteFullWifiLockReleased(int uid)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteFullWifiLockReleasedLocked(uid);
        }
    
public voidnoteInputEvent()

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteInputEventLocked();
        }
    
public voidnotePhoneDataConnectionState(int dataType, boolean hasData)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.notePhoneDataConnectionStateLocked(dataType, hasData);
        }
    
public voidnotePhoneOff()

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.notePhoneOffLocked();
        }
    
public voidnotePhoneOn()

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.notePhoneOnLocked();
        }
    
public voidnotePhoneSignalStrength(int asu)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.notePhoneSignalStrengthLocked(asu);
        }
    
public voidnoteScanWifiLockAcquired(int uid)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteScanWifiLockAcquiredLocked(uid);
        }
    
public voidnoteScanWifiLockReleased(int uid)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteScanWifiLockReleasedLocked(uid);
        }
    
public voidnoteScreenBrightness(int brightness)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteScreenBrightnessLocked(brightness);
        }
    
public voidnoteScreenOff()

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteScreenOffLocked();
        }
    
public voidnoteScreenOn()

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteScreenOnLocked();
        }
    
public voidnoteStartGps(int uid)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteStartGps(uid);
        }
    
public voidnoteStartSensor(int uid, int sensor)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.getUidStatsLocked(uid).noteStartSensor(sensor);
        }
    
public voidnoteStartWakelock(int uid, java.lang.String name, int type)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.getUidStatsLocked(uid).noteStartWakeLocked(name, type);
        }
    
public voidnoteStopGps(int uid)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteStopGps(uid);
        }
    
public voidnoteStopSensor(int uid, int sensor)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.getUidStatsLocked(uid).noteStopSensor(sensor);
        }
    
public voidnoteStopWakelock(int uid, java.lang.String name, int type)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.getUidStatsLocked(uid).noteStopWakeLocked(name, type);
        }
    
public voidnoteUserActivity(int uid, int event)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteUserActivityLocked(uid, event);
        }
    
public voidnoteWifiOff(int uid)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteWifiOffLocked(uid);
        }
    
public voidnoteWifiOn(int uid)

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteWifiOnLocked(uid);
        }
    
public voidnoteWifiRunning()

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteWifiRunningLocked();
        }
    
public voidnoteWifiStopped()

        enforceCallingPermission();
        synchronized (mStats) {
            mStats.noteWifiStoppedLocked();
        }
    
public voidpublish(android.content.Context context)

        mContext = context;
        ServiceManager.addService("batteryinfo", asBinder());
    
public voidsetOnBattery(boolean onBattery, int level)

        enforceCallingPermission();
        mStats.setOnBattery(onBattery, level);