Move GeoTZ toggle to Date&Time settings screen.
Previous sub-menu is deleted. Toggle is always enabled and shows current configuration setting. If MLS or auto time zone detection is off, the toggle has not effect. Bug: 152746236 Test: toggled and checked dumpsys time_zone_detector Test: checked summary info on different MLS/set time zone automatically states combinations Test: m -j30 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.datetime.LocationTimeZoneDetectionPreferenceControllerTest" Change-Id: I75ee41cfcaaf34b1b63e18809be4cd614446017d Merged-In: I75ee41cfcaaf34b1b63e18809be4cd614446017d
This commit is contained in:
@@ -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.
|
||||
|
Reference in New Issue
Block a user