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.timezonedetector; |
| 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 TimeZoneDetector}. |
| 28 | * |
| 29 | * @hide |
| 30 | */ |
| 31 | public final class TimeZoneDetectorImpl implements TimeZoneDetector { |
| 32 | private static final String TAG = "timezonedetector.TimeZoneDetector"; |
| 33 | private static final boolean DEBUG = false; |
| 34 | |
| 35 | private final ITimeZoneDetectorService mITimeZoneDetectorService; |
| 36 | |
| 37 | public TimeZoneDetectorImpl() throws ServiceNotFoundException { |
| 38 | mITimeZoneDetectorService = ITimeZoneDetectorService.Stub.asInterface( |
| 39 | ServiceManager.getServiceOrThrow(Context.TIME_ZONE_DETECTOR_SERVICE)); |
| 40 | } |
| 41 | |
| 42 | @Override |
Neil Fuller | c0d59e3 | 2020-02-04 14:30:06 +0000 | [diff] [blame] | 43 | public void suggestTelephonyTimeZone(@NonNull TelephonyTimeZoneSuggestion timeZoneSuggestion) { |
Neil Fuller | ad6eb2b | 2020-01-28 10:55:15 +0000 | [diff] [blame] | 44 | if (DEBUG) { |
Neil Fuller | c0d59e3 | 2020-02-04 14:30:06 +0000 | [diff] [blame] | 45 | Log.d(TAG, "suggestTelephonyTimeZone called: " + timeZoneSuggestion); |
Neil Fuller | ad6eb2b | 2020-01-28 10:55:15 +0000 | [diff] [blame] | 46 | } |
| 47 | try { |
Neil Fuller | c0d59e3 | 2020-02-04 14:30:06 +0000 | [diff] [blame] | 48 | mITimeZoneDetectorService.suggestTelephonyTimeZone(timeZoneSuggestion); |
Neil Fuller | ad6eb2b | 2020-01-28 10:55:15 +0000 | [diff] [blame] | 49 | } catch (RemoteException e) { |
| 50 | throw e.rethrowFromSystemServer(); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion) { |
| 56 | if (DEBUG) { |
| 57 | Log.d(TAG, "suggestManualTimeZone called: " + timeZoneSuggestion); |
| 58 | } |
| 59 | try { |
| 60 | mITimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion); |
| 61 | } catch (RemoteException e) { |
| 62 | throw e.rethrowFromSystemServer(); |
| 63 | } |
| 64 | } |
| 65 | } |