Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bded1d2f authored by Neil Fuller's avatar Neil Fuller
Browse files

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
parent 9fef807c
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -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);
    }
}
+10 −16
Original line number Diff line number Diff line
@@ -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();
        contentResolver.registerContentObserver(
                Settings.Global.getUriFor(Settings.Global.AUTO_TIME_ZONE), true,
                new ContentObserver(mHandler) {
        ContentObserver contentObserver = new ContentObserver(mHandler) {
            @Override
            public void onChange(boolean selfChange) {
                handleConfigChangeOnHandlerThread();
            }
                });
        };
        contentResolver.registerContentObserver(
                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() {
+5 −6
Original line number Diff line number Diff line
@@ -39,12 +39,11 @@ import java.util.StringTokenizer;
 * <ul>
 *     <li>{@code effectiveFromElapsedMillis}: The time according to the elapsed realtime clock
 *     after which the suggestion should be considered in effect. For example, when a location fix
 *     used to establish the time zone is old, then the suggestion
 *     {@code effectiveFromElapsedMillis} should reflect this and indicates the time zone that was
 *     detected / correct at that time. The time_zone_detector is only expected to use the latest
 *     suggestion it has received, and so later suggestions always counteract previous suggestions.
 *     The inclusion of this information means that the time_zone_detector can take into account
 *     ordering when comparing suggestions from different sources.
 *     used to establish the time zone is old, then the suggestion's {@code
 *     effectiveFromElapsedMillis} should reflect this and indicates the time zone that was
 *     detected / correct at that time. The inclusion of this information means that the
 *     time_zone_detector <em>may</em> take this into account if comparing suggestions or signals
 *     from different sources.
 *     <br />Note: Because the times can be back-dated, time_zone_detector can be sent a sequence of
 *     suggestions where the {@code effectiveFromElapsedMillis} of later suggestions is before
 *     the {@code effectiveFromElapsedMillis} of an earlier one.</li>
+21 −29
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.annotation.StringDef;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.SystemProperties;
import android.util.ArraySet;

import com.android.internal.R;
@@ -64,11 +63,11 @@ public final class ServiceConfigAccessor {
    public static final @ProviderMode String PROVIDER_MODE_ENABLED = "enabled";

    /**
     * Device config keys that affect the {@link TimeZoneDetectorService} service and {@link
     * com.android.server.timezonedetector.location.LocationTimeZoneManagerService}.
     * Device config keys that can affect {@link
     * com.android.server.timezonedetector.location.LocationTimeZoneManagerService} behavior.
     */
    private static final Set<String> SERVER_FLAGS_KEYS_TO_WATCH = Collections.unmodifiableSet(
            new ArraySet<>(new String[] {
    private static final Set<String> LOCATION_TIME_ZONE_MANAGER_SERVER_FLAGS_KEYS_TO_WATCH =
            Collections.unmodifiableSet(new ArraySet<>(new String[] {
                    ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_FEATURE_SUPPORTED,
                    ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_DEFAULT,
                    ServerFlags.KEY_LOCATION_TIME_ZONE_DETECTION_SETTING_ENABLED_OVERRIDE,
@@ -94,14 +93,6 @@ public final class ServiceConfigAccessor {

    @NonNull private final Context mContext;

    /**
     * An ultimate "feature switch" for location-based time zone detection. If this is
     * {@code false}, the device cannot support the feature without a config change or a reboot:
     * This affects what services are started on boot to minimize expense when the feature is not
     * wanted.
     */
    private final boolean mGeoDetectionFeatureSupportedInConfig;

    @NonNull private final ServerFlags mServerFlags;

    /**
@@ -148,14 +139,6 @@ public final class ServiceConfigAccessor {
    private ServiceConfigAccessor(@NonNull Context context) {
        mContext = Objects.requireNonNull(context);

        // The config value is expected to be the main feature flag. Platform developers can also
        // force enable the feature using a persistent system property. Because system properties
        // can change, this value is cached and only changes on reboot.
        mGeoDetectionFeatureSupportedInConfig = context.getResources().getBoolean(
                com.android.internal.R.bool.config_enableGeolocationTimeZoneDetection)
                || SystemProperties.getBoolean(
                "persist.sys.location_time_zone_detection_feature_supported", false);

        mServerFlags = ServerFlags.getInstance(mContext);
    }

@@ -170,14 +153,15 @@ public final class ServiceConfigAccessor {
    }

    /**
     * Adds a listener that will be called when server flags related to this class change. The
     * callbacks are delivered on the main looper thread.
     * Adds a listener that will be called when server flags related to location_time_zone_manager
     * change. The callbacks are delivered on the main looper thread.
     *
     * <p>Note: Only for use by long-lived objects. There is deliberately no associated remove
     * method.
     */
    public void addListener(@NonNull ConfigurationChangeListener listener) {
        mServerFlags.addListener(listener, SERVER_FLAGS_KEYS_TO_WATCH);
    public void addLocationTimeZoneManagerConfigListener(
            @NonNull ConfigurationChangeListener listener) {
        mServerFlags.addListener(listener, LOCATION_TIME_ZONE_MANAGER_SERVER_FLAGS_KEYS_TO_WATCH);
    }

    /** Returns {@code true} if any form of automatic time zone detection is supported. */
@@ -197,11 +181,19 @@ public final class ServiceConfigAccessor {
    /**
     * Returns {@code true} if the location-based time zone detection feature can be supported on
     * this device at all according to config. When {@code false}, implies that various other
     * location-based settings will be turned off or rendered meaningless. Typically {@link
     * #isGeoTimeZoneDetectionFeatureSupported()} should be used instead.
     * location-based services and settings will be turned off or rendered meaningless.
     *
     * <p>This is the ultimate "feature switch" for location-based time zone detection. If this is
     * {@code false}, the device cannot support the feature without a config change or a reboot:
     * This affects what services are started on boot to minimize expense when the feature is not
     * wanted.
     *
     * Typically {@link #isGeoTimeZoneDetectionFeatureSupported()} should be used except during
     * boot.
     */
    public boolean isGeoTimeZoneDetectionFeatureSupportedInConfig() {
        return mGeoDetectionFeatureSupportedInConfig;
        return mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_enableGeolocationTimeZoneDetection);
    }

    /**
@@ -213,7 +205,7 @@ public final class ServiceConfigAccessor {
        // 1) Be turned on in config.
        // 2) Not be turned off via a server flag.
        // 3) There must be at least one location time zone provider enabled / configured.
        return mGeoDetectionFeatureSupportedInConfig
        return isGeoTimeZoneDetectionFeatureSupportedInConfig()
                && isGeoTimeZoneDetectionFeatureSupportedInternal()
                && atLeastOneProviderIsEnabled();
    }
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import android.annotation.NonNull;
 * <p>The methods on this class can be called from any thread.
 * @hide
 */
public interface TimeZoneDetectorInternal extends Dumpable.Container {
public interface TimeZoneDetectorInternal {

    /** Adds a listener that will be invoked when {@link ConfigurationInternal} may have changed. */
    void addConfigurationListener(@NonNull ConfigurationChangeListener listener);
Loading