1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.app.timedetector; 18 19 import android.annotation.NonNull; 20 import android.annotation.RequiresPermission; 21 import android.annotation.SystemService; 22 import android.app.time.UnixEpochTime; 23 import android.content.Context; 24 import android.os.SystemClock; 25 26 /** 27 * The interface through which system components can query and send signals to the 28 * TimeDetectorService. 29 * 30 * <p>SDK APIs are exposed on {@link android.app.time.TimeManager} to obscure the internal split 31 * between time and time zone detection services. Migrate APIs there if they need to be part of an 32 * SDK API. 33 * 34 * @hide 35 */ 36 @SystemService(Context.TIME_DETECTOR_SERVICE) 37 public interface TimeDetector { 38 39 /** 40 * The name of the service for shell commands. 41 * @hide 42 */ 43 String SHELL_COMMAND_SERVICE_NAME = "time_detector"; 44 45 /** 46 * A shell command that prints the current "auto time detection" global setting value. 47 * @hide 48 */ 49 String SHELL_COMMAND_IS_AUTO_DETECTION_ENABLED = "is_auto_detection_enabled"; 50 51 /** 52 * A shell command that sets the current "auto time detection" global setting value. 53 * @hide 54 */ 55 String SHELL_COMMAND_SET_AUTO_DETECTION_ENABLED = "set_auto_detection_enabled"; 56 57 /** 58 * A shell command that injects a manual time suggestion. 59 * @hide 60 */ 61 String SHELL_COMMAND_SUGGEST_MANUAL_TIME = "suggest_manual_time"; 62 63 /** 64 * A shell command that injects a telephony time suggestion. 65 * @hide 66 */ 67 String SHELL_COMMAND_SUGGEST_TELEPHONY_TIME = "suggest_telephony_time"; 68 69 /** 70 * A shell command that injects a network time suggestion. 71 * @hide 72 */ 73 String SHELL_COMMAND_SUGGEST_NETWORK_TIME = "suggest_network_time"; 74 75 /** 76 * A shell command that prints the current network time information. 77 * @hide 78 */ 79 String SHELL_COMMAND_GET_NETWORK_TIME = "get_network_time"; 80 81 /** 82 * A shell command that clears the detector's network time information. 83 * @hide 84 */ 85 String SHELL_COMMAND_CLEAR_NETWORK_TIME = "clear_network_time"; 86 87 /** 88 * A shell command that injects a GNSS time suggestion. 89 * @hide 90 */ 91 String SHELL_COMMAND_SUGGEST_GNSS_TIME = "suggest_gnss_time"; 92 93 /** 94 * A shell command that injects a external time suggestion. 95 * @hide 96 */ 97 String SHELL_COMMAND_SUGGEST_EXTERNAL_TIME = "suggest_external_time"; 98 99 /** 100 * A shell command that retrieves the current system clock time state. 101 * @hide 102 */ 103 String SHELL_COMMAND_GET_TIME_STATE = "get_time_state"; 104 105 /** 106 * A shell command that sets the current time state for testing. 107 * @hide 108 */ 109 String SHELL_COMMAND_SET_TIME_STATE = "set_time_state_for_tests"; 110 111 /** 112 * A shell command that sets the confidence in the current time state for testing. 113 * @hide 114 */ 115 String SHELL_COMMAND_CONFIRM_TIME = "confirm_time"; 116 117 /** 118 * A shell command that clears the network time signal used by {@link 119 * SystemClock#currentNetworkTimeClock()}. 120 * @hide 121 */ 122 String SHELL_COMMAND_CLEAR_SYSTEM_CLOCK_NETWORK_TIME = "clear_system_clock_network_time"; 123 124 /** 125 * A shell command that sets the network time signal used by {@link 126 * SystemClock#currentNetworkTimeClock()}. 127 * @hide 128 */ 129 String SHELL_COMMAND_SET_SYSTEM_CLOCK_NETWORK_TIME = "set_system_clock_network_time"; 130 131 /** 132 * A shared utility method to create a {@link ManualTimeSuggestion}. 133 * 134 * @hide 135 */ createManualTimeSuggestion(long when, String why)136 static ManualTimeSuggestion createManualTimeSuggestion(long when, String why) { 137 UnixEpochTime unixEpochTime = new UnixEpochTime(SystemClock.elapsedRealtime(), when); 138 ManualTimeSuggestion manualTimeSuggestion = new ManualTimeSuggestion(unixEpochTime); 139 manualTimeSuggestion.addDebugInfo(why); 140 return manualTimeSuggestion; 141 } 142 143 /** 144 * Suggests a telephony-signal derived time to the detector. The detector may ignore the signal 145 * if better signals are available such as those that come from more reliable sources or were 146 * determined more recently. 147 */ 148 @RequiresPermission(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE) suggestTelephonyTime(@onNull TelephonyTimeSuggestion timeSuggestion)149 void suggestTelephonyTime(@NonNull TelephonyTimeSuggestion timeSuggestion); 150 151 /** 152 * Suggests the current time, determined from the user's manually entered information, to 153 * the detector. Returns {@code false} if the suggestion was invalid, or the device 154 * configuration prevented the suggestion being used, {@code true} if the suggestion was 155 * accepted. A suggestion that is valid but does not change the time because it matches the 156 * current device time is considered accepted. 157 * 158 * @hide 159 */ 160 @RequiresPermission(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE) suggestManualTime(@onNull ManualTimeSuggestion timeSuggestion)161 boolean suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion); 162 } 163