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.content.Context;
23 import android.os.SystemClock;
24 import android.os.TimestampedValue;
25 
26 /**
27  * The interface through which system components can send signals to the TimeDetectorService.
28  *
29  * @hide
30  */
31 @SystemService(Context.TIME_DETECTOR_SERVICE)
32 public interface TimeDetector {
33 
34     /**
35      * A shared utility method to create a {@link ManualTimeSuggestion}.
36      *
37      * @hide
38      */
createManualTimeSuggestion(long when, String why)39     static ManualTimeSuggestion createManualTimeSuggestion(long when, String why) {
40         TimestampedValue<Long> utcTime =
41                 new TimestampedValue<>(SystemClock.elapsedRealtime(), when);
42         ManualTimeSuggestion manualTimeSuggestion = new ManualTimeSuggestion(utcTime);
43         manualTimeSuggestion.addDebugInfo(why);
44         return manualTimeSuggestion;
45     }
46 
47     /**
48      * Suggests a telephony-signal derived time to the detector. The detector may ignore the signal
49      * if better signals are available such as those that come from more reliable sources or were
50      * determined more recently.
51      */
52     @RequiresPermission(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE)
suggestTelephonyTime(@onNull TelephonyTimeSuggestion timeSuggestion)53     void suggestTelephonyTime(@NonNull TelephonyTimeSuggestion timeSuggestion);
54 
55     /**
56      * Suggests the user's manually entered current time to the detector.
57      *
58      * @hide
59      */
60     @RequiresPermission(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE)
suggestManualTime(@onNull ManualTimeSuggestion timeSuggestion)61     void suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion);
62 
63     /**
64      * Suggests the time according to a network time source like NTP.
65      *
66      * @hide
67      */
68     @RequiresPermission(android.Manifest.permission.SET_TIME)
suggestNetworkTime(NetworkTimeSuggestion timeSuggestion)69     void suggestNetworkTime(NetworkTimeSuggestion timeSuggestion);
70 }
71