Move the Location time zone detection setting
Move the Location time zone detection setting to Date & Time as per UI review / product request. This initial commit just moves the existing MVP setting behavior to a different screen. Still invisible by default. Enable with: $ adb shell setprop persist.sys.location_time_zone_detection_feature_enabled 1 .. plus a reboot. Bug: 152746236 Test: Manual: build / boot / toggle switch in SettingsUI / inspect output of adb shell dumpsys time_zone_detector Test: m -j30 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.datetime.LocationTimeZoneDetectionPreferenceControllerTest" Test: m -j30 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.datetime.locationtimezone.TimeZoneDetectionTogglePreferenceControllerTest" Test: m -j30 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.datetime.locationtimezone.TimeZoneDetectionSettingsTest" Change-Id: I9ecfa853014a9f92086a9cb2d34e1517474ceb93
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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;
|
||||
|
||||
import static android.app.time.TimeZoneCapabilities.CAPABILITY_NOT_APPLICABLE;
|
||||
import static android.app.time.TimeZoneCapabilities.CAPABILITY_NOT_SUPPORTED;
|
||||
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.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.location.LocationManager;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
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;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LocationTimeZoneDetectionPreferenceControllerTest {
|
||||
@Mock
|
||||
private TimeManager mTimeManager;
|
||||
@Mock
|
||||
private LocationManager mLocationManager;
|
||||
private Context mContext;
|
||||
private LocationTimeZoneDetectionPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(TimeManager.class)).thenReturn(mTimeManager);
|
||||
when(mContext.getSystemService(LocationManager.class)).thenReturn(mLocationManager);
|
||||
mController = new LocationTimeZoneDetectionPreferenceController(mContext, "key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocationTimeZoneDetection_supported_shouldBeShown() {
|
||||
TimeZoneCapabilities capabilities =
|
||||
createTimeZoneCapabilities(/* geoDetectionSupported= */ true);
|
||||
TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true);
|
||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
|
||||
new TimeZoneCapabilitiesAndConfig(capabilities, configuration);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocationTimeZoneDetection_unsupported_shouldNotBeShown() {
|
||||
TimeZoneCapabilities capabilities =
|
||||
createTimeZoneCapabilities(/* geoDetectionSupported= */ false);
|
||||
TimeZoneConfiguration configuration = createTimeZoneConfig(/* geoDetectionEnabled= */ true);
|
||||
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
|
||||
new TimeZoneCapabilitiesAndConfig(capabilities, configuration);
|
||||
when(mTimeManager.getTimeZoneCapabilitiesAndConfig()).thenReturn(capabilitiesAndConfig);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the summary is set in just one of many cases. Exhaustive testing would be brittle.
|
||||
*/
|
||||
@Test
|
||||
public void testLocationTimeZoneDetection_summary_geoDetectionEnabled() {
|
||||
TimeZoneCapabilities capabilities =
|
||||
createTimeZoneCapabilities(/* geoDetectionSupported= */ true);
|
||||
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));
|
||||
}
|
||||
|
||||
private static TimeZoneCapabilities createTimeZoneCapabilities(boolean geoDetectionSupported) {
|
||||
UserHandle arbitraryUserHandle = UserHandle.of(123);
|
||||
int geoDetectionCapability =
|
||||
geoDetectionSupported ? CAPABILITY_POSSESSED : CAPABILITY_NOT_SUPPORTED;
|
||||
return new TimeZoneCapabilities.Builder(arbitraryUserHandle)
|
||||
.setConfigureAutoDetectionEnabledCapability(CAPABILITY_POSSESSED)
|
||||
.setConfigureGeoDetectionEnabledCapability(geoDetectionCapability)
|
||||
.setSuggestManualTimeZoneCapability(CAPABILITY_NOT_APPLICABLE)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static TimeZoneConfiguration createTimeZoneConfig(boolean geoDetectionEnabled) {
|
||||
return new TimeZoneConfiguration.Builder()
|
||||
.setAutoDetectionEnabled(true)
|
||||
.setGeoDetectionEnabled(geoDetectionEnabled)
|
||||
.build();
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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<SearchIndexableResource> 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);
|
||||
}
|
||||
}
|
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user