From 2c6c3c3dafc2bef5599717a9353457d451d6cd7c Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Mon, 2 Mar 2020 10:12:26 +0000 Subject: [PATCH] Disable auto time zone on non-telephony devices Disable auto time zone detection explicitly based on device capabilities. The TimeZoneDetector now enforces that the time zone cannot be set manually when "auto_zone" is 1 (on). On devices without a telephony network (the only devices that support auto time zone currently), nothing explicitly sets the "auto_zone" value to 0 leading to problems when the user tries to manually set the time zone. Therefore, to retain the check, the code needs to ignore the auto_zone setting for devices that inherently cannot support auto time zone detection. Bug: 150583524 Bug: 150156441 Test: treehugger Change-Id: Iea9c9e04c5617ccf0ba20511344884d3d88f2a9b --- .../TimeZoneDetectorCallbackImpl.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorCallbackImpl.java b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorCallbackImpl.java index 2520316b5d543..35194658a48f9 100644 --- a/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorCallbackImpl.java +++ b/services/core/java/com/android/server/timezonedetector/TimeZoneDetectorCallbackImpl.java @@ -20,6 +20,7 @@ import android.annotation.Nullable; import android.app.AlarmManager; import android.content.ContentResolver; import android.content.Context; +import android.net.ConnectivityManager; import android.os.SystemProperties; import android.provider.Settings; @@ -40,7 +41,20 @@ public final class TimeZoneDetectorCallbackImpl implements TimeZoneDetectorStrat @Override public boolean isAutoTimeZoneDetectionEnabled() { - return Settings.Global.getInt(mCr, Settings.Global.AUTO_TIME_ZONE, 1 /* default */) > 0; + if (isAutoTimeZoneDetectionSupported()) { + return Settings.Global.getInt(mCr, Settings.Global.AUTO_TIME_ZONE, 1 /* default */) > 0; + } + return false; + } + + private boolean isAutoTimeZoneDetectionSupported() { + return deviceHasTelephonyNetwork(); + } + + private boolean deviceHasTelephonyNetwork() { + // TODO b/150583524 Avoid the use of a deprecated API. + return mContext.getSystemService(ConnectivityManager.class) + .isNetworkSupported(ConnectivityManager.TYPE_MOBILE); } @Override