diff options
| author | 2022-11-23 16:14:45 +0000 | |
|---|---|---|
| committer | 2022-11-24 15:50:18 +0000 | |
| commit | 21891c40f1217564fa30e5dde726bd9ab550dbe1 (patch) | |
| tree | ec4dbd7067e391e58c7e8ff8223db7f7bbd60858 | |
| parent | 4e5a7a11df1c97e23a2a516d7be2b6c7ece72937 (diff) | |
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
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 710b8c40cefe..ec10d8431e74 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 12d0f3ca2425..fa811efcfec0 100644 --- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java +++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java @@ -1050,15 +1050,31 @@ 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) { int algorithmStatus; 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 b991c5a30415..74efdb5d6d98 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( |