Loading apex/jobscheduler/service/java/com/android/server/alarm/UserWakeupStore.java +8 −4 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ package com.android.server.alarm; import android.annotation.Nullable; import android.os.Environment; import android.os.SystemClock; import android.os.UserHandle; import android.util.AtomicFile; import android.util.IndentingPrintWriter; import android.util.Pair; Loading Loading @@ -113,16 +114,19 @@ public class UserWakeupStore { } /** * Add user wakeup for the alarm. * Add user wakeup for the alarm if needed. * @param userId Id of the user that scheduled alarm. * @param alarmTime time when alarm is expected to trigger. */ public void addUserWakeup(int userId, long alarmTime) { // SYSTEM user is always running, so no need to schedule wakeup for it. if (userId != UserHandle.USER_SYSTEM) { synchronized (mUserWakeupLock) { mUserStarts.put(userId, alarmTime - BUFFER_TIME_MS + getUserWakeupOffset()); } updateUserListFile(); } } /** * Remove wakeup scheduled for the user with given userId if present. Loading services/tests/mockingservicestests/src/com/android/server/alarm/UserWakeupStoreTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static com.android.server.alarm.UserWakeupStore.USER_START_TIME_DEVIATION import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.testng.AssertJUnit.assertFalse; import android.os.Environment; import android.os.FileUtils; Loading Loading @@ -51,6 +52,7 @@ public class UserWakeupStoreTest { private static final int USER_ID_1 = 10; private static final int USER_ID_2 = 11; private static final int USER_ID_3 = 12; private static final int USER_ID_SYSTEM = 0; private static final long TEST_TIMESTAMP = 150_000; private static final File TEST_SYSTEM_DIR = new File(InstrumentationRegistry .getInstrumentation().getContext().getDataDir(), "alarmsTestDir"); Loading Loading @@ -109,6 +111,14 @@ public class UserWakeupStoreTest { assertTrue(file.exists()); } @Test public void testAddWakeupForSystemUser_shouldDoNothing() { mUserWakeupStore.addUserWakeup(USER_ID_SYSTEM, TEST_TIMESTAMP - 19_000); assertEquals(0, mUserWakeupStore.getUserIdsToWakeup(TEST_TIMESTAMP).length); final File file = new File(ROOT_DIR , "usersWithAlarmClocks.xml"); assertFalse(file.exists()); } @Test public void testAddMultipleWakeupsForUser_ensureOnlyLastWakeupRemains() { final long finalAlarmTime = TEST_TIMESTAMP - 13_000; Loading Loading
apex/jobscheduler/service/java/com/android/server/alarm/UserWakeupStore.java +8 −4 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ package com.android.server.alarm; import android.annotation.Nullable; import android.os.Environment; import android.os.SystemClock; import android.os.UserHandle; import android.util.AtomicFile; import android.util.IndentingPrintWriter; import android.util.Pair; Loading Loading @@ -113,16 +114,19 @@ public class UserWakeupStore { } /** * Add user wakeup for the alarm. * Add user wakeup for the alarm if needed. * @param userId Id of the user that scheduled alarm. * @param alarmTime time when alarm is expected to trigger. */ public void addUserWakeup(int userId, long alarmTime) { // SYSTEM user is always running, so no need to schedule wakeup for it. if (userId != UserHandle.USER_SYSTEM) { synchronized (mUserWakeupLock) { mUserStarts.put(userId, alarmTime - BUFFER_TIME_MS + getUserWakeupOffset()); } updateUserListFile(); } } /** * Remove wakeup scheduled for the user with given userId if present. Loading
services/tests/mockingservicestests/src/com/android/server/alarm/UserWakeupStoreTest.java +10 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static com.android.server.alarm.UserWakeupStore.USER_START_TIME_DEVIATION import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.testng.AssertJUnit.assertFalse; import android.os.Environment; import android.os.FileUtils; Loading Loading @@ -51,6 +52,7 @@ public class UserWakeupStoreTest { private static final int USER_ID_1 = 10; private static final int USER_ID_2 = 11; private static final int USER_ID_3 = 12; private static final int USER_ID_SYSTEM = 0; private static final long TEST_TIMESTAMP = 150_000; private static final File TEST_SYSTEM_DIR = new File(InstrumentationRegistry .getInstrumentation().getContext().getDataDir(), "alarmsTestDir"); Loading Loading @@ -109,6 +111,14 @@ public class UserWakeupStoreTest { assertTrue(file.exists()); } @Test public void testAddWakeupForSystemUser_shouldDoNothing() { mUserWakeupStore.addUserWakeup(USER_ID_SYSTEM, TEST_TIMESTAMP - 19_000); assertEquals(0, mUserWakeupStore.getUserIdsToWakeup(TEST_TIMESTAMP).length); final File file = new File(ROOT_DIR , "usersWithAlarmClocks.xml"); assertFalse(file.exists()); } @Test public void testAddMultipleWakeupsForUser_ensureOnlyLastWakeupRemains() { final long finalAlarmTime = TEST_TIMESTAMP - 13_000; Loading