Loading services/core/java/com/android/server/timezonedetector/ConfigurationInternal.java +48 −12 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ public final class ConfigurationInternal { * testing only. See {@link #isGeoDetectionExecutionEnabled()} and {@link #getDetectionMode()} * for details. */ boolean getGeoDetectionRunInBackgroundEnabled() { boolean getGeoDetectionRunInBackgroundEnabledSetting() { return mGeoDetectionRunInBackgroundEnabled; } Loading @@ -132,7 +132,7 @@ public final class ConfigurationInternal { * from the raw setting value. */ public boolean getAutoDetectionEnabledBehavior() { return isAutoDetectionSupported() && mAutoDetectionEnabledSetting; return isAutoDetectionSupported() && getAutoDetectionEnabledSetting(); } /** Returns the ID of the user this configuration is associated with. */ Loading Loading @@ -171,27 +171,55 @@ public final class ConfigurationInternal { * time zone. */ public @DetectionMode int getDetectionMode() { if (!getAutoDetectionEnabledBehavior()) { if (!isAutoDetectionSupported()) { // Handle the easy case first: No auto detection algorithms supported must mean manual. return DETECTION_MODE_MANUAL; } else if (isGeoDetectionSupported() && getLocationEnabledSetting() && getGeoDetectionEnabledSetting()) { } else if (!getAutoDetectionEnabledSetting()) { // Auto detection algorithms are supported, but disabled by the user. return DETECTION_MODE_MANUAL; } else if (getGeoDetectionEnabledBehavior()) { return DETECTION_MODE_GEO; } else { } else if (isTelephonyDetectionSupported()) { return DETECTION_MODE_TELEPHONY; } else { // On devices with telephony detection support, telephony is used instead of geo when // geo cannot be used. This "unknown" case can occur on devices with only the location // detection algorithm supported when the user's master location setting prevents its // use. return DETECTION_MODE_UNKNOWN; } } private boolean getGeoDetectionEnabledBehavior() { // isAutoDetectionSupported() should already have been checked before calling this method. if (isGeoDetectionSupported() && getLocationEnabledSetting()) { if (isTelephonyDetectionSupported()) { // This is the "normal" case for smartphones that have both telephony and geo // detection: the user chooses which type of detection to use. return getGeoDetectionEnabledSetting(); } else { // When only geo detection is supported then there is no choice for the user to // make between detection modes, so no user setting is consulted. return true; } } return false; } /** * Returns true if geolocation time zone detection behavior can execute. Typically, this will * agree with {@link #getDetectionMode()}, but under rare circumstances the geolocation detector * may be run in the background if the user's settings allow. See also {@link * #getGeoDetectionRunInBackgroundEnabled()}. * may be run in the background if the user's settings allow. */ public boolean isGeoDetectionExecutionEnabled() { return getDetectionMode() == DETECTION_MODE_GEO || getGeoDetectionRunInBackgroundEnabledBehavior(); } private boolean getGeoDetectionRunInBackgroundEnabledBehavior() { return isGeoDetectionSupported() && getLocationEnabledSetting() && ((mAutoDetectionEnabledSetting && getGeoDetectionEnabledSetting()) || getGeoDetectionRunInBackgroundEnabled()); && getGeoDetectionRunInBackgroundEnabledSetting(); } @NonNull Loading @@ -216,11 +244,19 @@ public final class ConfigurationInternal { builder.setConfigureAutoDetectionEnabledCapability(configureAutoDetectionEnabledCapability); boolean deviceHasLocationTimeZoneDetection = isGeoDetectionSupported(); boolean deviceHasTelephonyDetection = isTelephonyDetectionSupported(); // Note: allowConfigDateTime does not restrict the ability to change location time zone // detection enabled. This is intentional as it has user privacy implications and so it // makes sense to leave this under a user's control. // makes sense to leave this under a user's control. The only time this is not true is // on devices that only support location-based detection and the main auto detection setting // is used to influence whether location can be used. final @CapabilityState int configureGeolocationDetectionEnabledCapability; if (!deviceHasLocationTimeZoneDetection) { if (!deviceHasLocationTimeZoneDetection || !deviceHasTelephonyDetection) { // If the device doesn't have geolocation detection support OR it ONLY has geolocation // detection support (no telephony) then the user doesn't need the ability to toggle the // location-based detection on and off (the auto detection toggle is considered // sufficient). configureGeolocationDetectionEnabledCapability = CAPABILITY_NOT_SUPPORTED; } else if (!mAutoDetectionEnabledSetting || !getLocationEnabledSetting()) { configureGeolocationDetectionEnabledCapability = CAPABILITY_NOT_APPLICABLE; Loading services/core/java/com/android/server/timezonedetector/MetricsTimeZoneDetectorState.java +1 −1 Original line number Diff line number Diff line Loading @@ -136,7 +136,7 @@ public final class MetricsTimeZoneDetectorState { * testing only. */ public boolean getGeoDetectionRunInBackgroundEnabled() { return mConfigurationInternal.getGeoDetectionRunInBackgroundEnabled(); return mConfigurationInternal.getGeoDetectionRunInBackgroundEnabledSetting(); } /** Returns true if enhanced metric collection is enabled. */ Loading services/core/java/com/android/server/timezonedetector/ServiceConfigAccessorImpl.java +11 −8 Original line number Diff line number Diff line Loading @@ -279,15 +279,18 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor { final boolean autoDetectionEnabled = configuration.isAutoDetectionEnabled(); setAutoDetectionEnabledIfRequired(autoDetectionEnabled); // Avoid writing the geo detection enabled setting for devices with settings that // are currently overridden by server flags: otherwise we might overwrite a droidfood // user's real setting permanently. // Also avoid writing the geo detection enabled setting for devices that do not support // geo time zone detection: if we wrote it down then we'd set the value explicitly, // which would prevent detecting "default" later. That might influence what happens on // later releases that start to support geo detection on the same hardware. // Only write the geo detection enabled setting when its values is used, e.g.: // 1) Devices with a setting value that is not currently overridden by server flags // 2) Devices that support both telephony and location detection algorithms // // If we wrote a setting value down when it's not used then we'd be setting the value // explicitly, which would prevent detecting the setting is in "default" state later. // Not being able to detect if the user has actually expressed a preference could // influence what happens on later releases that start to support geo detection on the // user's same hardware. if (!getGeoDetectionSettingEnabledOverride().isPresent() && isGeoTimeZoneDetectionFeatureSupported()) { && isGeoTimeZoneDetectionFeatureSupported() && isTelephonyTimeZoneDetectionFeatureSupported()) { final boolean geoDetectionEnabledSetting = configuration.isGeoDetectionEnabled(); setGeoDetectionEnabledSettingIfRequired(userId, geoDetectionEnabledSetting); } Loading services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java +12 −5 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import android.util.Slog; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.server.SystemTimeZone.TimeZoneConfidence; import com.android.server.timezonedetector.ConfigurationInternal.DetectionMode; import java.io.PrintWriter; import java.time.Duration; Loading Loading @@ -597,9 +598,10 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat @GuardedBy("this") private void doAutoTimeZoneDetection( @NonNull ConfigurationInternal currentUserConfig, @NonNull String detectionReason) { // Use the correct algorithm based on the user's current configuration. If it changes, then // detection will be re-run. switch (currentUserConfig.getDetectionMode()) { // Use the correct detection algorithm based on the device's config and the user's current // configuration. If user config changes, then detection will be re-run. @DetectionMode int detectionMode = currentUserConfig.getDetectionMode(); switch (detectionMode) { case ConfigurationInternal.DETECTION_MODE_MANUAL: // No work to do. break; Loading Loading @@ -635,9 +637,14 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat case ConfigurationInternal.DETECTION_MODE_TELEPHONY: doTelephonyTimeZoneDetection(detectionReason); break; case ConfigurationInternal.DETECTION_MODE_UNKNOWN: // The "DETECTION_MODE_UNKNOWN" state can occur on devices with only location // detection algorithm support and when the user's master location toggle is off. Slog.i(LOG_TAG, "Unknown detection mode: " + detectionMode + ", is location off?"); break; default: Slog.wtf(LOG_TAG, "Unknown detection mode: " + currentUserConfig.getDetectionMode()); // Coding error Slog.wtf(LOG_TAG, "Unknown detection mode: " + detectionMode); } } Loading services/tests/servicestests/src/com/android/server/timezonedetector/ConfigurationInternalTest.java +239 −44 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
services/core/java/com/android/server/timezonedetector/ConfigurationInternal.java +48 −12 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ public final class ConfigurationInternal { * testing only. See {@link #isGeoDetectionExecutionEnabled()} and {@link #getDetectionMode()} * for details. */ boolean getGeoDetectionRunInBackgroundEnabled() { boolean getGeoDetectionRunInBackgroundEnabledSetting() { return mGeoDetectionRunInBackgroundEnabled; } Loading @@ -132,7 +132,7 @@ public final class ConfigurationInternal { * from the raw setting value. */ public boolean getAutoDetectionEnabledBehavior() { return isAutoDetectionSupported() && mAutoDetectionEnabledSetting; return isAutoDetectionSupported() && getAutoDetectionEnabledSetting(); } /** Returns the ID of the user this configuration is associated with. */ Loading Loading @@ -171,27 +171,55 @@ public final class ConfigurationInternal { * time zone. */ public @DetectionMode int getDetectionMode() { if (!getAutoDetectionEnabledBehavior()) { if (!isAutoDetectionSupported()) { // Handle the easy case first: No auto detection algorithms supported must mean manual. return DETECTION_MODE_MANUAL; } else if (isGeoDetectionSupported() && getLocationEnabledSetting() && getGeoDetectionEnabledSetting()) { } else if (!getAutoDetectionEnabledSetting()) { // Auto detection algorithms are supported, but disabled by the user. return DETECTION_MODE_MANUAL; } else if (getGeoDetectionEnabledBehavior()) { return DETECTION_MODE_GEO; } else { } else if (isTelephonyDetectionSupported()) { return DETECTION_MODE_TELEPHONY; } else { // On devices with telephony detection support, telephony is used instead of geo when // geo cannot be used. This "unknown" case can occur on devices with only the location // detection algorithm supported when the user's master location setting prevents its // use. return DETECTION_MODE_UNKNOWN; } } private boolean getGeoDetectionEnabledBehavior() { // isAutoDetectionSupported() should already have been checked before calling this method. if (isGeoDetectionSupported() && getLocationEnabledSetting()) { if (isTelephonyDetectionSupported()) { // This is the "normal" case for smartphones that have both telephony and geo // detection: the user chooses which type of detection to use. return getGeoDetectionEnabledSetting(); } else { // When only geo detection is supported then there is no choice for the user to // make between detection modes, so no user setting is consulted. return true; } } return false; } /** * Returns true if geolocation time zone detection behavior can execute. Typically, this will * agree with {@link #getDetectionMode()}, but under rare circumstances the geolocation detector * may be run in the background if the user's settings allow. See also {@link * #getGeoDetectionRunInBackgroundEnabled()}. * may be run in the background if the user's settings allow. */ public boolean isGeoDetectionExecutionEnabled() { return getDetectionMode() == DETECTION_MODE_GEO || getGeoDetectionRunInBackgroundEnabledBehavior(); } private boolean getGeoDetectionRunInBackgroundEnabledBehavior() { return isGeoDetectionSupported() && getLocationEnabledSetting() && ((mAutoDetectionEnabledSetting && getGeoDetectionEnabledSetting()) || getGeoDetectionRunInBackgroundEnabled()); && getGeoDetectionRunInBackgroundEnabledSetting(); } @NonNull Loading @@ -216,11 +244,19 @@ public final class ConfigurationInternal { builder.setConfigureAutoDetectionEnabledCapability(configureAutoDetectionEnabledCapability); boolean deviceHasLocationTimeZoneDetection = isGeoDetectionSupported(); boolean deviceHasTelephonyDetection = isTelephonyDetectionSupported(); // Note: allowConfigDateTime does not restrict the ability to change location time zone // detection enabled. This is intentional as it has user privacy implications and so it // makes sense to leave this under a user's control. // makes sense to leave this under a user's control. The only time this is not true is // on devices that only support location-based detection and the main auto detection setting // is used to influence whether location can be used. final @CapabilityState int configureGeolocationDetectionEnabledCapability; if (!deviceHasLocationTimeZoneDetection) { if (!deviceHasLocationTimeZoneDetection || !deviceHasTelephonyDetection) { // If the device doesn't have geolocation detection support OR it ONLY has geolocation // detection support (no telephony) then the user doesn't need the ability to toggle the // location-based detection on and off (the auto detection toggle is considered // sufficient). configureGeolocationDetectionEnabledCapability = CAPABILITY_NOT_SUPPORTED; } else if (!mAutoDetectionEnabledSetting || !getLocationEnabledSetting()) { configureGeolocationDetectionEnabledCapability = CAPABILITY_NOT_APPLICABLE; Loading
services/core/java/com/android/server/timezonedetector/MetricsTimeZoneDetectorState.java +1 −1 Original line number Diff line number Diff line Loading @@ -136,7 +136,7 @@ public final class MetricsTimeZoneDetectorState { * testing only. */ public boolean getGeoDetectionRunInBackgroundEnabled() { return mConfigurationInternal.getGeoDetectionRunInBackgroundEnabled(); return mConfigurationInternal.getGeoDetectionRunInBackgroundEnabledSetting(); } /** Returns true if enhanced metric collection is enabled. */ Loading
services/core/java/com/android/server/timezonedetector/ServiceConfigAccessorImpl.java +11 −8 Original line number Diff line number Diff line Loading @@ -279,15 +279,18 @@ public final class ServiceConfigAccessorImpl implements ServiceConfigAccessor { final boolean autoDetectionEnabled = configuration.isAutoDetectionEnabled(); setAutoDetectionEnabledIfRequired(autoDetectionEnabled); // Avoid writing the geo detection enabled setting for devices with settings that // are currently overridden by server flags: otherwise we might overwrite a droidfood // user's real setting permanently. // Also avoid writing the geo detection enabled setting for devices that do not support // geo time zone detection: if we wrote it down then we'd set the value explicitly, // which would prevent detecting "default" later. That might influence what happens on // later releases that start to support geo detection on the same hardware. // Only write the geo detection enabled setting when its values is used, e.g.: // 1) Devices with a setting value that is not currently overridden by server flags // 2) Devices that support both telephony and location detection algorithms // // If we wrote a setting value down when it's not used then we'd be setting the value // explicitly, which would prevent detecting the setting is in "default" state later. // Not being able to detect if the user has actually expressed a preference could // influence what happens on later releases that start to support geo detection on the // user's same hardware. if (!getGeoDetectionSettingEnabledOverride().isPresent() && isGeoTimeZoneDetectionFeatureSupported()) { && isGeoTimeZoneDetectionFeatureSupported() && isTelephonyTimeZoneDetectionFeatureSupported()) { final boolean geoDetectionEnabledSetting = configuration.isGeoDetectionEnabled(); setGeoDetectionEnabledSettingIfRequired(userId, geoDetectionEnabledSetting); } Loading
services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java +12 −5 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import android.util.Slog; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.server.SystemTimeZone.TimeZoneConfidence; import com.android.server.timezonedetector.ConfigurationInternal.DetectionMode; import java.io.PrintWriter; import java.time.Duration; Loading Loading @@ -597,9 +598,10 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat @GuardedBy("this") private void doAutoTimeZoneDetection( @NonNull ConfigurationInternal currentUserConfig, @NonNull String detectionReason) { // Use the correct algorithm based on the user's current configuration. If it changes, then // detection will be re-run. switch (currentUserConfig.getDetectionMode()) { // Use the correct detection algorithm based on the device's config and the user's current // configuration. If user config changes, then detection will be re-run. @DetectionMode int detectionMode = currentUserConfig.getDetectionMode(); switch (detectionMode) { case ConfigurationInternal.DETECTION_MODE_MANUAL: // No work to do. break; Loading Loading @@ -635,9 +637,14 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat case ConfigurationInternal.DETECTION_MODE_TELEPHONY: doTelephonyTimeZoneDetection(detectionReason); break; case ConfigurationInternal.DETECTION_MODE_UNKNOWN: // The "DETECTION_MODE_UNKNOWN" state can occur on devices with only location // detection algorithm support and when the user's master location toggle is off. Slog.i(LOG_TAG, "Unknown detection mode: " + detectionMode + ", is location off?"); break; default: Slog.wtf(LOG_TAG, "Unknown detection mode: " + currentUserConfig.getDetectionMode()); // Coding error Slog.wtf(LOG_TAG, "Unknown detection mode: " + detectionMode); } } Loading
services/tests/servicestests/src/com/android/server/timezonedetector/ConfigurationInternalTest.java +239 −44 File changed.Preview size limit exceeded, changes collapsed. Show changes