@@ -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