blob: 0ada885001934bdf409e1f6d65e38d411a02d523 [file] [log] [blame]
Neil Fullerad6eb2b2020-01-28 10:55:15 +00001/*
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
17package android.app.timezonedetector;
18
19import android.annotation.NonNull;
20import android.content.Context;
21import android.os.RemoteException;
22import android.os.ServiceManager;
23import android.os.ServiceManager.ServiceNotFoundException;
24import android.util.Log;
25
26/**
27 * The real implementation of {@link TimeZoneDetector}.
28 *
29 * @hide
30 */
31public 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 Fullerc0d59e32020-02-04 14:30:06 +000043 public void suggestTelephonyTimeZone(@NonNull TelephonyTimeZoneSuggestion timeZoneSuggestion) {
Neil Fullerad6eb2b2020-01-28 10:55:15 +000044 if (DEBUG) {
Neil Fullerc0d59e32020-02-04 14:30:06 +000045 Log.d(TAG, "suggestTelephonyTimeZone called: " + timeZoneSuggestion);
Neil Fullerad6eb2b2020-01-28 10:55:15 +000046 }
47 try {
Neil Fullerc0d59e32020-02-04 14:30:06 +000048 mITimeZoneDetectorService.suggestTelephonyTimeZone(timeZoneSuggestion);
Neil Fullerad6eb2b2020-01-28 10:55:15 +000049 } 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}