From 4b9f62d1a25d05996ac20dd2178e2e79f7aefbc4 Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Mon, 11 Oct 2010 13:41:35 -0700 Subject: [PATCH] Don't throw when userActivity fails because of the permission check. Just log. But don't log too often. Bug: 3083024 Change-Id: I66f942a67ed6c481afb4079045c66931a4c81688 --- .../android/server/PowerManagerService.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java index 496c665e2c9ca..69fa3bff2fc49 100644 --- a/services/java/com/android/server/PowerManagerService.java +++ b/services/java/com/android/server/PowerManagerService.java @@ -245,6 +245,8 @@ class PowerManagerService extends IPowerManager.Stub private int[] mButtonBacklightValues; private int[] mKeyboardBacklightValues; private int mLightSensorWarmupTime; + private int mWarningSpewThrottleCount; + private long mWarningSpewThrottleTime; // Used when logging number and duration of touch-down cycles private long mTotalTouchDownTime; @@ -2095,6 +2097,21 @@ class PowerManagerService extends IPowerManager.Stub return (mScreenBrightness.animating && mScreenBrightness.targetValue == 0); } + private boolean shouldLog(long time) { + synchronized (mLocks) { + if (time > (mWarningSpewThrottleTime + (60*60*1000))) { + mWarningSpewThrottleTime = time; + mWarningSpewThrottleCount = 0; + return true; + } else if (mWarningSpewThrottleCount < 30) { + mWarningSpewThrottleCount++; + return true; + } else { + return false; + } + } + } + private void forceUserActivityLocked() { if (isScreenTurningOffLocked()) { // cancel animation so userActivity will succeed @@ -2112,7 +2129,15 @@ class PowerManagerService extends IPowerManager.Stub } public void userActivity(long time, boolean noChangeLights) { - mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); + if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER) + != PackageManager.PERMISSION_GRANTED) { + if (shouldLog(time)) { + Slog.w(TAG, "Caller does not have DEVICE_POWER permission. pid=" + + Binder.getCallingPid() + " uid=" + Binder.getCallingUid()); + } + return; + } + userActivity(time, -1, noChangeLights, OTHER_EVENT, false); }