blob: 15dfe62bb789b43d3d676e69d497ee2de6b5945f [file] [log] [blame]
Neil Fullerf7346ec2019-08-30 18:02:47 +01001/*
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.timezone;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.SystemApi;
22
23import com.android.internal.annotations.GuardedBy;
24
25/**
26 * A class that can be used to find time zones.
27 *
28 * @hide
29 */
30@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
31public final class TimeZoneFinder {
32
33 private static Object sLock = new Object();
34 @GuardedBy("sLock")
35 private static TimeZoneFinder sInstance;
36
37 private final libcore.timezone.TimeZoneFinder mDelegate;
38
39 private TimeZoneFinder(libcore.timezone.TimeZoneFinder delegate) {
40 mDelegate = delegate;
41 }
42
43 /**
44 * Obtains an instance for use when resolving telephony time zone information. This method never
45 * returns {@code null}.
46 */
47 @NonNull
48 public static TimeZoneFinder getInstance() {
49 synchronized (sLock) {
50 if (sInstance == null) {
51 sInstance = new TimeZoneFinder(libcore.timezone.TimeZoneFinder.getInstance());
52 }
53 }
54 return sInstance;
55 }
56
57 /**
58 * Returns a {@link CountryTimeZones} object associated with the specified country code.
59 * Caching is handled as needed. If the country code is not recognized or there is an error
60 * during lookup this method can return null.
61 */
62 @Nullable
63 public CountryTimeZones lookupCountryTimeZones(@NonNull String countryIso) {
64 libcore.timezone.CountryTimeZones delegate = mDelegate.lookupCountryTimeZones(countryIso);
65 return delegate == null ? null : new CountryTimeZones(delegate);
66 }
67}