Loading services/core/java/com/android/server/DeviceIdleController.java +7 −3 Original line number Diff line number Diff line Loading @@ -1031,9 +1031,9 @@ public class DeviceIdleController extends SystemService INACTIVE_TIMEOUT = mParser.getDurationMillis(KEY_INACTIVE_TIMEOUT, !COMPRESS_TIME ? inactiveTimeoutDefault : (inactiveTimeoutDefault / 10)); SENSING_TIMEOUT = mParser.getDurationMillis(KEY_SENSING_TIMEOUT, !DEBUG ? 4 * 60 * 1000L : 60 * 1000L); !COMPRESS_TIME ? 4 * 60 * 1000L : 60 * 1000L); LOCATING_TIMEOUT = mParser.getDurationMillis(KEY_LOCATING_TIMEOUT, !DEBUG ? 30 * 1000L : 15 * 1000L); !COMPRESS_TIME ? 30 * 1000L : 15 * 1000L); LOCATION_ACCURACY = mParser.getFloat(KEY_LOCATION_ACCURACY, 20); MOTION_INACTIVE_TIMEOUT = mParser.getDurationMillis(KEY_MOTION_INACTIVE_TIMEOUT, !COMPRESS_TIME ? 10 * 60 * 1000L : 60 * 1000L); Loading Loading @@ -1562,6 +1562,7 @@ public class DeviceIdleController extends SystemService static class Injector { private final Context mContext; private ConnectivityService mConnectivityService; private Constants mConstants; private LocationManager mLocationManager; Injector(Context ctx) { Loading Loading @@ -1591,7 +1592,10 @@ public class DeviceIdleController extends SystemService Constants getConstants(DeviceIdleController controller, Handler handler, ContentResolver resolver) { return controller.new Constants(handler, resolver); if (mConstants == null) { mConstants = controller.new Constants(handler, resolver); } return mConstants; } LocationManager getLocationManager() { Loading services/tests/mockingservicestests/src/com/android/server/DeviceIdleControllerTest.java +15 −10 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; Loading Loading @@ -89,6 +90,7 @@ public class DeviceIdleControllerTest { private DeviceIdleController mDeviceIdleController; private AnyMotionDetectorForTest mAnyMotionDetector; private AppStateTrackerForTest mAppStateTracker; private DeviceIdleController.Constants mConstants; private InjectorForTest mInjector; private MockitoSession mMockingSession; Loading @@ -97,7 +99,7 @@ public class DeviceIdleControllerTest { @Mock private ConnectivityService mConnectivityService; @Mock private DeviceIdleController.Constants mConstants; private ContentResolver mContentResolver; @Mock private IActivityManager mIActivityManager; @Mock Loading Loading @@ -138,13 +140,6 @@ public class DeviceIdleControllerTest { return connectivityService; } @Override DeviceIdleController.Constants getConstants(DeviceIdleController controller, Handler handler, ContentResolver resolver) { return mConstants; } @Override LocationManager getLocationManager() { return locationManager; Loading @@ -169,6 +164,11 @@ public class DeviceIdleControllerTest { mock(DeviceIdleCallback.class), 0.5f); } @Override public boolean hasSensor() { return true; } @Override public void checkForAnyMotion() { isMonitoring = true; Loading Loading @@ -221,6 +221,7 @@ public class DeviceIdleControllerTest { mAppStateTracker = new AppStateTrackerForTest(getContext(), Looper.getMainLooper()); mAnyMotionDetector = new AnyMotionDetectorForTest(); mInjector = new InjectorForTest(getContext()); doNothing().when(mContentResolver).registerContentObserver(any(), anyBoolean(), any()); mDeviceIdleController = new DeviceIdleController(getContext(), mInjector); spyOn(mDeviceIdleController); doNothing().when(mDeviceIdleController).publishBinderService(any(), any()); Loading @@ -228,6 +229,10 @@ public class DeviceIdleControllerTest { mDeviceIdleController.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY); mDeviceIdleController.setDeepEnabledForTest(true); mDeviceIdleController.setLightEnabledForTest(true); // Get the same Constants object that mDeviceIdleController got. mConstants = mInjector.getConstants(mDeviceIdleController, mInjector.getHandler(mDeviceIdleController), mContentResolver); } @After Loading Loading @@ -1456,8 +1461,8 @@ public class DeviceIdleControllerTest { private void setAlarmSoon(boolean isSoon) { if (isSoon) { doReturn(SystemClock.elapsedRealtime() + mConstants.MIN_TIME_TO_ALARM / 2).when( mAlarmManager).getNextWakeFromIdleTime(); doReturn(SystemClock.elapsedRealtime() + mConstants.MIN_TIME_TO_ALARM / 2) .when(mAlarmManager).getNextWakeFromIdleTime(); } else { doReturn(Long.MAX_VALUE).when(mAlarmManager).getNextWakeFromIdleTime(); } Loading Loading
services/core/java/com/android/server/DeviceIdleController.java +7 −3 Original line number Diff line number Diff line Loading @@ -1031,9 +1031,9 @@ public class DeviceIdleController extends SystemService INACTIVE_TIMEOUT = mParser.getDurationMillis(KEY_INACTIVE_TIMEOUT, !COMPRESS_TIME ? inactiveTimeoutDefault : (inactiveTimeoutDefault / 10)); SENSING_TIMEOUT = mParser.getDurationMillis(KEY_SENSING_TIMEOUT, !DEBUG ? 4 * 60 * 1000L : 60 * 1000L); !COMPRESS_TIME ? 4 * 60 * 1000L : 60 * 1000L); LOCATING_TIMEOUT = mParser.getDurationMillis(KEY_LOCATING_TIMEOUT, !DEBUG ? 30 * 1000L : 15 * 1000L); !COMPRESS_TIME ? 30 * 1000L : 15 * 1000L); LOCATION_ACCURACY = mParser.getFloat(KEY_LOCATION_ACCURACY, 20); MOTION_INACTIVE_TIMEOUT = mParser.getDurationMillis(KEY_MOTION_INACTIVE_TIMEOUT, !COMPRESS_TIME ? 10 * 60 * 1000L : 60 * 1000L); Loading Loading @@ -1562,6 +1562,7 @@ public class DeviceIdleController extends SystemService static class Injector { private final Context mContext; private ConnectivityService mConnectivityService; private Constants mConstants; private LocationManager mLocationManager; Injector(Context ctx) { Loading Loading @@ -1591,7 +1592,10 @@ public class DeviceIdleController extends SystemService Constants getConstants(DeviceIdleController controller, Handler handler, ContentResolver resolver) { return controller.new Constants(handler, resolver); if (mConstants == null) { mConstants = controller.new Constants(handler, resolver); } return mConstants; } LocationManager getLocationManager() { Loading
services/tests/mockingservicestests/src/com/android/server/DeviceIdleControllerTest.java +15 −10 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; Loading Loading @@ -89,6 +90,7 @@ public class DeviceIdleControllerTest { private DeviceIdleController mDeviceIdleController; private AnyMotionDetectorForTest mAnyMotionDetector; private AppStateTrackerForTest mAppStateTracker; private DeviceIdleController.Constants mConstants; private InjectorForTest mInjector; private MockitoSession mMockingSession; Loading @@ -97,7 +99,7 @@ public class DeviceIdleControllerTest { @Mock private ConnectivityService mConnectivityService; @Mock private DeviceIdleController.Constants mConstants; private ContentResolver mContentResolver; @Mock private IActivityManager mIActivityManager; @Mock Loading Loading @@ -138,13 +140,6 @@ public class DeviceIdleControllerTest { return connectivityService; } @Override DeviceIdleController.Constants getConstants(DeviceIdleController controller, Handler handler, ContentResolver resolver) { return mConstants; } @Override LocationManager getLocationManager() { return locationManager; Loading @@ -169,6 +164,11 @@ public class DeviceIdleControllerTest { mock(DeviceIdleCallback.class), 0.5f); } @Override public boolean hasSensor() { return true; } @Override public void checkForAnyMotion() { isMonitoring = true; Loading Loading @@ -221,6 +221,7 @@ public class DeviceIdleControllerTest { mAppStateTracker = new AppStateTrackerForTest(getContext(), Looper.getMainLooper()); mAnyMotionDetector = new AnyMotionDetectorForTest(); mInjector = new InjectorForTest(getContext()); doNothing().when(mContentResolver).registerContentObserver(any(), anyBoolean(), any()); mDeviceIdleController = new DeviceIdleController(getContext(), mInjector); spyOn(mDeviceIdleController); doNothing().when(mDeviceIdleController).publishBinderService(any(), any()); Loading @@ -228,6 +229,10 @@ public class DeviceIdleControllerTest { mDeviceIdleController.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY); mDeviceIdleController.setDeepEnabledForTest(true); mDeviceIdleController.setLightEnabledForTest(true); // Get the same Constants object that mDeviceIdleController got. mConstants = mInjector.getConstants(mDeviceIdleController, mInjector.getHandler(mDeviceIdleController), mContentResolver); } @After Loading Loading @@ -1456,8 +1461,8 @@ public class DeviceIdleControllerTest { private void setAlarmSoon(boolean isSoon) { if (isSoon) { doReturn(SystemClock.elapsedRealtime() + mConstants.MIN_TIME_TO_ALARM / 2).when( mAlarmManager).getNextWakeFromIdleTime(); doReturn(SystemClock.elapsedRealtime() + mConstants.MIN_TIME_TO_ALARM / 2) .when(mAlarmManager).getNextWakeFromIdleTime(); } else { doReturn(Long.MAX_VALUE).when(mAlarmManager).getNextWakeFromIdleTime(); } Loading