diff options
| author | 2020-11-15 13:48:22 +0000 | |
|---|---|---|
| committer | 2020-11-15 13:48:22 +0000 | |
| commit | 162922a2556b41878c625a6f33f6efdbbf43e9f3 (patch) | |
| tree | 9d5b8eeda386a86d6b3da80b4fafefdaed54410a | |
| parent | 1ca56e86a8ed56f3d0770cddfb38498b90e28081 (diff) | |
| parent | 4c05249d8bc4e70ed81625785340673a0dcff11e (diff) | |
Merge "Add resource config for the GeoTz feature"
4 files changed, 29 insertions, 11 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 3295df1122d0..c83594a7625f 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 fba431c66f53..acfafa4d8409 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 74491c5739f3..83f4ca2839fb 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 @@ public class LocationTimeZoneManagerService extends Binder { @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 @@ public class LocationTimeZoneManagerService extends Binder { @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 68a086da5037..033bfa648f2f 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 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub 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 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub 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 = |