Remove use of UserHandle in LocationTimeZoneEvent
It causes problems with permissions in testing and isn't strictly required so it can be removed. Bug: 152744911 Bug: 149014708 Test: atest services/tests/servicestests/src/android/location/timezone/LocationTimeZoneEventTest.java Change-Id: Iba9c07780e3cc9f94f2c77144c48916236f31e60
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -26,7 +26,6 @@ import static com.android.server.location.timezone.LocationTimeZoneProvider.Prov
|
||||
import static com.android.server.location.timezone.LocationTimeZoneProvider.ProviderState.PROVIDER_STATE_PERM_FAILED;
|
||||
import static com.android.server.location.timezone.TestSupport.USER1_CONFIG_GEO_DETECTION_DISABLED;
|
||||
import static com.android.server.location.timezone.TestSupport.USER1_CONFIG_GEO_DETECTION_ENABLED;
|
||||
import static com.android.server.location.timezone.TestSupport.USER1_ID;
|
||||
import static com.android.server.location.timezone.TestSupport.USER2_CONFIG_GEO_DETECTION_ENABLED;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -38,9 +37,7 @@ import static java.util.Arrays.asList;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.UserIdInt;
|
||||
import android.location.timezone.LocationTimeZoneEvent;
|
||||
import android.os.UserHandle;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.util.IndentingPrintWriter;
|
||||
|
||||
@@ -66,13 +63,13 @@ public class ControllerImplTest {
|
||||
private static final long ARBITRARY_TIME = 12345L;
|
||||
|
||||
private static final LocationTimeZoneEvent USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT1 =
|
||||
createLocationTimeZoneEvent(USER1_ID, EVENT_TYPE_SUCCESS, asList("Europe/London"));
|
||||
createLocationTimeZoneEvent(EVENT_TYPE_SUCCESS, asList("Europe/London"));
|
||||
private static final LocationTimeZoneEvent USER1_SUCCESS_LOCATION_TIME_ZONE_EVENT2 =
|
||||
createLocationTimeZoneEvent(USER1_ID, EVENT_TYPE_SUCCESS, asList("Europe/Paris"));
|
||||
createLocationTimeZoneEvent(EVENT_TYPE_SUCCESS, asList("Europe/Paris"));
|
||||
private static final LocationTimeZoneEvent USER1_UNCERTAIN_LOCATION_TIME_ZONE_EVENT =
|
||||
createLocationTimeZoneEvent(USER1_ID, EVENT_TYPE_UNCERTAIN, null);
|
||||
createLocationTimeZoneEvent(EVENT_TYPE_UNCERTAIN, null);
|
||||
private static final LocationTimeZoneEvent USER1_PERM_FAILURE_LOCATION_TIME_ZONE_EVENT =
|
||||
createLocationTimeZoneEvent(USER1_ID, EVENT_TYPE_PERMANENT_FAILURE, null);
|
||||
createLocationTimeZoneEvent(EVENT_TYPE_PERMANENT_FAILURE, null);
|
||||
|
||||
private TestThreadingDomain mTestThreadingDomain;
|
||||
private TestCallback mTestCallback;
|
||||
@@ -936,11 +933,10 @@ public class ControllerImplTest {
|
||||
controller.getUncertaintyTimeoutDelayMillis());
|
||||
}
|
||||
|
||||
private static LocationTimeZoneEvent createLocationTimeZoneEvent(@UserIdInt int userId,
|
||||
private static LocationTimeZoneEvent createLocationTimeZoneEvent(
|
||||
int eventType, @Nullable List<String> timeZoneIds) {
|
||||
LocationTimeZoneEvent.Builder builder = new LocationTimeZoneEvent.Builder()
|
||||
.setElapsedRealtimeNanos(ARBITRARY_TIME)
|
||||
.setUserHandle(UserHandle.of(userId))
|
||||
.setEventType(eventType);
|
||||
if (timeZoneIds != null) {
|
||||
builder.setTimeZoneIds(timeZoneIds);
|
||||
|
||||
Reference in New Issue
Block a user