blob: a4c3fbd3341030c921da3b7ebd90453aac05d4b6 [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;
Neil Fullerf7346ec2019-08-30 18:02:47 +010021
22import com.android.internal.annotations.GuardedBy;
23
24import java.util.Objects;
25
26/**
27 * A class that can find time zone-related information about telephony networks.
28 *
29 * @hide
30 */
Neil Fuller6a0664d2020-01-28 15:24:15 +000031public final class TelephonyLookup {
Neil Fullerf7346ec2019-08-30 18:02:47 +010032
Neil Fuller6a0664d2020-01-28 15:24:15 +000033 private static final Object sLock = new Object();
Neil Fullerf7346ec2019-08-30 18:02:47 +010034 @GuardedBy("sLock")
35 private static TelephonyLookup sInstance;
36
Neil Fullerf7346ec2019-08-30 18:02:47 +010037 /**
Neil Fuller2551c032020-01-16 18:39:17 +000038 * Obtains an instance for use when resolving telephony time zone information.
Neil Fullerf7346ec2019-08-30 18:02:47 +010039 */
40 @NonNull
41 public static TelephonyLookup getInstance() {
42 synchronized (sLock) {
43 if (sInstance == null) {
44 sInstance = new TelephonyLookup(libcore.timezone.TelephonyLookup.getInstance());
45 }
46 return sInstance;
47 }
48 }
49
Neil Fuller2551c032020-01-16 18:39:17 +000050 @NonNull
51 private final libcore.timezone.TelephonyLookup mDelegate;
52
Neil Fullerf7346ec2019-08-30 18:02:47 +010053 private TelephonyLookup(@NonNull libcore.timezone.TelephonyLookup delegate) {
54 mDelegate = Objects.requireNonNull(delegate);
55 }
56
57 /**
58 * Returns an object capable of querying telephony network information. This method can return
59 * {@code null} in the event of an error while reading the underlying data files.
60 */
61 @Nullable
62 public TelephonyNetworkFinder getTelephonyNetworkFinder() {
63 libcore.timezone.TelephonyNetworkFinder telephonyNetworkFinderDelegate =
64 mDelegate.getTelephonyNetworkFinder();
65 return telephonyNetworkFinderDelegate != null
66 ? new TelephonyNetworkFinder(telephonyNetworkFinderDelegate) : null;
67 }
68}