mSecondaryProviderStates;
@@ -95,8 +95,8 @@ final class LocationTimeZoneManagerServiceState {
}
@NonNull
- Builder setLastSuggestion(@NonNull GeolocationTimeZoneSuggestion lastSuggestion) {
- mLastSuggestion = Objects.requireNonNull(lastSuggestion);
+ Builder setLastEvent(@NonNull LocationAlgorithmEvent lastEvent) {
+ mLastEvent = Objects.requireNonNull(lastEvent);
return this;
}
diff --git a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneManagerShellCommand.java b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneManagerShellCommand.java
index 60bbea77b6365..cefd0b578df8b 100644
--- a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneManagerShellCommand.java
+++ b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneManagerShellCommand.java
@@ -15,6 +15,10 @@
*/
package com.android.server.timezonedetector.location;
+import static android.app.time.DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_NOT_RUNNING;
+import static android.app.time.DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_NOT_SUPPORTED;
+import static android.app.time.DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_RUNNING;
+import static android.app.time.DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_UNKNOWN;
import static android.app.time.LocationTimeZoneManager.DUMP_STATE_OPTION_PROTO;
import static android.app.time.LocationTimeZoneManager.NULL_PACKAGE_NAME_TOKEN;
import static android.app.time.LocationTimeZoneManager.SERVICE_NAME;
@@ -51,9 +55,14 @@ import static com.android.server.timezonedetector.location.LocationTimeZoneProvi
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.app.time.DetectorStatusTypes.DetectionAlgorithmStatus;
import android.app.time.GeolocationTimeZoneSuggestionProto;
+import android.app.time.LocationTimeZoneAlgorithmStatus;
+import android.app.time.LocationTimeZoneAlgorithmStatusProto;
import android.app.time.LocationTimeZoneManagerProto;
import android.app.time.LocationTimeZoneManagerServiceStateProto;
+import android.app.time.LocationTimeZoneProviderEventProto;
+import android.app.time.TimeZoneDetectorProto;
import android.app.time.TimeZoneProviderStateProto;
import android.app.timezonedetector.TimeZoneDetector;
import android.os.ShellCommand;
@@ -62,6 +71,7 @@ import android.util.proto.ProtoOutputStream;
import com.android.internal.util.dump.DualDumpOutputStream;
import com.android.server.timezonedetector.GeolocationTimeZoneSuggestion;
+import com.android.server.timezonedetector.LocationAlgorithmEvent;
import com.android.server.timezonedetector.location.LocationTimeZoneProvider.ProviderState.ProviderStateEnum;
import com.android.server.timezonedetector.location.LocationTimeZoneProviderController.State;
@@ -239,19 +249,39 @@ class LocationTimeZoneManagerShellCommand extends ShellCommand {
outputStream = new DualDumpOutputStream(
new IndentingPrintWriter(getOutPrintWriter(), " "));
}
- if (state.getLastSuggestion() != null) {
- GeolocationTimeZoneSuggestion lastSuggestion = state.getLastSuggestion();
- long lastSuggestionToken = outputStream.start(
- "last_suggestion", LocationTimeZoneManagerServiceStateProto.LAST_SUGGESTION);
- for (String zoneId : lastSuggestion.getZoneIds()) {
- outputStream.write(
- "zone_ids" , GeolocationTimeZoneSuggestionProto.ZONE_IDS, zoneId);
+
+ if (state.getLastEvent() != null) {
+ LocationAlgorithmEvent lastEvent = state.getLastEvent();
+ long lastEventToken = outputStream.start(
+ "last_event", LocationTimeZoneManagerServiceStateProto.LAST_EVENT);
+
+ // lastEvent.algorithmStatus
+ LocationTimeZoneAlgorithmStatus algorithmStatus = lastEvent.getAlgorithmStatus();
+ long algorithmStatusToken = outputStream.start(
+ "algorithm_status", LocationTimeZoneProviderEventProto.ALGORITHM_STATUS);
+ outputStream.write("status", LocationTimeZoneAlgorithmStatusProto.STATUS,
+ convertDetectionAlgorithmStatusToEnumToProtoEnum(algorithmStatus.getStatus()));
+ outputStream.end(algorithmStatusToken);
+
+ // lastEvent.suggestion
+ if (lastEvent.getSuggestion() != null) {
+ long suggestionToken = outputStream.start(
+ "suggestion", LocationTimeZoneProviderEventProto.SUGGESTION);
+ GeolocationTimeZoneSuggestion lastSuggestion = lastEvent.getSuggestion();
+ for (String zoneId : lastSuggestion.getZoneIds()) {
+ outputStream.write(
+ "zone_ids", GeolocationTimeZoneSuggestionProto.ZONE_IDS, zoneId);
+ }
+ outputStream.end(suggestionToken);
}
- for (String debugInfo : lastSuggestion.getDebugInfo()) {
+
+ // lastEvent.debugInfo
+ for (String debugInfo : lastEvent.getDebugInfo()) {
outputStream.write(
- "debug_info", GeolocationTimeZoneSuggestionProto.DEBUG_INFO, debugInfo);
+ "debug_info", LocationTimeZoneProviderEventProto.DEBUG_INFO, debugInfo);
}
- outputStream.end(lastSuggestionToken);
+
+ outputStream.end(lastEventToken);
}
writeControllerStates(outputStream, state.getControllerStates());
@@ -330,6 +360,22 @@ class LocationTimeZoneManagerShellCommand extends ShellCommand {
}
}
+ private static int convertDetectionAlgorithmStatusToEnumToProtoEnum(
+ @DetectionAlgorithmStatus int statusEnum) {
+ switch (statusEnum) {
+ case DETECTION_ALGORITHM_STATUS_UNKNOWN:
+ return TimeZoneDetectorProto.DETECTION_ALGORITHM_STATUS_UNKNOWN;
+ case DETECTION_ALGORITHM_STATUS_NOT_SUPPORTED:
+ return TimeZoneDetectorProto.DETECTION_ALGORITHM_STATUS_NOT_SUPPORTED;
+ case DETECTION_ALGORITHM_STATUS_NOT_RUNNING:
+ return TimeZoneDetectorProto.DETECTION_ALGORITHM_STATUS_NOT_RUNNING;
+ case DETECTION_ALGORITHM_STATUS_RUNNING:
+ return TimeZoneDetectorProto.DETECTION_ALGORITHM_STATUS_RUNNING;
+ default:
+ throw new IllegalArgumentException("Unknown statusEnum=" + statusEnum);
+ }
+ }
+
private void reportError(@NonNull Throwable e) {
PrintWriter errPrintWriter = getErrPrintWriter();
errPrintWriter.println("Error: ");
diff --git a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProvider.java b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProvider.java
index b1fc4f5610339..15b57b1fbdfb6 100644
--- a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProvider.java
+++ b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProvider.java
@@ -16,6 +16,10 @@
package com.android.server.timezonedetector.location;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_IS_CERTAIN;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_IS_UNCERTAIN;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_PRESENT;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_READY;
import static android.service.timezone.TimeZoneProviderEvent.EVENT_TYPE_PERMANENT_FAILURE;
import static android.service.timezone.TimeZoneProviderEvent.EVENT_TYPE_SUGGESTION;
import static android.service.timezone.TimeZoneProviderEvent.EVENT_TYPE_UNCERTAIN;
@@ -33,6 +37,7 @@ import android.annotation.ElapsedRealtimeLong;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.app.time.LocationTimeZoneAlgorithmStatus.ProviderStatus;
import android.os.Handler;
import android.os.SystemClock;
import android.service.timezone.TimeZoneProviderEvent;
@@ -295,6 +300,34 @@ abstract class LocationTimeZoneProvider implements Dumpable {
|| stateEnum == PROVIDER_STATE_DESTROYED;
}
+ /**
+ * Maps the internal state enum value to one of the status values exposed to the layers
+ * above.
+ */
+ public @ProviderStatus int getProviderStatus() {
+ switch (stateEnum) {
+ case PROVIDER_STATE_STARTED_INITIALIZING:
+ return PROVIDER_STATUS_NOT_READY;
+ case PROVIDER_STATE_STARTED_CERTAIN:
+ return PROVIDER_STATUS_IS_CERTAIN;
+ case PROVIDER_STATE_STARTED_UNCERTAIN:
+ return PROVIDER_STATUS_IS_UNCERTAIN;
+ case PROVIDER_STATE_PERM_FAILED:
+ // Perm failed means the providers wasn't configured, configured properly,
+ // or has removed itself for other reasons, e.g. turned-down server.
+ return PROVIDER_STATUS_NOT_PRESENT;
+ case PROVIDER_STATE_STOPPED:
+ case PROVIDER_STATE_DESTROYED:
+ // This is a "safe" default that best describes a provider that isn't in one of
+ // the more obviously mapped states.
+ return PROVIDER_STATUS_NOT_READY;
+ case PROVIDER_STATE_UNKNOWN:
+ default:
+ throw new IllegalStateException(
+ "Unknown state enum:" + prettyPrintStateEnum(stateEnum));
+ }
+ }
+
/** Returns the status reported by the provider, if available. */
@Nullable
TimeZoneProviderStatus getReportedStatus() {
diff --git a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProviderController.java b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProviderController.java
index a9b9884e0074b..ed7ea00ec8f57 100644
--- a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProviderController.java
+++ b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProviderController.java
@@ -35,6 +35,10 @@ import android.annotation.ElapsedRealtimeLong;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
+import android.app.time.DetectorStatusTypes;
+import android.app.time.DetectorStatusTypes.DetectionAlgorithmStatus;
+import android.app.time.LocationTimeZoneAlgorithmStatus;
+import android.app.time.LocationTimeZoneAlgorithmStatus.ProviderStatus;
import android.service.timezone.TimeZoneProviderEvent;
import android.service.timezone.TimeZoneProviderSuggestion;
import android.util.IndentingPrintWriter;
@@ -44,6 +48,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.server.timezonedetector.ConfigurationInternal;
import com.android.server.timezonedetector.Dumpable;
import com.android.server.timezonedetector.GeolocationTimeZoneSuggestion;
+import com.android.server.timezonedetector.LocationAlgorithmEvent;
import com.android.server.timezonedetector.ReferenceWithHistory;
import com.android.server.timezonedetector.location.ThreadingDomain.SingleRunnableQueue;
@@ -83,8 +88,7 @@ import java.util.Objects;
* All incoming calls except for {@link
* LocationTimeZoneProviderController#dump(android.util.IndentingPrintWriter, String[])} must be
* made on the {@link android.os.Handler} thread of the {@link ThreadingDomain} passed to {@link
- * #LocationTimeZoneProviderController(ThreadingDomain, LocationTimeZoneProvider,
- * LocationTimeZoneProvider)}.
+ * #LocationTimeZoneProviderController}.
*
*
Provider / controller integration notes:
*
@@ -172,10 +176,10 @@ class LocationTimeZoneProviderController implements Dumpable {
@GuardedBy("mSharedLock")
private final ReferenceWithHistory<@State String> mState = new ReferenceWithHistory<>(10);
- /** Contains the last suggestion actually made, if there is one. */
+ /** Contains the last event reported, if there is one. */
@GuardedBy("mSharedLock")
@Nullable
- private GeolocationTimeZoneSuggestion mLastSuggestion;
+ private LocationAlgorithmEvent mLastEvent;
LocationTimeZoneProviderController(@NonNull ThreadingDomain threadingDomain,
@NonNull MetricsLogger metricsLogger,
@@ -213,7 +217,7 @@ class LocationTimeZoneProviderController implements Dumpable {
setState(STATE_PROVIDERS_INITIALIZING);
mPrimaryProvider.initialize(providerListener);
mSecondaryProvider.initialize(providerListener);
- setState(STATE_STOPPED);
+ setStateAndReportStatusOnlyEvent(STATE_STOPPED, "initialize()");
alterProvidersStartedStateIfRequired(
null /* oldConfiguration */, mCurrentUserConfiguration);
@@ -273,13 +277,51 @@ class LocationTimeZoneProviderController implements Dumpable {
// Enter destroyed state.
mPrimaryProvider.destroy();
mSecondaryProvider.destroy();
- setState(STATE_DESTROYED);
+ setStateAndReportStatusOnlyEvent(STATE_DESTROYED, "destroy()");
}
}
/**
- * Updates {@link #mState} if needed, and performs all the record-keeping / callbacks associated
- * with state changes.
+ * Sets the state and reports an event containing the algorithm status and a {@code null}
+ * suggestion.
+ */
+ @GuardedBy("mSharedLock")
+ private void setStateAndReportStatusOnlyEvent(@State String state, @NonNull String reason) {
+ setState(state);
+
+ final GeolocationTimeZoneSuggestion suggestion = null;
+ LocationAlgorithmEvent event =
+ new LocationAlgorithmEvent(generateCurrentAlgorithmStatus(), suggestion);
+ event.addDebugInfo(reason);
+ reportEvent(event);
+ }
+
+ /**
+ * Reports an event containing the algorithm status and the supplied suggestion.
+ */
+ @GuardedBy("mSharedLock")
+ private void reportSuggestionEvent(
+ @NonNull GeolocationTimeZoneSuggestion suggestion, @NonNull String reason) {
+ LocationTimeZoneAlgorithmStatus algorithmStatus = generateCurrentAlgorithmStatus();
+ LocationAlgorithmEvent event = new LocationAlgorithmEvent(
+ algorithmStatus, suggestion);
+ event.addDebugInfo(reason);
+ reportEvent(event);
+ }
+
+ /**
+ * Sends an event immediately. This method updates {@link #mLastEvent}.
+ */
+ @GuardedBy("mSharedLock")
+ private void reportEvent(@NonNull LocationAlgorithmEvent event) {
+ debugLog("makeSuggestion: suggestion=" + event);
+ mCallback.sendEvent(event);
+ mLastEvent = event;
+ }
+
+ /**
+ * Updates the state if needed. This includes setting {@link #mState} and performing all the
+ * record-keeping / callbacks associated with state changes.
*/
@GuardedBy("mSharedLock")
private void setState(@State String state) {
@@ -300,17 +342,7 @@ class LocationTimeZoneProviderController implements Dumpable {
// By definition, if both providers are stopped, the controller is uncertain.
cancelUncertaintyTimeout();
- // If a previous "certain" suggestion has been made, then a new "uncertain"
- // suggestion must now be made to indicate the controller {does not / no longer has}
- // an opinion and will not be sending further updates (until at least the providers are
- // re-started).
- if (Objects.equals(mState.get(), STATE_CERTAIN)) {
- GeolocationTimeZoneSuggestion suggestion = createUncertainSuggestion(
- mEnvironment.elapsedRealtimeMillis(),
- "Withdraw previous suggestion, providers are stopping: " + reason);
- makeSuggestion(suggestion, STATE_UNCERTAIN);
- }
- setState(STATE_STOPPED);
+ setStateAndReportStatusOnlyEvent(STATE_STOPPED, "Providers stopped: " + reason);
}
@GuardedBy("mSharedLock")
@@ -381,7 +413,7 @@ class LocationTimeZoneProviderController implements Dumpable {
// timeout started when the primary entered {started uncertain} should be cancelled.
if (newIsGeoDetectionExecutionEnabled) {
- setState(STATE_INITIALIZING);
+ setStateAndReportStatusOnlyEvent(STATE_INITIALIZING, "initializing()");
// Try to start the primary provider.
tryStartProvider(mPrimaryProvider, newConfiguration);
@@ -397,13 +429,11 @@ class LocationTimeZoneProviderController implements Dumpable {
ProviderState newSecondaryState = mSecondaryProvider.getCurrentState();
if (!newSecondaryState.isStarted()) {
// If both providers are {perm failed} then the controller immediately
- // reports uncertain.
- GeolocationTimeZoneSuggestion suggestion = createUncertainSuggestion(
- mEnvironment.elapsedRealtimeMillis(),
- "Providers are failed:"
- + " primary=" + mPrimaryProvider.getCurrentState()
- + " secondary=" + mPrimaryProvider.getCurrentState());
- makeSuggestion(suggestion, STATE_FAILED);
+ // reports the failure.
+ String reason = "Providers are failed:"
+ + " primary=" + mPrimaryProvider.getCurrentState()
+ + " secondary=" + mPrimaryProvider.getCurrentState();
+ setStateAndReportStatusOnlyEvent(STATE_FAILED, reason);
}
}
} else {
@@ -537,12 +567,10 @@ class LocationTimeZoneProviderController implements Dumpable {
// If both providers are now terminated, then a suggestion must be sent informing the
// time zone detector that there are no further updates coming in the future.
- GeolocationTimeZoneSuggestion suggestion = createUncertainSuggestion(
- mEnvironment.elapsedRealtimeMillis(),
- "Both providers are terminated:"
- + " primary=" + primaryCurrentState.provider
- + ", secondary=" + secondaryCurrentState.provider);
- makeSuggestion(suggestion, STATE_FAILED);
+ String reason = "Both providers are terminated:"
+ + " primary=" + primaryCurrentState.provider
+ + ", secondary=" + secondaryCurrentState.provider;
+ setStateAndReportStatusOnlyEvent(STATE_FAILED, reason);
}
}
@@ -615,6 +643,9 @@ class LocationTimeZoneProviderController implements Dumpable {
TimeZoneProviderSuggestion providerSuggestion = providerEvent.getSuggestion();
+ // Set the current state so it is correct when the suggestion event is created.
+ setState(STATE_CERTAIN);
+
// For the suggestion's effectiveFromElapsedMillis, use the time embedded in the provider's
// suggestion (which indicates the time when the provider detected the location used to
// establish the time zone).
@@ -623,15 +654,13 @@ class LocationTimeZoneProviderController implements Dumpable {
// this would hinder the ability for the time_zone_detector to judge which suggestions are
// based on newer information when comparing suggestions between different sources.
long effectiveFromElapsedMillis = providerSuggestion.getElapsedRealtimeMillis();
- GeolocationTimeZoneSuggestion geoSuggestion =
+ GeolocationTimeZoneSuggestion suggestion =
GeolocationTimeZoneSuggestion.createCertainSuggestion(
effectiveFromElapsedMillis, providerSuggestion.getTimeZoneIds());
-
- String debugInfo = "Event received provider=" + provider
+ String debugInfo = "Provider event received: provider=" + provider
+ ", providerEvent=" + providerEvent
+ ", suggestionCreationTime=" + mEnvironment.elapsedRealtimeMillis();
- geoSuggestion.addDebugInfo(debugInfo);
- makeSuggestion(geoSuggestion, STATE_CERTAIN);
+ reportSuggestionEvent(suggestion, debugInfo);
}
@Override
@@ -647,7 +676,7 @@ class LocationTimeZoneProviderController implements Dumpable {
+ mEnvironment.getProviderInitializationTimeoutFuzz());
ipw.println("uncertaintyDelay=" + mEnvironment.getUncertaintyDelay());
ipw.println("mState=" + mState.get());
- ipw.println("mLastSuggestion=" + mLastSuggestion);
+ ipw.println("mLastEvent=" + mLastEvent);
ipw.println("State history:");
ipw.increaseIndent(); // level 2
@@ -668,19 +697,6 @@ class LocationTimeZoneProviderController implements Dumpable {
}
}
- /**
- * Sends an immediate suggestion and enters a new state if needed. This method updates
- * mLastSuggestion and changes mStateEnum / reports the new state for metrics.
- */
- @GuardedBy("mSharedLock")
- private void makeSuggestion(@NonNull GeolocationTimeZoneSuggestion suggestion,
- @State String newState) {
- debugLog("makeSuggestion: suggestion=" + suggestion);
- mCallback.suggest(suggestion);
- mLastSuggestion = suggestion;
- setState(newState);
- }
-
/** Clears the uncertainty timeout. */
@GuardedBy("mSharedLock")
private void cancelUncertaintyTimeout() {
@@ -688,18 +704,16 @@ class LocationTimeZoneProviderController implements Dumpable {
}
/**
- * Called when a provider has become "uncertain" about the time zone.
+ * Called when a provider has reported it is "uncertain" about the time zone.
*
*
A provider is expected to report its uncertainty as soon as it becomes uncertain, as
* this enables the most flexibility for the controller to start other providers when there are
- * multiple ones available. The controller is therefore responsible for deciding when to make a
- * "uncertain" suggestion to the downstream time zone detector.
+ * multiple ones available. The controller is therefore responsible for deciding when to pass
+ * the "uncertain" suggestion to the downstream time zone detector.
*
*
This method schedules an "uncertainty" timeout (if one isn't already scheduled) to be
* triggered later if nothing else preempts it. It can be preempted if the provider becomes
- * certain (or does anything else that calls {@link
- * #makeSuggestion(GeolocationTimeZoneSuggestion, String)}) within {@link
- * Environment#getUncertaintyDelay()}. Preemption causes the scheduled
+ * certain within {@link Environment#getUncertaintyDelay()}. Preemption causes the scheduled
* "uncertainty" timeout to be cancelled. If the provider repeatedly sends uncertainty events
* within the uncertainty delay period, those events are effectively ignored (i.e. the timeout
* is not reset each time).
@@ -741,6 +755,8 @@ class LocationTimeZoneProviderController implements Dumpable {
synchronized (mSharedLock) {
long afterUncertaintyTimeoutElapsedMillis = mEnvironment.elapsedRealtimeMillis();
+ setState(STATE_UNCERTAIN);
+
// For the effectiveFromElapsedMillis suggestion property, use the
// uncertaintyStartedElapsedMillis. This is the time when the provider first reported
// uncertainty, i.e. before the uncertainty timeout.
@@ -749,30 +765,65 @@ class LocationTimeZoneProviderController implements Dumpable {
// the location_time_zone_manager finally confirms that the time zone was uncertain,
// but the suggestion property allows the information to be back-dated, which should
// help when comparing suggestions from different sources.
- GeolocationTimeZoneSuggestion suggestion = createUncertainSuggestion(
- uncertaintyStartedElapsedMillis,
- "Uncertainty timeout triggered for " + provider.getName() + ":"
- + " primary=" + mPrimaryProvider
- + ", secondary=" + mSecondaryProvider
- + ", uncertaintyStarted="
- + Duration.ofMillis(uncertaintyStartedElapsedMillis)
- + ", afterUncertaintyTimeout="
- + Duration.ofMillis(afterUncertaintyTimeoutElapsedMillis)
- + ", uncertaintyDelay=" + uncertaintyDelay
- );
- makeSuggestion(suggestion, STATE_UNCERTAIN);
+ GeolocationTimeZoneSuggestion suggestion =
+ GeolocationTimeZoneSuggestion.createUncertainSuggestion(
+ uncertaintyStartedElapsedMillis);
+ String debugInfo = "Uncertainty timeout triggered for " + provider.getName() + ":"
+ + " primary=" + mPrimaryProvider
+ + ", secondary=" + mSecondaryProvider
+ + ", uncertaintyStarted="
+ + Duration.ofMillis(uncertaintyStartedElapsedMillis)
+ + ", afterUncertaintyTimeout="
+ + Duration.ofMillis(afterUncertaintyTimeoutElapsedMillis)
+ + ", uncertaintyDelay=" + uncertaintyDelay;
+ reportSuggestionEvent(suggestion, debugInfo);
}
}
+ @GuardedBy("mSharedLock")
@NonNull
- private static GeolocationTimeZoneSuggestion createUncertainSuggestion(
- @ElapsedRealtimeLong long effectiveFromElapsedMillis,
- @NonNull String reason) {
- GeolocationTimeZoneSuggestion suggestion =
- GeolocationTimeZoneSuggestion.createUncertainSuggestion(
- effectiveFromElapsedMillis);
- suggestion.addDebugInfo(reason);
- return suggestion;
+ private LocationTimeZoneAlgorithmStatus generateCurrentAlgorithmStatus() {
+ @State String controllerState = mState.get();
+ ProviderState primaryProviderState = mPrimaryProvider.getCurrentState();
+ ProviderState secondaryProviderState = mSecondaryProvider.getCurrentState();
+ return createAlgorithmStatus(controllerState, primaryProviderState, secondaryProviderState);
+ }
+
+ @NonNull
+ private static LocationTimeZoneAlgorithmStatus createAlgorithmStatus(
+ @NonNull @State String controllerState,
+ @NonNull ProviderState primaryProviderState,
+ @NonNull ProviderState secondaryProviderState) {
+
+ @DetectionAlgorithmStatus int algorithmStatus =
+ mapControllerStateToDetectionAlgorithmStatus(controllerState);
+ @ProviderStatus int primaryProviderStatus = primaryProviderState.getProviderStatus();
+ @ProviderStatus int secondaryProviderStatus = secondaryProviderState.getProviderStatus();
+
+ // Neither provider is running. The algorithm is not running.
+ return new LocationTimeZoneAlgorithmStatus(algorithmStatus,
+ primaryProviderStatus, primaryProviderState.getReportedStatus(),
+ secondaryProviderStatus, secondaryProviderState.getReportedStatus());
+ }
+
+ /**
+ * Maps the internal state enum value to one of the status values exposed to the layers above.
+ */
+ private static @DetectionAlgorithmStatus int mapControllerStateToDetectionAlgorithmStatus(
+ @NonNull @State String controllerState) {
+ switch (controllerState) {
+ case STATE_INITIALIZING:
+ case STATE_PROVIDERS_INITIALIZING:
+ case STATE_CERTAIN:
+ case STATE_UNCERTAIN:
+ return DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_RUNNING;
+ case STATE_STOPPED:
+ case STATE_DESTROYED:
+ case STATE_FAILED:
+ case STATE_UNKNOWN:
+ default:
+ return DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_NOT_RUNNING;
+ }
}
/**
@@ -798,8 +849,8 @@ class LocationTimeZoneProviderController implements Dumpable {
synchronized (mSharedLock) {
LocationTimeZoneManagerServiceState.Builder builder =
new LocationTimeZoneManagerServiceState.Builder();
- if (mLastSuggestion != null) {
- builder.setLastSuggestion(mLastSuggestion);
+ if (mLastEvent != null) {
+ builder.setLastEvent(mLastEvent);
}
builder.setControllerState(mState.get())
.setStateChanges(mRecordedStates)
@@ -867,17 +918,15 @@ class LocationTimeZoneProviderController implements Dumpable {
abstract static class Callback {
@NonNull protected final ThreadingDomain mThreadingDomain;
- @NonNull protected final Object mSharedLock;
Callback(@NonNull ThreadingDomain threadingDomain) {
mThreadingDomain = Objects.requireNonNull(threadingDomain);
- mSharedLock = threadingDomain.getLockObject();
}
/**
* Suggests the latest time zone state for the device.
*/
- abstract void suggest(@NonNull GeolocationTimeZoneSuggestion suggestion);
+ abstract void sendEvent(@NonNull LocationAlgorithmEvent event);
}
/**
diff --git a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProviderControllerCallbackImpl.java b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProviderControllerCallbackImpl.java
index 0c751aaa62c7c..7eb7e01b539a3 100644
--- a/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProviderControllerCallbackImpl.java
+++ b/services/core/java/com/android/server/timezonedetector/location/LocationTimeZoneProviderControllerCallbackImpl.java
@@ -19,7 +19,7 @@ package com.android.server.timezonedetector.location;
import android.annotation.NonNull;
import com.android.server.LocalServices;
-import com.android.server.timezonedetector.GeolocationTimeZoneSuggestion;
+import com.android.server.timezonedetector.LocationAlgorithmEvent;
import com.android.server.timezonedetector.TimeZoneDetectorInternal;
/**
@@ -34,11 +34,11 @@ class LocationTimeZoneProviderControllerCallbackImpl
}
@Override
- void suggest(@NonNull GeolocationTimeZoneSuggestion suggestion) {
+ void sendEvent(@NonNull LocationAlgorithmEvent event) {
mThreadingDomain.assertCurrentThread();
TimeZoneDetectorInternal timeZoneDetector =
LocalServices.getService(TimeZoneDetectorInternal.class);
- timeZoneDetector.suggestGeolocationTimeZone(suggestion);
+ timeZoneDetector.handleLocationAlgorithmEvent(event);
}
}
diff --git a/services/tests/servicestests/src/com/android/server/timezonedetector/FakeTimeZoneDetectorStrategy.java b/services/tests/servicestests/src/com/android/server/timezonedetector/FakeTimeZoneDetectorStrategy.java
index fed8b4040aba8..bcdc65c19330d 100644
--- a/services/tests/servicestests/src/com/android/server/timezonedetector/FakeTimeZoneDetectorStrategy.java
+++ b/services/tests/servicestests/src/com/android/server/timezonedetector/FakeTimeZoneDetectorStrategy.java
@@ -21,12 +21,14 @@ import android.annotation.NonNull;
import android.annotation.UserIdInt;
import android.app.time.TimeZoneCapabilitiesAndConfig;
import android.app.time.TimeZoneConfiguration;
+import android.app.time.TimeZoneDetectorStatus;
import android.app.time.TimeZoneState;
import android.app.timezonedetector.ManualTimeZoneSuggestion;
import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
import android.util.IndentingPrintWriter;
import java.util.ArrayList;
+import java.util.Objects;
public class FakeTimeZoneDetectorStrategy implements TimeZoneDetectorStrategy {
@@ -34,14 +36,17 @@ public class FakeTimeZoneDetectorStrategy implements TimeZoneDetectorStrategy {
new FakeServiceConfigAccessor();
private final ArrayList mListeners = new ArrayList<>();
private TimeZoneState mTimeZoneState;
+ private TimeZoneDetectorStatus mStatus;
public FakeTimeZoneDetectorStrategy() {
mFakeServiceConfigAccessor.addConfigurationInternalChangeListener(
this::notifyChangeListeners);
}
- public void initializeConfiguration(ConfigurationInternal configuration) {
+ public void initializeConfigurationAndStatus(
+ ConfigurationInternal configuration, TimeZoneDetectorStatus status) {
mFakeServiceConfigAccessor.initializeCurrentUserConfiguration(configuration);
+ mStatus = Objects.requireNonNull(status);
}
@Override
@@ -57,6 +62,7 @@ public class FakeTimeZoneDetectorStrategy implements TimeZoneDetectorStrategy {
assertEquals("Multi-user testing not supported",
configurationInternal.getUserId(), userId);
return new TimeZoneCapabilitiesAndConfig(
+ mStatus,
configurationInternal.asCapabilities(bypassUserPolicyChecks),
configurationInternal.asConfiguration());
}
@@ -90,7 +96,7 @@ public class FakeTimeZoneDetectorStrategy implements TimeZoneDetectorStrategy {
}
@Override
- public void suggestGeolocationTimeZone(GeolocationTimeZoneSuggestion timeZoneSuggestion) {
+ public void handleLocationAlgorithmEvent(LocationAlgorithmEvent locationAlgorithmEvent) {
}
@Override
diff --git a/services/tests/servicestests/src/com/android/server/timezonedetector/GeolocationTimeZoneSuggestionTest.java b/services/tests/servicestests/src/com/android/server/timezonedetector/GeolocationTimeZoneSuggestionTest.java
index 0f667b3a690b2..602842addff23 100644
--- a/services/tests/servicestests/src/com/android/server/timezonedetector/GeolocationTimeZoneSuggestionTest.java
+++ b/services/tests/servicestests/src/com/android/server/timezonedetector/GeolocationTimeZoneSuggestionTest.java
@@ -16,13 +16,8 @@
package com.android.server.timezonedetector;
-import static com.android.server.timezonedetector.ShellCommandTestSupport.createShellCommandWithArgsAndOptions;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNull;
-
-import android.os.ShellCommand;
import org.junit.Test;
@@ -49,11 +44,6 @@ public class GeolocationTimeZoneSuggestionTest {
assertEquals(certain1v1, certain1v2);
assertEquals(certain1v2, certain1v1);
- // DebugInfo must not be considered in equals().
- certain1v1.addDebugInfo("Debug info 1");
- certain1v2.addDebugInfo("Debug info 2");
- assertEquals(certain1v1, certain1v2);
-
long time2 = 2222L;
GeolocationTimeZoneSuggestion certain2 =
GeolocationTimeZoneSuggestion.createCertainSuggestion(time2, ARBITRARY_ZONE_IDS1);
@@ -71,40 +61,4 @@ public class GeolocationTimeZoneSuggestionTest {
assertNotEquals(certain1v1, certain3);
assertNotEquals(certain3, certain1v1);
}
-
- @Test(expected = IllegalArgumentException.class)
- public void testParseCommandLineArg_noZoneIdsArg() {
- ShellCommand testShellCommand =
- createShellCommandWithArgsAndOptions(Collections.emptyList());
- GeolocationTimeZoneSuggestion.parseCommandLineArg(testShellCommand);
- }
-
- @Test
- public void testParseCommandLineArg_zoneIdsUncertain() {
- ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--zone_ids UNCERTAIN");
- assertNull(GeolocationTimeZoneSuggestion.parseCommandLineArg(testShellCommand)
- .getZoneIds());
- }
-
- @Test
- public void testParseCommandLineArg_zoneIdsEmpty() {
- ShellCommand testShellCommand = createShellCommandWithArgsAndOptions("--zone_ids EMPTY");
- assertEquals(Collections.emptyList(),
- GeolocationTimeZoneSuggestion.parseCommandLineArg(testShellCommand).getZoneIds());
- }
-
- @Test
- public void testParseCommandLineArg_zoneIdsPresent() {
- ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
- "--zone_ids Europe/London,Europe/Paris");
- assertEquals(Arrays.asList("Europe/London", "Europe/Paris"),
- GeolocationTimeZoneSuggestion.parseCommandLineArg(testShellCommand).getZoneIds());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testParseCommandLineArg_unknownArgument() {
- ShellCommand testShellCommand = createShellCommandWithArgsAndOptions("--bad_arg 0");
- GeolocationTimeZoneSuggestion.parseCommandLineArg(testShellCommand);
- }
}
diff --git a/services/tests/servicestests/src/com/android/server/timezonedetector/LocationAlgorithmEventTest.java b/services/tests/servicestests/src/com/android/server/timezonedetector/LocationAlgorithmEventTest.java
new file mode 100644
index 0000000000000..4c14014405f47
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/timezonedetector/LocationAlgorithmEventTest.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2022 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 com.android.server.timezonedetector;
+
+import static android.app.time.DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_RUNNING;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_IS_CERTAIN;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_PRESENT;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_READY;
+import static android.service.timezone.TimeZoneProviderStatus.DEPENDENCY_STATUS_NOT_APPLICABLE;
+import static android.service.timezone.TimeZoneProviderStatus.DEPENDENCY_STATUS_OK;
+import static android.service.timezone.TimeZoneProviderStatus.OPERATION_STATUS_OK;
+
+import static com.android.server.timezonedetector.ShellCommandTestSupport.createShellCommandWithArgsAndOptions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import android.app.time.LocationTimeZoneAlgorithmStatus;
+import android.os.ShellCommand;
+import android.service.timezone.TimeZoneProviderStatus;
+
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+public class LocationAlgorithmEventTest {
+
+ public static final TimeZoneProviderStatus ARBITRARY_PROVIDER_STATUS =
+ new TimeZoneProviderStatus.Builder()
+ .setConnectivityDependencyStatus(DEPENDENCY_STATUS_OK)
+ .setLocationDetectionDependencyStatus(DEPENDENCY_STATUS_NOT_APPLICABLE)
+ .setTimeZoneResolutionOperationStatus(OPERATION_STATUS_OK)
+ .build();
+
+ public static final LocationTimeZoneAlgorithmStatus ARBITRARY_LOCATION_ALGORITHM_STATUS =
+ new LocationTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING,
+ PROVIDER_STATUS_IS_CERTAIN, ARBITRARY_PROVIDER_STATUS,
+ PROVIDER_STATUS_NOT_PRESENT, null);
+
+ @Test
+ public void testEquals() {
+ GeolocationTimeZoneSuggestion suggestion1 =
+ GeolocationTimeZoneSuggestion.createUncertainSuggestion(1111L);
+ LocationTimeZoneAlgorithmStatus status1 = new LocationTimeZoneAlgorithmStatus(
+ DETECTION_ALGORITHM_STATUS_RUNNING,
+ PROVIDER_STATUS_NOT_PRESENT, null, PROVIDER_STATUS_NOT_PRESENT, null);
+ LocationAlgorithmEvent event1v1 = new LocationAlgorithmEvent(status1, suggestion1);
+ assertEqualsAndHashCode(event1v1, event1v1);
+
+ LocationAlgorithmEvent event1v2 = new LocationAlgorithmEvent(status1, suggestion1);
+ assertEqualsAndHashCode(event1v1, event1v2);
+
+ GeolocationTimeZoneSuggestion suggestion2 =
+ GeolocationTimeZoneSuggestion.createUncertainSuggestion(2222L);
+ LocationAlgorithmEvent event2 = new LocationAlgorithmEvent(status1, suggestion2);
+ assertNotEquals(event1v1, event2);
+
+ LocationTimeZoneAlgorithmStatus status2 = new LocationTimeZoneAlgorithmStatus(
+ DETECTION_ALGORITHM_STATUS_RUNNING,
+ PROVIDER_STATUS_NOT_PRESENT, null, PROVIDER_STATUS_NOT_READY, null);
+ LocationAlgorithmEvent event3 = new LocationAlgorithmEvent(status2, suggestion1);
+ assertNotEquals(event1v1, event3);
+
+ // DebugInfo must not be considered in equals().
+ event1v1.addDebugInfo("Debug info 1");
+ event1v2.addDebugInfo("Debug info 2");
+ assertEquals(event1v1, event1v2);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testParseCommandLineArg_noStatus() {
+ GeolocationTimeZoneSuggestion suggestion =
+ GeolocationTimeZoneSuggestion.createUncertainSuggestion(1111L);
+ ShellCommand testShellCommand =
+ createShellCommandWithArgsAndOptions(
+ Arrays.asList("--suggestion", suggestion.toString()));
+
+ LocationAlgorithmEvent.parseCommandLineArg(testShellCommand);
+ }
+
+ @Test
+ public void testParseCommandLineArg_noSuggestion() {
+ GeolocationTimeZoneSuggestion suggestion = null;
+ LocationAlgorithmEvent event = new LocationAlgorithmEvent(
+ ARBITRARY_LOCATION_ALGORITHM_STATUS, suggestion);
+ ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
+ Arrays.asList("--status", event.getAlgorithmStatus().toString()));
+
+ assertEquals(event, LocationAlgorithmEvent.parseCommandLineArg(testShellCommand));
+ }
+
+ @Test
+ public void testParseCommandLineArg_suggestionUncertain() {
+ GeolocationTimeZoneSuggestion suggestion =
+ GeolocationTimeZoneSuggestion.createUncertainSuggestion(1111L);
+ LocationAlgorithmEvent event = new LocationAlgorithmEvent(
+ ARBITRARY_LOCATION_ALGORITHM_STATUS, suggestion);
+ ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
+ Arrays.asList("--status", event.getAlgorithmStatus().toString(),
+ "--suggestion", "UNCERTAIN"));
+
+ LocationAlgorithmEvent parsedEvent =
+ LocationAlgorithmEvent.parseCommandLineArg(testShellCommand);
+ assertEquals(event.getAlgorithmStatus(), parsedEvent.getAlgorithmStatus());
+ assertEquals(event.getSuggestion().getZoneIds(), parsedEvent.getSuggestion().getZoneIds());
+ }
+
+ @Test
+ public void testParseCommandLineArg_suggestionEmpty() {
+ GeolocationTimeZoneSuggestion suggestion =
+ GeolocationTimeZoneSuggestion.createCertainSuggestion(
+ 1111L, Collections.emptyList());
+ LocationAlgorithmEvent event = new LocationAlgorithmEvent(
+ ARBITRARY_LOCATION_ALGORITHM_STATUS, suggestion);
+ ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
+ Arrays.asList("--status", event.getAlgorithmStatus().toString(),
+ "--suggestion", "EMPTY"));
+
+ LocationAlgorithmEvent parsedEvent =
+ LocationAlgorithmEvent.parseCommandLineArg(testShellCommand);
+ assertEquals(event.getAlgorithmStatus(), parsedEvent.getAlgorithmStatus());
+ assertEquals(event.getSuggestion().getZoneIds(), parsedEvent.getSuggestion().getZoneIds());
+ }
+
+ @Test
+ public void testParseCommandLineArg_suggestionPresent() {
+ GeolocationTimeZoneSuggestion suggestion =
+ GeolocationTimeZoneSuggestion.createCertainSuggestion(
+ 1111L, Arrays.asList("Europe/London", "Europe/Paris"));
+ LocationAlgorithmEvent event = new LocationAlgorithmEvent(
+ ARBITRARY_LOCATION_ALGORITHM_STATUS, suggestion);
+ ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
+ Arrays.asList("--status", event.getAlgorithmStatus().toString(),
+ "--suggestion", "Europe/London,Europe/Paris"));
+
+ LocationAlgorithmEvent parsedEvent =
+ LocationAlgorithmEvent.parseCommandLineArg(testShellCommand);
+ assertEquals(event.getAlgorithmStatus(), parsedEvent.getAlgorithmStatus());
+ assertEquals(event.getSuggestion().getZoneIds(), parsedEvent.getSuggestion().getZoneIds());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testParseCommandLineArg_unknownArgument() {
+ GeolocationTimeZoneSuggestion suggestion =
+ GeolocationTimeZoneSuggestion.createCertainSuggestion(
+ 1111L, Arrays.asList("Europe/London", "Europe/Paris"));
+ LocationAlgorithmEvent event = new LocationAlgorithmEvent(
+ ARBITRARY_LOCATION_ALGORITHM_STATUS, suggestion);
+ ShellCommand testShellCommand = createShellCommandWithArgsAndOptions(
+ Arrays.asList("--status", event.getAlgorithmStatus().toString(),
+ "--suggestion", "Europe/London,Europe/Paris", "--bad_arg"));
+ LocationAlgorithmEvent.parseCommandLineArg(testShellCommand);
+ }
+
+ private static void assertEqualsAndHashCode(Object one, Object two) {
+ assertEquals(one, two);
+ assertEquals(two, one);
+ assertEquals(one.hashCode(), two.hashCode());
+ }
+}
diff --git a/services/tests/servicestests/src/com/android/server/timezonedetector/MetricsTimeZoneDetectorStateTest.java b/services/tests/servicestests/src/com/android/server/timezonedetector/MetricsTimeZoneDetectorStateTest.java
index 223c532330650..ea801e887c4c5 100644
--- a/services/tests/servicestests/src/com/android/server/timezonedetector/MetricsTimeZoneDetectorStateTest.java
+++ b/services/tests/servicestests/src/com/android/server/timezonedetector/MetricsTimeZoneDetectorStateTest.java
@@ -16,6 +16,10 @@
package com.android.server.timezonedetector;
+import static android.app.time.DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_RUNNING;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_IS_CERTAIN;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_PRESENT;
+
import static com.android.server.timezonedetector.MetricsTimeZoneDetectorState.DETECTION_MODE_GEO;
import static org.junit.Assert.assertEquals;
@@ -23,6 +27,7 @@ import static org.junit.Assert.assertNull;
import android.annotation.ElapsedRealtimeLong;
import android.annotation.UserIdInt;
+import android.app.time.LocationTimeZoneAlgorithmStatus;
import android.app.timezonedetector.ManualTimeZoneSuggestion;
import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
@@ -31,6 +36,7 @@ import com.android.server.timezonedetector.MetricsTimeZoneDetectorState.MetricsT
import org.junit.Test;
import java.util.Arrays;
+import java.util.List;
import java.util.function.Function;
/** Tests for {@link MetricsTimeZoneDetectorState}. */
@@ -38,6 +44,9 @@ public class MetricsTimeZoneDetectorStateTest {
private static final @UserIdInt int ARBITRARY_USER_ID = 1;
private static final @ElapsedRealtimeLong long ARBITRARY_ELAPSED_REALTIME_MILLIS = 1234L;
+ private static final LocationTimeZoneAlgorithmStatus ARBITRARY_CERTAIN_STATUS =
+ new LocationTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING,
+ PROVIDER_STATUS_IS_CERTAIN, null, PROVIDER_STATUS_NOT_PRESENT, null);
private static final String DEVICE_TIME_ZONE_ID = "DeviceTimeZoneId";
private static final ManualTimeZoneSuggestion MANUAL_TIME_ZONE_SUGGESTION =
@@ -50,11 +59,14 @@ public class MetricsTimeZoneDetectorStateTest {
.setQuality(TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE)
.build();
- private static final GeolocationTimeZoneSuggestion GEOLOCATION_TIME_ZONE_SUGGESTION =
+ public static final GeolocationTimeZoneSuggestion GEOLOCATION_SUGGESTION_CERTAIN =
GeolocationTimeZoneSuggestion.createCertainSuggestion(
ARBITRARY_ELAPSED_REALTIME_MILLIS,
Arrays.asList("GeoTimeZoneId1", "GeoTimeZoneId2"));
+ private static final LocationAlgorithmEvent LOCATION_ALGORITHM_EVENT =
+ new LocationAlgorithmEvent(ARBITRARY_CERTAIN_STATUS, GEOLOCATION_SUGGESTION_CERTAIN);
+
private final OrdinalGenerator mOrdinalGenerator =
new OrdinalGenerator<>(Function.identity());
@@ -68,7 +80,7 @@ public class MetricsTimeZoneDetectorStateTest {
MetricsTimeZoneDetectorState metricsTimeZoneDetectorState =
MetricsTimeZoneDetectorState.create(mOrdinalGenerator, configurationInternal,
DEVICE_TIME_ZONE_ID, MANUAL_TIME_ZONE_SUGGESTION,
- TELEPHONY_TIME_ZONE_SUGGESTION, GEOLOCATION_TIME_ZONE_SUGGESTION);
+ TELEPHONY_TIME_ZONE_SUGGESTION, LOCATION_ALGORITHM_EVENT);
// Assert the content.
assertCommonConfiguration(configurationInternal, metricsTimeZoneDetectorState);
@@ -88,9 +100,10 @@ public class MetricsTimeZoneDetectorStateTest {
assertEquals(expectedTelephonySuggestion,
metricsTimeZoneDetectorState.getLatestTelephonySuggestion());
+ List expectedZoneIds = LOCATION_ALGORITHM_EVENT.getSuggestion().getZoneIds();
MetricsTimeZoneSuggestion expectedGeoSuggestion =
MetricsTimeZoneSuggestion.createCertain(
- GEOLOCATION_TIME_ZONE_SUGGESTION.getZoneIds().toArray(new String[0]),
+ expectedZoneIds.toArray(new String[0]),
new int[] { 3, 4 });
assertEquals(expectedGeoSuggestion,
metricsTimeZoneDetectorState.getLatestGeolocationSuggestion());
@@ -106,7 +119,7 @@ public class MetricsTimeZoneDetectorStateTest {
MetricsTimeZoneDetectorState metricsTimeZoneDetectorState =
MetricsTimeZoneDetectorState.create(mOrdinalGenerator, configurationInternal,
DEVICE_TIME_ZONE_ID, MANUAL_TIME_ZONE_SUGGESTION,
- TELEPHONY_TIME_ZONE_SUGGESTION, GEOLOCATION_TIME_ZONE_SUGGESTION);
+ TELEPHONY_TIME_ZONE_SUGGESTION, LOCATION_ALGORITHM_EVENT);
// Assert the content.
assertCommonConfiguration(configurationInternal, metricsTimeZoneDetectorState);
diff --git a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorInternalImplTest.java b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorInternalImplTest.java
index 8909832391a48..a02c8ca001ce5 100644
--- a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorInternalImplTest.java
+++ b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorInternalImplTest.java
@@ -16,14 +16,22 @@
package com.android.server.timezonedetector;
+import static android.app.time.DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_RUNNING;
+import static android.app.time.DetectorStatusTypes.DETECTOR_STATUS_RUNNING;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_IS_CERTAIN;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_PRESENT;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
+import android.app.time.LocationTimeZoneAlgorithmStatus;
+import android.app.time.TelephonyTimeZoneAlgorithmStatus;
import android.app.time.TimeZoneCapabilitiesAndConfig;
import android.app.time.TimeZoneConfiguration;
+import android.app.time.TimeZoneDetectorStatus;
import android.app.timezonedetector.ManualTimeZoneSuggestion;
import android.content.Context;
import android.os.HandlerThread;
@@ -41,6 +49,15 @@ import java.util.List;
@RunWith(AndroidJUnit4.class)
public class TimeZoneDetectorInternalImplTest {
+ private static final TelephonyTimeZoneAlgorithmStatus ARBITRARY_TELEPHONY_STATUS =
+ new TelephonyTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING);
+ private static final LocationTimeZoneAlgorithmStatus ARBITRARY_LOCATION_CERTAIN_STATUS =
+ new LocationTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING,
+ PROVIDER_STATUS_IS_CERTAIN, null, PROVIDER_STATUS_NOT_PRESENT, null);
+ private static final TimeZoneDetectorStatus ARBITRARY_DETECTOR_STATUS =
+ new TimeZoneDetectorStatus(DETECTOR_STATUS_RUNNING, ARBITRARY_TELEPHONY_STATUS,
+ ARBITRARY_LOCATION_CERTAIN_STATUS);
+
private static final long ARBITRARY_ELAPSED_REALTIME_MILLIS = 1234L;
private static final String ARBITRARY_ZONE_ID = "TestZoneId";
private static final List ARBITRARY_ZONE_IDS = Arrays.asList(ARBITRARY_ZONE_ID);
@@ -81,7 +98,8 @@ public class TimeZoneDetectorInternalImplTest {
public void testGetCapabilitiesAndConfigForDpm() throws Exception {
final boolean autoDetectionEnabled = true;
ConfigurationInternal testConfig = createConfigurationInternal(autoDetectionEnabled);
- mFakeTimeZoneDetectorStrategySpy.initializeConfiguration(testConfig);
+ TimeZoneDetectorStatus testStatus = ARBITRARY_DETECTOR_STATUS;
+ mFakeTimeZoneDetectorStrategySpy.initializeConfigurationAndStatus(testConfig, testStatus);
TimeZoneCapabilitiesAndConfig actualCapabilitiesAndConfig =
mTimeZoneDetectorInternal.getCapabilitiesAndConfigForDpm();
@@ -93,6 +111,7 @@ public class TimeZoneDetectorInternalImplTest {
TimeZoneCapabilitiesAndConfig expectedCapabilitiesAndConfig =
new TimeZoneCapabilitiesAndConfig(
+ testStatus,
testConfig.asCapabilities(expectedBypassUserPolicyChecks),
testConfig.asConfiguration());
assertEquals(expectedCapabilitiesAndConfig, actualCapabilitiesAndConfig);
@@ -103,7 +122,9 @@ public class TimeZoneDetectorInternalImplTest {
final boolean autoDetectionEnabled = false;
ConfigurationInternal initialConfigurationInternal =
createConfigurationInternal(autoDetectionEnabled);
- mFakeTimeZoneDetectorStrategySpy.initializeConfiguration(initialConfigurationInternal);
+ TimeZoneDetectorStatus testStatus = ARBITRARY_DETECTOR_STATUS;
+ mFakeTimeZoneDetectorStrategySpy.initializeConfigurationAndStatus(
+ initialConfigurationInternal, testStatus);
TimeZoneConfiguration timeConfiguration = new TimeZoneConfiguration.Builder()
.setAutoDetectionEnabled(true)
@@ -131,13 +152,15 @@ public class TimeZoneDetectorInternalImplTest {
}
@Test
- public void testSuggestGeolocationTimeZone() throws Exception {
+ public void testHandleLocationAlgorithmEvent() throws Exception {
GeolocationTimeZoneSuggestion timeZoneSuggestion = createGeolocationTimeZoneSuggestion();
- mTimeZoneDetectorInternal.suggestGeolocationTimeZone(timeZoneSuggestion);
+ LocationAlgorithmEvent suggestionEvent = new LocationAlgorithmEvent(
+ ARBITRARY_LOCATION_CERTAIN_STATUS, timeZoneSuggestion);
+ mTimeZoneDetectorInternal.handleLocationAlgorithmEvent(suggestionEvent);
mTestHandler.assertTotalMessagesEnqueued(1);
mTestHandler.waitForMessagesToBeProcessed();
- verify(mFakeTimeZoneDetectorStrategySpy).suggestGeolocationTimeZone(timeZoneSuggestion);
+ verify(mFakeTimeZoneDetectorStrategySpy).handleLocationAlgorithmEvent(suggestionEvent);
}
private static ManualTimeZoneSuggestion createManualTimeZoneSuggestion() {
return new ManualTimeZoneSuggestion(ARBITRARY_ZONE_ID);
diff --git a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java
index d8346ee4355b2..d9d8053e6220c 100644
--- a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorServiceTest.java
@@ -16,6 +16,11 @@
package com.android.server.timezonedetector;
+import static android.app.time.DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_RUNNING;
+import static android.app.time.DetectorStatusTypes.DETECTOR_STATUS_RUNNING;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_IS_CERTAIN;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_PRESENT;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
@@ -34,8 +39,11 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import android.app.time.ITimeZoneDetectorListener;
+import android.app.time.LocationTimeZoneAlgorithmStatus;
+import android.app.time.TelephonyTimeZoneAlgorithmStatus;
import android.app.time.TimeZoneCapabilitiesAndConfig;
import android.app.time.TimeZoneConfiguration;
+import android.app.time.TimeZoneDetectorStatus;
import android.app.time.TimeZoneState;
import android.app.timezonedetector.ManualTimeZoneSuggestion;
import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
@@ -59,6 +67,13 @@ import java.util.List;
@RunWith(AndroidJUnit4.class)
public class TimeZoneDetectorServiceTest {
+ private static final LocationTimeZoneAlgorithmStatus ARBITRARY_LOCATION_CERTAIN_STATUS =
+ new LocationTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING,
+ PROVIDER_STATUS_IS_CERTAIN, null, PROVIDER_STATUS_NOT_PRESENT, null);
+ private static final TimeZoneDetectorStatus ARBITRARY_DETECTOR_STATUS =
+ new TimeZoneDetectorStatus(DETECTOR_STATUS_RUNNING,
+ new TelephonyTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING),
+ ARBITRARY_LOCATION_CERTAIN_STATUS);
private static final int ARBITRARY_USER_ID = 9999;
private static final List ARBITRARY_TIME_ZONE_IDS = Arrays.asList("TestZoneId");
private static final long ARBITRARY_ELAPSED_REALTIME_MILLIS = 1234L;
@@ -113,7 +128,8 @@ public class TimeZoneDetectorServiceTest {
ConfigurationInternal configuration =
createConfigurationInternal(true /* autoDetectionEnabled*/);
- mFakeTimeZoneDetectorStrategySpy.initializeConfiguration(configuration);
+ mFakeTimeZoneDetectorStrategySpy.initializeConfigurationAndStatus(configuration,
+ ARBITRARY_DETECTOR_STATUS);
TimeZoneCapabilitiesAndConfig actualCapabilitiesAndConfig =
mTimeZoneDetectorService.getCapabilitiesAndConfig();
@@ -128,6 +144,7 @@ public class TimeZoneDetectorServiceTest {
TimeZoneCapabilitiesAndConfig expectedCapabilitiesAndConfig =
new TimeZoneCapabilitiesAndConfig(
+ ARBITRARY_DETECTOR_STATUS,
configuration.asCapabilities(expectedBypassUserPolicyChecks),
configuration.asConfiguration());
assertEquals(expectedCapabilitiesAndConfig, actualCapabilitiesAndConfig);
@@ -161,7 +178,9 @@ public class TimeZoneDetectorServiceTest {
public void testListenerRegistrationAndCallbacks() throws Exception {
ConfigurationInternal initialConfiguration =
createConfigurationInternal(false /* autoDetectionEnabled */);
- mFakeTimeZoneDetectorStrategySpy.initializeConfiguration(initialConfiguration);
+
+ mFakeTimeZoneDetectorStrategySpy.initializeConfigurationAndStatus(
+ initialConfiguration, ARBITRARY_DETECTOR_STATUS);
IBinder mockListenerBinder = mock(IBinder.class);
ITimeZoneDetectorListener mockListener = mock(ITimeZoneDetectorListener.class);
@@ -231,31 +250,35 @@ public class TimeZoneDetectorServiceTest {
}
@Test
- public void testSuggestGeolocationTimeZone_withoutPermission() {
+ public void testHandleLocationAlgorithmEvent_withoutPermission() {
doThrow(new SecurityException("Mock"))
.when(mMockContext).enforceCallingPermission(anyString(), any());
GeolocationTimeZoneSuggestion timeZoneSuggestion = createGeolocationTimeZoneSuggestion();
+ LocationAlgorithmEvent event = new LocationAlgorithmEvent(
+ ARBITRARY_LOCATION_CERTAIN_STATUS, timeZoneSuggestion);
assertThrows(SecurityException.class,
- () -> mTimeZoneDetectorService.suggestGeolocationTimeZone(timeZoneSuggestion));
+ () -> mTimeZoneDetectorService.handleLocationAlgorithmEvent(event));
verify(mMockContext).enforceCallingPermission(
eq(android.Manifest.permission.SET_TIME_ZONE), anyString());
}
@Test
- public void testSuggestGeolocationTimeZone() throws Exception {
+ public void testHandleLocationAlgorithmEvent() throws Exception {
doNothing().when(mMockContext).enforceCallingPermission(anyString(), any());
GeolocationTimeZoneSuggestion timeZoneSuggestion = createGeolocationTimeZoneSuggestion();
+ LocationAlgorithmEvent event = new LocationAlgorithmEvent(
+ ARBITRARY_LOCATION_CERTAIN_STATUS, timeZoneSuggestion);
- mTimeZoneDetectorService.suggestGeolocationTimeZone(timeZoneSuggestion);
+ mTimeZoneDetectorService.handleLocationAlgorithmEvent(event);
mTestHandler.assertTotalMessagesEnqueued(1);
verify(mMockContext).enforceCallingPermission(
eq(android.Manifest.permission.SET_TIME_ZONE), anyString());
mTestHandler.waitForMessagesToBeProcessed();
- verify(mFakeTimeZoneDetectorStrategySpy).suggestGeolocationTimeZone(timeZoneSuggestion);
+ verify(mFakeTimeZoneDetectorStrategySpy).handleLocationAlgorithmEvent(event);
}
@Test
diff --git a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorStrategyImplTest.java b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorStrategyImplTest.java
index f50e7fbc76bb1..b991c5a304156 100644
--- a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorStrategyImplTest.java
+++ b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorStrategyImplTest.java
@@ -16,6 +16,12 @@
package com.android.server.timezonedetector;
+import static android.app.time.DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_RUNNING;
+import static android.app.time.DetectorStatusTypes.DETECTOR_STATUS_RUNNING;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_IS_CERTAIN;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_IS_UNCERTAIN;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_PRESENT;
+import static android.app.time.LocationTimeZoneAlgorithmStatus.PROVIDER_STATUS_NOT_READY;
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.MATCH_TYPE_EMULATOR_ZONE_ID;
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET;
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY;
@@ -35,6 +41,7 @@ import static com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.T
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -47,8 +54,11 @@ import static org.mockito.Mockito.verify;
import android.annotation.ElapsedRealtimeLong;
import android.annotation.NonNull;
import android.annotation.UserIdInt;
+import android.app.time.LocationTimeZoneAlgorithmStatus;
+import android.app.time.TelephonyTimeZoneAlgorithmStatus;
import android.app.time.TimeZoneCapabilitiesAndConfig;
import android.app.time.TimeZoneConfiguration;
+import android.app.time.TimeZoneDetectorStatus;
import android.app.time.TimeZoneState;
import android.app.timezonedetector.ManualTimeZoneSuggestion;
import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
@@ -189,6 +199,9 @@ public class TimeZoneDetectorStrategyImplTest {
.setGeoDetectionEnabledSetting(true)
.build();
+ private static final TelephonyTimeZoneAlgorithmStatus TELEPHONY_ALGORITHM_RUNNING_STATUS =
+ new TelephonyTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING);
+
private FakeServiceConfigAccessor mFakeServiceConfigAccessorSpy;
private FakeEnvironment mFakeEnvironment;
private HandlerThread mHandlerThread;
@@ -233,9 +246,7 @@ public class TimeZoneDetectorStrategyImplTest {
{
mFakeServiceConfigAccessorSpy.simulateCurrentUserConfigurationInternalChange(
CONFIG_AUTO_DISABLED_GEO_DISABLED);
- mTestHandler.waitForMessagesToBeProcessed();
-
- stateChangeListener.assertNotificationsReceived(0);
+ assertStateChangeNotificationsSent(stateChangeListener, 0);
assertEquals(CONFIG_AUTO_DISABLED_GEO_DISABLED,
mTimeZoneDetectorStrategy.getCachedCapabilitiesAndConfigForTests());
}
@@ -244,10 +255,7 @@ public class TimeZoneDetectorStrategyImplTest {
{
mFakeServiceConfigAccessorSpy.simulateCurrentUserConfigurationInternalChange(
CONFIG_AUTO_ENABLED_GEO_ENABLED);
- mTestHandler.waitForMessagesToBeProcessed();
-
- stateChangeListener.assertNotificationsReceived(1);
- stateChangeListener.resetNotificationsReceivedCount();
+ assertStateChangeNotificationsSent(stateChangeListener, 1);
assertEquals(CONFIG_AUTO_ENABLED_GEO_ENABLED,
mTimeZoneDetectorStrategy.getCachedCapabilitiesAndConfigForTests());
}
@@ -258,10 +266,7 @@ public class TimeZoneDetectorStrategyImplTest {
new TimeZoneConfiguration.Builder().setGeoDetectionEnabled(false).build();
mTimeZoneDetectorStrategy.updateConfiguration(
USER_ID, requestedChanges, bypassUserPolicyChecks);
- mTestHandler.waitForMessagesToBeProcessed();
-
- stateChangeListener.assertNotificationsReceived(1);
- stateChangeListener.resetNotificationsReceivedCount();
+ assertStateChangeNotificationsSent(stateChangeListener, 1);
}
}
@@ -290,11 +295,9 @@ public class TimeZoneDetectorStrategyImplTest {
new TimeZoneConfiguration.Builder().setGeoDetectionEnabled(false).build();
mTimeZoneDetectorStrategy.updateConfiguration(
otherUserId, requestedChanges, bypassUserPolicyChecks);
- mTestHandler.waitForMessagesToBeProcessed();
// Only changes to the current user's config are notified.
- stateChangeListener.assertNotificationsReceived(0);
- stateChangeListener.resetNotificationsReceivedCount();
+ assertStateChangeNotificationsSent(stateChangeListener, 0);
}
// Current user behavior: the strategy caches and returns the latest configuration.
@@ -426,9 +429,9 @@ public class TimeZoneDetectorStrategyImplTest {
QualifiedTelephonyTimeZoneSuggestion expectedSlotIndex1ScoredSuggestion =
new QualifiedTelephonyTimeZoneSuggestion(slotIndex1TimeZoneSuggestion,
TELEPHONY_SCORE_NONE);
- assertEquals(expectedSlotIndex1ScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
- assertNull(mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX2));
+ script.verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX1, expectedSlotIndex1ScoredSuggestion)
+ .verifyLatestQualifiedTelephonySuggestionReceived(SLOT_INDEX2, null);
assertEquals(expectedSlotIndex1ScoredSuggestion,
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
@@ -439,10 +442,10 @@ public class TimeZoneDetectorStrategyImplTest {
QualifiedTelephonyTimeZoneSuggestion expectedSlotIndex2ScoredSuggestion =
new QualifiedTelephonyTimeZoneSuggestion(slotIndex2TimeZoneSuggestion,
TELEPHONY_SCORE_NONE);
- assertEquals(expectedSlotIndex1ScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
- assertEquals(expectedSlotIndex2ScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX2));
+ script.verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX1, expectedSlotIndex1ScoredSuggestion)
+ .verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX2, expectedSlotIndex2ScoredSuggestion);
// SlotIndex1 should always beat slotIndex2, all other things being equal.
assertEquals(expectedSlotIndex1ScoredSuggestion,
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
@@ -477,8 +480,8 @@ public class TimeZoneDetectorStrategyImplTest {
QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion =
new QualifiedTelephonyTimeZoneSuggestion(
lowQualitySuggestion, testCase.expectedScore);
- assertEquals(expectedScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
+ script.verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX1, expectedScoredSuggestion);
assertEquals(expectedScoredSuggestion,
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
}
@@ -494,8 +497,8 @@ public class TimeZoneDetectorStrategyImplTest {
QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion =
new QualifiedTelephonyTimeZoneSuggestion(
goodQualitySuggestion, testCase2.expectedScore);
- assertEquals(expectedScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
+ script.verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX1, expectedScoredSuggestion);
assertEquals(expectedScoredSuggestion,
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
}
@@ -511,8 +514,8 @@ public class TimeZoneDetectorStrategyImplTest {
QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion =
new QualifiedTelephonyTimeZoneSuggestion(
lowQualitySuggestion2, testCase.expectedScore);
- assertEquals(expectedScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
+ script.verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX1, expectedScoredSuggestion);
assertEquals(expectedScoredSuggestion,
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
}
@@ -543,8 +546,8 @@ public class TimeZoneDetectorStrategyImplTest {
// Assert internal service state.
QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion =
new QualifiedTelephonyTimeZoneSuggestion(suggestion, testCase.expectedScore);
- assertEquals(expectedScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
+ script.verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX1, expectedScoredSuggestion);
assertEquals(expectedScoredSuggestion,
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
@@ -560,8 +563,8 @@ public class TimeZoneDetectorStrategyImplTest {
}
// Assert internal service state.
- assertEquals(expectedScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
+ script.verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX1, expectedScoredSuggestion);
assertEquals(expectedScoredSuggestion,
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
@@ -570,8 +573,8 @@ public class TimeZoneDetectorStrategyImplTest {
.verifyTimeZoneNotChanged();
// Assert internal service state.
- assertEquals(expectedScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
+ script.verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX1, expectedScoredSuggestion);
assertEquals(expectedScoredSuggestion,
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
}
@@ -622,8 +625,8 @@ public class TimeZoneDetectorStrategyImplTest {
}
// Assert internal service state.
- assertEquals(expectedZoneSlotIndex1ScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
+ script.verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX1, expectedZoneSlotIndex1ScoredSuggestion);
assertEquals(expectedZoneSlotIndex1ScoredSuggestion,
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
}
@@ -677,10 +680,10 @@ public class TimeZoneDetectorStrategyImplTest {
}
// Assert internal service state.
- assertEquals(expectedZoneSlotIndex1ScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
- assertEquals(expectedEmptySlotIndex2ScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX2));
+ script.verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX1, expectedZoneSlotIndex1ScoredSuggestion)
+ .verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX2, expectedEmptySlotIndex2ScoredSuggestion);
assertEquals(expectedZoneSlotIndex1ScoredSuggestion,
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
@@ -690,10 +693,10 @@ public class TimeZoneDetectorStrategyImplTest {
script.verifyTimeZoneNotChanged();
// Assert internal service state.
- assertEquals(expectedZoneSlotIndex1ScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
- assertEquals(expectedZoneSlotIndex2ScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX2));
+ script.verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX1, expectedZoneSlotIndex1ScoredSuggestion)
+ .verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX2, expectedZoneSlotIndex2ScoredSuggestion);
// SlotIndex1 should always beat slotIndex2, all other things being equal.
assertEquals(expectedZoneSlotIndex1ScoredSuggestion,
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
@@ -709,20 +712,20 @@ public class TimeZoneDetectorStrategyImplTest {
}
// Assert internal service state.
- assertEquals(expectedEmptySlotIndex1ScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
- assertEquals(expectedZoneSlotIndex2ScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX2));
+ script.verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX1, expectedEmptySlotIndex1ScoredSuggestion)
+ .verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX2, expectedZoneSlotIndex2ScoredSuggestion);
assertEquals(expectedZoneSlotIndex2ScoredSuggestion,
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
// Reset the state for the next loop.
script.simulateTelephonyTimeZoneSuggestion(emptySlotIndex2Suggestion)
.verifyTimeZoneNotChanged();
- assertEquals(expectedEmptySlotIndex1ScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
- assertEquals(expectedEmptySlotIndex2ScoredSuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX2));
+ script.verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX1, expectedEmptySlotIndex1ScoredSuggestion)
+ .verifyLatestQualifiedTelephonySuggestionReceived(
+ SLOT_INDEX2, expectedEmptySlotIndex2ScoredSuggestion);
}
}
@@ -866,53 +869,185 @@ public class TimeZoneDetectorStrategyImplTest {
}
@Test
- public void testGeoSuggestion_uncertain() {
+ public void testLocationAlgorithmEvent_statusChangesOnly() {
+ TestStateChangeListener stateChangeListener = new TestStateChangeListener();
Script script = new Script()
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID, TIME_ZONE_CONFIDENCE_LOW)
.simulateConfigurationInternalChange(CONFIG_AUTO_ENABLED_GEO_ENABLED)
- .resetConfigurationTracking();
+ .resetConfigurationTracking()
+ .registerStateChangeListener(stateChangeListener);
- GeolocationTimeZoneSuggestion uncertainSuggestion = createUncertainGeolocationSuggestion();
+ TimeZoneDetectorStatus expectedInitialDetectorStatus = new TimeZoneDetectorStatus(
+ DETECTOR_STATUS_RUNNING,
+ TELEPHONY_ALGORITHM_RUNNING_STATUS,
+ LocationTimeZoneAlgorithmStatus.UNKNOWN);
+ script.verifyCachedDetectorStatus(expectedInitialDetectorStatus);
- script.simulateGeolocationTimeZoneSuggestion(uncertainSuggestion)
- .verifyTimeZoneNotChanged();
+ LocationTimeZoneAlgorithmStatus algorithmStatus1 = new LocationTimeZoneAlgorithmStatus(
+ DETECTION_ALGORITHM_STATUS_RUNNING, PROVIDER_STATUS_NOT_READY, null,
+ PROVIDER_STATUS_NOT_PRESENT, null);
+ LocationTimeZoneAlgorithmStatus algorithmStatus2 = new LocationTimeZoneAlgorithmStatus(
+ DETECTION_ALGORITHM_STATUS_RUNNING, PROVIDER_STATUS_NOT_PRESENT, null,
+ PROVIDER_STATUS_NOT_PRESENT, null);
+ assertNotEquals(algorithmStatus1, algorithmStatus2);
- // Assert internal service state.
- assertEquals(uncertainSuggestion,
- mTimeZoneDetectorStrategy.getLatestGeolocationSuggestion());
+ {
+ LocationAlgorithmEvent locationAlgorithmEvent =
+ new LocationAlgorithmEvent(algorithmStatus1, null);
+ script.simulateLocationAlgorithmEvent(locationAlgorithmEvent)
+ .verifyTimeZoneNotChanged();
+
+ assertStateChangeNotificationsSent(stateChangeListener, 1);
+
+ // Assert internal service state.
+ TimeZoneDetectorStatus expectedDetectorStatus = new TimeZoneDetectorStatus(
+ DETECTOR_STATUS_RUNNING,
+ TELEPHONY_ALGORITHM_RUNNING_STATUS,
+ algorithmStatus1);
+ script.verifyCachedDetectorStatus(expectedDetectorStatus)
+ .verifyLatestLocationAlgorithmEventReceived(locationAlgorithmEvent);
+
+ // Repeat the event to demonstrate the state change notifier is not triggered.
+ script.simulateLocationAlgorithmEvent(locationAlgorithmEvent)
+ .verifyTimeZoneNotChanged();
+
+ assertStateChangeNotificationsSent(stateChangeListener, 0);
+
+ // Assert internal service state.
+ script.verifyCachedDetectorStatus(expectedDetectorStatus)
+ .verifyLatestLocationAlgorithmEventReceived(locationAlgorithmEvent);
+ }
+
+ {
+ LocationAlgorithmEvent locationAlgorithmEvent =
+ new LocationAlgorithmEvent(algorithmStatus2, null);
+ script.simulateLocationAlgorithmEvent(locationAlgorithmEvent)
+ .verifyTimeZoneNotChanged();
+
+ assertStateChangeNotificationsSent(stateChangeListener, 1);
+
+ // Assert internal service state.
+ TimeZoneDetectorStatus expectedDetectorStatus = new TimeZoneDetectorStatus(
+ DETECTOR_STATUS_RUNNING,
+ TELEPHONY_ALGORITHM_RUNNING_STATUS,
+ algorithmStatus2);
+ script.verifyCachedDetectorStatus(expectedDetectorStatus)
+ .verifyLatestLocationAlgorithmEventReceived(locationAlgorithmEvent);
+
+ // Repeat the event to demonstrate the state change notifier is not triggered.
+ script.simulateLocationAlgorithmEvent(locationAlgorithmEvent)
+ .verifyTimeZoneNotChanged();
+
+ assertStateChangeNotificationsSent(stateChangeListener, 0);
+
+ // Assert internal service state.
+ script.verifyCachedDetectorStatus(expectedDetectorStatus)
+ .verifyLatestLocationAlgorithmEventReceived(locationAlgorithmEvent);
+ }
}
@Test
- public void testGeoSuggestion_noZones() {
+ public void testLocationAlgorithmEvent_uncertain() {
+ TestStateChangeListener stateChangeListener = new TestStateChangeListener();
Script script = new Script()
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID, TIME_ZONE_CONFIDENCE_LOW)
.simulateConfigurationInternalChange(CONFIG_AUTO_ENABLED_GEO_ENABLED)
- .resetConfigurationTracking();
+ .resetConfigurationTracking()
+ .registerStateChangeListener(stateChangeListener);
- GeolocationTimeZoneSuggestion noZonesSuggestion = createCertainGeolocationSuggestion();
-
- script.simulateGeolocationTimeZoneSuggestion(noZonesSuggestion)
+ LocationAlgorithmEvent locationAlgorithmEvent = createUncertainLocationAlgorithmEvent();
+ script.simulateLocationAlgorithmEvent(locationAlgorithmEvent)
.verifyTimeZoneNotChanged();
+ assertStateChangeNotificationsSent(stateChangeListener, 1);
+
// Assert internal service state.
- assertEquals(noZonesSuggestion, mTimeZoneDetectorStrategy.getLatestGeolocationSuggestion());
+ TimeZoneDetectorStatus expectedDetectorStatus = new TimeZoneDetectorStatus(
+ DETECTOR_STATUS_RUNNING,
+ TELEPHONY_ALGORITHM_RUNNING_STATUS,
+ locationAlgorithmEvent.getAlgorithmStatus());
+ script.verifyCachedDetectorStatus(expectedDetectorStatus)
+ .verifyLatestLocationAlgorithmEventReceived(locationAlgorithmEvent);
+
+ // Repeat the event to demonstrate the state change notifier is not triggered.
+ script.simulateLocationAlgorithmEvent(locationAlgorithmEvent)
+ .verifyTimeZoneNotChanged();
+
+ // Detector remains running and location algorithm is still uncertain so nothing to report.
+ assertStateChangeNotificationsSent(stateChangeListener, 0);
+
+ // Assert internal service state.
+ script.verifyCachedDetectorStatus(expectedDetectorStatus)
+ .verifyLatestLocationAlgorithmEventReceived(locationAlgorithmEvent);
}
@Test
- public void testGeoSuggestion_oneZone() {
- GeolocationTimeZoneSuggestion suggestion =
- createCertainGeolocationSuggestion("Europe/London");
-
+ public void testLocationAlgorithmEvent_noZones() {
+ TestStateChangeListener stateChangeListener = new TestStateChangeListener();
Script script = new Script()
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID, TIME_ZONE_CONFIDENCE_LOW)
.simulateConfigurationInternalChange(CONFIG_AUTO_ENABLED_GEO_ENABLED)
- .resetConfigurationTracking();
+ .resetConfigurationTracking()
+ .registerStateChangeListener(stateChangeListener);
- script.simulateGeolocationTimeZoneSuggestion(suggestion)
- .verifyTimeZoneChangedAndReset(suggestion);
+ LocationAlgorithmEvent locationAlgorithmEvent = createCertainLocationAlgorithmEvent();
+ script.simulateLocationAlgorithmEvent(locationAlgorithmEvent)
+ .verifyTimeZoneNotChanged();
+
+ assertStateChangeNotificationsSent(stateChangeListener, 1);
// Assert internal service state.
- assertEquals(suggestion, mTimeZoneDetectorStrategy.getLatestGeolocationSuggestion());
+ TimeZoneDetectorStatus expectedDetectorStatus = new TimeZoneDetectorStatus(
+ DETECTOR_STATUS_RUNNING,
+ TELEPHONY_ALGORITHM_RUNNING_STATUS,
+ locationAlgorithmEvent.getAlgorithmStatus());
+ script.verifyCachedDetectorStatus(expectedDetectorStatus)
+ .verifyLatestLocationAlgorithmEventReceived(locationAlgorithmEvent);
+
+ // Repeat the event to demonstrate the state change notifier is not triggered.
+ script.simulateLocationAlgorithmEvent(locationAlgorithmEvent)
+ .verifyTimeZoneNotChanged();
+
+ assertStateChangeNotificationsSent(stateChangeListener, 0);
+
+ // Assert internal service state.
+ script.verifyCachedDetectorStatus(expectedDetectorStatus)
+ .verifyLatestLocationAlgorithmEventReceived(locationAlgorithmEvent);
+ }
+
+ @Test
+ public void testLocationAlgorithmEvent_oneZone() {
+ TestStateChangeListener stateChangeListener = new TestStateChangeListener();
+ Script script = new Script()
+ .initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID, TIME_ZONE_CONFIDENCE_LOW)
+ .simulateConfigurationInternalChange(CONFIG_AUTO_ENABLED_GEO_ENABLED)
+ .resetConfigurationTracking()
+ .registerStateChangeListener(stateChangeListener);
+
+ LocationAlgorithmEvent locationAlgorithmEvent =
+ createCertainLocationAlgorithmEvent("Europe/London");
+ script.simulateLocationAlgorithmEvent(locationAlgorithmEvent)
+ .verifyTimeZoneChangedAndReset(locationAlgorithmEvent);
+
+ assertStateChangeNotificationsSent(stateChangeListener, 1);
+
+ // Assert internal service state.
+ TimeZoneDetectorStatus expectedDetectorStatus = new TimeZoneDetectorStatus(
+ DETECTOR_STATUS_RUNNING,
+ TELEPHONY_ALGORITHM_RUNNING_STATUS,
+ locationAlgorithmEvent.getAlgorithmStatus());
+ script.verifyCachedDetectorStatus(expectedDetectorStatus)
+ .verifyLatestLocationAlgorithmEventReceived(locationAlgorithmEvent);
+
+ // Repeat the event to demonstrate the state change notifier is not triggered.
+ script.simulateLocationAlgorithmEvent(locationAlgorithmEvent)
+ .verifyTimeZoneNotChanged();
+
+ assertStateChangeNotificationsSent(stateChangeListener, 0);
+
+ // Assert internal service state.
+ script.verifyCachedDetectorStatus(expectedDetectorStatus)
+ .verifyLatestLocationAlgorithmEventReceived(locationAlgorithmEvent);
}
/**
@@ -921,41 +1056,35 @@ public class TimeZoneDetectorStrategyImplTest {
* set to until that unambiguously can't be correct.
*/
@Test
- public void testGeoSuggestion_multiZone() {
- GeolocationTimeZoneSuggestion londonOnlySuggestion =
- createCertainGeolocationSuggestion("Europe/London");
- GeolocationTimeZoneSuggestion londonOrParisSuggestion =
- createCertainGeolocationSuggestion("Europe/Paris", "Europe/London");
- GeolocationTimeZoneSuggestion parisOnlySuggestion =
- createCertainGeolocationSuggestion("Europe/Paris");
-
+ public void testLocationAlgorithmEvent_multiZone() {
Script script = new Script()
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID, TIME_ZONE_CONFIDENCE_LOW)
.simulateConfigurationInternalChange(CONFIG_AUTO_ENABLED_GEO_ENABLED)
.resetConfigurationTracking();
- script.simulateGeolocationTimeZoneSuggestion(londonOnlySuggestion)
- .verifyTimeZoneChangedAndReset(londonOnlySuggestion);
- assertEquals(londonOnlySuggestion,
- mTimeZoneDetectorStrategy.getLatestGeolocationSuggestion());
+ LocationAlgorithmEvent londonOnlyEvent =
+ createCertainLocationAlgorithmEvent("Europe/London");
+ script.simulateLocationAlgorithmEvent(londonOnlyEvent)
+ .verifyTimeZoneChangedAndReset(londonOnlyEvent)
+ .verifyLatestLocationAlgorithmEventReceived(londonOnlyEvent);
// Confirm bias towards the current device zone when there's multiple zones to choose from.
- script.simulateGeolocationTimeZoneSuggestion(londonOrParisSuggestion)
- .verifyTimeZoneNotChanged();
- assertEquals(londonOrParisSuggestion,
- mTimeZoneDetectorStrategy.getLatestGeolocationSuggestion());
+ LocationAlgorithmEvent londonOrParisEvent =
+ createCertainLocationAlgorithmEvent("Europe/Paris", "Europe/London");
+ script.simulateLocationAlgorithmEvent(londonOrParisEvent)
+ .verifyTimeZoneNotChanged()
+ .verifyLatestLocationAlgorithmEventReceived(londonOrParisEvent);
- script.simulateGeolocationTimeZoneSuggestion(parisOnlySuggestion)
- .verifyTimeZoneChangedAndReset(parisOnlySuggestion);
- assertEquals(parisOnlySuggestion,
- mTimeZoneDetectorStrategy.getLatestGeolocationSuggestion());
+ LocationAlgorithmEvent parisOnlyEvent = createCertainLocationAlgorithmEvent("Europe/Paris");
+ script.simulateLocationAlgorithmEvent(parisOnlyEvent)
+ .verifyTimeZoneChangedAndReset(parisOnlyEvent)
+ .verifyLatestLocationAlgorithmEventReceived(parisOnlyEvent);
// Now the suggestion that previously left the device on Europe/London will leave the device
// on Europe/Paris.
- script.simulateGeolocationTimeZoneSuggestion(londonOrParisSuggestion)
- .verifyTimeZoneNotChanged();
- assertEquals(londonOrParisSuggestion,
- mTimeZoneDetectorStrategy.getLatestGeolocationSuggestion());
+ script.simulateLocationAlgorithmEvent(londonOrParisEvent)
+ .verifyTimeZoneNotChanged()
+ .verifyLatestLocationAlgorithmEventReceived(londonOrParisEvent);
}
/**
@@ -964,8 +1093,9 @@ public class TimeZoneDetectorStrategyImplTest {
*/
@Test
public void testChangingGeoDetectionEnabled() {
- GeolocationTimeZoneSuggestion geolocationSuggestion =
- createCertainGeolocationSuggestion("Europe/London");
+ TestStateChangeListener stateChangeListener = new TestStateChangeListener();
+ LocationAlgorithmEvent locationAlgorithmEvent =
+ createCertainLocationAlgorithmEvent("Europe/London");
TelephonyTimeZoneSuggestion telephonySuggestion = createTelephonySuggestion(
SLOT_INDEX1, MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET, QUALITY_SINGLE_ZONE,
"Europe/Paris");
@@ -973,20 +1103,22 @@ public class TimeZoneDetectorStrategyImplTest {
Script script = new Script()
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID, TIME_ZONE_CONFIDENCE_LOW)
.simulateConfigurationInternalChange(CONFIG_AUTO_DISABLED_GEO_DISABLED)
- .resetConfigurationTracking();
+ .resetConfigurationTracking()
+ .registerStateChangeListener(stateChangeListener);
// Add suggestions. Nothing should happen as time zone detection is disabled.
- script.simulateGeolocationTimeZoneSuggestion(geolocationSuggestion)
- .verifyTimeZoneNotChanged();
+ script.simulateLocationAlgorithmEvent(locationAlgorithmEvent)
+ .verifyTimeZoneNotChanged()
+ .verifyLatestLocationAlgorithmEventReceived(locationAlgorithmEvent);
- assertEquals(geolocationSuggestion,
- mTimeZoneDetectorStrategy.getLatestGeolocationSuggestion());
+ // A detector status change is considered a "state change".
+ assertStateChangeNotificationsSent(stateChangeListener, 1);
script.simulateTelephonyTimeZoneSuggestion(telephonySuggestion)
- .verifyTimeZoneNotChanged();
+ .verifyTimeZoneNotChanged()
+ .verifyLatestTelephonySuggestionReceived(SLOT_INDEX1, telephonySuggestion);
- assertEquals(telephonySuggestion,
- mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1).suggestion);
+ assertStateChangeNotificationsSent(stateChangeListener, 0);
// Toggling the time zone detection enabled setting on should cause the device setting to be
// set from the telephony signal, as we've started with geolocation time zone detection
@@ -994,18 +1126,25 @@ public class TimeZoneDetectorStrategyImplTest {
script.simulateSetAutoMode(true)
.verifyTimeZoneChangedAndReset(telephonySuggestion);
+ // A configuration change is considered a "state change".
+ assertStateChangeNotificationsSent(stateChangeListener, 1);
+
// Changing the detection to enable geo detection will cause the device tz setting to
// change to use the latest geolocation suggestion.
script.simulateSetGeoDetectionEnabled(true)
- .verifyTimeZoneChangedAndReset(geolocationSuggestion);
+ .verifyTimeZoneChangedAndReset(locationAlgorithmEvent);
+
+ // A configuration change is considered a "state change".
+ assertStateChangeNotificationsSent(stateChangeListener, 1);
// Changing the detection to disable geo detection should cause the device tz setting to
// change to the telephony suggestion.
script.simulateSetGeoDetectionEnabled(false)
- .verifyTimeZoneChangedAndReset(telephonySuggestion);
+ .verifyTimeZoneChangedAndReset(telephonySuggestion)
+ .verifyLatestLocationAlgorithmEventReceived(locationAlgorithmEvent);
- assertEquals(geolocationSuggestion,
- mTimeZoneDetectorStrategy.getLatestGeolocationSuggestion());
+ // A configuration change is considered a "state change".
+ assertStateChangeNotificationsSent(stateChangeListener, 1);
}
@Test
@@ -1039,21 +1178,20 @@ public class TimeZoneDetectorStrategyImplTest {
// Receiving an "uncertain" geolocation suggestion should have no effect.
{
- GeolocationTimeZoneSuggestion uncertainGeolocationSuggestion =
- createUncertainGeolocationSuggestion();
+ LocationAlgorithmEvent locationAlgorithmEvent = createUncertainLocationAlgorithmEvent();
script.simulateIncrementClock()
- .simulateGeolocationTimeZoneSuggestion(uncertainGeolocationSuggestion)
+ .simulateLocationAlgorithmEvent(locationAlgorithmEvent)
.verifyTimeZoneNotChanged()
.verifyTelephonyFallbackIsEnabled(true);
}
// Receiving a "certain" geolocation suggestion should disable telephony fallback mode.
{
- GeolocationTimeZoneSuggestion geolocationSuggestion =
- createCertainGeolocationSuggestion("Europe/London");
+ LocationAlgorithmEvent locationAlgorithmEvent =
+ createCertainLocationAlgorithmEvent("Europe/London");
script.simulateIncrementClock()
- .simulateGeolocationTimeZoneSuggestion(geolocationSuggestion)
- .verifyTimeZoneChangedAndReset(geolocationSuggestion)
+ .simulateLocationAlgorithmEvent(locationAlgorithmEvent)
+ .verifyTimeZoneChangedAndReset(locationAlgorithmEvent)
.verifyTelephonyFallbackIsEnabled(false);
}
@@ -1076,22 +1214,22 @@ public class TimeZoneDetectorStrategyImplTest {
// Geolocation suggestions should continue to be used as normal (previous telephony
// suggestions are not used, even when the geolocation suggestion is uncertain).
{
- GeolocationTimeZoneSuggestion geolocationSuggestion =
- createCertainGeolocationSuggestion("Europe/Rome");
+ LocationAlgorithmEvent certainLocationAlgorithmEvent =
+ createCertainLocationAlgorithmEvent("Europe/Rome");
script.simulateIncrementClock()
- .simulateGeolocationTimeZoneSuggestion(geolocationSuggestion)
- .verifyTimeZoneChangedAndReset(geolocationSuggestion)
+ .simulateLocationAlgorithmEvent(certainLocationAlgorithmEvent)
+ .verifyTimeZoneChangedAndReset(certainLocationAlgorithmEvent)
.verifyTelephonyFallbackIsEnabled(false);
- GeolocationTimeZoneSuggestion uncertainGeolocationSuggestion =
- createUncertainGeolocationSuggestion();
+ LocationAlgorithmEvent uncertainLocationAlgorithmEvent =
+ createUncertainLocationAlgorithmEvent();
script.simulateIncrementClock()
- .simulateGeolocationTimeZoneSuggestion(uncertainGeolocationSuggestion)
+ .simulateLocationAlgorithmEvent(uncertainLocationAlgorithmEvent)
.verifyTimeZoneNotChanged()
.verifyTelephonyFallbackIsEnabled(false);
script.simulateIncrementClock()
- .simulateGeolocationTimeZoneSuggestion(geolocationSuggestion)
+ .simulateLocationAlgorithmEvent(certainLocationAlgorithmEvent)
// No change needed, device will already be set to Europe/Rome.
.verifyTimeZoneNotChanged()
.verifyTelephonyFallbackIsEnabled(false);
@@ -1108,21 +1246,20 @@ public class TimeZoneDetectorStrategyImplTest {
// Make the geolocation algorithm uncertain.
{
- GeolocationTimeZoneSuggestion uncertainGeolocationSuggestion =
- createUncertainGeolocationSuggestion();
+ LocationAlgorithmEvent locationAlgorithmEvent = createUncertainLocationAlgorithmEvent();
script.simulateIncrementClock()
- .simulateGeolocationTimeZoneSuggestion(uncertainGeolocationSuggestion)
+ .simulateLocationAlgorithmEvent(locationAlgorithmEvent)
.verifyTimeZoneChangedAndReset(lastTelephonySuggestion)
.verifyTelephonyFallbackIsEnabled(true);
}
// Make the geolocation algorithm certain, disabling telephony fallback.
{
- GeolocationTimeZoneSuggestion geolocationSuggestion =
- createCertainGeolocationSuggestion("Europe/Lisbon");
+ LocationAlgorithmEvent locationAlgorithmEvent =
+ createCertainLocationAlgorithmEvent("Europe/Lisbon");
script.simulateIncrementClock()
- .simulateGeolocationTimeZoneSuggestion(geolocationSuggestion)
- .verifyTimeZoneChangedAndReset(geolocationSuggestion)
+ .simulateLocationAlgorithmEvent(locationAlgorithmEvent)
+ .verifyTimeZoneChangedAndReset(locationAlgorithmEvent)
.verifyTelephonyFallbackIsEnabled(false);
}
@@ -1130,10 +1267,9 @@ public class TimeZoneDetectorStrategyImplTest {
// Demonstrate what happens when geolocation is uncertain when telephony fallback is
// enabled.
{
- GeolocationTimeZoneSuggestion uncertainGeolocationSuggestion =
- createUncertainGeolocationSuggestion();
+ LocationAlgorithmEvent locationAlgorithmEvent = createUncertainLocationAlgorithmEvent();
script.simulateIncrementClock()
- .simulateGeolocationTimeZoneSuggestion(uncertainGeolocationSuggestion)
+ .simulateLocationAlgorithmEvent(locationAlgorithmEvent)
.verifyTimeZoneNotChanged()
.verifyTelephonyFallbackIsEnabled(false)
.simulateEnableTelephonyFallback()
@@ -1161,10 +1297,9 @@ public class TimeZoneDetectorStrategyImplTest {
// Receiving an "uncertain" geolocation suggestion should have no effect.
{
- GeolocationTimeZoneSuggestion uncertainGeolocationSuggestion =
- createUncertainGeolocationSuggestion();
+ LocationAlgorithmEvent locationAlgorithmEvent = createUncertainLocationAlgorithmEvent();
script.simulateIncrementClock()
- .simulateGeolocationTimeZoneSuggestion(uncertainGeolocationSuggestion)
+ .simulateLocationAlgorithmEvent(locationAlgorithmEvent)
.verifyTimeZoneNotChanged()
.verifyTelephonyFallbackIsEnabled(true);
}
@@ -1172,10 +1307,9 @@ public class TimeZoneDetectorStrategyImplTest {
// Make an uncertain geolocation suggestion, there is no telephony suggestion to fall back
// to
{
- GeolocationTimeZoneSuggestion uncertainGeolocationSuggestion =
- createUncertainGeolocationSuggestion();
+ LocationAlgorithmEvent locationAlgorithmEvent = createUncertainLocationAlgorithmEvent();
script.simulateIncrementClock()
- .simulateGeolocationTimeZoneSuggestion(uncertainGeolocationSuggestion)
+ .simulateLocationAlgorithmEvent(locationAlgorithmEvent)
.verifyTimeZoneNotChanged()
.verifyTelephonyFallbackIsEnabled(true);
}
@@ -1185,17 +1319,16 @@ public class TimeZoneDetectorStrategyImplTest {
// Geolocation suggestions should continue to be used as normal (previous telephony
// suggestions are not used, even when the geolocation suggestion is uncertain).
{
- GeolocationTimeZoneSuggestion geolocationSuggestion =
- createCertainGeolocationSuggestion("Europe/Rome");
+ LocationAlgorithmEvent certainEvent =
+ createCertainLocationAlgorithmEvent("Europe/Rome");
script.simulateIncrementClock()
- .simulateGeolocationTimeZoneSuggestion(geolocationSuggestion)
- .verifyTimeZoneChangedAndReset(geolocationSuggestion)
+ .simulateLocationAlgorithmEvent(certainEvent)
+ .verifyTimeZoneChangedAndReset(certainEvent)
.verifyTelephonyFallbackIsEnabled(false);
- GeolocationTimeZoneSuggestion uncertainGeolocationSuggestion =
- createUncertainGeolocationSuggestion();
+ LocationAlgorithmEvent uncertainEvent = createUncertainLocationAlgorithmEvent();
script.simulateIncrementClock()
- .simulateGeolocationTimeZoneSuggestion(uncertainGeolocationSuggestion)
+ .simulateLocationAlgorithmEvent(uncertainEvent)
.verifyTimeZoneNotChanged()
.verifyTelephonyFallbackIsEnabled(false);
@@ -1319,15 +1452,15 @@ public class TimeZoneDetectorStrategyImplTest {
TelephonyTimeZoneSuggestion telephonySuggestion =
createTelephonySuggestion(0 /* slotIndex */, MATCH_TYPE_NETWORK_COUNTRY_ONLY,
QUALITY_SINGLE_ZONE, "Zone2");
- GeolocationTimeZoneSuggestion geolocationTimeZoneSuggestion =
- createCertainGeolocationSuggestion("Zone3", "Zone2");
+ LocationAlgorithmEvent locationAlgorithmEvent =
+ createCertainLocationAlgorithmEvent("Zone3", "Zone2");
script.simulateTelephonyTimeZoneSuggestion(telephonySuggestion)
.verifyTimeZoneNotChanged()
- .simulateGeolocationTimeZoneSuggestion(geolocationTimeZoneSuggestion)
+ .simulateLocationAlgorithmEvent(locationAlgorithmEvent)
.verifyTimeZoneNotChanged();
assertMetricsState(expectedInternalConfig, expectedDeviceTimeZoneId,
- manualSuggestion, telephonySuggestion, geolocationTimeZoneSuggestion,
+ manualSuggestion, telephonySuggestion, locationAlgorithmEvent,
MetricsTimeZoneDetectorState.DETECTION_MODE_MANUAL);
// Update the config and confirm that the config metrics state updates also.
@@ -1336,11 +1469,11 @@ public class TimeZoneDetectorStrategyImplTest {
.setGeoDetectionEnabledSetting(true)
.build();
- expectedDeviceTimeZoneId = geolocationTimeZoneSuggestion.getZoneIds().get(0);
+ expectedDeviceTimeZoneId = locationAlgorithmEvent.getSuggestion().getZoneIds().get(0);
script.simulateConfigurationInternalChange(expectedInternalConfig)
.verifyTimeZoneChangedAndReset(expectedDeviceTimeZoneId, TIME_ZONE_CONFIDENCE_HIGH);
assertMetricsState(expectedInternalConfig, expectedDeviceTimeZoneId,
- manualSuggestion, telephonySuggestion, geolocationTimeZoneSuggestion,
+ manualSuggestion, telephonySuggestion, locationAlgorithmEvent,
MetricsTimeZoneDetectorState.DETECTION_MODE_GEO);
}
@@ -1352,7 +1485,7 @@ public class TimeZoneDetectorStrategyImplTest {
ConfigurationInternal expectedInternalConfig,
String expectedDeviceTimeZoneId, ManualTimeZoneSuggestion expectedManualSuggestion,
TelephonyTimeZoneSuggestion expectedTelephonySuggestion,
- GeolocationTimeZoneSuggestion expectedGeolocationTimeZoneSuggestion,
+ LocationAlgorithmEvent expectedLocationAlgorithmEvent,
int expectedDetectionMode) {
MetricsTimeZoneDetectorState actualState = mTimeZoneDetectorStrategy.generateMetricsState();
@@ -1365,7 +1498,7 @@ public class TimeZoneDetectorStrategyImplTest {
MetricsTimeZoneDetectorState.create(
tzIdOrdinalGenerator, expectedInternalConfig, expectedDeviceTimeZoneId,
expectedManualSuggestion, expectedTelephonySuggestion,
- expectedGeolocationTimeZoneSuggestion);
+ expectedLocationAlgorithmEvent);
// Rely on MetricsTimeZoneDetectorState.equals() for time zone ID / ID ordinal comparisons.
assertEquals(expectedState, actualState);
}
@@ -1405,20 +1538,37 @@ public class TimeZoneDetectorStrategyImplTest {
return new TelephonyTimeZoneSuggestion.Builder(SLOT_INDEX2).build();
}
+ private LocationAlgorithmEvent createCertainLocationAlgorithmEvent(@NonNull String... zoneIds) {
+ GeolocationTimeZoneSuggestion suggestion = createCertainGeolocationSuggestion(zoneIds);
+ LocationTimeZoneAlgorithmStatus algorithmStatus = new LocationTimeZoneAlgorithmStatus(
+ DETECTION_ALGORITHM_STATUS_RUNNING, PROVIDER_STATUS_IS_CERTAIN, null,
+ PROVIDER_STATUS_NOT_PRESENT, null);
+ LocationAlgorithmEvent event = new LocationAlgorithmEvent(algorithmStatus, suggestion);
+ event.addDebugInfo("Test certain event");
+ return event;
+ }
+
+ private LocationAlgorithmEvent createUncertainLocationAlgorithmEvent() {
+ GeolocationTimeZoneSuggestion suggestion = createUncertainGeolocationSuggestion();
+ LocationTimeZoneAlgorithmStatus algorithmStatus = new LocationTimeZoneAlgorithmStatus(
+ DETECTION_ALGORITHM_STATUS_RUNNING, PROVIDER_STATUS_IS_UNCERTAIN, null,
+ PROVIDER_STATUS_NOT_PRESENT, null);
+ LocationAlgorithmEvent event = new LocationAlgorithmEvent(algorithmStatus, suggestion);
+ event.addDebugInfo("Test uncertain event");
+ return event;
+ }
+
private GeolocationTimeZoneSuggestion createUncertainGeolocationSuggestion() {
- return GeolocationTimeZoneSuggestion.createCertainSuggestion(
- mFakeEnvironment.elapsedRealtimeMillis(), null);
+ return GeolocationTimeZoneSuggestion.createUncertainSuggestion(
+ mFakeEnvironment.elapsedRealtimeMillis());
}
private GeolocationTimeZoneSuggestion createCertainGeolocationSuggestion(
@NonNull String... zoneIds) {
assertNotNull(zoneIds);
- GeolocationTimeZoneSuggestion suggestion =
- GeolocationTimeZoneSuggestion.createCertainSuggestion(
- mFakeEnvironment.elapsedRealtimeMillis(), Arrays.asList(zoneIds));
- suggestion.addDebugInfo("Test suggestion");
- return suggestion;
+ return GeolocationTimeZoneSuggestion.createCertainSuggestion(
+ mFakeEnvironment.elapsedRealtimeMillis(), Arrays.asList(zoneIds));
}
static class FakeEnvironment implements TimeZoneDetectorStrategyImpl.Environment {
@@ -1499,6 +1649,14 @@ public class TimeZoneDetectorStrategyImplTest {
}
}
+ private void assertStateChangeNotificationsSent(
+ TestStateChangeListener stateChangeListener, int expectedCount) {
+ // State change notifications are asynchronous, so we have to wait.
+ mTestHandler.waitForMessagesToBeProcessed();
+
+ stateChangeListener.assertNotificationsReceivedAndReset(expectedCount);
+ }
+
/**
* A "fluent" class allows reuse of code in tests: initialization, simulation and verification
* logic.
@@ -1516,6 +1674,11 @@ public class TimeZoneDetectorStrategyImplTest {
return this;
}
+ Script registerStateChangeListener(StateChangeListener stateChangeListener) {
+ mTimeZoneDetectorStrategy.addChangeListener(stateChangeListener);
+ return this;
+ }
+
Script simulateIncrementClock() {
mFakeEnvironment.incrementClock();
return this;
@@ -1555,11 +1718,10 @@ public class TimeZoneDetectorStrategyImplTest {
}
/**
- * Simulates the time zone detection strategy receiving a geolocation-originated
- * suggestion.
+ * Simulates the time zone detection strategy receiving a location algorithm event.
*/
- Script simulateGeolocationTimeZoneSuggestion(GeolocationTimeZoneSuggestion suggestion) {
- mTimeZoneDetectorStrategy.suggestGeolocationTimeZone(suggestion);
+ Script simulateLocationAlgorithmEvent(LocationAlgorithmEvent event) {
+ mTimeZoneDetectorStrategy.handleLocationAlgorithmEvent(event);
return this;
}
@@ -1616,7 +1778,9 @@ public class TimeZoneDetectorStrategyImplTest {
return this;
}
- Script verifyTimeZoneChangedAndReset(GeolocationTimeZoneSuggestion suggestion) {
+ Script verifyTimeZoneChangedAndReset(LocationAlgorithmEvent event) {
+ GeolocationTimeZoneSuggestion suggestion = event.getSuggestion();
+ assertNotNull("Only events with suggestions can change the time zone", suggestion);
assertEquals("Only use this method with unambiguous geo suggestions",
1, suggestion.getZoneIds().size());
verifyTimeZoneChangedAndReset(
@@ -1631,6 +1795,32 @@ public class TimeZoneDetectorStrategyImplTest {
return this;
}
+ Script verifyCachedDetectorStatus(TimeZoneDetectorStatus expectedStatus) {
+ assertEquals(expectedStatus,
+ mTimeZoneDetectorStrategy.getCachedDetectorStatusForTests());
+ return this;
+ }
+
+ Script verifyLatestLocationAlgorithmEventReceived(LocationAlgorithmEvent expectedEvent) {
+ assertEquals(expectedEvent,
+ mTimeZoneDetectorStrategy.getLatestLocationAlgorithmEvent());
+ return this;
+ }
+
+ Script verifyLatestTelephonySuggestionReceived(int slotIndex,
+ TelephonyTimeZoneSuggestion expectedSuggestion) {
+ assertEquals(expectedSuggestion,
+ mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(slotIndex).suggestion);
+ return this;
+ }
+
+ Script verifyLatestQualifiedTelephonySuggestionReceived(int slotIndex,
+ QualifiedTelephonyTimeZoneSuggestion expectedQualifiedSuggestion) {
+ assertEquals(expectedQualifiedSuggestion,
+ mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(slotIndex));
+ return this;
+ }
+
Script resetConfigurationTracking() {
mFakeEnvironment.commitAllChanges();
return this;
@@ -1671,11 +1861,16 @@ public class TimeZoneDetectorStrategyImplTest {
mNotificationsReceived++;
}
- public void resetNotificationsReceivedCount() {
+ public void assertNotificationsReceivedAndReset(int expectedCount) {
+ assertNotificationsReceived(expectedCount);
+ resetNotificationsReceivedCount();
+ }
+
+ private void resetNotificationsReceivedCount() {
mNotificationsReceived = 0;
}
- public void assertNotificationsReceived(int expectedCount) {
+ private void assertNotificationsReceived(int expectedCount) {
assertEquals(expectedCount, mNotificationsReceived);
}
}
diff --git a/services/tests/servicestests/src/com/android/server/timezonedetector/location/LocationTimeZoneProviderControllerTest.java b/services/tests/servicestests/src/com/android/server/timezonedetector/location/LocationTimeZoneProviderControllerTest.java
index c18acd20e96a5..b08705be2eacb 100644
--- a/services/tests/servicestests/src/com/android/server/timezonedetector/location/LocationTimeZoneProviderControllerTest.java
+++ b/services/tests/servicestests/src/com/android/server/timezonedetector/location/LocationTimeZoneProviderControllerTest.java
@@ -15,6 +15,8 @@
*/
package com.android.server.timezonedetector.location;
+import static android.app.time.DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_NOT_RUNNING;
+import static android.app.time.DetectorStatusTypes.DETECTION_ALGORITHM_STATUS_RUNNING;
import static android.service.timezone.TimeZoneProviderStatus.DEPENDENCY_STATUS_NOT_APPLICABLE;
import static android.service.timezone.TimeZoneProviderStatus.DEPENDENCY_STATUS_OK;
import static android.service.timezone.TimeZoneProviderStatus.DEPENDENCY_STATUS_TEMPORARILY_UNAVAILABLE;
@@ -42,6 +44,7 @@ import static com.android.server.timezonedetector.location.TestSupport.USER2_CON
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -51,6 +54,7 @@ import static java.util.Arrays.asList;
import android.annotation.ElapsedRealtimeLong;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.app.time.DetectorStatusTypes.DetectionAlgorithmStatus;
import android.os.SystemClock;
import android.platform.test.annotations.Presubmit;
import android.service.timezone.TimeZoneProviderEvent;
@@ -60,6 +64,7 @@ import android.util.IndentingPrintWriter;
import com.android.server.timezonedetector.ConfigurationInternal;
import com.android.server.timezonedetector.GeolocationTimeZoneSuggestion;
+import com.android.server.timezonedetector.LocationAlgorithmEvent;
import com.android.server.timezonedetector.TestState;
import com.android.server.timezonedetector.location.LocationTimeZoneProvider.ProviderMetricsLogger;
import com.android.server.timezonedetector.location.LocationTimeZoneProvider.ProviderState.ProviderStateEnum;
@@ -141,7 +146,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestPrimaryLocationTimeZoneProvider.setFailDuringInitialization(true);
// Initialize. After initialization the providers must be initialized and one should be
- // started.
+ // started. They should report their status change via the callback.
controller.initialize(testEnvironment, mTestCallback);
mTestPrimaryLocationTimeZoneProvider.assertInitialized();
@@ -154,7 +159,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertInitializationTimeoutSet(expectedInitTimeout);
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -184,7 +190,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsPermFailedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -211,7 +218,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsPermFailedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING, STATE_FAILED);
- mTestCallback.assertUncertainSuggestionMadeAndCommit();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_NOT_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -239,7 +247,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -262,7 +271,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestPrimaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_PROVIDERS_INITIALIZING, STATE_STOPPED);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_NOT_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -282,7 +292,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate time passing with no provider event being received from the primary.
@@ -296,7 +307,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
// Simulate time passing with no provider event being received from either the primary or
@@ -311,7 +322,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_UNCERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
// Finally, the uncertainty timeout should cause the controller to make an uncertain
@@ -324,7 +335,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_UNCERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit(STATE_UNCERTAIN);
- mTestCallback.assertUncertainSuggestionMadeAndCommit();
+ mTestCallback.assertEventWithUncertainSuggestionReportedAndCommit();
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -345,7 +356,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate a location event being received from the primary provider. This should cause a
@@ -358,7 +370,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_CERTAIN);
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -380,7 +392,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate time passing with no provider event being received from the primary.
@@ -392,7 +405,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
// Simulate a location event being received from the primary provider. This should cause a
@@ -405,7 +418,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_CERTAIN);
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -427,7 +440,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate time passing with no provider event being received from the primary.
@@ -439,7 +453,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
// Simulate a location event being received from the secondary provider. This should cause a
@@ -453,7 +467,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit(STATE_CERTAIN);
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -475,7 +489,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate a location event being received from the primary provider. This should cause a
@@ -488,7 +503,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_CERTAIN);
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1);
assertFalse(controller.isUncertaintyTimeoutSet());
@@ -501,7 +516,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertFalse(controller.isUncertaintyTimeoutSet());
// And a third, different event should cause another suggestion.
@@ -513,7 +528,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT2);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -535,7 +550,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate time passing with no provider event being received from the primary.
@@ -547,7 +563,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
// Simulate a location event being received from the secondary provider. This should cause a
@@ -561,7 +577,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit(STATE_CERTAIN);
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1);
assertFalse(controller.isUncertaintyTimeoutSet());
@@ -575,7 +591,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertFalse(controller.isUncertaintyTimeoutSet());
// And a third, different event should cause another suggestion.
@@ -588,7 +604,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT2);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -610,7 +626,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate a location event being received from the primary provider. This should cause a
@@ -623,7 +640,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_CERTAIN);
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1);
assertFalse(controller.isUncertaintyTimeoutSet());
@@ -639,7 +656,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
// Simulate a location event being received from the secondary provider. This should cause a
@@ -654,7 +671,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT2);
assertFalse(controller.isUncertaintyTimeoutSet());
@@ -670,7 +687,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_UNCERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
// Simulate time passing. This means the uncertainty timeout should fire and the uncertain
@@ -683,7 +700,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_UNCERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit(STATE_UNCERTAIN);
- mTestCallback.assertUncertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithUncertainSuggestionReportedAndCommit(
USER1_UNCERTAIN_LOCATION_TIME_ZONE_EVENT);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -705,7 +722,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate a location event being received from the primary provider. This should cause a
@@ -718,7 +736,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_CERTAIN);
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1);
assertFalse(controller.isUncertaintyTimeoutSet());
@@ -733,7 +751,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
// And a success event from the primary provider should cause the controller to make another
@@ -747,7 +765,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT2);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -767,7 +785,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestPrimaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_PROVIDERS_INITIALIZING, STATE_STOPPED);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_NOT_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Now signal a config change so that geo detection is enabled.
@@ -778,7 +797,8 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Now signal a config change so that geo detection is disabled.
@@ -788,7 +808,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestPrimaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_STOPPED);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_NOT_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -807,7 +828,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestPrimaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_PROVIDERS_INITIALIZING, STATE_STOPPED);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_NOT_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Now signal a config change so that geo detection is enabled.
@@ -818,7 +840,8 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate a success event being received from the primary provider.
@@ -830,7 +853,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_CERTAIN);
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1);
assertFalse(controller.isUncertaintyTimeoutSet());
@@ -843,8 +866,9 @@ public class LocationTimeZoneProviderControllerTest {
assertControllerState(controller, STATE_STOPPED);
mTestPrimaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
- mTestMetricsLogger.assertStateChangesAndCommit(STATE_UNCERTAIN, STATE_STOPPED);
- mTestCallback.assertUncertainSuggestionMadeAndCommit();
+ mTestMetricsLogger.assertStateChangesAndCommit(STATE_STOPPED);
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_NOT_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -865,7 +889,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate the primary provider suggesting a time zone.
@@ -879,7 +904,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_CERTAIN);
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1);
assertFalse(controller.isUncertaintyTimeoutSet());
@@ -897,9 +922,9 @@ public class LocationTimeZoneProviderControllerTest {
mTestPrimaryLocationTimeZoneProvider.assertStateEnumAndConfig(
PROVIDER_STATE_STARTED_INITIALIZING, USER2_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
- mTestMetricsLogger.assertStateChangesAndCommit(
- STATE_UNCERTAIN, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertUncertainSuggestionMadeAndCommit();
+ mTestMetricsLogger.assertStateChangesAndCommit(STATE_STOPPED, STATE_INITIALIZING);
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -920,7 +945,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate a failure location event being received from the primary provider. This should
@@ -933,7 +959,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate uncertainty from the secondary.
@@ -945,7 +971,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_UNCERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
// And a success event from the secondary provider should cause the controller to make
@@ -958,7 +984,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit(STATE_CERTAIN);
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT2);
assertFalse(controller.isUncertaintyTimeoutSet());
@@ -971,7 +997,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_UNCERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
}
@@ -992,7 +1018,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate a failure location event being received from the primary provider. This should
@@ -1005,7 +1032,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertFalse(controller.isUncertaintyTimeoutSet());
// Now signal a config change so that geo detection is disabled.
@@ -1015,7 +1042,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestPrimaryLocationTimeZoneProvider.assertIsPermFailedAndCommit();
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_STOPPED);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_NOT_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Now signal a config change so that geo detection is enabled.
@@ -1026,7 +1054,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit(STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -1047,7 +1076,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate an uncertain event from the primary. This will start the secondary, which will
@@ -1062,7 +1092,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
// Simulate failure event from the secondary. This should just affect the secondary's state.
@@ -1074,7 +1104,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_UNCERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsPermFailedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
// And a success event from the primary provider should cause the controller to make
@@ -1087,7 +1117,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsPermFailedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_CERTAIN);
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT2);
assertFalse(controller.isUncertaintyTimeoutSet());
@@ -1100,7 +1130,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_UNCERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsPermFailedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
}
@@ -1121,7 +1151,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate an uncertain event from the primary. This will start the secondary, which will
@@ -1136,7 +1167,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
// Simulate failure event from the secondary. This should just affect the secondary's state.
@@ -1148,7 +1179,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_UNCERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsPermFailedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertUncertaintyTimeoutSet(testEnvironment, controller);
// Now signal a config change so that geo detection is disabled.
@@ -1158,7 +1189,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestPrimaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestSecondaryLocationTimeZoneProvider.assertIsPermFailedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_STOPPED);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_NOT_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Now signal a config change so that geo detection is enabled. Only the primary can be
@@ -1170,7 +1202,8 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsPermFailedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -1191,7 +1224,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate a failure event from the primary. This will start the secondary.
@@ -1203,7 +1237,7 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertStateEnumAndConfigAndCommit(
PROVIDER_STATE_STARTED_INITIALIZING, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestMetricsLogger.assertStateChangesAndCommit();
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertNoEventReported();
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate failure event from the secondary.
@@ -1214,7 +1248,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestPrimaryLocationTimeZoneProvider.assertIsPermFailedAndCommit();
mTestSecondaryLocationTimeZoneProvider.assertIsPermFailedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_FAILED);
- mTestCallback.assertUncertainSuggestionMadeAndCommit();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_NOT_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
}
@@ -1233,7 +1268,7 @@ public class LocationTimeZoneProviderControllerTest {
{
LocationTimeZoneManagerServiceState state = controller.getStateForTests();
assertEquals(STATE_INITIALIZING, state.getControllerState());
- assertNull(state.getLastSuggestion());
+ assertNull(state.getLastEvent().getSuggestion());
assertControllerRecordedStates(state,
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
assertProviderStates(state.getPrimaryProviderStates(),
@@ -1251,7 +1286,7 @@ public class LocationTimeZoneProviderControllerTest {
{
LocationTimeZoneManagerServiceState state = controller.getStateForTests();
assertEquals(STATE_INITIALIZING, state.getControllerState());
- assertNull(state.getLastSuggestion());
+ assertNull(state.getLastEvent().getSuggestion());
assertControllerRecordedStates(state);
assertProviderStates(
state.getPrimaryProviderStates(), PROVIDER_STATE_STARTED_UNCERTAIN);
@@ -1268,7 +1303,7 @@ public class LocationTimeZoneProviderControllerTest {
LocationTimeZoneManagerServiceState state = controller.getStateForTests();
assertEquals(STATE_CERTAIN, state.getControllerState());
assertEquals(USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1.getSuggestion().getTimeZoneIds(),
- state.getLastSuggestion().getZoneIds());
+ state.getLastEvent().getSuggestion().getZoneIds());
assertControllerRecordedStates(state, STATE_CERTAIN);
assertProviderStates(state.getPrimaryProviderStates());
assertProviderStates(
@@ -1280,7 +1315,7 @@ public class LocationTimeZoneProviderControllerTest {
LocationTimeZoneManagerServiceState state = controller.getStateForTests();
assertEquals(STATE_CERTAIN, state.getControllerState());
assertEquals(USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1.getSuggestion().getTimeZoneIds(),
- state.getLastSuggestion().getZoneIds());
+ state.getLastEvent().getSuggestion().getZoneIds());
assertControllerRecordedStates(state);
assertProviderStates(state.getPrimaryProviderStates());
assertProviderStates(state.getSecondaryProviderStates());
@@ -1313,7 +1348,8 @@ public class LocationTimeZoneProviderControllerTest {
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(
STATE_PROVIDERS_INITIALIZING, STATE_STOPPED, STATE_INITIALIZING);
- mTestCallback.assertNoSuggestionMade();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_RUNNING);
assertFalse(controller.isUncertaintyTimeoutSet());
// Simulate the primary provider suggesting a time zone.
@@ -1327,7 +1363,7 @@ public class LocationTimeZoneProviderControllerTest {
PROVIDER_STATE_STARTED_CERTAIN, USER1_CONFIG_GEO_DETECTION_ENABLED);
mTestSecondaryLocationTimeZoneProvider.assertIsStoppedAndCommit();
mTestMetricsLogger.assertStateChangesAndCommit(STATE_CERTAIN);
- mTestCallback.assertCertainSuggestionMadeFromEventAndCommit(
+ mTestCallback.assertEventWithCertainSuggestionReportedAndCommit(
USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1);
assertFalse(controller.isUncertaintyTimeoutSet());
@@ -1335,11 +1371,11 @@ public class LocationTimeZoneProviderControllerTest {
controller.destroy();
assertControllerState(controller, STATE_DESTROYED);
- mTestMetricsLogger.assertStateChangesAndCommit(
- STATE_UNCERTAIN, STATE_STOPPED, STATE_DESTROYED);
+ mTestMetricsLogger.assertStateChangesAndCommit(STATE_STOPPED, STATE_DESTROYED);
// Confirm that the previous suggestion was overridden.
- mTestCallback.assertUncertainSuggestionMadeAndCommit();
+ mTestCallback.assertEventWithNoSuggestionReportedAndCommit(
+ DETECTION_ALGORITHM_STATUS_NOT_RUNNING);
mTestPrimaryLocationTimeZoneProvider.assertStateChangesAndCommit(
PROVIDER_STATE_STOPPED, PROVIDER_STATE_DESTROYED);
@@ -1517,63 +1553,101 @@ public class LocationTimeZoneProviderControllerTest {
private static class TestCallback extends LocationTimeZoneProviderController.Callback {
- private TestState mLatestSuggestion = new TestState<>();
+ private TestState mLatestEvent = new TestState<>();
TestCallback(ThreadingDomain threadingDomain) {
super(threadingDomain);
}
@Override
- void suggest(GeolocationTimeZoneSuggestion suggestion) {
- mLatestSuggestion.set(suggestion);
+ void sendEvent(LocationAlgorithmEvent event) {
+ mLatestEvent.set(event);
}
- void assertCertainSuggestionMadeFromEventAndCommit(TimeZoneProviderEvent event) {
+ void assertNoEventReported() {
+ mLatestEvent.assertHasNotBeenSet();
+ }
+
+ /**
+ * Asserts one or more events have been reported, and the most recent does not contain a
+ * suggestion.
+ */
+ void assertEventWithNoSuggestionReportedAndCommit(
+ @DetectionAlgorithmStatus int expectedAlgorithmStatus) {
+ mLatestEvent.assertHasBeenSet();
+
+ LocationAlgorithmEvent latest = mLatestEvent.getLatest();
+ assertEquals(expectedAlgorithmStatus, latest.getAlgorithmStatus().getStatus());
+ assertNull(latest.getSuggestion());
+ mLatestEvent.commitLatest();
+ }
+
+ void assertEventWithCertainSuggestionReportedAndCommit(TimeZoneProviderEvent event) {
// Test coding error if this fails.
assertEquals(TimeZoneProviderEvent.EVENT_TYPE_SUGGESTION, event.getType());
+ // By definition, the algorithm has to be running to report a suggestion.
+ @DetectionAlgorithmStatus int expectedAlgorithmStatus =
+ DETECTION_ALGORITHM_STATUS_RUNNING;
TimeZoneProviderSuggestion suggestion = event.getSuggestion();
- assertSuggestionMadeAndCommit(
+ assertEventWithSuggestionReportedAndCommit(
+ expectedAlgorithmStatus,
suggestion.getElapsedRealtimeMillis(),
suggestion.getTimeZoneIds());
}
- void assertNoSuggestionMade() {
- mLatestSuggestion.assertHasNotBeenSet();
- }
-
- /** Asserts that an uncertain suggestion has been made from the supplied event. */
- void assertUncertainSuggestionMadeFromEventAndCommit(TimeZoneProviderEvent event) {
+ /**
+ * Asserts that one or more events have been reported, and the most recent contains an
+ * uncertain suggestion matching select details from the supplied provider event.
+ */
+ void assertEventWithUncertainSuggestionReportedAndCommit(TimeZoneProviderEvent event) {
// Test coding error if this fails.
assertEquals(TimeZoneProviderEvent.EVENT_TYPE_UNCERTAIN, event.getType());
- assertSuggestionMadeAndCommit(event.getCreationElapsedMillis(), null);
+ // By definition, the algorithm has to be running to report a suggestion.
+ @DetectionAlgorithmStatus int expectedAlgorithmStatus =
+ DETECTION_ALGORITHM_STATUS_RUNNING;
+ assertEventWithSuggestionReportedAndCommit(
+ expectedAlgorithmStatus, event.getCreationElapsedMillis(), null);
}
/**
- * Asserts that an uncertain suggestion has been made.
- * Ignores the suggestion's effectiveFromElapsedMillis.
+ * Asserts that one or more events have been reported, and the most recent contains an
+ * uncertain suggestion. Ignores the suggestion's effectiveFromElapsedMillis.
*/
- void assertUncertainSuggestionMadeAndCommit() {
+ void assertEventWithUncertainSuggestionReportedAndCommit() {
+ // By definition, the algorithm has to be running to report a suggestion.
+ @DetectionAlgorithmStatus int expectedAlgorithmStatus =
+ DETECTION_ALGORITHM_STATUS_RUNNING;
+
// An "uncertain" suggestion has null time zone IDs.
- assertSuggestionMadeAndCommit(null, null);
+ assertEventWithSuggestionReportedAndCommit(expectedAlgorithmStatus, null, null);
}
/**
- * Asserts that a suggestion has been made and some properties of that suggestion.
- * When expectedEffectiveFromElapsedMillis is null then its value isn't checked.
+ * Asserts that an event has been reported containing a suggestion and some properties of
+ * that suggestion. When expectedEffectiveFromElapsedMillis is null then its value isn't
+ * checked.
*/
- private void assertSuggestionMadeAndCommit(
+ private void assertEventWithSuggestionReportedAndCommit(
+ @DetectionAlgorithmStatus int expectedAlgorithmStatus,
@Nullable @ElapsedRealtimeLong Long expectedEffectiveFromElapsedMillis,
@Nullable List expectedZoneIds) {
- mLatestSuggestion.assertHasBeenSet();
+ mLatestEvent.assertHasBeenSet();
+
+ LocationAlgorithmEvent latestEvent = mLatestEvent.getLatest();
+ assertEquals(expectedAlgorithmStatus, latestEvent.getAlgorithmStatus().getStatus());
+
+ GeolocationTimeZoneSuggestion suggestion = latestEvent.getSuggestion();
+ assertNotNull("Latest event doesn't contain a suggestion: event=" + latestEvent,
+ suggestion);
+
if (expectedEffectiveFromElapsedMillis != null) {
- assertEquals(
- expectedEffectiveFromElapsedMillis.longValue(),
- mLatestSuggestion.getLatest().getEffectiveFromElapsedMillis());
+ assertEquals(expectedEffectiveFromElapsedMillis.longValue(),
+ suggestion.getEffectiveFromElapsedMillis());
}
- assertEquals(expectedZoneIds, mLatestSuggestion.getLatest().getZoneIds());
- mLatestSuggestion.commitLatest();
+ assertEquals(expectedZoneIds, suggestion.getZoneIds());
+ mLatestEvent.commitLatest();
}
}