Merge "Make manual suggestions synchronous/return result"

This commit is contained in:
Almaz Mingaleev
2020-11-25 11:21:44 +00:00
committed by Gerrit Code Review
16 changed files with 110 additions and 74 deletions

View File

@@ -34,7 +34,7 @@ import android.app.timedetector.TelephonyTimeSuggestion;
* {@hide}
*/
interface ITimeDetectorService {
void suggestManualTime(in ManualTimeSuggestion timeSuggestion);
boolean suggestManualTime(in ManualTimeSuggestion timeSuggestion);
void suggestNetworkTime(in NetworkTimeSuggestion timeSuggestion);
void suggestTelephonyTime(in TelephonyTimeSuggestion timeSuggestion);
}

View File

@@ -53,12 +53,16 @@ public interface TimeDetector {
void suggestTelephonyTime(@NonNull TelephonyTimeSuggestion timeSuggestion);
/**
* Suggests the user's manually entered current time to the detector.
* Suggests the current time, determined from the user's manually entered information, to
* the detector. Returns {@code false} if the suggestion was invalid, or the device
* configuration prevented the suggestion being used, {@code true} if the suggestion was
* accepted. A suggestion that is valid but does not change the time because it matches the
* current device time is considered accepted.
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE)
void suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion);
boolean suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion);
/**
* Suggests the time according to a network time source like NTP.

View File

@@ -52,12 +52,12 @@ public final class TimeDetectorImpl implements TimeDetector {
}
@Override
public void suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion) {
public boolean suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion) {
if (DEBUG) {
Log.d(TAG, "suggestManualTime called: " + timeSuggestion);
}
try {
mITimeDetectorService.suggestManualTime(timeSuggestion);
return mITimeDetectorService.suggestManualTime(timeSuggestion);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}

View File

@@ -33,6 +33,6 @@ import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
* {@hide}
*/
interface ITimeZoneDetectorService {
void suggestManualTimeZone(in ManualTimeZoneSuggestion timeZoneSuggestion);
boolean suggestManualTimeZone(in ManualTimeZoneSuggestion timeZoneSuggestion);
void suggestTelephonyTimeZone(in TelephonyTimeZoneSuggestion timeZoneSuggestion);
}

View File

@@ -41,13 +41,16 @@ public interface TimeZoneDetector {
}
/**
* Suggests the current time zone, determined using the user's manually entered information, to
* the detector. The detector may ignore the signal based on system settings.
* Suggests the current time zone, determined from the user's manually entered information, to
* the detector. Returns {@code false} if the suggestion was invalid, or the device
* configuration prevented the suggestion being used, {@code true} if the suggestion was
* accepted. A suggestion that is valid but does not change the time zone because it matches
* the current device time zone is considered accepted.
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE)
void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion);
boolean suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion);
/**
* Suggests the current time zone, determined using telephony signals, to the detector. The

View File

@@ -40,12 +40,12 @@ public final class TimeZoneDetectorImpl implements TimeZoneDetector {
}
@Override
public void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion) {
public boolean suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion) {
if (DEBUG) {
Log.d(TAG, "suggestManualTimeZone called: " + timeZoneSuggestion);
}
try {
mITimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion);
return mITimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}

View File

@@ -25,6 +25,7 @@ import android.app.timedetector.TelephonyTimeSuggestion;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.os.Binder;
import android.os.Handler;
import android.provider.Settings;
@@ -101,11 +102,16 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub {
}
@Override
public void suggestManualTime(@NonNull ManualTimeSuggestion timeSignal) {
public boolean suggestManualTime(@NonNull ManualTimeSuggestion timeSignal) {
enforceSuggestManualTimePermission();
Objects.requireNonNull(timeSignal);
mHandler.post(() -> mTimeDetectorStrategy.suggestManualTime(timeSignal));
long token = Binder.clearCallingIdentity();
try {
return mTimeDetectorStrategy.suggestManualTime(timeSignal);
} finally {
Binder.restoreCallingIdentity(token);
}
}
@Override

View File

@@ -40,8 +40,13 @@ public interface TimeDetectorStrategy {
/** Process the suggested time from telephony sources. */
void suggestTelephonyTime(@NonNull TelephonyTimeSuggestion timeSuggestion);
/** Process the suggested manually entered time. */
void suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion);
/**
* Process the suggested manually entered time. Returns {@code false} if the suggestion was
* invalid, or the device configuration prevented the suggestion being used, {@code true} if the
* suggestion was accepted. A suggestion that is valid but does not change the time because it
* matches the current device time is considered accepted.
*/
boolean suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion);
/** Process the suggested time from network sources. */
void suggestNetworkTime(@NonNull NetworkTimeSuggestion timeSuggestion);

