blob: 334e9582a14561ffd39667de3a4a2dc81ab0712a [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 Fullerb5579072018-05-30 14:35:24 +010020import android.annotation.SystemService;
21import android.content.Context;
22import android.os.RemoteException;
23import android.os.ServiceManager;
24import android.os.ServiceManager.ServiceNotFoundException;
25import android.util.Log;
26
27/**
28 * The interface through which system components can send signals to the TimeDetectorService.
29 * @hide
30 */
31@SystemService(Context.TIME_DETECTOR_SERVICE)
32public final class TimeDetector {
33 private static final String TAG = "timedetector.TimeDetector";
34 private static final boolean DEBUG = false;
35
36 private final ITimeDetectorService mITimeDetectorService;
37
38 public TimeDetector() throws ServiceNotFoundException {
39 mITimeDetectorService = ITimeDetectorService.Stub.asInterface(
40 ServiceManager.getServiceOrThrow(Context.TIME_DETECTOR_SERVICE));
41 }
42
43 /**
Neil Fuller4773b9d2018-06-08 18:44:49 +010044 * Suggests the current time to the detector. The detector may ignore the signal if better
45 * signals are available such as those that come from more reliable sources or were
46 * determined more recently.
Neil Fullerb5579072018-05-30 14:35:24 +010047 */
Neil Fulleraf3eeaf2019-10-15 14:37:37 +010048 public void suggestPhoneTime(@NonNull PhoneTimeSuggestion timeSuggestion) {
Neil Fullerb5579072018-05-30 14:35:24 +010049 if (DEBUG) {
Neil Fulleraf3eeaf2019-10-15 14:37:37 +010050 Log.d(TAG, "suggestPhoneTime called: " + timeSuggestion);
Neil Fullerb5579072018-05-30 14:35:24 +010051 }
52 try {
Neil Fulleraf3eeaf2019-10-15 14:37:37 +010053 mITimeDetectorService.suggestPhoneTime(timeSuggestion);
Neil Fullerb5579072018-05-30 14:35:24 +010054 } catch (RemoteException e) {
55 throw e.rethrowFromSystemServer();
56 }
57 }
58
59}