diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2332909e5a0..a9175342351 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4050,18 +4050,8 @@
Location services for work
-
- Use location to set time zone
-
- Location time zone detection
-
- Allows the device\u2019s location to be used to detect the current time zone. Other location settings such as Wi\u2011Fi scanning can affect the accuracy of time zone detection.
-
-
- On
-
- Off
+
+ Use location to set time zone
diff --git a/res/xml/date_time_prefs.xml b/res/xml/date_time_prefs.xml
index 43a797a4b0c..6fc0b25d1d5 100644
--- a/res/xml/date_time_prefs.xml
+++ b/res/xml/date_time_prefs.xml
@@ -53,12 +53,12 @@
settings:keywords="@string/keywords_time_zone"/>
-
+ settings:userRestriction="no_config_date_time"
+ />
-
-
-
-
-
-
-
diff --git a/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceController.java b/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceController.java
index bbfbb193e17..1a45640c1df 100644
--- a/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceController.java
+++ b/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceController.java
@@ -31,7 +31,7 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
@@ -43,7 +43,7 @@ import java.util.concurrent.Executor;
* screen.
*/
public class LocationTimeZoneDetectionPreferenceController
- extends BasePreferenceController
+ extends TogglePreferenceController
implements LifecycleObserver, OnStart, OnStop, TimeManager.TimeZoneDetectorListener {
private final TimeManager mTimeManager;
@@ -57,6 +57,22 @@ public class LocationTimeZoneDetectionPreferenceController
mLocationManager = context.getSystemService(LocationManager.class);
}
+ @Override
+ public boolean isChecked() {
+ TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
+ mTimeManager.getTimeZoneCapabilitiesAndConfig();
+ TimeZoneConfiguration configuration = capabilitiesAndConfig.getConfiguration();
+ return configuration.isGeoDetectionEnabled();
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
+ .setGeoDetectionEnabled(isChecked)
+ .build();
+ return mTimeManager.updateTimeZoneConfiguration(configuration);
+ }
+
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
@@ -126,10 +142,10 @@ public class LocationTimeZoneDetectionPreferenceController
summaryResId = R.string.location_time_zone_detection_not_applicable;
}
} else if (configureGeoDetectionEnabledCapability == CAPABILITY_POSSESSED) {
- boolean isGeoDetectionEnabled = configuration.isGeoDetectionEnabled();
- summaryResId = isGeoDetectionEnabled
- ? R.string.location_time_zone_detection_on
- : R.string.location_time_zone_detection_off;
+ // If capability is possessed, toggle status already tells all the information needed.
+ // Returning null will make previous text stick on toggling.
+ // See AbstractPreferenceController#refreshSummary.
+ return "";
} else {
// This is unexpected: getAvailabilityStatus() should ensure that the UI element isn't
// even shown for known cases, or the capability is unknown.
diff --git a/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettings.java b/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettings.java
deleted file mode 100644
index db6ffc40e33..00000000000
--- a/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettings.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.datetime.locationtimezone;
-
-import android.app.settings.SettingsEnums;
-
-import com.android.settings.R;
-import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settingslib.search.SearchIndexable;
-
-/**
- * The controller for the "location time zone detection" screen.
- */
-@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
-public class TimeZoneDetectionSettings extends DashboardFragment {
- private static final String TAG = "LTZDetectionSettings";
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.LOCATION_TIME_ZONE_DETECTION;
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.location_time_zone_detection;
- }
-
- @Override
- protected String getLogTag() {
- return TAG;
- }
-
- /**
- * For Search.
- */
- public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider(R.xml.location_time_zone_detection);
-}
diff --git a/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceController.java b/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceController.java
deleted file mode 100644
index c91be7f1ed5..00000000000
--- a/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceController.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.datetime.locationtimezone;
-
-import android.app.time.TimeManager;
-import android.app.time.TimeZoneCapabilitiesAndConfig;
-import android.app.time.TimeZoneConfiguration;
-import android.content.Context;
-
-import com.android.settings.core.TogglePreferenceController;
-
-/**
- * The controller for the "location time zone detection" switch on the location time zone detection
- * screen.
- */
-public class TimeZoneDetectionTogglePreferenceController extends TogglePreferenceController {
-
- private final TimeManager mTimeManager;
-
- public TimeZoneDetectionTogglePreferenceController(Context context, String key) {
- super(context, key);
- mTimeManager = context.getSystemService(TimeManager.class);
- }
-
- @Override
- public int getAvailabilityStatus() {
- return AVAILABLE;
- }
-
- @Override
- public boolean isChecked() {
- TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
- mTimeManager.getTimeZoneCapabilitiesAndConfig();
- TimeZoneConfiguration configuration = capabilitiesAndConfig.getConfiguration();
- return configuration.isGeoDetectionEnabled();
- }
-
- @Override
- public boolean setChecked(boolean isChecked) {
- TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
- .setGeoDetectionEnabled(isChecked)
- .build();
- return mTimeManager.updateTimeZoneConfiguration(configuration);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceControllerTest.java
index 07588691b00..ae200b9a709 100644
--- a/tests/robotests/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/LocationTimeZoneDetectionPreferenceControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2018 The Android Open Source Project
+ * Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import static android.app.time.TimeZoneCapabilities.CAPABILITY_POSSESSED;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.time.TimeManager;
@@ -61,10 +62,34 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
mController = new LocationTimeZoneDetectionPreferenceController(mContext, "key");
}
+ @Test
+ public void setChecked_withTrue_shouldUpdateSetting() {
+ // Simulate the UI being clicked.
+ mController.setChecked(true);
+
+ // Verify the TimeManager was updated with the UI value.
+ TimeZoneConfiguration expectedConfiguration = new TimeZoneConfiguration.Builder()
+ .setGeoDetectionEnabled(true)
+ .build();
+ verify(mTimeManager).updateTimeZoneConfiguration(expectedConfiguration);
+ }
+
+ @Test
+ public void setChecked_withFalse_shouldUpdateSetting() {
+ // Simulate the UI being clicked.
+ mController.setChecked(false);
+
+ // Verify the TimeManager was updated with the UI value.
+ TimeZoneConfiguration expectedConfiguration = new TimeZoneConfiguration.Builder()
+ .setGeoDetectionEnabled(false)
+ .build();
+ verify(mTimeManager).updateTimeZoneConfiguration(expectedConfiguration);
+ }
+
@Test
public void testLocationTimeZoneDetection_supported_shouldBeShown() {
TimeZoneCapabilities capabilities =
- createTimeZoneCapabilities(/* geoDetectionSupported= */ true);
+ createTimeZoneCapabilities(CAPABILITY_POSSESSED);
TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true);
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
new TimeZoneCapabilitiesAndConfig(capabilities, configuration);
@@ -76,7 +101,7 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
@Test
public void testLocationTimeZoneDetection_unsupported_shouldNotBeShown() {
TimeZoneCapabilities capabilities =
- createTimeZoneCapabilities(/* geoDetectionSupported= */ false);
+ createTimeZoneCapabilities(CAPABILITY_NOT_SUPPORTED);
TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true);
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
new TimeZoneCapabilitiesAndConfig(capabilities, configuration);
@@ -91,20 +116,34 @@ public class LocationTimeZoneDetectionPreferenceControllerTest {
@Test
public void testLocationTimeZoneDetection_summary_geoDetectionEnabled() {
TimeZoneCapabilities capabilities =
- createTimeZoneCapabilities(/* geoDetectionSupported= */ true);
+ createTimeZoneCapabilities(CAPABILITY_POSSESSED);
TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true);
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
new TimeZoneCapabilitiesAndConfig(capabilities, configuration);
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
- assertThat(mController.getSummary()).isEqualTo(
- mContext.getString(R.string.location_time_zone_detection_on));
+ assertThat(mController.getSummary().toString()).isEmpty();
}
- private static TimeZoneCapabilities createTimeZoneCapabilities(boolean geoDetectionSupported) {
+ @Test
+ public void testLocationTimeZoneDetection_toggleIsOn_whenGeoDetectionEnabledAnsMlsIsOff() {
+ TimeZoneCapabilities capabilities =
+ createTimeZoneCapabilities(CAPABILITY_NOT_APPLICABLE);
+ TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true);
+ TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
+ new TimeZoneCapabilitiesAndConfig(capabilities, configuration);
+
+ when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
+ when(mLocationManager.isLocationEnabled()).thenReturn(false);
+
+ assertThat(mController.isChecked()).isTrue();
+ assertThat(mController.getSummary()).isEqualTo(
+ mContext.getString(R.string.location_app_permission_summary_location_off));
+ }
+
+ private static TimeZoneCapabilities createTimeZoneCapabilities(
+ @TimeZoneCapabilities.CapabilityState int geoDetectionCapability) {
UserHandle arbitraryUserHandle = UserHandle.of(123);
- int geoDetectionCapability =
- geoDetectionSupported ? CAPABILITY_POSSESSED : CAPABILITY_NOT_SUPPORTED;
return new TimeZoneCapabilities.Builder(arbitraryUserHandle)
.setConfigureAutoDetectionEnabledCapability(CAPABILITY_POSSESSED)
.setConfigureGeoDetectionEnabledCapability(geoDetectionCapability)
diff --git a/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettingsTest.java b/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettingsTest.java
deleted file mode 100644
index 9f164924133..00000000000
--- a/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionSettingsTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.datetime.locationtimezone;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Context;
-import android.provider.SearchIndexableResource;
-
-import com.android.settings.R;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-
-import java.util.List;
-
-@RunWith(RobolectricTestRunner.class)
-public class TimeZoneDetectionSettingsTest {
-
- private Context mContext;
-
- @Before
- public void setUp() {
- mContext = RuntimeEnvironment.application;
- }
-
- @Test
- public void searchProvider_shouldIndexDefaultXml() {
- final List sir =
- TimeZoneDetectionSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
- mContext, /* enabled= */ true);
-
- assertThat(sir).hasSize(1);
- assertThat(sir.get(0).xmlResId).isEqualTo(R.xml.location_time_zone_detection);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceControllerTest.java
deleted file mode 100644
index 27a985962a3..00000000000
--- a/tests/robotests/src/com/android/settings/datetime/locationtimezone/TimeZoneDetectionTogglePreferenceControllerTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.datetime.locationtimezone;
-
-import static android.app.time.TimeZoneCapabilities.CAPABILITY_NOT_APPLICABLE;
-import static android.app.time.TimeZoneCapabilities.CAPABILITY_POSSESSED;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.app.time.TimeManager;
-import android.app.time.TimeZoneCapabilities;
-import android.app.time.TimeZoneCapabilitiesAndConfig;
-import android.app.time.TimeZoneConfiguration;
-import android.content.Context;
-import android.os.UserHandle;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-
-@RunWith(RobolectricTestRunner.class)
-public class TimeZoneDetectionTogglePreferenceControllerTest {
-
- private static final String PREF_KEY = "test_key";
-
- @Mock
- private Context mContext;
-
- @Mock
- private TimeManager mTimeManager;
- private TimeZoneDetectionTogglePreferenceController mController;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
-
- mController = new TimeZoneDetectionTogglePreferenceController(mContext, PREF_KEY);
- }
-
- @Test
- public void isAvailable_shouldReturnTrue() {
- assertThat(mController.isAvailable()).isTrue();
- }
-
- @Test
- public void isChecked_whenEnabled_shouldReturnTrue() {
- when(mTimeManager.getTimeZoneCapabilitiesAndConfig())
- .thenReturn(createTimeZoneCapabilitiesAndConfig(true));
-
- assertThat(mController.isChecked()).isTrue();
- }
-
- @Test
- public void isChecked_whenDisabled_shouldReturnFalse() {
- when(mTimeManager.getTimeZoneCapabilitiesAndConfig())
- .thenReturn(createTimeZoneCapabilitiesAndConfig(false));
-
- assertThat(mController.isChecked()).isFalse();
- }
-
- @Test
- public void setChecked_withTrue_shouldUpdateSetting() {
- // Simulate the UI being clicked.
- mController.setChecked(true);
-
- // Verify the TimeManager was updated with the UI value.
- TimeZoneConfiguration expectedConfiguration = new TimeZoneConfiguration.Builder()
- .setGeoDetectionEnabled(true)
- .build();
- verify(mTimeManager).updateTimeZoneConfiguration(expectedConfiguration);
- }
-
- @Test
- public void setChecked_withFalse_shouldUpdateSetting() {
- // Simulate the UI being clicked.
- mController.setChecked(false);
-
- // Verify the TimeManager was updated with the UI value.
- TimeZoneConfiguration expectedConfiguration = new TimeZoneConfiguration.Builder()
- .setGeoDetectionEnabled(false)
- .build();
- verify(mTimeManager).updateTimeZoneConfiguration(expectedConfiguration);
- }
-
- private static TimeZoneCapabilitiesAndConfig createTimeZoneCapabilitiesAndConfig(
- boolean geoDetectionEnabled) {
- UserHandle arbitraryUserHandle = UserHandle.of(123);
- TimeZoneCapabilities capabilities = new TimeZoneCapabilities.Builder(arbitraryUserHandle)
- .setConfigureAutoDetectionEnabledCapability(CAPABILITY_POSSESSED)
- .setConfigureGeoDetectionEnabledCapability(CAPABILITY_POSSESSED)
- .setSuggestManualTimeZoneCapability(CAPABILITY_NOT_APPLICABLE)
- .build();
- TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
- .setAutoDetectionEnabled(true)
- .setGeoDetectionEnabled(geoDetectionEnabled)
- .build();
- return new TimeZoneCapabilitiesAndConfig(capabilities, configuration);
- }
-}