Loading location/java/com/android/internal/location/timezone/LocationTimeZoneEvent.java +20 −18 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.os.Parcelable; import com.android.internal.util.Preconditions; import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.List; Loading Loading @@ -70,30 +71,30 @@ public final class LocationTimeZoneEvent implements Parcelable { @NonNull private final List<String> mTimeZoneIds; private final long mElapsedRealtimeNanos; private final long mElapsedRealtimeMillis; private LocationTimeZoneEvent(@EventType int eventType, @NonNull List<String> timeZoneIds, long elapsedRealtimeNanos) { long elapsedRealtimeMillis) { mEventType = checkValidEventType(eventType); mTimeZoneIds = immutableList(timeZoneIds); boolean emptyTimeZoneIdListExpected = eventType != EVENT_TYPE_SUCCESS; Preconditions.checkState(!emptyTimeZoneIdListExpected || timeZoneIds.isEmpty()); mElapsedRealtimeNanos = elapsedRealtimeNanos; mElapsedRealtimeMillis = elapsedRealtimeMillis; } /** * Returns the time of this fix, in elapsed real-time since system boot. * * <p>This value can be reliably compared to {@link * android.os.SystemClock#elapsedRealtimeNanos}, to calculate the age of a fix and to compare * android.os.SystemClock#elapsedRealtime()}, to calculate the age of a fix and to compare * {@link LocationTimeZoneEvent} instances. * * @return elapsed real-time of fix, in nanoseconds since system boot. * @return elapsed real-time of fix, in milliseconds */ public long getElapsedRealtimeNanos() { return mElapsedRealtimeNanos; public long getElapsedRealtimeMillis() { return mElapsedRealtimeMillis; } /** Loading @@ -118,7 +119,8 @@ public final class LocationTimeZoneEvent implements Parcelable { return "LocationTimeZoneEvent{" + "mEventType=" + mEventType + ", mTimeZoneIds=" + mTimeZoneIds + ", mElapsedRealtimeNanos=" + mElapsedRealtimeNanos + ", mElapsedRealtimeMillis=" + mElapsedRealtimeMillis + "(" + Duration.ofMillis(mElapsedRealtimeMillis) + ")" + '}'; } Loading @@ -130,8 +132,8 @@ public final class LocationTimeZoneEvent implements Parcelable { @SuppressWarnings("unchecked") ArrayList<String> timeZoneIds = (ArrayList<String>) in.readArrayList(null /* classLoader */); long elapsedRealtimeNanos = in.readLong(); return new LocationTimeZoneEvent(eventType, timeZoneIds, elapsedRealtimeNanos); long elapsedRealtimeMillis = in.readLong(); return new LocationTimeZoneEvent(eventType, timeZoneIds, elapsedRealtimeMillis); } @Override Loading @@ -149,7 +151,7 @@ public final class LocationTimeZoneEvent implements Parcelable { public void writeToParcel(Parcel parcel, int flags) { parcel.writeInt(mEventType); parcel.writeList(mTimeZoneIds); parcel.writeLong(mElapsedRealtimeNanos); parcel.writeLong(mElapsedRealtimeMillis); } @Override Loading @@ -162,13 +164,13 @@ public final class LocationTimeZoneEvent implements Parcelable { } LocationTimeZoneEvent that = (LocationTimeZoneEvent) o; return mEventType == that.mEventType && mElapsedRealtimeNanos == that.mElapsedRealtimeNanos && mElapsedRealtimeMillis == that.mElapsedRealtimeMillis && mTimeZoneIds.equals(that.mTimeZoneIds); } @Override public int hashCode() { return Objects.hash(mEventType, mTimeZoneIds, mElapsedRealtimeNanos); return Objects.hash(mEventType, mTimeZoneIds, mElapsedRealtimeMillis); } /** @hide */ Loading @@ -176,7 +178,7 @@ public final class LocationTimeZoneEvent implements Parcelable { private @EventType int mEventType = EVENT_TYPE_UNKNOWN; private @NonNull List<String> mTimeZoneIds = Collections.emptyList(); private long mElapsedRealtimeNanos; private long mElapsedRealtimeMillis; public Builder() { } Loading @@ -187,7 +189,7 @@ public final class LocationTimeZoneEvent implements Parcelable { public Builder(@NonNull LocationTimeZoneEvent ltz) { mEventType = ltz.mEventType; mTimeZoneIds = ltz.mTimeZoneIds; mElapsedRealtimeNanos = ltz.mElapsedRealtimeNanos; mElapsedRealtimeMillis = ltz.mElapsedRealtimeMillis; } /** Loading @@ -210,8 +212,8 @@ public final class LocationTimeZoneEvent implements Parcelable { /** * Sets the time of this event, in elapsed real-time since system boot. */ public Builder setElapsedRealtimeNanos(long time) { mElapsedRealtimeNanos = time; public Builder setElapsedRealtimeMillis(long time) { mElapsedRealtimeMillis = time; return this; } Loading @@ -219,7 +221,7 @@ public final class LocationTimeZoneEvent implements Parcelable { * Builds a {@link LocationTimeZoneEvent} instance. */ public LocationTimeZoneEvent build() { return new LocationTimeZoneEvent(mEventType, mTimeZoneIds, mElapsedRealtimeNanos); return new LocationTimeZoneEvent(mEventType, mTimeZoneIds, mElapsedRealtimeMillis); } } Loading location/lib/java/com/android/location/timezone/provider/LocationTimeZoneEventUnbundled.java +1 −1 Original line number Diff line number Diff line Loading @@ -147,7 +147,7 @@ public final class LocationTimeZoneEventUnbundled { LocationTimeZoneEvent event = new LocationTimeZoneEvent.Builder() .setEventType(internalEventType) .setTimeZoneIds(mTimeZoneIds) .setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()) .setElapsedRealtimeMillis(SystemClock.elapsedRealtime()) .build(); return new LocationTimeZoneEventUnbundled(event); } Loading services/core/java/com/android/server/location/timezone/SimulatedBinderProviderEvent.java +1 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ final class SimulatedBinderProviderEvent { private static LocationTimeZoneEvent parseLocationTimeZoneEventArgs(ShellCommand shellCommand) { LocationTimeZoneEvent.Builder eventBuilder = new LocationTimeZoneEvent.Builder() .setElapsedRealtimeNanos(SystemClock.elapsedRealtime()); .setElapsedRealtimeMillis(SystemClock.elapsedRealtime()); String eventTypeString = shellCommand.getNextArgRequired(); switch (eventTypeString.toUpperCase()) { Loading services/tests/servicestests/src/com/android/internal/location/timezone/LocationTimeZoneEventTest.java +8 −8 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ import java.util.List; public class LocationTimeZoneEventTest { private static final long ARBITRARY_ELAPSED_REALTIME_NANOS = 9999; private static final long ARBITRARY_ELAPSED_REALTIME_MILLIS = 9999; private static final List<String> ARBITRARY_TIME_ZONE_IDS = singletonList("Europe/London"); Loading @@ -42,7 +42,7 @@ public class LocationTimeZoneEventTest { public void testBuildUnsetEventType() { new LocationTimeZoneEvent.Builder() .setTimeZoneIds(ARBITRARY_TIME_ZONE_IDS) .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS) .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS) .build(); } Loading @@ -51,7 +51,7 @@ public class LocationTimeZoneEventTest { new LocationTimeZoneEvent.Builder() .setEventType(LocationTimeZoneEvent.EVENT_TYPE_UNCERTAIN) .setTimeZoneIds(ARBITRARY_TIME_ZONE_IDS) .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS) .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS) .build(); } Loading @@ -59,7 +59,7 @@ public class LocationTimeZoneEventTest { public void testEquals() { LocationTimeZoneEvent.Builder builder1 = new LocationTimeZoneEvent.Builder() .setEventType(LocationTimeZoneEvent.EVENT_TYPE_UNCERTAIN) .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS); .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS); { LocationTimeZoneEvent one = builder1.build(); assertEquals(one, one); Loading @@ -67,7 +67,7 @@ public class LocationTimeZoneEventTest { LocationTimeZoneEvent.Builder builder2 = new LocationTimeZoneEvent.Builder() .setEventType(LocationTimeZoneEvent.EVENT_TYPE_UNCERTAIN) .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS); .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS); { LocationTimeZoneEvent one = builder1.build(); LocationTimeZoneEvent two = builder2.build(); Loading @@ -75,7 +75,7 @@ public class LocationTimeZoneEventTest { assertEquals(two, one); } builder1.setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS + 1); builder1.setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS + 1); { LocationTimeZoneEvent one = builder1.build(); LocationTimeZoneEvent two = builder2.build(); Loading @@ -83,7 +83,7 @@ public class LocationTimeZoneEventTest { assertNotEquals(two, one); } builder2.setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS + 1); builder2.setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS + 1); { LocationTimeZoneEvent one = builder1.build(); LocationTimeZoneEvent two = builder2.build(); Loading Loading @@ -128,7 +128,7 @@ public class LocationTimeZoneEventTest { public void testParcelable() { LocationTimeZoneEvent.Builder builder = new LocationTimeZoneEvent.Builder() .setEventType(LocationTimeZoneEvent.EVENT_TYPE_PERMANENT_FAILURE) .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS); .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS); assertRoundTripParcelable(builder.build()); builder.setEventType(LocationTimeZoneEvent.EVENT_TYPE_SUCCESS) Loading services/tests/servicestests/src/com/android/server/location/timezone/ControllerImplTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ import java.util.Objects; @Presubmit public class ControllerImplTest { private static final long ARBITRARY_TIME = 12345L; private static final long ARBITRARY_TIME_MILLIS = 12345L; private static final LocationTimeZoneEvent USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1 = createLocationTimeZoneEvent(EVENT_TYPE_SUCCESS, asList("Europe/London")); Loading Loading @@ -935,7 +935,7 @@ public class ControllerImplTest { private static LocationTimeZoneEvent createLocationTimeZoneEvent( int eventType, @Nullable List<String> timeZoneIds) { LocationTimeZoneEvent.Builder builder = new LocationTimeZoneEvent.Builder() .setElapsedRealtimeNanos(ARBITRARY_TIME) .setElapsedRealtimeMillis(ARBITRARY_TIME_MILLIS) .setEventType(eventType); if (timeZoneIds != null) { builder.setTimeZoneIds(timeZoneIds); Loading Loading
location/java/com/android/internal/location/timezone/LocationTimeZoneEvent.java +20 −18 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.os.Parcelable; import com.android.internal.util.Preconditions; import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.List; Loading Loading @@ -70,30 +71,30 @@ public final class LocationTimeZoneEvent implements Parcelable { @NonNull private final List<String> mTimeZoneIds; private final long mElapsedRealtimeNanos; private final long mElapsedRealtimeMillis; private LocationTimeZoneEvent(@EventType int eventType, @NonNull List<String> timeZoneIds, long elapsedRealtimeNanos) { long elapsedRealtimeMillis) { mEventType = checkValidEventType(eventType); mTimeZoneIds = immutableList(timeZoneIds); boolean emptyTimeZoneIdListExpected = eventType != EVENT_TYPE_SUCCESS; Preconditions.checkState(!emptyTimeZoneIdListExpected || timeZoneIds.isEmpty()); mElapsedRealtimeNanos = elapsedRealtimeNanos; mElapsedRealtimeMillis = elapsedRealtimeMillis; } /** * Returns the time of this fix, in elapsed real-time since system boot. * * <p>This value can be reliably compared to {@link * android.os.SystemClock#elapsedRealtimeNanos}, to calculate the age of a fix and to compare * android.os.SystemClock#elapsedRealtime()}, to calculate the age of a fix and to compare * {@link LocationTimeZoneEvent} instances. * * @return elapsed real-time of fix, in nanoseconds since system boot. * @return elapsed real-time of fix, in milliseconds */ public long getElapsedRealtimeNanos() { return mElapsedRealtimeNanos; public long getElapsedRealtimeMillis() { return mElapsedRealtimeMillis; } /** Loading @@ -118,7 +119,8 @@ public final class LocationTimeZoneEvent implements Parcelable { return "LocationTimeZoneEvent{" + "mEventType=" + mEventType + ", mTimeZoneIds=" + mTimeZoneIds + ", mElapsedRealtimeNanos=" + mElapsedRealtimeNanos + ", mElapsedRealtimeMillis=" + mElapsedRealtimeMillis + "(" + Duration.ofMillis(mElapsedRealtimeMillis) + ")" + '}'; } Loading @@ -130,8 +132,8 @@ public final class LocationTimeZoneEvent implements Parcelable { @SuppressWarnings("unchecked") ArrayList<String> timeZoneIds = (ArrayList<String>) in.readArrayList(null /* classLoader */); long elapsedRealtimeNanos = in.readLong(); return new LocationTimeZoneEvent(eventType, timeZoneIds, elapsedRealtimeNanos); long elapsedRealtimeMillis = in.readLong(); return new LocationTimeZoneEvent(eventType, timeZoneIds, elapsedRealtimeMillis); } @Override Loading @@ -149,7 +151,7 @@ public final class LocationTimeZoneEvent implements Parcelable { public void writeToParcel(Parcel parcel, int flags) { parcel.writeInt(mEventType); parcel.writeList(mTimeZoneIds); parcel.writeLong(mElapsedRealtimeNanos); parcel.writeLong(mElapsedRealtimeMillis); } @Override Loading @@ -162,13 +164,13 @@ public final class LocationTimeZoneEvent implements Parcelable { } LocationTimeZoneEvent that = (LocationTimeZoneEvent) o; return mEventType == that.mEventType && mElapsedRealtimeNanos == that.mElapsedRealtimeNanos && mElapsedRealtimeMillis == that.mElapsedRealtimeMillis && mTimeZoneIds.equals(that.mTimeZoneIds); } @Override public int hashCode() { return Objects.hash(mEventType, mTimeZoneIds, mElapsedRealtimeNanos); return Objects.hash(mEventType, mTimeZoneIds, mElapsedRealtimeMillis); } /** @hide */ Loading @@ -176,7 +178,7 @@ public final class LocationTimeZoneEvent implements Parcelable { private @EventType int mEventType = EVENT_TYPE_UNKNOWN; private @NonNull List<String> mTimeZoneIds = Collections.emptyList(); private long mElapsedRealtimeNanos; private long mElapsedRealtimeMillis; public Builder() { } Loading @@ -187,7 +189,7 @@ public final class LocationTimeZoneEvent implements Parcelable { public Builder(@NonNull LocationTimeZoneEvent ltz) { mEventType = ltz.mEventType; mTimeZoneIds = ltz.mTimeZoneIds; mElapsedRealtimeNanos = ltz.mElapsedRealtimeNanos; mElapsedRealtimeMillis = ltz.mElapsedRealtimeMillis; } /** Loading @@ -210,8 +212,8 @@ public final class LocationTimeZoneEvent implements Parcelable { /** * Sets the time of this event, in elapsed real-time since system boot. */ public Builder setElapsedRealtimeNanos(long time) { mElapsedRealtimeNanos = time; public Builder setElapsedRealtimeMillis(long time) { mElapsedRealtimeMillis = time; return this; } Loading @@ -219,7 +221,7 @@ public final class LocationTimeZoneEvent implements Parcelable { * Builds a {@link LocationTimeZoneEvent} instance. */ public LocationTimeZoneEvent build() { return new LocationTimeZoneEvent(mEventType, mTimeZoneIds, mElapsedRealtimeNanos); return new LocationTimeZoneEvent(mEventType, mTimeZoneIds, mElapsedRealtimeMillis); } } Loading
location/lib/java/com/android/location/timezone/provider/LocationTimeZoneEventUnbundled.java +1 −1 Original line number Diff line number Diff line Loading @@ -147,7 +147,7 @@ public final class LocationTimeZoneEventUnbundled { LocationTimeZoneEvent event = new LocationTimeZoneEvent.Builder() .setEventType(internalEventType) .setTimeZoneIds(mTimeZoneIds) .setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()) .setElapsedRealtimeMillis(SystemClock.elapsedRealtime()) .build(); return new LocationTimeZoneEventUnbundled(event); } Loading
services/core/java/com/android/server/location/timezone/SimulatedBinderProviderEvent.java +1 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,7 @@ final class SimulatedBinderProviderEvent { private static LocationTimeZoneEvent parseLocationTimeZoneEventArgs(ShellCommand shellCommand) { LocationTimeZoneEvent.Builder eventBuilder = new LocationTimeZoneEvent.Builder() .setElapsedRealtimeNanos(SystemClock.elapsedRealtime()); .setElapsedRealtimeMillis(SystemClock.elapsedRealtime()); String eventTypeString = shellCommand.getNextArgRequired(); switch (eventTypeString.toUpperCase()) { Loading
services/tests/servicestests/src/com/android/internal/location/timezone/LocationTimeZoneEventTest.java +8 −8 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ import java.util.List; public class LocationTimeZoneEventTest { private static final long ARBITRARY_ELAPSED_REALTIME_NANOS = 9999; private static final long ARBITRARY_ELAPSED_REALTIME_MILLIS = 9999; private static final List<String> ARBITRARY_TIME_ZONE_IDS = singletonList("Europe/London"); Loading @@ -42,7 +42,7 @@ public class LocationTimeZoneEventTest { public void testBuildUnsetEventType() { new LocationTimeZoneEvent.Builder() .setTimeZoneIds(ARBITRARY_TIME_ZONE_IDS) .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS) .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS) .build(); } Loading @@ -51,7 +51,7 @@ public class LocationTimeZoneEventTest { new LocationTimeZoneEvent.Builder() .setEventType(LocationTimeZoneEvent.EVENT_TYPE_UNCERTAIN) .setTimeZoneIds(ARBITRARY_TIME_ZONE_IDS) .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS) .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS) .build(); } Loading @@ -59,7 +59,7 @@ public class LocationTimeZoneEventTest { public void testEquals() { LocationTimeZoneEvent.Builder builder1 = new LocationTimeZoneEvent.Builder() .setEventType(LocationTimeZoneEvent.EVENT_TYPE_UNCERTAIN) .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS); .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS); { LocationTimeZoneEvent one = builder1.build(); assertEquals(one, one); Loading @@ -67,7 +67,7 @@ public class LocationTimeZoneEventTest { LocationTimeZoneEvent.Builder builder2 = new LocationTimeZoneEvent.Builder() .setEventType(LocationTimeZoneEvent.EVENT_TYPE_UNCERTAIN) .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS); .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS); { LocationTimeZoneEvent one = builder1.build(); LocationTimeZoneEvent two = builder2.build(); Loading @@ -75,7 +75,7 @@ public class LocationTimeZoneEventTest { assertEquals(two, one); } builder1.setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS + 1); builder1.setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS + 1); { LocationTimeZoneEvent one = builder1.build(); LocationTimeZoneEvent two = builder2.build(); Loading @@ -83,7 +83,7 @@ public class LocationTimeZoneEventTest { assertNotEquals(two, one); } builder2.setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS + 1); builder2.setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS + 1); { LocationTimeZoneEvent one = builder1.build(); LocationTimeZoneEvent two = builder2.build(); Loading Loading @@ -128,7 +128,7 @@ public class LocationTimeZoneEventTest { public void testParcelable() { LocationTimeZoneEvent.Builder builder = new LocationTimeZoneEvent.Builder() .setEventType(LocationTimeZoneEvent.EVENT_TYPE_PERMANENT_FAILURE) .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS); .setElapsedRealtimeMillis(ARBITRARY_ELAPSED_REALTIME_MILLIS); assertRoundTripParcelable(builder.build()); builder.setEventType(LocationTimeZoneEvent.EVENT_TYPE_SUCCESS) Loading
services/tests/servicestests/src/com/android/server/location/timezone/ControllerImplTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ import java.util.Objects; @Presubmit public class ControllerImplTest { private static final long ARBITRARY_TIME = 12345L; private static final long ARBITRARY_TIME_MILLIS = 12345L; private static final LocationTimeZoneEvent USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1 = createLocationTimeZoneEvent(EVENT_TYPE_SUCCESS, asList("Europe/London")); Loading Loading @@ -935,7 +935,7 @@ public class ControllerImplTest { private static LocationTimeZoneEvent createLocationTimeZoneEvent( int eventType, @Nullable List<String> timeZoneIds) { LocationTimeZoneEvent.Builder builder = new LocationTimeZoneEvent.Builder() .setElapsedRealtimeNanos(ARBITRARY_TIME) .setElapsedRealtimeMillis(ARBITRARY_TIME_MILLIS) .setEventType(eventType); if (timeZoneIds != null) { builder.setTimeZoneIds(timeZoneIds); Loading