The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.am; |
| 18 | |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 19 | import android.bluetooth.BluetoothAdapter; |
Amith Yamasani | 14fb81a | 2009-11-05 11:41:58 -0800 | [diff] [blame] | 20 | import android.bluetooth.BluetoothHeadset; |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 21 | import android.bluetooth.BluetoothProfile; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.Context; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 23 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.os.Binder; |
| 25 | import android.os.IBinder; |
| 26 | import android.os.Parcel; |
| 27 | import android.os.Process; |
| 28 | import android.os.ServiceManager; |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 29 | import android.os.WorkSource; |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 30 | import android.telephony.SignalStrength; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 31 | import android.telephony.TelephonyManager; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 32 | import android.util.Slog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 34 | import com.android.internal.app.IBatteryStats; |
| 35 | import com.android.internal.os.BatteryStatsImpl; |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 36 | import com.android.internal.os.PowerProfile; |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 37 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import java.io.FileDescriptor; |
| 39 | import java.io.PrintWriter; |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 40 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * All information we are collecting about things that can happen that impact |
| 44 | * battery life. |
| 45 | */ |
| 46 | public final class BatteryStatsService extends IBatteryStats.Stub { |
| 47 | static IBatteryStats sService; |
| 48 | |
| 49 | final BatteryStatsImpl mStats; |
| 50 | Context mContext; |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 51 | private boolean mBluetoothPendingStats; |
| 52 | private BluetoothHeadset mBluetoothHeadset; |
Amith Yamasani | 3f7e35c | 2009-07-13 16:02:45 -0700 | [diff] [blame] | 53 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | BatteryStatsService(String filename) { |
| 55 | mStats = new BatteryStatsImpl(filename); |
| 56 | } |
| 57 | |
| 58 | public void publish(Context context) { |
| 59 | mContext = context; |
| 60 | ServiceManager.addService("batteryinfo", asBinder()); |
Amith Yamasani | e43530a | 2009-08-21 13:11:37 -0700 | [diff] [blame] | 61 | mStats.setNumSpeedSteps(new PowerProfile(mContext).getNumSpeedSteps()); |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 62 | mStats.setRadioScanningTimeout(mContext.getResources().getInteger( |
| 63 | com.android.internal.R.integer.config_radioScanningTimeout) |
| 64 | * 1000L); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 67 | public void shutdown() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 68 | Slog.w("BatteryStats", "Writing battery stats before shutdown..."); |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 69 | synchronized (mStats) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 70 | mStats.shutdownLocked(); |
Dianne Hackborn | 55280a9 | 2009-05-07 15:53:46 -0700 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | public static IBatteryStats getService() { |
| 75 | if (sService != null) { |
| 76 | return sService; |
| 77 | } |
| 78 | IBinder b = ServiceManager.getService("batteryinfo"); |
| 79 | sService = asInterface(b); |
| 80 | return sService; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @return the current statistics object, which may be modified |
| 85 | * to reflect events that affect battery usage. You must lock the |
| 86 | * stats object before doing anything with it. |
| 87 | */ |
| 88 | public BatteryStatsImpl getActiveStatistics() { |
| 89 | return mStats; |
| 90 | } |
| 91 | |
| 92 | public byte[] getStatistics() { |
| 93 | mContext.enforceCallingPermission( |
| 94 | android.Manifest.permission.BATTERY_STATS, null); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 95 | //Slog.i("foo", "SENDING BATTERY INFO:"); |
| 96 | //mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | Parcel out = Parcel.obtain(); |
| 98 | mStats.writeToParcel(out, 0); |
| 99 | byte[] data = out.marshall(); |
| 100 | out.recycle(); |
| 101 | return data; |
| 102 | } |
| 103 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 104 | public void noteStartWakelock(int uid, int pid, String name, int type) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | enforceCallingPermission(); |
| 106 | synchronized (mStats) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 107 | mStats.noteStartWakeLocked(uid, pid, name, type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 111 | public void noteStopWakelock(int uid, int pid, String name, int type) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | enforceCallingPermission(); |
| 113 | synchronized (mStats) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 114 | mStats.noteStopWakeLocked(uid, pid, name, type); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 118 | public void noteStartWakelockFromSource(WorkSource ws, int pid, String name, int type) { |
| 119 | enforceCallingPermission(); |
| 120 | synchronized (mStats) { |
| 121 | mStats.noteStartWakeFromSourceLocked(ws, pid, name, type); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | public void noteStopWakelockFromSource(WorkSource ws, int pid, String name, int type) { |
| 126 | enforceCallingPermission(); |
| 127 | synchronized (mStats) { |
| 128 | mStats.noteStopWakeFromSourceLocked(ws, pid, name, type); |
| 129 | } |
| 130 | } |
| 131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | public void noteStartSensor(int uid, int sensor) { |
| 133 | enforceCallingPermission(); |
| 134 | synchronized (mStats) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 135 | mStats.noteStartSensorLocked(uid, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | public void noteStopSensor(int uid, int sensor) { |
| 140 | enforceCallingPermission(); |
| 141 | synchronized (mStats) { |
Dianne Hackborn | 9adb9c3 | 2010-08-13 14:09:56 -0700 | [diff] [blame] | 142 | mStats.noteStopSensorLocked(uid, sensor); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
| 146 | public void noteStartGps(int uid) { |
| 147 | enforceCallingPermission(); |
| 148 | synchronized (mStats) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 149 | mStats.noteStartGpsLocked(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
| 153 | public void noteStopGps(int uid) { |
| 154 | enforceCallingPermission(); |
| 155 | synchronized (mStats) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 156 | mStats.noteStopGpsLocked(uid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
| 160 | public void noteScreenOn() { |
| 161 | enforceCallingPermission(); |
| 162 | synchronized (mStats) { |
| 163 | mStats.noteScreenOnLocked(); |
| 164 | } |
| 165 | } |
| 166 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 167 | public void noteScreenBrightness(int brightness) { |
| 168 | enforceCallingPermission(); |
| 169 | synchronized (mStats) { |
| 170 | mStats.noteScreenBrightnessLocked(brightness); |
| 171 | } |
| 172 | } |
| 173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | public void noteScreenOff() { |
| 175 | enforceCallingPermission(); |
| 176 | synchronized (mStats) { |
| 177 | mStats.noteScreenOffLocked(); |
| 178 | } |
| 179 | } |
| 180 | |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 181 | public void noteInputEvent() { |
| 182 | enforceCallingPermission(); |
Christopher Tate | 4cee725 | 2010-03-19 14:50:40 -0700 | [diff] [blame] | 183 | mStats.noteInputEventAtomic(); |
Dianne Hackborn | 617f877 | 2009-03-31 15:04:46 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | public void noteUserActivity(int uid, int event) { |
| 187 | enforceCallingPermission(); |
| 188 | synchronized (mStats) { |
| 189 | mStats.noteUserActivityLocked(uid, event); |
| 190 | } |
| 191 | } |
| 192 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | public void notePhoneOn() { |
| 194 | enforceCallingPermission(); |
| 195 | synchronized (mStats) { |
| 196 | mStats.notePhoneOnLocked(); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | public void notePhoneOff() { |
| 201 | enforceCallingPermission(); |
| 202 | synchronized (mStats) { |
| 203 | mStats.notePhoneOffLocked(); |
| 204 | } |
| 205 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 206 | |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 207 | public void notePhoneSignalStrength(SignalStrength signalStrength) { |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 208 | enforceCallingPermission(); |
| 209 | synchronized (mStats) { |
Wink Saville | e9b06d7 | 2009-05-18 21:47:50 -0700 | [diff] [blame] | 210 | mStats.notePhoneSignalStrengthLocked(signalStrength); |
Dianne Hackborn | 627bba7 | 2009-03-24 22:32:56 -0700 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
| 214 | public void notePhoneDataConnectionState(int dataType, boolean hasData) { |
| 215 | enforceCallingPermission(); |
| 216 | synchronized (mStats) { |
| 217 | mStats.notePhoneDataConnectionStateLocked(dataType, hasData); |
| 218 | } |
| 219 | } |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 220 | |
Amith Yamasani | f37447b | 2009-10-08 18:28:01 -0700 | [diff] [blame] | 221 | public void notePhoneState(int state) { |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 222 | enforceCallingPermission(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 223 | int simState = TelephonyManager.getDefault().getSimState(); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 224 | synchronized (mStats) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 225 | mStats.notePhoneStateLocked(state, simState); |
Amith Yamasani | 32dbefd | 2009-06-19 09:21:17 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 229 | public void noteWifiOn() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 230 | enforceCallingPermission(); |
| 231 | synchronized (mStats) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 232 | mStats.noteWifiOnLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 236 | public void noteWifiOff() { |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 237 | enforceCallingPermission(); |
| 238 | synchronized (mStats) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 239 | mStats.noteWifiOffLocked(); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 242 | |
Amith Yamasani | 244fa5c | 2009-05-22 14:36:07 -0700 | [diff] [blame] | 243 | public void noteStartAudio(int uid) { |
| 244 | enforceCallingPermission(); |
| 245 | synchronized (mStats) { |
| 246 | mStats.noteAudioOnLocked(uid); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | public void noteStopAudio(int uid) { |
| 251 | enforceCallingPermission(); |
| 252 | synchronized (mStats) { |
| 253 | mStats.noteAudioOffLocked(uid); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | public void noteStartVideo(int uid) { |
| 258 | enforceCallingPermission(); |
| 259 | synchronized (mStats) { |
| 260 | mStats.noteVideoOnLocked(uid); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | public void noteStopVideo(int uid) { |
| 265 | enforceCallingPermission(); |
| 266 | synchronized (mStats) { |
| 267 | mStats.noteVideoOffLocked(uid); |
| 268 | } |
| 269 | } |
| 270 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 271 | public void noteWifiRunning(WorkSource ws) { |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 272 | enforceCallingPermission(); |
| 273 | synchronized (mStats) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 274 | mStats.noteWifiRunningLocked(ws); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 278 | public void noteWifiRunningChanged(WorkSource oldWs, WorkSource newWs) { |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 279 | enforceCallingPermission(); |
| 280 | synchronized (mStats) { |
Dianne Hackborn | 58e0eef | 2010-09-16 01:22:10 -0700 | [diff] [blame] | 281 | mStats.noteWifiRunningChangedLocked(oldWs, newWs); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | public void noteWifiStopped(WorkSource ws) { |
| 286 | enforceCallingPermission(); |
| 287 | synchronized (mStats) { |
| 288 | mStats.noteWifiStoppedLocked(ws); |
Eric Shienbrood | d4c5f89 | 2009-03-24 18:13:20 -0700 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 292 | public void noteBluetoothOn() { |
| 293 | enforceCallingPermission(); |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 294 | BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
| 295 | if (adapter != null) { |
| 296 | adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener, |
| 297 | BluetoothProfile.HEADSET); |
| 298 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 299 | synchronized (mStats) { |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 300 | if (mBluetoothHeadset != null) { |
| 301 | mStats.noteBluetoothOnLocked(); |
| 302 | mStats.setBtHeadset(mBluetoothHeadset); |
| 303 | } else { |
| 304 | mBluetoothPendingStats = true; |
| 305 | } |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 306 | } |
| 307 | } |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 308 | |
| 309 | private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener = |
| 310 | new BluetoothProfile.ServiceListener() { |
| 311 | public void onServiceConnected(int profile, BluetoothProfile proxy) { |
| 312 | mBluetoothHeadset = (BluetoothHeadset) proxy; |
| 313 | synchronized (mStats) { |
| 314 | if (mBluetoothPendingStats) { |
| 315 | mStats.noteBluetoothOnLocked(); |
| 316 | mStats.setBtHeadset(mBluetoothHeadset); |
| 317 | mBluetoothPendingStats = false; |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | public void onServiceDisconnected(int profile) { |
| 323 | mBluetoothHeadset = null; |
| 324 | } |
| 325 | }; |
| 326 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 327 | public void noteBluetoothOff() { |
| 328 | enforceCallingPermission(); |
| 329 | synchronized (mStats) { |
Jaikumar Ganesh | 3f03496 | 2010-09-27 17:02:23 -0700 | [diff] [blame] | 330 | mBluetoothPendingStats = false; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 331 | mStats.noteBluetoothOffLocked(); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | public void noteFullWifiLockAcquired(int uid) { |
| 336 | enforceCallingPermission(); |
| 337 | synchronized (mStats) { |
| 338 | mStats.noteFullWifiLockAcquiredLocked(uid); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | public void noteFullWifiLockReleased(int uid) { |
| 343 | enforceCallingPermission(); |
| 344 | synchronized (mStats) { |
| 345 | mStats.noteFullWifiLockReleasedLocked(uid); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | public void noteScanWifiLockAcquired(int uid) { |
| 350 | enforceCallingPermission(); |
| 351 | synchronized (mStats) { |
| 352 | mStats.noteScanWifiLockAcquiredLocked(uid); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | public void noteScanWifiLockReleased(int uid) { |
| 357 | enforceCallingPermission(); |
| 358 | synchronized (mStats) { |
| 359 | mStats.noteScanWifiLockReleasedLocked(uid); |
| 360 | } |
| 361 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | |
Robert Greenwalt | 5347bd4 | 2009-05-13 15:10:16 -0700 | [diff] [blame] | 363 | public void noteWifiMulticastEnabled(int uid) { |
| 364 | enforceCallingPermission(); |
| 365 | synchronized (mStats) { |
| 366 | mStats.noteWifiMulticastEnabledLocked(uid); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | public void noteWifiMulticastDisabled(int uid) { |
| 371 | enforceCallingPermission(); |
| 372 | synchronized (mStats) { |
| 373 | mStats.noteWifiMulticastDisabledLocked(uid); |
| 374 | } |
| 375 | } |
| 376 | |
Dianne Hackborn | 7e9f4eb | 2010-09-10 18:43:00 -0700 | [diff] [blame] | 377 | public void noteFullWifiLockAcquiredFromSource(WorkSource ws) { |
| 378 | enforceCallingPermission(); |
| 379 | synchronized (mStats) { |
| 380 | mStats.noteFullWifiLockAcquiredFromSourceLocked(ws); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | public void noteFullWifiLockReleasedFromSource(WorkSource ws) { |
| 385 | enforceCallingPermission(); |
| 386 | synchronized (mStats) { |
| 387 | mStats.noteFullWifiLockReleasedFromSourceLocked(ws); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | public void noteScanWifiLockAcquiredFromSource(WorkSource ws) { |
| 392 | enforceCallingPermission(); |
| 393 | synchronized (mStats) { |
| 394 | mStats.noteScanWifiLockAcquiredFromSourceLocked(ws); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | public void noteScanWifiLockReleasedFromSource(WorkSource ws) { |
| 399 | enforceCallingPermission(); |
| 400 | synchronized (mStats) { |
| 401 | mStats.noteScanWifiLockReleasedFromSourceLocked(ws); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | public void noteWifiMulticastEnabledFromSource(WorkSource ws) { |
| 406 | enforceCallingPermission(); |
| 407 | synchronized (mStats) { |
| 408 | mStats.noteWifiMulticastEnabledFromSourceLocked(ws); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | public void noteWifiMulticastDisabledFromSource(WorkSource ws) { |
| 413 | enforceCallingPermission(); |
| 414 | synchronized (mStats) { |
| 415 | mStats.noteWifiMulticastDisabledFromSourceLocked(ws); |
| 416 | } |
| 417 | } |
| 418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | public boolean isOnBattery() { |
| 420 | return mStats.isOnBattery(); |
| 421 | } |
| 422 | |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 423 | public void setBatteryState(int status, int health, int plugType, int level, |
| 424 | int temp, int volt) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 425 | enforceCallingPermission(); |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 426 | mStats.setBatteryState(status, health, plugType, level, temp, volt); |
Evan Millar | 633a174 | 2009-04-02 16:36:33 -0700 | [diff] [blame] | 427 | } |
| 428 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 429 | public long getAwakeTimeBattery() { |
| 430 | mContext.enforceCallingOrSelfPermission( |
| 431 | android.Manifest.permission.BATTERY_STATS, null); |
| 432 | return mStats.getAwakeTimeBattery(); |
| 433 | } |
| 434 | |
| 435 | public long getAwakeTimePlugged() { |
| 436 | mContext.enforceCallingOrSelfPermission( |
| 437 | android.Manifest.permission.BATTERY_STATS, null); |
| 438 | return mStats.getAwakeTimePlugged(); |
| 439 | } |
| 440 | |
| 441 | public void enforceCallingPermission() { |
| 442 | if (Binder.getCallingPid() == Process.myPid()) { |
| 443 | return; |
| 444 | } |
| 445 | mContext.enforcePermission(android.Manifest.permission.UPDATE_DEVICE_STATS, |
| 446 | Binder.getCallingPid(), Binder.getCallingUid(), null); |
| 447 | } |
| 448 | |
| 449 | @Override |
| 450 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 451 | boolean isCheckin = false; |
| 452 | if (args != null) { |
| 453 | for (String arg : args) { |
| 454 | if ("--checkin".equals(arg)) { |
| 455 | isCheckin = true; |
| 456 | } else if ("--reset".equals(arg)) { |
| 457 | synchronized (mStats) { |
Dianne Hackborn | 6b7b484 | 2010-06-14 17:17:44 -0700 | [diff] [blame] | 458 | mStats.resetAllStatsLocked(); |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 459 | pw.println("Battery stats reset."); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | } |
Dianne Hackborn | e4a5951 | 2010-12-07 11:08:07 -0800 | [diff] [blame] | 463 | } |
| 464 | if (isCheckin) { |
| 465 | List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0); |
| 466 | synchronized (mStats) { |
| 467 | mStats.dumpCheckinLocked(pw, args, apps); |
| 468 | } |
| 469 | } else { |
| 470 | synchronized (mStats) { |
| 471 | mStats.dumpLocked(pw); |
| 472 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | } |