blob: 2412fb3994edcbae472460adfabf1d93b861372f [file] [log] [blame]
Neil Fullerb5579072018-05-30 14:35:24 +01001/*
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
17package android.app.timedetector;
18
Neil Fuller4773b9d2018-06-08 18:44:49 +010019import android.annotation.NonNull;
Neil Fuller3aedd492019-11-23 11:33:57 +000020import android.annotation.RequiresPermission;
Neil Fullerefe063e2020-01-07 11:09:29 +000021import android.annotation.SystemApi;
Neil Fullerb5579072018-05-30 14:35:24 +010022import android.annotation.SystemService;
23import android.content.Context;
Neil Fuller3aedd492019-11-23 11:33:57 +000024import android.os.SystemClock;
Neil Fuller35cc2962020-01-08 16:31:44 +000025import android.os.TimestampedValue;
Neil Fullerb5579072018-05-30 14:35:24 +010026
27/**
28 * The interface through which system components can send signals to the TimeDetectorService.
Neil Fullerefe063e2020-01-07 11:09:29 +000029 *
Neil Fullerb5579072018-05-30 14:35:24 +010030 * @hide
31 */
Neil Fullerefe063e2020-01-07 11:09:29 +000032@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
Neil Fullerb5579072018-05-30 14:35:24 +010033@SystemService(Context.TIME_DETECTOR_SERVICE)
Neil Fullerad6eb2b2020-01-28 10:55:15 +000034public interface TimeDetector {
Neil Fuller3aedd492019-11-23 11:33:57 +000035
36 /**
37 * A shared utility method to create a {@link ManualTimeSuggestion}.
Neil Fullerefe063e2020-01-07 11:09:29 +000038 *
39 * @hide
Neil Fuller3aedd492019-11-23 11:33:57 +000040 */
Neil Fullerad6eb2b2020-01-28 10:55:15 +000041 static ManualTimeSuggestion createManualTimeSuggestion(long when, String why) {
Neil Fuller3aedd492019-11-23 11:33:57 +000042 TimestampedValue<Long> utcTime =
43 new TimestampedValue<>(SystemClock.elapsedRealtime(), when);
44 ManualTimeSuggestion manualTimeSuggestion = new ManualTimeSuggestion(utcTime);
45 manualTimeSuggestion.addDebugInfo(why);
46 return manualTimeSuggestion;
47 }
Neil Fuller4ab8a192019-12-16 16:54:06 +000048
49 /**
Neil Fullerad6eb2b2020-01-28 10:55:15 +000050 * 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 Fuller4ab8a192019-12-16 16:54:06 +000066 * Suggests the time according to a network time source like NTP.
Neil Fullerefe063e2020-01-07 11:09:29 +000067 *
68 * @hide
Neil Fuller4ab8a192019-12-16 16:54:06 +000069 */
70 @RequiresPermission(android.Manifest.permission.SET_TIME)
Neil Fullerad6eb2b2020-01-28 10:55:15 +000071 void suggestNetworkTime(NetworkTimeSuggestion timeSuggestion);
Neil Fullerb5579072018-05-30 14:35:24 +010072}