Loading src/java/com/android/internal/telephony/MccTable.java +3 −4 Original line number Diff line number Diff line Loading @@ -27,15 +27,14 @@ import android.os.RemoteException; import android.os.SystemProperties; import android.telephony.Rlog; import android.text.TextUtils; import android.timezone.TelephonyLookup; import android.timezone.TelephonyNetwork; import android.timezone.TelephonyNetworkFinder; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.util.TelephonyUtils; import libcore.timezone.TelephonyLookup; import libcore.timezone.TelephonyNetwork; import libcore.timezone.TelephonyNetworkFinder; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; Loading src/java/com/android/internal/telephony/NitzStateMachineImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -22,11 +22,11 @@ import android.os.PowerManager; import android.os.TimestampedValue; import android.telephony.Rlog; import android.text.TextUtils; import android.timezone.CountryTimeZones.OffsetResult; import android.util.LocalLog; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.TimeZoneLookupHelper.CountryResult; import com.android.internal.telephony.TimeZoneLookupHelper.OffsetResult; import com.android.internal.telephony.metrics.TelephonyMetrics; import com.android.internal.util.IndentingPrintWriter; Loading src/java/com/android/internal/telephony/TimeZoneLookupHelper.java +7 −70 Original line number Diff line number Diff line Loading @@ -24,10 +24,10 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.icu.util.TimeZone; import android.text.TextUtils; import libcore.timezone.CountryTimeZones; import libcore.timezone.CountryTimeZones.TimeZoneMapping; import libcore.timezone.TimeZoneFinder; import android.timezone.CountryTimeZones; import android.timezone.CountryTimeZones.OffsetResult; import android.timezone.CountryTimeZones.TimeZoneMapping; import android.timezone.TimeZoneFinder; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; Loading @@ -40,65 +40,6 @@ import java.util.Objects; // Non-final to allow mocking. public class TimeZoneLookupHelper { /** * The result of looking up a time zone using offset information (and possibly more). */ public static final class OffsetResult { /** A zone that matches the supplied criteria. See also {@link #mIsOnlyMatch}. */ @NonNull private final TimeZone mTimeZone; /** True if there is only one matching time zone for the supplied criteria. */ private final boolean mIsOnlyMatch; public OffsetResult(@NonNull TimeZone timeZone, boolean isOnlyMatch) { mTimeZone = Objects.requireNonNull(timeZone); mIsOnlyMatch = isOnlyMatch; } /** * Returns a time zone that matches the supplied criteria. */ @NonNull public TimeZone getTimeZone() { return mTimeZone; } /** * Returns {@code true} if there is only one matching time zone for the supplied criteria. */ public boolean getIsOnlyMatch() { return mIsOnlyMatch; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } OffsetResult that = (OffsetResult) o; return mIsOnlyMatch == that.mIsOnlyMatch && mTimeZone.getID().equals(that.mTimeZone.getID()); } @Override public int hashCode() { return Objects.hash(mTimeZone, mIsOnlyMatch); } @Override public String toString() { return "OffsetResult{" + "mTimeZone(Id)=" + mTimeZone.getID() + ", mIsOnlyMatch=" + mIsOnlyMatch + '}'; } } /** * The result of looking up a time zone using country information. */ Loading Loading @@ -194,13 +135,9 @@ public class TimeZoneLookupHelper { Integer dstAdjustmentMillis = nitzData.getDstAdjustmentMillis(); Boolean isDst = dstAdjustmentMillis == null ? null : dstAdjustmentMillis != 0; Integer dstAdjustmentMillisToMatch = null; // Don't try to match the precise DST offset. CountryTimeZones.OffsetResult offsetResult = countryTimeZones.lookupByOffsetWithBias( return countryTimeZones.lookupByOffsetWithBias( nitzData.getLocalOffsetMillis(), isDst, dstAdjustmentMillisToMatch, nitzData.getCurrentTimeInMillis(), bias); if (offsetResult == null) { return null; } return new OffsetResult(offsetResult.mTimeZone, offsetResult.mOneMatch); } /** Loading Loading @@ -257,7 +194,7 @@ public class TimeZoneLookupHelper { String debugInfo; int matchQuality; if (countryTimeZones.getDefaultTimeZoneBoost()) { if (countryTimeZones.isDefaultTimeZoneBoosted()) { matchQuality = CountryResult.QUALITY_DEFAULT_BOOSTED; debugInfo = "Country default is boosted"; } else { Loading Loading @@ -291,7 +228,7 @@ public class TimeZoneLookupHelper { String countryDefaultId = countryDefaultZone.getID(); int countryDefaultOffset = countryDefaultZone.getOffset(whenMillis); for (TimeZoneMapping timeZoneMapping : effectiveTimeZoneMappings) { if (timeZoneMapping.timeZoneId.equals(countryDefaultId)) { if (timeZoneMapping.getTimeZoneId().equals(countryDefaultId)) { continue; } Loading src/java/com/android/internal/telephony/nitz/TimeZoneSuggesterImpl.java +5 −4 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.app.timezonedetector.PhoneTimeZoneSuggestion; import android.os.TimestampedValue; import android.telephony.Rlog; import android.text.TextUtils; import android.timezone.CountryTimeZones.OffsetResult; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.NitzData; Loading Loading @@ -142,7 +143,7 @@ public class TimeZoneSuggesterImpl implements TimeZoneSuggester { PhoneTimeZoneSuggestion.Builder suggestionBuilder = new PhoneTimeZoneSuggestion.Builder(phoneId); suggestionBuilder.addDebugInfo("findTimeZoneForTestNetwork: nitzSignal=" + nitzSignal); TimeZoneLookupHelper.OffsetResult lookupResult = OffsetResult lookupResult = mTimeZoneLookupHelper.lookupByNitz(nitzData); if (lookupResult == null) { suggestionBuilder.addDebugInfo("findTimeZoneForTestNetwork: No zone found"); Loading @@ -150,7 +151,7 @@ public class TimeZoneSuggesterImpl implements TimeZoneSuggester { suggestionBuilder.setZoneId(lookupResult.getTimeZone().getID()); suggestionBuilder.setMatchType( PhoneTimeZoneSuggestion.MATCH_TYPE_TEST_NETWORK_OFFSET_ONLY); int quality = lookupResult.getIsOnlyMatch() int quality = lookupResult.isOnlyMatch() ? PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE : PhoneTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET; suggestionBuilder.setQuality(quality); Loading Loading @@ -183,13 +184,13 @@ public class TimeZoneSuggesterImpl implements TimeZoneSuggester { } // Try to find a match using both country + NITZ signal. TimeZoneLookupHelper.OffsetResult lookupResult = OffsetResult lookupResult = mTimeZoneLookupHelper.lookupByNitzCountry(nitzData, countryIsoCode); if (lookupResult != null) { suggestionBuilder.setZoneId(lookupResult.getTimeZone().getID()); suggestionBuilder.setMatchType( PhoneTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET); int quality = lookupResult.getIsOnlyMatch() int quality = lookupResult.isOnlyMatch() ? PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE : PhoneTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET; suggestionBuilder.setQuality(quality); Loading tests/telephonytests/src/com/android/internal/telephony/NitzStateMachineImplTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -36,10 +36,10 @@ import static org.junit.Assert.assertTrue; import android.app.timedetector.PhoneTimeSuggestion; import android.icu.util.TimeZone; import android.os.TimestampedValue; import android.timezone.CountryTimeZones.OffsetResult; import com.android.internal.telephony.NitzStateMachineTestSupport.FakeDeviceState; import com.android.internal.telephony.NitzStateMachineTestSupport.Scenario; import com.android.internal.telephony.TimeZoneLookupHelper.OffsetResult; import org.junit.After; import org.junit.Before; Loading Loading @@ -1166,7 +1166,7 @@ public class NitzStateMachineImplTest extends TelephonyTest { String expectedZoneId = result.getTimeZone().getID(); // All our scenarios should return multiple matches. The only cases where this wouldn't be // true are places that use offsets like XX:15, XX:30 and XX:45. assertFalse(result.getIsOnlyMatch()); assertFalse(result.isOnlyMatch()); assertSameOffset(scenario.getActualTimeMillis(), expectedZoneId, scenario.getTimeZoneId()); return expectedZoneId; } Loading Loading
src/java/com/android/internal/telephony/MccTable.java +3 −4 Original line number Diff line number Diff line Loading @@ -27,15 +27,14 @@ import android.os.RemoteException; import android.os.SystemProperties; import android.telephony.Rlog; import android.text.TextUtils; import android.timezone.TelephonyLookup; import android.timezone.TelephonyNetwork; import android.timezone.TelephonyNetworkFinder; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.util.TelephonyUtils; import libcore.timezone.TelephonyLookup; import libcore.timezone.TelephonyNetwork; import libcore.timezone.TelephonyNetworkFinder; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; Loading
src/java/com/android/internal/telephony/NitzStateMachineImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -22,11 +22,11 @@ import android.os.PowerManager; import android.os.TimestampedValue; import android.telephony.Rlog; import android.text.TextUtils; import android.timezone.CountryTimeZones.OffsetResult; import android.util.LocalLog; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.TimeZoneLookupHelper.CountryResult; import com.android.internal.telephony.TimeZoneLookupHelper.OffsetResult; import com.android.internal.telephony.metrics.TelephonyMetrics; import com.android.internal.util.IndentingPrintWriter; Loading
src/java/com/android/internal/telephony/TimeZoneLookupHelper.java +7 −70 Original line number Diff line number Diff line Loading @@ -24,10 +24,10 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.icu.util.TimeZone; import android.text.TextUtils; import libcore.timezone.CountryTimeZones; import libcore.timezone.CountryTimeZones.TimeZoneMapping; import libcore.timezone.TimeZoneFinder; import android.timezone.CountryTimeZones; import android.timezone.CountryTimeZones.OffsetResult; import android.timezone.CountryTimeZones.TimeZoneMapping; import android.timezone.TimeZoneFinder; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; Loading @@ -40,65 +40,6 @@ import java.util.Objects; // Non-final to allow mocking. public class TimeZoneLookupHelper { /** * The result of looking up a time zone using offset information (and possibly more). */ public static final class OffsetResult { /** A zone that matches the supplied criteria. See also {@link #mIsOnlyMatch}. */ @NonNull private final TimeZone mTimeZone; /** True if there is only one matching time zone for the supplied criteria. */ private final boolean mIsOnlyMatch; public OffsetResult(@NonNull TimeZone timeZone, boolean isOnlyMatch) { mTimeZone = Objects.requireNonNull(timeZone); mIsOnlyMatch = isOnlyMatch; } /** * Returns a time zone that matches the supplied criteria. */ @NonNull public TimeZone getTimeZone() { return mTimeZone; } /** * Returns {@code true} if there is only one matching time zone for the supplied criteria. */ public boolean getIsOnlyMatch() { return mIsOnlyMatch; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } OffsetResult that = (OffsetResult) o; return mIsOnlyMatch == that.mIsOnlyMatch && mTimeZone.getID().equals(that.mTimeZone.getID()); } @Override public int hashCode() { return Objects.hash(mTimeZone, mIsOnlyMatch); } @Override public String toString() { return "OffsetResult{" + "mTimeZone(Id)=" + mTimeZone.getID() + ", mIsOnlyMatch=" + mIsOnlyMatch + '}'; } } /** * The result of looking up a time zone using country information. */ Loading Loading @@ -194,13 +135,9 @@ public class TimeZoneLookupHelper { Integer dstAdjustmentMillis = nitzData.getDstAdjustmentMillis(); Boolean isDst = dstAdjustmentMillis == null ? null : dstAdjustmentMillis != 0; Integer dstAdjustmentMillisToMatch = null; // Don't try to match the precise DST offset. CountryTimeZones.OffsetResult offsetResult = countryTimeZones.lookupByOffsetWithBias( return countryTimeZones.lookupByOffsetWithBias( nitzData.getLocalOffsetMillis(), isDst, dstAdjustmentMillisToMatch, nitzData.getCurrentTimeInMillis(), bias); if (offsetResult == null) { return null; } return new OffsetResult(offsetResult.mTimeZone, offsetResult.mOneMatch); } /** Loading Loading @@ -257,7 +194,7 @@ public class TimeZoneLookupHelper { String debugInfo; int matchQuality; if (countryTimeZones.getDefaultTimeZoneBoost()) { if (countryTimeZones.isDefaultTimeZoneBoosted()) { matchQuality = CountryResult.QUALITY_DEFAULT_BOOSTED; debugInfo = "Country default is boosted"; } else { Loading Loading @@ -291,7 +228,7 @@ public class TimeZoneLookupHelper { String countryDefaultId = countryDefaultZone.getID(); int countryDefaultOffset = countryDefaultZone.getOffset(whenMillis); for (TimeZoneMapping timeZoneMapping : effectiveTimeZoneMappings) { if (timeZoneMapping.timeZoneId.equals(countryDefaultId)) { if (timeZoneMapping.getTimeZoneId().equals(countryDefaultId)) { continue; } Loading
src/java/com/android/internal/telephony/nitz/TimeZoneSuggesterImpl.java +5 −4 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.app.timezonedetector.PhoneTimeZoneSuggestion; import android.os.TimestampedValue; import android.telephony.Rlog; import android.text.TextUtils; import android.timezone.CountryTimeZones.OffsetResult; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.NitzData; Loading Loading @@ -142,7 +143,7 @@ public class TimeZoneSuggesterImpl implements TimeZoneSuggester { PhoneTimeZoneSuggestion.Builder suggestionBuilder = new PhoneTimeZoneSuggestion.Builder(phoneId); suggestionBuilder.addDebugInfo("findTimeZoneForTestNetwork: nitzSignal=" + nitzSignal); TimeZoneLookupHelper.OffsetResult lookupResult = OffsetResult lookupResult = mTimeZoneLookupHelper.lookupByNitz(nitzData); if (lookupResult == null) { suggestionBuilder.addDebugInfo("findTimeZoneForTestNetwork: No zone found"); Loading @@ -150,7 +151,7 @@ public class TimeZoneSuggesterImpl implements TimeZoneSuggester { suggestionBuilder.setZoneId(lookupResult.getTimeZone().getID()); suggestionBuilder.setMatchType( PhoneTimeZoneSuggestion.MATCH_TYPE_TEST_NETWORK_OFFSET_ONLY); int quality = lookupResult.getIsOnlyMatch() int quality = lookupResult.isOnlyMatch() ? PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE : PhoneTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET; suggestionBuilder.setQuality(quality); Loading Loading @@ -183,13 +184,13 @@ public class TimeZoneSuggesterImpl implements TimeZoneSuggester { } // Try to find a match using both country + NITZ signal. TimeZoneLookupHelper.OffsetResult lookupResult = OffsetResult lookupResult = mTimeZoneLookupHelper.lookupByNitzCountry(nitzData, countryIsoCode); if (lookupResult != null) { suggestionBuilder.setZoneId(lookupResult.getTimeZone().getID()); suggestionBuilder.setMatchType( PhoneTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET); int quality = lookupResult.getIsOnlyMatch() int quality = lookupResult.isOnlyMatch() ? PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE : PhoneTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET; suggestionBuilder.setQuality(quality); Loading
tests/telephonytests/src/com/android/internal/telephony/NitzStateMachineImplTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -36,10 +36,10 @@ import static org.junit.Assert.assertTrue; import android.app.timedetector.PhoneTimeSuggestion; import android.icu.util.TimeZone; import android.os.TimestampedValue; import android.timezone.CountryTimeZones.OffsetResult; import com.android.internal.telephony.NitzStateMachineTestSupport.FakeDeviceState; import com.android.internal.telephony.NitzStateMachineTestSupport.Scenario; import com.android.internal.telephony.TimeZoneLookupHelper.OffsetResult; import org.junit.After; import org.junit.Before; Loading Loading @@ -1166,7 +1166,7 @@ public class NitzStateMachineImplTest extends TelephonyTest { String expectedZoneId = result.getTimeZone().getID(); // All our scenarios should return multiple matches. The only cases where this wouldn't be // true are places that use offsets like XX:15, XX:30 and XX:45. assertFalse(result.getIsOnlyMatch()); assertFalse(result.isOnlyMatch()); assertSameOffset(scenario.getActualTimeMillis(), expectedZoneId, scenario.getTimeZoneId()); return expectedZoneId; } Loading