Methods Summary |
---|
void | addIsolatedUid(int isolatedUid, int appUid)
synchronized (mStats) {
mStats.addIsolatedUidLocked(isolatedUid, appUid);
}
|
public long | computeBatteryTimeRemaining()
synchronized (mStats) {
long time = mStats.computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
return time >= 0 ? (time/1000) : time;
}
|
public long | computeChargeTimeRemaining()
synchronized (mStats) {
long time = mStats.computeChargeTimeRemaining(SystemClock.elapsedRealtime());
return time >= 0 ? (time/1000) : time;
}
|
private int | doEnableOrDisable(java.io.PrintWriter pw, int i, java.lang.String[] args, boolean enable)
i++;
if (i >= args.length) {
pw.println("Missing option argument for " + (enable ? "--enable" : "--disable"));
dumpHelp(pw);
return -1;
}
if ("full-wake-history".equals(args[i]) || "full-history".equals(args[i])) {
synchronized (mStats) {
mStats.setRecordAllHistoryLocked(enable);
}
} else if ("no-auto-reset".equals(args[i])) {
synchronized (mStats) {
mStats.setNoAutoReset(enable);
}
} else {
pw.println("Unknown enable/disable option: " + args[i]);
dumpHelp(pw);
return -1;
}
return i;
|
protected void | dump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
!= PackageManager.PERMISSION_GRANTED) {
pw.println("Permission Denial: can't dump BatteryStats from from pid="
+ Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
+ " without permission " + android.Manifest.permission.DUMP);
return;
}
int flags = 0;
boolean useCheckinFormat = false;
boolean isRealCheckin = false;
boolean noOutput = false;
boolean writeData = false;
long historyStart = -1;
int reqUid = -1;
if (args != null) {
for (int i=0; i<args.length; i++) {
String arg = args[i];
if ("--checkin".equals(arg)) {
useCheckinFormat = true;
isRealCheckin = true;
} else if ("--history".equals(arg)) {
flags |= BatteryStats.DUMP_HISTORY_ONLY;
} else if ("--history-start".equals(arg)) {
flags |= BatteryStats.DUMP_HISTORY_ONLY;
i++;
if (i >= args.length) {
pw.println("Missing time argument for --history-since");
dumpHelp(pw);
return;
}
historyStart = Long.parseLong(args[i]);
writeData = true;
} else if ("-c".equals(arg)) {
useCheckinFormat = true;
flags |= BatteryStats.DUMP_INCLUDE_HISTORY;
} else if ("--unplugged".equals(arg)) {
flags |= BatteryStats.DUMP_UNPLUGGED_ONLY;
} else if ("--charged".equals(arg)) {
flags |= BatteryStats.DUMP_CHARGED_ONLY;
} else if ("--reset".equals(arg)) {
synchronized (mStats) {
mStats.resetAllStatsCmdLocked();
pw.println("Battery stats reset.");
noOutput = true;
}
} else if ("--write".equals(arg)) {
synchronized (mStats) {
mStats.writeSyncLocked();
pw.println("Battery stats written.");
noOutput = true;
}
} else if ("--enable".equals(arg) || "enable".equals(arg)) {
i = doEnableOrDisable(pw, i, args, true);
if (i < 0) {
return;
}
pw.println("Enabled: " + args[i]);
return;
} else if ("--disable".equals(arg) || "disable".equals(arg)) {
i = doEnableOrDisable(pw, i, args, false);
if (i < 0) {
return;
}
pw.println("Disabled: " + args[i]);
return;
} else if ("-h".equals(arg)) {
dumpHelp(pw);
return;
} else if ("-a".equals(arg)) {
flags |= BatteryStats.DUMP_VERBOSE;
} else if (arg.length() > 0 && arg.charAt(0) == '-"){
pw.println("Unknown option: " + arg);
dumpHelp(pw);
return;
} else {
// Not an option, last argument must be a package name.
try {
reqUid = mContext.getPackageManager().getPackageUid(arg,
UserHandle.getCallingUserId());
} catch (PackageManager.NameNotFoundException e) {
pw.println("Unknown package: " + arg);
dumpHelp(pw);
return;
}
}
}
}
if (noOutput) {
return;
}
if (BatteryStatsHelper.checkWifiOnly(mContext)) {
flags |= BatteryStats.DUMP_DEVICE_WIFI_ONLY;
}
if (reqUid >= 0) {
// By default, if the caller is only interested in a specific package, then
// we only dump the aggregated data since charged.
if ((flags&(BatteryStats.DUMP_HISTORY_ONLY|BatteryStats.DUMP_UNPLUGGED_ONLY
|BatteryStats.DUMP_CHARGED_ONLY)) == 0) {
flags |= BatteryStats.DUMP_CHARGED_ONLY;
// Also if they are doing -c, we don't want history.
flags &= ~BatteryStats.DUMP_INCLUDE_HISTORY;
}
}
if (useCheckinFormat) {
List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0);
if (isRealCheckin) {
// For a real checkin, first we want to prefer to use the last complete checkin
// file if there is one.
synchronized (mStats.mCheckinFile) {
if (mStats.mCheckinFile.exists()) {
try {
byte[] raw = mStats.mCheckinFile.readFully();
if (raw != null) {
Parcel in = Parcel.obtain();
in.unmarshall(raw, 0, raw.length);
in.setDataPosition(0);
BatteryStatsImpl checkinStats = new BatteryStatsImpl(
null, mStats.mHandler);
checkinStats.readSummaryFromParcel(in);
in.recycle();
checkinStats.dumpCheckinLocked(mContext, pw, apps, flags,
historyStart);
mStats.mCheckinFile.delete();
return;
}
} catch (IOException e) {
Slog.w(TAG, "Failure reading checkin file "
+ mStats.mCheckinFile.getBaseFile(), e);
}
}
}
}
synchronized (mStats) {
mStats.dumpCheckinLocked(mContext, pw, apps, flags, historyStart);
if (writeData) {
mStats.writeAsyncLocked();
}
}
} else {
synchronized (mStats) {
mStats.dumpLocked(mContext, pw, flags, reqUid, historyStart);
if (writeData) {
mStats.writeAsyncLocked();
}
}
}
|
private void | dumpHelp(java.io.PrintWriter pw)
pw.println("Battery stats (batterystats) dump options:");
pw.println(" [--checkin] [--history] [--history-start] [--unplugged] [--charged] [-c]");
pw.println(" [--reset] [--write] [-h] [<package.name>]");
pw.println(" --checkin: format output for a checkin report.");
pw.println(" --history: show only history data.");
pw.println(" --history-start <num>: show only history data starting at given time offset.");
pw.println(" --unplugged: only output data since last unplugged.");
pw.println(" --charged: only output data since last charged.");
pw.println(" --reset: reset the stats, clearing all current data.");
pw.println(" --write: force write current collected stats to disk.");
pw.println(" <package.name>: optional name of package to filter output by.");
pw.println(" -h: print this help text.");
pw.println("Battery stats (batterystats) commands:");
pw.println(" enable|disable <option>");
pw.println(" Enable or disable a running option. Option state is not saved across boots.");
pw.println(" Options are:");
pw.println(" full-history: include additional detailed events in battery history:");
pw.println(" wake_lock_in and proc events");
pw.println(" no-auto-reset: don't automatically reset stats when unplugged");
|
public void | enforceCallingPermission()
if (Binder.getCallingPid() == Process.myPid()) {
return;
}
mContext.enforcePermission(android.Manifest.permission.UPDATE_DEVICE_STATS,
Binder.getCallingPid(), Binder.getCallingUid(), null);
|
public com.android.internal.os.BatteryStatsImpl | getActiveStatistics()
return mStats;
|
public long | getAwakeTimeBattery()
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.BATTERY_STATS, null);
return mStats.getAwakeTimeBattery();
|
public long | getAwakeTimePlugged()
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.BATTERY_STATS, null);
return mStats.getAwakeTimePlugged();
|
public static com.android.internal.app.IBatteryStats | getService()
if (sService != null) {
return sService;
}
IBinder b = ServiceManager.getService(BatteryStats.SERVICE_NAME);
sService = asInterface(b);
return sService;
|
public byte[] | getStatistics()
mContext.enforceCallingPermission(
android.Manifest.permission.BATTERY_STATS, null);
//Slog.i("foo", "SENDING BATTERY INFO:");
//mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM));
Parcel out = Parcel.obtain();
mStats.writeToParcel(out, 0);
byte[] data = out.marshall();
out.recycle();
return data;
|
public android.os.ParcelFileDescriptor | getStatisticsStream()
mContext.enforceCallingPermission(
android.Manifest.permission.BATTERY_STATS, null);
//Slog.i("foo", "SENDING BATTERY INFO:");
//mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM));
Parcel out = Parcel.obtain();
mStats.writeToParcel(out, 0);
byte[] data = out.marshall();
out.recycle();
try {
return ParcelFileDescriptor.fromData(data, "battery-stats");
} catch (IOException e) {
Slog.w(TAG, "Unable to create shared memory", e);
return null;
}
|
public void | initPowerManagement()At the time when the constructor runs, the power manager has not yet been
initialized. So we initialize the low power observer later.
mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
mPowerManagerInternal.registerLowPowerModeObserver(this);
mStats.noteLowPowerMode(mPowerManagerInternal.getLowPowerModeEnabled());
(new WakeupReasonThread()).start();
|
public boolean | isOnBattery()
return mStats.isOnBattery();
|
private static native int | nativeWaitWakeup(int[] outIrqs, java.lang.String[] outReasons)
|
public void | noteBluetoothOff()
enforceCallingPermission();
synchronized (mStats) {
mBluetoothPendingStats = false;
mStats.noteBluetoothOffLocked();
}
|
public void | noteBluetoothOn()
enforceCallingPermission();
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener,
BluetoothProfile.HEADSET);
}
synchronized (mStats) {
if (mBluetoothHeadset != null) {
mStats.noteBluetoothOnLocked();
mStats.setBtHeadset(mBluetoothHeadset);
} else {
mBluetoothPendingStats = true;
}
}
|
public void | noteBluetoothState(int bluetoothState)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteBluetoothStateLocked(bluetoothState);
}
|
public void | noteChangeWakelockFromSource(android.os.WorkSource ws, int pid, java.lang.String name, java.lang.String historyName, int type, android.os.WorkSource newWs, int newPid, java.lang.String newName, java.lang.String newHistoryName, int newType, boolean newUnimportantForLogging)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteChangeWakelockFromSourceLocked(ws, pid, name, historyName, type,
newWs, newPid, newName, newHistoryName, newType, newUnimportantForLogging);
}
|
public void | noteConnectivityChanged(int type, java.lang.String extra)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteConnectivityChangedLocked(type, extra);
}
|
public void | noteEvent(int code, java.lang.String name, int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteEventLocked(code, name, uid);
}
|
public void | noteFlashlightOff()
enforceCallingPermission();
synchronized (mStats) {
mStats.noteFlashlightOffLocked();
}
|
public void | noteFlashlightOn()
enforceCallingPermission();
synchronized (mStats) {
mStats.noteFlashlightOnLocked();
}
|
public void | noteFullWifiLockAcquired(int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteFullWifiLockAcquiredLocked(uid);
}
|
public void | noteFullWifiLockAcquiredFromSource(android.os.WorkSource ws)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteFullWifiLockAcquiredFromSourceLocked(ws);
}
|
public void | noteFullWifiLockReleased(int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteFullWifiLockReleasedLocked(uid);
}
|
public void | noteFullWifiLockReleasedFromSource(android.os.WorkSource ws)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteFullWifiLockReleasedFromSourceLocked(ws);
}
|
public void | noteInteractive(boolean interactive)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteInteractiveLocked(interactive);
}
|
public void | noteJobFinish(java.lang.String name, int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteJobFinishLocked(name, uid);
}
|
public void | noteJobStart(java.lang.String name, int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteJobStartLocked(name, uid);
}
|
public void | noteMobileRadioPowerState(int powerState, long timestampNs)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteMobileRadioPowerState(powerState, timestampNs);
}
|
public void | noteNetworkInterfaceType(java.lang.String iface, int type)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteNetworkInterfaceTypeLocked(iface, type);
}
|
public void | noteNetworkStatsEnabled()
enforceCallingPermission();
synchronized (mStats) {
mStats.noteNetworkStatsEnabledLocked();
}
|
public void | notePhoneDataConnectionState(int dataType, boolean hasData)
enforceCallingPermission();
synchronized (mStats) {
mStats.notePhoneDataConnectionStateLocked(dataType, hasData);
}
|
public void | notePhoneOff()
enforceCallingPermission();
synchronized (mStats) {
mStats.notePhoneOffLocked();
}
|
public void | notePhoneOn()
enforceCallingPermission();
synchronized (mStats) {
mStats.notePhoneOnLocked();
}
|
public void | notePhoneSignalStrength(android.telephony.SignalStrength signalStrength)
enforceCallingPermission();
synchronized (mStats) {
mStats.notePhoneSignalStrengthLocked(signalStrength);
}
|
public void | notePhoneState(int state)
enforceCallingPermission();
int simState = TelephonyManager.getDefault().getSimState();
synchronized (mStats) {
mStats.notePhoneStateLocked(state, simState);
}
|
void | noteProcessAnr(java.lang.String name, int uid)
synchronized (mStats) {
mStats.noteProcessAnrLocked(name, uid);
}
|
void | noteProcessCrash(java.lang.String name, int uid)
synchronized (mStats) {
mStats.noteProcessCrashLocked(name, uid);
}
|
void | noteProcessFinish(java.lang.String name, int uid)
synchronized (mStats) {
mStats.noteProcessFinishLocked(name, uid);
}
|
void | noteProcessStart(java.lang.String name, int uid)
synchronized (mStats) {
mStats.noteProcessStartLocked(name, uid);
}
|
void | noteProcessState(java.lang.String name, int uid, int state)
synchronized (mStats) {
mStats.noteProcessStateLocked(name, uid, state);
}
|
public void | noteResetAudio()
enforceCallingPermission();
synchronized (mStats) {
mStats.noteResetAudioLocked();
}
|
public void | noteResetVideo()
enforceCallingPermission();
synchronized (mStats) {
mStats.noteResetVideoLocked();
}
|
public void | noteScreenBrightness(int brightness)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteScreenBrightnessLocked(brightness);
}
|
public void | noteScreenState(int state)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteScreenStateLocked(state);
}
|
public void | noteStartAudio(int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteAudioOnLocked(uid);
}
|
public void | noteStartGps(int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteStartGpsLocked(uid);
}
|
public void | noteStartSensor(int uid, int sensor)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteStartSensorLocked(uid, sensor);
}
|
public void | noteStartVideo(int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteVideoOnLocked(uid);
}
|
public void | noteStartWakelock(int uid, int pid, java.lang.String name, java.lang.String historyName, int type, boolean unimportantForLogging)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteStartWakeLocked(uid, pid, name, historyName, type, unimportantForLogging,
SystemClock.elapsedRealtime(), SystemClock.uptimeMillis());
}
|
public void | noteStartWakelockFromSource(android.os.WorkSource ws, int pid, java.lang.String name, java.lang.String historyName, int type, boolean unimportantForLogging)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteStartWakeFromSourceLocked(ws, pid, name, historyName,
type, unimportantForLogging);
}
|
public void | noteStopAudio(int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteAudioOffLocked(uid);
}
|
public void | noteStopGps(int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteStopGpsLocked(uid);
}
|
public void | noteStopSensor(int uid, int sensor)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteStopSensorLocked(uid, sensor);
}
|
public void | noteStopVideo(int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteVideoOffLocked(uid);
}
|
public void | noteStopWakelock(int uid, int pid, java.lang.String name, java.lang.String historyName, int type)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteStopWakeLocked(uid, pid, name, historyName, type,
SystemClock.elapsedRealtime(), SystemClock.uptimeMillis());
}
|
public void | noteStopWakelockFromSource(android.os.WorkSource ws, int pid, java.lang.String name, java.lang.String historyName, int type)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteStopWakeFromSourceLocked(ws, pid, name, historyName, type);
}
|
public void | noteSyncFinish(java.lang.String name, int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteSyncFinishLocked(name, uid);
}
|
public void | noteSyncStart(java.lang.String name, int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteSyncStartLocked(name, uid);
}
|
public void | noteUserActivity(int uid, int event)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteUserActivityLocked(uid, event);
}
|
public void | noteVibratorOff(int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteVibratorOffLocked(uid);
}
|
public void | noteVibratorOn(int uid, long durationMillis)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteVibratorOnLocked(uid, durationMillis);
}
|
public void | noteWifiBatchedScanStartedFromSource(android.os.WorkSource ws, int csph)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiBatchedScanStartedFromSourceLocked(ws, csph);
}
|
public void | noteWifiBatchedScanStoppedFromSource(android.os.WorkSource ws)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiBatchedScanStoppedFromSourceLocked(ws);
}
|
public void | noteWifiMulticastDisabled(int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiMulticastDisabledLocked(uid);
}
|
public void | noteWifiMulticastDisabledFromSource(android.os.WorkSource ws)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiMulticastDisabledFromSourceLocked(ws);
}
|
public void | noteWifiMulticastEnabled(int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiMulticastEnabledLocked(uid);
}
|
public void | noteWifiMulticastEnabledFromSource(android.os.WorkSource ws)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiMulticastEnabledFromSourceLocked(ws);
}
|
public void | noteWifiOff()
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiOffLocked();
}
|
public void | noteWifiOn()
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiOnLocked();
}
|
public void | noteWifiRssiChanged(int newRssi)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiRssiChangedLocked(newRssi);
}
|
public void | noteWifiRunning(android.os.WorkSource ws)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiRunningLocked(ws);
}
|
public void | noteWifiRunningChanged(android.os.WorkSource oldWs, android.os.WorkSource newWs)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiRunningChangedLocked(oldWs, newWs);
}
|
public void | noteWifiScanStarted(int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiScanStartedLocked(uid);
}
|
public void | noteWifiScanStartedFromSource(android.os.WorkSource ws)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiScanStartedFromSourceLocked(ws);
}
|
public void | noteWifiScanStopped(int uid)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiScanStoppedLocked(uid);
}
|
public void | noteWifiScanStoppedFromSource(android.os.WorkSource ws)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiScanStoppedFromSourceLocked(ws);
}
|
public void | noteWifiState(int wifiState, java.lang.String accessPoint)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiStateLocked(wifiState, accessPoint);
}
|
public void | noteWifiStopped(android.os.WorkSource ws)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiStoppedLocked(ws);
}
|
public void | noteWifiSupplicantStateChanged(int supplState, boolean failedAuth)
enforceCallingPermission();
synchronized (mStats) {
mStats.noteWifiSupplicantStateChangedLocked(supplState, failedAuth);
}
|
public void | onLowPowerModeChanged(boolean enabled)
synchronized (mStats) {
mStats.noteLowPowerMode(enabled);
}
|
public void | publish(android.content.Context context)
mContext = context;
ServiceManager.addService(BatteryStats.SERVICE_NAME, asBinder());
mStats.setNumSpeedSteps(new PowerProfile(mContext).getNumSpeedSteps());
mStats.setRadioScanningTimeout(mContext.getResources().getInteger(
com.android.internal.R.integer.config_radioScanningTimeout)
* 1000L);
|
void | removeIsolatedUid(int isolatedUid, int appUid)
synchronized (mStats) {
mStats.removeIsolatedUidLocked(isolatedUid, appUid);
}
|
public void | setBatteryState(int status, int health, int plugType, int level, int temp, int volt)
enforceCallingPermission();
mStats.setBatteryState(status, health, plugType, level, temp, volt);
|
public void | shutdown()
Slog.w("BatteryStats", "Writing battery stats before shutdown...");
synchronized (mStats) {
mStats.shutdownLocked();
}
|