Neil Fuller | 2551c03 | 2020-01-16 18:39:17 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.timezone; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.SystemApi; |
| 21 | |
| 22 | import com.android.internal.annotations.GuardedBy; |
| 23 | |
| 24 | import java.util.Objects; |
| 25 | |
| 26 | /** |
| 27 | * Android's internal factory for java.util.TimeZone objects. Provides access to core library time |
| 28 | * zone metadata not available via {@link java.util.TimeZone}. |
| 29 | * |
| 30 | * @hide |
| 31 | */ |
| 32 | @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) |
| 33 | public final class ZoneInfoDb { |
| 34 | |
| 35 | private static Object sLock = new Object(); |
| 36 | @GuardedBy("sLock") |
| 37 | private static ZoneInfoDb sInstance; |
| 38 | |
| 39 | /** |
| 40 | * Obtains the singleton instance. |
| 41 | */ |
| 42 | @NonNull |
| 43 | public static ZoneInfoDb getInstance() { |
| 44 | synchronized (sLock) { |
| 45 | if (sInstance == null) { |
| 46 | sInstance = new ZoneInfoDb(libcore.timezone.ZoneInfoDB.getInstance()); |
| 47 | } |
| 48 | } |
| 49 | return sInstance; |
| 50 | } |
| 51 | |
| 52 | @NonNull |
| 53 | private final libcore.timezone.ZoneInfoDB mDelegate; |
| 54 | |
| 55 | private ZoneInfoDb(libcore.timezone.ZoneInfoDB delegate) { |
| 56 | mDelegate = Objects.requireNonNull(delegate); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns the tzdb version in use. |
| 61 | */ |
| 62 | @NonNull |
| 63 | public String getVersion() { |
| 64 | return mDelegate.getVersion(); |
| 65 | } |
| 66 | } |