Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d533ec48 authored by Geoffrey Boullanger's avatar Geoffrey Boullanger Committed by Android (Google) Code Review
Browse files

Merge "Annotate time zone classes to be usable by module libraries" into main

parents fe1703ff 158c127a
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -654,6 +654,53 @@ package android.telephony {

}

package android.timezone {

  @FlaggedApi("android.timezone.flags.expose_time_zone_system_api") public final class CountryTimeZones {
    method @NonNull public String getCountryIso();
    method @Nullable public android.icu.util.TimeZone getDefaultTimeZone();
    method @Nullable public String getDefaultTimeZoneId();
    method @NonNull public java.util.List<android.timezone.CountryTimeZones.TimeZoneMapping> getEffectiveTimeZoneMappingsAt(long);
    method public boolean hasUtcZone(long);
    method public boolean isDefaultTimeZoneBoosted();
    method @Nullable public android.timezone.CountryTimeZones.OffsetResult lookupByOffsetWithBias(long, @NonNull android.icu.util.TimeZone, int, boolean);
    method @Nullable public android.timezone.CountryTimeZones.OffsetResult lookupByOffsetWithBias(long, @NonNull android.icu.util.TimeZone, int);
  }

  @FlaggedApi("android.timezone.flags.expose_time_zone_system_api") public static final class CountryTimeZones.OffsetResult {
    ctor public CountryTimeZones.OffsetResult(@NonNull android.icu.util.TimeZone, @Nullable String, boolean);
    method @Nullable public String getCountryIsoCode();
    method @NonNull public android.icu.util.TimeZone getTimeZone();
    method public boolean isOnlyMatch();
  }

  @FlaggedApi("android.timezone.flags.expose_time_zone_system_api") public static final class CountryTimeZones.TimeZoneMapping {
    method @Nullable public android.icu.util.TimeZone getTimeZone();
    method @NonNull public String getTimeZoneId();
  }

  @FlaggedApi("android.timezone.flags.expose_time_zone_system_api") public final class MobileCountries {
    method @NonNull public static android.timezone.MobileCountries createTestCell(@NonNull String);
    method @NonNull public java.util.Set<java.lang.String> getCountryIsoCodes();
    method @NonNull public String getDefaultCountryIsoCode();
    method @NonNull public String getMcc();
    method @Nullable public String getMnc();
  }

  @FlaggedApi("android.timezone.flags.expose_time_zone_system_api") public final class TelephonyNetworkFinder {
    method @Nullable public android.timezone.MobileCountries findCountriesByMcc(@NonNull String);
    method @Nullable public android.timezone.MobileCountries findCountriesByMccMnc(@NonNull String, @NonNull String);
    method @Nullable public static android.timezone.TelephonyNetworkFinder getInstance();
  }

  @FlaggedApi("android.timezone.flags.expose_time_zone_system_api") public final class TimeZoneFinder {
    method @Nullable public String getIanaVersion();
    method @NonNull public static android.timezone.TimeZoneFinder getInstance();
    method @Nullable public android.timezone.CountryTimeZones lookupCountryTimeZones(@NonNull String);
  }

}

