Merge "Rename phoneId to slotIndex" am: 4e540a1c59
Change-Id: If220028441547c85c3540c52af9f714a15853b3a
This commit is contained in:
@@ -6,7 +6,7 @@ package android.app.timedetector {
|
|||||||
method public void addDebugInfo(@NonNull java.util.List<java.lang.String>);
|
method public void addDebugInfo(@NonNull java.util.List<java.lang.String>);
|
||||||
method public int describeContents();
|
method public int describeContents();
|
||||||
method @NonNull public java.util.List<java.lang.String> getDebugInfo();
|
method @NonNull public java.util.List<java.lang.String> getDebugInfo();
|
||||||
method public int getPhoneId();
|
method public int getSlotIndex();
|
||||||
method @Nullable public android.os.TimestampedValue<java.lang.Long> getUtcTime();
|
method @Nullable public android.os.TimestampedValue<java.lang.Long> getUtcTime();
|
||||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||||
field @NonNull public static final android.os.Parcelable.Creator<android.app.timedetector.PhoneTimeSuggestion> CREATOR;
|
field @NonNull public static final android.os.Parcelable.Creator<android.app.timedetector.PhoneTimeSuggestion> CREATOR;
|
||||||
@@ -34,8 +34,8 @@ package android.app.timezonedetector {
|
|||||||
method public int describeContents();
|
method public int describeContents();
|
||||||
method @NonNull public java.util.List<java.lang.String> getDebugInfo();
|
method @NonNull public java.util.List<java.lang.String> getDebugInfo();
|
||||||
method public int getMatchType();
|
method public int getMatchType();
|
||||||
method public int getPhoneId();
|
|
||||||
method public int getQuality();
|
method public int getQuality();
|
||||||
|
method public int getSlotIndex();
|
||||||
method @Nullable public String getZoneId();
|
method @Nullable public String getZoneId();
|
||||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||||
field @NonNull public static final android.os.Parcelable.Creator<android.app.timezonedetector.PhoneTimeZoneSuggestion> CREATOR;
|
field @NonNull public static final android.os.Parcelable.Creator<android.app.timezonedetector.PhoneTimeZoneSuggestion> CREATOR;
|
||||||
|
|||||||
@@ -57,19 +57,19 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private final int mPhoneId;
|
private final int mSlotIndex;
|
||||||
@Nullable private final TimestampedValue<Long> mUtcTime;
|
@Nullable private final TimestampedValue<Long> mUtcTime;
|
||||||
@Nullable private ArrayList<String> mDebugInfo;
|
@Nullable private ArrayList<String> mDebugInfo;
|
||||||
|
|
||||||
private PhoneTimeSuggestion(Builder builder) {
|
private PhoneTimeSuggestion(Builder builder) {
|
||||||
mPhoneId = builder.mPhoneId;
|
mSlotIndex = builder.mSlotIndex;
|
||||||
mUtcTime = builder.mUtcTime;
|
mUtcTime = builder.mUtcTime;
|
||||||
mDebugInfo = builder.mDebugInfo != null ? new ArrayList<>(builder.mDebugInfo) : null;
|
mDebugInfo = builder.mDebugInfo != null ? new ArrayList<>(builder.mDebugInfo) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PhoneTimeSuggestion createFromParcel(Parcel in) {
|
private static PhoneTimeSuggestion createFromParcel(Parcel in) {
|
||||||
int phoneId = in.readInt();
|
int slotIndex = in.readInt();
|
||||||
PhoneTimeSuggestion suggestion = new PhoneTimeSuggestion.Builder(phoneId)
|
PhoneTimeSuggestion suggestion = new PhoneTimeSuggestion.Builder(slotIndex)
|
||||||
.setUtcTime(in.readParcelable(null /* classLoader */))
|
.setUtcTime(in.readParcelable(null /* classLoader */))
|
||||||
.build();
|
.build();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -87,17 +87,17 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||||
dest.writeInt(mPhoneId);
|
dest.writeInt(mSlotIndex);
|
||||||
dest.writeParcelable(mUtcTime, 0);
|
dest.writeParcelable(mUtcTime, 0);
|
||||||
dest.writeList(mDebugInfo);
|
dest.writeList(mDebugInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an identifier for the source of this suggestion. When a device has several "phones",
|
* Returns an identifier for the source of this suggestion. When a device has several sim slots
|
||||||
* i.e. sim slots or equivalent, it is used to identify which one.
|
* or equivalent, it is used to identify which one the suggestion is from.
|
||||||
*/
|
*/
|
||||||
public int getPhoneId() {
|
public int getSlotIndex() {
|
||||||
return mPhoneId;
|
return mSlotIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,19 +152,19 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PhoneTimeSuggestion that = (PhoneTimeSuggestion) o;
|
PhoneTimeSuggestion that = (PhoneTimeSuggestion) o;
|
||||||
return mPhoneId == that.mPhoneId
|
return mSlotIndex == that.mSlotIndex
|
||||||
&& Objects.equals(mUtcTime, that.mUtcTime);
|
&& Objects.equals(mUtcTime, that.mUtcTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(mPhoneId, mUtcTime);
|
return Objects.hash(mSlotIndex, mUtcTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "PhoneTimeSuggestion{"
|
return "PhoneTimeSuggestion{"
|
||||||
+ "mPhoneId='" + mPhoneId + '\''
|
+ "mSlotIndex='" + mSlotIndex + '\''
|
||||||
+ ", mUtcTime=" + mUtcTime
|
+ ", mUtcTime=" + mUtcTime
|
||||||
+ ", mDebugInfo=" + mDebugInfo
|
+ ", mDebugInfo=" + mDebugInfo
|
||||||
+ '}';
|
+ '}';
|
||||||
@@ -177,13 +177,13 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
private final int mPhoneId;
|
private final int mSlotIndex;
|
||||||
@Nullable private TimestampedValue<Long> mUtcTime;
|
@Nullable private TimestampedValue<Long> mUtcTime;
|
||||||
@Nullable private List<String> mDebugInfo;
|
@Nullable private List<String> mDebugInfo;
|
||||||
|
|
||||||
/** Creates a builder with the specified {@code phoneId}. */
|
/** Creates a builder with the specified {@code slotIndex}. */
|
||||||
public Builder(int phoneId) {
|
public Builder(int slotIndex) {
|
||||||
mPhoneId = phoneId;
|
mSlotIndex = slotIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the builder for call chaining. */
|
/** Returns the builder for call chaining. */
|
||||||
|
|||||||
@@ -66,12 +66,12 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty time zone suggestion, i.e. one that will cancel previous suggestions with
|
* Creates an empty time zone suggestion, i.e. one that will cancel previous suggestions with
|
||||||
* the same {@code phoneId}.
|
* the same {@code slotIndex}.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public static PhoneTimeZoneSuggestion createEmptySuggestion(
|
public static PhoneTimeZoneSuggestion createEmptySuggestion(
|
||||||
int phoneId, @NonNull String debugInfo) {
|
int slotIndex, @NonNull String debugInfo) {
|
||||||
return new Builder(phoneId).addDebugInfo(debugInfo).build();
|
return new Builder(slotIndex).addDebugInfo(debugInfo).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -135,7 +135,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
* The ID of the phone this suggestion is associated with. For multiple-sim devices this
|
* The ID of the phone this suggestion is associated with. For multiple-sim devices this
|
||||||
* helps to establish source so filtering / stickiness can be implemented.
|
* helps to establish source so filtering / stickiness can be implemented.
|
||||||
*/
|
*/
|
||||||
private final int mPhoneId;
|
private final int mSlotIndex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The suggestion. {@code null} means there is no current suggestion and any previous suggestion
|
* The suggestion. {@code null} means there is no current suggestion and any previous suggestion
|
||||||
@@ -165,7 +165,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
private List<String> mDebugInfo;
|
private List<String> mDebugInfo;
|
||||||
|
|
||||||
private PhoneTimeZoneSuggestion(Builder builder) {
|
private PhoneTimeZoneSuggestion(Builder builder) {
|
||||||
mPhoneId = builder.mPhoneId;
|
mSlotIndex = builder.mSlotIndex;
|
||||||
mZoneId = builder.mZoneId;
|
mZoneId = builder.mZoneId;
|
||||||
mMatchType = builder.mMatchType;
|
mMatchType = builder.mMatchType;
|
||||||
mQuality = builder.mQuality;
|
mQuality = builder.mQuality;
|
||||||
@@ -175,8 +175,8 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static PhoneTimeZoneSuggestion createFromParcel(Parcel in) {
|
private static PhoneTimeZoneSuggestion createFromParcel(Parcel in) {
|
||||||
// Use the Builder so we get validation during build().
|
// Use the Builder so we get validation during build().
|
||||||
int phoneId = in.readInt();
|
int slotIndex = in.readInt();
|
||||||
PhoneTimeZoneSuggestion suggestion = new Builder(phoneId)
|
PhoneTimeZoneSuggestion suggestion = new Builder(slotIndex)
|
||||||
.setZoneId(in.readString())
|
.setZoneId(in.readString())
|
||||||
.setMatchType(in.readInt())
|
.setMatchType(in.readInt())
|
||||||
.setQuality(in.readInt())
|
.setQuality(in.readInt())
|
||||||
@@ -190,7 +190,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
public void writeToParcel(@NonNull Parcel dest, int flags) {
|
||||||
dest.writeInt(mPhoneId);
|
dest.writeInt(mSlotIndex);
|
||||||
dest.writeString(mZoneId);
|
dest.writeString(mZoneId);
|
||||||
dest.writeInt(mMatchType);
|
dest.writeInt(mMatchType);
|
||||||
dest.writeInt(mQuality);
|
dest.writeInt(mQuality);
|
||||||
@@ -203,11 +203,11 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an identifier for the source of this suggestion. When a device has several "phones",
|
* Returns an identifier for the source of this suggestion. When a device has several sim slots
|
||||||
* i.e. sim slots or equivalent, it is used to identify which one.
|
* or equivalent, it is used to identify which one the suggestion is from.
|
||||||
*/
|
*/
|
||||||
public int getPhoneId() {
|
public int getSlotIndex() {
|
||||||
return mPhoneId;
|
return mSlotIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -282,7 +282,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PhoneTimeZoneSuggestion that = (PhoneTimeZoneSuggestion) o;
|
PhoneTimeZoneSuggestion that = (PhoneTimeZoneSuggestion) o;
|
||||||
return mPhoneId == that.mPhoneId
|
return mSlotIndex == that.mSlotIndex
|
||||||
&& mMatchType == that.mMatchType
|
&& mMatchType == that.mMatchType
|
||||||
&& mQuality == that.mQuality
|
&& mQuality == that.mQuality
|
||||||
&& Objects.equals(mZoneId, that.mZoneId);
|
&& Objects.equals(mZoneId, that.mZoneId);
|
||||||
@@ -290,13 +290,13 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(mPhoneId, mZoneId, mMatchType, mQuality);
|
return Objects.hash(mSlotIndex, mZoneId, mMatchType, mQuality);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "PhoneTimeZoneSuggestion{"
|
return "PhoneTimeZoneSuggestion{"
|
||||||
+ "mPhoneId=" + mPhoneId
|
+ "mSlotIndex=" + mSlotIndex
|
||||||
+ ", mZoneId='" + mZoneId + '\''
|
+ ", mZoneId='" + mZoneId + '\''
|
||||||
+ ", mMatchType=" + mMatchType
|
+ ", mMatchType=" + mMatchType
|
||||||
+ ", mQuality=" + mQuality
|
+ ", mQuality=" + mQuality
|
||||||
@@ -311,14 +311,14 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
private final int mPhoneId;
|
private final int mSlotIndex;
|
||||||
@Nullable private String mZoneId;
|
@Nullable private String mZoneId;
|
||||||
@MatchType private int mMatchType;
|
@MatchType private int mMatchType;
|
||||||
@Quality private int mQuality;
|
@Quality private int mQuality;
|
||||||
@Nullable private List<String> mDebugInfo;
|
@Nullable private List<String> mDebugInfo;
|
||||||
|
|
||||||
public Builder(int phoneId) {
|
public Builder(int slotIndex) {
|
||||||
mPhoneId = phoneId;
|
mSlotIndex = slotIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,17 +27,17 @@ import android.os.TimestampedValue;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class PhoneTimeSuggestionTest {
|
public class PhoneTimeSuggestionTest {
|
||||||
private static final int PHONE_ID = 99999;
|
private static final int SLOT_INDEX = 99999;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
PhoneTimeSuggestion.Builder builder1 = new PhoneTimeSuggestion.Builder(PHONE_ID);
|
PhoneTimeSuggestion.Builder builder1 = new PhoneTimeSuggestion.Builder(SLOT_INDEX);
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion one = builder1.build();
|
PhoneTimeSuggestion one = builder1.build();
|
||||||
assertEquals(one, one);
|
assertEquals(one, one);
|
||||||
}
|
}
|
||||||
|
|
||||||
PhoneTimeSuggestion.Builder builder2 = new PhoneTimeSuggestion.Builder(PHONE_ID);
|
PhoneTimeSuggestion.Builder builder2 = new PhoneTimeSuggestion.Builder(SLOT_INDEX);
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion one = builder1.build();
|
PhoneTimeSuggestion one = builder1.build();
|
||||||
PhoneTimeSuggestion two = builder2.build();
|
PhoneTimeSuggestion two = builder2.build();
|
||||||
@@ -59,7 +59,7 @@ public class PhoneTimeSuggestionTest {
|
|||||||
assertEquals(two, one);
|
assertEquals(two, one);
|
||||||
}
|
}
|
||||||
|
|
||||||
PhoneTimeSuggestion.Builder builder3 = new PhoneTimeSuggestion.Builder(PHONE_ID + 1);
|
PhoneTimeSuggestion.Builder builder3 = new PhoneTimeSuggestion.Builder(SLOT_INDEX + 1);
|
||||||
builder3.setUtcTime(new TimestampedValue<>(1111L, 2222L));
|
builder3.setUtcTime(new TimestampedValue<>(1111L, 2222L));
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion one = builder1.build();
|
PhoneTimeSuggestion one = builder1.build();
|
||||||
@@ -80,7 +80,7 @@ public class PhoneTimeSuggestionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParcelable() {
|
public void testParcelable() {
|
||||||
PhoneTimeSuggestion.Builder builder = new PhoneTimeSuggestion.Builder(PHONE_ID);
|
PhoneTimeSuggestion.Builder builder = new PhoneTimeSuggestion.Builder(SLOT_INDEX);
|
||||||
assertRoundTripParcelable(builder.build());
|
assertRoundTripParcelable(builder.build());
|
||||||
|
|
||||||
builder.setUtcTime(new TimestampedValue<>(1111L, 2222L));
|
builder.setUtcTime(new TimestampedValue<>(1111L, 2222L));
|
||||||
|
|||||||
@@ -26,17 +26,17 @@ import static org.junit.Assert.assertTrue;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class PhoneTimeZoneSuggestionTest {
|
public class PhoneTimeZoneSuggestionTest {
|
||||||
private static final int PHONE_ID = 99999;
|
private static final int SLOT_INDEX = 99999;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
PhoneTimeZoneSuggestion.Builder builder1 = new PhoneTimeZoneSuggestion.Builder(PHONE_ID);
|
PhoneTimeZoneSuggestion.Builder builder1 = new PhoneTimeZoneSuggestion.Builder(SLOT_INDEX);
|
||||||
{
|
{
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
PhoneTimeZoneSuggestion one = builder1.build();
|
||||||
assertEquals(one, one);
|
assertEquals(one, one);
|
||||||
}
|
}
|
||||||
|
|
||||||
PhoneTimeZoneSuggestion.Builder builder2 = new PhoneTimeZoneSuggestion.Builder(PHONE_ID);
|
PhoneTimeZoneSuggestion.Builder builder2 = new PhoneTimeZoneSuggestion.Builder(SLOT_INDEX);
|
||||||
{
|
{
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
PhoneTimeZoneSuggestion one = builder1.build();
|
||||||
PhoneTimeZoneSuggestion two = builder2.build();
|
PhoneTimeZoneSuggestion two = builder2.build();
|
||||||
@@ -45,7 +45,7 @@ public class PhoneTimeZoneSuggestionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PhoneTimeZoneSuggestion.Builder builder3 =
|
PhoneTimeZoneSuggestion.Builder builder3 =
|
||||||
new PhoneTimeZoneSuggestion.Builder(PHONE_ID + 1);
|
new PhoneTimeZoneSuggestion.Builder(SLOT_INDEX + 1);
|
||||||
{
|
{
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
PhoneTimeZoneSuggestion one = builder1.build();
|
||||||
PhoneTimeZoneSuggestion three = builder3.build();
|
PhoneTimeZoneSuggestion three = builder3.build();
|
||||||
@@ -120,7 +120,7 @@ public class PhoneTimeZoneSuggestionTest {
|
|||||||
|
|
||||||
@Test(expected = RuntimeException.class)
|
@Test(expected = RuntimeException.class)
|
||||||
public void testBuilderValidates_emptyZone_badMatchType() {
|
public void testBuilderValidates_emptyZone_badMatchType() {
|
||||||
PhoneTimeZoneSuggestion.Builder builder = new PhoneTimeZoneSuggestion.Builder(PHONE_ID);
|
PhoneTimeZoneSuggestion.Builder builder = new PhoneTimeZoneSuggestion.Builder(SLOT_INDEX);
|
||||||
// No zone ID, so match type should be left unset.
|
// No zone ID, so match type should be left unset.
|
||||||
builder.setMatchType(PhoneTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET);
|
builder.setMatchType(PhoneTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET);
|
||||||
builder.build();
|
builder.build();
|
||||||
@@ -128,7 +128,7 @@ public class PhoneTimeZoneSuggestionTest {
|
|||||||
|
|
||||||
@Test(expected = RuntimeException.class)
|
@Test(expected = RuntimeException.class)
|
||||||
public void testBuilderValidates_zoneSet_badMatchType() {
|
public void testBuilderValidates_zoneSet_badMatchType() {
|
||||||
PhoneTimeZoneSuggestion.Builder builder = new PhoneTimeZoneSuggestion.Builder(PHONE_ID);
|
PhoneTimeZoneSuggestion.Builder builder = new PhoneTimeZoneSuggestion.Builder(SLOT_INDEX);
|
||||||
builder.setZoneId("Europe/London");
|
builder.setZoneId("Europe/London");
|
||||||
builder.setQuality(PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
|
builder.setQuality(PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
|
||||||
builder.build();
|
builder.build();
|
||||||
@@ -136,7 +136,7 @@ public class PhoneTimeZoneSuggestionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParcelable() {
|
public void testParcelable() {
|
||||||
PhoneTimeZoneSuggestion.Builder builder = new PhoneTimeZoneSuggestion.Builder(PHONE_ID);
|
PhoneTimeZoneSuggestion.Builder builder = new PhoneTimeZoneSuggestion.Builder(SLOT_INDEX);
|
||||||
assertRoundTripParcelable(builder.build());
|
assertRoundTripParcelable(builder.build());
|
||||||
|
|
||||||
builder.setZoneId("Europe/London");
|
builder.setZoneId("Europe/London");
|
||||||
|
|||||||
@@ -101,11 +101,12 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
private TimestampedValue<Long> mLastAutoSystemClockTimeSet;
|
private TimestampedValue<Long> mLastAutoSystemClockTimeSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mapping from phoneId to a time suggestion. We typically expect one or two mappings: devices
|
* A mapping from slotIndex to a time suggestion. We typically expect one or two mappings:
|
||||||
* will have a small number of telephony devices and phoneIds are assumed to be stable.
|
* devices will have a small number of telephony devices and slotIndexs are assumed to be
|
||||||
|
* stable.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
private final ArrayMapWithHistory<Integer, PhoneTimeSuggestion> mSuggestionByPhoneId =
|
private final ArrayMapWithHistory<Integer, PhoneTimeSuggestion> mSuggestionBySlotIndex =
|
||||||
new ArrayMapWithHistory<>(KEEP_SUGGESTION_HISTORY_SIZE);
|
new ArrayMapWithHistory<>(KEEP_SUGGESTION_HISTORY_SIZE);
|
||||||
|
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
@@ -155,7 +156,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform validation / input filtering and record the validated suggestion against the
|
// Perform validation / input filtering and record the validated suggestion against the
|
||||||
// phoneId.
|
// slotIndex.
|
||||||
if (!validateAndStorePhoneSuggestion(timeSuggestion)) {
|
if (!validateAndStorePhoneSuggestion(timeSuggestion)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -202,7 +203,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
|
|
||||||
ipw.println("Phone suggestion history:");
|
ipw.println("Phone suggestion history:");
|
||||||
ipw.increaseIndent(); // level 2
|
ipw.increaseIndent(); // level 2
|
||||||
mSuggestionByPhoneId.dump(ipw);
|
mSuggestionBySlotIndex.dump(ipw);
|
||||||
ipw.decreaseIndent(); // level 2
|
ipw.decreaseIndent(); // level 2
|
||||||
|
|
||||||
ipw.println("Network suggestion history:");
|
ipw.println("Network suggestion history:");
|
||||||
@@ -223,8 +224,8 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int phoneId = suggestion.getPhoneId();
|
int slotIndex = suggestion.getSlotIndex();
|
||||||
PhoneTimeSuggestion previousSuggestion = mSuggestionByPhoneId.get(phoneId);
|
PhoneTimeSuggestion previousSuggestion = mSuggestionBySlotIndex.get(slotIndex);
|
||||||
if (previousSuggestion != null) {
|
if (previousSuggestion != null) {
|
||||||
// We can log / discard suggestions with obvious issues with the reference time clock.
|
// We can log / discard suggestions with obvious issues with the reference time clock.
|
||||||
if (previousSuggestion.getUtcTime() == null
|
if (previousSuggestion.getUtcTime() == null
|
||||||
@@ -249,7 +250,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store the latest suggestion.
|
// Store the latest suggestion.
|
||||||
mSuggestionByPhoneId.put(phoneId, suggestion);
|
mSuggestionBySlotIndex.put(slotIndex, suggestion);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,15 +324,15 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
//
|
//
|
||||||
// [1] https://en.wikipedia.org/wiki/NITZ
|
// [1] https://en.wikipedia.org/wiki/NITZ
|
||||||
//
|
//
|
||||||
// Generally, when there are suggestions from multiple phoneIds they should usually
|
// Generally, when there are suggestions from multiple slotIndexs they should usually
|
||||||
// approximately agree. In cases where signals *are* inaccurate we don't want to vacillate
|
// approximately agree. In cases where signals *are* inaccurate we don't want to vacillate
|
||||||
// between signals from two phoneIds. However, it is known for NITZ signals to be incorrect
|
// between signals from two slotIndexs. However, it is known for NITZ signals to be
|
||||||
// occasionally, which means we also don't want to stick forever with one phoneId. Without
|
// incorrect occasionally, which means we also don't want to stick forever with one
|
||||||
// cross-referencing across sources (e.g. the current device time, NTP), or doing some kind
|
// slotIndex. Without cross-referencing across sources (e.g. the current device time, NTP),
|
||||||
// of statistical analysis of consistency within and across phoneIds, we can't know which
|
// or doing some kind of statistical analysis of consistency within and across slotIndexs,
|
||||||
// suggestions are more correct.
|
// we can't know which suggestions are more correct.
|
||||||
//
|
//
|
||||||
// For simplicity, we try to value recency, then consistency of phoneId.
|
// For simplicity, we try to value recency, then consistency of slotIndex.
|
||||||
//
|
//
|
||||||
// The heuristic works as follows:
|
// The heuristic works as follows:
|
||||||
// Recency: The most recent suggestion from each phone is scored. The score is based on a
|
// Recency: The most recent suggestion from each phone is scored. The score is based on a
|
||||||
@@ -339,20 +340,20 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
// bucket, thus applying a loose reference time ordering. The suggestion with the highest
|
// bucket, thus applying a loose reference time ordering. The suggestion with the highest
|
||||||
// score is used.
|
// score is used.
|
||||||
// Consistency: If there a multiple suggestions with the same score, the suggestion with the
|
// Consistency: If there a multiple suggestions with the same score, the suggestion with the
|
||||||
// lowest phoneId is always taken.
|
// lowest slotIndex is always taken.
|
||||||
//
|
//
|
||||||
// In the trivial case with a single ID this will just mean that the latest received
|
// In the trivial case with a single ID this will just mean that the latest received
|
||||||
// suggestion is used.
|
// suggestion is used.
|
||||||
|
|
||||||
PhoneTimeSuggestion bestSuggestion = null;
|
PhoneTimeSuggestion bestSuggestion = null;
|
||||||
int bestScore = PHONE_INVALID_SCORE;
|
int bestScore = PHONE_INVALID_SCORE;
|
||||||
for (int i = 0; i < mSuggestionByPhoneId.size(); i++) {
|
for (int i = 0; i < mSuggestionBySlotIndex.size(); i++) {
|
||||||
Integer phoneId = mSuggestionByPhoneId.keyAt(i);
|
Integer slotIndex = mSuggestionBySlotIndex.keyAt(i);
|
||||||
PhoneTimeSuggestion candidateSuggestion = mSuggestionByPhoneId.valueAt(i);
|
PhoneTimeSuggestion candidateSuggestion = mSuggestionBySlotIndex.valueAt(i);
|
||||||
if (candidateSuggestion == null) {
|
if (candidateSuggestion == null) {
|
||||||
// Unexpected - null suggestions should never be stored.
|
// Unexpected - null suggestions should never be stored.
|
||||||
Slog.w(LOG_TAG, "Latest suggestion unexpectedly null for phoneId."
|
Slog.w(LOG_TAG, "Latest suggestion unexpectedly null for slotIndex."
|
||||||
+ " phoneId=" + phoneId);
|
+ " slotIndex=" + slotIndex);
|
||||||
continue;
|
continue;
|
||||||
} else if (candidateSuggestion.getUtcTime() == null) {
|
} else if (candidateSuggestion.getUtcTime() == null) {
|
||||||
// Unexpected - we do not store empty suggestions.
|
// Unexpected - we do not store empty suggestions.
|
||||||
@@ -372,10 +373,10 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
bestSuggestion = candidateSuggestion;
|
bestSuggestion = candidateSuggestion;
|
||||||
bestScore = candidateScore;
|
bestScore = candidateScore;
|
||||||
} else if (bestScore == candidateScore) {
|
} else if (bestScore == candidateScore) {
|
||||||
// Tie! Use the suggestion with the lowest phoneId.
|
// Tie! Use the suggestion with the lowest slotIndex.
|
||||||
int candidatePhoneId = candidateSuggestion.getPhoneId();
|
int candidateSlotIndex = candidateSuggestion.getSlotIndex();
|
||||||
int bestPhoneId = bestSuggestion.getPhoneId();
|
int bestSlotIndex = bestSuggestion.getSlotIndex();
|
||||||
if (candidatePhoneId < bestPhoneId) {
|
if (candidateSlotIndex < bestSlotIndex) {
|
||||||
bestSuggestion = candidateSuggestion;
|
bestSuggestion = candidateSuggestion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -396,7 +397,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The score is based on the age since receipt. Suggestions are bucketed so two
|
// The score is based on the age since receipt. Suggestions are bucketed so two
|
||||||
// suggestions in the same bucket from different phoneIds are scored the same.
|
// suggestions in the same bucket from different slotIndexs are scored the same.
|
||||||
long ageMillis = elapsedRealtimeMillis - utcTime.getReferenceTimeMillis();
|
long ageMillis = elapsedRealtimeMillis - utcTime.getReferenceTimeMillis();
|
||||||
|
|
||||||
// Turn the age into a discrete value: 0 <= bucketIndex < PHONE_BUCKET_COUNT.
|
// Turn the age into a discrete value: 0 <= bucketIndex < PHONE_BUCKET_COUNT.
|
||||||
@@ -560,8 +561,8 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@Nullable
|
@Nullable
|
||||||
public synchronized PhoneTimeSuggestion getLatestPhoneSuggestion(int phoneId) {
|
public synchronized PhoneTimeSuggestion getLatestPhoneSuggestion(int slotIndex) {
|
||||||
return mSuggestionByPhoneId.get(phoneId);
|
return mSuggestionBySlotIndex.get(slotIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -172,12 +172,12 @@ public class TimeZoneDetectorStrategy {
|
|||||||
private final LocalLog mTimeZoneChangesLog = new LocalLog(30, false /* useLocalTimestamps */);
|
private final LocalLog mTimeZoneChangesLog = new LocalLog(30, false /* useLocalTimestamps */);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mapping from phoneId to a phone time zone suggestion. We typically expect one or two
|
* A mapping from slotIndex to a phone time zone suggestion. We typically expect one or two
|
||||||
* mappings: devices will have a small number of telephony devices and phoneIds are assumed to
|
* mappings: devices will have a small number of telephony devices and slotIndexs are assumed to
|
||||||
* be stable.
|
* be stable.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
private ArrayMapWithHistory<Integer, QualifiedPhoneTimeZoneSuggestion> mSuggestionByPhoneId =
|
private ArrayMapWithHistory<Integer, QualifiedPhoneTimeZoneSuggestion> mSuggestionBySlotIndex =
|
||||||
new ArrayMapWithHistory<>(KEEP_PHONE_SUGGESTION_HISTORY_SIZE);
|
new ArrayMapWithHistory<>(KEEP_PHONE_SUGGESTION_HISTORY_SIZE);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -205,7 +205,7 @@ public class TimeZoneDetectorStrategy {
|
|||||||
/**
|
/**
|
||||||
* Suggests a time zone for the device, or withdraws a previous suggestion if
|
* Suggests a time zone for the device, or withdraws a previous suggestion if
|
||||||
* {@link PhoneTimeZoneSuggestion#getZoneId()} is {@code null}. The suggestion is scoped to a
|
* {@link PhoneTimeZoneSuggestion#getZoneId()} is {@code null}. The suggestion is scoped to a
|
||||||
* specific {@link PhoneTimeZoneSuggestion#getPhoneId() phone}.
|
* specific {@link PhoneTimeZoneSuggestion#getSlotIndex() phone}.
|
||||||
* See {@link PhoneTimeZoneSuggestion} for an explanation of the metadata associated with a
|
* See {@link PhoneTimeZoneSuggestion} for an explanation of the metadata associated with a
|
||||||
* suggestion. The strategy uses suggestions to decide whether to modify the device's time zone
|
* suggestion. The strategy uses suggestions to decide whether to modify the device's time zone
|
||||||
* setting and what to set it to.
|
* setting and what to set it to.
|
||||||
@@ -221,8 +221,8 @@ public class TimeZoneDetectorStrategy {
|
|||||||
QualifiedPhoneTimeZoneSuggestion scoredSuggestion =
|
QualifiedPhoneTimeZoneSuggestion scoredSuggestion =
|
||||||
new QualifiedPhoneTimeZoneSuggestion(suggestion, score);
|
new QualifiedPhoneTimeZoneSuggestion(suggestion, score);
|
||||||
|
|
||||||
// Store the suggestion against the correct phoneId.
|
// Store the suggestion against the correct slotIndex.
|
||||||
mSuggestionByPhoneId.put(suggestion.getPhoneId(), scoredSuggestion);
|
mSuggestionBySlotIndex.put(suggestion.getSlotIndex(), scoredSuggestion);
|
||||||
|
|
||||||
// Now perform auto time zone detection. The new suggestion may be used to modify the time
|
// Now perform auto time zone detection. The new suggestion may be used to modify the time
|
||||||
// zone setting.
|
// zone setting.
|
||||||
@@ -384,8 +384,9 @@ public class TimeZoneDetectorStrategy {
|
|||||||
// and find the best. Note that we deliberately do not look at age: the caller can
|
// and find the best. Note that we deliberately do not look at age: the caller can
|
||||||
// rate-limit so age is not a strong indicator of confidence. Instead, the callers are
|
// rate-limit so age is not a strong indicator of confidence. Instead, the callers are
|
||||||
// expected to withdraw suggestions they no longer have confidence in.
|
// expected to withdraw suggestions they no longer have confidence in.
|
||||||
for (int i = 0; i < mSuggestionByPhoneId.size(); i++) {
|
for (int i = 0; i < mSuggestionBySlotIndex.size(); i++) {
|
||||||
QualifiedPhoneTimeZoneSuggestion candidateSuggestion = mSuggestionByPhoneId.valueAt(i);
|
QualifiedPhoneTimeZoneSuggestion candidateSuggestion =
|
||||||
|
mSuggestionBySlotIndex.valueAt(i);
|
||||||
if (candidateSuggestion == null) {
|
if (candidateSuggestion == null) {
|
||||||
// Unexpected
|
// Unexpected
|
||||||
continue;
|
continue;
|
||||||
@@ -396,10 +397,10 @@ public class TimeZoneDetectorStrategy {
|
|||||||
} else if (candidateSuggestion.score > bestSuggestion.score) {
|
} else if (candidateSuggestion.score > bestSuggestion.score) {
|
||||||
bestSuggestion = candidateSuggestion;
|
bestSuggestion = candidateSuggestion;
|
||||||
} else if (candidateSuggestion.score == bestSuggestion.score) {
|
} else if (candidateSuggestion.score == bestSuggestion.score) {
|
||||||
// Tie! Use the suggestion with the lowest phoneId.
|
// Tie! Use the suggestion with the lowest slotIndex.
|
||||||
int candidatePhoneId = candidateSuggestion.suggestion.getPhoneId();
|
int candidateSlotIndex = candidateSuggestion.suggestion.getSlotIndex();
|
||||||
int bestPhoneId = bestSuggestion.suggestion.getPhoneId();
|
int bestSlotIndex = bestSuggestion.suggestion.getSlotIndex();
|
||||||
if (candidatePhoneId < bestPhoneId) {
|
if (candidateSlotIndex < bestSlotIndex) {
|
||||||
bestSuggestion = candidateSuggestion;
|
bestSuggestion = candidateSuggestion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -455,7 +456,7 @@ public class TimeZoneDetectorStrategy {
|
|||||||
|
|
||||||
ipw.println("Phone suggestion history:");
|
ipw.println("Phone suggestion history:");
|
||||||
ipw.increaseIndent(); // level 2
|
ipw.increaseIndent(); // level 2
|
||||||
mSuggestionByPhoneId.dump(ipw);
|
mSuggestionBySlotIndex.dump(ipw);
|
||||||
ipw.decreaseIndent(); // level 2
|
ipw.decreaseIndent(); // level 2
|
||||||
ipw.decreaseIndent(); // level 1
|
ipw.decreaseIndent(); // level 1
|
||||||
ipw.flush();
|
ipw.flush();
|
||||||
@@ -465,8 +466,8 @@ public class TimeZoneDetectorStrategy {
|
|||||||
* A method used to inspect strategy state during tests. Not intended for general use.
|
* A method used to inspect strategy state during tests. Not intended for general use.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public synchronized QualifiedPhoneTimeZoneSuggestion getLatestPhoneSuggestion(int phoneId) {
|
public synchronized QualifiedPhoneTimeZoneSuggestion getLatestPhoneSuggestion(int slotIndex) {
|
||||||
return mSuggestionByPhoneId.get(phoneId);
|
return mSuggestionBySlotIndex.get(slotIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user