Merge "Add resource config for the GeoTz feature"

This commit is contained in:
Neil Fuller
2020-11-15 13:48:22 +00:00
committed by Android (Google) Code Review
4 changed files with 29 additions and 11 deletions

View File

@@ -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

View File

@@ -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" />

View File

@@ -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();

View File

@@ -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 =