Add resource config for the GeoTz feature
Add resource config for the Geolocation tz detection feature.
The feature can still be enabled for local dev via a persistent system
property, but the config is intended to be the "proper" way to turn the
feature on.
Bug: 172546738
Test: build / boot
Change-Id: Ia35dde9308274825d0d3c4afe908b6310aa834e4
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 433a46b..8258f89 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -1602,6 +1602,9 @@
config_timeZoneRulesUpdateTrackingEnabled are true.] -->
<integer name="config_timeZoneRulesCheckRetryCount">5</integer>
+ <!-- Whether the geolocation time zone detection feature is enabled. -->
+ <bool name="config_enableGeolocationTimeZoneDetection" translatable="false">false</bool>
+
<!-- Whether to enable primary location time zone provider overlay which allows the primary
location time zone provider to be replaced by an app at run-time. When disabled, only the
config_primaryLocationTimeZoneProviderPackageName package will be searched for the primary
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 6960fb3..5e7a814 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2165,6 +2165,7 @@
<java-symbol type="string" name="config_defaultNetworkScorerPackageName" />
<java-symbol type="string" name="config_persistentDataPackageName" />
<java-symbol type="string" name="config_deviceConfiguratorPackageName" />
+ <java-symbol type="bool" name="config_enableGeolocationTimeZoneDetection" />
<java-symbol type="bool" name="config_enablePrimaryLocationTimeZoneOverlay" />
<java-symbol type="string" name="config_primaryLocationTimeZoneProviderPackageName" />
<java-symbol type="bool" name="config_enableSecondaryLocationTimeZoneOverlay" />
diff --git a/services/core/java/com/android/server/location/timezone/LocationTimeZoneManagerService.java b/services/core/java/com/android/server/location/timezone/LocationTimeZoneManagerService.java
index 74491c5..83f4ca2 100644
--- a/services/core/java/com/android/server/location/timezone/LocationTimeZoneManagerService.java
+++ b/services/core/java/com/android/server/location/timezone/LocationTimeZoneManagerService.java
@@ -79,8 +79,8 @@
@Override
public void onStart() {
- if (TimeZoneDetectorService.GEOLOCATION_TIME_ZONE_DETECTION_ENABLED) {
- Context context = getContext();
+ Context context = getContext();
+ if (TimeZoneDetectorService.isGeoLocationTimeZoneDetectionEnabled(context)) {
mService = new LocationTimeZoneManagerService(context);
// The service currently exposes no LocalService or Binder API, but it extends
@@ -93,7 +93,8 @@
@Override
public void onBootPhase(int phase) {
- if (TimeZoneDetectorService.GEOLOCATION_TIME_ZONE_DETECTION_ENABLED) {
+ Context context = getContext();
+ if (TimeZoneDetectorService.isGeoLocationTimeZoneDetectionEnabled(context)) {
if (phase == PHASE_SYSTEM_SERVICES_READY) {
// The location service must be functioning after this boot phase.
mService.onSystemReady();
diff --git a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java
index 68a086d..033bfa6 100644
--- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java
+++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorService.java
@@ -59,14 +59,25 @@
private static final String TAG = "TimeZoneDetectorService";
/**
- * A "feature switch" for enabling / disabling location-based time zone detection. If this is
- * {@code false}, there should be few / little changes in behavior with previous releases and
- * little overhead associated with geolocation components.
- * TODO(b/151304765) Remove this when the feature is on for all.
+ * A "feature switch" for location-based time zone detection. If this is {@code false}. It is
+ * initialized and never refreshed; it affects what services are started on boot so consistency
+ * is important.
*/
- public static final boolean GEOLOCATION_TIME_ZONE_DETECTION_ENABLED =
- SystemProperties.getBoolean(
- "persist.sys.location_time_zone_detection_feature_enabled", false);
+ @Nullable
+ private static Boolean sGeoLocationTimeZoneDetectionEnabled;
+
+ /** Returns {@code true} if the location-based time zone detection feature is enabled. */
+ public static boolean isGeoLocationTimeZoneDetectionEnabled(Context context) {
+ if (sGeoLocationTimeZoneDetectionEnabled == null) {
+ // The config value is expected to be the main switch. Platform developers can also
+ // enable the feature using a persistent system property.
+ sGeoLocationTimeZoneDetectionEnabled = context.getResources().getBoolean(
+ com.android.internal.R.bool.config_enableGeolocationTimeZoneDetection)
+ || SystemProperties.getBoolean(
+ "persist.sys.location_time_zone_detection_feature_enabled", false);
+ }
+ return sGeoLocationTimeZoneDetectionEnabled;
+ }
/**
* Handles the service lifecycle for {@link TimeZoneDetectorService} and
@@ -84,9 +95,11 @@
Context context = getContext();
Handler handler = FgThread.getHandler();
+ boolean geolocationTimeZoneDetectionEnabled =
+ isGeoLocationTimeZoneDetectionEnabled(context);
TimeZoneDetectorStrategy timeZoneDetectorStrategy =
TimeZoneDetectorStrategyImpl.create(
- context, handler, GEOLOCATION_TIME_ZONE_DETECTION_ENABLED);
+ context, handler, geolocationTimeZoneDetectionEnabled);
// Create and publish the local service for use by internal callers.
TimeZoneDetectorInternal internal =