View File

@@ -164,15 +164,15 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
}
@Override
public synchronized void suggestManualTime(@NonNull ManualTimeSuggestion suggestion) {
public synchronized boolean suggestManualTime(@NonNull ManualTimeSuggestion suggestion) {
final TimestampedValue<Long> newUtcTime = suggestion.getUtcTime();
if (!validateSuggestionTime(newUtcTime, suggestion)) {
return;
return false;
}
String cause = "Manual time suggestion received: suggestion=" + suggestion;
setSystemClockIfRequired(ORIGIN_MANUAL, newUtcTime, cause);
return setSystemClockIfRequired(ORIGIN_MANUAL, newUtcTime, cause);
}
@Override
@@ -489,7 +489,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
}
@GuardedBy("this")
private void setSystemClockIfRequired(
private boolean setSystemClockIfRequired(
@Origin int origin, @NonNull TimestampedValue<Long> time, @NonNull String cause) {
boolean isOriginAutomatic = isOriginAutomatic(origin);
@@ -501,7 +501,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
+ ", time=" + time
+ ", cause=" + cause);
}
return;
return false;
}
} else {
if (mCallback.isAutoTimeDetectionEnabled()) {
@@ -511,13 +511,13 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
+ ", time=" + time
+ ", cause=" + cause);
}
return;
return false;
}
}
mCallback.acquireWakeLock();
try {
setSystemClockUnderWakeLock(origin, time, cause);
return setSystemClockUnderWakeLock(origin, time, cause);
} finally {
mCallback.releaseWakeLock();
}
@@ -528,7 +528,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
}
@GuardedBy("this")
private void setSystemClockUnderWakeLock(
private boolean setSystemClockUnderWakeLock(
int origin, @NonNull TimestampedValue<Long> newTime, @NonNull Object cause) {
long elapsedRealtimeMillis = mCallback.elapsedRealtimeMillis();
@@ -572,7 +572,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
+ " systemClockUpdateThreshold=" + systemClockUpdateThreshold
+ " absTimeDifference=" + absTimeDifference);
}
return;
return true;
}
mCallback.setSystemClock(newSystemClockMillis);
@@ -592,6 +592,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
} else {
mLastAutoSystemClockTimeSet = null;
}
return true;
}
/**

View File

@@ -24,6 +24,7 @@ import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.os.Binder;
import android.os.Handler;
import android.os.ResultReceiver;
import android.os.ShellCallback;
@@ -95,11 +96,16 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub
}
@Override
public void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion) {
public boolean suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion timeZoneSuggestion) {
enforceSuggestManualTimeZonePermission();
Objects.requireNonNull(timeZoneSuggestion);
mHandler.post(() -> mTimeZoneDetectorStrategy.suggestManualTimeZone(timeZoneSuggestion));
long token = Binder.clearCallingIdentity();
try {
return mTimeZoneDetectorStrategy.suggestManualTimeZone(timeZoneSuggestion);
} finally {
Binder.restoreCallingIdentity(token);
}
}
@Override

View File

@@ -37,9 +37,13 @@ import java.io.PrintWriter;
public interface TimeZoneDetectorStrategy {
/**
* Suggests a time zone for the device using manually-entered (i.e. user sourced) information.
* Suggests a time zone for the device, determined from the user's manually entered information.
* Returns {@code false} if the suggestion was invalid, or the device configuration prevented
* the suggestion being used, {@code true} if the suggestion was accepted. A suggestion that is
* valid but does not change the time zone because it matches the current device time zone is
* considered accepted.
*/
void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion suggestion);
boolean suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion suggestion);
/**
* Suggests a time zone for the device, or withdraws a previous suggestion if

View File

@@ -199,12 +199,13 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
}
@Override
public synchronized void suggestManualTimeZone(@NonNull ManualTimeZoneSuggestion suggestion) {
public synchronized boolean suggestManualTimeZone(
@NonNull ManualTimeZoneSuggestion suggestion) {
Objects.requireNonNull(suggestion);
String timeZoneId = suggestion.getZoneId();
String cause = "Manual time suggestion received: suggestion=" + suggestion;
setDeviceTimeZoneIfRequired(ORIGIN_MANUAL, timeZoneId, cause);
return setDeviceTimeZoneIfRequired(ORIGIN_MANUAL, timeZoneId, cause);
}
@Override
@@ -305,7 +306,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
}
@GuardedBy("this")
private void setDeviceTimeZoneIfRequired(
private boolean setDeviceTimeZoneIfRequired(
@Origin int origin, @NonNull String newZoneId, @NonNull String cause) {
Objects.requireNonNull(newZoneId);
Objects.requireNonNull(cause);
@@ -319,7 +320,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
+ ", newZoneId=" + newZoneId
+ ", cause=" + cause);
}
return;
return false;
}
} else {
if (mCallback.isAutoTimeZoneDetectionEnabled()) {
@@ -329,7 +330,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
+ ", newZoneId=" + newZoneId
+ ", cause=" + cause);
}
return;
return false;
}
}
@@ -346,7 +347,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
+ ", newZoneId=" + newZoneId
+ ", cause=" + cause);
}
return;
return true;
}
mCallback.setDeviceTimeZone(newZoneId);
@@ -359,6 +360,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
Slog.d(LOG_TAG, msg);
}
mTimeZoneChangesLog.log(msg);
return true;
}
private static boolean isOriginAutomatic(@Origin int origin) {

View File

@@ -132,15 +132,14 @@ public class TimeDetectorServiceTest {
doNothing().when(mMockContext).enforceCallingOrSelfPermission(anyString(), any());
ManualTimeSuggestion manualTimeSuggestion = createManualTimeSuggestion();
mTimeDetectorService.suggestManualTime(manualTimeSuggestion);
mTestHandler.assertTotalMessagesEnqueued(1);
assertTrue(mTimeDetectorService.suggestManualTime(manualTimeSuggestion));
mStubbedTimeDetectorStrategy.verifySuggestManualTimeCalled(manualTimeSuggestion);
verify(mMockContext).enforceCallingOrSelfPermission(
eq(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE),
anyString());
mTestHandler.waitForMessagesToBeProcessed();
mStubbedTimeDetectorStrategy.verifySuggestManualTimeCalled(manualTimeSuggestion);
}
@Test(expected = SecurityException.class)
@@ -232,8 +231,9 @@ public class TimeDetectorServiceTest {
}
@Override
public void suggestManualTime(ManualTimeSuggestion timeSuggestion) {
public boolean suggestManualTime(ManualTimeSuggestion timeSuggestion) {
mLastManualSuggestion = timeSuggestion;
return true;
}
@Override
@@ -263,11 +263,11 @@ public class TimeDetectorServiceTest {
assertEquals(expectedSuggestion, mLastTelephonySuggestion);
}
public void verifySuggestManualTimeCalled(ManualTimeSuggestion expectedSuggestion) {
void verifySuggestManualTimeCalled(ManualTimeSuggestion expectedSuggestion) {
assertEquals(expectedSuggestion, mLastManualSuggestion);
}
public void verifySuggestNetworkTimeCalled(NetworkTimeSuggestion expectedSuggestion) {
void verifySuggestNetworkTimeCalled(NetworkTimeSuggestion expectedSuggestion) {
assertEquals(expectedSuggestion, mLastNetworkSuggestion);
}

View File

@@ -403,7 +403,7 @@ public class TimeDetectorStrategyImplTest {
long expectedSystemClockMillis =
mScript.calculateTimeInMillisForNow(timeSuggestion.getUtcTime());
mScript.simulateManualTimeSuggestion(timeSuggestion)
mScript.simulateManualTimeSuggestion(timeSuggestion, true /* expectedResult */)
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis);
}
@@ -448,7 +448,7 @@ public class TimeDetectorStrategyImplTest {
long expectedManualClockMillis =
mScript.calculateTimeInMillisForNow(manualTimeSuggestion.getUtcTime());
mScript.simulateManualTimeSuggestion(manualTimeSuggestion)
mScript.simulateManualTimeSuggestion(manualTimeSuggestion, true /* expectedResult */)
.verifySystemClockWasSetAndResetCallTracking(expectedManualClockMillis)
.assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion);
@@ -481,7 +481,7 @@ public class TimeDetectorStrategyImplTest {
mScript.generateManualTimeSuggestion(ARBITRARY_TEST_TIME_MILLIS);
mScript.simulateTimePassing()
.simulateManualTimeSuggestion(timeSuggestion)
.simulateManualTimeSuggestion(timeSuggestion, false /* expectedResult */)
.verifySystemClockWasNotSetAndResetCallTracking();
}
@@ -763,8 +763,9 @@ public class TimeDetectorStrategyImplTest {
return this;
}
Script simulateManualTimeSuggestion(ManualTimeSuggestion timeSuggestion) {
mTimeDetectorStrategy.suggestManualTime(timeSuggestion);
Script simulateManualTimeSuggestion(
ManualTimeSuggestion timeSuggestion, boolean expectedResult) {
assertEquals(expectedResult, mTimeDetectorStrategy.suggestManualTime(timeSuggestion));
return this;
}

View File

@@ -96,15 +96,16 @@ public class TimeZoneDetectorServiceTest {
doNothing().when(mMockContext).enforceCallingOrSelfPermission(anyString(), any());
ManualTimeZoneSuggestion timeZoneSuggestion = createManualTimeZoneSuggestion();
mTimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion);
mTestHandler.assertTotalMessagesEnqueued(1);
boolean expectedResult = true; // The test strategy always returns true.
assertEquals(expectedResult,
mTimeZoneDetectorService.suggestManualTimeZone(timeZoneSuggestion));
mStubbedTimeZoneDetectorStrategy.verifySuggestManualTimeZoneCalled(timeZoneSuggestion);
verify(mMockContext).enforceCallingOrSelfPermission(
eq(android.Manifest.permission.SUGGEST_MANUAL_TIME_AND_ZONE),
anyString());
mTestHandler.waitForMessagesToBeProcessed();
mStubbedTimeZoneDetectorStrategy.verifySuggestManualTimeZoneCalled(timeZoneSuggestion);
}
@Test(expected = SecurityException.class)
@@ -187,8 +188,9 @@ public class TimeZoneDetectorServiceTest {
private boolean mDumpCalled;
@Override
public void suggestManualTimeZone(ManualTimeZoneSuggestion timeZoneSuggestion) {
public boolean suggestManualTimeZone(ManualTimeZoneSuggestion timeZoneSuggestion) {
mLastManualSuggestion = timeZoneSuggestion;
return true;
}
@Override

View File

@@ -98,7 +98,7 @@ public class TimeZoneDetectorStrategyImplTest {
.initializeAutoTimeZoneDetection(true)
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
script.suggestTelephonyTimeZone(slotIndex1TimeZoneSuggestion)
script.simulateTelephonyTimeZoneSuggestion(slotIndex1TimeZoneSuggestion)
.verifyTimeZoneNotSet();
// Assert internal service state.
@@ -111,7 +111,7 @@ public class TimeZoneDetectorStrategyImplTest {
assertEquals(expectedSlotIndex1ScoredSuggestion,
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
script.suggestTelephonyTimeZone(slotIndex2TimeZoneSuggestion)
script.simulateTelephonyTimeZoneSuggestion(slotIndex2TimeZoneSuggestion)
.verifyTimeZoneNotSet();
// Assert internal service state.
@@ -144,8 +144,7 @@ public class TimeZoneDetectorStrategyImplTest {
{
TelephonyTimeZoneSuggestion lowQualitySuggestion =
testCase.createSuggestion(SLOT_INDEX1, "America/New_York");
script.suggestTelephonyTimeZone(lowQualitySuggestion)
script.simulateTelephonyTimeZoneSuggestion(lowQualitySuggestion)
.verifyTimeZoneNotSet();
// Assert internal service state.
@@ -162,7 +161,7 @@ public class TimeZoneDetectorStrategyImplTest {
{
TelephonyTimeZoneSuggestion goodQualitySuggestion =
testCase2.createSuggestion(SLOT_INDEX1, "Europe/London");
script.suggestTelephonyTimeZone(goodQualitySuggestion)
script.simulateTelephonyTimeZoneSuggestion(goodQualitySuggestion)
.verifyTimeZoneSetAndReset(goodQualitySuggestion);
// Assert internal service state.
@@ -179,7 +178,7 @@ public class TimeZoneDetectorStrategyImplTest {
{
TelephonyTimeZoneSuggestion lowQualitySuggestion2 =
testCase.createSuggestion(SLOT_INDEX1, "America/Los_Angeles");
script.suggestTelephonyTimeZone(lowQualitySuggestion2)
script.simulateTelephonyTimeZoneSuggestion(lowQualitySuggestion2)
.verifyTimeZoneNotSet();
// Assert internal service state.
@@ -208,7 +207,7 @@ public class TimeZoneDetectorStrategyImplTest {
TelephonyTimeZoneSuggestion suggestion =
testCase.createSuggestion(SLOT_INDEX1, "Europe/London");
script.suggestTelephonyTimeZone(suggestion);
script.simulateTelephonyTimeZoneSuggestion(suggestion);
// When time zone detection is not enabled, the time zone suggestion will not be set
// regardless of the score.
@@ -288,7 +287,7 @@ public class TimeZoneDetectorStrategyImplTest {
new QualifiedTelephonyTimeZoneSuggestion(
zoneSlotIndex1Suggestion, testCase.expectedScore);
script.suggestTelephonyTimeZone(zoneSlotIndex1Suggestion);
script.simulateTelephonyTimeZoneSuggestion(zoneSlotIndex1Suggestion);
if (testCase.expectedScore >= TELEPHONY_SCORE_USAGE_THRESHOLD) {
script.verifyTimeZoneSetAndReset(zoneSlotIndex1Suggestion);
} else {
@@ -324,8 +323,8 @@ public class TimeZoneDetectorStrategyImplTest {
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID)
// Initialize the latest suggestions as empty so we don't need to worry about nulls
// below for the first loop.
.suggestTelephonyTimeZone(emptySlotIndex1Suggestion)
.suggestTelephonyTimeZone(emptySlotIndex2Suggestion)
.simulateTelephonyTimeZoneSuggestion(emptySlotIndex1Suggestion)
.simulateTelephonyTimeZoneSuggestion(emptySlotIndex2Suggestion)
.resetState();
for (SuggestionTestCase testCase : TEST_CASES) {
@@ -341,7 +340,7 @@ public class TimeZoneDetectorStrategyImplTest {
testCase.expectedScore);
// Start the test by making a suggestion for slotIndex1.
script.suggestTelephonyTimeZone(zoneSlotIndex1Suggestion);
script.simulateTelephonyTimeZoneSuggestion(zoneSlotIndex1Suggestion);
if (testCase.expectedScore >= TELEPHONY_SCORE_USAGE_THRESHOLD) {
script.verifyTimeZoneSetAndReset(zoneSlotIndex1Suggestion);
} else {
@@ -358,7 +357,7 @@ public class TimeZoneDetectorStrategyImplTest {
// SlotIndex2 then makes an alternative suggestion with an identical score. SlotIndex1's
// suggestion should still "win" if it is above the required threshold.
script.suggestTelephonyTimeZone(zoneSlotIndex2Suggestion);
script.simulateTelephonyTimeZoneSuggestion(zoneSlotIndex2Suggestion);
script.verifyTimeZoneNotSet();
// Assert internal service state.
@@ -373,7 +372,7 @@ public class TimeZoneDetectorStrategyImplTest {
// Withdrawing slotIndex1's suggestion should leave slotIndex2 as the new winner. Since
// the zoneId is different, the time zone setting should be updated if the score is high
// enough.
script.suggestTelephonyTimeZone(emptySlotIndex1Suggestion);
script.simulateTelephonyTimeZoneSuggestion(emptySlotIndex1Suggestion);
if (testCase.expectedScore >= TELEPHONY_SCORE_USAGE_THRESHOLD) {
script.verifyTimeZoneSetAndReset(zoneSlotIndex2Suggestion);
} else {
@@ -389,7 +388,7 @@ public class TimeZoneDetectorStrategyImplTest {
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
// Reset the state for the next loop.
script.suggestTelephonyTimeZone(emptySlotIndex2Suggestion)
script.simulateTelephonyTimeZoneSuggestion(emptySlotIndex2Suggestion)
.verifyTimeZoneNotSet();
assertEquals(expectedEmptySlotIndex1ScoredSuggestion,
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
@@ -417,10 +416,10 @@ public class TimeZoneDetectorStrategyImplTest {
testCase.createSuggestion(SLOT_INDEX1, "America/New_York");
// Initialization.
script.suggestTelephonyTimeZone(losAngelesSuggestion)
script.simulateTelephonyTimeZoneSuggestion(losAngelesSuggestion)
.verifyTimeZoneSetAndReset(losAngelesSuggestion);
// Suggest it again - it should not be set because it is already set.
script.suggestTelephonyTimeZone(losAngelesSuggestion)
script.simulateTelephonyTimeZoneSuggestion(losAngelesSuggestion)
.verifyTimeZoneNotSet();
// Toggling time zone detection should set the device time zone only if the current setting
@@ -433,7 +432,7 @@ public class TimeZoneDetectorStrategyImplTest {
// Simulate a user turning auto detection off, a new suggestion being made while auto
// detection is off, and the user turning it on again.
script.autoTimeZoneDetectionEnabled(false)
.suggestTelephonyTimeZone(newYorkSuggestion)
.simulateTelephonyTimeZoneSuggestion(newYorkSuggestion)
.verifyTimeZoneNotSet();
// Latest suggestion should be used.
script.autoTimeZoneDetectionEnabled(true)
@@ -447,7 +446,8 @@ public class TimeZoneDetectorStrategyImplTest {
.initializeAutoTimeZoneDetection(true);
// Auto time zone detection is enabled so the manual suggestion should be ignored.
script.suggestManualTimeZone(createManualSuggestion("Europe/Paris"))
script.simulateManualTimeZoneSuggestion(
createManualSuggestion("Europe/Paris"), false /* expectedResult */)
.verifyTimeZoneNotSet();
}
@@ -460,7 +460,7 @@ public class TimeZoneDetectorStrategyImplTest {
// Auto time zone detection is disabled so the manual suggestion should be used.
ManualTimeZoneSuggestion manualSuggestion = createManualSuggestion("Europe/Paris");
script.suggestManualTimeZone(manualSuggestion)
script.simulateManualTimeZoneSuggestion(manualSuggestion, true /* expectedResult */)
.verifyTimeZoneSetAndReset(manualSuggestion);
}
@@ -603,14 +603,16 @@ public class TimeZoneDetectorStrategyImplTest {
/**
* Simulates the time zone detection strategy receiving a telephony-originated suggestion.
*/
Script suggestTelephonyTimeZone(TelephonyTimeZoneSuggestion timeZoneSuggestion) {
Script simulateTelephonyTimeZoneSuggestion(TelephonyTimeZoneSuggestion timeZoneSuggestion) {
mTimeZoneDetectorStrategy.suggestTelephonyTimeZone(timeZoneSuggestion);
return this;
}
/** Simulates the time zone detection strategy receiving a user-originated suggestion. */
Script suggestManualTimeZone(ManualTimeZoneSuggestion manualTimeZoneSuggestion) {
mTimeZoneDetectorStrategy.suggestManualTimeZone(manualTimeZoneSuggestion);
Script simulateManualTimeZoneSuggestion(
ManualTimeZoneSuggestion manualTimeZoneSuggestion, boolean expectedResult) {
assertEquals(expectedResult,
mTimeZoneDetectorStrategy.suggestManualTimeZone(manualTimeZoneSuggestion));
return this;
}