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

Commit 726c5061 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Tidy ups in preparation for adding metrics" into sc-dev

parents 1180590c 43d7f9cd
Loading
Loading
Loading
Loading
+19 −18
Original line number Diff line number Diff line
@@ -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;

/**
@@ -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;
@@ -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;

@@ -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. */
@@ -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. */
@@ -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
@@ -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);
    }
@@ -231,7 +232,7 @@ public final class ConfigurationInternal {
        return "ConfigurationInternal{"
                + "mUserId=" + mUserId
                + ", mUserConfigAllowed=" + mUserConfigAllowed
                + ", mAutoDetectionSupported=" + mAutoDetectionSupported
                + ", mTelephonyDetectionSupported=" + mTelephonyDetectionSupported
                + ", mGeoDetectionSupported=" + mGeoDetectionSupported
                + ", mAutoDetectionEnabled=" + mAutoDetectionEnabled
                + ", mLocationEnabled=" + mLocationEnabled
@@ -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;
@@ -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;
@@ -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;
        }

+2 −2
Original line number Diff line number Diff line
@@ -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())
+7 −2
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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));
    }
+27 −0
Original line number Diff line number Diff line
@@ -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<>();

@@ -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
@@ -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;
    }
@@ -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);
@@ -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