summaryrefslogtreecommitdiff
path: root/services/robotests/src
diff options
context:
space:
mode:
author Neil Fuller <nfuller@google.com> 2022-12-13 14:49:06 +0000
committer Neil Fuller <nfuller@google.com> 2023-01-19 14:08:46 +0000
commit8ad07e271f1acb30746502fd69a9d6260832f877 (patch)
tree37b28d853051d2f0e5c2887886cf1ccbfb9820bc /services/robotests/src
parentb9080f55eeed808eaa29879d9da20ca737399a82 (diff)
Refactoring: Support alt. network time source
Refactoring to support an alternative source of network time for passing to the GNSS component. The new implementation will be submitted in a follow-up. NtpTimeHelper has been replaced by NetworkTimeHelper in GnssLocationProvider. NetworkTimeHelper provides the stable interface between GnssLocationProvider and the original / alternative impl for what was NtpTimeHelper. NtpTimeHelper has been renamed NtpNetworkTimeHelper. These changes are not intended to change any behavior. There are some minor changes between the interaction between GnssLocationProvider and the NetworkTimeHelper class, but these are not expected to alter the runtime behavior. The NetworkTimeHelper.setPeriodicTimeInjectionMode() method touches a pre-existing bug: The method name reflected the effect of the method, which is the near-opposite of what the capability name would suggest. This appears to be due to an accidental logic inversion, not by intent. As can be seen in the changes for GnssLocationProvider: the enablePeriodicTimeInjection() method was called when mGnssNative.getCapabilities().hasOnDemandTime() was true. The existence of bug 73893222 supports the fact that there is a long-standing bug here. The intent with this commit is not to fix it or alter behavior, just to make it more obvious, as it is unclear if the current behavior is relied upon somewhere. Comments and field names have been improved to try to clarify the actual behavior. Bug: 73893222 Bug: 222295093 Test: atest services/robotests/src/com/android/server/location/gnss/NtpNetworkTimeHelperTest.java Change-Id: I0b1ba43a55ff531df343c022650e3f5721dda7f1
Diffstat (limited to 'services/robotests/src')
-rw-r--r--services/robotests/src/com/android/server/location/gnss/NtpNetworkTimeHelperTest.java (renamed from services/robotests/src/com/android/server/location/gnss/NtpTimeHelperTest.java)30
1 files changed, 15 insertions, 15 deletions
diff --git a/services/robotests/src/com/android/server/location/gnss/NtpTimeHelperTest.java b/services/robotests/src/com/android/server/location/gnss/NtpNetworkTimeHelperTest.java
index e5a1cfeb55c2..4949091646dd 100644
--- a/services/robotests/src/com/android/server/location/gnss/NtpTimeHelperTest.java
+++ b/services/robotests/src/com/android/server/location/gnss/NtpNetworkTimeHelperTest.java
@@ -26,7 +26,7 @@ import android.os.SystemClock;
import android.platform.test.annotations.Presubmit;
import android.util.NtpTrustedTime;
-import com.android.server.location.gnss.NtpTimeHelper.InjectNtpTimeCallback;
+import com.android.server.location.gnss.NetworkTimeHelper.InjectTimeCallback;
import org.junit.Before;
import org.junit.Test;
@@ -41,16 +41,16 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
/**
- * Unit tests for {@link NtpTimeHelper}.
+ * Unit tests for {@link NtpNetworkTimeHelper}.
*/
@RunWith(RobolectricTestRunner.class)
@Presubmit
-public class NtpTimeHelperTest {
+public class NtpNetworkTimeHelperTest {
private static final long MOCK_NTP_TIME = 1519930775453L;
@Mock
private NtpTrustedTime mMockNtpTrustedTime;
- private NtpTimeHelper mNtpTimeHelper;
+ private NtpNetworkTimeHelper mNtpNetworkTimeHelper;
private CountDownLatch mCountDownLatch;
/**
@@ -60,12 +60,12 @@ public class NtpTimeHelperTest {
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mCountDownLatch = new CountDownLatch(1);
- InjectNtpTimeCallback callback =
+ InjectTimeCallback callback =
(time, timeReference, uncertainty) -> {
assertThat(time).isEqualTo(MOCK_NTP_TIME);
mCountDownLatch.countDown();
};
- mNtpTimeHelper = new NtpTimeHelper(RuntimeEnvironment.application,
+ mNtpNetworkTimeHelper = new NtpNetworkTimeHelper(RuntimeEnvironment.application,
Looper.myLooper(),
callback, mMockNtpTrustedTime);
}
@@ -74,13 +74,13 @@ public class NtpTimeHelperTest {
* Verify that cached time is returned if cached age is low.
*/
@Test
- public void handleInjectNtpTime_cachedAgeLow_injectTime() throws InterruptedException {
+ public void demandUtcTimeInjection_cachedAgeLow_injectTime() throws InterruptedException {
NtpTrustedTime.TimeResult result = mock(NtpTrustedTime.TimeResult.class);
- doReturn(NtpTimeHelper.NTP_INTERVAL - 1).when(result).getAgeMillis();
+ doReturn(NtpNetworkTimeHelper.NTP_INTERVAL - 1).when(result).getAgeMillis();
doReturn(MOCK_NTP_TIME).when(result).getTimeMillis();
doReturn(result).when(mMockNtpTrustedTime).getCachedTimeResult();
- mNtpTimeHelper.retrieveAndInjectNtpTime();
+ mNtpNetworkTimeHelper.demandUtcTimeInjection();
waitForTasksToBePostedOnHandlerAndRunThem();
assertThat(mCountDownLatch.await(2, TimeUnit.SECONDS)).isTrue();
@@ -90,14 +90,14 @@ public class NtpTimeHelperTest {
* Verify that failed inject time and delayed inject time are handled properly.
*/
@Test
- public void handleInjectNtpTime_injectTimeFailed_injectTimeDelayed()
+ public void demandUtcTimeInjection_injectTimeFailed_injectTimeDelayed()
throws InterruptedException {
NtpTrustedTime.TimeResult result1 = mock(NtpTrustedTime.TimeResult.class);
- doReturn(NtpTimeHelper.NTP_INTERVAL + 1).when(result1).getAgeMillis();
+ doReturn(NtpNetworkTimeHelper.NTP_INTERVAL + 1).when(result1).getAgeMillis();
doReturn(result1).when(mMockNtpTrustedTime).getCachedTimeResult();
doReturn(false).when(mMockNtpTrustedTime).forceRefresh();
- mNtpTimeHelper.retrieveAndInjectNtpTime();
+ mNtpNetworkTimeHelper.demandUtcTimeInjection();
waitForTasksToBePostedOnHandlerAndRunThem();
assertThat(mCountDownLatch.await(2, TimeUnit.SECONDS)).isFalse();
@@ -106,15 +106,15 @@ public class NtpTimeHelperTest {
doReturn(1L).when(result2).getAgeMillis();
doReturn(MOCK_NTP_TIME).when(result2).getTimeMillis();
doReturn(result2).when(mMockNtpTrustedTime).getCachedTimeResult();
- SystemClock.sleep(NtpTimeHelper.RETRY_INTERVAL);
+ SystemClock.sleep(NtpNetworkTimeHelper.RETRY_INTERVAL);
waitForTasksToBePostedOnHandlerAndRunThem();
assertThat(mCountDownLatch.await(2, TimeUnit.SECONDS)).isTrue();
}
/**
- * Since a thread is created in {@link NtpTimeHelper#retrieveAndInjectNtpTime} and the task to
- * be verified is posted in the thread, we have to wait for the task to be posted and then it
+ * Since a thread is created in {@link NtpNetworkTimeHelper#demandUtcTimeInjection} and the task
+ * to be verified is posted in the thread, we have to wait for the task to be posted and then it
* can be run.
*/
private void waitForTasksToBePostedOnHandlerAndRunThem() throws InterruptedException {