Skip to content

Commit 046cff1

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "Fix CTS test failures." into jb-mr1-dev
2 parents 9f5ed35 + 9ba8d78 commit 046cff1

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

services/java/com/android/server/power/PowerManagerService.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ public final class PowerManagerService extends IPowerManager.Stub
282282
// Use NaN to disable.
283283
private float mTemporaryScreenAutoBrightnessAdjustmentSettingOverride = Float.NaN;
284284

285+
// Time when we last logged a warning about calling userActivity() without permission.
286+
private long mLastWarningAboutUserActivityPermission = Long.MIN_VALUE;
287+
285288
private native void nativeInit();
286289
private static native void nativeShutdown();
287290
private static native void nativeReboot(String reason) throws IOException;
@@ -688,12 +691,29 @@ private boolean isWakeLockLevelSupportedInternal(int level) {
688691

689692
@Override // Binder call
690693
public void userActivity(long eventTime, int event, int flags) {
694+
final long now = SystemClock.uptimeMillis();
695+
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER)
696+
!= PackageManager.PERMISSION_GRANTED) {
697+
// Once upon a time applications could call userActivity().
698+
// Now we require the DEVICE_POWER permission. Log a warning and ignore the
699+
// request instead of throwing a SecurityException so we don't break old apps.
700+
synchronized (mLock) {
701+
if (now >= mLastWarningAboutUserActivityPermission + (5 * 60 * 1000)) {
702+
mLastWarningAboutUserActivityPermission = now;
703+
Slog.w(TAG, "Ignoring call to PowerManager.userActivity() because the "
704+
+ "caller does not have DEVICE_POWER permission. "
705+
+ "Please fix your app! "
706+
+ " pid=" + Binder.getCallingPid()
707+
+ " uid=" + Binder.getCallingUid());
708+
}
709+
}
710+
return;
711+
}
712+
691713
if (eventTime > SystemClock.uptimeMillis()) {
692714
throw new IllegalArgumentException("event time must not be in the future");
693715
}
694716

695-
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
696-
697717
final int uid = Binder.getCallingUid();
698718
final long ident = Binder.clearCallingIdentity();
699719
try {

0 commit comments

Comments
 (0)