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 | b557907 | 2018-05-30 14:35:24 +0100 | [diff] [blame] | 20 | import android.annotation.SystemService; |
| 21 | import android.content.Context; |
| 22 | import android.os.RemoteException; |
| 23 | import android.os.ServiceManager; |
| 24 | import android.os.ServiceManager.ServiceNotFoundException; |
| 25 | import 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) |
| 32 | public 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 Fuller | 4773b9d | 2018-06-08 18:44:49 +0100 | [diff] [blame] | 44 | * 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 Fuller | b557907 | 2018-05-30 14:35:24 +0100 | [diff] [blame] | 47 | */ |
Neil Fuller | af3eeaf | 2019-10-15 14:37:37 +0100 | [diff] [blame] | 48 | public void suggestPhoneTime(@NonNull PhoneTimeSuggestion timeSuggestion) { |
Neil Fuller | b557907 | 2018-05-30 14:35:24 +0100 | [diff] [blame] | 49 | if (DEBUG) { |
Neil Fuller | af3eeaf | 2019-10-15 14:37:37 +0100 | [diff] [blame] | 50 | Log.d(TAG, "suggestPhoneTime called: " + timeSuggestion); |
Neil Fuller | b557907 | 2018-05-30 14:35:24 +0100 | [diff] [blame] | 51 | } |
| 52 | try { |
Neil Fuller | af3eeaf | 2019-10-15 14:37:37 +0100 | [diff] [blame] | 53 | mITimeDetectorService.suggestPhoneTime(timeSuggestion); |
Neil Fuller | b557907 | 2018-05-30 14:35:24 +0100 | [diff] [blame] | 54 | } catch (RemoteException e) { |
| 55 | throw e.rethrowFromSystemServer(); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | } |