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

Commit 85327e0e authored by Neil Fuller's avatar Neil Fuller
Browse files

Add "Use location" state to TimeZoneCapabilities

Add the user's "Use location" state to TimeZoneCapabilities. This
information is available anyway and saves the SettingsUI needing to call
LocationManager directly (with the small possibility it would get an
inconsistent answer).

Bug: 262407244
Test: atest tests/robotests/src/com/android/settings/datetime/
Change-Id: I49d4e41b27f9817b3189a7643c24237603e36396
parent 7bde01ab
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -19,10 +19,12 @@ import android.app.time.DetectorStatusTypes;
import android.app.time.LocationTimeZoneAlgorithmStatus;
import android.app.time.TelephonyTimeZoneAlgorithmStatus;
import android.app.time.TimeManager;
import android.app.time.TimeZoneCapabilities;
import android.app.time.TimeZoneCapabilitiesAndConfig;
import android.app.time.TimeZoneDetectorStatus;
import android.content.Context;
import android.location.LocationManager;
import android.service.timezone.TimeZoneProviderStatus;
import android.service.timezone.TimeZoneProviderStatus.DependencyStatus;
import android.text.TextUtils;

import androidx.annotation.Nullable;
@@ -43,14 +45,12 @@ import java.util.concurrent.Executor;
public class LocationProviderStatusPreferenceController
        extends BasePreferenceController implements TimeManager.TimeZoneDetectorListener {
    private final TimeManager mTimeManager;
    private final LocationManager mLocationManager;

    private BannerMessagePreference mPreference = null;

    public LocationProviderStatusPreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
        mTimeManager = context.getSystemService(TimeManager.class);
        mLocationManager = context.getSystemService(LocationManager.class);

        Executor mainExecutor = context.getMainExecutor();
        mTimeManager.addTimeZoneDetectorListener(mainExecutor, this);
@@ -123,11 +123,15 @@ public class LocationProviderStatusPreferenceController

    @Override
    public CharSequence getSummary() {
        boolean locationEnabled = mLocationManager.isLocationEnabled();
        final TimeZoneCapabilitiesAndConfig timeZoneCapabilitiesAndConfig =
                mTimeManager.getTimeZoneCapabilitiesAndConfig();
        final TimeZoneDetectorStatus detectorStatus =
                mTimeManager.getTimeZoneCapabilitiesAndConfig().getDetectorStatus();
                timeZoneCapabilitiesAndConfig.getDetectorStatus();
        final TimeZoneCapabilities timeZoneCapabilities =
                timeZoneCapabilitiesAndConfig.getCapabilities();

        if (!locationEnabled && hasLocationTimeZoneNoTelephonyFallback(detectorStatus)) {
        if (!timeZoneCapabilities.isUseLocationEnabled()
                && hasLocationTimeZoneNoTelephonyFallback(detectorStatus)) {
            return mContext.getResources().getString(
                    R.string.location_time_zone_detection_status_summary_blocked_by_settings);
        }
@@ -137,7 +141,7 @@ public class LocationProviderStatusPreferenceController
            return "";
        }

        int status = ltzpStatus.getLocationDetectionDependencyStatus();
        @DependencyStatus int status = ltzpStatus.getLocationDetectionDependencyStatus();

        if (status == TimeZoneProviderStatus.DEPENDENCY_STATUS_BLOCKED_BY_ENVIRONMENT) {
            return mContext.getResources().getString(
+17 −10
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.app.time.TimeZoneCapabilities;
import android.app.time.TimeZoneCapabilitiesAndConfig;
import android.app.time.TimeZoneConfiguration;
import android.content.Context;
import android.location.LocationManager;

import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -50,7 +49,6 @@ public class LocationTimeZoneDetectionPreferenceController
    private static final String TAG = "location_time_zone_detection";

    private final TimeManager mTimeManager;
    private final LocationManager mLocationManager;
    private TimeZoneCapabilitiesAndConfig mTimeZoneCapabilitiesAndConfig;
    private InstrumentedPreferenceFragment mFragment;
    private Preference mPreference;
@@ -58,7 +56,6 @@ public class LocationTimeZoneDetectionPreferenceController
    public LocationTimeZoneDetectionPreferenceController(Context context) {
        super(context, TAG);
        mTimeManager = context.getSystemService(TimeManager.class);
        mLocationManager = context.getSystemService(LocationManager.class);
    }

    void setFragment(InstrumentedPreferenceFragment fragment) {
@@ -68,14 +65,18 @@ public class LocationTimeZoneDetectionPreferenceController
    @Override
    public boolean isChecked() {
        TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
                mTimeManager.getTimeZoneCapabilitiesAndConfig();
                getTimeZoneCapabilitiesAndConfig(/*forceRefresh=*/false);
        TimeZoneConfiguration configuration = capabilitiesAndConfig.getConfiguration();
        return configuration.isGeoDetectionEnabled();
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        if (isChecked && !mLocationManager.isLocationEnabled()) {
        TimeZoneCapabilitiesAndConfig timeZoneCapabilitiesAndConfig =
                getTimeZoneCapabilitiesAndConfig(/*forceRefresh=*/false);
        boolean isLocationEnabled =
                timeZoneCapabilitiesAndConfig.getCapabilities().isUseLocationEnabled();
        if (isChecked && !isLocationEnabled) {
            new LocationToggleDisabledDialogFragment(mContext)
                    .show(mFragment.getFragmentManager(), TAG);
            // Toggle status is not updated.
@@ -157,11 +158,13 @@ public class LocationTimeZoneDetectionPreferenceController
            // The preference should not be visible, but text is referenced in case this changes.
            summaryResId = R.string.location_time_zone_detection_not_allowed;
        } else if (configureGeoDetectionEnabledCapability == CAPABILITY_NOT_APPLICABLE) {
            // The TimeZoneCapabilities deliberately doesn't provide information about why the user
            // doesn't have the capability, but the user's "location enabled" being off and the
            // global automatic detection setting will always be considered overriding reasons why
            // location time zone detection cannot be used.
            if (!mLocationManager.isLocationEnabled()) {
            boolean isLocationEnabled =
                    timeZoneCapabilitiesAndConfig.getCapabilities().isUseLocationEnabled();
            // The TimeZoneCapabilities cannot provide implementation-specific information about why
            // the user doesn't have the capability, but the user's "location enabled" being off and
            // the global automatic detection setting will always be considered overriding reasons
            // why location time zone detection cannot be used.
            if (!isLocationEnabled) {
                summaryResId = R.string.location_app_permission_summary_location_off;
            } else if (!configuration.isAutoDetectionEnabled()) {
                summaryResId = R.string.location_time_zone_detection_auto_is_off;
@@ -184,6 +187,10 @@ public class LocationTimeZoneDetectionPreferenceController
        return mContext.getString(summaryResId);
    }

    /**
     * Implementation of {@link TimeManager.TimeZoneDetectorListener#onChange()}. Called by the
     * system server after a change that affects {@link TimeZoneCapabilitiesAndConfig}.
     */
    @Override
    public void onChange() {
        refreshUi();
+1 −6
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import android.app.time.TimeZoneCapabilitiesAndConfig;
import android.app.time.TimeZoneConfiguration;
import android.app.time.TimeZoneDetectorStatus;
import android.content.Context;
import android.location.LocationManager;
import android.os.UserHandle;

import androidx.preference.Preference;
@@ -62,8 +61,6 @@ public class AutoTimeZonePreferenceControllerTest {
    private Preference mPreference;
    @Mock
    private TimeManager mTimeManager;
    @Mock
    private LocationManager mLocationManager;

    @Before
    public void setUp() {
@@ -73,9 +70,6 @@ public class AutoTimeZonePreferenceControllerTest {
        mPreference = new Preference(mContext);

        when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
        when(mContext.getSystemService(LocationManager.class)).thenReturn(mLocationManager);

        when(mLocationManager.isLocationEnabled()).thenReturn(true);
    }

    @Test
@@ -267,6 +261,7 @@ public class AutoTimeZonePreferenceControllerTest {
                        : Capabilities.CAPABILITY_NOT_SUPPORTED;
        TimeZoneCapabilities capabilities = new TimeZoneCapabilities.Builder(UserHandle.SYSTEM)
                .setConfigureAutoDetectionEnabledCapability(configureAutoDetectionEnabledCapability)
                .setUseLocationEnabled(true)
                .setConfigureGeoDetectionEnabledCapability(Capabilities.CAPABILITY_NOT_SUPPORTED)
                .setSetManualTimeZoneCapability(Capabilities.CAPABILITY_POSSESSED)
                .build();
+90 −53
Original line number Diff line number Diff line
@@ -29,7 +29,9 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import android.app.time.Capabilities;
import android.app.time.Capabilities.CapabilityState;
import android.app.time.LocationTimeZoneAlgorithmStatus;
import android.app.time.LocationTimeZoneAlgorithmStatus.ProviderStatus;
import android.app.time.TelephonyTimeZoneAlgorithmStatus;
import android.app.time.TimeManager;
import android.app.time.TimeZoneCapabilities;
@@ -37,9 +39,9 @@ import android.app.time.TimeZoneCapabilitiesAndConfig;
import android.app.time.TimeZoneConfiguration;
import android.app.time.TimeZoneDetectorStatus;
import android.content.Context;
import android.location.LocationManager;
import android.os.UserHandle;
import android.service.timezone.TimeZoneProviderStatus;
import android.service.timezone.TimeZoneProviderStatus.DependencyStatus;

import androidx.annotation.Nullable;

@@ -60,8 +62,6 @@ public class LocationProviderStatusPreferenceControllerTest {
    private Context mContext;
    @Mock
    private TimeManager mTimeManager;
    @Mock
    private LocationManager mLocationManager;

    @Before
    public void setUp() {
@@ -69,8 +69,6 @@ public class LocationProviderStatusPreferenceControllerTest {
        mContext = spy(RuntimeEnvironment.application);

        when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
        when(mContext.getSystemService(LocationManager.class)).thenReturn(mLocationManager);
        when(mLocationManager.isLocationEnabled()).thenReturn(true);
        when(mContext.getString(
                R.string.location_time_zone_detection_status_summary_blocked_by_settings))
                .thenReturn("BBS");
@@ -78,11 +76,12 @@ public class LocationProviderStatusPreferenceControllerTest {

    @Test
    public void testCapabilityStatus() {
        LocationProviderStatusPreferenceController controller =
                new LocationProviderStatusPreferenceController(mContext, "LPSPC");

        TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                DEPENDENCY_STATUS_OK, DEPENDENCY_STATUS_OK);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
        LocationProviderStatusPreferenceController controller =
                new LocationProviderStatusPreferenceController(mContext, "LPSPC");

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
@@ -95,14 +94,16 @@ public class LocationProviderStatusPreferenceControllerTest {
                BasePreferenceController.CONDITIONALLY_UNAVAILABLE);

        capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS, DEPENDENCY_STATUS_OK);
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.AVAILABLE_UNSEARCHABLE);

        capabilitiesAndConfig = createCapabilitiesAndConfig(true,
                DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS, DEPENDENCY_STATUS_OK);
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
@@ -111,31 +112,36 @@ public class LocationProviderStatusPreferenceControllerTest {

    @Test
    public void testProviderStatus_primaryCertain() {
        TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                DEPENDENCY_STATUS_OK, DEPENDENCY_STATUS_OK);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
        LocationProviderStatusPreferenceController controller =
                new LocationProviderStatusPreferenceController(mContext, "LPSPC");

        TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.CONDITIONALLY_UNAVAILABLE);

        capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS, DEPENDENCY_STATUS_OK);
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.AVAILABLE_UNSEARCHABLE);

        capabilitiesAndConfig = createCapabilitiesAndConfig(false, DEPENDENCY_STATUS_OK,
                DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
        capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.CONDITIONALLY_UNAVAILABLE);

        capabilitiesAndConfig = createCapabilitiesAndConfig(false, DEPENDENCY_STATUS_OK,
                DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
        capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
@@ -144,32 +150,36 @@ public class LocationProviderStatusPreferenceControllerTest {

    @Test
    public void testProviderStatus_primaryUncertain() {
        TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                DEPENDENCY_STATUS_OK, DEPENDENCY_STATUS_OK, PROVIDER_STATUS_IS_CERTAIN);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
        LocationProviderStatusPreferenceController controller =
                new LocationProviderStatusPreferenceController(mContext, "LPSPC");

        TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.CONDITIONALLY_UNAVAILABLE);

        capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS, DEPENDENCY_STATUS_OK,
                PROVIDER_STATUS_IS_CERTAIN);
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.AVAILABLE_UNSEARCHABLE);

        capabilitiesAndConfig = createCapabilitiesAndConfig(false, DEPENDENCY_STATUS_OK,
                DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS, PROVIDER_STATUS_IS_UNCERTAIN);
        capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                PROVIDER_STATUS_IS_UNCERTAIN, DEPENDENCY_STATUS_OK,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.AVAILABLE_UNSEARCHABLE);

        capabilitiesAndConfig = createCapabilitiesAndConfig(false, DEPENDENCY_STATUS_OK,
                DEPENDENCY_STATUS_OK, PROVIDER_STATUS_IS_UNCERTAIN);
        capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                PROVIDER_STATUS_IS_UNCERTAIN, DEPENDENCY_STATUS_OK,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_OK);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
@@ -177,18 +187,21 @@ public class LocationProviderStatusPreferenceControllerTest {
    }

    @Test
    public void testProviderStatus_nullProviders() {
        TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                null, null);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
    public void testProviderStatus_nullProviderStatuses() {
        LocationProviderStatusPreferenceController controller =
                new LocationProviderStatusPreferenceController(mContext, "LPSPC");

        TimeZoneCapabilitiesAndConfig capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                PROVIDER_STATUS_IS_CERTAIN, null,
                PROVIDER_STATUS_IS_CERTAIN, null);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.CONDITIONALLY_UNAVAILABLE);

        capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS, null);
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS,
                PROVIDER_STATUS_IS_CERTAIN, null);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
@@ -200,39 +213,63 @@ public class LocationProviderStatusPreferenceControllerTest {
        assertThat(controller.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.CONDITIONALLY_UNAVAILABLE);

        capabilitiesAndConfig = createCapabilitiesAndConfig(false, null,
                DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
        capabilitiesAndConfig = createCapabilitiesAndConfig(false,
                PROVIDER_STATUS_IS_CERTAIN, null,
                PROVIDER_STATUS_IS_CERTAIN, DEPENDENCY_STATUS_BLOCKED_BY_SETTINGS);
        when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);

        assertThat(controller.getAvailabilityStatus()).isEqualTo(
                BasePreferenceController.AVAILABLE_UNSEARCHABLE);
    }

    private TimeZoneCapabilitiesAndConfig createCapabilitiesAndConfig(boolean capabilitySupported,
            @Nullable Integer primary, @Nullable Integer secondary) {
        return createCapabilitiesAndConfig(capabilitySupported, primary, secondary,
                PROVIDER_STATUS_IS_CERTAIN);
    private static TimeZoneCapabilitiesAndConfig createCapabilitiesAndConfig(
            boolean userCanConfigureGeoDetection,
            @Nullable @DependencyStatus Integer primaryProviderLocationStatus,
            @Nullable @DependencyStatus Integer secondaryProviderLocationStatus) {
        return createCapabilitiesAndConfig(userCanConfigureGeoDetection,
                PROVIDER_STATUS_IS_CERTAIN, primaryProviderLocationStatus,
                PROVIDER_STATUS_IS_CERTAIN, secondaryProviderLocationStatus);
    }

    private TimeZoneCapabilitiesAndConfig createCapabilitiesAndConfig(boolean capabilitySupported,
            @Nullable Integer primary, @Nullable Integer secondary, int primaryProviderStatus) {
        TimeZoneDetectorStatus status = new TimeZoneDetectorStatus(DETECTOR_STATUS_RUNNING,
                new TelephonyTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING),
    private static TimeZoneCapabilitiesAndConfig createCapabilitiesAndConfig(
            boolean userCanConfigureGeoDetection,
            @ProviderStatus int primaryProviderStatus,
            @Nullable @DependencyStatus Integer primaryProviderLocationStatus,
            @ProviderStatus int secondaryProviderStatus,
            @Nullable @DependencyStatus Integer secondaryProviderLocationStatus) {
        TelephonyTimeZoneAlgorithmStatus telephonyTimeZoneAlgorithmStatus =
                new TelephonyTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING);

        LocationTimeZoneAlgorithmStatus locationTimeZoneAlgorithmStatus =
                new LocationTimeZoneAlgorithmStatus(DETECTION_ALGORITHM_STATUS_RUNNING,
                        primaryProviderStatus, primary != null
                        ? new TimeZoneProviderStatus.Builder().setLocationDetectionDependencyStatus(
                        primary).build() : null, PROVIDER_STATUS_IS_CERTAIN, secondary != null
                        ? new TimeZoneProviderStatus.Builder().setLocationDetectionDependencyStatus(
                        secondary).build() : null));

        TimeZoneCapabilities capabilities = new TimeZoneCapabilities.Builder(
                UserHandle.SYSTEM).setConfigureAutoDetectionEnabledCapability(
                Capabilities.CAPABILITY_POSSESSED).setConfigureGeoDetectionEnabledCapability(
                capabilitySupported ? Capabilities.CAPABILITY_POSSESSED
                        : Capabilities.CAPABILITY_NOT_SUPPORTED).setSetManualTimeZoneCapability(
                Capabilities.CAPABILITY_POSSESSED).build();
                        primaryProviderStatus,
                        createTimeZoneProviderStatusOrNull(primaryProviderLocationStatus),
                        secondaryProviderStatus,
                        createTimeZoneProviderStatusOrNull(secondaryProviderLocationStatus));

        TimeZoneDetectorStatus status = new TimeZoneDetectorStatus(DETECTOR_STATUS_RUNNING,
                telephonyTimeZoneAlgorithmStatus, locationTimeZoneAlgorithmStatus);

        @CapabilityState int configureGeoDetectionEnabledCapability = userCanConfigureGeoDetection
                ? Capabilities.CAPABILITY_POSSESSED : Capabilities.CAPABILITY_NOT_SUPPORTED;
        TimeZoneCapabilities capabilities = new TimeZoneCapabilities.Builder(UserHandle.SYSTEM)
                .setConfigureAutoDetectionEnabledCapability(Capabilities.CAPABILITY_POSSESSED)
                .setUseLocationEnabled(true)
                .setConfigureGeoDetectionEnabledCapability(configureGeoDetectionEnabledCapability)
                .setSetManualTimeZoneCapability(Capabilities.CAPABILITY_POSSESSED)
                .build();

        return new TimeZoneCapabilitiesAndConfig(status, capabilities,
                new TimeZoneConfiguration.Builder().build());
    }

    private static TimeZoneProviderStatus createTimeZoneProviderStatusOrNull(
            @Nullable @DependencyStatus Integer locationDependencyStatusOrNull) {
        if (locationDependencyStatusOrNull == null) {
            return null;
        }
        return new TimeZoneProviderStatus.Builder()
                .setLocationDetectionDependencyStatus(locationDependencyStatusOrNull)
                .build();
    }
}
+29 −16

File changed.

Preview size limit exceeded, changes collapsed.

Loading