Loading core/java/android/os/SystemClock.java +31 −36 Original line number Diff line number Diff line Loading @@ -109,6 +109,7 @@ public final class SystemClock { private static final String TAG = "SystemClock"; private static volatile IAlarmManager sIAlarmManager; private static volatile ITimeDetectorService sITimeDetectorService; /** * Since {@code nanoTime()} is arbitrary, anchor our Ravenwood clocks against it. Loading Loading @@ -188,6 +189,14 @@ public final class SystemClock { return sIAlarmManager; } private static ITimeDetectorService getITimeDetectorService() { if (sITimeDetectorService == null) { sITimeDetectorService = ITimeDetectorService.Stub .asInterface(ServiceManager.getService(Context.TIME_DETECTOR_SERVICE)); } return sITimeDetectorService; } /** * Returns milliseconds since boot, not counting time spent in deep sleep. * Loading Loading @@ -313,15 +322,6 @@ public final class SystemClock { return System.nanoTime() / 1000L; } /** * @see #currentNetworkTimeMillis(ITimeDetectorService) * @hide */ public static long currentNetworkTimeMillis() { return currentNetworkTimeMillis(ITimeDetectorService.Stub .asInterface(ServiceManager.getService(Context.TIME_DETECTOR_SERVICE))); } /** * Returns milliseconds since January 1, 1970 00:00:00.0 UTC, synchronized * using a remote network source outside the device. Loading @@ -346,9 +346,12 @@ public final class SystemClock { * @throws DateTimeException when no network time can be provided. * @hide */ public static long currentNetworkTimeMillis( ITimeDetectorService timeDetectorService) { if (timeDetectorService != null) { public static long currentNetworkTimeMillis() { ITimeDetectorService timeDetectorService = getITimeDetectorService(); if (timeDetectorService == null) { throw new RuntimeException(new DeadSystemException()); } UnixEpochTime time; try { time = timeDetectorService.latestNetworkTime(); Loading @@ -358,17 +361,14 @@ public final class SystemClock { } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } if (time == null) { // This is not expected. throw new DateTimeException("Network based time is not available."); } long currentMillis = elapsedRealtime(); long deltaMs = currentMillis - time.getElapsedRealtimeMillis(); return time.getUnixEpochTimeMillis() + deltaMs; } else { throw new RuntimeException(new DeadSystemException()); } } /** Loading Loading @@ -396,14 +396,9 @@ public final class SystemClock { */ public static @NonNull Clock currentNetworkTimeClock() { return new SimpleClock(ZoneOffset.UTC) { private ITimeDetectorService mSvc; @Override public long millis() { if (mSvc == null) { mSvc = ITimeDetectorService.Stub .asInterface(ServiceManager.getService(Context.TIME_DETECTOR_SERVICE)); } return SystemClock.currentNetworkTimeMillis(mSvc); return SystemClock.currentNetworkTimeMillis(); } }; } Loading Loading
core/java/android/os/SystemClock.java +31 −36 Original line number Diff line number Diff line Loading @@ -109,6 +109,7 @@ public final class SystemClock { private static final String TAG = "SystemClock"; private static volatile IAlarmManager sIAlarmManager; private static volatile ITimeDetectorService sITimeDetectorService; /** * Since {@code nanoTime()} is arbitrary, anchor our Ravenwood clocks against it. Loading Loading @@ -188,6 +189,14 @@ public final class SystemClock { return sIAlarmManager; } private static ITimeDetectorService getITimeDetectorService() { if (sITimeDetectorService == null) { sITimeDetectorService = ITimeDetectorService.Stub .asInterface(ServiceManager.getService(Context.TIME_DETECTOR_SERVICE)); } return sITimeDetectorService; } /** * Returns milliseconds since boot, not counting time spent in deep sleep. * Loading Loading @@ -313,15 +322,6 @@ public final class SystemClock { return System.nanoTime() / 1000L; } /** * @see #currentNetworkTimeMillis(ITimeDetectorService) * @hide */ public static long currentNetworkTimeMillis() { return currentNetworkTimeMillis(ITimeDetectorService.Stub .asInterface(ServiceManager.getService(Context.TIME_DETECTOR_SERVICE))); } /** * Returns milliseconds since January 1, 1970 00:00:00.0 UTC, synchronized * using a remote network source outside the device. Loading @@ -346,9 +346,12 @@ public final class SystemClock { * @throws DateTimeException when no network time can be provided. * @hide */ public static long currentNetworkTimeMillis( ITimeDetectorService timeDetectorService) { if (timeDetectorService != null) { public static long currentNetworkTimeMillis() { ITimeDetectorService timeDetectorService = getITimeDetectorService(); if (timeDetectorService == null) { throw new RuntimeException(new DeadSystemException()); } UnixEpochTime time; try { time = timeDetectorService.latestNetworkTime(); Loading @@ -358,17 +361,14 @@ public final class SystemClock { } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } if (time == null) { // This is not expected. throw new DateTimeException("Network based time is not available."); } long currentMillis = elapsedRealtime(); long deltaMs = currentMillis - time.getElapsedRealtimeMillis(); return time.getUnixEpochTimeMillis() + deltaMs; } else { throw new RuntimeException(new DeadSystemException()); } } /** Loading Loading @@ -396,14 +396,9 @@ public final class SystemClock { */ public static @NonNull Clock currentNetworkTimeClock() { return new SimpleClock(ZoneOffset.UTC) { private ITimeDetectorService mSvc; @Override public long millis() { if (mSvc == null) { mSvc = ITimeDetectorService.Stub .asInterface(ServiceManager.getService(Context.TIME_DETECTOR_SERVICE)); } return SystemClock.currentNetworkTimeMillis(mSvc); return SystemClock.currentNetworkTimeMillis(); } }; } Loading