From 21891c40f1217564fa30e5dde726bd9ab550dbe1 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Wed, 23 Nov 2022 16:14:45 +0000 Subject: [PATCH] Improve info about location algorithm status Be more informative about location algorithm status than "unknown": It's possible for the time zone detector to tell when the location algorithm is supported, not running, or running (but not yet reported an event). Bug: 236624675 Test: atest services/tests/servicestests/src/com/android/server/timezonedetector/ Change-Id: I1cf569efe1f00cfa2faee02f76b84a71a68fb8ad --- .../time/LocationTimeZoneAlgorithmStatus.java | 25 ++++++++++++++----- .../TimeZoneDetectorStrategyImpl.java | 22 +++++++++++++--- .../TimeZoneDetectorStrategyImplTest.java | 2 +- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/core/java/android/app/time/LocationTimeZoneAlgorithmStatus.java b/core/java/android/app/time/LocationTimeZoneAlgorithmStatus.java index 710b8c40cefe8..ec10d8431e741 100644 --- a/core/java/android/app/time/LocationTimeZoneAlgorithmStatus.java +++ b/core/java/android/app/time/LocationTimeZoneAlgorithmStatus.java @@ -16,8 +16,9 @@ package android.app.time; +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.DetectorStatusTypes.detectionAlgorithmStatusFromString; import static android.app.time.DetectorStatusTypes.detectionAlgorithmStatusToString; import static android.app.time.DetectorStatusTypes.requireValidDetectionAlgorithmStatus; @@ -86,12 +87,24 @@ public final class LocationTimeZoneAlgorithmStatus implements Parcelable { public static final @ProviderStatus int PROVIDER_STATUS_IS_UNCERTAIN = 4; /** - * An instance that provides no information about algorithm status because the algorithm has not - * yet reported. Effectively a "null" status placeholder. + * An instance used when the location algorithm is not supported by the device. */ - @NonNull - public static final LocationTimeZoneAlgorithmStatus UNKNOWN = - new LocationTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_UNKNOWN, + public static final LocationTimeZoneAlgorithmStatus NOT_SUPPORTED = + new LocationTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_NOT_SUPPORTED, + PROVIDER_STATUS_NOT_PRESENT, null, PROVIDER_STATUS_NOT_PRESENT, null); + + /** + * An instance used when the location algorithm is running, but has not reported an event. + */ + public static final LocationTimeZoneAlgorithmStatus RUNNING_NOT_REPORTED = + new LocationTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_NOT_RUNNING, + PROVIDER_STATUS_NOT_READY, null, PROVIDER_STATUS_NOT_READY, null); + + /** + * An instance used when the location algorithm is supported but not running. + */ + public static final LocationTimeZoneAlgorithmStatus NOT_RUNNING = + new LocationTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_NOT_RUNNING, PROVIDER_STATUS_NOT_READY, null, PROVIDER_STATUS_NOT_READY, null); private final @DetectionAlgorithmStatus int mStatus; diff --git a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java index 12d0f3ca2425f..fa811efcfec02 100644 --- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java +++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java @@ -1050,14 +1050,30 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat TelephonyTimeZoneAlgorithmStatus telephonyAlgorithmStatus = createTelephonyAlgorithmStatus(currentConfigurationInternal); - LocationTimeZoneAlgorithmStatus locationAlgorithmStatus = - latestLocationAlgorithmEvent == null ? LocationTimeZoneAlgorithmStatus.UNKNOWN - : latestLocationAlgorithmEvent.getAlgorithmStatus(); + LocationTimeZoneAlgorithmStatus locationAlgorithmStatus = createLocationAlgorithmStatus( + currentConfigurationInternal, latestLocationAlgorithmEvent); return new TimeZoneDetectorStatus( detectorStatus, telephonyAlgorithmStatus, locationAlgorithmStatus); } + @NonNull + private static LocationTimeZoneAlgorithmStatus createLocationAlgorithmStatus( + ConfigurationInternal currentConfigurationInternal, + LocationAlgorithmEvent latestLocationAlgorithmEvent) { + LocationTimeZoneAlgorithmStatus locationAlgorithmStatus; + if (latestLocationAlgorithmEvent != null) { + locationAlgorithmStatus = latestLocationAlgorithmEvent.getAlgorithmStatus(); + } else if (!currentConfigurationInternal.isGeoDetectionSupported()) { + locationAlgorithmStatus = LocationTimeZoneAlgorithmStatus.NOT_SUPPORTED; + } else if (currentConfigurationInternal.isGeoDetectionExecutionEnabled()) { + locationAlgorithmStatus = LocationTimeZoneAlgorithmStatus.RUNNING_NOT_REPORTED; + } else { + locationAlgorithmStatus = LocationTimeZoneAlgorithmStatus.NOT_RUNNING; + } + return locationAlgorithmStatus; + } + @NonNull private static TelephonyTimeZoneAlgorithmStatus createTelephonyAlgorithmStatus( @NonNull ConfigurationInternal currentConfigurationInternal) { 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 b991c5a304156..74efdb5d6d989 100644 --- a/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorStrategyImplTest.java +++ b/services/tests/servicestests/src/com/android/server/timezonedetector/TimeZoneDetectorStrategyImplTest.java @@ -880,7 +880,7 @@ public class TimeZoneDetectorStrategyImplTest { TimeZoneDetectorStatus expectedInitialDetectorStatus = new TimeZoneDetectorStatus( DETECTOR_STATUS_RUNNING, TELEPHONY_ALGORITHM_RUNNING_STATUS, - LocationTimeZoneAlgorithmStatus.UNKNOWN); + LocationTimeZoneAlgorithmStatus.RUNNING_NOT_REPORTED); script.verifyCachedDetectorStatus(expectedInitialDetectorStatus); LocationTimeZoneAlgorithmStatus algorithmStatus1 = new LocationTimeZoneAlgorithmStatus(