package android.util {

  public class AtomicFile {
+27 −15
Original line number Diff line number Diff line
@@ -16,10 +16,16 @@

package android.timezone;

import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;

import android.annotation.FlaggedApi;
import android.annotation.SystemApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.icu.util.TimeZone;

import android.timezone.flags.Flags;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -30,13 +36,21 @@ import java.util.Objects;
 *
 * @hide
 */
@FlaggedApi(Flags.FLAG_EXPOSE_TIME_ZONE_SYSTEM_API)
@SystemApi(client = MODULE_LIBRARIES)
public final class CountryTimeZones {

    /**
     * A mapping to a time zone ID with some associated metadata.
     * A wrapper for a time zone mapping.
     *
     * <p>This class currently only exposes the time zone and its ID (e.g., "America/Los_Angeles").
     * It is structured to allow for additional metadata to be exposed in the future without
     * breaking the API.
     *
     * @hide
     */
    @FlaggedApi(Flags.FLAG_EXPOSE_TIME_ZONE_SYSTEM_API)
    @SystemApi(client = MODULE_LIBRARIES)
    public static final class TimeZoneMapping {

        @NonNull
@@ -57,10 +71,8 @@ public final class CountryTimeZones {
            return mDelegate.getTimeZoneId();
        }

        /**
         * Returns a frozen {@link TimeZone} object for this mapping.
         */
        @NonNull
        /** Returns a frozen {@link TimeZone} object for this mapping. */
        @Nullable
        public TimeZone getTimeZone() {
            return mDelegate.getTimeZone();
        }
@@ -93,6 +105,8 @@ public final class CountryTimeZones {
     *
     * @hide
     */
    @FlaggedApi(Flags.FLAG_EXPOSE_TIME_ZONE_SYSTEM_API)
    @SystemApi(client = MODULE_LIBRARIES)
    public static final class OffsetResult {

        private final TimeZone mTimeZone;
@@ -164,12 +178,10 @@ public final class CountryTimeZones {
        mDelegate = delegate;
    }

    /**
     * Returns true if the ISO code for the country is a case-insensitive match for the one
     * supplied.
     */
    public boolean matchesCountryCode(@NonNull String countryIso) {
        return mDelegate.matchesCountryCode(countryIso);
    /** Returns the ISO code for the country in lower case (e.g., "us"). */
    @NonNull
    public String getCountryIso() {
        return mDelegate.getCountryIso();
    }

    /**
@@ -230,8 +242,8 @@ public final class CountryTimeZones {
     *     there is no match
     */
    @Nullable
    public OffsetResult lookupByOffsetWithBias(long whenMillis, @Nullable TimeZone bias,
            int totalOffsetMillis, boolean isDst) {
    public OffsetResult lookupByOffsetWithBias(
            long whenMillis, @NonNull TimeZone bias, int totalOffsetMillis, boolean isDst) {
        com.android.i18n.timezone.CountryTimeZones.OffsetResult delegateOffsetResult =
                mDelegate.lookupByOffsetWithBias(
                        whenMillis, bias, totalOffsetMillis, isDst);
@@ -253,8 +265,8 @@ public final class CountryTimeZones {
     *     there is no match
     */
    @Nullable
    public OffsetResult lookupByOffsetWithBias(long whenMillis, @Nullable TimeZone bias,
            int totalOffsetMillis) {
    public OffsetResult lookupByOffsetWithBias(
            long whenMillis, @NonNull TimeZone bias, int totalOffsetMillis) {
        com.android.i18n.timezone.CountryTimeZones.OffsetResult delegateOffsetResult =
                mDelegate.lookupByOffsetWithBias(whenMillis, bias, totalOffsetMillis);
        return delegateOffsetResult == null ? null :
+21 −3
Original line number Diff line number Diff line
@@ -16,8 +16,15 @@

package android.timezone;

import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.TestApi;

import android.timezone.flags.Flags;

import com.android.internal.annotations.VisibleForTesting;
import java.util.Objects;
@@ -28,6 +35,8 @@ import java.util.Set;
 *
 * @hide
 */
@FlaggedApi(Flags.FLAG_EXPOSE_TIME_ZONE_SYSTEM_API)
@SystemApi(client = MODULE_LIBRARIES)
public final class MobileCountries {

    @NonNull
@@ -37,15 +46,24 @@ public final class MobileCountries {
     * Create a {@link MobileCountries} entity. This can be used for test networks (i.e. integration
     * tests).
     */
    public static MobileCountries createTestCell(String mcc) {
    @NonNull
    public static MobileCountries createTestCell(@NonNull String mcc) {
        return new MobileCountries(
                com.android.i18n.timezone.MobileCountries.create(mcc, Set.of(""), ""));
    }

    /** Create a {@link MobileCountries} entity for tests (i.e. unit tests). */
    /**
     * Create a {@link MobileCountries} entity for tests (i.e. unit tests).
     *
     * @hide
     */
    @VisibleForTesting
    @NonNull
    public static MobileCountries createForTest(
            String mcc, String mnc, Set<String> countryIsoCodes, String defaultCountryIsoCode) {
            @NonNull String mcc,
            @Nullable String mnc,
            @NonNull Set<String> countryIsoCodes,
            @NonNull String defaultCountryIsoCode) {
        return new MobileCountries(
                com.android.i18n.timezone.MobileCountries.create(
                        mcc, mnc, countryIsoCodes, defaultCountryIsoCode));
+0 −69
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.timezone;

import android.annotation.NonNull;
import android.annotation.Nullable;

import com.android.internal.annotations.GuardedBy;

import java.util.Objects;

/**
 * A class that can find time zone-related information about telephony networks.
 *
 * @hide
 */
public final class TelephonyLookup {

    private static final Object sLock = new Object();
    @GuardedBy("sLock")
    private static TelephonyLookup sInstance;

    /**
     * Obtains an instance for use when resolving telephony time zone information.
     */
    @NonNull
    public static TelephonyLookup getInstance() {
        synchronized (sLock) {
            if (sInstance == null) {
                sInstance = new TelephonyLookup(com.android.i18n.timezone.TelephonyLookup
                    .getInstance());
            }
            return sInstance;
        }
    }

    @NonNull
    private final com.android.i18n.timezone.TelephonyLookup mDelegate;

    private TelephonyLookup(@NonNull com.android.i18n.timezone.TelephonyLookup delegate) {
        mDelegate = Objects.requireNonNull(delegate);
    }

    /**
     * Returns an object capable of querying telephony network information. This method can return
     * {@code null} in the event of an error while reading the underlying data files.
     */
    @Nullable
    public TelephonyNetworkFinder getTelephonyNetworkFinder() {
        com.android.i18n.timezone.TelephonyNetworkFinder telephonyNetworkFinderDelegate =
                mDelegate.getTelephonyNetworkFinder();
        return telephonyNetworkFinderDelegate != null
                ? new TelephonyNetworkFinder(telephonyNetworkFinderDelegate) : null;
    }
}
+32 −0
Original line number Diff line number Diff line
@@ -16,8 +16,16 @@

package android.timezone;

import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;

import android.timezone.flags.Flags;

import com.android.internal.annotations.GuardedBy;

import java.util.Objects;

@@ -26,8 +34,32 @@ import java.util.Objects;
 *
 * @hide
 */
@FlaggedApi(Flags.FLAG_EXPOSE_TIME_ZONE_SYSTEM_API)
@SystemApi(client = MODULE_LIBRARIES)
public final class TelephonyNetworkFinder {

    private static final Object sLock = new Object();

    @GuardedBy("sLock")
    private static TelephonyNetworkFinder sInstance;

    /**
     * Returns an object capable of querying telephony network information. This method can return
     * {@code null} in the event of an error while reading the underlying data files.
     */
    @Nullable
    public static TelephonyNetworkFinder getInstance() {
        synchronized (sLock) {
            if (sInstance == null) {
                sInstance =
                        new TelephonyNetworkFinder(
                                com.android.i18n.timezone.TelephonyLookup.getInstance()
                                        .getTelephonyNetworkFinder());
            }
            return sInstance;
        }
    }

    @NonNull
    private final com.android.i18n.timezone.TelephonyNetworkFinder mDelegate;

Loading