blob: 387a36bba608a61a0926680ef2a4891bac45f511 [file] [log] [blame]
Neil Fuller3352cfc2019-11-07 15:35:05 +00001/*
2 * Copyright (C) 2019 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;
Neil Fuller106f18a2019-12-04 13:27:04 +000020import android.annotation.RequiresPermission;
Neil Fuller3352cfc2019-11-07 15:35:05 +000021import android.annotation.SystemService;
22import android.content.Context;
23import android.os.RemoteException;
24import android.os.ServiceManager;
25import android.os.ServiceManager.ServiceNotFoundException;
26import android.util.Log;
27
28/**
29 * The interface through which system components can send signals to the TimeZoneDetectorService.
Neil Fuller106f18a2019-12-04 13:27:04 +000030 *
Neil Fuller3352cfc2019-11-07 15:35:05 +000031 * @hide
32 */
33@SystemService(Context.TIME_ZONE_DETECTOR_SERVICE)
Neil Fuller106f18a2019-12-04 13:27:04 +000034public class TimeZoneDetector {
Neil Fuller3352cfc2019-11-07 15:35:05 +000035 private static final String TAG = "timezonedetector.TimeZoneDetector";
36 private static final boolean DEBUG = false;
37
38 private final ITimeZoneDetectorService mITimeZoneDetectorService;
39
40 public TimeZoneDetector() throws ServiceNotFoundException {
41 mITimeZoneDetectorService = ITimeZoneDetectorService.Stub.asInterface(
42 ServiceManager.getServiceOrThrow(Context.TIME_ZONE_DETECTOR_SERVICE));
43 }
44
45 /**
Neil Fuller106f18a2019-12-04 13:27:04 +000046 * Suggests the current time zone, determined using telephony signals, to the detector. The
47 * detector may ignore the signal based on system settings, whether better information is
48 * available, and so on.
Neil Fuller3352cfc2019-11-07 15:35:05 +000049 */
Neil Fuller106f18a2019-12-04 13:27:04 +000050 @RequiresPermission(android.Manifest.permission.SET_TIME_ZONE)
Neil Fuller3352cfc2019-11-07 15:35:05 +000051 public void suggestPhoneTimeZone(@NonNull PhoneTimeZoneSuggestion timeZoneSuggestion) {
52 if (DEBUG) {
53 Log.d(TAG, "suggestPhoneTimeZone called: " + timeZoneSuggestion);
54 }
55 try {
56 mITimeZoneDetectorService.suggestPhoneTimeZone(timeZoneSuggestion);
57 } catch (RemoteException e) {
58 throw e.rethrowFromSystemServer();
59 }
60 }
61
Neil Fuller106f18a2019-12-04 13:27:04 +000062 /**
63 * Suggests the current time zone, determined for the user's manually information, to the
64 * detector. The detector may ignore the signal based on system settings.
65 */
66 @RequiresPermission(android.Manifest.permission.SET_TIME_ZONE)
67 public void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion) {
68 if (DEBUG) {
69 Log.d(TAG, "suggestManualTimeZone called: " + timeZoneSuggestion);
70 }
71 try {
72 mITimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion);
73 } catch (RemoteException e) {
74 throw e.rethrowFromSystemServer();
75 }
76 }
77
78 /**
79 * A shared utility method to create a {@link ManualTimeZoneSuggestion}.
80 */
81 public static ManualTimeZoneSuggestion createManualTimeZoneSuggestion(String tzId, String why) {
82 ManualTimeZoneSuggestion suggestion = new ManualTimeZoneSuggestion(tzId);
83 suggestion.addDebugInfo(why);
84 return suggestion;
85 }
Neil Fuller3352cfc2019-11-07 15:35:05 +000086}