Neil Fuller | ad6eb2b | 2020-01-28 10:55:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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.content.Context; |
| 21 | import android.os.RemoteException; |
| 22 | import android.os.ServiceManager; |
| 23 | import android.os.ServiceManager.ServiceNotFoundException; |
| 24 | import android.util.Log; |
| 25 | |
| 26 | /** |
| 27 | * The real implementation of {@link TimeDetector}. |
| 28 | * |
| 29 | * @hide |
| 30 | */ |
| 31 | public final class TimeDetectorImpl implements TimeDetector { |
| 32 | private static final String TAG = "timedetector.TimeDetector"; |
| 33 | private static final boolean DEBUG = false; |
| 34 | |
| 35 | private final ITimeDetectorService mITimeDetectorService; |
| 36 | |
| 37 | public TimeDetectorImpl() throws ServiceNotFoundException { |
| 38 | mITimeDetectorService = ITimeDetectorService.Stub.asInterface( |
| 39 | ServiceManager.getServiceOrThrow(Context.TIME_DETECTOR_SERVICE)); |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public void suggestPhoneTime(@NonNull PhoneTimeSuggestion timeSuggestion) { |
| 44 | if (DEBUG) { |
| 45 | Log.d(TAG, "suggestPhoneTime called: " + timeSuggestion); |
| 46 | } |
| 47 | try { |
| 48 | mITimeDetectorService.suggestPhoneTime(timeSuggestion); |
| 49 | } catch (RemoteException e) { |
| 50 | throw e.rethrowFromSystemServer(); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion) { |
| 56 | if (DEBUG) { |
| 57 | Log.d(TAG, "suggestManualTime called: " + timeSuggestion); |
| 58 | } |
| 59 | try { |
| 60 | mITimeDetectorService.suggestManualTime(timeSuggestion); |
| 61 | } catch (RemoteException e) { |
| 62 | throw e.rethrowFromSystemServer(); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public void suggestNetworkTime(NetworkTimeSuggestion timeSuggestion) { |
| 68 | if (DEBUG) { |
| 69 | Log.d(TAG, "suggestNetworkTime called: " + timeSuggestion); |
| 70 | } |
| 71 | try { |
| 72 | mITimeDetectorService.suggestNetworkTime(timeSuggestion); |
| 73 | } catch (RemoteException e) { |
| 74 | throw e.rethrowFromSystemServer(); |
| 75 | } |
| 76 | } |
| 77 | } |