Neil Fuller | b557907 | 2018-05-30 14:35:24 +0100 | [diff] [blame] | 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 | |
Neil Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 20 | import android.annotation.RequiresPermission; |
Neil Fuller | efe063e | 2020-01-07 11:09:29 +0000 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Neil Fuller | b557907 | 2018-05-30 14:35:24 +0100 | [diff] [blame] | 22 | import android.annotation.SystemService; |
| 23 | import android.content.Context; |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 24 | import android.os.SystemClock; |
Neil Fuller | 35cc296 | 2020-01-08 16:31:44 +0000 | [diff] [blame] | 25 | import android.os.TimestampedValue; |
Neil Fuller | b557907 | 2018-05-30 14:35:24 +0100 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * The interface through which system components can send signals to the TimeDetectorService. |
Neil Fuller | efe063e | 2020-01-07 11:09:29 +0000 | [diff] [blame] | 29 | * |
Neil Fuller | b557907 | 2018-05-30 14:35:24 +0100 | [diff] [blame] | 30 | * @hide |
| 31 | */ |
Neil Fuller | efe063e | 2020-01-07 11:09:29 +0000 | [diff] [blame] | 32 | @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
Neil Fuller | b557907 | 2018-05-30 14:35:24 +0100 | [diff] [blame] | 33 | @SystemService(Context.TIME_DETECTOR_SERVICE) |
Neil Fuller | ad6eb2b | 2020-01-28 10:55:15 +0000 | [diff] [blame] | 34 | public interface TimeDetector { |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * A shared utility method to create a {@link ManualTimeSuggestion}. |
Neil Fuller | efe063e | 2020-01-07 11:09:29 +0000 | [diff] [blame] | 38 | * |
| 39 | * @hide |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 40 | */ |
Neil Fuller | ad6eb2b | 2020-01-28 10:55:15 +0000 | [diff] [blame] | 41 | static ManualTimeSuggestion createManualTimeSuggestion(long when, String why) { |
Neil Fuller | 3aedd49 | 2019-11-23 11:33:57 +0000 | [diff] [blame] | 42 | TimestampedValue<Long> utcTime = |
| 43 | new TimestampedValue<>(SystemClock.elapsedRealtime(), when); |
| 44 | ManualTimeSuggestion manualTimeSuggestion = new ManualTimeSuggestion(utcTime); |
| 45 | manualTimeSuggestion.addDebugInfo(why); |
| 46 | return manualTimeSuggestion; |
| 47 | } |
Neil Fuller | 4ab8a19 | 2019-12-16 16:54:06 +0000 | [diff] [blame] | 48 | |
| 49 | /** |
Neil Fuller | ad6eb2b | 2020-01-28 10:55:15 +0000 | [diff] [blame] | 50 | * Suggests the current phone-signal derived time to the detector. The detector may ignore the |
| 51 | * signal if better signals are available such as those that come from more reliable sources or |
| 52 | * were determined more recently. |
| 53 | */ |
| 54 | @RequiresPermission(android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE) |
| 55 | void suggestPhoneTime(@NonNull PhoneTimeSuggestion timeSuggestion); |
| 56 | |
| 57 | /** |
| 58 | * Suggests the user's manually entered current time to the detector. |
| 59 | * |
| 60 | * @hide |
| 61 | */ |
| 62 | @RequiresPermission(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE) |
| 63 | void suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion); |
| 64 | |
| 65 | /** |
Neil Fuller | 4ab8a19 | 2019-12-16 16:54:06 +0000 | [diff] [blame] | 66 | * Suggests the time according to a network time source like NTP. |
Neil Fuller | efe063e | 2020-01-07 11:09:29 +0000 | [diff] [blame] | 67 | * |
| 68 | * @hide |
Neil Fuller | 4ab8a19 | 2019-12-16 16:54:06 +0000 | [diff] [blame] | 69 | */ |
| 70 | @RequiresPermission(android.Manifest.permission.SET_TIME) |
Neil Fuller | ad6eb2b | 2020-01-28 10:55:15 +0000 | [diff] [blame] | 71 | void suggestNetworkTime(NetworkTimeSuggestion timeSuggestion); |
Neil Fuller | b557907 | 2018-05-30 14:35:24 +0100 | [diff] [blame] | 72 | } |