diff options
8 files changed, 249 insertions, 127 deletions
diff --git a/apex/jobscheduler/framework/java/android/app/AlarmManager.java b/apex/jobscheduler/framework/java/android/app/AlarmManager.java index 5a445d476711..dade7c3d84a8 100644 --- a/apex/jobscheduler/framework/java/android/app/AlarmManager.java +++ b/apex/jobscheduler/framework/java/android/app/AlarmManager.java @@ -309,7 +309,7 @@ public class AlarmManager { /** * Callback method that is invoked by the system when the alarm time is reached. */ - public void onAlarm(); + void onAlarm(); } final class ListenerWrapper extends IAlarmListener.Stub implements Runnable { @@ -453,7 +453,7 @@ public class AlarmManager { * @see #RTC * @see #RTC_WAKEUP */ - public void set(@AlarmType int type, long triggerAtMillis, PendingIntent operation) { + public void set(@AlarmType int type, long triggerAtMillis, @NonNull PendingIntent operation) { setImpl(type, triggerAtMillis, legacyExactLength(), 0, 0, operation, null, null, (Handler) null, null, null); } @@ -480,8 +480,8 @@ public class AlarmManager { * @param targetHandler {@link Handler} on which to execute the listener's onAlarm() * callback, or {@code null} to run that callback on the main looper. */ - public void set(@AlarmType int type, long triggerAtMillis, String tag, OnAlarmListener listener, - Handler targetHandler) { + public void set(@AlarmType int type, long triggerAtMillis, @Nullable String tag, + @NonNull OnAlarmListener listener, @Nullable Handler targetHandler) { setImpl(type, triggerAtMillis, legacyExactLength(), 0, 0, null, listener, tag, targetHandler, null, null); } @@ -546,7 +546,7 @@ public class AlarmManager { * @see Intent#EXTRA_ALARM_COUNT */ public void setRepeating(@AlarmType int type, long triggerAtMillis, - long intervalMillis, PendingIntent operation) { + long intervalMillis, @NonNull PendingIntent operation) { setImpl(type, triggerAtMillis, legacyExactLength(), intervalMillis, 0, operation, null, null, (Handler) null, null, null); } @@ -602,7 +602,7 @@ public class AlarmManager { * @see #RTC_WAKEUP */ public void setWindow(@AlarmType int type, long windowStartMillis, long windowLengthMillis, - PendingIntent operation) { + @NonNull PendingIntent operation) { setImpl(type, windowStartMillis, windowLengthMillis, 0, 0, operation, null, null, (Handler) null, null, null); } @@ -625,12 +625,62 @@ public class AlarmManager { * @see #setWindow(int, long, long, PendingIntent) */ public void setWindow(@AlarmType int type, long windowStartMillis, long windowLengthMillis, - String tag, OnAlarmListener listener, Handler targetHandler) { + @Nullable String tag, @NonNull OnAlarmListener listener, + @Nullable Handler targetHandler) { setImpl(type, windowStartMillis, windowLengthMillis, 0, 0, null, listener, tag, targetHandler, null, null); } /** + * Direct callback version of {@link #setWindow(int, long, long, PendingIntent)}. Rather + * than supplying a PendingIntent to be sent when the alarm time is reached, this variant + * supplies an {@link OnAlarmListener} instance that will be invoked at that time. + * <p> + * The OnAlarmListener {@link OnAlarmListener#onAlarm() onAlarm()} method will be + * invoked via the specified target Executor. + * + * <p> + * Note: Starting with API {@link Build.VERSION_CODES#S}, apps should not pass in a window of + * less than 10 minutes. The system will try its best to accommodate smaller windows if the + * alarm is supposed to fire in the near future, but there are no guarantees and the app should + * expect any window smaller than 10 minutes to get elongated to 10 minutes. + * + * @see #setWindow(int, long, long, PendingIntent) + */ + public void setWindow(@AlarmType int type, long windowStartMillis, long windowLengthMillis, + @Nullable String tag, @NonNull Executor executor, @NonNull OnAlarmListener listener) { + setImpl(type, windowStartMillis, windowLengthMillis, 0, 0, null, listener, tag, + executor, null, null); + } + + /** + * Direct callback version of {@link #setWindow(int, long, long, PendingIntent)}. Rather + * than supplying a PendingIntent to be sent when the alarm time is reached, this variant + * supplies an {@link OnAlarmListener} instance that will be invoked at that time. + * <p> + * The OnAlarmListener {@link OnAlarmListener#onAlarm() onAlarm()} method will be + * invoked via the specified target Executor. + * + * <p> + * Note: Starting with API {@link Build.VERSION_CODES#S}, apps should not pass in a window of + * less than 10 minutes. The system will try its best to accommodate smaller windows if the + * alarm is supposed to fire in the near future, but there are no guarantees and the app should + * expect any window smaller than 10 minutes to get elongated to 10 minutes. + * + * @see #setWindow(int, long, long, PendingIntent) + * + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) + public void setWindow(@AlarmType int type, long windowStartMillis, long windowLengthMillis, + @Nullable String tag, @NonNull Executor executor, @Nullable WorkSource workSource, + @NonNull OnAlarmListener listener) { + setImpl(type, windowStartMillis, windowLengthMillis, 0, 0, null, listener, tag, + executor, workSource, null); + } + + /** * Schedule an alarm that is prioritized by the system while the device is in power saving modes * such as battery saver and device idle (doze). * @@ -725,7 +775,8 @@ public class AlarmManager { * @see Manifest.permission#SCHEDULE_EXACT_ALARM SCHEDULE_EXACT_ALARM */ @RequiresPermission(value = Manifest.permission.SCHEDULE_EXACT_ALARM, conditional = true) - public void setExact(@AlarmType int type, long triggerAtMillis, PendingIntent operation) { + public void setExact(@AlarmType int type, long triggerAtMillis, + @NonNull PendingIntent operation) { setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, 0, operation, null, null, (Handler) null, null, null); } @@ -756,8 +807,8 @@ public class AlarmManager { * @see Manifest.permission#SCHEDULE_EXACT_ALARM SCHEDULE_EXACT_ALARM */ @RequiresPermission(value = Manifest.permission.SCHEDULE_EXACT_ALARM, conditional = true) - public void setExact(@AlarmType int type, long triggerAtMillis, String tag, - OnAlarmListener listener, Handler targetHandler) { + public void setExact(@AlarmType int type, long triggerAtMillis, @Nullable String tag, + @NonNull OnAlarmListener listener, @Nullable Handler targetHandler) { setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, 0, null, listener, tag, targetHandler, null, null); } @@ -767,8 +818,8 @@ public class AlarmManager { * the given time. * @hide */ - public void setIdleUntil(@AlarmType int type, long triggerAtMillis, String tag, - OnAlarmListener listener, Handler targetHandler) { + public void setIdleUntil(@AlarmType int type, long triggerAtMillis, @Nullable String tag, + @NonNull OnAlarmListener listener, @Nullable Handler targetHandler) { setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, FLAG_IDLE_UNTIL, null, listener, tag, targetHandler, null, null); } @@ -828,7 +879,7 @@ public class AlarmManager { * @see Manifest.permission#SCHEDULE_EXACT_ALARM SCHEDULE_EXACT_ALARM */ @RequiresPermission(Manifest.permission.SCHEDULE_EXACT_ALARM) - public void setAlarmClock(AlarmClockInfo info, PendingIntent operation) { + public void setAlarmClock(@NonNull AlarmClockInfo info, @NonNull PendingIntent operation) { setImpl(RTC_WAKEUP, info.getTriggerTime(), WINDOW_EXACT, 0, 0, operation, null, null, (Handler) null, null, info); } @@ -837,7 +888,8 @@ public class AlarmManager { @SystemApi @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void set(@AlarmType int type, long triggerAtMillis, long windowMillis, - long intervalMillis, PendingIntent operation, WorkSource workSource) { + long intervalMillis, @NonNull PendingIntent operation, + @Nullable WorkSource workSource) { setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, operation, null, null, (Handler) null, workSource, null); } @@ -854,8 +906,8 @@ public class AlarmManager { */ @UnsupportedAppUsage public void set(@AlarmType int type, long triggerAtMillis, long windowMillis, - long intervalMillis, String tag, OnAlarmListener listener, Handler targetHandler, - WorkSource workSource) { + long intervalMillis, @Nullable String tag, @NonNull OnAlarmListener listener, + @Nullable Handler targetHandler, @Nullable WorkSource workSource) { setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, null, listener, tag, targetHandler, workSource, null); } @@ -873,8 +925,8 @@ public class AlarmManager { @SystemApi @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void set(@AlarmType int type, long triggerAtMillis, long windowMillis, - long intervalMillis, OnAlarmListener listener, Handler targetHandler, - WorkSource workSource) { + long intervalMillis, @NonNull OnAlarmListener listener, @Nullable Handler targetHandler, + @Nullable WorkSource workSource) { setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, null, listener, null, targetHandler, workSource, null); } @@ -1072,7 +1124,7 @@ public class AlarmManager { * @see Intent#EXTRA_ALARM_COUNT */ public void setInexactRepeating(@AlarmType int type, long triggerAtMillis, - long intervalMillis, PendingIntent operation) { + long intervalMillis, @NonNull PendingIntent operation) { setImpl(type, triggerAtMillis, WINDOW_HEURISTIC, intervalMillis, 0, operation, null, null, (Handler) null, null, null); } @@ -1122,7 +1174,7 @@ public class AlarmManager { * @see #RTC_WAKEUP */ public void setAndAllowWhileIdle(@AlarmType int type, long triggerAtMillis, - PendingIntent operation) { + @NonNull PendingIntent operation) { setImpl(type, triggerAtMillis, WINDOW_HEURISTIC, 0, FLAG_ALLOW_WHILE_IDLE, operation, null, null, (Handler) null, null, null); } @@ -1195,12 +1247,46 @@ public class AlarmManager { */ @RequiresPermission(value = Manifest.permission.SCHEDULE_EXACT_ALARM, conditional = true) public void setExactAndAllowWhileIdle(@AlarmType int type, long triggerAtMillis, - PendingIntent operation) { + @NonNull PendingIntent operation) { setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, FLAG_ALLOW_WHILE_IDLE, operation, null, null, (Handler) null, null, null); } /** + * Like {@link #setExact(int, long, String, Executor, WorkSource, OnAlarmListener)}, but this + * alarm will be allowed to execute even when the system is in low-power idle modes. + * + * <p> See {@link #setExactAndAllowWhileIdle(int, long, PendingIntent)} for more details. + * + * @param type type of alarm + * @param triggerAtMillis The exact time in milliseconds, that the alarm should be delivered, + * expressed in the appropriate clock's units (depending on the alarm + * type). + * @param listener {@link OnAlarmListener} instance whose + * {@link OnAlarmListener#onAlarm() onAlarm()} method will be called when + * the alarm time is reached. + * @param executor The {@link Executor} on which to execute the listener's onAlarm() + * callback. + * @param tag Optional. A string tag used to identify this alarm in logs and + * battery-attribution. + * @param workSource A {@link WorkSource} object to attribute this alarm to the app that + * requested this work. + * @hide + */ + @SystemApi + @RequiresPermission(allOf = { + Manifest.permission.UPDATE_DEVICE_STATS, + Manifest.permission.SCHEDULE_EXACT_ALARM}, conditional = true) + public void setExactAndAllowWhileIdle(@AlarmType int type, long triggerAtMillis, + @Nullable String tag, @NonNull Executor executor, @Nullable WorkSource workSource, + @NonNull OnAlarmListener listener) { + Objects.requireNonNull(executor); + Objects.requireNonNull(listener); + setImpl(type, triggerAtMillis, WINDOW_EXACT, 0, FLAG_ALLOW_WHILE_IDLE, null, listener, tag, + executor, workSource, null); + } + + /** * Remove any alarms with a matching {@link Intent}. * Any alarm, of any type, whose Intent matches this one (as defined by * {@link Intent#filterEquals}), will be canceled. @@ -1210,7 +1296,7 @@ public class AlarmManager { * * @see #set */ - public void cancel(PendingIntent operation) { + public void cancel(@NonNull PendingIntent operation) { if (operation == null) { final String msg = "cancel() called with a null PendingIntent"; if (mTargetSdkVersion >= Build.VERSION_CODES.N) { @@ -1233,7 +1319,7 @@ public class AlarmManager { * * @param listener OnAlarmListener instance that is the target of a currently-set alarm. */ - public void cancel(OnAlarmListener listener) { + public void cancel(@NonNull OnAlarmListener listener) { if (listener == null) { throw new NullPointerException("cancel() called with a null OnAlarmListener"); } diff --git a/core/api/current.txt b/core/api/current.txt index 2049d91acbe3..50161fb6fe4a 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -4604,23 +4604,24 @@ package android.app { public class AlarmManager { method public boolean canScheduleExactAlarms(); - method public void cancel(android.app.PendingIntent); - method public void cancel(android.app.AlarmManager.OnAlarmListener); + method public void cancel(@NonNull android.app.PendingIntent); + method public void cancel(@NonNull android.app.AlarmManager.OnAlarmListener); method public void cancelAll(); method public android.app.AlarmManager.AlarmClockInfo getNextAlarmClock(); - method public void set(int, long, android.app.PendingIntent); - method public void set(int, long, String, android.app.AlarmManager.OnAlarmListener, android.os.Handler); - method @RequiresPermission(android.Manifest.permission.SCHEDULE_EXACT_ALARM) public void setAlarmClock(android.app.AlarmManager.AlarmClockInfo, android.app.PendingIntent); - method public void setAndAllowWhileIdle(int, long, android.app.PendingIntent); - method @RequiresPermission(value=android.Manifest.permission.SCHEDULE_EXACT_ALARM, conditional=true) public void setExact(int, long, android.app.PendingIntent); - method @RequiresPermission(value=android.Manifest.permission.SCHEDULE_EXACT_ALARM, conditional=true) public void setExact(int, long, String, android.app.AlarmManager.OnAlarmListener, android.os.Handler); - method @RequiresPermission(value=android.Manifest.permission.SCHEDULE_EXACT_ALARM, conditional=true) public void setExactAndAllowWhileIdle(int, long, android.app.PendingIntent); - method public void setInexactRepeating(int, long, long, android.app.PendingIntent); - method public void setRepeating(int, long, long, android.app.PendingIntent); + method public void set(int, long, @NonNull android.app.PendingIntent); + method public void set(int, long, @Nullable String, @NonNull android.app.AlarmManager.OnAlarmListener, @Nullable android.os.Handler); + method @RequiresPermission(android.Manifest.permission.SCHEDULE_EXACT_ALARM) public void setAlarmClock(@NonNull android.app.AlarmManager.AlarmClockInfo, @NonNull android.app.PendingIntent); + method public void setAndAllowWhileIdle(int, long, @NonNull android.app.PendingIntent); + method @RequiresPermission(value=android.Manifest.permission.SCHEDULE_EXACT_ALARM, conditional=true) public void setExact(int, long, @NonNull android.app.PendingIntent); + method @RequiresPermission(value=android.Manifest.permission.SCHEDULE_EXACT_ALARM, conditional=true) public void setExact(int, long, @Nullable String, @NonNull android.app.AlarmManager.OnAlarmListener, @Nullable android.os.Handler); + method @RequiresPermission(value=android.Manifest.permission.SCHEDULE_EXACT_ALARM, conditional=true) public void setExactAndAllowWhileIdle(int, long, @NonNull android.app.PendingIntent); + method public void setInexactRepeating(int, long, long, @NonNull android.app.PendingIntent); + method public void setRepeating(int, long, long, @NonNull android.app.PendingIntent); method @RequiresPermission(android.Manifest.permission.SET_TIME) public void setTime(long); method @RequiresPermission(android.Manifest.permission.SET_TIME_ZONE) public void setTimeZone(String); - method public void setWindow(int, long, long, android.app.PendingIntent); - method public void setWindow(int, long, long, String, android.app.AlarmManager.OnAlarmListener, android.os.Handler); + method public void setWindow(int, long, long, @NonNull android.app.PendingIntent); + method public void setWindow(int, long, long, @Nullable String, @NonNull android.app.AlarmManager.OnAlarmListener, @Nullable android.os.Handler); + method public void setWindow(int, long, long, @Nullable String, @NonNull java.util.concurrent.Executor, @NonNull android.app.AlarmManager.OnAlarmListener); field public static final String ACTION_NEXT_ALARM_CLOCK_CHANGED = "android.app.action.NEXT_ALARM_CLOCK_CHANGED"; field public static final String ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED = "android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED"; field public static final int ELAPSED_REALTIME = 3; // 0x3 diff --git a/core/api/system-current.txt b/core/api/system-current.txt index fdb5e071c610..7cbf4617d991 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -524,10 +524,12 @@ package android.app { } public class AlarmManager { - method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void set(int, long, long, long, android.app.PendingIntent, android.os.WorkSource); - method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void set(int, long, long, long, android.app.AlarmManager.OnAlarmListener, android.os.Handler, android.os.WorkSource); + method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void set(int, long, long, long, @NonNull android.app.PendingIntent, @Nullable android.os.WorkSource); + method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void set(int, long, long, long, @NonNull android.app.AlarmManager.OnAlarmListener, @Nullable android.os.Handler, @Nullable android.os.WorkSource); method @RequiresPermission(allOf={android.Manifest.permission.UPDATE_DEVICE_STATS, android.Manifest.permission.SCHEDULE_EXACT_ALARM}, conditional=true) public void setExact(int, long, @Nullable String, @NonNull java.util.concurrent.Executor, @NonNull android.os.WorkSource, @NonNull android.app.AlarmManager.OnAlarmListener); + method @RequiresPermission(allOf={android.Manifest.permission.UPDATE_DEVICE_STATS, android.Manifest.permission.SCHEDULE_EXACT_ALARM}, conditional=true) public void setExactAndAllowWhileIdle(int, long, @Nullable String, @NonNull java.util.concurrent.Executor, @Nullable android.os.WorkSource, @NonNull android.app.AlarmManager.OnAlarmListener); method @RequiresPermission(android.Manifest.permission.SCHEDULE_PRIORITIZED_ALARM) public void setPrioritized(int, long, long, @Nullable String, @NonNull java.util.concurrent.Executor, @NonNull android.app.AlarmManager.OnAlarmListener); + method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void setWindow(int, long, long, @Nullable String, @NonNull java.util.concurrent.Executor, @Nullable android.os.WorkSource, @NonNull android.app.AlarmManager.OnAlarmListener); } public class AppOpsManager { diff --git a/services/tests/mockingservicestests/src/com/android/server/DeviceIdleControllerTest.java b/services/tests/mockingservicestests/src/com/android/server/DeviceIdleControllerTest.java index cb14864876ab..2583f44787ad 100644 --- a/services/tests/mockingservicestests/src/com/android/server/DeviceIdleControllerTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/DeviceIdleControllerTest.java @@ -325,7 +325,7 @@ public class DeviceIdleControllerTest { doNothing().when(mAlarmManager).set(anyInt(), anyLong(), anyString(), any(), any()); doNothing().when(mAlarmManager).setExact(anyInt(), anyLong(), anyString(), any(), any()); doNothing().when(mAlarmManager) - .setWindow(anyInt(), anyLong(), anyLong(), anyString(), any(), any()); + .setWindow(anyInt(), anyLong(), anyLong(), anyString(), any(), any(Handler.class)); doReturn(mock(Sensor.class)).when(mSensorManager) .getDefaultSensor(eq(Sensor.TYPE_SIGNIFICANT_MOTION), eq(true)); doReturn(true).when(mSensorManager).registerListener(any(), any(), anyInt()); @@ -1111,12 +1111,12 @@ public class DeviceIdleControllerTest { alarmManagerInOrder.verify(mAlarmManager).setWindow( eq(AlarmManager.ELAPSED_REALTIME), eq(idleAfterInactiveExpiryTime), - anyLong(), anyString(), any(), any()); + anyLong(), anyString(), any(), any(Handler.class)); // Maintenance alarm alarmManagerInOrder.verify(mAlarmManager).setWindow( eq(AlarmManager.ELAPSED_REALTIME_WAKEUP), eq(idleAfterInactiveExpiryTime + idlingTimeMs), - anyLong(), anyString(), any(), any()); + anyLong(), anyString(), any(), any(Handler.class)); final AlarmManager.OnAlarmListener progressionListener = alarmListenerCaptor.getAllValues().get(0); @@ -1130,7 +1130,7 @@ public class DeviceIdleControllerTest { alarmManagerInOrder.verify(mAlarmManager).setWindow( eq(AlarmManager.ELAPSED_REALTIME_WAKEUP), eq(mInjector.nowElapsed + idlingTimeMs), - anyLong(), anyString(), any(), any()); + anyLong(), anyString(), any(), any(Handler.class)); for (int i = 0; i < 2; ++i) { // IDLE->MAINTENANCE alarm @@ -1144,12 +1144,12 @@ public class DeviceIdleControllerTest { alarmManagerInOrder.verify(mAlarmManager).setWindow( eq(AlarmManager.ELAPSED_REALTIME), eq(maintenanceExpiryTime), - anyLong(), anyString(), any(), any()); + anyLong(), anyString(), any(), any(Handler.class)); // Set IDLE->MAINTENANCE alarmManagerInOrder.verify(mAlarmManager).setWindow( eq(AlarmManager.ELAPSED_REALTIME_WAKEUP), eq(maintenanceExpiryTime + idlingTimeMs), - anyLong(), anyString(), any(), any()); + anyLong(), anyString(), any(), any(Handler.class)); // MAINTENANCE->IDLE alarm mInjector.nowElapsed = mDeviceIdleController.getNextLightAlarmTimeForTesting(); @@ -1159,7 +1159,7 @@ public class DeviceIdleControllerTest { alarmManagerInOrder.verify(mAlarmManager).setWindow( eq(AlarmManager.ELAPSED_REALTIME_WAKEUP), eq(mInjector.nowElapsed + idlingTimeMs), - anyLong(), anyString(), any(), any()); + anyLong(), anyString(), any(), any(Handler.class)); } } @@ -2019,7 +2019,8 @@ public class DeviceIdleControllerTest { final ArgumentCaptor<AlarmManager.OnAlarmListener> alarmListener = ArgumentCaptor .forClass(AlarmManager.OnAlarmListener.class); doNothing().when(mAlarmManager).setWindow( - anyInt(), anyLong(), anyLong(), eq("DeviceIdleController.motion"), any(), any()); + anyInt(), anyLong(), anyLong(), eq("DeviceIdleController.motion"), any(), + any(Handler.class)); doNothing().when(mAlarmManager).setWindow(anyInt(), anyLong(), anyLong(), eq("DeviceIdleController.motion_registration"), alarmListener.capture(), any()); @@ -2063,7 +2064,8 @@ public class DeviceIdleControllerTest { final ArgumentCaptor<AlarmManager.OnAlarmListener> alarmListener = ArgumentCaptor .forClass(AlarmManager.OnAlarmListener.class); doNothing().when(mAlarmManager).setWindow( - anyInt(), anyLong(), anyLong(), eq("DeviceIdleController.motion"), any(), any()); + anyInt(), anyLong(), anyLong(), eq("DeviceIdleController.motion"), any(), + any(Handler.class)); doNothing().when(mAlarmManager).setWindow(anyInt(), anyLong(), anyLong(), eq("DeviceIdleController.motion_registration"), alarmListener.capture(), any()); @@ -2130,7 +2132,7 @@ public class DeviceIdleControllerTest { eq(SensorManager.SENSOR_DELAY_NORMAL)); inOrder.verify(mAlarmManager).setWindow( anyInt(), eq(mInjector.nowElapsed + mConstants.MOTION_INACTIVE_TIMEOUT), anyLong(), - eq("DeviceIdleController.motion"), any(), any()); + eq("DeviceIdleController.motion"), any(), any(Handler.class)); final SensorEventListener listener = listenerCaptor.getValue(); // Trigger motion @@ -2140,7 +2142,7 @@ public class DeviceIdleControllerTest { final ArgumentCaptor<Long> registrationTimeCaptor = ArgumentCaptor.forClass(Long.class); inOrder.verify(mAlarmManager).setWindow( anyInt(), registrationTimeCaptor.capture(), anyLong(), - eq("DeviceIdleController.motion_registration"), any(), any()); + eq("DeviceIdleController.motion_registration"), any(), any(Handler.class)); // Make sure the listener is re-registered. mInjector.nowElapsed = registrationTimeCaptor.getValue(); @@ -2150,7 +2152,7 @@ public class DeviceIdleControllerTest { eq(SensorManager.SENSOR_DELAY_NORMAL)); final ArgumentCaptor<Long> timeoutCaptor = ArgumentCaptor.forClass(Long.class); inOrder.verify(mAlarmManager).setWindow(anyInt(), timeoutCaptor.capture(), anyLong(), - eq("DeviceIdleController.motion"), any(), any()); + eq("DeviceIdleController.motion"), any(), any(Handler.class)); // No motion before timeout stationaryListener.motionExpected = false; diff --git a/services/tests/mockingservicestests/src/com/android/server/job/controllers/PrefetchControllerTest.java b/services/tests/mockingservicestests/src/com/android/server/job/controllers/PrefetchControllerTest.java index bb477b18d5fa..b949b3b265af 100644 --- a/services/tests/mockingservicestests/src/com/android/server/job/controllers/PrefetchControllerTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/job/controllers/PrefetchControllerTest.java @@ -47,6 +47,7 @@ import android.app.usage.UsageStatsManagerInternal.EstimatedLaunchTimeChangedLis import android.appwidget.AppWidgetManager; import android.content.ComponentName; import android.content.Context; +import android.os.Handler; import android.os.Looper; import android.os.Process; import android.os.SystemClock; @@ -276,13 +277,13 @@ public class PrefetchControllerTest { inOrder.verify(mAlarmManager, timeout(DEFAULT_WAIT_MS).times(1)) .setWindow( anyInt(), eq(sElapsedRealtimeClock.millis() + 4 * HOUR_IN_MILLIS), - anyLong(), eq(TAG_PREFETCH), any(), any()); + anyLong(), eq(TAG_PREFETCH), any(), any(Handler.class)); setDeviceConfigLong(PcConstants.KEY_LAUNCH_TIME_THRESHOLD_MS, 3 * HOUR_IN_MILLIS); inOrder.verify(mAlarmManager, timeout(DEFAULT_WAIT_MS).times(1)) .setWindow( anyInt(), eq(sElapsedRealtimeClock.millis() + 8 * HOUR_IN_MILLIS), - anyLong(), eq(TAG_PREFETCH), any(), any()); + anyLong(), eq(TAG_PREFETCH), any(), any(Handler.class)); } @Test @@ -414,7 +415,7 @@ public class PrefetchControllerTest { verify(mAlarmManager, timeout(DEFAULT_WAIT_MS).times(1)) .setWindow( anyInt(), eq(sElapsedRealtimeClock.millis() + 3 * HOUR_IN_MILLIS), - anyLong(), eq(TAG_PREFETCH), any(), any()); + anyLong(), eq(TAG_PREFETCH), any(), any(Handler.class)); assertFalse(jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_PREFETCH)); assertFalse(jobStatus.isReady()); } @@ -464,7 +465,7 @@ public class PrefetchControllerTest { verify(mAlarmManager, timeout(DEFAULT_WAIT_MS).times(1)) .setWindow( anyInt(), eq(sElapsedRealtimeClock.millis() + 3 * HOUR_IN_MILLIS), - anyLong(), eq(TAG_PREFETCH), any(), any()); + anyLong(), eq(TAG_PREFETCH), any(), any(Handler.class)); assertFalse(jobStatus.isConstraintSatisfied(JobStatus.CONSTRAINT_PREFETCH)); assertFalse(jobStatus.isReady()); diff --git a/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java b/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java index 9407968dbb56..bc7757b434ea 100644 --- a/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/job/controllers/QuotaControllerTest.java @@ -2708,7 +2708,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); final long now = JobSchedulerService.sElapsedRealtimeClock.millis(); // Test with timing sessions out of window but still under max execution limit. @@ -2725,7 +2725,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE, createTimingSession(now - 2 * HOUR_IN_MILLIS, 55 * MINUTE_IN_MILLIS, 1), false); @@ -2734,7 +2734,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); synchronized (mQuotaController.mLock) { mQuotaController.prepareForExecutionLocked(jobStatus); @@ -2749,7 +2749,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); } @Test @@ -2771,7 +2772,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test with timing sessions out of window. final long now = JobSchedulerService.sElapsedRealtimeClock.millis(); @@ -2782,7 +2783,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test with timing sessions in window but still in quota. final long end = now - (2 * HOUR_IN_MILLIS - 5 * MINUTE_IN_MILLIS); @@ -2796,7 +2797,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Add some more sessions, but still in quota. mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE, @@ -2808,7 +2809,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test when out of quota. mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE, @@ -2818,7 +2819,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); // Alarm already scheduled, so make sure it's not scheduled again. synchronized (mQuotaController.mLock) { @@ -2826,7 +2828,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); } @Test @@ -2850,7 +2853,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test with timing sessions out of window. final long now = JobSchedulerService.sElapsedRealtimeClock.millis(); @@ -2861,7 +2864,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test with timing sessions in window but still in quota. final long start = now - (6 * HOUR_IN_MILLIS); @@ -2873,7 +2876,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Add some more sessions, but still in quota. mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE, @@ -2885,7 +2888,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test when out of quota. mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE, @@ -2895,7 +2898,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); // Alarm already scheduled, so make sure it's not scheduled again. synchronized (mQuotaController.mLock) { @@ -2903,7 +2907,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); } /** @@ -2932,7 +2937,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, effectiveStandbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test with timing sessions out of window. final long now = JobSchedulerService.sElapsedRealtimeClock.millis(); @@ -2943,7 +2948,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, effectiveStandbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test with timing sessions in window but still in quota. final long start = now - (6 * HOUR_IN_MILLIS); @@ -2955,7 +2960,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, effectiveStandbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Add some more sessions, but still in quota. mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE, @@ -2967,7 +2972,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, effectiveStandbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test when out of quota. mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE, @@ -2977,7 +2982,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, effectiveStandbyBucket); } verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); // Alarm already scheduled, so make sure it's not scheduled again. synchronized (mQuotaController.mLock) { @@ -2985,7 +2991,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, effectiveStandbyBucket); } verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); } @Test @@ -3013,7 +3020,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test with timing sessions out of window. final long now = JobSchedulerService.sElapsedRealtimeClock.millis(); @@ -3023,7 +3030,7 @@ public class QuotaControllerTest { mQuotaController.maybeScheduleStartAlarmLocked(0, "com.android.test", standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test with timing sessions in window but still in quota. final long start = now - (6 * HOUR_IN_MILLIS); @@ -3039,7 +3046,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Add some more sessions, but still in quota. mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE, @@ -3051,7 +3058,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test when out of quota. mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE, @@ -3061,7 +3068,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); // Alarm already scheduled, so make sure it's not scheduled again. synchronized (mQuotaController.mLock) { @@ -3069,7 +3077,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); } /** Tests that the start alarm is properly rescheduled if the app's bucket is changed. */ @@ -3108,7 +3117,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, ACTIVE_INDEX); } inOrder.verify(mAlarmManager, timeout(1000).times(0)) - .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); inOrder.verify(mAlarmManager, timeout(1000).times(0)) .cancel(any(AlarmManager.OnAlarmListener.class)); @@ -3123,7 +3133,7 @@ public class QuotaControllerTest { } inOrder.verify(mAlarmManager, timeout(1000).times(1)).setWindow( anyInt(), eq(expectedWorkingAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); final long expectedFrequentAlarmTime = outOfQuotaTime + (8 * HOUR_IN_MILLIS) @@ -3135,7 +3145,7 @@ public class QuotaControllerTest { } inOrder.verify(mAlarmManager, timeout(1000).times(1)).setWindow( anyInt(), eq(expectedFrequentAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); final long expectedRareAlarmTime = outOfQuotaTime + (24 * HOUR_IN_MILLIS) @@ -3146,7 +3156,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, RARE_INDEX); } inOrder.verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedRareAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedRareAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); // And back up again. setStandbyBucket(FREQUENT_INDEX, jobStatus); @@ -3156,7 +3167,7 @@ public class QuotaControllerTest { } inOrder.verify(mAlarmManager, timeout(1000).times(1)).setWindow( anyInt(), eq(expectedFrequentAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); setStandbyBucket(WORKING_INDEX, jobStatus); synchronized (mQuotaController.mLock) { @@ -3165,7 +3176,7 @@ public class QuotaControllerTest { } inOrder.verify(mAlarmManager, timeout(1000).times(1)).setWindow( anyInt(), eq(expectedWorkingAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); setStandbyBucket(ACTIVE_INDEX, jobStatus); synchronized (mQuotaController.mLock) { @@ -3173,7 +3184,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, ACTIVE_INDEX); } inOrder.verify(mAlarmManager, timeout(1000).times(0)) - .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); inOrder.verify(mAlarmManager, timeout(1000).times(1)) .cancel(any(AlarmManager.OnAlarmListener.class)); } @@ -3210,7 +3222,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Valid time in the future, so the count should be used. stats.jobRateLimitExpirationTimeElapsed = now + 5 * MINUTE_IN_MILLIS / 2; @@ -3221,7 +3233,7 @@ public class QuotaControllerTest { } verify(mAlarmManager, timeout(1000).times(1)).setWindow( anyInt(), eq(expectedWorkingAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); } /** @@ -3318,7 +3330,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); } private void runTestMaybeScheduleStartAlarmLocked_SmallRollingQuota_MaxTimeCheck() { @@ -3355,7 +3368,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); } @Test @@ -4611,7 +4625,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Ran jobs up to the job limit. All of them should be allowed to run. for (int i = 0; i < mQcConstants.MAX_JOB_COUNT_PER_RATE_LIMITING_WINDOW; ++i) { @@ -4630,7 +4644,7 @@ public class QuotaControllerTest { } // Start alarm shouldn't have been scheduled since the app was in quota up until this point. verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // The app is now out of job count quota JobStatus throttledJob = createJobStatus( @@ -4649,7 +4663,7 @@ public class QuotaControllerTest { final long expectedWorkingAlarmTime = stats.jobRateLimitExpirationTimeElapsed; verify(mAlarmManager, timeout(1000).times(1)).setWindow( anyInt(), eq(expectedWorkingAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); } /** @@ -4680,7 +4694,7 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Ran jobs up to the job limit. All of them should be allowed to run. for (int i = 0; i < mQcConstants.MAX_SESSION_COUNT_PER_RATE_LIMITING_WINDOW; ++i) { @@ -4701,7 +4715,7 @@ public class QuotaControllerTest { } // Start alarm shouldn't have been scheduled since the app was in quota up until this point. verify(mAlarmManager, timeout(1000).times(0)).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // The app is now out of session count quota JobStatus throttledJob = createJobStatus( @@ -4721,7 +4735,7 @@ public class QuotaControllerTest { final long expectedWorkingAlarmTime = stats.sessionRateLimitExpirationTimeElapsed; verify(mAlarmManager, timeout(1000).times(1)).setWindow( anyInt(), eq(expectedWorkingAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); } @Test @@ -5185,7 +5199,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } inOrder.verify(mAlarmManager, timeout(1000).times(0)) - .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); // Test with timing sessions out of window. final long now = JobSchedulerService.sElapsedRealtimeClock.millis(); @@ -5196,7 +5211,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } inOrder.verify(mAlarmManager, timeout(1000).times(0)) - .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); // Test with timing sessions in window but still in quota. final long end = now - (22 * HOUR_IN_MILLIS - 5 * MINUTE_IN_MILLIS); @@ -5208,7 +5224,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } inOrder.verify(mAlarmManager, timeout(1000).times(0)) - .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); // Add some more sessions, but still in quota. mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE, @@ -5220,7 +5237,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } inOrder.verify(mAlarmManager, timeout(1000).times(0)) - .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); // Test when out of quota. mQuotaController.saveTimingSession(SOURCE_USER_ID, SOURCE_PACKAGE, @@ -5230,7 +5248,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } inOrder.verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); // Alarm already scheduled, so make sure it's not scheduled again. synchronized (mQuotaController.mLock) { @@ -5238,7 +5257,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, standbyBucket); } inOrder.verify(mAlarmManager, timeout(1000).times(0)) - .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); } /** Tests that the start alarm is properly rescheduled if the app's bucket is changed. */ @@ -5282,7 +5302,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, ACTIVE_INDEX); } inOrder.verify(mAlarmManager, timeout(1000).times(0)) - .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); inOrder.verify(mAlarmManager, timeout(1000).times(0)) .cancel(any(AlarmManager.OnAlarmListener.class)); @@ -5297,7 +5318,7 @@ public class QuotaControllerTest { } inOrder.verify(mAlarmManager, timeout(1000).times(1)).setWindow( anyInt(), eq(expectedWorkingAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); setStandbyBucket(FREQUENT_INDEX); final long expectedFrequentAlarmTime = @@ -5308,7 +5329,7 @@ public class QuotaControllerTest { } inOrder.verify(mAlarmManager, timeout(1000).times(1)).setWindow( anyInt(), eq(expectedFrequentAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); setStandbyBucket(RARE_INDEX); final long expectedRareAlarmTime = @@ -5319,7 +5340,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, RARE_INDEX); } inOrder.verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedRareAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedRareAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); // And back up again. setStandbyBucket(FREQUENT_INDEX); @@ -5329,7 +5351,7 @@ public class QuotaControllerTest { } inOrder.verify(mAlarmManager, timeout(1000).times(1)).setWindow( anyInt(), eq(expectedFrequentAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); setStandbyBucket(WORKING_INDEX); synchronized (mQuotaController.mLock) { @@ -5338,7 +5360,7 @@ public class QuotaControllerTest { } inOrder.verify(mAlarmManager, timeout(1000).times(1)).setWindow( anyInt(), eq(expectedWorkingAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); setStandbyBucket(ACTIVE_INDEX); synchronized (mQuotaController.mLock) { @@ -5346,7 +5368,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, ACTIVE_INDEX); } inOrder.verify(mAlarmManager, timeout(1000).times(0)) - .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); inOrder.verify(mAlarmManager, timeout(1000).times(1)) .cancel(any(AlarmManager.OnAlarmListener.class)); } @@ -5388,7 +5411,8 @@ public class QuotaControllerTest { SOURCE_USER_ID, SOURCE_PACKAGE, WORKING_INDEX); } verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); } /** Tests that TimingSessions aren't saved when the device is charging. */ diff --git a/services/tests/mockingservicestests/src/com/android/server/utils/AlarmQueueTest.java b/services/tests/mockingservicestests/src/com/android/server/utils/AlarmQueueTest.java index 00d7541a79dc..a3a49d7035d9 100644 --- a/services/tests/mockingservicestests/src/com/android/server/utils/AlarmQueueTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/utils/AlarmQueueTest.java @@ -35,6 +35,7 @@ import static org.mockito.Mockito.when; import android.app.AlarmManager; import android.content.Context; +import android.os.Handler; import android.os.Looper; import android.os.SystemClock; import android.util.ArraySet; @@ -222,7 +223,8 @@ public class AlarmQueueTest { alarmQueue.addAlarm("com.android.test.1", nowElapsed + HOUR_IN_MILLIS); verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(nowElapsed + HOUR_IN_MILLIS), anyLong(), eq(ALARM_TAG), any(), any()); + anyInt(), eq(nowElapsed + HOUR_IN_MILLIS), anyLong(), eq(ALARM_TAG), any(), any( + Handler.class)); } @Test diff --git a/services/tests/mockingservicestests/src/com/android/server/utils/quota/CountQuotaTrackerTest.java b/services/tests/mockingservicestests/src/com/android/server/utils/quota/CountQuotaTrackerTest.java index 608b64e7d12a..0d14c9f02677 100644 --- a/services/tests/mockingservicestests/src/com/android/server/utils/quota/CountQuotaTrackerTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/utils/quota/CountQuotaTrackerTest.java @@ -589,14 +589,14 @@ public class CountQuotaTrackerTest { // No sessions saved yet. mQuotaTracker.maybeScheduleStartAlarmLocked(TEST_USER_ID, TEST_PACKAGE, TEST_TAG); verify(mAlarmManager, never()).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test with timing sessions out of window. final long now = mInjector.getElapsedRealtime(); logEventsAt(TEST_USER_ID, TEST_PACKAGE, TEST_TAG, now - 10 * HOUR_IN_MILLIS, 20); mQuotaTracker.maybeScheduleStartAlarmLocked(TEST_USER_ID, TEST_PACKAGE, TEST_TAG); verify(mAlarmManager, never()).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test with timing sessions in window but still in quota. final long start = now - (6 * HOUR_IN_MILLIS); @@ -604,25 +604,27 @@ public class CountQuotaTrackerTest { logEventsAt(TEST_USER_ID, TEST_PACKAGE, TEST_TAG, start, 5); mQuotaTracker.maybeScheduleStartAlarmLocked(TEST_USER_ID, TEST_PACKAGE, TEST_TAG); verify(mAlarmManager, never()).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Add some more sessions, but still in quota. logEventsAt(TEST_USER_ID, TEST_PACKAGE, TEST_TAG, now - 3 * HOUR_IN_MILLIS, 1); logEventsAt(TEST_USER_ID, TEST_PACKAGE, TEST_TAG, now - HOUR_IN_MILLIS, 3); mQuotaTracker.maybeScheduleStartAlarmLocked(TEST_USER_ID, TEST_PACKAGE, TEST_TAG); verify(mAlarmManager, never()).setWindow( - anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // Test when out of quota. logEventsAt(TEST_USER_ID, TEST_PACKAGE, TEST_TAG, now - HOUR_IN_MILLIS, 1); mQuotaTracker.maybeScheduleStartAlarmLocked(TEST_USER_ID, TEST_PACKAGE, TEST_TAG); verify(mAlarmManager, timeout(1000).times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); // Alarm already scheduled, so make sure it's not scheduled again. mQuotaTracker.maybeScheduleStartAlarmLocked(TEST_USER_ID, TEST_PACKAGE, TEST_TAG); verify(mAlarmManager, times(1)).setWindow( - anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + anyInt(), eq(expectedAlarmTime), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); } /** Tests that the start alarm is properly rescheduled if the app's category is changed. */ @@ -656,7 +658,8 @@ public class CountQuotaTrackerTest { mCategorizer.mCategoryToUse = ACTIVE_BUCKET_CATEGORY; mQuotaTracker.maybeScheduleStartAlarmLocked(TEST_USER_ID, TEST_PACKAGE, TEST_TAG); inOrder.verify(mAlarmManager, never()) - .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); inOrder.verify(mAlarmManager, never()).cancel(any(AlarmManager.OnAlarmListener.class)); // And down from there. @@ -665,41 +668,42 @@ public class CountQuotaTrackerTest { mQuotaTracker.maybeScheduleStartAlarmLocked(TEST_USER_ID, TEST_PACKAGE, TEST_TAG); inOrder.verify(mAlarmManager, timeout(1000).times(1)) .setWindow(anyInt(), eq(expectedWorkingAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); final long expectedFrequentAlarmTime = outOfQuotaTime + (8 * HOUR_IN_MILLIS); mCategorizer.mCategoryToUse = FREQUENT_BUCKET_CATEGORY; mQuotaTracker.maybeScheduleStartAlarmLocked(TEST_USER_ID, TEST_PACKAGE, TEST_TAG); inOrder.verify(mAlarmManager, timeout(1000).times(1)) .setWindow(anyInt(), eq(expectedFrequentAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); final long expectedRareAlarmTime = outOfQuotaTime + (24 * HOUR_IN_MILLIS); mCategorizer.mCategoryToUse = RARE_BUCKET_CATEGORY; mQuotaTracker.maybeScheduleStartAlarmLocked(TEST_USER_ID, TEST_PACKAGE, TEST_TAG); inOrder.verify(mAlarmManager, timeout(1000).times(1)) .setWindow(anyInt(), eq(expectedRareAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); // And back up again. mCategorizer.mCategoryToUse = FREQUENT_BUCKET_CATEGORY; mQuotaTracker.maybeScheduleStartAlarmLocked(TEST_USER_ID, TEST_PACKAGE, TEST_TAG); inOrder.verify(mAlarmManager, timeout(1000).times(1)) .setWindow(anyInt(), eq(expectedFrequentAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); mCategorizer.mCategoryToUse = WORKING_SET_BUCKET_CATEGORY; mQuotaTracker.maybeScheduleStartAlarmLocked(TEST_USER_ID, TEST_PACKAGE, TEST_TAG); inOrder.verify(mAlarmManager, timeout(1000).times(1)) .setWindow(anyInt(), eq(expectedWorkingAlarmTime), anyLong(), - eq(TAG_QUOTA_CHECK), any(), any()); + eq(TAG_QUOTA_CHECK), any(), any(Handler.class)); mCategorizer.mCategoryToUse = ACTIVE_BUCKET_CATEGORY; mQuotaTracker.maybeScheduleStartAlarmLocked(TEST_USER_ID, TEST_PACKAGE, TEST_TAG); inOrder.verify(mAlarmManager, timeout(1000).times(1)) .cancel(any(AlarmManager.OnAlarmListener.class)); inOrder.verify(mAlarmManager, timeout(1000).times(0)) - .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), any()); + .setWindow(anyInt(), anyLong(), anyLong(), eq(TAG_QUOTA_CHECK), any(), + any(Handler.class)); } @Test |