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

Commit ea6b34da authored by Neil Fuller's avatar Neil Fuller
Browse files

Raise tz standards for uninitialized devices

Removes the lowering of standards applied for tz detection on
uninitialized devices. Before this change, the device would accept any
telephony tz suggestion, which could include lower-quality answers; i.e.
those where the zone was chosen based on a country's default zone, even
when there are multiple different zones to choose from.

Unfortunately, the stock device setup wizard assumes any time zone
change made while it is running is a high quality answer and so it then
doesn't ask the user to confirm the choice. Without an API it has no way
of telling whether the time zone chosen was a high or low quality
answer. This should eventually be resolved with improved system APIs.

Bug: 143721631
Test: atest services/tests/servicestests/src/com/android/server/timezonedetector
Change-Id: I1dbd1046f0e641e609ecc8809cf86b7ddb6111b3
parent 64737571
Loading
Loading
Loading
Loading
+1 −12
Original line number Diff line number Diff line
@@ -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) {
@@ -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
+54 −28
Original line number Diff line number Diff line
@@ -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 =
@@ -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