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

Commit ca04b8dd authored by Neil Fuller's avatar Neil Fuller Committed by Android (Google) Code Review
Browse files

Merge "Remove use of UserHandle in LocationTimeZoneEvent"

parents cfa70cde 95600ac2
Loading
Loading
Loading
Loading
+7 −36
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.UserHandle;

import com.android.internal.util.Preconditions;

@@ -65,9 +64,6 @@ public final class LocationTimeZoneEvent implements Parcelable {

    private static final int EVENT_TYPE_MAX = EVENT_TYPE_UNCERTAIN;

    @NonNull
    private final UserHandle mUserHandle;

    @EventType
    private final int mEventType;

@@ -76,9 +72,8 @@ public final class LocationTimeZoneEvent implements Parcelable {

    private final long mElapsedRealtimeNanos;

    private LocationTimeZoneEvent(@NonNull UserHandle userHandle, @EventType int eventType,
            @NonNull List<String> timeZoneIds, long elapsedRealtimeNanos) {
        mUserHandle = Objects.requireNonNull(userHandle);
    private LocationTimeZoneEvent(@EventType int eventType, @NonNull List<String> timeZoneIds,
            long elapsedRealtimeNanos) {
        mEventType = checkValidEventType(eventType);
        mTimeZoneIds = immutableList(timeZoneIds);

@@ -88,14 +83,6 @@ public final class LocationTimeZoneEvent implements Parcelable {
        mElapsedRealtimeNanos = elapsedRealtimeNanos;
    }

    /**
     * Returns the current user when the event was generated.
     */
    @NonNull
    public UserHandle getUserHandle() {
        return mUserHandle;
    }

    /**
     * Returns the time of this fix, in elapsed real-time since system boot.
     *
@@ -129,8 +116,7 @@ public final class LocationTimeZoneEvent implements Parcelable {
    @Override
    public String toString() {
        return "LocationTimeZoneEvent{"
                + "mUserHandle=" + mUserHandle
                + ", mEventType=" + mEventType
                + "mEventType=" + mEventType
                + ", mTimeZoneIds=" + mTimeZoneIds
                + ", mElapsedRealtimeNanos=" + mElapsedRealtimeNanos
                + '}';
@@ -140,14 +126,12 @@ public final class LocationTimeZoneEvent implements Parcelable {
            new Parcelable.Creator<LocationTimeZoneEvent>() {
                @Override
                public LocationTimeZoneEvent createFromParcel(Parcel in) {
                    UserHandle userHandle = UserHandle.readFromParcel(in);
                    int eventType = in.readInt();
                    @SuppressWarnings("unchecked")
                    ArrayList<String> timeZoneIds =
                            (ArrayList<String>) in.readArrayList(null /* classLoader */);
                    long elapsedRealtimeNanos = in.readLong();
                    return new LocationTimeZoneEvent(
                            userHandle, eventType, timeZoneIds, elapsedRealtimeNanos);
                    return new LocationTimeZoneEvent(eventType, timeZoneIds, elapsedRealtimeNanos);
                }

                @Override
@@ -163,7 +147,6 @@ public final class LocationTimeZoneEvent implements Parcelable {

    @Override
    public void writeToParcel(Parcel parcel, int flags) {
        mUserHandle.writeToParcel(parcel, flags);
        parcel.writeInt(mEventType);
        parcel.writeList(mTimeZoneIds);
        parcel.writeLong(mElapsedRealtimeNanos);
@@ -178,21 +161,19 @@ public final class LocationTimeZoneEvent implements Parcelable {
            return false;
        }
        LocationTimeZoneEvent that = (LocationTimeZoneEvent) o;
        return mUserHandle.equals(that.mUserHandle)
                && mEventType == that.mEventType
        return mEventType == that.mEventType
                && mElapsedRealtimeNanos == that.mElapsedRealtimeNanos
                && mTimeZoneIds.equals(that.mTimeZoneIds);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mUserHandle, mEventType, mTimeZoneIds, mElapsedRealtimeNanos);
        return Objects.hash(mEventType, mTimeZoneIds, mElapsedRealtimeNanos);
    }

    /** @hide */
    public static final class Builder {

        private UserHandle mUserHandle;
        private @EventType int mEventType = EVENT_TYPE_UNKNOWN;
        private @NonNull List<String> mTimeZoneIds = Collections.emptyList();
        private long mElapsedRealtimeNanos;
@@ -204,20 +185,11 @@ public final class LocationTimeZoneEvent implements Parcelable {
         * Sets the contents of this from the supplied instance.
         */
        public Builder(@NonNull LocationTimeZoneEvent ltz) {
            mUserHandle = ltz.mUserHandle;
            mEventType = ltz.mEventType;
            mTimeZoneIds = ltz.mTimeZoneIds;
            mElapsedRealtimeNanos = ltz.mElapsedRealtimeNanos;
        }

        /**
         * Set the current user when this event was generated.
         */
        public Builder setUserHandle(@NonNull UserHandle userHandle) {
            mUserHandle = Objects.requireNonNull(userHandle);
            return this;
        }

        /**
         * Set the time zone ID of this event.
         */
@@ -247,8 +219,7 @@ public final class LocationTimeZoneEvent implements Parcelable {
         * Builds a {@link LocationTimeZoneEvent} instance.
         */
        public LocationTimeZoneEvent build() {
            return new LocationTimeZoneEvent(
                    mUserHandle, mEventType, mTimeZoneIds, mElapsedRealtimeNanos);
            return new LocationTimeZoneEvent(mEventType, mTimeZoneIds, mElapsedRealtimeNanos);
        }
    }

+0 −3
Original line number Diff line number Diff line
@@ -18,10 +18,8 @@ package com.android.location.timezone.provider;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.app.ActivityManager;
import android.location.timezone.LocationTimeZoneEvent;
import android.os.SystemClock;
import android.os.UserHandle;

import java.util.Collections;
import java.util.List;
@@ -146,7 +144,6 @@ public final class LocationTimeZoneEventUnbundled {
        public LocationTimeZoneEventUnbundled build() {
            final int internalEventType = this.mEventType;
            LocationTimeZoneEvent event = new LocationTimeZoneEvent.Builder()
                    .setUserHandle(UserHandle.of(ActivityManager.getCurrentUser()))
                    .setEventType(internalEventType)
                    .setTimeZoneIds(mTimeZoneIds)
                    .setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos())
+0 −7
Original line number Diff line number Diff line
@@ -404,13 +404,6 @@ class ControllerImpl extends LocationTimeZoneProviderController {
            return;
        }

        // Consistency check for user. This may be possible as there are various races around
        // current user switches.
        if (!Objects.equals(event.getUserHandle(), mCurrentUserConfiguration.getUserHandle())) {
            warnLog("Using event=" + event + " from a different user="
                    + mCurrentUserConfiguration);
        }

        if (!mCurrentUserConfiguration.getGeoDetectionEnabledBehavior()) {
            // This should not happen: the provider should not be in an enabled state if the user
            // does not have geodetection enabled.
+1 −4
Original line number Diff line number Diff line
@@ -25,11 +25,9 @@ import static com.android.server.location.timezone.LocationTimeZoneManagerServic

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.location.timezone.LocationTimeZoneEvent;
import android.os.ShellCommand;
import android.os.SystemClock;
import android.os.UserHandle;

import java.io.PrintWriter;
import java.util.ArrayList;
@@ -119,8 +117,7 @@ final class SimulatedBinderProviderEvent {

    private static LocationTimeZoneEvent parseLocationTimeZoneEventArgs(ShellCommand shellCommand) {
        LocationTimeZoneEvent.Builder eventBuilder = new LocationTimeZoneEvent.Builder()
                .setElapsedRealtimeNanos(SystemClock.elapsedRealtime())
                .setUserHandle(UserHandle.of(ActivityManager.getCurrentUser()));
                .setElapsedRealtimeNanos(SystemClock.elapsedRealtime());

        String eventTypeString = shellCommand.getNextArgRequired();
        switch (eventTypeString.toUpperCase()) {
+0 −27
Original line number Diff line number Diff line
@@ -23,8 +23,6 @@ import static org.junit.Assert.assertNotEquals;

import static java.util.Collections.singletonList;

import android.os.UserHandle;

import org.junit.Test;

import java.util.List;
@@ -35,10 +33,6 @@ public class LocationTimeZoneEventTest {

    private static final List<String> ARBITRARY_TIME_ZONE_IDS = singletonList("Europe/London");

    private static final UserHandle ARBITRARY_USER_HANDLE = UserHandle.SYSTEM;
    private static final UserHandle ARBITRARY_USER_HANDLE2 =
            UserHandle.of(ARBITRARY_USER_HANDLE.getIdentifier() + 1);

    @Test(expected = RuntimeException.class)
    public void testSetInvalidEventType() {
        new LocationTimeZoneEvent.Builder().setEventType(Integer.MAX_VALUE);
@@ -47,7 +41,6 @@ public class LocationTimeZoneEventTest {
    @Test(expected = RuntimeException.class)
    public void testBuildUnsetEventType() {
        new LocationTimeZoneEvent.Builder()
                .setUserHandle(ARBITRARY_USER_HANDLE)
                .setTimeZoneIds(ARBITRARY_TIME_ZONE_IDS)
                .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS)
                .build();
@@ -56,7 +49,6 @@ public class LocationTimeZoneEventTest {
    @Test(expected = RuntimeException.class)
    public void testInvalidTimeZoneIds() {
        new LocationTimeZoneEvent.Builder()
                .setUserHandle(ARBITRARY_USER_HANDLE)
                .setEventType(LocationTimeZoneEvent.EVENT_TYPE_UNCERTAIN)
                .setTimeZoneIds(ARBITRARY_TIME_ZONE_IDS)
                .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS)
@@ -66,7 +58,6 @@ public class LocationTimeZoneEventTest {
    @Test
    public void testEquals() {
        LocationTimeZoneEvent.Builder builder1 = new LocationTimeZoneEvent.Builder()
                .setUserHandle(ARBITRARY_USER_HANDLE)
                .setEventType(LocationTimeZoneEvent.EVENT_TYPE_UNCERTAIN)
                .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS);
        {
@@ -75,7 +66,6 @@ public class LocationTimeZoneEventTest {
        }

        LocationTimeZoneEvent.Builder builder2 = new LocationTimeZoneEvent.Builder()
                .setUserHandle(ARBITRARY_USER_HANDLE)
                .setEventType(LocationTimeZoneEvent.EVENT_TYPE_UNCERTAIN)
                .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS);
        {
@@ -85,22 +75,6 @@ public class LocationTimeZoneEventTest {
            assertEquals(two, one);
        }

        builder1.setUserHandle(ARBITRARY_USER_HANDLE2);
        {
            LocationTimeZoneEvent one = builder1.build();
            LocationTimeZoneEvent two = builder2.build();
            assertNotEquals(one, two);
            assertNotEquals(two, one);
        }

        builder2.setUserHandle(ARBITRARY_USER_HANDLE2);
        {
            LocationTimeZoneEvent one = builder1.build();
            LocationTimeZoneEvent two = builder2.build();
            assertEquals(one, two);
            assertEquals(two, one);
        }

        builder1.setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS + 1);
        {
            LocationTimeZoneEvent one = builder1.build();
@@ -153,7 +127,6 @@ public class LocationTimeZoneEventTest {
    @Test
    public void testParcelable() {
        LocationTimeZoneEvent.Builder builder = new LocationTimeZoneEvent.Builder()
                .setUserHandle(ARBITRARY_USER_HANDLE)
                .setEventType(LocationTimeZoneEvent.EVENT_TYPE_PERMANENT_FAILURE)
                .setElapsedRealtimeNanos(ARBITRARY_ELAPSED_REALTIME_NANOS);
        assertRoundTripParcelable(builder.build());
Loading