blob: ab20208403d62f897a5bc9982d2872d4504191e9 [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
147 public void noteStartGps(int uid) {
148 enforceCallingPermission();
149 synchronized (mStats) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700150 mStats.noteStartGpsLocked(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 }
152 }
153
154 public void noteStopGps(int uid) {
155 enforceCallingPermission();
156 synchronized (mStats) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700157 mStats.noteStopGpsLocked(uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 }
159 }
160
161 public void noteScreenOn() {
162 enforceCallingPermission();
163 synchronized (mStats) {
164 mStats.noteScreenOnLocked();
165 }
166 }
167
Dianne Hackborn617f8772009-03-31 15:04:46 -0700168 public void noteScreenBrightness(int brightness) {
169 enforceCallingPermission();
170 synchronized (mStats) {
171 mStats.noteScreenBrightnessLocked(brightness);
172 }
173 }
174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 public void noteScreenOff() {
176 enforceCallingPermission();
177 synchronized (mStats) {
178 mStats.noteScreenOffLocked();
179 }
180 }
181
Dianne Hackborn617f8772009-03-31 15:04:46 -0700182 public void noteInputEvent() {
183 enforceCallingPermission();
Christopher Tate4cee7252010-03-19 14:50:40 -0700184 mStats.noteInputEventAtomic();
Dianne Hackborn617f8772009-03-31 15:04:46 -0700185 }
186
187 public void noteUserActivity(int uid, int event) {
188 enforceCallingPermission();
189 synchronized (mStats) {
190 mStats.noteUserActivityLocked(uid, event);
191 }
192 }
193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 public void notePhoneOn() {
195 enforceCallingPermission();
196 synchronized (mStats) {
197 mStats.notePhoneOnLocked();
198 }
199 }
200
201 public void notePhoneOff() {
202 enforceCallingPermission();
203 synchronized (mStats) {
204 mStats.notePhoneOffLocked();
205 }
206 }
The Android Open Source Project10592532009-03-18 17:39:46 -0700207
Wink Savillee9b06d72009-05-18 21:47:50 -0700208 public void notePhoneSignalStrength(SignalStrength signalStrength) {
Dianne Hackborn627bba72009-03-24 22:32:56 -0700209 enforceCallingPermission();
210 synchronized (mStats) {
Wink Savillee9b06d72009-05-18 21:47:50 -0700211 mStats.notePhoneSignalStrengthLocked(signalStrength);
Dianne Hackborn627bba72009-03-24 22:32:56 -0700212 }
213 }
214
215 public void notePhoneDataConnectionState(int dataType, boolean hasData) {
216 enforceCallingPermission();
217 synchronized (mStats) {
218 mStats.notePhoneDataConnectionStateLocked(dataType, hasData);
219 }
220 }
Amith Yamasani32dbefd2009-06-19 09:21:17 -0700221
Amith Yamasanif37447b2009-10-08 18:28:01 -0700222 public void notePhoneState(int state) {
Amith Yamasani32dbefd2009-06-19 09:21:17 -0700223 enforceCallingPermission();
Dianne Hackborne4a59512010-12-07 11:08:07 -0800224 int simState = TelephonyManager.getDefault().getSimState();
Amith Yamasani32dbefd2009-06-19 09:21:17 -0700225 synchronized (mStats) {
Dianne Hackborne4a59512010-12-07 11:08:07 -0800226 mStats.notePhoneStateLocked(state, simState);
Amith Yamasani32dbefd2009-06-19 09:21:17 -0700227 }
228 }
229
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700230 public void noteWifiOn() {
The Android Open Source Project10592532009-03-18 17:39:46 -0700231 enforceCallingPermission();
232 synchronized (mStats) {
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700233 mStats.noteWifiOnLocked();
The Android Open Source Project10592532009-03-18 17:39:46 -0700234 }
235 }
236
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700237 public void noteWifiOff() {
The Android Open Source Project10592532009-03-18 17:39:46 -0700238 enforceCallingPermission();
239 synchronized (mStats) {
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700240 mStats.noteWifiOffLocked();
The Android Open Source Project10592532009-03-18 17:39:46 -0700241 }
242 }
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700243
Amith Yamasani244fa5c2009-05-22 14:36:07 -0700244 public void noteStartAudio(int uid) {
245 enforceCallingPermission();
246 synchronized (mStats) {
247 mStats.noteAudioOnLocked(uid);
248 }
249 }
250
251 public void noteStopAudio(int uid) {
252 enforceCallingPermission();
253 synchronized (mStats) {
254 mStats.noteAudioOffLocked(uid);
255 }
256 }
257
258 public void noteStartVideo(int uid) {
259 enforceCallingPermission();
260 synchronized (mStats) {
261 mStats.noteVideoOnLocked(uid);
262 }
263 }
264
265 public void noteStopVideo(int uid) {
266 enforceCallingPermission();
267 synchronized (mStats) {
268 mStats.noteVideoOffLocked(uid);
269 }
270 }
271
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700272 public void noteWifiRunning(WorkSource ws) {
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700273 enforceCallingPermission();
274 synchronized (mStats) {
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700275 mStats.noteWifiRunningLocked(ws);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700276 }
277 }
278
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700279 public void noteWifiRunningChanged(WorkSource oldWs, WorkSource newWs) {
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700280 enforceCallingPermission();
281 synchronized (mStats) {
Dianne Hackborn58e0eef2010-09-16 01:22:10 -0700282 mStats.noteWifiRunningChangedLocked(oldWs, newWs);
283 }
284 }
285
286 public void noteWifiStopped(WorkSource ws) {
287 enforceCallingPermission();
288 synchronized (mStats) {
289 mStats.noteWifiStoppedLocked(ws);
Eric Shienbroodd4c5f892009-03-24 18:13:20 -0700290 }
291 }
292
The Android Open Source Project10592532009-03-18 17:39:46 -0700293 public void noteBluetoothOn() {
294 enforceCallingPermission();
Jaikumar Ganesh3f034962010-09-27 17:02:23 -0700295 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
296 if (adapter != null) {
297 adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener,
298 BluetoothProfile.HEADSET);
299 }
The Android Open Source Project10592532009-03-18 17:39:46 -0700300 synchronized (mStats) {
Jaikumar Ganesh3f034962010-09-27 17:02:23 -0700301 if (mBluetoothHeadset != null) {
302 mStats.noteBluetoothOnLocked();
303 mStats.setBtHeadset(mBluetoothHeadset);
304 } else {
305 mBluetoothPendingStats = true;
306 }
The Android Open Source Project10592532009-03-18 17:39:46 -0700307 }
308 }
Jaikumar Ganesh3f034962010-09-27 17:02:23 -0700309
310 private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
311 new BluetoothProfile.ServiceListener() {
312 public void onServiceConnected(int profile, BluetoothProfile proxy) {
313 mBluetoothHeadset = (BluetoothHeadset) proxy;
314 synchronized (mStats) {
315 if (mBluetoothPendingStats) {
316 mStats.noteBluetoothOnLocked();
317 mStats.setBtHeadset(mBluetoothHeadset);
318 mBluetoothPendingStats = false;
319 }
320 }
321 }
322
323 public void onServiceDisconnected(int profile) {
324 mBluetoothHeadset = null;
325 }
326 };
327
The Android Open Source Project10592532009-03-18 17:39:46 -0700328 public void noteBluetoothOff() {
329 enforceCallingPermission();
330 synchronized (mStats) {
Jaikumar Ganesh3f034962010-09-27 17:02:23 -0700331 mBluetoothPendingStats = false;
The Android Open Source Project10592532009-03-18 17:39:46 -0700332 mStats.noteBluetoothOffLocked();
333 }
334 }
335
336 public void noteFullWifiLockAcquired(int uid) {
337 enforceCallingPermission();
338 synchronized (mStats) {
339 mStats.noteFullWifiLockAcquiredLocked(uid);
340 }
341 }
342
343 public void noteFullWifiLockReleased(int uid) {
344 enforceCallingPermission();
345 synchronized (mStats) {
346 mStats.noteFullWifiLockReleasedLocked(uid);
347 }
348 }
Nick Pelly6ccaa542012-06-15 15:22:47 -0700349
350 public void noteWifiScanStarted(int uid) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700351 enforceCallingPermission();
352 synchronized (mStats) {
Nick Pelly6ccaa542012-06-15 15:22:47 -0700353 mStats.noteWifiScanStartedLocked(uid);
The Android Open Source Project10592532009-03-18 17:39:46 -0700354 }
355 }
Nick Pelly6ccaa542012-06-15 15:22:47 -0700356
357 public void noteWifiScanStopped(int uid) {
The Android Open Source Project10592532009-03-18 17:39:46 -0700358 enforceCallingPermission();
359 synchronized (mStats) {
Nick Pelly6ccaa542012-06-15 15:22:47 -0700360 mStats.noteWifiScanStoppedLocked(uid);
The Android Open Source Project10592532009-03-18 17:39:46 -0700361 }
362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363
Robert Greenwalt5347bd42009-05-13 15:10:16 -0700364 public void noteWifiMulticastEnabled(int uid) {
365 enforceCallingPermission();
366 synchronized (mStats) {
367 mStats.noteWifiMulticastEnabledLocked(uid);
368 }
369 }
370
371 public void noteWifiMulticastDisabled(int uid) {
372 enforceCallingPermission();
373 synchronized (mStats) {
374 mStats.noteWifiMulticastDisabledLocked(uid);
375 }
376 }
377
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700378 public void noteFullWifiLockAcquiredFromSource(WorkSource ws) {
379 enforceCallingPermission();
380 synchronized (mStats) {
381 mStats.noteFullWifiLockAcquiredFromSourceLocked(ws);
382 }
383 }
384
385 public void noteFullWifiLockReleasedFromSource(WorkSource ws) {
386 enforceCallingPermission();
387 synchronized (mStats) {
388 mStats.noteFullWifiLockReleasedFromSourceLocked(ws);
389 }
390 }
391
Nick Pelly6ccaa542012-06-15 15:22:47 -0700392 public void noteWifiScanStartedFromSource(WorkSource ws) {
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700393 enforceCallingPermission();
394 synchronized (mStats) {
Nick Pelly6ccaa542012-06-15 15:22:47 -0700395 mStats.noteWifiScanStartedFromSourceLocked(ws);
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700396 }
397 }
398
Nick Pelly6ccaa542012-06-15 15:22:47 -0700399 public void noteWifiScanStoppedFromSource(WorkSource ws) {
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700400 enforceCallingPermission();
401 synchronized (mStats) {
Nick Pelly6ccaa542012-06-15 15:22:47 -0700402 mStats.noteWifiScanStoppedFromSourceLocked(ws);
Dianne Hackborn7e9f4eb2010-09-10 18:43:00 -0700403 }
404 }
405
406 public void noteWifiMulticastEnabledFromSource(WorkSource ws) {
407 enforceCallingPermission();
408 synchronized (mStats) {
409 mStats.noteWifiMulticastEnabledFromSourceLocked(ws);
410 }
411 }
412
413 public void noteWifiMulticastDisabledFromSource(WorkSource ws) {
414 enforceCallingPermission();
415 synchronized (mStats) {
416 mStats.noteWifiMulticastDisabledFromSourceLocked(ws);
417 }
418 }
419
Jeff Sharkey1059c3c2011-10-04 16:54:49 -0700420 public void noteNetworkInterfaceType(String iface, int type) {
421 enforceCallingPermission();
422 synchronized (mStats) {
423 mStats.noteNetworkInterfaceTypeLocked(iface, type);
424 }
425 }
426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 public boolean isOnBattery() {
428 return mStats.isOnBattery();
429 }
430
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700431 public void setBatteryState(int status, int health, int plugType, int level,
432 int temp, int volt) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 enforceCallingPermission();
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700434 mStats.setBatteryState(status, health, plugType, level, temp, volt);
Evan Millar633a1742009-04-02 16:36:33 -0700435 }
436
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800437 public long getAwakeTimeBattery() {
438 mContext.enforceCallingOrSelfPermission(
439 android.Manifest.permission.BATTERY_STATS, null);
440 return mStats.getAwakeTimeBattery();
441 }
442
443 public long getAwakeTimePlugged() {
444 mContext.enforceCallingOrSelfPermission(
445 android.Manifest.permission.BATTERY_STATS, null);
446 return mStats.getAwakeTimePlugged();
447 }
448
449 public void enforceCallingPermission() {
450 if (Binder.getCallingPid() == Process.myPid()) {
451 return;
452 }
453 mContext.enforcePermission(android.Manifest.permission.UPDATE_DEVICE_STATS,
454 Binder.getCallingPid(), Binder.getCallingUid(), null);
455 }
456
Dianne Hackbornae384452011-06-28 12:33:48 -0700457 private void dumpHelp(PrintWriter pw) {
458 pw.println("Battery stats (batteryinfo) dump options:");
459 pw.println(" [--checkin] [--reset] [--write] [-h]");
460 pw.println(" --checkin: format output for a checkin report.");
461 pw.println(" --reset: reset the stats, clearing all current data.");
462 pw.println(" --write: force write current collected stats to disk.");
463 pw.println(" -h: print this help text.");
464 }
465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 @Override
467 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
Kenny Root3abd75b2011-09-29 11:00:41 -0700468 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
469 != PackageManager.PERMISSION_GRANTED) {
470 pw.println("Permission Denial: can't dump BatteryStats from from pid="
471 + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
472 + " without permission " + android.Manifest.permission.DUMP);
473 return;
474 }
475
Dianne Hackborne4a59512010-12-07 11:08:07 -0800476 boolean isCheckin = false;
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700477 boolean noOutput = false;
Dianne Hackborne4a59512010-12-07 11:08:07 -0800478 if (args != null) {
479 for (String arg : args) {
480 if ("--checkin".equals(arg)) {
481 isCheckin = true;
482 } else if ("--reset".equals(arg)) {
483 synchronized (mStats) {
Dianne Hackborn6b7b4842010-06-14 17:17:44 -0700484 mStats.resetAllStatsLocked();
Dianne Hackborne4a59512010-12-07 11:08:07 -0800485 pw.println("Battery stats reset.");
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700486 noOutput = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700488 } else if ("--write".equals(arg)) {
489 synchronized (mStats) {
490 mStats.writeSyncLocked();
491 pw.println("Battery stats written.");
492 noOutput = true;
493 }
Dianne Hackbornae384452011-06-28 12:33:48 -0700494 } else if ("-h".equals(arg)) {
495 dumpHelp(pw);
496 return;
Mike Lockwoode8174042011-08-16 12:53:43 -0700497 } else if ("-a".equals(arg)) {
498 // fall through
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700499 } else {
500 pw.println("Unknown option: " + arg);
Dianne Hackbornae384452011-06-28 12:33:48 -0700501 dumpHelp(pw);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 }
503 }
Dianne Hackborne4a59512010-12-07 11:08:07 -0800504 }
Dianne Hackborn0ffc9882011-04-13 18:15:56 -0700505 if (noOutput) {
506 return;
507 }
Dianne Hackborne4a59512010-12-07 11:08:07 -0800508 if (isCheckin) {
509 List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0);
510 synchronized (mStats) {
511 mStats.dumpCheckinLocked(pw, args, apps);
512 }
513 } else {
514 synchronized (mStats) {
515 mStats.dumpLocked(pw);
516 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 }
518 }
519}