blob: d19c7f6c762051c2fc96e3577613dda3f3943b3a [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006-2007 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
17package com.android.server.am;
18
Jaikumar Ganesh3f034962010-09-27 17:02:23 -070019import android.bluetooth.BluetoothAdapter;
Amith Yamasani14fb81a2009-11-05 11:41:58 -080020import android.bluetooth.BluetoothHeadset;
Jaikumar Ganesh3f034962010-09-27 17:02:23 -070021import android.bluetooth.BluetoothProfile;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
Dianne Hackborne4a59512010-12-07 11:08:07 -080023import android.content.pm.ApplicationInfo;
Kenny Root3abd75b2011-09-29 11:00:41 -070024import android.content.pm.PackageManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.os.Binder;
26import android.os.IBinder;
27import android.os.Parcel;
28import android.os.Process;
29import android.os.ServiceManager;
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -070030import android.os.WorkSource;
Wink Savillee9b06d72009-05-18 21:47:50 -070031import android.telephony.SignalStrength;
Dianne Hackborne4a59512010-12-07 11:08:07 -080032import android.telephony.TelephonyManager;
Joe Onorato8a9b2202010-02-26 18:56:32 -080033import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034
Amith Yamasani32dbefd2009-06-19 09:21:17 -070035import com.android.internal.app.IBatteryStats;
36import com.android.internal.os.BatteryStatsImpl;
Amith Yamasanie43530a2009-08-21 13:11:37 -070037import com.android.internal.os.PowerProfile;
Amith Yamasani32dbefd2009-06-19 09:21:17 -070038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import java.io.FileDescriptor;
40import java.io.PrintWriter;
Dianne Hackborne4a59512010-12-07 11:08:07 -080041import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
43/**
44 * All information we are collecting about things that can happen that impact
45 * battery life.
46 */
47public final class BatteryStatsService extends IBatteryStats.Stub {
48 static IBatteryStats sService;
49
50 final BatteryStatsImpl mStats;
51 Context mContext;
Jaikumar Ganesh3f034962010-09-27 17:02:23 -070052 private boolean mBluetoothPendingStats;
53 private BluetoothHeadset mBluetoothHeadset;
Amith Yamasani3f7e35c2009-07-13 16:02:45 -070054
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 BatteryStatsService(String filename) {
56 mStats = new BatteryStatsImpl(filename);
57 }
58
59 public void publish(Context context) {
60 mContext = context;
61 ServiceManager.addService("batteryinfo", asBinder());
Amith Yamasanie43530a2009-08-21 13:11:37 -070062 mStats.setNumSpeedSteps(new PowerProfile(mContext).getNumSpeedSteps());
Amith Yamasanif37447b2009-10-08 18:28:01 -070063 mStats.setRadioScanningTimeout(mContext.getResources().getInteger(
64 com.android.internal.R.integer.config_radioScanningTimeout)
65 * 1000L);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 }
67
Dianne Hackborn55280a92009-05-07 15:53:46 -070068 public void shutdown() {
Joe Onorato8a9b2202010-02-26 18:56:32 -080069 Slog.w("BatteryStats", "Writing battery stats before shutdown...");
Dianne Hackborn55280a92009-05-07 15:53:46 -070070 synchronized (mStats) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -070071 mStats.shutdownLocked();
Dianne Hackborn55280a92009-05-07 15:53:46 -070072 }
73 }
74
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 public static IBatteryStats getService() {
76 if (sService != null) {
77 return sService;
78 }
79 IBinder b = ServiceManager.getService("batteryinfo");
80 sService = asInterface(b);
81 return sService;
82 }
83
84 /**
85 * @return the current statistics object, which may be modified
86 * to reflect events that affect battery usage. You must lock the
87 * stats object before doing anything with it.
88 */
89 public BatteryStatsImpl getActiveStatistics() {
90 return mStats;
91 }
92
93 public byte[] getStatistics() {
94 mContext.enforceCallingPermission(
95 android.Manifest.permission.BATTERY_STATS, null);
Joe Onorato8a9b2202010-02-26 18:56:32 -080096 //Slog.i("foo", "SENDING BATTERY INFO:");
97 //mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 Parcel out = Parcel.obtain();
99 mStats.writeToParcel(out, 0);
100 byte[] data = out.marshall();
101 out.recycle();
102 return data;
103 }
104
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700105 public void noteStartWakelock(int uid, int pid, String name, int type) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 enforceCallingPermission();
107 synchronized (mStats) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700108 mStats.noteStartWakeLocked(uid, pid, name, type);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 }
110 }
111
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700112 public void noteStopWakelock(int uid, int pid, String name, int type) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 enforceCallingPermission();
114 synchronized (mStats) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700115 mStats.noteStopWakeLocked(uid, pid, name, type);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 }
117 }
118
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700119 public void noteStartWakelockFromSource(WorkSource ws, int pid, String name, int type) {
120 enforceCallingPermission();
121 synchronized (mStats) {
122 mStats.noteStartWakeFromSourceLocked(ws, pid, name, type);
123 }
124 }
125
126 public void noteStopWakelockFromSource(WorkSource ws, int pid, String name, int type) {
127 enforceCallingPermission();
128 synchronized (mStats) {
129 mStats.noteStopWakeFromSourceLocked(ws, pid, name, type);
130 }
131 }
132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 public void noteStartSensor(int uid, int sensor) {
134 enforceCallingPermission();
135 synchronized (mStats) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700136 mStats.noteStartSensorLocked(uid, sensor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 }
138 }
139
140 public void noteStopSensor(int uid, int sensor) {
141 enforceCallingPermission();
142 synchronized (mStats) {
Dianne Hackborn9adb9c32010-08-13 14:09:56 -0700143 mStats.noteStopSensorLocked(uid, sensor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 }
145 }
146
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800147 public void noteVibratorOn(int uid, long durationMillis) {
148 enforceCallingPermission();
149 synchronized (mStats) {
150 mStats.noteVibratorOnLocked(uid, durationMillis);
151 }
152 }
153
154 public void noteVibratorOff(int uid) {
155 enforceCallingPermission();
156 synchronized (mStats) {
157 mStats.noteVibratorOffLocked(uid);
158 }
159 }
160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 public void noteStartGps(int uid) {
162 enforceCallingPermission();
163 synchronized (mStats) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700164 mStats.noteStartGpsLocked(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 }
166 }
167
168 public void noteStopGps(int uid) {
169 enforceCallingPermission();
170 synchronized (mStats) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700171 mStats.noteStopGpsLocked(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 }
173 }
174
175 public void noteScreenOn() {
176 enforceCallingPermission();
177 synchronized (mStats) {
178 mStats.noteScreenOnLocked();
179 }
180 }
181
Dianne Hackborn617f8772009-03-31 15:04:46 -0700182 public void noteScreenBrightness(int brightness) {
183 enforceCallingPermission();
184 synchronized (mStats) {
185 mStats.noteScreenBrightnessLocked(brightness);
186 }
187 }
188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 public void noteScreenOff() {
190 enforceCallingPermission();
191 synchronized (mStats) {
192 mStats.noteScreenOffLocked();
193 }
194 }
195
Dianne Hackborn617f8772009-03-31 15:04:46 -0700196 public void noteInputEvent() {
197 enforceCallingPermission();
Christopher Tate4cee7252010-03-19 14:50:40 -0700198 mStats.noteInputEventAtomic();
Dianne Hackborn617f8772009-03-31 15:04:46 -0700199 }
200
201 public void noteUserActivity(int uid, int event) {
202 enforceCallingPermission();
203 synchronized (mStats) {
204 mStats.noteUserActivityLocked(uid, event);
205 }
206 }
207
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 public void notePhoneOn() {
209 enforceCallingPermission();
210 synchronized (mStats) {
211 mStats.notePhoneOnLocked();
212 }
213 }
214
215 public void notePhoneOff() {
216 enforceCallingPermission();
217 synchronized (mStats) {
218 mStats.notePhoneOffLocked();
219 }
220 }
The Android Open Source Project10592532009-03-18 17:39:46 -0700221
Wink Savillee9b06d72009-05-18 21:47:50 -0700222 public void notePhoneSignalStrength(SignalStrength signalStrength) {
Dianne Hackborn627bba72009-03-24 22:32:56 -0700223 enforceCallingPermission();
224 synchronized (mStats) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700225 mStats.notePhoneSignalStrengthLocked(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -0700226 }
227 }
228
229 public void notePhoneDataConnectionState(int dataType, boolean hasData) {
230 enforceCallingPermission();
231 synchronized (mStats) {
232 mStats.notePhoneDataConnectionStateLocked(dataType, hasData);
233 }
234 }
Amith Yamasani32dbefd2009-06-19 09:21:17 -0700235
Amith Yamasanif37447b2009-10-08 18:28:01 -0700236 public void notePhoneState(int state) {
Amith Yamasani32dbefd2009-06-19 09:21:17 -0700237 enforceCallingPermission();
Dianne Hackborne4a59512010-12-07 11:08:07 -0800238 int simState = TelephonyManager.getDefault().getSimState();
Amith Yamasani32dbefd2009-06-19 09:21:17 -0700239 synchronized (mStats) {
Dianne Hackborne4a59512010-12-07 11:08:07 -0800240 mStats.notePhoneStateLocked(state, simState);
Amith Yamasani32dbefd2009-06-19 09:21:17 -0700241 }
242 }
243
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700244 public void noteWifiOn() {
The Android Open Source Project10592532009-03-18 17:39:46 -0700245 enforceCallingPermission();
246 synchronized (mStats) {
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700247 mStats.noteWifiOnLocked();
The Android Open Source Project10592532009-03-18 17:39:46 -0700248 }
249 }
250
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700251 public void noteWifiOff() {
The Android Open Source Project10592532009-03-18 17:39:46 -0700252 enforceCallingPermission();
253 synchronized (mStats) {
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700254 mStats.noteWifiOffLocked();
The Android Open Source Project10592532009-03-18 17:39:46 -0700255 }
256 }
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700257
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700258 public void noteStartAudio(int uid) {
259 enforceCallingPermission();
260 synchronized (mStats) {
261 mStats.noteAudioOnLocked(uid);
262 }
263 }
264
265 public void noteStopAudio(int uid) {
266 enforceCallingPermission();
267 synchronized (mStats) {
268 mStats.noteAudioOffLocked(uid);
269 }
270 }
271
272 public void noteStartVideo(int uid) {
273 enforceCallingPermission();
274 synchronized (mStats) {
275 mStats.noteVideoOnLocked(uid);
276 }
277 }
278
279 public void noteStopVideo(int uid) {
280 enforceCallingPermission();
281 synchronized (mStats) {
282 mStats.noteVideoOffLocked(uid);
283 }
284 }
285
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700286 public void noteWifiRunning(WorkSource ws) {
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700287 enforceCallingPermission();
288 synchronized (mStats) {
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700289 mStats.noteWifiRunningLocked(ws);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700290 }
291 }
292
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700293 public void noteWifiRunningChanged(WorkSource oldWs, WorkSource newWs) {
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700294 enforceCallingPermission();
295 synchronized (mStats) {
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700296 mStats.noteWifiRunningChangedLocked(oldWs, newWs);
297 }
298 }
299
300 public void noteWifiStopped(WorkSource ws) {
301 enforceCallingPermission();
302 synchronized (mStats) {
303 mStats.noteWifiStoppedLocked(ws);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700304 }
305 }
306
The Android Open Source Project10592532009-03-18 17:39:46 -0700307 public void noteBluetoothOn() {
308 enforceCallingPermission();
Jaikumar Ganesh3f034962010-09-27 17:02:23 -0700309 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
310 if (adapter != null) {
311 adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener,
312 BluetoothProfile.HEADSET);
313 }
The Android Open Source Project10592532009-03-18 17:39:46 -0700314 synchronized (mStats) {
Jaikumar Ganesh3f034962010-09-27 17:02:23 -0700315 if (mBluetoothHeadset != null) {
316 mStats.noteBluetoothOnLocked();
317 mStats.setBtHeadset(mBluetoothHeadset);
318 } else {
319 mBluetoothPendingStats = true;
320 }
The Android Open Source Project10592532009-03-18 17:39:46 -0700321 }
322 }
Jaikumar Ganesh3f034962010-09-27 17:02:23 -0700323
324 private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
325 new BluetoothProfile.ServiceListener() {
326 public void onServiceConnected(int profile, BluetoothProfile proxy) {
327 mBluetoothHeadset = (BluetoothHeadset) proxy;
328 synchronized (mStats) {
329 if (mBluetoothPendingStats) {
330 mStats.noteBluetoothOnLocked();
331 mStats.setBtHeadset(mBluetoothHeadset);
332 mBluetoothPendingStats = false;
333 }
334 }
335 }
336
337 public void onServiceDisconnected(int profile) {
338 mBluetoothHeadset = null;
339 }
340 };
341
The Android Open Source Project10592532009-03-18 17:39:46 -0700342 public void noteBluetoothOff() {
343 enforceCallingPermission();
344 synchronized (mStats) {
Jaikumar Ganesh3f034962010-09-27 17:02:23 -0700345 mBluetoothPendingStats = false;
The Android Open Source Project10592532009-03-18 17:39:46 -0700346 mStats.noteBluetoothOffLocked();
347 }
348 }
349
350 public void noteFullWifiLockAcquired(int uid) {
351 enforceCallingPermission();
352 synchronized (mStats) {
353 mStats.noteFullWifiLockAcquiredLocked(uid);
354 }
355 }
356
357 public void noteFullWifiLockReleased(int uid) {
358 enforceCallingPermission();
359 synchronized (mStats) {
360 mStats.noteFullWifiLockReleasedLocked(uid);
361 }
362 }
Nick Pelly6ccaa542012-06-15 15:22:47 -0700363
364 public void noteWifiScanStarted(int uid) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700365 enforceCallingPermission();
366 synchronized (mStats) {
Nick Pelly6ccaa542012-06-15 15:22:47 -0700367 mStats.noteWifiScanStartedLocked(uid);
The Android Open Source Project10592532009-03-18 17:39:46 -0700368 }
369 }
Nick Pelly6ccaa542012-06-15 15:22:47 -0700370
371 public void noteWifiScanStopped(int uid) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700372 enforceCallingPermission();
373 synchronized (mStats) {
Nick Pelly6ccaa542012-06-15 15:22:47 -0700374 mStats.noteWifiScanStoppedLocked(uid);
The Android Open Source Project10592532009-03-18 17:39:46 -0700375 }
376 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800377
Robert Greenwalt5347bd42009-05-13 15:10:16 -0700378 public void noteWifiMulticastEnabled(int uid) {
379 enforceCallingPermission();
380 synchronized (mStats) {
381 mStats.noteWifiMulticastEnabledLocked(uid);
382 }
383 }
384
385 public void noteWifiMulticastDisabled(int uid) {
386 enforceCallingPermission();
387 synchronized (mStats) {
388 mStats.noteWifiMulticastDisabledLocked(uid);
389 }
390 }
391
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700392 public void noteFullWifiLockAcquiredFromSource(WorkSource ws) {
393 enforceCallingPermission();
394 synchronized (mStats) {
395 mStats.noteFullWifiLockAcquiredFromSourceLocked(ws);
396 }
397 }
398
399 public void noteFullWifiLockReleasedFromSource(WorkSource ws) {
400 enforceCallingPermission();
401 synchronized (mStats) {
402 mStats.noteFullWifiLockReleasedFromSourceLocked(ws);
403 }
404 }
405
Nick Pelly6ccaa542012-06-15 15:22:47 -0700406 public void noteWifiScanStartedFromSource(WorkSource ws) {
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700407 enforceCallingPermission();
408 synchronized (mStats) {
Nick Pelly6ccaa542012-06-15 15:22:47 -0700409 mStats.noteWifiScanStartedFromSourceLocked(ws);
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700410 }
411 }
412
Nick Pelly6ccaa542012-06-15 15:22:47 -0700413 public void noteWifiScanStoppedFromSource(WorkSource ws) {
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700414 enforceCallingPermission();
415 synchronized (mStats) {
Nick Pelly6ccaa542012-06-15 15:22:47 -0700416 mStats.noteWifiScanStoppedFromSourceLocked(ws);
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700417 }
418 }
419
420 public void noteWifiMulticastEnabledFromSource(WorkSource ws) {
421 enforceCallingPermission();
422 synchronized (mStats) {
423 mStats.noteWifiMulticastEnabledFromSourceLocked(ws);
424 }
425 }
426
427 public void noteWifiMulticastDisabledFromSource(WorkSource ws) {
428 enforceCallingPermission();
429 synchronized (mStats) {
430 mStats.noteWifiMulticastDisabledFromSourceLocked(ws);
431 }
432 }
433
Jeff Sharkey1059c3c2011-10-04 16:54:49 -0700434 public void noteNetworkInterfaceType(String iface, int type) {
435 enforceCallingPermission();
436 synchronized (mStats) {
437 mStats.noteNetworkInterfaceTypeLocked(iface, type);
438 }
439 }
440
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 public boolean isOnBattery() {
442 return mStats.isOnBattery();
443 }
444
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700445 public void setBatteryState(int status, int health, int plugType, int level,
446 int temp, int volt) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 enforceCallingPermission();
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700448 mStats.setBatteryState(status, health, plugType, level, temp, volt);
Evan Millar633a1742009-04-02 16:36:33 -0700449 }
450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 public long getAwakeTimeBattery() {
452 mContext.enforceCallingOrSelfPermission(
453 android.Manifest.permission.BATTERY_STATS, null);
454 return mStats.getAwakeTimeBattery();
455 }
456
457 public long getAwakeTimePlugged() {
458 mContext.enforceCallingOrSelfPermission(
459 android.Manifest.permission.BATTERY_STATS, null);
460 return mStats.getAwakeTimePlugged();
461 }
462
463 public void enforceCallingPermission() {
464 if (Binder.getCallingPid() == Process.myPid()) {
465 return;
466 }
467 mContext.enforcePermission(android.Manifest.permission.UPDATE_DEVICE_STATS,
468 Binder.getCallingPid(), Binder.getCallingUid(), null);
469 }
470
Dianne Hackbornae384452011-06-28 12:33:48 -0700471 private void dumpHelp(PrintWriter pw) {
472 pw.println("Battery stats (batteryinfo) dump options:");
473 pw.println(" [--checkin] [--reset] [--write] [-h]");
474 pw.println(" --checkin: format output for a checkin report.");
475 pw.println(" --reset: reset the stats, clearing all current data.");
476 pw.println(" --write: force write current collected stats to disk.");
477 pw.println(" -h: print this help text.");
478 }
479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 @Override
481 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Kenny Root3abd75b2011-09-29 11:00:41 -0700482 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
483 != PackageManager.PERMISSION_GRANTED) {
484 pw.println("Permission Denial: can't dump BatteryStats from from pid="
485 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
486 + " without permission " + android.Manifest.permission.DUMP);
487 return;
488 }
489
Dianne Hackborne4a59512010-12-07 11:08:07 -0800490 boolean isCheckin = false;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700491 boolean noOutput = false;
Dianne Hackborne4a59512010-12-07 11:08:07 -0800492 if (args != null) {
493 for (String arg : args) {
494 if ("--checkin".equals(arg)) {
495 isCheckin = true;
496 } else if ("--reset".equals(arg)) {
497 synchronized (mStats) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700498 mStats.resetAllStatsLocked();
Dianne Hackborne4a59512010-12-07 11:08:07 -0800499 pw.println("Battery stats reset.");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700500 noOutput = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700502 } else if ("--write".equals(arg)) {
503 synchronized (mStats) {
504 mStats.writeSyncLocked();
505 pw.println("Battery stats written.");
506 noOutput = true;
507 }
Dianne Hackbornae384452011-06-28 12:33:48 -0700508 } else if ("-h".equals(arg)) {
509 dumpHelp(pw);
510 return;
Mike Lockwoode8174042011-08-16 12:53:43 -0700511 } else if ("-a".equals(arg)) {
512 // fall through
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700513 } else {
514 pw.println("Unknown option: " + arg);
Dianne Hackbornae384452011-06-28 12:33:48 -0700515 dumpHelp(pw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 }
517 }
Dianne Hackborne4a59512010-12-07 11:08:07 -0800518 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700519 if (noOutput) {
520 return;
521 }
Dianne Hackborne4a59512010-12-07 11:08:07 -0800522 if (isCheckin) {
523 List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0);
524 synchronized (mStats) {
525 mStats.dumpCheckinLocked(pw, args, apps);
526 }
527 } else {
528 synchronized (mStats) {
529 mStats.dumpLocked(pw);
530 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 }
532 }
533}