From a6daf85a3223cfee73ed543b45471b7b2e59107b Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Tue, 12 Jan 2021 10:30:25 -0800 Subject: [PATCH] Add a flag for controlling location indicator settings. Bug: 177334097 Test: Manual && make RunSettingsRoboTests ROBOTEST_FILTER=LocationIndicatorsPreferenceControllerTest Change-Id: I33821ab8328fd18b796a78813b7354a928832792 --- src/com/android/settings/Utils.java | 6 +++++ ...ocationIndicatorsPreferenceController.java | 5 ++++ ...ionIndicatorsPreferenceControllerTest.java | 24 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java index eca38693998..e44ee78c636 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -147,6 +147,12 @@ public final class Utils extends com.android.settingslib.Utils { */ public static final String PROPERTY_LOCATION_INDICATORS_ENABLED = "location_indicators_enabled"; + /** + * Whether to show location indicator settings in developer options. + */ + public static final String PROPERTY_LOCATION_INDICATOR_SETTINGS_ENABLED = + "location_indicator_settings_enabled"; + /** * Finds a matching activity for a preference's intent. If a matching * activity is not found, it will remove the preference. diff --git a/src/com/android/settings/location/LocationIndicatorsPreferenceController.java b/src/com/android/settings/location/LocationIndicatorsPreferenceController.java index f7b740860c9..d39c280f5a6 100644 --- a/src/com/android/settings/location/LocationIndicatorsPreferenceController.java +++ b/src/com/android/settings/location/LocationIndicatorsPreferenceController.java @@ -45,6 +45,11 @@ public class LocationIndicatorsPreferenceController extends TogglePreferenceCont @Override public int getAvailabilityStatus() { + final boolean isEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY, + Utils.PROPERTY_LOCATION_INDICATOR_SETTINGS_ENABLED, false); + if (!isEnabled) { + return UNSUPPORTED_ON_DEVICE; + } // Location indicators feature is only available on devices that support location. return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; diff --git a/tests/robotests/src/com/android/settings/location/LocationIndicatorsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationIndicatorsPreferenceControllerTest.java index e1182fdba84..912c8537403 100644 --- a/tests/robotests/src/com/android/settings/location/LocationIndicatorsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/location/LocationIndicatorsPreferenceControllerTest.java @@ -75,6 +75,10 @@ public class LocationIndicatorsPreferenceControllerTest { */ @Test public void getAvailabilityStatus_locationSupported_shouldReturnAVAILABLE() { + // Enable the settings flags. + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY, + Utils.PROPERTY_LOCATION_INDICATOR_SETTINGS_ENABLED, Boolean.toString(true), + true); when(mPackageManager.hasSystemFeature(eq(PackageManager.FEATURE_LOCATION))).thenReturn( true); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); @@ -86,11 +90,31 @@ public class LocationIndicatorsPreferenceControllerTest { */ @Test public void getAvailabilityStatus_locationNotSupported_shouldReturnUNSUPPORTED() { + // Enable the settings flags. + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY, + Utils.PROPERTY_LOCATION_INDICATOR_SETTINGS_ENABLED, Boolean.toString(true), + true); when(mPackageManager.hasSystemFeature(eq(PackageManager.FEATURE_LOCATION))).thenReturn( false); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); } + /** + * Verify the location indicator settings are not visible when location indicator settings + * are disabled on the device. + */ + @Test + public void getAvailabilityStatus_flagDisabled_shouldReturnUNSUPPORTED() { + // Disable the settings flags. + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY, + Utils.PROPERTY_LOCATION_INDICATOR_SETTINGS_ENABLED, Boolean.toString(false), + false); + when(mPackageManager.hasSystemFeature(eq(PackageManager.FEATURE_LOCATION))).thenReturn( + true); + + assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); + } + /** * Verify the location indicator preference is checked when the feature is enabled. */