Neil Fuller | f7346ec | 2019-08-30 18:02:47 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.timezone; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
| 21 | import android.annotation.SystemApi; |
| 22 | |
| 23 | import com.android.internal.annotations.GuardedBy; |
| 24 | |
| 25 | import java.util.Objects; |
| 26 | |
| 27 | /** |
| 28 | * A class that can find time zone-related information about telephony networks. |
| 29 | * |
| 30 | * @hide |
| 31 | */ |
| 32 | @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
Neil Fuller | 6a0664d | 2020-01-28 15:24:15 +0000 | [diff] [blame] | 33 | public final class TelephonyLookup { |
Neil Fuller | f7346ec | 2019-08-30 18:02:47 +0100 | [diff] [blame] | 34 | |
Neil Fuller | 6a0664d | 2020-01-28 15:24:15 +0000 | [diff] [blame] | 35 | private static final Object sLock = new Object(); |
Neil Fuller | f7346ec | 2019-08-30 18:02:47 +0100 | [diff] [blame] | 36 | @GuardedBy("sLock") |
| 37 | private static TelephonyLookup sInstance; |
| 38 | |
Neil Fuller | f7346ec | 2019-08-30 18:02:47 +0100 | [diff] [blame] | 39 | /** |
Neil Fuller | 2551c03 | 2020-01-16 18:39:17 +0000 | [diff] [blame] | 40 | * Obtains an instance for use when resolving telephony time zone information. |
Neil Fuller | f7346ec | 2019-08-30 18:02:47 +0100 | [diff] [blame] | 41 | */ |
| 42 | @NonNull |
| 43 | public static TelephonyLookup getInstance() { |
| 44 | synchronized (sLock) { |
| 45 | if (sInstance == null) { |
| 46 | sInstance = new TelephonyLookup(libcore.timezone.TelephonyLookup.getInstance()); |
| 47 | } |
| 48 | return sInstance; |
| 49 | } |
| 50 | } |
| 51 | |
Neil Fuller | 2551c03 | 2020-01-16 18:39:17 +0000 | [diff] [blame] | 52 | @NonNull |
| 53 | private final libcore.timezone.TelephonyLookup mDelegate; |
| 54 | |
Neil Fuller | f7346ec | 2019-08-30 18:02:47 +0100 | [diff] [blame] | 55 | private TelephonyLookup(@NonNull libcore.timezone.TelephonyLookup delegate) { |
| 56 | mDelegate = Objects.requireNonNull(delegate); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns an object capable of querying telephony network information. This method can return |
| 61 | * {@code null} in the event of an error while reading the underlying data files. |
| 62 | */ |
| 63 | @Nullable |
| 64 | public TelephonyNetworkFinder getTelephonyNetworkFinder() { |
| 65 | libcore.timezone.TelephonyNetworkFinder telephonyNetworkFinderDelegate = |
| 66 | mDelegate.getTelephonyNetworkFinder(); |
| 67 | return telephonyNetworkFinderDelegate != null |
| 68 | ? new TelephonyNetworkFinder(telephonyNetworkFinderDelegate) : null; |
| 69 | } |
| 70 | } |