Loading services/core/java/com/android/server/timezonedetector/ConfigurationInternal.java +19 −18 Original line number Diff line number Diff line Loading @@ -28,8 +28,6 @@ import android.app.time.TimeZoneCapabilitiesAndConfig; import android.app.time.TimeZoneConfiguration; import android.os.UserHandle; import com.android.internal.util.Preconditions; import java.util.Objects; /** Loading @@ -39,7 +37,7 @@ import java.util.Objects; */ public final class ConfigurationInternal { private final boolean mAutoDetectionSupported; private final boolean mTelephonyDetectionSupported; private final boolean mGeoDetectionSupported; private final boolean mAutoDetectionEnabled; private final @UserIdInt int mUserId; Loading @@ -48,7 +46,7 @@ public final class ConfigurationInternal { private final boolean mGeoDetectionEnabled; private ConfigurationInternal(Builder builder) { mAutoDetectionSupported = builder.mAutoDetectionSupported; mTelephonyDetectionSupported = builder.mTelephonyDetectionSupported; mGeoDetectionSupported = builder.mGeoDetectionSupported; mAutoDetectionEnabled = builder.mAutoDetectionEnabled; Loading @@ -56,14 +54,16 @@ public final class ConfigurationInternal { mUserConfigAllowed = builder.mUserConfigAllowed; mLocationEnabled = builder.mLocationEnabled; mGeoDetectionEnabled = builder.mGeoDetectionEnabled; // if mGeoDetectionSupported then mAutoDetectionSupported, i.e. mGeoDetectionSupported // cannot be true if mAutoDetectionSupported == false Preconditions.checkState(mAutoDetectionSupported || !mGeoDetectionSupported); } /** Returns true if the device supports any form of auto time zone detection. */ public boolean isAutoDetectionSupported() { return mAutoDetectionSupported; return mTelephonyDetectionSupported || mGeoDetectionSupported; } /** Returns true if the device supports telephony time zone detection. */ public boolean isTelephonyDetectionSupported() { return mTelephonyDetectionSupported; } /** Returns true if the device supports geolocation time zone detection. */ Loading @@ -78,9 +78,10 @@ public final class ConfigurationInternal { /** * Returns true if auto time zone detection behavior is actually enabled, which can be distinct * from the raw setting value. */ * from the raw setting value. */ public boolean getAutoDetectionEnabledBehavior() { return mAutoDetectionSupported && mAutoDetectionEnabled; return isAutoDetectionSupported() && mAutoDetectionEnabled; } /** Returns the ID of the user this configuration is associated with. */ Loading Loading @@ -212,7 +213,7 @@ public final class ConfigurationInternal { ConfigurationInternal that = (ConfigurationInternal) o; return mUserId == that.mUserId && mUserConfigAllowed == that.mUserConfigAllowed && mAutoDetectionSupported == that.mAutoDetectionSupported && mTelephonyDetectionSupported == that.mTelephonyDetectionSupported && mGeoDetectionSupported == that.mGeoDetectionSupported && mAutoDetectionEnabled == that.mAutoDetectionEnabled && mLocationEnabled == that.mLocationEnabled Loading @@ -221,7 +222,7 @@ public final class ConfigurationInternal { @Override public int hashCode() { return Objects.hash(mUserId, mUserConfigAllowed, mAutoDetectionSupported, return Objects.hash(mUserId, mUserConfigAllowed, mTelephonyDetectionSupported, mGeoDetectionSupported, mAutoDetectionEnabled, mLocationEnabled, mGeoDetectionEnabled); } Loading @@ -231,7 +232,7 @@ public final class ConfigurationInternal { return "ConfigurationInternal{" + "mUserId=" + mUserId + ", mUserConfigAllowed=" + mUserConfigAllowed + ", mAutoDetectionSupported=" + mAutoDetectionSupported + ", mTelephonyDetectionSupported=" + mTelephonyDetectionSupported + ", mGeoDetectionSupported=" + mGeoDetectionSupported + ", mAutoDetectionEnabled=" + mAutoDetectionEnabled + ", mLocationEnabled=" + mLocationEnabled Loading @@ -247,7 +248,7 @@ public final class ConfigurationInternal { private final @UserIdInt int mUserId; private boolean mUserConfigAllowed; private boolean mAutoDetectionSupported; private boolean mTelephonyDetectionSupported; private boolean mGeoDetectionSupported; private boolean mAutoDetectionEnabled; private boolean mLocationEnabled; Loading @@ -266,7 +267,7 @@ public final class ConfigurationInternal { public Builder(ConfigurationInternal toCopy) { this.mUserId = toCopy.mUserId; this.mUserConfigAllowed = toCopy.mUserConfigAllowed; this.mAutoDetectionSupported = toCopy.mAutoDetectionSupported; this.mTelephonyDetectionSupported = toCopy.mTelephonyDetectionSupported; this.mGeoDetectionSupported = toCopy.mGeoDetectionSupported; this.mAutoDetectionEnabled = toCopy.mAutoDetectionEnabled; this.mLocationEnabled = toCopy.mLocationEnabled; Loading @@ -282,10 +283,10 @@ public final class ConfigurationInternal { } /** * Sets whether any form of automatic time zone detection is supported on this device. * Sets whether telephony time zone detection is supported on this device. */ public Builder setAutoDetectionFeatureSupported(boolean supported) { mAutoDetectionSupported = supported; public Builder setTelephonyDetectionFeatureSupported(boolean supported) { mTelephonyDetectionSupported = supported; return this; } Loading services/core/java/com/android/server/timezonedetector/EnvironmentImpl.java +2 −2 Original line number Diff line number Diff line Loading @@ -128,8 +128,8 @@ public final class EnvironmentImpl implements TimeZoneDetectorStrategyImpl.Envir @Override public ConfigurationInternal getConfigurationInternal(@UserIdInt int userId) { return new ConfigurationInternal.Builder(userId) .setAutoDetectionFeatureSupported( mServiceConfigAccessor.isAutoDetectionFeatureSupported()) .setTelephonyDetectionFeatureSupported( mServiceConfigAccessor.isTelephonyTimeZoneDetectionFeatureSupported()) .setGeoDetectionFeatureSupported( mServiceConfigAccessor.isGeoTimeZoneDetectionFeatureSupported()) .setAutoDetectionEnabled(isAutoDetectionEnabled()) Loading services/core/java/com/android/server/timezonedetector/ServiceConfigAccessor.java +7 −2 Original line number Diff line number Diff line Loading @@ -115,10 +115,15 @@ public final class ServiceConfigAccessor { /** Returns {@code true} if any form of automatic time zone detection is supported. */ public boolean isAutoDetectionFeatureSupported() { return deviceHasTelephonyNetwork() || isGeoTimeZoneDetectionFeatureSupported(); return isTelephonyTimeZoneDetectionFeatureSupported() || isGeoTimeZoneDetectionFeatureSupported(); } private boolean deviceHasTelephonyNetwork() { /** * Returns {@code true} if the telephony-based time zone detection feature is supported on the * device. */ public boolean isTelephonyTimeZoneDetectionFeatureSupported() { // TODO b/150583524 Avoid the use of a deprecated API. return mContext.getSystemService(ConnectivityManager.class) .isNetworkSupported(ConnectivityManager.TYPE_MOBILE); Loading services/core/java/com/android/server/timezonedetector/TimeZoneDetectorInternalImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -86,7 +86,7 @@ public final class TimeZoneDetectorInternalImpl implements TimeZoneDetectorInter @NonNull GeolocationTimeZoneSuggestion timeZoneSuggestion) { Objects.requireNonNull(timeZoneSuggestion); // All strategy calls must take place on the mHandler thread. // This call can take place on the mHandler thread because there is no return value. mHandler.post( () -> mTimeZoneDetectorStrategy.suggestGeolocationTimeZone(timeZoneSuggestion)); } Loading services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java +27 −0 Original line number Diff line number Diff line Loading @@ -195,6 +195,13 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat private ReferenceWithHistory<GeolocationTimeZoneSuggestion> mLatestGeoLocationSuggestion = new ReferenceWithHistory<>(KEEP_SUGGESTION_HISTORY_SIZE); /** * The latest manual suggestion received. */ @GuardedBy("this") private ReferenceWithHistory<ManualTimeZoneSuggestion> mLatestManualSuggestion = new ReferenceWithHistory<>(KEEP_SUGGESTION_HISTORY_SIZE); @GuardedBy("this") private final List<Dumpable> mDumpables = new ArrayList<>(); Loading Loading @@ -286,6 +293,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat if (currentUserConfig.getGeoDetectionEnabledBehavior()) { // Only store a geolocation suggestion if geolocation detection is currently enabled. // See also clearGeolocationSuggestionIfNeeded(). mLatestGeoLocationSuggestion.set(suggestion); // Now perform auto time zone detection. The new suggestion may be used to modify the Loading Loading @@ -324,6 +332,12 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat return false; } // Record the manual suggestion for debugging / metrics (but only if manual detection is // currently enabled). // Note: This is not used to set the device back to a previous manual suggestion if the user // later disables automatic time zone detection. mLatestManualSuggestion.set(suggestion); setDeviceTimeZoneIfRequired(timeZoneId, cause); return true; } Loading Loading @@ -619,6 +633,11 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat mTimeZoneChangesLog.dump(ipw); ipw.decreaseIndent(); // level 2 ipw.println("Manual suggestion history:"); ipw.increaseIndent(); // level 2 mLatestManualSuggestion.dump(ipw); ipw.decreaseIndent(); // level 2 ipw.println("Geolocation suggestion history:"); ipw.increaseIndent(); // level 2 mLatestGeoLocationSuggestion.dump(ipw); Loading @@ -635,6 +654,14 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat } } /** * A method used to inspect strategy state during tests. Not intended for general use. */ @VisibleForTesting public synchronized ManualTimeZoneSuggestion getLatestManualSuggestion() { return mLatestManualSuggestion.get(); } /** * A method used to inspect strategy state during tests. Not intended for general use. */ Loading Loading
services/core/java/com/android/server/timezonedetector/ConfigurationInternal.java +19 −18 Original line number Diff line number Diff line Loading @@ -28,8 +28,6 @@ import android.app.time.TimeZoneCapabilitiesAndConfig; import android.app.time.TimeZoneConfiguration; import android.os.UserHandle; import com.android.internal.util.Preconditions; import java.util.Objects; /** Loading @@ -39,7 +37,7 @@ import java.util.Objects; */ public final class ConfigurationInternal { private final boolean mAutoDetectionSupported; private final boolean mTelephonyDetectionSupported; private final boolean mGeoDetectionSupported; private final boolean mAutoDetectionEnabled; private final @UserIdInt int mUserId; Loading @@ -48,7 +46,7 @@ public final class ConfigurationInternal { private final boolean mGeoDetectionEnabled; private ConfigurationInternal(Builder builder) { mAutoDetectionSupported = builder.mAutoDetectionSupported; mTelephonyDetectionSupported = builder.mTelephonyDetectionSupported; mGeoDetectionSupported = builder.mGeoDetectionSupported; mAutoDetectionEnabled = builder.mAutoDetectionEnabled; Loading @@ -56,14 +54,16 @@ public final class ConfigurationInternal { mUserConfigAllowed = builder.mUserConfigAllowed; mLocationEnabled = builder.mLocationEnabled; mGeoDetectionEnabled = builder.mGeoDetectionEnabled; // if mGeoDetectionSupported then mAutoDetectionSupported, i.e. mGeoDetectionSupported // cannot be true if mAutoDetectionSupported == false Preconditions.checkState(mAutoDetectionSupported || !mGeoDetectionSupported); } /** Returns true if the device supports any form of auto time zone detection. */ public boolean isAutoDetectionSupported() { return mAutoDetectionSupported; return mTelephonyDetectionSupported || mGeoDetectionSupported; } /** Returns true if the device supports telephony time zone detection. */ public boolean isTelephonyDetectionSupported() { return mTelephonyDetectionSupported; } /** Returns true if the device supports geolocation time zone detection. */ Loading @@ -78,9 +78,10 @@ public final class ConfigurationInternal { /** * Returns true if auto time zone detection behavior is actually enabled, which can be distinct * from the raw setting value. */ * from the raw setting value. */ public boolean getAutoDetectionEnabledBehavior() { return mAutoDetectionSupported && mAutoDetectionEnabled; return isAutoDetectionSupported() && mAutoDetectionEnabled; } /** Returns the ID of the user this configuration is associated with. */ Loading Loading @@ -212,7 +213,7 @@ public final class ConfigurationInternal { ConfigurationInternal that = (ConfigurationInternal) o; return mUserId == that.mUserId && mUserConfigAllowed == that.mUserConfigAllowed && mAutoDetectionSupported == that.mAutoDetectionSupported && mTelephonyDetectionSupported == that.mTelephonyDetectionSupported && mGeoDetectionSupported == that.mGeoDetectionSupported && mAutoDetectionEnabled == that.mAutoDetectionEnabled && mLocationEnabled == that.mLocationEnabled Loading @@ -221,7 +222,7 @@ public final class ConfigurationInternal { @Override public int hashCode() { return Objects.hash(mUserId, mUserConfigAllowed, mAutoDetectionSupported, return Objects.hash(mUserId, mUserConfigAllowed, mTelephonyDetectionSupported, mGeoDetectionSupported, mAutoDetectionEnabled, mLocationEnabled, mGeoDetectionEnabled); } Loading @@ -231,7 +232,7 @@ public final class ConfigurationInternal { return "ConfigurationInternal{" + "mUserId=" + mUserId + ", mUserConfigAllowed=" + mUserConfigAllowed + ", mAutoDetectionSupported=" + mAutoDetectionSupported + ", mTelephonyDetectionSupported=" + mTelephonyDetectionSupported + ", mGeoDetectionSupported=" + mGeoDetectionSupported + ", mAutoDetectionEnabled=" + mAutoDetectionEnabled + ", mLocationEnabled=" + mLocationEnabled Loading @@ -247,7 +248,7 @@ public final class ConfigurationInternal { private final @UserIdInt int mUserId; private boolean mUserConfigAllowed; private boolean mAutoDetectionSupported; private boolean mTelephonyDetectionSupported; private boolean mGeoDetectionSupported; private boolean mAutoDetectionEnabled; private boolean mLocationEnabled; Loading @@ -266,7 +267,7 @@ public final class ConfigurationInternal { public Builder(ConfigurationInternal toCopy) { this.mUserId = toCopy.mUserId; this.mUserConfigAllowed = toCopy.mUserConfigAllowed; this.mAutoDetectionSupported = toCopy.mAutoDetectionSupported; this.mTelephonyDetectionSupported = toCopy.mTelephonyDetectionSupported; this.mGeoDetectionSupported = toCopy.mGeoDetectionSupported; this.mAutoDetectionEnabled = toCopy.mAutoDetectionEnabled; this.mLocationEnabled = toCopy.mLocationEnabled; Loading @@ -282,10 +283,10 @@ public final class ConfigurationInternal { } /** * Sets whether any form of automatic time zone detection is supported on this device. * Sets whether telephony time zone detection is supported on this device. */ public Builder setAutoDetectionFeatureSupported(boolean supported) { mAutoDetectionSupported = supported; public Builder setTelephonyDetectionFeatureSupported(boolean supported) { mTelephonyDetectionSupported = supported; return this; } Loading
services/core/java/com/android/server/timezonedetector/EnvironmentImpl.java +2 −2 Original line number Diff line number Diff line Loading @@ -128,8 +128,8 @@ public final class EnvironmentImpl implements TimeZoneDetectorStrategyImpl.Envir @Override public ConfigurationInternal getConfigurationInternal(@UserIdInt int userId) { return new ConfigurationInternal.Builder(userId) .setAutoDetectionFeatureSupported( mServiceConfigAccessor.isAutoDetectionFeatureSupported()) .setTelephonyDetectionFeatureSupported( mServiceConfigAccessor.isTelephonyTimeZoneDetectionFeatureSupported()) .setGeoDetectionFeatureSupported( mServiceConfigAccessor.isGeoTimeZoneDetectionFeatureSupported()) .setAutoDetectionEnabled(isAutoDetectionEnabled()) Loading
services/core/java/com/android/server/timezonedetector/ServiceConfigAccessor.java +7 −2 Original line number Diff line number Diff line Loading @@ -115,10 +115,15 @@ public final class ServiceConfigAccessor { /** Returns {@code true} if any form of automatic time zone detection is supported. */ public boolean isAutoDetectionFeatureSupported() { return deviceHasTelephonyNetwork() || isGeoTimeZoneDetectionFeatureSupported(); return isTelephonyTimeZoneDetectionFeatureSupported() || isGeoTimeZoneDetectionFeatureSupported(); } private boolean deviceHasTelephonyNetwork() { /** * Returns {@code true} if the telephony-based time zone detection feature is supported on the * device. */ public boolean isTelephonyTimeZoneDetectionFeatureSupported() { // TODO b/150583524 Avoid the use of a deprecated API. return mContext.getSystemService(ConnectivityManager.class) .isNetworkSupported(ConnectivityManager.TYPE_MOBILE); Loading
services/core/java/com/android/server/timezonedetector/TimeZoneDetectorInternalImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -86,7 +86,7 @@ public final class TimeZoneDetectorInternalImpl implements TimeZoneDetectorInter @NonNull GeolocationTimeZoneSuggestion timeZoneSuggestion) { Objects.requireNonNull(timeZoneSuggestion); // All strategy calls must take place on the mHandler thread. // This call can take place on the mHandler thread because there is no return value. mHandler.post( () -> mTimeZoneDetectorStrategy.suggestGeolocationTimeZone(timeZoneSuggestion)); } Loading
services/core/java/com/android/server/timezonedetector/TimeZoneDetectorStrategyImpl.java +27 −0 Original line number Diff line number Diff line Loading @@ -195,6 +195,13 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat private ReferenceWithHistory<GeolocationTimeZoneSuggestion> mLatestGeoLocationSuggestion = new ReferenceWithHistory<>(KEEP_SUGGESTION_HISTORY_SIZE); /** * The latest manual suggestion received. */ @GuardedBy("this") private ReferenceWithHistory<ManualTimeZoneSuggestion> mLatestManualSuggestion = new ReferenceWithHistory<>(KEEP_SUGGESTION_HISTORY_SIZE); @GuardedBy("this") private final List<Dumpable> mDumpables = new ArrayList<>(); Loading Loading @@ -286,6 +293,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat if (currentUserConfig.getGeoDetectionEnabledBehavior()) { // Only store a geolocation suggestion if geolocation detection is currently enabled. // See also clearGeolocationSuggestionIfNeeded(). mLatestGeoLocationSuggestion.set(suggestion); // Now perform auto time zone detection. The new suggestion may be used to modify the Loading Loading @@ -324,6 +332,12 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat return false; } // Record the manual suggestion for debugging / metrics (but only if manual detection is // currently enabled). // Note: This is not used to set the device back to a previous manual suggestion if the user // later disables automatic time zone detection. mLatestManualSuggestion.set(suggestion); setDeviceTimeZoneIfRequired(timeZoneId, cause); return true; } Loading Loading @@ -619,6 +633,11 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat mTimeZoneChangesLog.dump(ipw); ipw.decreaseIndent(); // level 2 ipw.println("Manual suggestion history:"); ipw.increaseIndent(); // level 2 mLatestManualSuggestion.dump(ipw); ipw.decreaseIndent(); // level 2 ipw.println("Geolocation suggestion history:"); ipw.increaseIndent(); // level 2 mLatestGeoLocationSuggestion.dump(ipw); Loading @@ -635,6 +654,14 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat } } /** * A method used to inspect strategy state during tests. Not intended for general use. */ @VisibleForTesting public synchronized ManualTimeZoneSuggestion getLatestManualSuggestion() { return mLatestManualSuggestion.get(); } /** * A method used to inspect strategy state during tests. Not intended for general use. */ Loading