Loading core/java/android/app/time/UnixEpochTime.java +1 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ public final class UnixEpochTime implements Parcelable { @Override public String toString() { return "UnixEpochTime{" + "mElapsedRealtimeTimeMillis=" + mElapsedRealtimeMillis + "mElapsedRealtimeMillis=" + mElapsedRealtimeMillis + ", mUnixEpochTimeMillis=" + mUnixEpochTimeMillis + '}'; } Loading core/java/android/app/timedetector/TimeDetector.java +12 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,18 @@ public interface TimeDetector { */ String SHELL_COMMAND_SUGGEST_NETWORK_TIME = "suggest_network_time"; /** * A shell command that prints the current network time information. * @hide */ String SHELL_COMMAND_GET_NETWORK_TIME = "get_network_time"; /** * A shell command that clears the detector's network time information. * @hide */ String SHELL_COMMAND_CLEAR_NETWORK_TIME = "clear_network_time"; /** * A shell command that injects a GNSS time suggestion. * @hide Loading services/core/java/com/android/server/timedetector/TimeDetectorService.java +32 −2 Original line number Diff line number Diff line Loading @@ -143,7 +143,7 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub return getTimeCapabilitiesAndConfig(userId); } TimeCapabilitiesAndConfig getTimeCapabilitiesAndConfig(@UserIdInt int userId) { private TimeCapabilitiesAndConfig getTimeCapabilitiesAndConfig(@UserIdInt int userId) { enforceManageTimeDetectorPermission(); final long token = mCallerIdentityInjector.clearCallingIdentity(); Loading @@ -163,6 +163,9 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub return updateConfiguration(callingUserId, configuration); } /** * Updates the user's configuration. Exposed for use by {@link TimeDetectorShellCommand}. */ boolean updateConfiguration(@UserIdInt int userId, @NonNull TimeConfiguration configuration) { // Resolve constants like USER_CURRENT to the true user ID as needed. int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Loading Loading @@ -256,7 +259,7 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub } } void handleConfigurationInternalChangedOnHandlerThread() { private void handleConfigurationInternalChangedOnHandlerThread() { // Configuration has changed, but each user may have a different view of the configuration. // It's possible that this will cause unnecessary notifications but that shouldn't be a // problem. Loading Loading @@ -287,6 +290,10 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub } } /** * Sets the system time state. See {@link TimeState} for details. For use by {@link * TimeDetectorShellCommand}. */ void setTimeState(@NonNull TimeState timeState) { enforceManageTimeDetectorPermission(); Loading Loading @@ -353,6 +360,9 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub } } /** * Suggests network time with permission checks. For use by {@link TimeDetectorShellCommand}. */ void suggestNetworkTime(@NonNull NetworkTimeSuggestion timeSignal) { enforceSuggestNetworkTimePermission(); Objects.requireNonNull(timeSignal); Loading @@ -360,6 +370,23 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub mHandler.post(() -> mTimeDetectorStrategy.suggestNetworkTime(timeSignal)); } /** * Clears the cached network time information. For use during tests to simulate when no network * time has been made available. For use by {@link TimeDetectorShellCommand}. * * <p>This operation takes place in the calling thread. */ void clearNetworkTime() { enforceSuggestNetworkTimePermission(); final long token = Binder.clearCallingIdentity(); try { mTimeDetectorStrategy.clearLatestNetworkSuggestion(); } finally { Binder.restoreCallingIdentity(token); } } @Override public UnixEpochTime latestNetworkTime() { NetworkTimeSuggestion suggestion = getLatestNetworkSuggestion(); Loading Loading @@ -388,6 +415,9 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub } } /** * Suggests GNSS time with permission checks. For use by {@link TimeDetectorShellCommand}. */ void suggestGnssTime(@NonNull GnssTimeSuggestion timeSignal) { enforceSuggestGnssTimePermission(); Objects.requireNonNull(timeSignal); Loading services/core/java/com/android/server/timedetector/TimeDetectorShellCommand.java +22 −0 Original line number Diff line number Diff line Loading @@ -15,7 +15,9 @@ */ package com.android.server.timedetector; import static android.app.timedetector.TimeDetector.SHELL_COMMAND_CLEAR_NETWORK_TIME; import static android.app.timedetector.TimeDetector.SHELL_COMMAND_CONFIRM_TIME; import static android.app.timedetector.TimeDetector.SHELL_COMMAND_GET_NETWORK_TIME; import static android.app.timedetector.TimeDetector.SHELL_COMMAND_GET_TIME_STATE; import static android.app.timedetector.TimeDetector.SHELL_COMMAND_IS_AUTO_DETECTION_ENABLED; import static android.app.timedetector.TimeDetector.SHELL_COMMAND_SERVICE_NAME; Loading Loading @@ -70,6 +72,10 @@ class TimeDetectorShellCommand extends ShellCommand { return runSuggestTelephonyTime(); case SHELL_COMMAND_SUGGEST_NETWORK_TIME: return runSuggestNetworkTime(); case SHELL_COMMAND_GET_NETWORK_TIME: return runGetNetworkTime(); case SHELL_COMMAND_CLEAR_NETWORK_TIME: return runClearNetworkTime(); case SHELL_COMMAND_SUGGEST_GNSS_TIME: return runSuggestGnssTime(); case SHELL_COMMAND_SUGGEST_EXTERNAL_TIME: Loading Loading @@ -122,6 +128,18 @@ class TimeDetectorShellCommand extends ShellCommand { mInterface::suggestNetworkTime); } private int runGetNetworkTime() { NetworkTimeSuggestion networkTimeSuggestion = mInterface.getLatestNetworkSuggestion(); final PrintWriter pw = getOutPrintWriter(); pw.println(networkTimeSuggestion); return 0; } private int runClearNetworkTime() { mInterface.clearNetworkTime(); return 0; } private int runSuggestGnssTime() { return runSuggestTime( () -> GnssTimeSuggestion.parseCommandLineArg(this), Loading Loading @@ -196,6 +214,10 @@ class TimeDetectorShellCommand extends ShellCommand { pw.printf(" Sets the current time state for tests.\n"); pw.printf(" %s <unix epoch time options>\n", SHELL_COMMAND_CONFIRM_TIME); pw.printf(" Tries to confirms the time, raising the confidence.\n"); pw.printf(" %s\n", SHELL_COMMAND_GET_NETWORK_TIME); pw.printf(" Prints the network time information held by the detector.\n"); pw.printf(" %s\n", SHELL_COMMAND_CLEAR_NETWORK_TIME); pw.printf(" Clears the network time information held by the detector.\n"); pw.println(); ManualTimeSuggestion.printCommandLineOpts(pw); pw.println(); Loading services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java +15 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.timedetector; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.time.ExternalTimeSuggestion; import android.app.time.TimeState; Loading Loading @@ -103,6 +104,20 @@ public interface TimeDetectorStrategy extends Dumpable { /** Processes the suggested time from network sources. */ void suggestNetworkTime(@NonNull NetworkTimeSuggestion timeSuggestion); /** * Returns the latest (accepted) network time suggestion. Returns {@code null} if there isn't * one. */ @Nullable NetworkTimeSuggestion getLatestNetworkSuggestion(); /** * Clears the latest network time suggestion, leaving none. The remaining time signals from * other sources will be reassessed causing the device's time to be updated if config and * settings allow. */ void clearLatestNetworkSuggestion(); /** Processes the suggested time from gnss sources. */ void suggestGnssTime(@NonNull GnssTimeSuggestion timeSuggestion); Loading Loading
core/java/android/app/time/UnixEpochTime.java +1 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ public final class UnixEpochTime implements Parcelable { @Override public String toString() { return "UnixEpochTime{" + "mElapsedRealtimeTimeMillis=" + mElapsedRealtimeMillis + "mElapsedRealtimeMillis=" + mElapsedRealtimeMillis + ", mUnixEpochTimeMillis=" + mUnixEpochTimeMillis + '}'; } Loading
core/java/android/app/timedetector/TimeDetector.java +12 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,18 @@ public interface TimeDetector { */ String SHELL_COMMAND_SUGGEST_NETWORK_TIME = "suggest_network_time"; /** * A shell command that prints the current network time information. * @hide */ String SHELL_COMMAND_GET_NETWORK_TIME = "get_network_time"; /** * A shell command that clears the detector's network time information. * @hide */ String SHELL_COMMAND_CLEAR_NETWORK_TIME = "clear_network_time"; /** * A shell command that injects a GNSS time suggestion. * @hide Loading
services/core/java/com/android/server/timedetector/TimeDetectorService.java +32 −2 Original line number Diff line number Diff line Loading @@ -143,7 +143,7 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub return getTimeCapabilitiesAndConfig(userId); } TimeCapabilitiesAndConfig getTimeCapabilitiesAndConfig(@UserIdInt int userId) { private TimeCapabilitiesAndConfig getTimeCapabilitiesAndConfig(@UserIdInt int userId) { enforceManageTimeDetectorPermission(); final long token = mCallerIdentityInjector.clearCallingIdentity(); Loading @@ -163,6 +163,9 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub return updateConfiguration(callingUserId, configuration); } /** * Updates the user's configuration. Exposed for use by {@link TimeDetectorShellCommand}. */ boolean updateConfiguration(@UserIdInt int userId, @NonNull TimeConfiguration configuration) { // Resolve constants like USER_CURRENT to the true user ID as needed. int resolvedUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Loading Loading @@ -256,7 +259,7 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub } } void handleConfigurationInternalChangedOnHandlerThread() { private void handleConfigurationInternalChangedOnHandlerThread() { // Configuration has changed, but each user may have a different view of the configuration. // It's possible that this will cause unnecessary notifications but that shouldn't be a // problem. Loading Loading @@ -287,6 +290,10 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub } } /** * Sets the system time state. See {@link TimeState} for details. For use by {@link * TimeDetectorShellCommand}. */ void setTimeState(@NonNull TimeState timeState) { enforceManageTimeDetectorPermission(); Loading Loading @@ -353,6 +360,9 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub } } /** * Suggests network time with permission checks. For use by {@link TimeDetectorShellCommand}. */ void suggestNetworkTime(@NonNull NetworkTimeSuggestion timeSignal) { enforceSuggestNetworkTimePermission(); Objects.requireNonNull(timeSignal); Loading @@ -360,6 +370,23 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub mHandler.post(() -> mTimeDetectorStrategy.suggestNetworkTime(timeSignal)); } /** * Clears the cached network time information. For use during tests to simulate when no network * time has been made available. For use by {@link TimeDetectorShellCommand}. * * <p>This operation takes place in the calling thread. */ void clearNetworkTime() { enforceSuggestNetworkTimePermission(); final long token = Binder.clearCallingIdentity(); try { mTimeDetectorStrategy.clearLatestNetworkSuggestion(); } finally { Binder.restoreCallingIdentity(token); } } @Override public UnixEpochTime latestNetworkTime() { NetworkTimeSuggestion suggestion = getLatestNetworkSuggestion(); Loading Loading @@ -388,6 +415,9 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub } } /** * Suggests GNSS time with permission checks. For use by {@link TimeDetectorShellCommand}. */ void suggestGnssTime(@NonNull GnssTimeSuggestion timeSignal) { enforceSuggestGnssTimePermission(); Objects.requireNonNull(timeSignal); Loading
services/core/java/com/android/server/timedetector/TimeDetectorShellCommand.java +22 −0 Original line number Diff line number Diff line Loading @@ -15,7 +15,9 @@ */ package com.android.server.timedetector; import static android.app.timedetector.TimeDetector.SHELL_COMMAND_CLEAR_NETWORK_TIME; import static android.app.timedetector.TimeDetector.SHELL_COMMAND_CONFIRM_TIME; import static android.app.timedetector.TimeDetector.SHELL_COMMAND_GET_NETWORK_TIME; import static android.app.timedetector.TimeDetector.SHELL_COMMAND_GET_TIME_STATE; import static android.app.timedetector.TimeDetector.SHELL_COMMAND_IS_AUTO_DETECTION_ENABLED; import static android.app.timedetector.TimeDetector.SHELL_COMMAND_SERVICE_NAME; Loading Loading @@ -70,6 +72,10 @@ class TimeDetectorShellCommand extends ShellCommand { return runSuggestTelephonyTime(); case SHELL_COMMAND_SUGGEST_NETWORK_TIME: return runSuggestNetworkTime(); case SHELL_COMMAND_GET_NETWORK_TIME: return runGetNetworkTime(); case SHELL_COMMAND_CLEAR_NETWORK_TIME: return runClearNetworkTime(); case SHELL_COMMAND_SUGGEST_GNSS_TIME: return runSuggestGnssTime(); case SHELL_COMMAND_SUGGEST_EXTERNAL_TIME: Loading Loading @@ -122,6 +128,18 @@ class TimeDetectorShellCommand extends ShellCommand { mInterface::suggestNetworkTime); } private int runGetNetworkTime() { NetworkTimeSuggestion networkTimeSuggestion = mInterface.getLatestNetworkSuggestion(); final PrintWriter pw = getOutPrintWriter(); pw.println(networkTimeSuggestion); return 0; } private int runClearNetworkTime() { mInterface.clearNetworkTime(); return 0; } private int runSuggestGnssTime() { return runSuggestTime( () -> GnssTimeSuggestion.parseCommandLineArg(this), Loading Loading @@ -196,6 +214,10 @@ class TimeDetectorShellCommand extends ShellCommand { pw.printf(" Sets the current time state for tests.\n"); pw.printf(" %s <unix epoch time options>\n", SHELL_COMMAND_CONFIRM_TIME); pw.printf(" Tries to confirms the time, raising the confidence.\n"); pw.printf(" %s\n", SHELL_COMMAND_GET_NETWORK_TIME); pw.printf(" Prints the network time information held by the detector.\n"); pw.printf(" %s\n", SHELL_COMMAND_CLEAR_NETWORK_TIME); pw.printf(" Clears the network time information held by the detector.\n"); pw.println(); ManualTimeSuggestion.printCommandLineOpts(pw); pw.println(); Loading
services/core/java/com/android/server/timedetector/TimeDetectorStrategy.java +15 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.timedetector; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; import android.app.time.ExternalTimeSuggestion; import android.app.time.TimeState; Loading Loading @@ -103,6 +104,20 @@ public interface TimeDetectorStrategy extends Dumpable { /** Processes the suggested time from network sources. */ void suggestNetworkTime(@NonNull NetworkTimeSuggestion timeSuggestion); /** * Returns the latest (accepted) network time suggestion. Returns {@code null} if there isn't * one. */ @Nullable NetworkTimeSuggestion getLatestNetworkSuggestion(); /** * Clears the latest network time suggestion, leaving none. The remaining time signals from * other sources will be reassessed causing the device's time to be updated if config and * settings allow. */ void clearLatestNetworkSuggestion(); /** Processes the suggested time from gnss sources. */ void suggestGnssTime(@NonNull GnssTimeSuggestion timeSuggestion); Loading