Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2e2f95fd authored by Neil Fuller's avatar Neil Fuller Committed by Android (Google) Code Review
Browse files

Merge "Improve info about location algorithm status"

parents f2ad1ae9 21891c40
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -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;
+19 −3
Original line number Diff line number Diff line
@@ -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) {
+1 −1
Original line number Diff line number Diff line
@@ -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(