Loading core/java/android/app/timezonedetector/TimeZoneConfiguration.java +2 −2 Original line number Diff line number Diff line Loading @@ -162,9 +162,9 @@ public final class TimeZoneConfiguration implements Parcelable { @Override public String toString() { return "TimeZoneDetectorConfiguration{" return "TimeZoneConfiguration{" + "mUserId=" + mUserId + "mBundle=" + mBundle + ", mBundle=" + mBundle + '}'; } Loading location/java/android/location/timezone/LocationTimeZoneEvent.java +6 −4 Original line number Diff line number Diff line Loading @@ -35,7 +35,8 @@ import java.util.Objects; */ public final class LocationTimeZoneEvent implements Parcelable { @IntDef({ EVENT_TYPE_UNKNOWN, EVENT_TYPE_SUCCESS, EVENT_TYPE_SUCCESS }) @IntDef({ EVENT_TYPE_UNKNOWN, EVENT_TYPE_PERMANENT_FAILURE, EVENT_TYPE_SUCCESS, EVENT_TYPE_UNCERTAIN }) @interface EventType {} /** Uninitialized value for {@link #mEventType} - must not be used for real events. */ Loading @@ -43,7 +44,7 @@ public final class LocationTimeZoneEvent implements Parcelable { /** * Indicates there was a permanent failure. This is not generally expected, and probably means a * required backend service is no longer supported / available. * required backend service has been turned down, or the client is unreasonably old. */ public static final int EVENT_TYPE_PERMANENT_FAILURE = 1; Loading @@ -54,8 +55,9 @@ public final class LocationTimeZoneEvent implements Parcelable { public static final int EVENT_TYPE_SUCCESS = 2; /** * Indicates the time zone is not known because there was a (temporary) error, e.g. when * detecting location, or when resolving the location to a time zone. * Indicates the time zone is not known because of an expected runtime state or error, e.g. when * the provider is unable to detect location, or there was a problem when resolving the location * to a time zone. */ public static final int EVENT_TYPE_UNCERTAIN = 3; Loading services/core/java/com/android/server/timezonedetector/ConfigurationInternal.java +13 −6 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.annotation.NonNull; import android.annotation.UserIdInt; import android.app.timezonedetector.TimeZoneCapabilities; import android.app.timezonedetector.TimeZoneConfiguration; import android.os.UserHandle; import java.util.Objects; Loading Loading @@ -56,6 +57,12 @@ public final class ConfigurationInternal { return mUserId; } /** Returns the handle of the user this configuration is associated with. */ @NonNull public UserHandle getUserHandle() { return UserHandle.of(mUserId); } /** Returns true if the user allowed to modify time zone configuration. */ public boolean isUserConfigAllowed() { return mUserConfigAllowed; Loading Loading @@ -198,13 +205,13 @@ public final class ConfigurationInternal { @Override public String toString() { return "TimeZoneDetectorConfiguration{" return "ConfigurationInternal{" + "mUserId=" + mUserId + "mUserConfigAllowed=" + mUserConfigAllowed + "mAutoDetectionSupported=" + mAutoDetectionSupported + "mAutoDetectionEnabled=" + mAutoDetectionEnabled + "mLocationEnabled=" + mLocationEnabled + "mGeoDetectionEnabled=" + mGeoDetectionEnabled + ", mUserConfigAllowed=" + mUserConfigAllowed + ", mAutoDetectionSupported=" + mAutoDetectionSupported + ", mAutoDetectionEnabled=" + mAutoDetectionEnabled + ", mLocationEnabled=" + mLocationEnabled + ", mGeoDetectionEnabled=" + mGeoDetectionEnabled + '}'; } Loading services/core/java/com/android/server/timezonedetector/TimeZoneDetectorShellCommand.java +1 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ import java.io.PrintWriter; import java.util.function.Consumer; import java.util.function.Supplier; /** Implemented the shell command interface for {@link TimeZoneDetectorService}. */ /** Implements the shell command interface for {@link TimeZoneDetectorService}. */ class TimeZoneDetectorShellCommand extends ShellCommand { private final TimeZoneDetectorService mInterface; Loading services/tests/servicestests/src/com/android/server/timezonedetector/TestState.java 0 → 100644 +92 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.timezonedetector; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.ArrayList; /** * A test support class used for tracking a piece of state in test objects like fakes and mocks. * State can optionally be initialized using {@link #init}, which sets the value to an initial * value, but is not treated as a change. Calls to {@link #set} are tracked and can be checked for * during tests. The change-tracking can be cleared by calling {@link #commitLatest}, which puts the * object into an unchanged state and sets the initial value to the latest value passed to * {@link #set}. */ public class TestState<T> { private T mInitialValue; private final ArrayList<T> mValues = new ArrayList<>(5); /** Sets the initial value for the state. */ public void init(T value) { mValues.clear(); mInitialValue = value; } /** Sets the latest value for the state. */ public void set(T value) { mValues.add(value); } /** Returns {@code true} if {@link #set} has been called. */ public boolean hasBeenSet() { return mValues.size() > 0; } /** Fails if {@link #set} has been called. */ public void assertHasNotBeenSet() { assertFalse(hasBeenSet()); } /** Fails if {@link #set} has not been called. */ public void assertHasBeenSet() { assertTrue(hasBeenSet()); } /** * Clears tracked changes and re-initializes using the latest set value as the initial value. */ public void commitLatest() { if (hasBeenSet()) { mInitialValue = mValues.get(mValues.size() - 1); mValues.clear(); } } /** Asserts the latest value passed to {@link #set} equals {@code expected}. */ public void assertLatestEquals(T expected) { assertEquals(expected, getLatest()); } /** Asserts the number of times {@link #set} has been called. */ public void assertChangeCount(int expectedCount) { assertEquals(expectedCount, mValues.size()); } /** * Returns the latest value passed to {@link #set}. If {@link #set} hasn't been called then the * initial value is returned. */ public T getLatest() { if (hasBeenSet()) { return mValues.get(mValues.size() - 1); } return mInitialValue; } } Loading
core/java/android/app/timezonedetector/TimeZoneConfiguration.java +2 −2 Original line number Diff line number Diff line Loading @@ -162,9 +162,9 @@ public final class TimeZoneConfiguration implements Parcelable { @Override public String toString() { return "TimeZoneDetectorConfiguration{" return "TimeZoneConfiguration{" + "mUserId=" + mUserId + "mBundle=" + mBundle + ", mBundle=" + mBundle + '}'; } Loading
location/java/android/location/timezone/LocationTimeZoneEvent.java +6 −4 Original line number Diff line number Diff line Loading @@ -35,7 +35,8 @@ import java.util.Objects; */ public final class LocationTimeZoneEvent implements Parcelable { @IntDef({ EVENT_TYPE_UNKNOWN, EVENT_TYPE_SUCCESS, EVENT_TYPE_SUCCESS }) @IntDef({ EVENT_TYPE_UNKNOWN, EVENT_TYPE_PERMANENT_FAILURE, EVENT_TYPE_SUCCESS, EVENT_TYPE_UNCERTAIN }) @interface EventType {} /** Uninitialized value for {@link #mEventType} - must not be used for real events. */ Loading @@ -43,7 +44,7 @@ public final class LocationTimeZoneEvent implements Parcelable { /** * Indicates there was a permanent failure. This is not generally expected, and probably means a * required backend service is no longer supported / available. * required backend service has been turned down, or the client is unreasonably old. */ public static final int EVENT_TYPE_PERMANENT_FAILURE = 1; Loading @@ -54,8 +55,9 @@ public final class LocationTimeZoneEvent implements Parcelable { public static final int EVENT_TYPE_SUCCESS = 2; /** * Indicates the time zone is not known because there was a (temporary) error, e.g. when * detecting location, or when resolving the location to a time zone. * Indicates the time zone is not known because of an expected runtime state or error, e.g. when * the provider is unable to detect location, or there was a problem when resolving the location * to a time zone. */ public static final int EVENT_TYPE_UNCERTAIN = 3; Loading
services/core/java/com/android/server/timezonedetector/ConfigurationInternal.java +13 −6 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.annotation.NonNull; import android.annotation.UserIdInt; import android.app.timezonedetector.TimeZoneCapabilities; import android.app.timezonedetector.TimeZoneConfiguration; import android.os.UserHandle; import java.util.Objects; Loading Loading @@ -56,6 +57,12 @@ public final class ConfigurationInternal { return mUserId; } /** Returns the handle of the user this configuration is associated with. */ @NonNull public UserHandle getUserHandle() { return UserHandle.of(mUserId); } /** Returns true if the user allowed to modify time zone configuration. */ public boolean isUserConfigAllowed() { return mUserConfigAllowed; Loading Loading @@ -198,13 +205,13 @@ public final class ConfigurationInternal { @Override public String toString() { return "TimeZoneDetectorConfiguration{" return "ConfigurationInternal{" + "mUserId=" + mUserId + "mUserConfigAllowed=" + mUserConfigAllowed + "mAutoDetectionSupported=" + mAutoDetectionSupported + "mAutoDetectionEnabled=" + mAutoDetectionEnabled + "mLocationEnabled=" + mLocationEnabled + "mGeoDetectionEnabled=" + mGeoDetectionEnabled + ", mUserConfigAllowed=" + mUserConfigAllowed + ", mAutoDetectionSupported=" + mAutoDetectionSupported + ", mAutoDetectionEnabled=" + mAutoDetectionEnabled + ", mLocationEnabled=" + mLocationEnabled + ", mGeoDetectionEnabled=" + mGeoDetectionEnabled + '}'; } Loading
services/core/java/com/android/server/timezonedetector/TimeZoneDetectorShellCommand.java +1 −1 Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ import java.io.PrintWriter; import java.util.function.Consumer; import java.util.function.Supplier; /** Implemented the shell command interface for {@link TimeZoneDetectorService}. */ /** Implements the shell command interface for {@link TimeZoneDetectorService}. */ class TimeZoneDetectorShellCommand extends ShellCommand { private final TimeZoneDetectorService mInterface; Loading
services/tests/servicestests/src/com/android/server/timezonedetector/TestState.java 0 → 100644 +92 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.timezonedetector; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.ArrayList; /** * A test support class used for tracking a piece of state in test objects like fakes and mocks. * State can optionally be initialized using {@link #init}, which sets the value to an initial * value, but is not treated as a change. Calls to {@link #set} are tracked and can be checked for * during tests. The change-tracking can be cleared by calling {@link #commitLatest}, which puts the * object into an unchanged state and sets the initial value to the latest value passed to * {@link #set}. */ public class TestState<T> { private T mInitialValue; private final ArrayList<T> mValues = new ArrayList<>(5); /** Sets the initial value for the state. */ public void init(T value) { mValues.clear(); mInitialValue = value; } /** Sets the latest value for the state. */ public void set(T value) { mValues.add(value); } /** Returns {@code true} if {@link #set} has been called. */ public boolean hasBeenSet() { return mValues.size() > 0; } /** Fails if {@link #set} has been called. */ public void assertHasNotBeenSet() { assertFalse(hasBeenSet()); } /** Fails if {@link #set} has not been called. */ public void assertHasBeenSet() { assertTrue(hasBeenSet()); } /** * Clears tracked changes and re-initializes using the latest set value as the initial value. */ public void commitLatest() { if (hasBeenSet()) { mInitialValue = mValues.get(mValues.size() - 1); mValues.clear(); } } /** Asserts the latest value passed to {@link #set} equals {@code expected}. */ public void assertLatestEquals(T expected) { assertEquals(expected, getLatest()); } /** Asserts the number of times {@link #set} has been called. */ public void assertChangeCount(int expectedCount) { assertEquals(expectedCount, mValues.size()); } /** * Returns the latest value passed to {@link #set}. If {@link #set} hasn't been called then the * initial value is returned. */ public T getLatest() { if (hasBeenSet()) { return mValues.get(mValues.size() - 1); } return mInitialValue; } }