From 70be1673abf6334d2caf60fdc0504088b0e0859c Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Tue, 14 Sep 2010 11:13:03 -0700 Subject: [PATCH] Fix problem where power manager was calling battery stats with bad wl type. Also fiddle code to reduce duplication. Change-Id: I3f1b086e53ef88dac1ec1896fe711b3cfe7fdd58 --- .../android/server/PowerManagerService.java | 74 +++++++++---------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java index af8d7d42d85d3..8ab1bb87d3937 100644 --- a/services/java/com/android/server/PowerManagerService.java +++ b/services/java/com/android/server/PowerManagerService.java @@ -660,28 +660,38 @@ class PowerManagerService extends IPowerManager.Stub } void noteStartWakeLocked(WakeLock wl, WorkSource ws) { - try { - if (ws != null) { - mBatteryStats.noteStartWakelockFromSource(ws, wl.pid, wl.tag, - wl.monitorType); - } else { - mBatteryStats.noteStartWakelock(wl.uid, wl.pid, wl.tag, wl.monitorType); + if (wl.monitorType >= 0) { + long origId = Binder.clearCallingIdentity(); + try { + if (ws != null) { + mBatteryStats.noteStartWakelockFromSource(ws, wl.pid, wl.tag, + wl.monitorType); + } else { + mBatteryStats.noteStartWakelock(wl.uid, wl.pid, wl.tag, wl.monitorType); + } + } catch (RemoteException e) { + // Ignore + } finally { + Binder.restoreCallingIdentity(origId); } - } catch (RemoteException e) { - // Ignore } } void noteStopWakeLocked(WakeLock wl, WorkSource ws) { - try { - if (ws != null) { - mBatteryStats.noteStopWakelockFromSource(ws, wl.pid, wl.tag, - wl.monitorType); - } else { - mBatteryStats.noteStopWakelock(wl.uid, wl.pid, wl.tag, wl.monitorType); + if (wl.monitorType >= 0) { + long origId = Binder.clearCallingIdentity(); + try { + if (ws != null) { + mBatteryStats.noteStopWakelockFromSource(ws, wl.pid, wl.tag, + wl.monitorType); + } else { + mBatteryStats.noteStopWakelock(wl.uid, wl.pid, wl.tag, wl.monitorType); + } + } catch (RemoteException e) { + // Ignore + } finally { + Binder.restoreCallingIdentity(origId); } - } catch (RemoteException e) { - // Ignore } } @@ -813,21 +823,16 @@ class PowerManagerService extends IPowerManager.Stub if (ws != null) { enforceWakeSourcePermission(uid, pid); } - long ident = Binder.clearCallingIdentity(); - try { - synchronized (mLocks) { - int index = mLocks.getIndex(lock); - if (index < 0) { - throw new IllegalArgumentException("Wake lock not active"); - } - WakeLock wl = mLocks.get(index); - WorkSource oldsource = wl.ws; - wl.ws = ws != null ? new WorkSource(ws) : null; - noteStopWakeLocked(wl, oldsource); - noteStartWakeLocked(wl, ws); + synchronized (mLocks) { + int index = mLocks.getIndex(lock); + if (index < 0) { + throw new IllegalArgumentException("Wake lock not active"); } - } finally { - Binder.restoreCallingIdentity(ident); + WakeLock wl = mLocks.get(index); + WorkSource oldsource = wl.ws; + wl.ws = ws != null ? new WorkSource(ws) : null; + noteStopWakeLocked(wl, oldsource); + noteStartWakeLocked(wl, ws); } } @@ -884,14 +889,7 @@ class PowerManagerService extends IPowerManager.Stub // Unlink the lock from the binder. wl.binder.unlinkToDeath(wl, 0); - if (wl.monitorType >= 0) { - long origId = Binder.clearCallingIdentity(); - try { - noteStopWakeLocked(wl, wl.ws); - } finally { - Binder.restoreCallingIdentity(origId); - } - } + noteStopWakeLocked(wl, wl.ws); } private class PokeLock implements IBinder.DeathRecipient