From bded1d2f5d0bfaf6224cbca74590b899e56b61a9 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Fri, 12 Nov 2021 13:47:06 +0000 Subject: [PATCH] A mixed bag of tidy ups / refactoring A mixed bag of tidy ups / refactoring to make the following commits smaller. This change is not intended to have any user-facing functional impact. Summary of changes that aren't obvious comment / code / string tidy-ups: 1) Support for geolocation time zone detection support configuration via the system property "persist.sys.location_time_zone_detection_feature_supported" has been removed. I haven't used this recently and "real" devices get to use server flags to turn the feature off now. Turning the feature on will have to be done in .xml config after this. 2) Remove Dumpable.Container from TimeZoneDetectorInternal and TimeZoneDetectorStrategy as it is not used. 3) Add support for adding Dumpable to TimeZoneDetectorService, because it will be used in a following commit. Removed Dumpable.Container interface as it's not currently pulling its weight, with only one user where nothing refers to the interface. 4) Put all debugging logging under control of a constant in TimeZoneDetectorService. Bug: 197624972 Test: treehugger Test: atest services/tests/servicestests/src/com/android/server/timezonedetector/ Change-Id: I3c3895b3ec7b0ad88fc3776221616a973d54863b --- .../server/timezonedetector/Dumpable.java | 14 ------ .../timezonedetector/EnvironmentImpl.java | 26 ++++------ .../GeolocationTimeZoneSuggestion.java | 11 ++-- .../ServiceConfigAccessor.java | 50 ++++++++----------- .../TimeZoneDetectorInternal.java | 2 +- .../TimeZoneDetectorInternalImpl.java | 5 -- .../TimeZoneDetectorService.java | 38 +++++++++++--- .../TimeZoneDetectorStrategy.java | 11 +++- .../TimeZoneDetectorStrategyImpl.java | 45 +++++++---------- .../LocationTimeZoneManagerService.java | 3 +- .../FakeTimeZoneDetectorStrategy.java | 13 ----- .../TimeZoneDetectorInternalImplTest.java | 10 ---- .../TimeZoneDetectorServiceTest.java | 6 ++- .../TimeZoneDetectorStrategyImplTest.java | 45 ++++++----------- 14 files changed, 115 insertions(+), 164 deletions(-) diff --git a/services/core/java/com/android/server/timezonedetector/Dumpable.java b/services/core/java/com/android/server/timezonedetector/Dumpable.java index 5603c38bd0aee..1dd963795f6d0 100644 --- a/services/core/java/com/android/server/timezonedetector/Dumpable.java +++ b/services/core/java/com/android/server/timezonedetector/Dumpable.java @@ -24,18 +24,4 @@ public interface Dumpable { /** Dump internal state. */ void dump(@NonNull IndentingPrintWriter pw, @Nullable String[] args); - - /** - * An interface that can be used expose when one component allows another to be registered so - * that it is dumped at the same time. - */ - interface Container { - - /** - * Registers the supplied {@link Dumpable}. When the implementation is dumped - * {@link Dumpable#dump(IndentingPrintWriter, String[])} should be called on the - * {@code dumpable}. - */ - void addDumpable(@NonNull Dumpable dumpable); - } } diff --git a/services/core/java/com/android/server/timezonedetector/EnvironmentImpl.java b/services/core/java/com/android/server/timezonedetector/EnvironmentImpl.java index b84f8a850ba76..fc6e372b80414 100644 --- a/services/core/java/com/android/server/timezonedetector/EnvironmentImpl.java +++ b/services/core/java/com/android/server/timezonedetector/EnvironmentImpl.java @@ -72,8 +72,8 @@ final class EnvironmentImpl implements TimeZoneDetectorStrategyImpl.Environment mLocationManager = context.getSystemService(LocationManager.class); mServiceConfigAccessor = Objects.requireNonNull(serviceConfigAccessor); - // Wire up the config change listeners. All invocations are performed on the mHandler - // thread. + // Wire up the config change listeners for anything that could affect the return values from + // this object. All listener invocations are performed on the mHandler thread. // Listen for the user changing / the user's location mode changing. IntentFilter filter = new IntentFilter(); @@ -88,25 +88,19 @@ final class EnvironmentImpl implements TimeZoneDetectorStrategyImpl.Environment // Add async callbacks for global settings being changed. ContentResolver contentResolver = mContext.getContentResolver(); + ContentObserver contentObserver = new ContentObserver(mHandler) { + @Override + public void onChange(boolean selfChange) { + handleConfigChangeOnHandlerThread(); + } + }; contentResolver.registerContentObserver( - Settings.Global.getUriFor(Settings.Global.AUTO_TIME_ZONE), true, - new ContentObserver(mHandler) { - @Override - public void onChange(boolean selfChange) { - handleConfigChangeOnHandlerThread(); - } - }); + Settings.Global.getUriFor(Settings.Global.AUTO_TIME_ZONE), true, contentObserver); // Add async callbacks for user scoped location settings being changed. contentResolver.registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.LOCATION_TIME_ZONE_DETECTION_ENABLED), - true, - new ContentObserver(mHandler) { - @Override - public void onChange(boolean selfChange) { - handleConfigChangeOnHandlerThread(); - } - }, UserHandle.USER_ALL); + true, contentObserver, UserHandle.USER_ALL); } private void handleConfigChangeOnHandlerThread() { diff --git a/services/core/java/com/android/server/timezonedetector/GeolocationTimeZoneSuggestion.java b/services/core/java/com/android/server/timezonedetector/GeolocationTimeZoneSuggestion.java index 3b3254985abca..f4a6ef0bf25c0 100644 --- a/services/core/java/com/android/server/timezonedetector/GeolocationTimeZoneSuggestion.java +++ b/services/core/java/com/android/server/timezonedetector/GeolocationTimeZoneSuggestion.java @@ -39,12 +39,11 @@ import java.util.StringTokenizer; *