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
This commit is contained in:
Neil Fuller
2022-11-23 16:14:45 +00:00
parent 4e5a7a11df
commit 21891c40f1
3 changed files with 39 additions and 10 deletions

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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(