Loading services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java +1 −12 Original line number Diff line number Diff line Loading @@ -276,18 +276,6 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat return; } // Special case handling for uninitialized devices. This should only happen once. String newZoneId = bestTelephonySuggestion.suggestion.getZoneId(); if (newZoneId != null && !mCallback.isDeviceTimeZoneInitialized()) { String cause = "Device has no time zone set. Attempting to set the device to the best" + " available suggestion." + " bestTelephonySuggestion=" + bestTelephonySuggestion + ", detectionReason=" + detectionReason; Slog.i(LOG_TAG, cause); setDeviceTimeZoneIfRequired(ORIGIN_TELEPHONY, newZoneId, cause); return; } boolean suggestionGoodEnough = bestTelephonySuggestion.score >= TELEPHONY_SCORE_USAGE_THRESHOLD; if (!suggestionGoodEnough) { Loading @@ -301,6 +289,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat // Paranoia: Every suggestion above the SCORE_USAGE_THRESHOLD should have a non-null time // zone ID. String newZoneId = bestTelephonySuggestion.suggestion.getZoneId(); if (newZoneId == null) { Slog.w(LOG_TAG, "Empty zone suggestion scored higher than expected. This is an error:" + " bestTelephonySuggestion=" + bestTelephonySuggestion Loading services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorStrategyImplTest.java +54 −28 Original line number Diff line number Diff line Loading @@ -128,19 +128,25 @@ public class TimeZoneDetectorStrategyImplTest { } @Test public void testFirstPlausibleTelephonySuggestionAcceptedWhenTimeZoneUninitialized() { public void testTelephonySuggestionsWhenTimeZoneUninitialized() { assertTrue(TELEPHONY_SCORE_LOW < TELEPHONY_SCORE_USAGE_THRESHOLD); assertTrue(TELEPHONY_SCORE_HIGH >= TELEPHONY_SCORE_USAGE_THRESHOLD); SuggestionTestCase testCase = newTestCase(MATCH_TYPE_NETWORK_COUNTRY_ONLY, QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS, TELEPHONY_SCORE_LOW); TelephonyTimeZoneSuggestion lowQualitySuggestion = testCase.createSuggestion(SLOT_INDEX1, "America/New_York"); SuggestionTestCase testCase2 = newTestCase(MATCH_TYPE_NETWORK_COUNTRY_ONLY, QUALITY_SINGLE_ZONE, TELEPHONY_SCORE_HIGH); // The device time zone setting is left uninitialized. Script script = new Script() .initializeAutoTimeZoneDetection(true); // The very first suggestion will be taken. // A low quality suggestions will not be taken: The device time zone setting is left // uninitialized. { TelephonyTimeZoneSuggestion lowQualitySuggestion = testCase.createSuggestion(SLOT_INDEX1, "America/New_York"); script.suggestTelephonyTimeZone(lowQualitySuggestion) .verifyTimeZoneSetAndReset(lowQualitySuggestion); .verifyTimeZoneNotSet(); // Assert internal service state. QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion = Loading @@ -150,22 +156,42 @@ public class TimeZoneDetectorStrategyImplTest { mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1)); assertEquals(expectedScoredSuggestion, mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests()); } // A good quality suggestion will be used. { TelephonyTimeZoneSuggestion goodQualitySuggestion = testCase2.createSuggestion(SLOT_INDEX1, "Europe/London"); script.suggestTelephonyTimeZone(goodQualitySuggestion) .verifyTimeZoneSetAndReset(goodQualitySuggestion); // Another low quality suggestion will be ignored now that the setting is initialized. // Assert internal service state. QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion = new QualifiedTelephonyTimeZoneSuggestion( goodQualitySuggestion, testCase2.expectedScore); assertEquals(expectedScoredSuggestion, mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1)); assertEquals(expectedScoredSuggestion, mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests()); } // A low quality suggestion will be accepted, but not used to set the device time zone. { TelephonyTimeZoneSuggestion lowQualitySuggestion2 = testCase.createSuggestion(SLOT_INDEX1, "America/Los_Angeles"); script.suggestTelephonyTimeZone(lowQualitySuggestion2) .verifyTimeZoneNotSet(); // Assert internal service state. QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion2 = QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion = new QualifiedTelephonyTimeZoneSuggestion( lowQualitySuggestion2, testCase.expectedScore); assertEquals(expectedScoredSuggestion2, assertEquals(expectedScoredSuggestion, mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1)); assertEquals(expectedScoredSuggestion2, assertEquals(expectedScoredSuggestion, mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests()); } } /** * Confirms that toggling the auto time zone detection setting has the expected behavior when Loading Loading
services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java +1 −12 Original line number Diff line number Diff line Loading @@ -276,18 +276,6 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat return; } // Special case handling for uninitialized devices. This should only happen once. String newZoneId = bestTelephonySuggestion.suggestion.getZoneId(); if (newZoneId != null && !mCallback.isDeviceTimeZoneInitialized()) { String cause = "Device has no time zone set. Attempting to set the device to the best" + " available suggestion." + " bestTelephonySuggestion=" + bestTelephonySuggestion + ", detectionReason=" + detectionReason; Slog.i(LOG_TAG, cause); setDeviceTimeZoneIfRequired(ORIGIN_TELEPHONY, newZoneId, cause); return; } boolean suggestionGoodEnough = bestTelephonySuggestion.score >= TELEPHONY_SCORE_USAGE_THRESHOLD; if (!suggestionGoodEnough) { Loading @@ -301,6 +289,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat // Paranoia: Every suggestion above the SCORE_USAGE_THRESHOLD should have a non-null time // zone ID. String newZoneId = bestTelephonySuggestion.suggestion.getZoneId(); if (newZoneId == null) { Slog.w(LOG_TAG, "Empty zone suggestion scored higher than expected. This is an error:" + " bestTelephonySuggestion=" + bestTelephonySuggestion Loading
services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorStrategyImplTest.java +54 −28 Original line number Diff line number Diff line Loading @@ -128,19 +128,25 @@ public class TimeZoneDetectorStrategyImplTest { } @Test public void testFirstPlausibleTelephonySuggestionAcceptedWhenTimeZoneUninitialized() { public void testTelephonySuggestionsWhenTimeZoneUninitialized() { assertTrue(TELEPHONY_SCORE_LOW < TELEPHONY_SCORE_USAGE_THRESHOLD); assertTrue(TELEPHONY_SCORE_HIGH >= TELEPHONY_SCORE_USAGE_THRESHOLD); SuggestionTestCase testCase = newTestCase(MATCH_TYPE_NETWORK_COUNTRY_ONLY, QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS, TELEPHONY_SCORE_LOW); TelephonyTimeZoneSuggestion lowQualitySuggestion = testCase.createSuggestion(SLOT_INDEX1, "America/New_York"); SuggestionTestCase testCase2 = newTestCase(MATCH_TYPE_NETWORK_COUNTRY_ONLY, QUALITY_SINGLE_ZONE, TELEPHONY_SCORE_HIGH); // The device time zone setting is left uninitialized. Script script = new Script() .initializeAutoTimeZoneDetection(true); // The very first suggestion will be taken. // A low quality suggestions will not be taken: The device time zone setting is left // uninitialized. { TelephonyTimeZoneSuggestion lowQualitySuggestion = testCase.createSuggestion(SLOT_INDEX1, "America/New_York"); script.suggestTelephonyTimeZone(lowQualitySuggestion) .verifyTimeZoneSetAndReset(lowQualitySuggestion); .verifyTimeZoneNotSet(); // Assert internal service state. QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion = Loading @@ -150,22 +156,42 @@ public class TimeZoneDetectorStrategyImplTest { mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1)); assertEquals(expectedScoredSuggestion, mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests()); } // A good quality suggestion will be used. { TelephonyTimeZoneSuggestion goodQualitySuggestion = testCase2.createSuggestion(SLOT_INDEX1, "Europe/London"); script.suggestTelephonyTimeZone(goodQualitySuggestion) .verifyTimeZoneSetAndReset(goodQualitySuggestion); // Another low quality suggestion will be ignored now that the setting is initialized. // Assert internal service state. QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion = new QualifiedTelephonyTimeZoneSuggestion( goodQualitySuggestion, testCase2.expectedScore); assertEquals(expectedScoredSuggestion, mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1)); assertEquals(expectedScoredSuggestion, mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests()); } // A low quality suggestion will be accepted, but not used to set the device time zone. { TelephonyTimeZoneSuggestion lowQualitySuggestion2 = testCase.createSuggestion(SLOT_INDEX1, "America/Los_Angeles"); script.suggestTelephonyTimeZone(lowQualitySuggestion2) .verifyTimeZoneNotSet(); // Assert internal service state. QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion2 = QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion = new QualifiedTelephonyTimeZoneSuggestion( lowQualitySuggestion2, testCase.expectedScore); assertEquals(expectedScoredSuggestion2, assertEquals(expectedScoredSuggestion, mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1)); assertEquals(expectedScoredSuggestion2, assertEquals(expectedScoredSuggestion, mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests()); } } /** * Confirms that toggling the auto time zone detection setting has the expected behavior when Loading