Merge "More renames for API council" am: b03661f5d8
Change-Id: I1bd4db67106f8e885ca8449103af569ab100c361
This commit is contained in:
@@ -18,7 +18,7 @@ package android.app.timedetector;
|
|||||||
|
|
||||||
import android.app.timedetector.ManualTimeSuggestion;
|
import android.app.timedetector.ManualTimeSuggestion;
|
||||||
import android.app.timedetector.NetworkTimeSuggestion;
|
import android.app.timedetector.NetworkTimeSuggestion;
|
||||||
import android.app.timedetector.PhoneTimeSuggestion;
|
import android.app.timedetector.TelephonyTimeSuggestion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System private API to communicate with time detector service.
|
* System private API to communicate with time detector service.
|
||||||
@@ -34,7 +34,7 @@ import android.app.timedetector.PhoneTimeSuggestion;
|
|||||||
* {@hide}
|
* {@hide}
|
||||||
*/
|
*/
|
||||||
interface ITimeDetectorService {
|
interface ITimeDetectorService {
|
||||||
void suggestPhoneTime(in PhoneTimeSuggestion timeSuggestion);
|
|
||||||
void suggestManualTime(in ManualTimeSuggestion timeSuggestion);
|
void suggestManualTime(in ManualTimeSuggestion timeSuggestion);
|
||||||
void suggestNetworkTime(in NetworkTimeSuggestion timeSuggestion);
|
void suggestNetworkTime(in NetworkTimeSuggestion timeSuggestion);
|
||||||
|
void suggestTelephonyTime(in TelephonyTimeSuggestion timeSuggestion);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,4 +16,4 @@
|
|||||||
|
|
||||||
package android.app.timedetector;
|
package android.app.timedetector;
|
||||||
|
|
||||||
parcelable PhoneTimeSuggestion;
|
parcelable TelephonyTimeSuggestion;
|
||||||
@@ -50,17 +50,17 @@ import java.util.Objects;
|
|||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public final class PhoneTimeSuggestion implements Parcelable {
|
public final class TelephonyTimeSuggestion implements Parcelable {
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public static final @NonNull Parcelable.Creator<PhoneTimeSuggestion> CREATOR =
|
public static final @NonNull Parcelable.Creator<TelephonyTimeSuggestion> CREATOR =
|
||||||
new Parcelable.Creator<PhoneTimeSuggestion>() {
|
new Parcelable.Creator<TelephonyTimeSuggestion>() {
|
||||||
public PhoneTimeSuggestion createFromParcel(Parcel in) {
|
public TelephonyTimeSuggestion createFromParcel(Parcel in) {
|
||||||
return PhoneTimeSuggestion.createFromParcel(in);
|
return TelephonyTimeSuggestion.createFromParcel(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PhoneTimeSuggestion[] newArray(int size) {
|
public TelephonyTimeSuggestion[] newArray(int size) {
|
||||||
return new PhoneTimeSuggestion[size];
|
return new TelephonyTimeSuggestion[size];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -68,15 +68,15 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
@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 TelephonyTimeSuggestion(Builder builder) {
|
||||||
mSlotIndex = builder.mSlotIndex;
|
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 TelephonyTimeSuggestion createFromParcel(Parcel in) {
|
||||||
int slotIndex = in.readInt();
|
int slotIndex = in.readInt();
|
||||||
PhoneTimeSuggestion suggestion = new PhoneTimeSuggestion.Builder(slotIndex)
|
TelephonyTimeSuggestion suggestion = new TelephonyTimeSuggestion.Builder(slotIndex)
|
||||||
.setUtcTime(in.readParcelable(null /* classLoader */))
|
.setUtcTime(in.readParcelable(null /* classLoader */))
|
||||||
.build();
|
.build();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -102,7 +102,7 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Returns an identifier for the source of this suggestion.
|
* Returns an identifier for the source of this suggestion.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeSuggestion} for more information about {@code slotIndex}.
|
* <p>See {@link TelephonyTimeSuggestion} for more information about {@code slotIndex}.
|
||||||
*/
|
*/
|
||||||
public int getSlotIndex() {
|
public int getSlotIndex() {
|
||||||
return mSlotIndex;
|
return mSlotIndex;
|
||||||
@@ -111,7 +111,7 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Returns the suggested time or {@code null} if there isn't one.
|
* Returns the suggested time or {@code null} if there isn't one.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeSuggestion} for more information about {@code utcTime}.
|
* <p>See {@link TelephonyTimeSuggestion} for more information about {@code utcTime}.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public TimestampedValue<Long> getUtcTime() {
|
public TimestampedValue<Long> getUtcTime() {
|
||||||
@@ -121,7 +121,7 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Returns debug metadata for the suggestion.
|
* Returns debug metadata for the suggestion.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeSuggestion} for more information about {@code debugInfo}.
|
* <p>See {@link TelephonyTimeSuggestion} for more information about {@code debugInfo}.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public List<String> getDebugInfo() {
|
public List<String> getDebugInfo() {
|
||||||
@@ -132,7 +132,7 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Associates information with the instance that can be useful for debugging / logging.
|
* Associates information with the instance that can be useful for debugging / logging.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeSuggestion} for more information about {@code debugInfo}.
|
* <p>See {@link TelephonyTimeSuggestion} for more information about {@code debugInfo}.
|
||||||
*/
|
*/
|
||||||
public void addDebugInfo(@NonNull String debugInfo) {
|
public void addDebugInfo(@NonNull String debugInfo) {
|
||||||
if (mDebugInfo == null) {
|
if (mDebugInfo == null) {
|
||||||
@@ -144,7 +144,7 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Associates information with the instance that can be useful for debugging / logging.
|
* Associates information with the instance that can be useful for debugging / logging.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeSuggestion} for more information about {@code debugInfo}.
|
* <p>See {@link TelephonyTimeSuggestion} for more information about {@code debugInfo}.
|
||||||
*/
|
*/
|
||||||
public void addDebugInfo(@NonNull List<String> debugInfo) {
|
public void addDebugInfo(@NonNull List<String> debugInfo) {
|
||||||
if (mDebugInfo == null) {
|
if (mDebugInfo == null) {
|
||||||
@@ -161,7 +161,7 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
if (o == null || getClass() != o.getClass()) {
|
if (o == null || getClass() != o.getClass()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PhoneTimeSuggestion that = (PhoneTimeSuggestion) o;
|
TelephonyTimeSuggestion that = (TelephonyTimeSuggestion) o;
|
||||||
return mSlotIndex == that.mSlotIndex
|
return mSlotIndex == that.mSlotIndex
|
||||||
&& Objects.equals(mUtcTime, that.mUtcTime);
|
&& Objects.equals(mUtcTime, that.mUtcTime);
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "PhoneTimeSuggestion{"
|
return "TelephonyTimeSuggestion{"
|
||||||
+ "mSlotIndex='" + mSlotIndex + '\''
|
+ "mSlotIndex='" + mSlotIndex + '\''
|
||||||
+ ", mUtcTime=" + mUtcTime
|
+ ", mUtcTime=" + mUtcTime
|
||||||
+ ", mDebugInfo=" + mDebugInfo
|
+ ", mDebugInfo=" + mDebugInfo
|
||||||
@@ -181,7 +181,7 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds {@link PhoneTimeSuggestion} instances.
|
* Builds {@link TelephonyTimeSuggestion} instances.
|
||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@@ -193,7 +193,7 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Creates a builder with the specified {@code slotIndex}.
|
* Creates a builder with the specified {@code slotIndex}.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeSuggestion} for more information about {@code slotIndex}.
|
* <p>See {@link TelephonyTimeSuggestion} for more information about {@code slotIndex}.
|
||||||
*/
|
*/
|
||||||
public Builder(int slotIndex) {
|
public Builder(int slotIndex) {
|
||||||
mSlotIndex = slotIndex;
|
mSlotIndex = slotIndex;
|
||||||
@@ -202,7 +202,7 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Returns the builder for call chaining.
|
* Returns the builder for call chaining.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeSuggestion} for more information about {@code utcTime}.
|
* <p>See {@link TelephonyTimeSuggestion} for more information about {@code utcTime}.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public Builder setUtcTime(@Nullable TimestampedValue<Long> utcTime) {
|
public Builder setUtcTime(@Nullable TimestampedValue<Long> utcTime) {
|
||||||
@@ -218,7 +218,7 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Returns the builder for call chaining.
|
* Returns the builder for call chaining.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeSuggestion} for more information about {@code debugInfo}.
|
* <p>See {@link TelephonyTimeSuggestion} for more information about {@code debugInfo}.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public Builder addDebugInfo(@NonNull String debugInfo) {
|
public Builder addDebugInfo(@NonNull String debugInfo) {
|
||||||
@@ -229,10 +229,10 @@ public final class PhoneTimeSuggestion implements Parcelable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the {@link PhoneTimeSuggestion}. */
|
/** Returns the {@link TelephonyTimeSuggestion}. */
|
||||||
@NonNull
|
@NonNull
|
||||||
public PhoneTimeSuggestion build() {
|
public TelephonyTimeSuggestion build() {
|
||||||
return new PhoneTimeSuggestion(this);
|
return new TelephonyTimeSuggestion(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,12 +45,12 @@ public interface TimeDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Suggests the current phone-signal derived time to the detector. The detector may ignore the
|
* Suggests a telephony-signal derived time to the detector. The detector may ignore the signal
|
||||||
* signal if better signals are available such as those that come from more reliable sources or
|
* if better signals are available such as those that come from more reliable sources or were
|
||||||
* were determined more recently.
|
* determined more recently.
|
||||||
*/
|
*/
|
||||||
@RequiresPermission(android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE)
|
@RequiresPermission(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE)
|
||||||
void suggestPhoneTime(@NonNull PhoneTimeSuggestion timeSuggestion);
|
void suggestTelephonyTime(@NonNull TelephonyTimeSuggestion timeSuggestion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Suggests the user's manually entered current time to the detector.
|
* Suggests the user's manually entered current time to the detector.
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ public final class TimeDetectorImpl implements TimeDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void suggestPhoneTime(@NonNull PhoneTimeSuggestion timeSuggestion) {
|
public void suggestTelephonyTime(@NonNull TelephonyTimeSuggestion timeSuggestion) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "suggestPhoneTime called: " + timeSuggestion);
|
Log.d(TAG, "suggestTelephonyTime called: " + timeSuggestion);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
mITimeDetectorService.suggestPhoneTime(timeSuggestion);
|
mITimeDetectorService.suggestTelephonyTime(timeSuggestion);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
package android.app.timezonedetector;
|
package android.app.timezonedetector;
|
||||||
|
|
||||||
import android.app.timezonedetector.ManualTimeZoneSuggestion;
|
import android.app.timezonedetector.ManualTimeZoneSuggestion;
|
||||||
import android.app.timezonedetector.PhoneTimeZoneSuggestion;
|
import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System private API to communicate with time zone detector service.
|
* System private API to communicate with time zone detector service.
|
||||||
@@ -34,5 +34,5 @@ import android.app.timezonedetector.PhoneTimeZoneSuggestion;
|
|||||||
*/
|
*/
|
||||||
interface ITimeZoneDetectorService {
|
interface ITimeZoneDetectorService {
|
||||||
void suggestManualTimeZone(in ManualTimeZoneSuggestion timeZoneSuggestion);
|
void suggestManualTimeZone(in ManualTimeZoneSuggestion timeZoneSuggestion);
|
||||||
void suggestPhoneTimeZone(in PhoneTimeZoneSuggestion timeZoneSuggestion);
|
void suggestTelephonyTimeZone(in TelephonyTimeZoneSuggestion timeZoneSuggestion);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,4 +16,4 @@
|
|||||||
|
|
||||||
package android.app.timezonedetector;
|
package android.app.timezonedetector;
|
||||||
|
|
||||||
parcelable PhoneTimeZoneSuggestion;
|
parcelable TelephonyTimeZoneSuggestion;
|
||||||
@@ -56,18 +56,18 @@ import java.util.Objects;
|
|||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public final class PhoneTimeZoneSuggestion implements Parcelable {
|
public final class TelephonyTimeZoneSuggestion implements Parcelable {
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@NonNull
|
@NonNull
|
||||||
public static final Creator<PhoneTimeZoneSuggestion> CREATOR =
|
public static final Creator<TelephonyTimeZoneSuggestion> CREATOR =
|
||||||
new Creator<PhoneTimeZoneSuggestion>() {
|
new Creator<TelephonyTimeZoneSuggestion>() {
|
||||||
public PhoneTimeZoneSuggestion createFromParcel(Parcel in) {
|
public TelephonyTimeZoneSuggestion createFromParcel(Parcel in) {
|
||||||
return PhoneTimeZoneSuggestion.createFromParcel(in);
|
return TelephonyTimeZoneSuggestion.createFromParcel(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PhoneTimeZoneSuggestion[] newArray(int size) {
|
public TelephonyTimeZoneSuggestion[] newArray(int size) {
|
||||||
return new PhoneTimeZoneSuggestion[size];
|
return new TelephonyTimeZoneSuggestion[size];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
* the same {@code slotIndex}.
|
* the same {@code slotIndex}.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public static PhoneTimeZoneSuggestion createEmptySuggestion(
|
public static TelephonyTimeZoneSuggestion createEmptySuggestion(
|
||||||
int slotIndex, @NonNull String debugInfo) {
|
int slotIndex, @NonNull String debugInfo) {
|
||||||
return new Builder(slotIndex).addDebugInfo(debugInfo).build();
|
return new Builder(slotIndex).addDebugInfo(debugInfo).build();
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
@Quality private final int mQuality;
|
@Quality private final int mQuality;
|
||||||
@Nullable private List<String> mDebugInfo;
|
@Nullable private List<String> mDebugInfo;
|
||||||
|
|
||||||
private PhoneTimeZoneSuggestion(Builder builder) {
|
private TelephonyTimeZoneSuggestion(Builder builder) {
|
||||||
mSlotIndex = builder.mSlotIndex;
|
mSlotIndex = builder.mSlotIndex;
|
||||||
mZoneId = builder.mZoneId;
|
mZoneId = builder.mZoneId;
|
||||||
mMatchType = builder.mMatchType;
|
mMatchType = builder.mMatchType;
|
||||||
@@ -153,15 +153,16 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static PhoneTimeZoneSuggestion createFromParcel(Parcel in) {
|
private static TelephonyTimeZoneSuggestion createFromParcel(Parcel in) {
|
||||||
// Use the Builder so we get validation during build().
|
// Use the Builder so we get validation during build().
|
||||||
int slotIndex = in.readInt();
|
int slotIndex = in.readInt();
|
||||||
PhoneTimeZoneSuggestion suggestion = new Builder(slotIndex)
|
TelephonyTimeZoneSuggestion suggestion = new Builder(slotIndex)
|
||||||
.setZoneId(in.readString())
|
.setZoneId(in.readString())
|
||||||
.setMatchType(in.readInt())
|
.setMatchType(in.readInt())
|
||||||
.setQuality(in.readInt())
|
.setQuality(in.readInt())
|
||||||
.build();
|
.build();
|
||||||
List<String> debugInfo = in.readArrayList(PhoneTimeZoneSuggestion.class.getClassLoader());
|
List<String> debugInfo =
|
||||||
|
in.readArrayList(TelephonyTimeZoneSuggestion.class.getClassLoader());
|
||||||
if (debugInfo != null) {
|
if (debugInfo != null) {
|
||||||
suggestion.addDebugInfo(debugInfo);
|
suggestion.addDebugInfo(debugInfo);
|
||||||
}
|
}
|
||||||
@@ -185,7 +186,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Returns an identifier for the source of this suggestion.
|
* Returns an identifier for the source of this suggestion.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeZoneSuggestion} for more information about {@code slotIndex}.
|
* <p>See {@link TelephonyTimeZoneSuggestion} for more information about {@code slotIndex}.
|
||||||
*/
|
*/
|
||||||
public int getSlotIndex() {
|
public int getSlotIndex() {
|
||||||
return mSlotIndex;
|
return mSlotIndex;
|
||||||
@@ -195,7 +196,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
* Returns the suggested time zone Olson ID, e.g. "America/Los_Angeles". {@code null} means that
|
* Returns the suggested time zone Olson ID, e.g. "America/Los_Angeles". {@code null} means that
|
||||||
* the caller is no longer sure what the current time zone is.
|
* the caller is no longer sure what the current time zone is.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeZoneSuggestion} for more information about {@code zoneId}.
|
* <p>See {@link TelephonyTimeZoneSuggestion} for more information about {@code zoneId}.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getZoneId() {
|
public String getZoneId() {
|
||||||
@@ -206,7 +207,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
* Returns information about how the suggestion was determined which could be used to rank
|
* Returns information about how the suggestion was determined which could be used to rank
|
||||||
* suggestions when several are available from different sources.
|
* suggestions when several are available from different sources.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeZoneSuggestion} for more information about {@code matchType}.
|
* <p>See {@link TelephonyTimeZoneSuggestion} for more information about {@code matchType}.
|
||||||
*/
|
*/
|
||||||
@MatchType
|
@MatchType
|
||||||
public int getMatchType() {
|
public int getMatchType() {
|
||||||
@@ -216,7 +217,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Returns information about the likelihood of the suggested zone being correct.
|
* Returns information about the likelihood of the suggested zone being correct.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeZoneSuggestion} for more information about {@code quality}.
|
* <p>See {@link TelephonyTimeZoneSuggestion} for more information about {@code quality}.
|
||||||
*/
|
*/
|
||||||
@Quality
|
@Quality
|
||||||
public int getQuality() {
|
public int getQuality() {
|
||||||
@@ -226,7 +227,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Returns debug metadata for the suggestion.
|
* Returns debug metadata for the suggestion.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeZoneSuggestion} for more information about {@code debugInfo}.
|
* <p>See {@link TelephonyTimeZoneSuggestion} for more information about {@code debugInfo}.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public List<String> getDebugInfo() {
|
public List<String> getDebugInfo() {
|
||||||
@@ -237,7 +238,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Associates information with the instance that can be useful for debugging / logging.
|
* Associates information with the instance that can be useful for debugging / logging.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeZoneSuggestion} for more information about {@code debugInfo}.
|
* <p>See {@link TelephonyTimeZoneSuggestion} for more information about {@code debugInfo}.
|
||||||
*/
|
*/
|
||||||
public void addDebugInfo(@NonNull String debugInfo) {
|
public void addDebugInfo(@NonNull String debugInfo) {
|
||||||
if (mDebugInfo == null) {
|
if (mDebugInfo == null) {
|
||||||
@@ -249,7 +250,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Associates information with the instance that can be useful for debugging / logging.
|
* Associates information with the instance that can be useful for debugging / logging.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeZoneSuggestion} for more information about {@code debugInfo}.
|
* <p>See {@link TelephonyTimeZoneSuggestion} for more information about {@code debugInfo}.
|
||||||
*/
|
*/
|
||||||
public void addDebugInfo(@NonNull List<String> debugInfo) {
|
public void addDebugInfo(@NonNull List<String> debugInfo) {
|
||||||
if (mDebugInfo == null) {
|
if (mDebugInfo == null) {
|
||||||
@@ -266,7 +267,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
if (o == null || getClass() != o.getClass()) {
|
if (o == null || getClass() != o.getClass()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PhoneTimeZoneSuggestion that = (PhoneTimeZoneSuggestion) o;
|
TelephonyTimeZoneSuggestion that = (TelephonyTimeZoneSuggestion) o;
|
||||||
return mSlotIndex == that.mSlotIndex
|
return mSlotIndex == that.mSlotIndex
|
||||||
&& mMatchType == that.mMatchType
|
&& mMatchType == that.mMatchType
|
||||||
&& mQuality == that.mQuality
|
&& mQuality == that.mQuality
|
||||||
@@ -280,7 +281,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "PhoneTimeZoneSuggestion{"
|
return "TelephonyTimeZoneSuggestion{"
|
||||||
+ "mSlotIndex=" + mSlotIndex
|
+ "mSlotIndex=" + mSlotIndex
|
||||||
+ ", mZoneId='" + mZoneId + '\''
|
+ ", mZoneId='" + mZoneId + '\''
|
||||||
+ ", mMatchType=" + mMatchType
|
+ ", mMatchType=" + mMatchType
|
||||||
@@ -290,7 +291,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds {@link PhoneTimeZoneSuggestion} instances.
|
* Builds {@link TelephonyTimeZoneSuggestion} instances.
|
||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@@ -304,7 +305,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Creates a builder with the specified {@code slotIndex}.
|
* Creates a builder with the specified {@code slotIndex}.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeZoneSuggestion} for more information about {@code slotIndex}.
|
* <p>See {@link TelephonyTimeZoneSuggestion} for more information about {@code slotIndex}.
|
||||||
*/
|
*/
|
||||||
public Builder(int slotIndex) {
|
public Builder(int slotIndex) {
|
||||||
mSlotIndex = slotIndex;
|
mSlotIndex = slotIndex;
|
||||||
@@ -313,7 +314,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Returns the builder for call chaining.
|
* Returns the builder for call chaining.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeZoneSuggestion} for more information about {@code zoneId}.
|
* <p>See {@link TelephonyTimeZoneSuggestion} for more information about {@code zoneId}.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public Builder setZoneId(@Nullable String zoneId) {
|
public Builder setZoneId(@Nullable String zoneId) {
|
||||||
@@ -324,7 +325,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Returns the builder for call chaining.
|
* Returns the builder for call chaining.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeZoneSuggestion} for more information about {@code matchType}.
|
* <p>See {@link TelephonyTimeZoneSuggestion} for more information about {@code matchType}.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public Builder setMatchType(@MatchType int matchType) {
|
public Builder setMatchType(@MatchType int matchType) {
|
||||||
@@ -335,7 +336,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Returns the builder for call chaining.
|
* Returns the builder for call chaining.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeZoneSuggestion} for more information about {@code quality}.
|
* <p>See {@link TelephonyTimeZoneSuggestion} for more information about {@code quality}.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public Builder setQuality(@Quality int quality) {
|
public Builder setQuality(@Quality int quality) {
|
||||||
@@ -346,7 +347,7 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* Returns the builder for call chaining.
|
* Returns the builder for call chaining.
|
||||||
*
|
*
|
||||||
* <p>See {@link PhoneTimeZoneSuggestion} for more information about {@code debugInfo}.
|
* <p>See {@link TelephonyTimeZoneSuggestion} for more information about {@code debugInfo}.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public Builder addDebugInfo(@NonNull String debugInfo) {
|
public Builder addDebugInfo(@NonNull String debugInfo) {
|
||||||
@@ -384,11 +385,11 @@ public final class PhoneTimeZoneSuggestion implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the {@link PhoneTimeZoneSuggestion}. */
|
/** Returns the {@link TelephonyTimeZoneSuggestion}. */
|
||||||
@NonNull
|
@NonNull
|
||||||
public PhoneTimeZoneSuggestion build() {
|
public TelephonyTimeZoneSuggestion build() {
|
||||||
validate();
|
validate();
|
||||||
return new PhoneTimeZoneSuggestion(this);
|
return new TelephonyTimeZoneSuggestion(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,8 +47,8 @@ public interface TimeZoneDetector {
|
|||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@RequiresPermission(android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE)
|
@RequiresPermission(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE)
|
||||||
void suggestPhoneTimeZone(@NonNull PhoneTimeZoneSuggestion timeZoneSuggestion);
|
void suggestTelephonyTimeZone(@NonNull TelephonyTimeZoneSuggestion timeZoneSuggestion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Suggests the current time zone, determined for the user's manually information, to the
|
* Suggests the current time zone, determined for the user's manually information, to the
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ public final class TimeZoneDetectorImpl implements TimeZoneDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void suggestPhoneTimeZone(@NonNull PhoneTimeZoneSuggestion timeZoneSuggestion) {
|
public void suggestTelephonyTimeZone(@NonNull TelephonyTimeZoneSuggestion timeZoneSuggestion) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "suggestPhoneTimeZone called: " + timeZoneSuggestion);
|
Log.d(TAG, "suggestTelephonyTimeZone called: " + timeZoneSuggestion);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
mITimeZoneDetectorService.suggestPhoneTimeZone(timeZoneSuggestion);
|
mITimeZoneDetectorService.suggestTelephonyTimeZone(timeZoneSuggestion);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2563,7 +2563,7 @@
|
|||||||
<p>Not for use by third-party applications.
|
<p>Not for use by third-party applications.
|
||||||
@hide
|
@hide
|
||||||
-->
|
-->
|
||||||
<permission android:name="android.permission.SUGGEST_PHONE_TIME_AND_ZONE"
|
<permission android:name="android.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE"
|
||||||
android:protectionLevel="signature|telephony" />
|
android:protectionLevel="signature|telephony" />
|
||||||
|
|
||||||
<!-- Allows applications like settings to suggest the user's manually chosen time / time zone.
|
<!-- Allows applications like settings to suggest the user's manually chosen time / time zone.
|
||||||
|
|||||||
@@ -26,44 +26,45 @@ import android.os.TimestampedValue;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class PhoneTimeSuggestionTest {
|
public class TelephonyTimeSuggestionTest {
|
||||||
private static final int SLOT_INDEX = 99999;
|
private static final int SLOT_INDEX = 99999;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
PhoneTimeSuggestion.Builder builder1 = new PhoneTimeSuggestion.Builder(SLOT_INDEX);
|
TelephonyTimeSuggestion.Builder builder1 = new TelephonyTimeSuggestion.Builder(SLOT_INDEX);
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion one = builder1.build();
|
TelephonyTimeSuggestion one = builder1.build();
|
||||||
assertEquals(one, one);
|
assertEquals(one, one);
|
||||||
}
|
}
|
||||||
|
|
||||||
PhoneTimeSuggestion.Builder builder2 = new PhoneTimeSuggestion.Builder(SLOT_INDEX);
|
TelephonyTimeSuggestion.Builder builder2 = new TelephonyTimeSuggestion.Builder(SLOT_INDEX);
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion one = builder1.build();
|
TelephonyTimeSuggestion one = builder1.build();
|
||||||
PhoneTimeSuggestion two = builder2.build();
|
TelephonyTimeSuggestion two = builder2.build();
|
||||||
assertEquals(one, two);
|
assertEquals(one, two);
|
||||||
assertEquals(two, one);
|
assertEquals(two, one);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder1.setUtcTime(new TimestampedValue<>(1111L, 2222L));
|
builder1.setUtcTime(new TimestampedValue<>(1111L, 2222L));
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion one = builder1.build();
|
TelephonyTimeSuggestion one = builder1.build();
|
||||||
assertEquals(one, one);
|
assertEquals(one, one);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder2.setUtcTime(new TimestampedValue<>(1111L, 2222L));
|
builder2.setUtcTime(new TimestampedValue<>(1111L, 2222L));
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion one = builder1.build();
|
TelephonyTimeSuggestion one = builder1.build();
|
||||||
PhoneTimeSuggestion two = builder2.build();
|
TelephonyTimeSuggestion two = builder2.build();
|
||||||
assertEquals(one, two);
|
assertEquals(one, two);
|
||||||
assertEquals(two, one);
|
assertEquals(two, one);
|
||||||
}
|
}
|
||||||
|
|
||||||
PhoneTimeSuggestion.Builder builder3 = new PhoneTimeSuggestion.Builder(SLOT_INDEX + 1);
|
TelephonyTimeSuggestion.Builder builder3 =
|
||||||
|
new TelephonyTimeSuggestion.Builder(SLOT_INDEX + 1);
|
||||||
builder3.setUtcTime(new TimestampedValue<>(1111L, 2222L));
|
builder3.setUtcTime(new TimestampedValue<>(1111L, 2222L));
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion one = builder1.build();
|
TelephonyTimeSuggestion one = builder1.build();
|
||||||
PhoneTimeSuggestion three = builder3.build();
|
TelephonyTimeSuggestion three = builder3.build();
|
||||||
assertNotEquals(one, three);
|
assertNotEquals(one, three);
|
||||||
assertNotEquals(three, one);
|
assertNotEquals(three, one);
|
||||||
}
|
}
|
||||||
@@ -72,15 +73,15 @@ public class PhoneTimeSuggestionTest {
|
|||||||
builder1.addDebugInfo("Debug info 1");
|
builder1.addDebugInfo("Debug info 1");
|
||||||
builder2.addDebugInfo("Debug info 2");
|
builder2.addDebugInfo("Debug info 2");
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion one = builder1.build();
|
TelephonyTimeSuggestion one = builder1.build();
|
||||||
PhoneTimeSuggestion two = builder2.build();
|
TelephonyTimeSuggestion two = builder2.build();
|
||||||
assertEquals(one, two);
|
assertEquals(one, two);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParcelable() {
|
public void testParcelable() {
|
||||||
PhoneTimeSuggestion.Builder builder = new PhoneTimeSuggestion.Builder(SLOT_INDEX);
|
TelephonyTimeSuggestion.Builder builder = new TelephonyTimeSuggestion.Builder(SLOT_INDEX);
|
||||||
assertRoundTripParcelable(builder.build());
|
assertRoundTripParcelable(builder.build());
|
||||||
|
|
||||||
builder.setUtcTime(new TimestampedValue<>(1111L, 2222L));
|
builder.setUtcTime(new TimestampedValue<>(1111L, 2222L));
|
||||||
@@ -88,9 +89,9 @@ public class PhoneTimeSuggestionTest {
|
|||||||
|
|
||||||
// DebugInfo should also be stored (but is not checked by equals()
|
// DebugInfo should also be stored (but is not checked by equals()
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion suggestion1 = builder.build();
|
TelephonyTimeSuggestion suggestion1 = builder.build();
|
||||||
builder.addDebugInfo("This is debug info");
|
builder.addDebugInfo("This is debug info");
|
||||||
PhoneTimeSuggestion rtSuggestion1 = roundTripParcelable(suggestion1);
|
TelephonyTimeSuggestion rtSuggestion1 = roundTripParcelable(suggestion1);
|
||||||
assertEquals(suggestion1.getDebugInfo(), rtSuggestion1.getDebugInfo());
|
assertEquals(suggestion1.getDebugInfo(), rtSuggestion1.getDebugInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2019 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 android.app.timezonedetector;
|
|
||||||
|
|
||||||
import static android.app.timezonedetector.ParcelableTestSupport.assertRoundTripParcelable;
|
|
||||||
import static android.app.timezonedetector.ParcelableTestSupport.roundTripParcelable;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class PhoneTimeZoneSuggestionTest {
|
|
||||||
private static final int SLOT_INDEX = 99999;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testEquals() {
|
|
||||||
PhoneTimeZoneSuggestion.Builder builder1 = new PhoneTimeZoneSuggestion.Builder(SLOT_INDEX);
|
|
||||||
{
|
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
|
||||||
assertEquals(one, one);
|
|
||||||
}
|
|
||||||
|
|
||||||
PhoneTimeZoneSuggestion.Builder builder2 = new PhoneTimeZoneSuggestion.Builder(SLOT_INDEX);
|
|
||||||
{
|
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
|
||||||
PhoneTimeZoneSuggestion two = builder2.build();
|
|
||||||
assertEquals(one, two);
|
|
||||||
assertEquals(two, one);
|
|
||||||
}
|
|
||||||
|
|
||||||
PhoneTimeZoneSuggestion.Builder builder3 =
|
|
||||||
new PhoneTimeZoneSuggestion.Builder(SLOT_INDEX + 1);
|
|
||||||
{
|
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
|
||||||
PhoneTimeZoneSuggestion three = builder3.build();
|
|
||||||
assertNotEquals(one, three);
|
|
||||||
assertNotEquals(three, one);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder1.setZoneId("Europe/London");
|
|
||||||
builder1.setMatchType(PhoneTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY);
|
|
||||||
builder1.setQuality(PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
|
|
||||||
{
|
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
|
||||||
PhoneTimeZoneSuggestion two = builder2.build();
|
|
||||||
assertNotEquals(one, two);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder2.setZoneId("Europe/Paris");
|
|
||||||
builder2.setMatchType(PhoneTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY);
|
|
||||||
builder2.setQuality(PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
|
|
||||||
{
|
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
|
||||||
PhoneTimeZoneSuggestion two = builder2.build();
|
|
||||||
assertNotEquals(one, two);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder1.setZoneId("Europe/Paris");
|
|
||||||
{
|
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
|
||||||
PhoneTimeZoneSuggestion two = builder2.build();
|
|
||||||
assertEquals(one, two);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder1.setMatchType(PhoneTimeZoneSuggestion.MATCH_TYPE_EMULATOR_ZONE_ID);
|
|
||||||
builder2.setMatchType(PhoneTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY);
|
|
||||||
{
|
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
|
||||||
PhoneTimeZoneSuggestion two = builder2.build();
|
|
||||||
assertNotEquals(one, two);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder1.setMatchType(PhoneTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY);
|
|
||||||
{
|
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
|
||||||
PhoneTimeZoneSuggestion two = builder2.build();
|
|
||||||
assertEquals(one, two);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder1.setQuality(PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
|
|
||||||
builder2.setQuality(PhoneTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS);
|
|
||||||
{
|
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
|
||||||
PhoneTimeZoneSuggestion two = builder2.build();
|
|
||||||
assertNotEquals(one, two);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder1.setQuality(PhoneTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS);
|
|
||||||
{
|
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
|
||||||
PhoneTimeZoneSuggestion two = builder2.build();
|
|
||||||
assertEquals(one, two);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DebugInfo must not be considered in equals().
|
|
||||||
{
|
|
||||||
PhoneTimeZoneSuggestion one = builder1.build();
|
|
||||||
PhoneTimeZoneSuggestion two = builder2.build();
|
|
||||||
one.addDebugInfo("Debug info 1");
|
|
||||||
two.addDebugInfo("Debug info 2");
|
|
||||||
assertEquals(one, two);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = RuntimeException.class)
|
|
||||||
public void testBuilderValidates_emptyZone_badMatchType() {
|
|
||||||
PhoneTimeZoneSuggestion.Builder builder = new PhoneTimeZoneSuggestion.Builder(SLOT_INDEX);
|
|
||||||
// No zone ID, so match type should be left unset.
|
|
||||||
builder.setMatchType(PhoneTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET);
|
|
||||||
builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = RuntimeException.class)
|
|
||||||
public void testBuilderValidates_zoneSet_badMatchType() {
|
|
||||||
PhoneTimeZoneSuggestion.Builder builder = new PhoneTimeZoneSuggestion.Builder(SLOT_INDEX);
|
|
||||||
builder.setZoneId("Europe/London");
|
|
||||||
builder.setQuality(PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
|
|
||||||
builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testParcelable() {
|
|
||||||
PhoneTimeZoneSuggestion.Builder builder = new PhoneTimeZoneSuggestion.Builder(SLOT_INDEX);
|
|
||||||
assertRoundTripParcelable(builder.build());
|
|
||||||
|
|
||||||
builder.setZoneId("Europe/London");
|
|
||||||
builder.setMatchType(PhoneTimeZoneSuggestion.MATCH_TYPE_EMULATOR_ZONE_ID);
|
|
||||||
builder.setQuality(PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
|
|
||||||
PhoneTimeZoneSuggestion suggestion1 = builder.build();
|
|
||||||
assertRoundTripParcelable(suggestion1);
|
|
||||||
|
|
||||||
// DebugInfo should also be stored (but is not checked by equals()
|
|
||||||
String debugString = "This is debug info";
|
|
||||||
suggestion1.addDebugInfo(debugString);
|
|
||||||
PhoneTimeZoneSuggestion suggestion1_2 = roundTripParcelable(suggestion1);
|
|
||||||
assertEquals(suggestion1, suggestion1_2);
|
|
||||||
assertTrue(suggestion1_2.getDebugInfo().contains(debugString));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 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 android.app.timezonedetector;
|
||||||
|
|
||||||
|
import static android.app.timezonedetector.ParcelableTestSupport.assertRoundTripParcelable;
|
||||||
|
import static android.app.timezonedetector.ParcelableTestSupport.roundTripParcelable;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TelephonyTimeZoneSuggestionTest {
|
||||||
|
private static final int SLOT_INDEX = 99999;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEquals() {
|
||||||
|
TelephonyTimeZoneSuggestion.Builder builder1 =
|
||||||
|
new TelephonyTimeZoneSuggestion.Builder(SLOT_INDEX);
|
||||||
|
{
|
||||||
|
TelephonyTimeZoneSuggestion one = builder1.build();
|
||||||
|
assertEquals(one, one);
|
||||||
|
}
|
||||||
|
|
||||||
|
TelephonyTimeZoneSuggestion.Builder builder2 =
|
||||||
|
new TelephonyTimeZoneSuggestion.Builder(SLOT_INDEX);
|
||||||
|
{
|
||||||
|
TelephonyTimeZoneSuggestion one = builder1.build();
|
||||||
|
TelephonyTimeZoneSuggestion two = builder2.build();
|
||||||
|
assertEquals(one, two);
|
||||||
|
assertEquals(two, one);
|
||||||
|
}
|
||||||
|
|
||||||
|
TelephonyTimeZoneSuggestion.Builder builder3 =
|
||||||
|
new TelephonyTimeZoneSuggestion.Builder(SLOT_INDEX + 1);
|
||||||
|
{
|
||||||
|
TelephonyTimeZoneSuggestion one = builder1.build();
|
||||||
|
TelephonyTimeZoneSuggestion three = builder3.build();
|
||||||
|
assertNotEquals(one, three);
|
||||||
|
assertNotEquals(three, one);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder1.setZoneId("Europe/London");
|
||||||
|
builder1.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY);
|
||||||
|
builder1.setQuality(TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
|
||||||
|
{
|
||||||
|
TelephonyTimeZoneSuggestion one = builder1.build();
|
||||||
|
TelephonyTimeZoneSuggestion two = builder2.build();
|
||||||
|
assertNotEquals(one, two);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder2.setZoneId("Europe/Paris");
|
||||||
|
builder2.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY);
|
||||||
|
builder2.setQuality(TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
|
||||||
|
{
|
||||||
|
TelephonyTimeZoneSuggestion one = builder1.build();
|
||||||
|
TelephonyTimeZoneSuggestion two = builder2.build();
|
||||||
|
assertNotEquals(one, two);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder1.setZoneId("Europe/Paris");
|
||||||
|
{
|
||||||
|
TelephonyTimeZoneSuggestion one = builder1.build();
|
||||||
|
TelephonyTimeZoneSuggestion two = builder2.build();
|
||||||
|
assertEquals(one, two);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder1.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_EMULATOR_ZONE_ID);
|
||||||
|
builder2.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY);
|
||||||
|
{
|
||||||
|
TelephonyTimeZoneSuggestion one = builder1.build();
|
||||||
|
TelephonyTimeZoneSuggestion two = builder2.build();
|
||||||
|
assertNotEquals(one, two);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder1.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY);
|
||||||
|
{
|
||||||
|
TelephonyTimeZoneSuggestion one = builder1.build();
|
||||||
|
TelephonyTimeZoneSuggestion two = builder2.build();
|
||||||
|
assertEquals(one, two);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder1.setQuality(TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
|
||||||
|
builder2.setQuality(
|
||||||
|
TelephonyTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS);
|
||||||
|
{
|
||||||
|
TelephonyTimeZoneSuggestion one = builder1.build();
|
||||||
|
TelephonyTimeZoneSuggestion two = builder2.build();
|
||||||
|
assertNotEquals(one, two);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder1.setQuality(
|
||||||
|
TelephonyTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS);
|
||||||
|
{
|
||||||
|
TelephonyTimeZoneSuggestion one = builder1.build();
|
||||||
|
TelephonyTimeZoneSuggestion two = builder2.build();
|
||||||
|
assertEquals(one, two);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DebugInfo must not be considered in equals().
|
||||||
|
{
|
||||||
|
TelephonyTimeZoneSuggestion one = builder1.build();
|
||||||
|
TelephonyTimeZoneSuggestion two = builder2.build();
|
||||||
|
one.addDebugInfo("Debug info 1");
|
||||||
|
two.addDebugInfo("Debug info 2");
|
||||||
|
assertEquals(one, two);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = RuntimeException.class)
|
||||||
|
public void testBuilderValidates_emptyZone_badMatchType() {
|
||||||
|
TelephonyTimeZoneSuggestion.Builder builder =
|
||||||
|
new TelephonyTimeZoneSuggestion.Builder(SLOT_INDEX);
|
||||||
|
// No zone ID, so match type should be left unset.
|
||||||
|
builder.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET);
|
||||||
|
builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = RuntimeException.class)
|
||||||
|
public void testBuilderValidates_zoneSet_badMatchType() {
|
||||||
|
TelephonyTimeZoneSuggestion.Builder builder =
|
||||||
|
new TelephonyTimeZoneSuggestion.Builder(SLOT_INDEX);
|
||||||
|
builder.setZoneId("Europe/London");
|
||||||
|
builder.setQuality(TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
|
||||||
|
builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParcelable() {
|
||||||
|
TelephonyTimeZoneSuggestion.Builder builder =
|
||||||
|
new TelephonyTimeZoneSuggestion.Builder(SLOT_INDEX);
|
||||||
|
assertRoundTripParcelable(builder.build());
|
||||||
|
|
||||||
|
builder.setZoneId("Europe/London");
|
||||||
|
builder.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_EMULATOR_ZONE_ID);
|
||||||
|
builder.setQuality(TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE);
|
||||||
|
TelephonyTimeZoneSuggestion suggestion1 = builder.build();
|
||||||
|
assertRoundTripParcelable(suggestion1);
|
||||||
|
|
||||||
|
// DebugInfo should also be stored (but is not checked by equals()
|
||||||
|
String debugString = "This is debug info";
|
||||||
|
suggestion1.addDebugInfo(debugString);
|
||||||
|
TelephonyTimeZoneSuggestion suggestion1_2 = roundTripParcelable(suggestion1);
|
||||||
|
assertEquals(suggestion1, suggestion1_2);
|
||||||
|
assertTrue(suggestion1_2.getDebugInfo().contains(debugString));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -159,7 +159,7 @@ applications that come with the platform
|
|||||||
<permission name="android.permission.START_ACTIVITIES_FROM_BACKGROUND"/>
|
<permission name="android.permission.START_ACTIVITIES_FROM_BACKGROUND"/>
|
||||||
<permission name="android.permission.STATUS_BAR"/>
|
<permission name="android.permission.STATUS_BAR"/>
|
||||||
<permission name="android.permission.STOP_APP_SWITCHES"/>
|
<permission name="android.permission.STOP_APP_SWITCHES"/>
|
||||||
<permission name="android.permission.SUGGEST_PHONE_TIME_AND_ZONE"/>
|
<permission name="android.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE"/>
|
||||||
<permission name="android.permission.UPDATE_APP_OPS_STATS"/>
|
<permission name="android.permission.UPDATE_APP_OPS_STATS"/>
|
||||||
<permission name="android.permission.UPDATE_DEVICE_STATS"/>
|
<permission name="android.permission.UPDATE_DEVICE_STATS"/>
|
||||||
<permission name="android.permission.UPDATE_LOCK"/>
|
<permission name="android.permission.UPDATE_LOCK"/>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import android.annotation.Nullable;
|
|||||||
import android.app.timedetector.ITimeDetectorService;
|
import android.app.timedetector.ITimeDetectorService;
|
||||||
import android.app.timedetector.ManualTimeSuggestion;
|
import android.app.timedetector.ManualTimeSuggestion;
|
||||||
import android.app.timedetector.NetworkTimeSuggestion;
|
import android.app.timedetector.NetworkTimeSuggestion;
|
||||||
import android.app.timedetector.PhoneTimeSuggestion;
|
import android.app.timedetector.TelephonyTimeSuggestion;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
@@ -94,11 +94,11 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void suggestPhoneTime(@NonNull PhoneTimeSuggestion timeSignal) {
|
public void suggestTelephonyTime(@NonNull TelephonyTimeSuggestion timeSignal) {
|
||||||
enforceSuggestPhoneTimePermission();
|
enforceSuggestTelephonyTimePermission();
|
||||||
Objects.requireNonNull(timeSignal);
|
Objects.requireNonNull(timeSignal);
|
||||||
|
|
||||||
mHandler.post(() -> mTimeDetectorStrategy.suggestPhoneTime(timeSignal));
|
mHandler.post(() -> mTimeDetectorStrategy.suggestTelephonyTime(timeSignal));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -131,10 +131,10 @@ public final class TimeDetectorService extends ITimeDetectorService.Stub {
|
|||||||
mTimeDetectorStrategy.dump(pw, args);
|
mTimeDetectorStrategy.dump(pw, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enforceSuggestPhoneTimePermission() {
|
private void enforceSuggestTelephonyTimePermission() {
|
||||||
mContext.enforceCallingPermission(
|
mContext.enforceCallingPermission(
|
||||||
android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE,
|
android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE,
|
||||||
"suggest phone time and time zone");
|
"suggest telephony time and time zone");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enforceSuggestManualTimePermission() {
|
private void enforceSuggestManualTimePermission() {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import android.annotation.NonNull;
|
|||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.timedetector.ManualTimeSuggestion;
|
import android.app.timedetector.ManualTimeSuggestion;
|
||||||
import android.app.timedetector.NetworkTimeSuggestion;
|
import android.app.timedetector.NetworkTimeSuggestion;
|
||||||
import android.app.timedetector.PhoneTimeSuggestion;
|
import android.app.timedetector.TelephonyTimeSuggestion;
|
||||||
import android.os.TimestampedValue;
|
import android.os.TimestampedValue;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@@ -78,7 +78,7 @@ public interface TimeDetectorStrategy {
|
|||||||
void initialize(@NonNull Callback callback);
|
void initialize(@NonNull Callback callback);
|
||||||
|
|
||||||
/** Process the suggested time from telephony sources. */
|
/** Process the suggested time from telephony sources. */
|
||||||
void suggestPhoneTime(@NonNull PhoneTimeSuggestion timeSuggestion);
|
void suggestTelephonyTime(@NonNull TelephonyTimeSuggestion timeSuggestion);
|
||||||
|
|
||||||
/** Process the suggested manually entered time. */
|
/** Process the suggested manually entered time. */
|
||||||
void suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion);
|
void suggestManualTime(@NonNull ManualTimeSuggestion timeSuggestion);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import android.annotation.Nullable;
|
|||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.timedetector.ManualTimeSuggestion;
|
import android.app.timedetector.ManualTimeSuggestion;
|
||||||
import android.app.timedetector.NetworkTimeSuggestion;
|
import android.app.timedetector.NetworkTimeSuggestion;
|
||||||
import android.app.timedetector.PhoneTimeSuggestion;
|
import android.app.timedetector.TelephonyTimeSuggestion;
|
||||||
import android.os.TimestampedValue;
|
import android.os.TimestampedValue;
|
||||||
import android.util.LocalLog;
|
import android.util.LocalLog;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
@@ -38,9 +38,9 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of {@link TimeDetectorStrategy} that passes phone and manual suggestions to
|
* An implementation of {@link TimeDetectorStrategy} that passes telephony and manual suggestions to
|
||||||
* {@link AlarmManager}. When there are multiple phone sources, the one with the lowest ID is used
|
* {@link AlarmManager}. When there are multiple telephony sources, the one with the lowest ID is
|
||||||
* unless the data becomes too stale.
|
* used unless the data becomes too stale.
|
||||||
*
|
*
|
||||||
* <p>Most public methods are marked synchronized to ensure thread safety around internal state.
|
* <p>Most public methods are marked synchronized to ensure thread safety around internal state.
|
||||||
*/
|
*/
|
||||||
@@ -50,23 +50,26 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
private static final String LOG_TAG = "SimpleTimeDetectorStrategy";
|
private static final String LOG_TAG = "SimpleTimeDetectorStrategy";
|
||||||
|
|
||||||
/** A score value used to indicate "no score", either due to validation failure or age. */
|
/** A score value used to indicate "no score", either due to validation failure or age. */
|
||||||
private static final int PHONE_INVALID_SCORE = -1;
|
private static final int TELEPHONY_INVALID_SCORE = -1;
|
||||||
/** The number of buckets phone suggestions can be put in by age. */
|
/** The number of buckets telephony suggestions can be put in by age. */
|
||||||
private static final int PHONE_BUCKET_COUNT = 24;
|
private static final int TELEPHONY_BUCKET_COUNT = 24;
|
||||||
/** Each bucket is this size. All buckets are equally sized. */
|
/** Each bucket is this size. All buckets are equally sized. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int PHONE_BUCKET_SIZE_MILLIS = 60 * 60 * 1000;
|
static final int TELEPHONY_BUCKET_SIZE_MILLIS = 60 * 60 * 1000;
|
||||||
/** Phone and network suggestions older than this value are considered too old to be used. */
|
/**
|
||||||
|
* Telephony and network suggestions older than this value are considered too old to be used.
|
||||||
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final long MAX_UTC_TIME_AGE_MILLIS = PHONE_BUCKET_COUNT * PHONE_BUCKET_SIZE_MILLIS;
|
static final long MAX_UTC_TIME_AGE_MILLIS =
|
||||||
|
TELEPHONY_BUCKET_COUNT * TELEPHONY_BUCKET_SIZE_MILLIS;
|
||||||
|
|
||||||
@IntDef({ ORIGIN_PHONE, ORIGIN_MANUAL, ORIGIN_NETWORK })
|
@IntDef({ ORIGIN_TELEPHONY, ORIGIN_MANUAL, ORIGIN_NETWORK })
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface Origin {}
|
public @interface Origin {}
|
||||||
|
|
||||||
/** Used when a time value originated from a telephony signal. */
|
/** Used when a time value originated from a telephony signal. */
|
||||||
@Origin
|
@Origin
|
||||||
private static final int ORIGIN_PHONE = 1;
|
private static final int ORIGIN_TELEPHONY = 1;
|
||||||
|
|
||||||
/** Used when a time value originated from a user / manual settings. */
|
/** Used when a time value originated from a user / manual settings. */
|
||||||
@Origin
|
@Origin
|
||||||
@@ -83,7 +86,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
*/
|
*/
|
||||||
private static final long SYSTEM_CLOCK_PARANOIA_THRESHOLD_MILLIS = 2 * 1000;
|
private static final long SYSTEM_CLOCK_PARANOIA_THRESHOLD_MILLIS = 2 * 1000;
|
||||||
|
|
||||||
/** The number of previous phone suggestions to keep for each ID (for use during debugging). */
|
/**
|
||||||
|
* The number of previous telephony suggestions to keep for each ID (for use during debugging).
|
||||||
|
*/
|
||||||
private static final int KEEP_SUGGESTION_HISTORY_SIZE = 30;
|
private static final int KEEP_SUGGESTION_HISTORY_SIZE = 30;
|
||||||
|
|
||||||
// A log for changes made to the system clock and why.
|
// A log for changes made to the system clock and why.
|
||||||
@@ -106,7 +111,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
* stable.
|
* stable.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
private final ArrayMapWithHistory<Integer, PhoneTimeSuggestion> mSuggestionBySlotIndex =
|
private final ArrayMapWithHistory<Integer, TelephonyTimeSuggestion> mSuggestionBySlotIndex =
|
||||||
new ArrayMapWithHistory<>(KEEP_SUGGESTION_HISTORY_SIZE);
|
new ArrayMapWithHistory<>(KEEP_SUGGESTION_HISTORY_SIZE);
|
||||||
|
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
@@ -144,7 +149,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void suggestPhoneTime(@NonNull PhoneTimeSuggestion timeSuggestion) {
|
public synchronized void suggestTelephonyTime(@NonNull TelephonyTimeSuggestion timeSuggestion) {
|
||||||
// Empty time suggestion means that telephony network connectivity has been lost.
|
// Empty time suggestion means that telephony network connectivity has been lost.
|
||||||
// The passage of time is relentless, and we don't expect our users to use a time machine,
|
// The passage of time is relentless, and we don't expect our users to use a time machine,
|
||||||
// so we can continue relying on previous suggestions when we lose connectivity. This is
|
// so we can continue relying on previous suggestions when we lose connectivity. This is
|
||||||
@@ -157,13 +162,13 @@ 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
|
||||||
// slotIndex.
|
// slotIndex.
|
||||||
if (!validateAndStorePhoneSuggestion(timeSuggestion)) {
|
if (!validateAndStoreTelephonySuggestion(timeSuggestion)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now perform auto time detection. The new suggestion may be used to modify the system
|
// Now perform auto time detection. The new suggestion may be used to modify the system
|
||||||
// clock.
|
// clock.
|
||||||
String reason = "New phone time suggested. timeSuggestion=" + timeSuggestion;
|
String reason = "New telephony time suggested. timeSuggestion=" + timeSuggestion;
|
||||||
doAutoTimeDetection(reason);
|
doAutoTimeDetection(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +206,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
mTimeChangesLog.dump(ipw);
|
mTimeChangesLog.dump(ipw);
|
||||||
ipw.decreaseIndent(); // level 2
|
ipw.decreaseIndent(); // level 2
|
||||||
|
|
||||||
ipw.println("Phone suggestion history:");
|
ipw.println("Telephony suggestion history:");
|
||||||
ipw.increaseIndent(); // level 2
|
ipw.increaseIndent(); // level 2
|
||||||
mSuggestionBySlotIndex.dump(ipw);
|
mSuggestionBySlotIndex.dump(ipw);
|
||||||
ipw.decreaseIndent(); // level 2
|
ipw.decreaseIndent(); // level 2
|
||||||
@@ -216,7 +221,8 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
private boolean validateAndStorePhoneSuggestion(@NonNull PhoneTimeSuggestion suggestion) {
|
private boolean validateAndStoreTelephonySuggestion(
|
||||||
|
@NonNull TelephonyTimeSuggestion suggestion) {
|
||||||
TimestampedValue<Long> newUtcTime = suggestion.getUtcTime();
|
TimestampedValue<Long> newUtcTime = suggestion.getUtcTime();
|
||||||
if (!validateSuggestionTime(newUtcTime, suggestion)) {
|
if (!validateSuggestionTime(newUtcTime, suggestion)) {
|
||||||
// There's probably nothing useful we can do: elsewhere we assume that reference
|
// There's probably nothing useful we can do: elsewhere we assume that reference
|
||||||
@@ -225,7 +231,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int slotIndex = suggestion.getSlotIndex();
|
int slotIndex = suggestion.getSlotIndex();
|
||||||
PhoneTimeSuggestion previousSuggestion = mSuggestionBySlotIndex.get(slotIndex);
|
TelephonyTimeSuggestion 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
|
||||||
@@ -241,7 +247,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
newUtcTime, previousSuggestion.getUtcTime());
|
newUtcTime, previousSuggestion.getUtcTime());
|
||||||
if (referenceTimeDifference < 0) {
|
if (referenceTimeDifference < 0) {
|
||||||
// The reference time is before the previously received suggestion. Ignore it.
|
// The reference time is before the previously received suggestion. Ignore it.
|
||||||
Slog.w(LOG_TAG, "Out of order phone suggestion received."
|
Slog.w(LOG_TAG, "Out of order telephony suggestion received."
|
||||||
+ " referenceTimeDifference=" + referenceTimeDifference
|
+ " referenceTimeDifference=" + referenceTimeDifference
|
||||||
+ " previousSuggestion=" + previousSuggestion
|
+ " previousSuggestion=" + previousSuggestion
|
||||||
+ " suggestion=" + suggestion);
|
+ " suggestion=" + suggestion);
|
||||||
@@ -282,18 +288,18 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
|
|
||||||
// Android devices currently prioritize any telephony over network signals. There are
|
// Android devices currently prioritize any telephony over network signals. There are
|
||||||
// carrier compliance tests that would need to be changed before we could ignore NITZ or
|
// carrier compliance tests that would need to be changed before we could ignore NITZ or
|
||||||
// prefer NTP generally. This check is cheap on devices without phone hardware.
|
// prefer NTP generally. This check is cheap on devices without telephony hardware.
|
||||||
PhoneTimeSuggestion bestPhoneSuggestion = findBestPhoneSuggestion();
|
TelephonyTimeSuggestion bestTelephonySuggestion = findBestTelephonySuggestion();
|
||||||
if (bestPhoneSuggestion != null) {
|
if (bestTelephonySuggestion != null) {
|
||||||
final TimestampedValue<Long> newUtcTime = bestPhoneSuggestion.getUtcTime();
|
final TimestampedValue<Long> newUtcTime = bestTelephonySuggestion.getUtcTime();
|
||||||
String cause = "Found good phone suggestion."
|
String cause = "Found good telephony suggestion."
|
||||||
+ ", bestPhoneSuggestion=" + bestPhoneSuggestion
|
+ ", bestTelephonySuggestion=" + bestTelephonySuggestion
|
||||||
+ ", detectionReason=" + detectionReason;
|
+ ", detectionReason=" + detectionReason;
|
||||||
setSystemClockIfRequired(ORIGIN_PHONE, newUtcTime, cause);
|
setSystemClockIfRequired(ORIGIN_TELEPHONY, newUtcTime, cause);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// There is no good phone suggestion, try network.
|
// There is no good telephony suggestion, try network.
|
||||||
NetworkTimeSuggestion networkSuggestion = findLatestValidNetworkSuggestion();
|
NetworkTimeSuggestion networkSuggestion = findLatestValidNetworkSuggestion();
|
||||||
if (networkSuggestion != null) {
|
if (networkSuggestion != null) {
|
||||||
final TimestampedValue<Long> newUtcTime = networkSuggestion.getUtcTime();
|
final TimestampedValue<Long> newUtcTime = networkSuggestion.getUtcTime();
|
||||||
@@ -305,18 +311,18 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Slog.d(LOG_TAG, "Could not determine time: No best phone or network suggestion."
|
Slog.d(LOG_TAG, "Could not determine time: No best telephony or network suggestion."
|
||||||
+ " detectionReason=" + detectionReason);
|
+ " detectionReason=" + detectionReason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
@Nullable
|
@Nullable
|
||||||
private PhoneTimeSuggestion findBestPhoneSuggestion() {
|
private TelephonyTimeSuggestion findBestTelephonySuggestion() {
|
||||||
long elapsedRealtimeMillis = mCallback.elapsedRealtimeMillis();
|
long elapsedRealtimeMillis = mCallback.elapsedRealtimeMillis();
|
||||||
|
|
||||||
// Phone time suggestions are assumed to be derived from NITZ or NITZ-like signals. These
|
// Telephony time suggestions are assumed to be derived from NITZ or NITZ-like signals.
|
||||||
// have a number of limitations:
|
// These have a number of limitations:
|
||||||
// 1) No guarantee of accuracy ("accuracy of the time information is in the order of
|
// 1) No guarantee of accuracy ("accuracy of the time information is in the order of
|
||||||
// minutes") [1]
|
// minutes") [1]
|
||||||
// 2) No guarantee of regular signals ("dependent on the handset crossing radio network
|
// 2) No guarantee of regular signals ("dependent on the handset crossing radio network
|
||||||
@@ -335,8 +341,8 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
// For simplicity, we try to value recency, then consistency of slotIndex.
|
// 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 slotIndex is scored. The score is based on
|
||||||
// discrete age bucket, i.e. so signals received around the same time will be in the same
|
// a discrete age bucket, i.e. so signals received around the same time will be in the same
|
||||||
// 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
|
||||||
@@ -345,11 +351,11 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
// 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;
|
TelephonyTimeSuggestion bestSuggestion = null;
|
||||||
int bestScore = PHONE_INVALID_SCORE;
|
int bestScore = TELEPHONY_INVALID_SCORE;
|
||||||
for (int i = 0; i < mSuggestionBySlotIndex.size(); i++) {
|
for (int i = 0; i < mSuggestionBySlotIndex.size(); i++) {
|
||||||
Integer slotIndex = mSuggestionBySlotIndex.keyAt(i);
|
Integer slotIndex = mSuggestionBySlotIndex.keyAt(i);
|
||||||
PhoneTimeSuggestion candidateSuggestion = mSuggestionBySlotIndex.valueAt(i);
|
TelephonyTimeSuggestion 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 slotIndex."
|
Slog.w(LOG_TAG, "Latest suggestion unexpectedly null for slotIndex."
|
||||||
@@ -362,8 +368,9 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int candidateScore = scorePhoneSuggestion(elapsedRealtimeMillis, candidateSuggestion);
|
int candidateScore =
|
||||||
if (candidateScore == PHONE_INVALID_SCORE) {
|
scoreTelephonySuggestion(elapsedRealtimeMillis, candidateSuggestion);
|
||||||
|
if (candidateScore == TELEPHONY_INVALID_SCORE) {
|
||||||
// Expected: This means the suggestion is obviously invalid or just too old.
|
// Expected: This means the suggestion is obviously invalid or just too old.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -384,8 +391,8 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
return bestSuggestion;
|
return bestSuggestion;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int scorePhoneSuggestion(
|
private static int scoreTelephonySuggestion(
|
||||||
long elapsedRealtimeMillis, @NonNull PhoneTimeSuggestion timeSuggestion) {
|
long elapsedRealtimeMillis, @NonNull TelephonyTimeSuggestion timeSuggestion) {
|
||||||
|
|
||||||
// Validate first.
|
// Validate first.
|
||||||
TimestampedValue<Long> utcTime = timeSuggestion.getUtcTime();
|
TimestampedValue<Long> utcTime = timeSuggestion.getUtcTime();
|
||||||
@@ -393,21 +400,21 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
Slog.w(LOG_TAG, "Existing suggestion found to be invalid "
|
Slog.w(LOG_TAG, "Existing suggestion found to be invalid "
|
||||||
+ " elapsedRealtimeMillis=" + elapsedRealtimeMillis
|
+ " elapsedRealtimeMillis=" + elapsedRealtimeMillis
|
||||||
+ ", timeSuggestion=" + timeSuggestion);
|
+ ", timeSuggestion=" + timeSuggestion);
|
||||||
return PHONE_INVALID_SCORE;
|
return TELEPHONY_INVALID_SCORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 slotIndexs 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 < TELEPHONY_BUCKET_COUNT.
|
||||||
int bucketIndex = (int) (ageMillis / PHONE_BUCKET_SIZE_MILLIS);
|
int bucketIndex = (int) (ageMillis / TELEPHONY_BUCKET_SIZE_MILLIS);
|
||||||
if (bucketIndex >= PHONE_BUCKET_COUNT) {
|
if (bucketIndex >= TELEPHONY_BUCKET_COUNT) {
|
||||||
return PHONE_INVALID_SCORE;
|
return TELEPHONY_INVALID_SCORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We want the lowest bucket index to have the highest score. 0 > score >= BUCKET_COUNT.
|
// We want the lowest bucket index to have the highest score. 0 > score >= BUCKET_COUNT.
|
||||||
return PHONE_BUCKET_COUNT - bucketIndex;
|
return TELEPHONY_BUCKET_COUNT - bucketIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the latest, valid, network suggestion. Returns {@code null} if there isn't one. */
|
/** Returns the latest, valid, network suggestion. Returns {@code null} if there isn't one. */
|
||||||
@@ -537,13 +544,13 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current best phone suggestion. Not intended for general use: it is used during
|
* Returns the current best telephony suggestion. Not intended for general use: it is used
|
||||||
* tests to check strategy behavior.
|
* during tests to check strategy behavior.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@Nullable
|
@Nullable
|
||||||
public synchronized PhoneTimeSuggestion findBestPhoneSuggestionForTests() {
|
public synchronized TelephonyTimeSuggestion findBestTelephonySuggestionForTests() {
|
||||||
return findBestPhoneSuggestion();
|
return findBestTelephonySuggestion();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -561,7 +568,7 @@ public final class TimeDetectorStrategyImpl implements TimeDetectorStrategy {
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@Nullable
|
@Nullable
|
||||||
public synchronized PhoneTimeSuggestion getLatestPhoneSuggestion(int slotIndex) {
|
public synchronized TelephonyTimeSuggestion getLatestTelephonySuggestion(int slotIndex) {
|
||||||
return mSuggestionBySlotIndex.get(slotIndex);
|
return mSuggestionBySlotIndex.get(slotIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import android.annotation.NonNull;
|
|||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.timezonedetector.ITimeZoneDetectorService;
|
import android.app.timezonedetector.ITimeZoneDetectorService;
|
||||||
import android.app.timezonedetector.ManualTimeZoneSuggestion;
|
import android.app.timezonedetector.ManualTimeZoneSuggestion;
|
||||||
import android.app.timezonedetector.PhoneTimeZoneSuggestion;
|
import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
@@ -101,11 +101,11 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void suggestPhoneTimeZone(@NonNull PhoneTimeZoneSuggestion timeZoneSuggestion) {
|
public void suggestTelephonyTimeZone(@NonNull TelephonyTimeZoneSuggestion timeZoneSuggestion) {
|
||||||
enforceSuggestPhoneTimeZonePermission();
|
enforceSuggestTelephonyTimeZonePermission();
|
||||||
Objects.requireNonNull(timeZoneSuggestion);
|
Objects.requireNonNull(timeZoneSuggestion);
|
||||||
|
|
||||||
mHandler.post(() -> mTimeZoneDetectorStrategy.suggestPhoneTimeZone(timeZoneSuggestion));
|
mHandler.post(() -> mTimeZoneDetectorStrategy.suggestTelephonyTimeZone(timeZoneSuggestion));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -122,10 +122,10 @@ public final class TimeZoneDetectorService extends ITimeZoneDetectorService.Stub
|
|||||||
mHandler.post(mTimeZoneDetectorStrategy::handleAutoTimeZoneDetectionChanged);
|
mHandler.post(mTimeZoneDetectorStrategy::handleAutoTimeZoneDetectionChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enforceSuggestPhoneTimeZonePermission() {
|
private void enforceSuggestTelephonyTimeZonePermission() {
|
||||||
mContext.enforceCallingPermission(
|
mContext.enforceCallingPermission(
|
||||||
android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE,
|
android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE,
|
||||||
"suggest phone time and time zone");
|
"suggest telephony time and time zone");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enforceSuggestManualTimeZonePermission() {
|
private void enforceSuggestManualTimeZonePermission() {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ package com.android.server.timezonedetector;
|
|||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.app.timezonedetector.ManualTimeZoneSuggestion;
|
import android.app.timezonedetector.ManualTimeZoneSuggestion;
|
||||||
import android.app.timezonedetector.PhoneTimeZoneSuggestion;
|
import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
@@ -38,13 +38,13 @@ public interface 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 TelephonyTimeZoneSuggestion#getZoneId()} is {@code null}. The suggestion is scoped to
|
||||||
* specific {@link PhoneTimeZoneSuggestion#getSlotIndex() phone}.
|
* a specific {@link TelephonyTimeZoneSuggestion#getSlotIndex() slotIndex}.
|
||||||
* See {@link PhoneTimeZoneSuggestion} for an explanation of the metadata associated with a
|
* See {@link TelephonyTimeZoneSuggestion} 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.
|
||||||
*/
|
*/
|
||||||
void suggestPhoneTimeZone(@NonNull PhoneTimeZoneSuggestion suggestion);
|
void suggestTelephonyTimeZone(@NonNull TelephonyTimeZoneSuggestion suggestion);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when there has been a change to the automatic time zone detection setting.
|
* Called when there has been a change to the automatic time zone detection setting.
|
||||||
|
|||||||
@@ -15,17 +15,17 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.server.timezonedetector;
|
package com.android.server.timezonedetector;
|
||||||
|
|
||||||
import static android.app.timezonedetector.PhoneTimeZoneSuggestion.MATCH_TYPE_EMULATOR_ZONE_ID;
|
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.MATCH_TYPE_EMULATOR_ZONE_ID;
|
||||||
import static android.app.timezonedetector.PhoneTimeZoneSuggestion.MATCH_TYPE_TEST_NETWORK_OFFSET_ONLY;
|
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.MATCH_TYPE_TEST_NETWORK_OFFSET_ONLY;
|
||||||
import static android.app.timezonedetector.PhoneTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS;
|
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS;
|
||||||
import static android.app.timezonedetector.PhoneTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET;
|
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET;
|
||||||
import static android.app.timezonedetector.PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE;
|
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE;
|
||||||
|
|
||||||
import android.annotation.IntDef;
|
import android.annotation.IntDef;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.timezonedetector.ManualTimeZoneSuggestion;
|
import android.app.timezonedetector.ManualTimeZoneSuggestion;
|
||||||
import android.app.timezonedetector.PhoneTimeZoneSuggestion;
|
import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.LocalLog;
|
import android.util.LocalLog;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
@@ -44,11 +44,11 @@ import java.util.Objects;
|
|||||||
* suggestions. Suggestions are acted on or ignored as needed, dependent on the current "auto time
|
* suggestions. Suggestions are acted on or ignored as needed, dependent on the current "auto time
|
||||||
* zone detection" setting.
|
* zone detection" setting.
|
||||||
*
|
*
|
||||||
* <p>For automatic detection it keeps track of the most recent suggestion from each phone it uses
|
* <p>For automatic detection, it keeps track of the most recent telephony suggestion from each
|
||||||
* the best suggestion based on a scoring algorithm. If several phones provide the same score then
|
* slotIndex and it uses the best suggestion based on a scoring algorithm. If several slotIndexes
|
||||||
* the phone with the lowest numeric ID "wins". If the situation changes and it is no longer
|
* provide the same score then the slotIndex with the lowest numeric value "wins". If the situation
|
||||||
* possible to be confident about the time zone, phones must submit an empty suggestion in order to
|
* changes and it is no longer possible to be confident about the time zone, slotIndexes must have
|
||||||
* "withdraw" their previous suggestion.
|
* an empty suggestion submitted in order to "withdraw" their previous suggestion.
|
||||||
*
|
*
|
||||||
* <p>Most public methods are marked synchronized to ensure thread safety around internal state.
|
* <p>Most public methods are marked synchronized to ensure thread safety around internal state.
|
||||||
*/
|
*/
|
||||||
@@ -91,28 +91,28 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
private static final String LOG_TAG = "TimeZoneDetectorStrategy";
|
private static final String LOG_TAG = "TimeZoneDetectorStrategy";
|
||||||
private static final boolean DBG = false;
|
private static final boolean DBG = false;
|
||||||
|
|
||||||
@IntDef({ ORIGIN_PHONE, ORIGIN_MANUAL })
|
@IntDef({ ORIGIN_TELEPHONY, ORIGIN_MANUAL })
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface Origin {}
|
public @interface Origin {}
|
||||||
|
|
||||||
/** Used when a time value originated from a telephony signal. */
|
/** Used when a time value originated from a telephony signal. */
|
||||||
@Origin
|
@Origin
|
||||||
private static final int ORIGIN_PHONE = 1;
|
private static final int ORIGIN_TELEPHONY = 1;
|
||||||
|
|
||||||
/** Used when a time value originated from a user / manual settings. */
|
/** Used when a time value originated from a user / manual settings. */
|
||||||
@Origin
|
@Origin
|
||||||
private static final int ORIGIN_MANUAL = 2;
|
private static final int ORIGIN_MANUAL = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The abstract score for an empty or invalid phone suggestion.
|
* The abstract score for an empty or invalid telephony suggestion.
|
||||||
*
|
*
|
||||||
* Used to score phone suggestions where there is no zone.
|
* Used to score telephony suggestions where there is no zone.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final int PHONE_SCORE_NONE = 0;
|
public static final int TELEPHONY_SCORE_NONE = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The abstract score for a low quality phone suggestion.
|
* The abstract score for a low quality telephony suggestion.
|
||||||
*
|
*
|
||||||
* Used to score suggestions where:
|
* Used to score suggestions where:
|
||||||
* The suggested zone ID is one of several possibilities, and the possibilities have different
|
* The suggested zone ID is one of several possibilities, and the possibilities have different
|
||||||
@@ -121,10 +121,10 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
* You would have to be quite desperate to want to use this choice.
|
* You would have to be quite desperate to want to use this choice.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final int PHONE_SCORE_LOW = 1;
|
public static final int TELEPHONY_SCORE_LOW = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The abstract score for a medium quality phone suggestion.
|
* The abstract score for a medium quality telephony suggestion.
|
||||||
*
|
*
|
||||||
* Used for:
|
* Used for:
|
||||||
* The suggested zone ID is one of several possibilities but at least the possibilities have the
|
* The suggested zone ID is one of several possibilities but at least the possibilities have the
|
||||||
@@ -132,36 +132,38 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
* switch to DST at the wrong time and (for example) their calendar events.
|
* switch to DST at the wrong time and (for example) their calendar events.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final int PHONE_SCORE_MEDIUM = 2;
|
public static final int TELEPHONY_SCORE_MEDIUM = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The abstract score for a high quality phone suggestion.
|
* The abstract score for a high quality telephony suggestion.
|
||||||
*
|
*
|
||||||
* Used for:
|
* Used for:
|
||||||
* The suggestion was for one zone ID and the answer was unambiguous and likely correct given
|
* The suggestion was for one zone ID and the answer was unambiguous and likely correct given
|
||||||
* the info available.
|
* the info available.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final int PHONE_SCORE_HIGH = 3;
|
public static final int TELEPHONY_SCORE_HIGH = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The abstract score for a highest quality phone suggestion.
|
* The abstract score for a highest quality telephony suggestion.
|
||||||
*
|
*
|
||||||
* Used for:
|
* Used for:
|
||||||
* Suggestions that must "win" because they constitute test or emulator zone ID.
|
* Suggestions that must "win" because they constitute test or emulator zone ID.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final int PHONE_SCORE_HIGHEST = 4;
|
public static final int TELEPHONY_SCORE_HIGHEST = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The threshold at which phone suggestions are good enough to use to set the device's time
|
* The threshold at which telephony suggestions are good enough to use to set the device's time
|
||||||
* zone.
|
* zone.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final int PHONE_SCORE_USAGE_THRESHOLD = PHONE_SCORE_MEDIUM;
|
public static final int TELEPHONY_SCORE_USAGE_THRESHOLD = TELEPHONY_SCORE_MEDIUM;
|
||||||
|
|
||||||
/** The number of previous phone suggestions to keep for each ID (for use during debugging). */
|
/**
|
||||||
private static final int KEEP_PHONE_SUGGESTION_HISTORY_SIZE = 30;
|
* The number of previous telephony suggestions to keep for each ID (for use during debugging).
|
||||||
|
*/
|
||||||
|
private static final int KEEP_TELEPHONY_SUGGESTION_HISTORY_SIZE = 30;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Callback mCallback;
|
private final Callback mCallback;
|
||||||
@@ -174,13 +176,14 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
private final LocalLog mTimeZoneChangesLog = new LocalLog(30, false /* useLocalTimestamps */);
|
private final LocalLog mTimeZoneChangesLog = new LocalLog(30, false /* useLocalTimestamps */);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mapping from slotIndex to a phone time zone suggestion. We typically expect one or two
|
* A mapping from slotIndex to a telephony time zone suggestion. We typically expect one or two
|
||||||
* mappings: devices will have a small number of telephony devices and slotIndexs are assumed to
|
* mappings: devices will have a small number of telephony devices and slotIndexes are assumed
|
||||||
* be stable.
|
* to be stable.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
private ArrayMapWithHistory<Integer, QualifiedPhoneTimeZoneSuggestion> mSuggestionBySlotIndex =
|
private ArrayMapWithHistory<Integer, QualifiedTelephonyTimeZoneSuggestion>
|
||||||
new ArrayMapWithHistory<>(KEEP_PHONE_SUGGESTION_HISTORY_SIZE);
|
mSuggestionBySlotIndex =
|
||||||
|
new ArrayMapWithHistory<>(KEEP_TELEPHONY_SUGGESTION_HISTORY_SIZE);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of {@link TimeZoneDetectorStrategyImpl}.
|
* Creates a new instance of {@link TimeZoneDetectorStrategyImpl}.
|
||||||
@@ -205,42 +208,43 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void suggestPhoneTimeZone(@NonNull PhoneTimeZoneSuggestion suggestion) {
|
public synchronized void suggestTelephonyTimeZone(
|
||||||
|
@NonNull TelephonyTimeZoneSuggestion suggestion) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Slog.d(LOG_TAG, "Phone suggestion received. newSuggestion=" + suggestion);
|
Slog.d(LOG_TAG, "Telephony suggestion received. newSuggestion=" + suggestion);
|
||||||
}
|
}
|
||||||
Objects.requireNonNull(suggestion);
|
Objects.requireNonNull(suggestion);
|
||||||
|
|
||||||
// Score the suggestion.
|
// Score the suggestion.
|
||||||
int score = scorePhoneSuggestion(suggestion);
|
int score = scoreTelephonySuggestion(suggestion);
|
||||||
QualifiedPhoneTimeZoneSuggestion scoredSuggestion =
|
QualifiedTelephonyTimeZoneSuggestion scoredSuggestion =
|
||||||
new QualifiedPhoneTimeZoneSuggestion(suggestion, score);
|
new QualifiedTelephonyTimeZoneSuggestion(suggestion, score);
|
||||||
|
|
||||||
// Store the suggestion against the correct slotIndex.
|
// Store the suggestion against the correct slotIndex.
|
||||||
mSuggestionBySlotIndex.put(suggestion.getSlotIndex(), 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.
|
||||||
String reason = "New phone time suggested. suggestion=" + suggestion;
|
String reason = "New telephony time suggested. suggestion=" + suggestion;
|
||||||
doAutoTimeZoneDetection(reason);
|
doAutoTimeZoneDetection(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int scorePhoneSuggestion(@NonNull PhoneTimeZoneSuggestion suggestion) {
|
private static int scoreTelephonySuggestion(@NonNull TelephonyTimeZoneSuggestion suggestion) {
|
||||||
int score;
|
int score;
|
||||||
if (suggestion.getZoneId() == null) {
|
if (suggestion.getZoneId() == null) {
|
||||||
score = PHONE_SCORE_NONE;
|
score = TELEPHONY_SCORE_NONE;
|
||||||
} else if (suggestion.getMatchType() == MATCH_TYPE_TEST_NETWORK_OFFSET_ONLY
|
} else if (suggestion.getMatchType() == MATCH_TYPE_TEST_NETWORK_OFFSET_ONLY
|
||||||
|| suggestion.getMatchType() == MATCH_TYPE_EMULATOR_ZONE_ID) {
|
|| suggestion.getMatchType() == MATCH_TYPE_EMULATOR_ZONE_ID) {
|
||||||
// Handle emulator / test cases : These suggestions should always just be used.
|
// Handle emulator / test cases : These suggestions should always just be used.
|
||||||
score = PHONE_SCORE_HIGHEST;
|
score = TELEPHONY_SCORE_HIGHEST;
|
||||||
} else if (suggestion.getQuality() == QUALITY_SINGLE_ZONE) {
|
} else if (suggestion.getQuality() == QUALITY_SINGLE_ZONE) {
|
||||||
score = PHONE_SCORE_HIGH;
|
score = TELEPHONY_SCORE_HIGH;
|
||||||
} else if (suggestion.getQuality() == QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET) {
|
} else if (suggestion.getQuality() == QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET) {
|
||||||
// The suggestion may be wrong, but at least the offset should be correct.
|
// The suggestion may be wrong, but at least the offset should be correct.
|
||||||
score = PHONE_SCORE_MEDIUM;
|
score = TELEPHONY_SCORE_MEDIUM;
|
||||||
} else if (suggestion.getQuality() == QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS) {
|
} else if (suggestion.getQuality() == QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS) {
|
||||||
// The suggestion has a good chance of being wrong.
|
// The suggestion has a good chance of being wrong.
|
||||||
score = PHONE_SCORE_LOW;
|
score = TELEPHONY_SCORE_LOW;
|
||||||
} else {
|
} else {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
@@ -248,9 +252,9 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the best available time zone suggestion from all phones. If it is high-enough quality
|
* Finds the best available time zone suggestion from all slotIndexes. If it is high-enough
|
||||||
* and automatic time zone detection is enabled then it will be set on the device. The outcome
|
* quality and automatic time zone detection is enabled then it will be set on the device. The
|
||||||
* can be that this strategy becomes / remains un-opinionated and nothing is set.
|
* outcome can be that this strategy becomes / remains un-opinionated and nothing is set.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
private void doAutoTimeZoneDetection(@NonNull String detectionReason) {
|
private void doAutoTimeZoneDetection(@NonNull String detectionReason) {
|
||||||
@@ -259,35 +263,37 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QualifiedPhoneTimeZoneSuggestion bestPhoneSuggestion = findBestPhoneSuggestion();
|
QualifiedTelephonyTimeZoneSuggestion bestTelephonySuggestion =
|
||||||
|
findBestTelephonySuggestion();
|
||||||
|
|
||||||
// Work out what to do with the best suggestion.
|
// Work out what to do with the best suggestion.
|
||||||
if (bestPhoneSuggestion == null) {
|
if (bestTelephonySuggestion == null) {
|
||||||
// There is no phone suggestion available at all. Become un-opinionated.
|
// There is no telephony suggestion available at all. Become un-opinionated.
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Slog.d(LOG_TAG, "Could not determine time zone: No best phone suggestion."
|
Slog.d(LOG_TAG, "Could not determine time zone: No best telephony suggestion."
|
||||||
+ " detectionReason=" + detectionReason);
|
+ " detectionReason=" + detectionReason);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case handling for uninitialized devices. This should only happen once.
|
// Special case handling for uninitialized devices. This should only happen once.
|
||||||
String newZoneId = bestPhoneSuggestion.suggestion.getZoneId();
|
String newZoneId = bestTelephonySuggestion.suggestion.getZoneId();
|
||||||
if (newZoneId != null && !mCallback.isDeviceTimeZoneInitialized()) {
|
if (newZoneId != null && !mCallback.isDeviceTimeZoneInitialized()) {
|
||||||
String cause = "Device has no time zone set. Attempting to set the device to the best"
|
String cause = "Device has no time zone set. Attempting to set the device to the best"
|
||||||
+ " available suggestion."
|
+ " available suggestion."
|
||||||
+ " bestPhoneSuggestion=" + bestPhoneSuggestion
|
+ " bestTelephonySuggestion=" + bestTelephonySuggestion
|
||||||
+ ", detectionReason=" + detectionReason;
|
+ ", detectionReason=" + detectionReason;
|
||||||
Slog.i(LOG_TAG, cause);
|
Slog.i(LOG_TAG, cause);
|
||||||
setDeviceTimeZoneIfRequired(ORIGIN_PHONE, newZoneId, cause);
|
setDeviceTimeZoneIfRequired(ORIGIN_TELEPHONY, newZoneId, cause);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean suggestionGoodEnough = bestPhoneSuggestion.score >= PHONE_SCORE_USAGE_THRESHOLD;
|
boolean suggestionGoodEnough =
|
||||||
|
bestTelephonySuggestion.score >= TELEPHONY_SCORE_USAGE_THRESHOLD;
|
||||||
if (!suggestionGoodEnough) {
|
if (!suggestionGoodEnough) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Slog.d(LOG_TAG, "Best suggestion not good enough."
|
Slog.d(LOG_TAG, "Best suggestion not good enough."
|
||||||
+ " bestPhoneSuggestion=" + bestPhoneSuggestion
|
+ " bestTelephonySuggestion=" + bestTelephonySuggestion
|
||||||
+ ", detectionReason=" + detectionReason);
|
+ ", detectionReason=" + detectionReason);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -297,16 +303,16 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
// zone ID.
|
// zone ID.
|
||||||
if (newZoneId == null) {
|
if (newZoneId == null) {
|
||||||
Slog.w(LOG_TAG, "Empty zone suggestion scored higher than expected. This is an error:"
|
Slog.w(LOG_TAG, "Empty zone suggestion scored higher than expected. This is an error:"
|
||||||
+ " bestPhoneSuggestion=" + bestPhoneSuggestion
|
+ " bestTelephonySuggestion=" + bestTelephonySuggestion
|
||||||
+ " detectionReason=" + detectionReason);
|
+ " detectionReason=" + detectionReason);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String zoneId = bestPhoneSuggestion.suggestion.getZoneId();
|
String zoneId = bestTelephonySuggestion.suggestion.getZoneId();
|
||||||
String cause = "Found good suggestion."
|
String cause = "Found good suggestion."
|
||||||
+ ", bestPhoneSuggestion=" + bestPhoneSuggestion
|
+ ", bestTelephonySuggestion=" + bestTelephonySuggestion
|
||||||
+ ", detectionReason=" + detectionReason;
|
+ ", detectionReason=" + detectionReason;
|
||||||
setDeviceTimeZoneIfRequired(ORIGIN_PHONE, zoneId, cause);
|
setDeviceTimeZoneIfRequired(ORIGIN_TELEPHONY, zoneId, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
@@ -372,15 +378,15 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
|
|
||||||
@GuardedBy("this")
|
@GuardedBy("this")
|
||||||
@Nullable
|
@Nullable
|
||||||
private QualifiedPhoneTimeZoneSuggestion findBestPhoneSuggestion() {
|
private QualifiedTelephonyTimeZoneSuggestion findBestTelephonySuggestion() {
|
||||||
QualifiedPhoneTimeZoneSuggestion bestSuggestion = null;
|
QualifiedTelephonyTimeZoneSuggestion bestSuggestion = null;
|
||||||
|
|
||||||
// Iterate over the latest QualifiedPhoneTimeZoneSuggestion objects received for each phone
|
// Iterate over the latest QualifiedTelephonyTimeZoneSuggestion objects received for each
|
||||||
// and find the best. Note that we deliberately do not look at age: the caller can
|
// slotIndex 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 < mSuggestionBySlotIndex.size(); i++) {
|
for (int i = 0; i < mSuggestionBySlotIndex.size(); i++) {
|
||||||
QualifiedPhoneTimeZoneSuggestion candidateSuggestion =
|
QualifiedTelephonyTimeZoneSuggestion candidateSuggestion =
|
||||||
mSuggestionBySlotIndex.valueAt(i);
|
mSuggestionBySlotIndex.valueAt(i);
|
||||||
if (candidateSuggestion == null) {
|
if (candidateSuggestion == null) {
|
||||||
// Unexpected
|
// Unexpected
|
||||||
@@ -404,13 +410,13 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current best phone suggestion. Not intended for general use: it is used during
|
* Returns the current best telephony suggestion. Not intended for general use: it is used
|
||||||
* tests to check strategy behavior.
|
* during tests to check strategy behavior.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@Nullable
|
@Nullable
|
||||||
public synchronized QualifiedPhoneTimeZoneSuggestion findBestPhoneSuggestionForTests() {
|
public synchronized QualifiedTelephonyTimeZoneSuggestion findBestTelephonySuggestionForTests() {
|
||||||
return findBestPhoneSuggestion();
|
return findBestTelephonySuggestion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -447,7 +453,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
mTimeZoneChangesLog.dump(ipw);
|
mTimeZoneChangesLog.dump(ipw);
|
||||||
ipw.decreaseIndent(); // level 2
|
ipw.decreaseIndent(); // level 2
|
||||||
|
|
||||||
ipw.println("Phone suggestion history:");
|
ipw.println("Telephony suggestion history:");
|
||||||
ipw.increaseIndent(); // level 2
|
ipw.increaseIndent(); // level 2
|
||||||
mSuggestionBySlotIndex.dump(ipw);
|
mSuggestionBySlotIndex.dump(ipw);
|
||||||
ipw.decreaseIndent(); // level 2
|
ipw.decreaseIndent(); // level 2
|
||||||
@@ -459,18 +465,19 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
* 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 slotIndex) {
|
public synchronized QualifiedTelephonyTimeZoneSuggestion getLatestTelephonySuggestion(
|
||||||
|
int slotIndex) {
|
||||||
return mSuggestionBySlotIndex.get(slotIndex);
|
return mSuggestionBySlotIndex.get(slotIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link PhoneTimeZoneSuggestion} with additional qualifying metadata.
|
* A {@link TelephonyTimeZoneSuggestion} with additional qualifying metadata.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static class QualifiedPhoneTimeZoneSuggestion {
|
public static class QualifiedTelephonyTimeZoneSuggestion {
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public final PhoneTimeZoneSuggestion suggestion;
|
public final TelephonyTimeZoneSuggestion suggestion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The score the suggestion has been given. This can be used to rank against other
|
* The score the suggestion has been given. This can be used to rank against other
|
||||||
@@ -480,7 +487,8 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
public final int score;
|
public final int score;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public QualifiedPhoneTimeZoneSuggestion(PhoneTimeZoneSuggestion suggestion, int score) {
|
public QualifiedTelephonyTimeZoneSuggestion(
|
||||||
|
TelephonyTimeZoneSuggestion suggestion, int score) {
|
||||||
this.suggestion = suggestion;
|
this.suggestion = suggestion;
|
||||||
this.score = score;
|
this.score = score;
|
||||||
}
|
}
|
||||||
@@ -493,7 +501,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
if (o == null || getClass() != o.getClass()) {
|
if (o == null || getClass() != o.getClass()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QualifiedPhoneTimeZoneSuggestion that = (QualifiedPhoneTimeZoneSuggestion) o;
|
QualifiedTelephonyTimeZoneSuggestion that = (QualifiedTelephonyTimeZoneSuggestion) o;
|
||||||
return score == that.score
|
return score == that.score
|
||||||
&& suggestion.equals(that.suggestion);
|
&& suggestion.equals(that.suggestion);
|
||||||
}
|
}
|
||||||
@@ -505,7 +513,7 @@ public final class TimeZoneDetectorStrategyImpl implements TimeZoneDetectorStrat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "QualifiedPhoneTimeZoneSuggestion{"
|
return "QualifiedTelephonyTimeZoneSuggestion{"
|
||||||
+ "suggestion=" + suggestion
|
+ "suggestion=" + suggestion
|
||||||
+ ", score=" + score
|
+ ", score=" + score
|
||||||
+ '}';
|
+ '}';
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.app.timedetector.ManualTimeSuggestion;
|
import android.app.timedetector.ManualTimeSuggestion;
|
||||||
import android.app.timedetector.NetworkTimeSuggestion;
|
import android.app.timedetector.NetworkTimeSuggestion;
|
||||||
import android.app.timedetector.PhoneTimeSuggestion;
|
import android.app.timedetector.TelephonyTimeSuggestion;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
@@ -80,35 +80,35 @@ public class TimeDetectorServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = SecurityException.class)
|
@Test(expected = SecurityException.class)
|
||||||
public void testSuggestPhoneTime_withoutPermission() {
|
public void testSuggestTelephonyTime_withoutPermission() {
|
||||||
doThrow(new SecurityException("Mock"))
|
doThrow(new SecurityException("Mock"))
|
||||||
.when(mMockContext).enforceCallingPermission(anyString(), any());
|
.when(mMockContext).enforceCallingPermission(anyString(), any());
|
||||||
PhoneTimeSuggestion phoneTimeSuggestion = createPhoneTimeSuggestion();
|
TelephonyTimeSuggestion timeSuggestion = createTelephonyTimeSuggestion();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mTimeDetectorService.suggestPhoneTime(phoneTimeSuggestion);
|
mTimeDetectorService.suggestTelephonyTime(timeSuggestion);
|
||||||
fail();
|
fail();
|
||||||
} finally {
|
} finally {
|
||||||
verify(mMockContext).enforceCallingPermission(
|
verify(mMockContext).enforceCallingPermission(
|
||||||
eq(android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE),
|
eq(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE),
|
||||||
anyString());
|
anyString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestPhoneTime() throws Exception {
|
public void testSuggestTelephonyTime() throws Exception {
|
||||||
doNothing().when(mMockContext).enforceCallingPermission(anyString(), any());
|
doNothing().when(mMockContext).enforceCallingPermission(anyString(), any());
|
||||||
|
|
||||||
PhoneTimeSuggestion phoneTimeSuggestion = createPhoneTimeSuggestion();
|
TelephonyTimeSuggestion timeSuggestion = createTelephonyTimeSuggestion();
|
||||||
mTimeDetectorService.suggestPhoneTime(phoneTimeSuggestion);
|
mTimeDetectorService.suggestTelephonyTime(timeSuggestion);
|
||||||
mTestHandler.assertTotalMessagesEnqueued(1);
|
mTestHandler.assertTotalMessagesEnqueued(1);
|
||||||
|
|
||||||
verify(mMockContext).enforceCallingPermission(
|
verify(mMockContext).enforceCallingPermission(
|
||||||
eq(android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE),
|
eq(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE),
|
||||||
anyString());
|
anyString());
|
||||||
|
|
||||||
mTestHandler.waitForMessagesToBeProcessed();
|
mTestHandler.waitForMessagesToBeProcessed();
|
||||||
mStubbedTimeDetectorStrategy.verifySuggestPhoneTimeCalled(phoneTimeSuggestion);
|
mStubbedTimeDetectorStrategy.verifySuggestTelephonyTimeCalled(timeSuggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = SecurityException.class)
|
@Test(expected = SecurityException.class)
|
||||||
@@ -199,10 +199,10 @@ public class TimeDetectorServiceTest {
|
|||||||
mStubbedTimeDetectorStrategy.verifyHandleAutoTimeDetectionChangedCalled();
|
mStubbedTimeDetectorStrategy.verifyHandleAutoTimeDetectionChangedCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PhoneTimeSuggestion createPhoneTimeSuggestion() {
|
private static TelephonyTimeSuggestion createTelephonyTimeSuggestion() {
|
||||||
int slotIndex = 1234;
|
int slotIndex = 1234;
|
||||||
TimestampedValue<Long> timeValue = new TimestampedValue<>(100L, 1_000_000L);
|
TimestampedValue<Long> timeValue = new TimestampedValue<>(100L, 1_000_000L);
|
||||||
return new PhoneTimeSuggestion.Builder(slotIndex)
|
return new TelephonyTimeSuggestion.Builder(slotIndex)
|
||||||
.setUtcTime(timeValue)
|
.setUtcTime(timeValue)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
@@ -220,7 +220,7 @@ public class TimeDetectorServiceTest {
|
|||||||
private static class StubbedTimeDetectorStrategy implements TimeDetectorStrategy {
|
private static class StubbedTimeDetectorStrategy implements TimeDetectorStrategy {
|
||||||
|
|
||||||
// Call tracking.
|
// Call tracking.
|
||||||
private PhoneTimeSuggestion mLastPhoneSuggestion;
|
private TelephonyTimeSuggestion mLastTelephonySuggestion;
|
||||||
private ManualTimeSuggestion mLastManualSuggestion;
|
private ManualTimeSuggestion mLastManualSuggestion;
|
||||||
private NetworkTimeSuggestion mLastNetworkSuggestion;
|
private NetworkTimeSuggestion mLastNetworkSuggestion;
|
||||||
private boolean mHandleAutoTimeDetectionChangedCalled;
|
private boolean mHandleAutoTimeDetectionChangedCalled;
|
||||||
@@ -231,8 +231,8 @@ public class TimeDetectorServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void suggestPhoneTime(PhoneTimeSuggestion timeSuggestion) {
|
public void suggestTelephonyTime(TelephonyTimeSuggestion timeSuggestion) {
|
||||||
mLastPhoneSuggestion = timeSuggestion;
|
mLastTelephonySuggestion = timeSuggestion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -256,15 +256,15 @@ public class TimeDetectorServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void resetCallTracking() {
|
void resetCallTracking() {
|
||||||
mLastPhoneSuggestion = null;
|
mLastTelephonySuggestion = null;
|
||||||
mLastManualSuggestion = null;
|
mLastManualSuggestion = null;
|
||||||
mLastNetworkSuggestion = null;
|
mLastNetworkSuggestion = null;
|
||||||
mHandleAutoTimeDetectionChangedCalled = false;
|
mHandleAutoTimeDetectionChangedCalled = false;
|
||||||
mDumpCalled = false;
|
mDumpCalled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifySuggestPhoneTimeCalled(PhoneTimeSuggestion expectedSuggestion) {
|
void verifySuggestTelephonyTimeCalled(TelephonyTimeSuggestion expectedSuggestion) {
|
||||||
assertEquals(expectedSuggestion, mLastPhoneSuggestion);
|
assertEquals(expectedSuggestion, mLastTelephonySuggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void verifySuggestManualTimeCalled(ManualTimeSuggestion expectedSuggestion) {
|
public void verifySuggestManualTimeCalled(ManualTimeSuggestion expectedSuggestion) {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import static org.junit.Assert.fail;
|
|||||||
|
|
||||||
import android.app.timedetector.ManualTimeSuggestion;
|
import android.app.timedetector.ManualTimeSuggestion;
|
||||||
import android.app.timedetector.NetworkTimeSuggestion;
|
import android.app.timedetector.NetworkTimeSuggestion;
|
||||||
import android.app.timedetector.PhoneTimeSuggestion;
|
import android.app.timedetector.TelephonyTimeSuggestion;
|
||||||
import android.icu.util.Calendar;
|
import android.icu.util.Calendar;
|
||||||
import android.icu.util.GregorianCalendar;
|
import android.icu.util.GregorianCalendar;
|
||||||
import android.icu.util.TimeZone;
|
import android.icu.util.TimeZone;
|
||||||
@@ -52,7 +52,7 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
*/
|
*/
|
||||||
private static final long ARBITRARY_TEST_TIME_MILLIS = createUtcTime(2018, 1, 1, 12, 0, 0);
|
private static final long ARBITRARY_TEST_TIME_MILLIS = createUtcTime(2018, 1, 1, 12, 0, 0);
|
||||||
|
|
||||||
private static final int ARBITRARY_PHONE_ID = 123456;
|
private static final int ARBITRARY_SLOT_INDEX = 123456;
|
||||||
|
|
||||||
private Script mScript;
|
private Script mScript;
|
||||||
|
|
||||||
@@ -62,51 +62,51 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestPhoneTime_autoTimeEnabled() {
|
public void testSuggestTelephonyTime_autoTimeEnabled() {
|
||||||
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
||||||
.pokeAutoTimeDetectionEnabled(true);
|
.pokeAutoTimeDetectionEnabled(true);
|
||||||
|
|
||||||
int phoneId = ARBITRARY_PHONE_ID;
|
int slotIndex = ARBITRARY_SLOT_INDEX;
|
||||||
long testTimeMillis = ARBITRARY_TEST_TIME_MILLIS;
|
long testTimeMillis = ARBITRARY_TEST_TIME_MILLIS;
|
||||||
|
|
||||||
PhoneTimeSuggestion timeSuggestion =
|
TelephonyTimeSuggestion timeSuggestion =
|
||||||
mScript.generatePhoneTimeSuggestion(phoneId, testTimeMillis);
|
mScript.generateTelephonyTimeSuggestion(slotIndex, testTimeMillis);
|
||||||
mScript.simulateTimePassing()
|
mScript.simulateTimePassing()
|
||||||
.simulatePhoneTimeSuggestion(timeSuggestion);
|
.simulateTelephonyTimeSuggestion(timeSuggestion);
|
||||||
|
|
||||||
long expectedSystemClockMillis =
|
long expectedSystemClockMillis =
|
||||||
mScript.calculateTimeInMillisForNow(timeSuggestion.getUtcTime());
|
mScript.calculateTimeInMillisForNow(timeSuggestion.getUtcTime());
|
||||||
mScript.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis)
|
mScript.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis)
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestPhoneTime_emptySuggestionIgnored() {
|
public void testSuggestTelephonyTime_emptySuggestionIgnored() {
|
||||||
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
||||||
.pokeAutoTimeDetectionEnabled(true);
|
.pokeAutoTimeDetectionEnabled(true);
|
||||||
|
|
||||||
int phoneId = ARBITRARY_PHONE_ID;
|
int slotIndex = ARBITRARY_SLOT_INDEX;
|
||||||
PhoneTimeSuggestion timeSuggestion =
|
TelephonyTimeSuggestion timeSuggestion =
|
||||||
mScript.generatePhoneTimeSuggestion(phoneId, null);
|
mScript.generateTelephonyTimeSuggestion(slotIndex, null);
|
||||||
mScript.simulatePhoneTimeSuggestion(timeSuggestion)
|
mScript.simulateTelephonyTimeSuggestion(timeSuggestion)
|
||||||
.verifySystemClockWasNotSetAndResetCallTracking()
|
.verifySystemClockWasNotSetAndResetCallTracking()
|
||||||
.assertLatestPhoneSuggestion(phoneId, null);
|
.assertLatestTelephonySuggestion(slotIndex, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestPhoneTime_systemClockThreshold() {
|
public void testSuggestTelephonyTime_systemClockThreshold() {
|
||||||
final int systemClockUpdateThresholdMillis = 1000;
|
final int systemClockUpdateThresholdMillis = 1000;
|
||||||
final int clockIncrementMillis = 100;
|
final int clockIncrementMillis = 100;
|
||||||
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
||||||
.pokeThresholds(systemClockUpdateThresholdMillis)
|
.pokeThresholds(systemClockUpdateThresholdMillis)
|
||||||
.pokeAutoTimeDetectionEnabled(true);
|
.pokeAutoTimeDetectionEnabled(true);
|
||||||
|
|
||||||
int phoneId = ARBITRARY_PHONE_ID;
|
int slotIndex = ARBITRARY_SLOT_INDEX;
|
||||||
|
|
||||||
// Send the first time signal. It should be used.
|
// Send the first time signal. It should be used.
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion timeSuggestion1 =
|
TelephonyTimeSuggestion timeSuggestion1 =
|
||||||
mScript.generatePhoneTimeSuggestion(phoneId, ARBITRARY_TEST_TIME_MILLIS);
|
mScript.generateTelephonyTimeSuggestion(slotIndex, ARBITRARY_TEST_TIME_MILLIS);
|
||||||
|
|
||||||
// Increment the the device clocks to simulate the passage of time.
|
// Increment the the device clocks to simulate the passage of time.
|
||||||
mScript.simulateTimePassing(clockIncrementMillis);
|
mScript.simulateTimePassing(clockIncrementMillis);
|
||||||
@@ -114,151 +114,151 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
long expectedSystemClockMillis1 =
|
long expectedSystemClockMillis1 =
|
||||||
mScript.calculateTimeInMillisForNow(timeSuggestion1.getUtcTime());
|
mScript.calculateTimeInMillisForNow(timeSuggestion1.getUtcTime());
|
||||||
|
|
||||||
mScript.simulatePhoneTimeSuggestion(timeSuggestion1)
|
mScript.simulateTelephonyTimeSuggestion(timeSuggestion1)
|
||||||
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis1)
|
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis1)
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion1);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now send another time signal, but one that is too similar to the last one and should be
|
// Now send another time signal, but one that is too similar to the last one and should be
|
||||||
// stored, but not used to set the system clock.
|
// stored, but not used to set the system clock.
|
||||||
{
|
{
|
||||||
int underThresholdMillis = systemClockUpdateThresholdMillis - 1;
|
int underThresholdMillis = systemClockUpdateThresholdMillis - 1;
|
||||||
PhoneTimeSuggestion timeSuggestion2 = mScript.generatePhoneTimeSuggestion(
|
TelephonyTimeSuggestion timeSuggestion2 = mScript.generateTelephonyTimeSuggestion(
|
||||||
phoneId, mScript.peekSystemClockMillis() + underThresholdMillis);
|
slotIndex, mScript.peekSystemClockMillis() + underThresholdMillis);
|
||||||
mScript.simulateTimePassing(clockIncrementMillis)
|
mScript.simulateTimePassing(clockIncrementMillis)
|
||||||
.simulatePhoneTimeSuggestion(timeSuggestion2)
|
.simulateTelephonyTimeSuggestion(timeSuggestion2)
|
||||||
.verifySystemClockWasNotSetAndResetCallTracking()
|
.verifySystemClockWasNotSetAndResetCallTracking()
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion2);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now send another time signal, but one that is on the threshold and so should be used.
|
// Now send another time signal, but one that is on the threshold and so should be used.
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion timeSuggestion3 = mScript.generatePhoneTimeSuggestion(
|
TelephonyTimeSuggestion timeSuggestion3 = mScript.generateTelephonyTimeSuggestion(
|
||||||
phoneId,
|
slotIndex,
|
||||||
mScript.peekSystemClockMillis() + systemClockUpdateThresholdMillis);
|
mScript.peekSystemClockMillis() + systemClockUpdateThresholdMillis);
|
||||||
mScript.simulateTimePassing(clockIncrementMillis);
|
mScript.simulateTimePassing(clockIncrementMillis);
|
||||||
|
|
||||||
long expectedSystemClockMillis3 =
|
long expectedSystemClockMillis3 =
|
||||||
mScript.calculateTimeInMillisForNow(timeSuggestion3.getUtcTime());
|
mScript.calculateTimeInMillisForNow(timeSuggestion3.getUtcTime());
|
||||||
|
|
||||||
mScript.simulatePhoneTimeSuggestion(timeSuggestion3)
|
mScript.simulateTelephonyTimeSuggestion(timeSuggestion3)
|
||||||
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis3)
|
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis3)
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion3);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestPhoneTime_multiplePhoneIdsAndBucketing() {
|
public void testSuggestTelephonyTime_multipleSlotIndexsAndBucketing() {
|
||||||
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
||||||
.pokeAutoTimeDetectionEnabled(true);
|
.pokeAutoTimeDetectionEnabled(true);
|
||||||
|
|
||||||
// There are 2 phones in this test. Phone 2 has a different idea of the current time.
|
// There are 2 slotIndexes in this test. slotIndex1 and slotIndex2 have different opinions
|
||||||
// phone1Id < phone2Id (which is important because the strategy uses the lowest ID when
|
// about the current time. slotIndex1 < slotIndex2 (which is important because the strategy
|
||||||
// multiple phone suggestions are available.
|
// uses the lowest slotIndex when multiple telephony suggestions are available.
|
||||||
int phone1Id = ARBITRARY_PHONE_ID;
|
int slotIndex1 = ARBITRARY_SLOT_INDEX;
|
||||||
int phone2Id = ARBITRARY_PHONE_ID + 1;
|
int slotIndex2 = ARBITRARY_SLOT_INDEX + 1;
|
||||||
long phone1TimeMillis = ARBITRARY_TEST_TIME_MILLIS;
|
long slotIndex1TimeMillis = ARBITRARY_TEST_TIME_MILLIS;
|
||||||
long phone2TimeMillis = ARBITRARY_TEST_TIME_MILLIS + Duration.ofDays(1).toMillis();
|
long slotIndex2TimeMillis = ARBITRARY_TEST_TIME_MILLIS + Duration.ofDays(1).toMillis();
|
||||||
|
|
||||||
// Make a suggestion with phone2Id.
|
// Make a suggestion with slotIndex2.
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion phone2TimeSuggestion =
|
TelephonyTimeSuggestion slotIndex2TimeSuggestion =
|
||||||
mScript.generatePhoneTimeSuggestion(phone2Id, phone2TimeMillis);
|
mScript.generateTelephonyTimeSuggestion(slotIndex2, slotIndex2TimeMillis);
|
||||||
mScript.simulateTimePassing();
|
mScript.simulateTimePassing();
|
||||||
|
|
||||||
long expectedSystemClockMillis =
|
long expectedSystemClockMillis =
|
||||||
mScript.calculateTimeInMillisForNow(phone2TimeSuggestion.getUtcTime());
|
mScript.calculateTimeInMillisForNow(slotIndex2TimeSuggestion.getUtcTime());
|
||||||
|
|
||||||
mScript.simulatePhoneTimeSuggestion(phone2TimeSuggestion)
|
mScript.simulateTelephonyTimeSuggestion(slotIndex2TimeSuggestion)
|
||||||
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis)
|
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis)
|
||||||
.assertLatestPhoneSuggestion(phone1Id, null)
|
.assertLatestTelephonySuggestion(slotIndex1, null)
|
||||||
.assertLatestPhoneSuggestion(phone2Id, phone2TimeSuggestion);
|
.assertLatestTelephonySuggestion(slotIndex2, slotIndex2TimeSuggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
mScript.simulateTimePassing();
|
mScript.simulateTimePassing();
|
||||||
|
|
||||||
// Now make a different suggestion with phone1Id.
|
// Now make a different suggestion with slotIndex1.
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion phone1TimeSuggestion =
|
TelephonyTimeSuggestion slotIndex1TimeSuggestion =
|
||||||
mScript.generatePhoneTimeSuggestion(phone1Id, phone1TimeMillis);
|
mScript.generateTelephonyTimeSuggestion(slotIndex1, slotIndex1TimeMillis);
|
||||||
mScript.simulateTimePassing();
|
mScript.simulateTimePassing();
|
||||||
|
|
||||||
long expectedSystemClockMillis =
|
long expectedSystemClockMillis =
|
||||||
mScript.calculateTimeInMillisForNow(phone1TimeSuggestion.getUtcTime());
|
mScript.calculateTimeInMillisForNow(slotIndex1TimeSuggestion.getUtcTime());
|
||||||
|
|
||||||
mScript.simulatePhoneTimeSuggestion(phone1TimeSuggestion)
|
mScript.simulateTelephonyTimeSuggestion(slotIndex1TimeSuggestion)
|
||||||
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis)
|
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis)
|
||||||
.assertLatestPhoneSuggestion(phone1Id, phone1TimeSuggestion);
|
.assertLatestTelephonySuggestion(slotIndex1, slotIndex1TimeSuggestion);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mScript.simulateTimePassing();
|
mScript.simulateTimePassing();
|
||||||
|
|
||||||
// Make another suggestion with phone2Id. It should be stored but not used because the
|
// Make another suggestion with slotIndex2. It should be stored but not used because the
|
||||||
// phone1Id suggestion will still "win".
|
// slotIndex1 suggestion will still "win".
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion phone2TimeSuggestion =
|
TelephonyTimeSuggestion slotIndex2TimeSuggestion =
|
||||||
mScript.generatePhoneTimeSuggestion(phone2Id, phone2TimeMillis);
|
mScript.generateTelephonyTimeSuggestion(slotIndex2, slotIndex2TimeMillis);
|
||||||
mScript.simulateTimePassing();
|
mScript.simulateTimePassing();
|
||||||
|
|
||||||
mScript.simulatePhoneTimeSuggestion(phone2TimeSuggestion)
|
mScript.simulateTelephonyTimeSuggestion(slotIndex2TimeSuggestion)
|
||||||
.verifySystemClockWasNotSetAndResetCallTracking()
|
.verifySystemClockWasNotSetAndResetCallTracking()
|
||||||
.assertLatestPhoneSuggestion(phone2Id, phone2TimeSuggestion);
|
.assertLatestTelephonySuggestion(slotIndex2, slotIndex2TimeSuggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let enough time pass that phone1Id's suggestion should now be too old.
|
// Let enough time pass that slotIndex1's suggestion should now be too old.
|
||||||
mScript.simulateTimePassing(TimeDetectorStrategyImpl.PHONE_BUCKET_SIZE_MILLIS);
|
mScript.simulateTimePassing(TimeDetectorStrategyImpl.TELEPHONY_BUCKET_SIZE_MILLIS);
|
||||||
|
|
||||||
// Make another suggestion with phone2Id. It should be used because the phoneId1
|
// Make another suggestion with slotIndex2. It should be used because the slotIndex1
|
||||||
// is in an older "bucket".
|
// is in an older "bucket".
|
||||||
{
|
{
|
||||||
PhoneTimeSuggestion phone2TimeSuggestion =
|
TelephonyTimeSuggestion slotIndex2TimeSuggestion =
|
||||||
mScript.generatePhoneTimeSuggestion(phone2Id, phone2TimeMillis);
|
mScript.generateTelephonyTimeSuggestion(slotIndex2, slotIndex2TimeMillis);
|
||||||
mScript.simulateTimePassing();
|
mScript.simulateTimePassing();
|
||||||
|
|
||||||
long expectedSystemClockMillis =
|
long expectedSystemClockMillis =
|
||||||
mScript.calculateTimeInMillisForNow(phone2TimeSuggestion.getUtcTime());
|
mScript.calculateTimeInMillisForNow(slotIndex2TimeSuggestion.getUtcTime());
|
||||||
|
|
||||||
mScript.simulatePhoneTimeSuggestion(phone2TimeSuggestion)
|
mScript.simulateTelephonyTimeSuggestion(slotIndex2TimeSuggestion)
|
||||||
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis)
|
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis)
|
||||||
.assertLatestPhoneSuggestion(phone2Id, phone2TimeSuggestion);
|
.assertLatestTelephonySuggestion(slotIndex2, slotIndex2TimeSuggestion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestPhoneTime_autoTimeDisabled() {
|
public void testSuggestTelephonyTime_autoTimeDisabled() {
|
||||||
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
||||||
.pokeAutoTimeDetectionEnabled(false);
|
.pokeAutoTimeDetectionEnabled(false);
|
||||||
|
|
||||||
int phoneId = ARBITRARY_PHONE_ID;
|
int slotIndex = ARBITRARY_SLOT_INDEX;
|
||||||
PhoneTimeSuggestion timeSuggestion =
|
TelephonyTimeSuggestion timeSuggestion =
|
||||||
mScript.generatePhoneTimeSuggestion(phoneId, ARBITRARY_TEST_TIME_MILLIS);
|
mScript.generateTelephonyTimeSuggestion(slotIndex, ARBITRARY_TEST_TIME_MILLIS);
|
||||||
mScript.simulateTimePassing()
|
mScript.simulateTimePassing()
|
||||||
.simulatePhoneTimeSuggestion(timeSuggestion)
|
.simulateTelephonyTimeSuggestion(timeSuggestion)
|
||||||
.verifySystemClockWasNotSetAndResetCallTracking()
|
.verifySystemClockWasNotSetAndResetCallTracking()
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestPhoneTime_invalidNitzReferenceTimesIgnored() {
|
public void testSuggestTelephonyTime_invalidNitzReferenceTimesIgnored() {
|
||||||
final int systemClockUpdateThreshold = 2000;
|
final int systemClockUpdateThreshold = 2000;
|
||||||
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
||||||
.pokeThresholds(systemClockUpdateThreshold)
|
.pokeThresholds(systemClockUpdateThreshold)
|
||||||
.pokeAutoTimeDetectionEnabled(true);
|
.pokeAutoTimeDetectionEnabled(true);
|
||||||
|
|
||||||
long testTimeMillis = ARBITRARY_TEST_TIME_MILLIS;
|
long testTimeMillis = ARBITRARY_TEST_TIME_MILLIS;
|
||||||
int phoneId = ARBITRARY_PHONE_ID;
|
int slotIndex = ARBITRARY_SLOT_INDEX;
|
||||||
|
|
||||||
PhoneTimeSuggestion timeSuggestion1 =
|
TelephonyTimeSuggestion timeSuggestion1 =
|
||||||
mScript.generatePhoneTimeSuggestion(phoneId, testTimeMillis);
|
mScript.generateTelephonyTimeSuggestion(slotIndex, testTimeMillis);
|
||||||
TimestampedValue<Long> utcTime1 = timeSuggestion1.getUtcTime();
|
TimestampedValue<Long> utcTime1 = timeSuggestion1.getUtcTime();
|
||||||
|
|
||||||
// Initialize the strategy / device with a time set from a phone suggestion.
|
// Initialize the strategy / device with a time set from a telephony suggestion.
|
||||||
mScript.simulateTimePassing();
|
mScript.simulateTimePassing();
|
||||||
long expectedSystemClockMillis1 = mScript.calculateTimeInMillisForNow(utcTime1);
|
long expectedSystemClockMillis1 = mScript.calculateTimeInMillisForNow(utcTime1);
|
||||||
mScript.simulatePhoneTimeSuggestion(timeSuggestion1)
|
mScript.simulateTelephonyTimeSuggestion(timeSuggestion1)
|
||||||
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis1)
|
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis1)
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion1);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion1);
|
||||||
|
|
||||||
// The UTC time increment should be larger than the system clock update threshold so we
|
// The UTC time increment should be larger than the system clock update threshold so we
|
||||||
// know it shouldn't be ignored for other reasons.
|
// know it shouldn't be ignored for other reasons.
|
||||||
@@ -269,11 +269,11 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
long referenceTimeBeforeLastSignalMillis = utcTime1.getReferenceTimeMillis() - 1;
|
long referenceTimeBeforeLastSignalMillis = utcTime1.getReferenceTimeMillis() - 1;
|
||||||
TimestampedValue<Long> utcTime2 = new TimestampedValue<>(
|
TimestampedValue<Long> utcTime2 = new TimestampedValue<>(
|
||||||
referenceTimeBeforeLastSignalMillis, validUtcTimeMillis);
|
referenceTimeBeforeLastSignalMillis, validUtcTimeMillis);
|
||||||
PhoneTimeSuggestion timeSuggestion2 =
|
TelephonyTimeSuggestion timeSuggestion2 =
|
||||||
createPhoneTimeSuggestion(phoneId, utcTime2);
|
createTelephonyTimeSuggestion(slotIndex, utcTime2);
|
||||||
mScript.simulatePhoneTimeSuggestion(timeSuggestion2)
|
mScript.simulateTelephonyTimeSuggestion(timeSuggestion2)
|
||||||
.verifySystemClockWasNotSetAndResetCallTracking()
|
.verifySystemClockWasNotSetAndResetCallTracking()
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion1);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion1);
|
||||||
|
|
||||||
// Now supply a new signal that has an obviously bogus reference time : substantially in the
|
// Now supply a new signal that has an obviously bogus reference time : substantially in the
|
||||||
// future.
|
// future.
|
||||||
@@ -281,36 +281,36 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
utcTime1.getReferenceTimeMillis() + Integer.MAX_VALUE + 1;
|
utcTime1.getReferenceTimeMillis() + Integer.MAX_VALUE + 1;
|
||||||
TimestampedValue<Long> utcTime3 = new TimestampedValue<>(
|
TimestampedValue<Long> utcTime3 = new TimestampedValue<>(
|
||||||
referenceTimeInFutureMillis, validUtcTimeMillis);
|
referenceTimeInFutureMillis, validUtcTimeMillis);
|
||||||
PhoneTimeSuggestion timeSuggestion3 =
|
TelephonyTimeSuggestion timeSuggestion3 =
|
||||||
createPhoneTimeSuggestion(phoneId, utcTime3);
|
createTelephonyTimeSuggestion(slotIndex, utcTime3);
|
||||||
mScript.simulatePhoneTimeSuggestion(timeSuggestion3)
|
mScript.simulateTelephonyTimeSuggestion(timeSuggestion3)
|
||||||
.verifySystemClockWasNotSetAndResetCallTracking()
|
.verifySystemClockWasNotSetAndResetCallTracking()
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion1);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion1);
|
||||||
|
|
||||||
// Just to prove validUtcTimeMillis is valid.
|
// Just to prove validUtcTimeMillis is valid.
|
||||||
long validReferenceTimeMillis = utcTime1.getReferenceTimeMillis() + 100;
|
long validReferenceTimeMillis = utcTime1.getReferenceTimeMillis() + 100;
|
||||||
TimestampedValue<Long> utcTime4 = new TimestampedValue<>(
|
TimestampedValue<Long> utcTime4 = new TimestampedValue<>(
|
||||||
validReferenceTimeMillis, validUtcTimeMillis);
|
validReferenceTimeMillis, validUtcTimeMillis);
|
||||||
long expectedSystemClockMillis4 = mScript.calculateTimeInMillisForNow(utcTime4);
|
long expectedSystemClockMillis4 = mScript.calculateTimeInMillisForNow(utcTime4);
|
||||||
PhoneTimeSuggestion timeSuggestion4 =
|
TelephonyTimeSuggestion timeSuggestion4 =
|
||||||
createPhoneTimeSuggestion(phoneId, utcTime4);
|
createTelephonyTimeSuggestion(slotIndex, utcTime4);
|
||||||
mScript.simulatePhoneTimeSuggestion(timeSuggestion4)
|
mScript.simulateTelephonyTimeSuggestion(timeSuggestion4)
|
||||||
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis4)
|
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis4)
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion4);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestPhoneTime_timeDetectionToggled() {
|
public void testSuggestTelephonyTime_timeDetectionToggled() {
|
||||||
final int clockIncrementMillis = 100;
|
final int clockIncrementMillis = 100;
|
||||||
final int systemClockUpdateThreshold = 2000;
|
final int systemClockUpdateThreshold = 2000;
|
||||||
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
||||||
.pokeThresholds(systemClockUpdateThreshold)
|
.pokeThresholds(systemClockUpdateThreshold)
|
||||||
.pokeAutoTimeDetectionEnabled(false);
|
.pokeAutoTimeDetectionEnabled(false);
|
||||||
|
|
||||||
int phoneId = ARBITRARY_PHONE_ID;
|
int slotIndex = ARBITRARY_SLOT_INDEX;
|
||||||
long testTimeMillis = ARBITRARY_TEST_TIME_MILLIS;
|
long testTimeMillis = ARBITRARY_TEST_TIME_MILLIS;
|
||||||
PhoneTimeSuggestion timeSuggestion1 =
|
TelephonyTimeSuggestion timeSuggestion1 =
|
||||||
mScript.generatePhoneTimeSuggestion(phoneId, testTimeMillis);
|
mScript.generateTelephonyTimeSuggestion(slotIndex, testTimeMillis);
|
||||||
TimestampedValue<Long> utcTime1 = timeSuggestion1.getUtcTime();
|
TimestampedValue<Long> utcTime1 = timeSuggestion1.getUtcTime();
|
||||||
|
|
||||||
// Simulate time passing.
|
// Simulate time passing.
|
||||||
@@ -318,9 +318,9 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
|
|
||||||
// Simulate the time signal being received. It should not be used because auto time
|
// Simulate the time signal being received. It should not be used because auto time
|
||||||
// detection is off but it should be recorded.
|
// detection is off but it should be recorded.
|
||||||
mScript.simulatePhoneTimeSuggestion(timeSuggestion1)
|
mScript.simulateTelephonyTimeSuggestion(timeSuggestion1)
|
||||||
.verifySystemClockWasNotSetAndResetCallTracking()
|
.verifySystemClockWasNotSetAndResetCallTracking()
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion1);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion1);
|
||||||
|
|
||||||
// Simulate more time passing.
|
// Simulate more time passing.
|
||||||
mScript.simulateTimePassing(clockIncrementMillis);
|
mScript.simulateTimePassing(clockIncrementMillis);
|
||||||
@@ -330,17 +330,17 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
// Turn on auto time detection.
|
// Turn on auto time detection.
|
||||||
mScript.simulateAutoTimeDetectionToggle()
|
mScript.simulateAutoTimeDetectionToggle()
|
||||||
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis1)
|
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis1)
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion1);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion1);
|
||||||
|
|
||||||
// Turn off auto time detection.
|
// Turn off auto time detection.
|
||||||
mScript.simulateAutoTimeDetectionToggle()
|
mScript.simulateAutoTimeDetectionToggle()
|
||||||
.verifySystemClockWasNotSetAndResetCallTracking()
|
.verifySystemClockWasNotSetAndResetCallTracking()
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion1);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion1);
|
||||||
|
|
||||||
// Receive another valid time signal.
|
// Receive another valid time signal.
|
||||||
// It should be on the threshold and accounting for the clock increments.
|
// It should be on the threshold and accounting for the clock increments.
|
||||||
PhoneTimeSuggestion timeSuggestion2 = mScript.generatePhoneTimeSuggestion(
|
TelephonyTimeSuggestion timeSuggestion2 = mScript.generateTelephonyTimeSuggestion(
|
||||||
phoneId, mScript.peekSystemClockMillis() + systemClockUpdateThreshold);
|
slotIndex, mScript.peekSystemClockMillis() + systemClockUpdateThreshold);
|
||||||
|
|
||||||
// Simulate more time passing.
|
// Simulate more time passing.
|
||||||
mScript.simulateTimePassing(clockIncrementMillis);
|
mScript.simulateTimePassing(clockIncrementMillis);
|
||||||
@@ -350,45 +350,45 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
|
|
||||||
// The new time, though valid, should not be set in the system clock because auto time is
|
// The new time, though valid, should not be set in the system clock because auto time is
|
||||||
// disabled.
|
// disabled.
|
||||||
mScript.simulatePhoneTimeSuggestion(timeSuggestion2)
|
mScript.simulateTelephonyTimeSuggestion(timeSuggestion2)
|
||||||
.verifySystemClockWasNotSetAndResetCallTracking()
|
.verifySystemClockWasNotSetAndResetCallTracking()
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion2);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion2);
|
||||||
|
|
||||||
// Turn on auto time detection.
|
// Turn on auto time detection.
|
||||||
mScript.simulateAutoTimeDetectionToggle()
|
mScript.simulateAutoTimeDetectionToggle()
|
||||||
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis2)
|
.verifySystemClockWasSetAndResetCallTracking(expectedSystemClockMillis2)
|
||||||
.assertLatestPhoneSuggestion(phoneId, timeSuggestion2);
|
.assertLatestTelephonySuggestion(slotIndex, timeSuggestion2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestPhoneTime_maxSuggestionAge() {
|
public void testSuggestTelephonyTime_maxSuggestionAge() {
|
||||||
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
||||||
.pokeAutoTimeDetectionEnabled(true);
|
.pokeAutoTimeDetectionEnabled(true);
|
||||||
|
|
||||||
int phoneId = ARBITRARY_PHONE_ID;
|
int slotIndex = ARBITRARY_SLOT_INDEX;
|
||||||
long testTimeMillis = ARBITRARY_TEST_TIME_MILLIS;
|
long testTimeMillis = ARBITRARY_TEST_TIME_MILLIS;
|
||||||
PhoneTimeSuggestion phoneSuggestion =
|
TelephonyTimeSuggestion telephonySuggestion =
|
||||||
mScript.generatePhoneTimeSuggestion(phoneId, testTimeMillis);
|
mScript.generateTelephonyTimeSuggestion(slotIndex, testTimeMillis);
|
||||||
|
|
||||||
mScript.simulateTimePassing();
|
mScript.simulateTimePassing();
|
||||||
|
|
||||||
long expectedSystemClockMillis =
|
long expectedSystemClockMillis =
|
||||||
mScript.calculateTimeInMillisForNow(phoneSuggestion.getUtcTime());
|
mScript.calculateTimeInMillisForNow(telephonySuggestion.getUtcTime());
|
||||||
mScript.simulatePhoneTimeSuggestion(phoneSuggestion)
|
mScript.simulateTelephonyTimeSuggestion(telephonySuggestion)
|
||||||
.verifySystemClockWasSetAndResetCallTracking(
|
.verifySystemClockWasSetAndResetCallTracking(
|
||||||
expectedSystemClockMillis /* expectedNetworkBroadcast */)
|
expectedSystemClockMillis /* expectedNetworkBroadcast */)
|
||||||
.assertLatestPhoneSuggestion(phoneId, phoneSuggestion);
|
.assertLatestTelephonySuggestion(slotIndex, telephonySuggestion);
|
||||||
|
|
||||||
// Look inside and check what the strategy considers the current best phone suggestion.
|
// Look inside and check what the strategy considers the current best telephony suggestion.
|
||||||
assertEquals(phoneSuggestion, mScript.peekBestPhoneSuggestion());
|
assertEquals(telephonySuggestion, mScript.peekBestTelephonySuggestion());
|
||||||
|
|
||||||
// Simulate time passing, long enough that phoneSuggestion is now too old.
|
// Simulate time passing, long enough that telephonySuggestion is now too old.
|
||||||
mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS);
|
mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS);
|
||||||
|
|
||||||
// Look inside and check what the strategy considers the current best phone suggestion. It
|
// Look inside and check what the strategy considers the current best telephony suggestion.
|
||||||
// should still be the, it's just no longer used.
|
// It should still be the, it's just no longer used.
|
||||||
assertNull(mScript.peekBestPhoneSuggestion());
|
assertNull(mScript.peekBestTelephonySuggestion());
|
||||||
mScript.assertLatestPhoneSuggestion(phoneId, phoneSuggestion);
|
mScript.assertLatestTelephonySuggestion(slotIndex, telephonySuggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -413,21 +413,21 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
||||||
.pokeAutoTimeDetectionEnabled(true);
|
.pokeAutoTimeDetectionEnabled(true);
|
||||||
|
|
||||||
int phoneId = ARBITRARY_PHONE_ID;
|
int slotIndex = ARBITRARY_SLOT_INDEX;
|
||||||
|
|
||||||
// Simulate a phone suggestion.
|
// Simulate a telephony suggestion.
|
||||||
long testTimeMillis = ARBITRARY_TEST_TIME_MILLIS;
|
long testTimeMillis = ARBITRARY_TEST_TIME_MILLIS;
|
||||||
PhoneTimeSuggestion phoneTimeSuggestion =
|
TelephonyTimeSuggestion telephonyTimeSuggestion =
|
||||||
mScript.generatePhoneTimeSuggestion(phoneId, testTimeMillis);
|
mScript.generateTelephonyTimeSuggestion(slotIndex, testTimeMillis);
|
||||||
|
|
||||||
// Simulate the passage of time.
|
// Simulate the passage of time.
|
||||||
mScript.simulateTimePassing();
|
mScript.simulateTimePassing();
|
||||||
|
|
||||||
long expectedAutoClockMillis =
|
long expectedAutoClockMillis =
|
||||||
mScript.calculateTimeInMillisForNow(phoneTimeSuggestion.getUtcTime());
|
mScript.calculateTimeInMillisForNow(telephonyTimeSuggestion.getUtcTime());
|
||||||
mScript.simulatePhoneTimeSuggestion(phoneTimeSuggestion)
|
mScript.simulateTelephonyTimeSuggestion(telephonyTimeSuggestion)
|
||||||
.verifySystemClockWasSetAndResetCallTracking(expectedAutoClockMillis)
|
.verifySystemClockWasSetAndResetCallTracking(expectedAutoClockMillis)
|
||||||
.assertLatestPhoneSuggestion(phoneId, phoneTimeSuggestion);
|
.assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion);
|
||||||
|
|
||||||
// Simulate the passage of time.
|
// Simulate the passage of time.
|
||||||
mScript.simulateTimePassing();
|
mScript.simulateTimePassing();
|
||||||
@@ -435,7 +435,7 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
// Switch to manual.
|
// Switch to manual.
|
||||||
mScript.simulateAutoTimeDetectionToggle()
|
mScript.simulateAutoTimeDetectionToggle()
|
||||||
.verifySystemClockWasNotSetAndResetCallTracking()
|
.verifySystemClockWasNotSetAndResetCallTracking()
|
||||||
.assertLatestPhoneSuggestion(phoneId, phoneTimeSuggestion);
|
.assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion);
|
||||||
|
|
||||||
// Simulate the passage of time.
|
// Simulate the passage of time.
|
||||||
mScript.simulateTimePassing();
|
mScript.simulateTimePassing();
|
||||||
@@ -450,7 +450,7 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
mScript.calculateTimeInMillisForNow(manualTimeSuggestion.getUtcTime());
|
mScript.calculateTimeInMillisForNow(manualTimeSuggestion.getUtcTime());
|
||||||
mScript.simulateManualTimeSuggestion(manualTimeSuggestion)
|
mScript.simulateManualTimeSuggestion(manualTimeSuggestion)
|
||||||
.verifySystemClockWasSetAndResetCallTracking(expectedManualClockMillis)
|
.verifySystemClockWasSetAndResetCallTracking(expectedManualClockMillis)
|
||||||
.assertLatestPhoneSuggestion(phoneId, phoneTimeSuggestion);
|
.assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion);
|
||||||
|
|
||||||
// Simulate the passage of time.
|
// Simulate the passage of time.
|
||||||
mScript.simulateTimePassing();
|
mScript.simulateTimePassing();
|
||||||
@@ -459,14 +459,14 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
mScript.simulateAutoTimeDetectionToggle();
|
mScript.simulateAutoTimeDetectionToggle();
|
||||||
|
|
||||||
expectedAutoClockMillis =
|
expectedAutoClockMillis =
|
||||||
mScript.calculateTimeInMillisForNow(phoneTimeSuggestion.getUtcTime());
|
mScript.calculateTimeInMillisForNow(telephonyTimeSuggestion.getUtcTime());
|
||||||
mScript.verifySystemClockWasSetAndResetCallTracking(expectedAutoClockMillis)
|
mScript.verifySystemClockWasSetAndResetCallTracking(expectedAutoClockMillis)
|
||||||
.assertLatestPhoneSuggestion(phoneId, phoneTimeSuggestion);
|
.assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion);
|
||||||
|
|
||||||
// Switch back to manual - nothing should happen to the clock.
|
// Switch back to manual - nothing should happen to the clock.
|
||||||
mScript.simulateAutoTimeDetectionToggle()
|
mScript.simulateAutoTimeDetectionToggle()
|
||||||
.verifySystemClockWasNotSetAndResetCallTracking()
|
.verifySystemClockWasNotSetAndResetCallTracking()
|
||||||
.assertLatestPhoneSuggestion(phoneId, phoneTimeSuggestion);
|
.assertLatestTelephonySuggestion(slotIndex, telephonyTimeSuggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -515,19 +515,19 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestNetworkTime_phoneSuggestionsBeatNetworkSuggestions() {
|
public void testSuggestNetworkTime_telephonySuggestionsBeatNetworkSuggestions() {
|
||||||
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
mScript.pokeFakeClocks(ARBITRARY_CLOCK_INITIALIZATION_INFO)
|
||||||
.pokeAutoTimeDetectionEnabled(true);
|
.pokeAutoTimeDetectionEnabled(true);
|
||||||
|
|
||||||
// Three obviously different times that could not be mistaken for each other.
|
// Three obviously different times that could not be mistaken for each other.
|
||||||
long networkTimeMillis1 = ARBITRARY_TEST_TIME_MILLIS;
|
long networkTimeMillis1 = ARBITRARY_TEST_TIME_MILLIS;
|
||||||
long networkTimeMillis2 = ARBITRARY_TEST_TIME_MILLIS + Duration.ofDays(30).toMillis();
|
long networkTimeMillis2 = ARBITRARY_TEST_TIME_MILLIS + Duration.ofDays(30).toMillis();
|
||||||
long phoneTimeMillis = ARBITRARY_TEST_TIME_MILLIS + Duration.ofDays(60).toMillis();
|
long telephonyTimeMillis = ARBITRARY_TEST_TIME_MILLIS + Duration.ofDays(60).toMillis();
|
||||||
// A small increment used to simulate the passage of time, but not enough to interfere with
|
// A small increment used to simulate the passage of time, but not enough to interfere with
|
||||||
// macro-level time changes associated with suggestion age.
|
// macro-level time changes associated with suggestion age.
|
||||||
final long smallTimeIncrementMillis = 101;
|
final long smallTimeIncrementMillis = 101;
|
||||||
|
|
||||||
// A network suggestion is made. It should be used because there is no phone suggestion.
|
// A network suggestion is made. It should be used because there is no telephony suggestion.
|
||||||
NetworkTimeSuggestion networkTimeSuggestion1 =
|
NetworkTimeSuggestion networkTimeSuggestion1 =
|
||||||
mScript.generateNetworkTimeSuggestion(networkTimeMillis1);
|
mScript.generateNetworkTimeSuggestion(networkTimeMillis1);
|
||||||
mScript.simulateTimePassing(smallTimeIncrementMillis)
|
mScript.simulateTimePassing(smallTimeIncrementMillis)
|
||||||
@@ -536,37 +536,37 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
mScript.calculateTimeInMillisForNow(networkTimeSuggestion1.getUtcTime()));
|
mScript.calculateTimeInMillisForNow(networkTimeSuggestion1.getUtcTime()));
|
||||||
|
|
||||||
// Check internal state.
|
// Check internal state.
|
||||||
mScript.assertLatestPhoneSuggestion(ARBITRARY_PHONE_ID, null)
|
mScript.assertLatestTelephonySuggestion(ARBITRARY_SLOT_INDEX, null)
|
||||||
.assertLatestNetworkSuggestion(networkTimeSuggestion1);
|
.assertLatestNetworkSuggestion(networkTimeSuggestion1);
|
||||||
assertEquals(networkTimeSuggestion1, mScript.peekLatestValidNetworkSuggestion());
|
assertEquals(networkTimeSuggestion1, mScript.peekLatestValidNetworkSuggestion());
|
||||||
assertNull(mScript.peekBestPhoneSuggestion());
|
assertNull(mScript.peekBestTelephonySuggestion());
|
||||||
|
|
||||||
// Simulate a little time passing.
|
// Simulate a little time passing.
|
||||||
mScript.simulateTimePassing(smallTimeIncrementMillis)
|
mScript.simulateTimePassing(smallTimeIncrementMillis)
|
||||||
.verifySystemClockWasNotSetAndResetCallTracking();
|
.verifySystemClockWasNotSetAndResetCallTracking();
|
||||||
|
|
||||||
// Now a phone suggestion is made. Phone suggestions are prioritized over network
|
// Now a telephony suggestion is made. Telephony suggestions are prioritized over network
|
||||||
// suggestions so it should "win".
|
// suggestions so it should "win".
|
||||||
PhoneTimeSuggestion phoneTimeSuggestion =
|
TelephonyTimeSuggestion telephonyTimeSuggestion =
|
||||||
mScript.generatePhoneTimeSuggestion(ARBITRARY_PHONE_ID, phoneTimeMillis);
|
mScript.generateTelephonyTimeSuggestion(ARBITRARY_SLOT_INDEX, telephonyTimeMillis);
|
||||||
mScript.simulateTimePassing(smallTimeIncrementMillis)
|
mScript.simulateTimePassing(smallTimeIncrementMillis)
|
||||||
.simulatePhoneTimeSuggestion(phoneTimeSuggestion)
|
.simulateTelephonyTimeSuggestion(telephonyTimeSuggestion)
|
||||||
.verifySystemClockWasSetAndResetCallTracking(
|
.verifySystemClockWasSetAndResetCallTracking(
|
||||||
mScript.calculateTimeInMillisForNow(phoneTimeSuggestion.getUtcTime()));
|
mScript.calculateTimeInMillisForNow(telephonyTimeSuggestion.getUtcTime()));
|
||||||
|
|
||||||
// Check internal state.
|
// Check internal state.
|
||||||
mScript.assertLatestPhoneSuggestion(ARBITRARY_PHONE_ID, phoneTimeSuggestion)
|
mScript.assertLatestTelephonySuggestion(ARBITRARY_SLOT_INDEX, telephonyTimeSuggestion)
|
||||||
.assertLatestNetworkSuggestion(networkTimeSuggestion1);
|
.assertLatestNetworkSuggestion(networkTimeSuggestion1);
|
||||||
assertEquals(networkTimeSuggestion1, mScript.peekLatestValidNetworkSuggestion());
|
assertEquals(networkTimeSuggestion1, mScript.peekLatestValidNetworkSuggestion());
|
||||||
assertEquals(phoneTimeSuggestion, mScript.peekBestPhoneSuggestion());
|
assertEquals(telephonyTimeSuggestion, mScript.peekBestTelephonySuggestion());
|
||||||
|
|
||||||
// Simulate some significant time passing: half the time allowed before a time signal
|
// Simulate some significant time passing: half the time allowed before a time signal
|
||||||
// becomes "too old to use".
|
// becomes "too old to use".
|
||||||
mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS / 2)
|
mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS / 2)
|
||||||
.verifySystemClockWasNotSetAndResetCallTracking();
|
.verifySystemClockWasNotSetAndResetCallTracking();
|
||||||
|
|
||||||
// Now another network suggestion is made. Phone suggestions are prioritized over network
|
// Now another network suggestion is made. Telephony suggestions are prioritized over
|
||||||
// suggestions so the latest phone suggestion should still "win".
|
// network suggestions so the latest telephony suggestion should still "win".
|
||||||
NetworkTimeSuggestion networkTimeSuggestion2 =
|
NetworkTimeSuggestion networkTimeSuggestion2 =
|
||||||
mScript.generateNetworkTimeSuggestion(networkTimeMillis2);
|
mScript.generateNetworkTimeSuggestion(networkTimeMillis2);
|
||||||
mScript.simulateTimePassing(smallTimeIncrementMillis)
|
mScript.simulateTimePassing(smallTimeIncrementMillis)
|
||||||
@@ -574,14 +574,14 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
.verifySystemClockWasNotSetAndResetCallTracking();
|
.verifySystemClockWasNotSetAndResetCallTracking();
|
||||||
|
|
||||||
// Check internal state.
|
// Check internal state.
|
||||||
mScript.assertLatestPhoneSuggestion(ARBITRARY_PHONE_ID, phoneTimeSuggestion)
|
mScript.assertLatestTelephonySuggestion(ARBITRARY_SLOT_INDEX, telephonyTimeSuggestion)
|
||||||
.assertLatestNetworkSuggestion(networkTimeSuggestion2);
|
.assertLatestNetworkSuggestion(networkTimeSuggestion2);
|
||||||
assertEquals(networkTimeSuggestion2, mScript.peekLatestValidNetworkSuggestion());
|
assertEquals(networkTimeSuggestion2, mScript.peekLatestValidNetworkSuggestion());
|
||||||
assertEquals(phoneTimeSuggestion, mScript.peekBestPhoneSuggestion());
|
assertEquals(telephonyTimeSuggestion, mScript.peekBestTelephonySuggestion());
|
||||||
|
|
||||||
// Simulate some significant time passing: half the time allowed before a time signal
|
// Simulate some significant time passing: half the time allowed before a time signal
|
||||||
// becomes "too old to use". This should mean that phoneTimeSuggestion is now too old to be
|
// becomes "too old to use". This should mean that telephonyTimeSuggestion is now too old to
|
||||||
// used but networkTimeSuggestion2 is not.
|
// be used but networkTimeSuggestion2 is not.
|
||||||
mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS / 2);
|
mScript.simulateTimePassing(TimeDetectorStrategyImpl.MAX_UTC_TIME_AGE_MILLIS / 2);
|
||||||
|
|
||||||
// NOTE: The TimeDetectorStrategyImpl doesn't set an alarm for the point when the last
|
// NOTE: The TimeDetectorStrategyImpl doesn't set an alarm for the point when the last
|
||||||
@@ -591,10 +591,10 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
mScript.verifySystemClockWasNotSetAndResetCallTracking();
|
mScript.verifySystemClockWasNotSetAndResetCallTracking();
|
||||||
|
|
||||||
// Check internal state.
|
// Check internal state.
|
||||||
mScript.assertLatestPhoneSuggestion(ARBITRARY_PHONE_ID, phoneTimeSuggestion)
|
mScript.assertLatestTelephonySuggestion(ARBITRARY_SLOT_INDEX, telephonyTimeSuggestion)
|
||||||
.assertLatestNetworkSuggestion(networkTimeSuggestion2);
|
.assertLatestNetworkSuggestion(networkTimeSuggestion2);
|
||||||
assertEquals(networkTimeSuggestion2, mScript.peekLatestValidNetworkSuggestion());
|
assertEquals(networkTimeSuggestion2, mScript.peekLatestValidNetworkSuggestion());
|
||||||
assertNull(mScript.peekBestPhoneSuggestion());
|
assertNull(mScript.peekBestTelephonySuggestion());
|
||||||
|
|
||||||
// Toggle auto-time off and on to force the detection logic to run.
|
// Toggle auto-time off and on to force the detection logic to run.
|
||||||
mScript.simulateAutoTimeDetectionToggle()
|
mScript.simulateAutoTimeDetectionToggle()
|
||||||
@@ -606,10 +606,10 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
mScript.calculateTimeInMillisForNow(networkTimeSuggestion2.getUtcTime()));
|
mScript.calculateTimeInMillisForNow(networkTimeSuggestion2.getUtcTime()));
|
||||||
|
|
||||||
// Check internal state.
|
// Check internal state.
|
||||||
mScript.assertLatestPhoneSuggestion(ARBITRARY_PHONE_ID, phoneTimeSuggestion)
|
mScript.assertLatestTelephonySuggestion(ARBITRARY_SLOT_INDEX, telephonyTimeSuggestion)
|
||||||
.assertLatestNetworkSuggestion(networkTimeSuggestion2);
|
.assertLatestNetworkSuggestion(networkTimeSuggestion2);
|
||||||
assertEquals(networkTimeSuggestion2, mScript.peekLatestValidNetworkSuggestion());
|
assertEquals(networkTimeSuggestion2, mScript.peekLatestValidNetworkSuggestion());
|
||||||
assertNull(mScript.peekBestPhoneSuggestion());
|
assertNull(mScript.peekBestTelephonySuggestion());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -760,8 +760,8 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
return mFakeCallback.peekSystemClockMillis();
|
return mFakeCallback.peekSystemClockMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
Script simulatePhoneTimeSuggestion(PhoneTimeSuggestion timeSuggestion) {
|
Script simulateTelephonyTimeSuggestion(TelephonyTimeSuggestion timeSuggestion) {
|
||||||
mTimeDetectorStrategy.suggestPhoneTime(timeSuggestion);
|
mTimeDetectorStrategy.suggestTelephonyTime(timeSuggestion);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -806,10 +806,10 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* White box test info: Asserts the latest suggestion for the phone ID is as expected.
|
* White box test info: Asserts the latest suggestion for the slotIndex is as expected.
|
||||||
*/
|
*/
|
||||||
Script assertLatestPhoneSuggestion(int phoneId, PhoneTimeSuggestion expected) {
|
Script assertLatestTelephonySuggestion(int slotIndex, TelephonyTimeSuggestion expected) {
|
||||||
assertEquals(expected, mTimeDetectorStrategy.getLatestPhoneSuggestion(phoneId));
|
assertEquals(expected, mTimeDetectorStrategy.getLatestTelephonySuggestion(slotIndex));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -822,11 +822,11 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* White box test info: Returns the phone suggestion that would be used, if any, given the
|
* White box test info: Returns the telephony suggestion that would be used, if any, given
|
||||||
* current elapsed real time clock and regardless of origin prioritization.
|
* the current elapsed real time clock and regardless of origin prioritization.
|
||||||
*/
|
*/
|
||||||
PhoneTimeSuggestion peekBestPhoneSuggestion() {
|
TelephonyTimeSuggestion peekBestTelephonySuggestion() {
|
||||||
return mTimeDetectorStrategy.findBestPhoneSuggestionForTests();
|
return mTimeDetectorStrategy.findBestTelephonySuggestionForTests();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -848,15 +848,15 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a PhoneTimeSuggestion using the current elapsed realtime clock for the
|
* Generates a {@link TelephonyTimeSuggestion} using the current elapsed realtime clock for
|
||||||
* reference time.
|
* the reference time.
|
||||||
*/
|
*/
|
||||||
PhoneTimeSuggestion generatePhoneTimeSuggestion(int phoneId, Long timeMillis) {
|
TelephonyTimeSuggestion generateTelephonyTimeSuggestion(int slotIndex, Long timeMillis) {
|
||||||
TimestampedValue<Long> time = null;
|
TimestampedValue<Long> time = null;
|
||||||
if (timeMillis != null) {
|
if (timeMillis != null) {
|
||||||
time = new TimestampedValue<>(peekElapsedRealtimeMillis(), timeMillis);
|
time = new TimestampedValue<>(peekElapsedRealtimeMillis(), timeMillis);
|
||||||
}
|
}
|
||||||
return createPhoneTimeSuggestion(phoneId, time);
|
return createTelephonyTimeSuggestion(slotIndex, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -878,9 +878,9 @@ public class TimeDetectorStrategyImplTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PhoneTimeSuggestion createPhoneTimeSuggestion(int phoneId,
|
private static TelephonyTimeSuggestion createTelephonyTimeSuggestion(int slotIndex,
|
||||||
TimestampedValue<Long> utcTime) {
|
TimestampedValue<Long> utcTime) {
|
||||||
return new PhoneTimeSuggestion.Builder(phoneId)
|
return new TelephonyTimeSuggestion.Builder(slotIndex)
|
||||||
.setUtcTime(utcTime)
|
.setUtcTime(utcTime)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import static org.mockito.Mockito.verify;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.timezonedetector.ManualTimeZoneSuggestion;
|
import android.app.timezonedetector.ManualTimeZoneSuggestion;
|
||||||
import android.app.timezonedetector.PhoneTimeZoneSuggestion;
|
import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
@@ -76,35 +76,35 @@ public class TimeZoneDetectorServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = SecurityException.class)
|
@Test(expected = SecurityException.class)
|
||||||
public void testSuggestPhoneTime_withoutPermission() {
|
public void testSuggestTelephonyTime_withoutPermission() {
|
||||||
doThrow(new SecurityException("Mock"))
|
doThrow(new SecurityException("Mock"))
|
||||||
.when(mMockContext).enforceCallingPermission(anyString(), any());
|
.when(mMockContext).enforceCallingPermission(anyString(), any());
|
||||||
PhoneTimeZoneSuggestion timeZoneSuggestion = createPhoneTimeZoneSuggestion();
|
TelephonyTimeZoneSuggestion timeZoneSuggestion = createTelephonyTimeZoneSuggestion();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mTimeZoneDetectorService.suggestPhoneTimeZone(timeZoneSuggestion);
|
mTimeZoneDetectorService.suggestTelephonyTimeZone(timeZoneSuggestion);
|
||||||
fail();
|
fail();
|
||||||
} finally {
|
} finally {
|
||||||
verify(mMockContext).enforceCallingPermission(
|
verify(mMockContext).enforceCallingPermission(
|
||||||
eq(android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE),
|
eq(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE),
|
||||||
anyString());
|
anyString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestPhoneTimeZone() throws Exception {
|
public void testSuggestTelephonyTimeZone() throws Exception {
|
||||||
doNothing().when(mMockContext).enforceCallingPermission(anyString(), any());
|
doNothing().when(mMockContext).enforceCallingPermission(anyString(), any());
|
||||||
|
|
||||||
PhoneTimeZoneSuggestion timeZoneSuggestion = createPhoneTimeZoneSuggestion();
|
TelephonyTimeZoneSuggestion timeZoneSuggestion = createTelephonyTimeZoneSuggestion();
|
||||||
mTimeZoneDetectorService.suggestPhoneTimeZone(timeZoneSuggestion);
|
mTimeZoneDetectorService.suggestTelephonyTimeZone(timeZoneSuggestion);
|
||||||
mTestHandler.assertTotalMessagesEnqueued(1);
|
mTestHandler.assertTotalMessagesEnqueued(1);
|
||||||
|
|
||||||
verify(mMockContext).enforceCallingPermission(
|
verify(mMockContext).enforceCallingPermission(
|
||||||
eq(android.Manifest.permission.SUGGEST_PHONE_TIME_AND_ZONE),
|
eq(android.Manifest.permission.SUGGEST_TELEPHONY_TIME_AND_ZONE),
|
||||||
anyString());
|
anyString());
|
||||||
|
|
||||||
mTestHandler.waitForMessagesToBeProcessed();
|
mTestHandler.waitForMessagesToBeProcessed();
|
||||||
mStubbedTimeZoneDetectorStrategy.verifySuggestPhoneTimeZoneCalled(timeZoneSuggestion);
|
mStubbedTimeZoneDetectorStrategy.verifySuggestTelephonyTimeZoneCalled(timeZoneSuggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = SecurityException.class)
|
@Test(expected = SecurityException.class)
|
||||||
@@ -165,12 +165,12 @@ public class TimeZoneDetectorServiceTest {
|
|||||||
mStubbedTimeZoneDetectorStrategy.verifyHandleAutoTimeZoneDetectionChangedCalled();
|
mStubbedTimeZoneDetectorStrategy.verifyHandleAutoTimeZoneDetectionChangedCalled();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PhoneTimeZoneSuggestion createPhoneTimeZoneSuggestion() {
|
private static TelephonyTimeZoneSuggestion createTelephonyTimeZoneSuggestion() {
|
||||||
int slotIndex = 1234;
|
int slotIndex = 1234;
|
||||||
return new PhoneTimeZoneSuggestion.Builder(slotIndex)
|
return new TelephonyTimeZoneSuggestion.Builder(slotIndex)
|
||||||
.setZoneId("TestZoneId")
|
.setZoneId("TestZoneId")
|
||||||
.setMatchType(PhoneTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET)
|
.setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET)
|
||||||
.setQuality(PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE)
|
.setQuality(TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,14 +181,14 @@ public class TimeZoneDetectorServiceTest {
|
|||||||
private static class StubbedTimeZoneDetectorStrategy implements TimeZoneDetectorStrategy {
|
private static class StubbedTimeZoneDetectorStrategy implements TimeZoneDetectorStrategy {
|
||||||
|
|
||||||
// Call tracking.
|
// Call tracking.
|
||||||
private PhoneTimeZoneSuggestion mLastPhoneSuggestion;
|
private TelephonyTimeZoneSuggestion mLastTelephonySuggestion;
|
||||||
private ManualTimeZoneSuggestion mLastManualSuggestion;
|
private ManualTimeZoneSuggestion mLastManualSuggestion;
|
||||||
private boolean mHandleAutoTimeZoneDetectionChangedCalled;
|
private boolean mHandleAutoTimeZoneDetectionChangedCalled;
|
||||||
private boolean mDumpCalled;
|
private boolean mDumpCalled;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void suggestPhoneTimeZone(PhoneTimeZoneSuggestion timeZoneSuggestion) {
|
public void suggestTelephonyTimeZone(TelephonyTimeZoneSuggestion timeZoneSuggestion) {
|
||||||
mLastPhoneSuggestion = timeZoneSuggestion;
|
mLastTelephonySuggestion = timeZoneSuggestion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -207,14 +207,14 @@ public class TimeZoneDetectorServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void resetCallTracking() {
|
void resetCallTracking() {
|
||||||
mLastPhoneSuggestion = null;
|
mLastTelephonySuggestion = null;
|
||||||
mLastManualSuggestion = null;
|
mLastManualSuggestion = null;
|
||||||
mHandleAutoTimeZoneDetectionChangedCalled = false;
|
mHandleAutoTimeZoneDetectionChangedCalled = false;
|
||||||
mDumpCalled = false;
|
mDumpCalled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifySuggestPhoneTimeZoneCalled(PhoneTimeZoneSuggestion expectedSuggestion) {
|
void verifySuggestTelephonyTimeZoneCalled(TelephonyTimeZoneSuggestion expectedSuggestion) {
|
||||||
assertEquals(expectedSuggestion, mLastPhoneSuggestion);
|
assertEquals(expectedSuggestion, mLastTelephonySuggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void verifySuggestManualTimeZoneCalled(ManualTimeZoneSuggestion expectedSuggestion) {
|
public void verifySuggestManualTimeZoneCalled(ManualTimeZoneSuggestion expectedSuggestion) {
|
||||||
|
|||||||
@@ -16,20 +16,20 @@
|
|||||||
|
|
||||||
package com.android.server.timezonedetector;
|
package com.android.server.timezonedetector;
|
||||||
|
|
||||||
import static android.app.timezonedetector.PhoneTimeZoneSuggestion.MATCH_TYPE_EMULATOR_ZONE_ID;
|
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.MATCH_TYPE_EMULATOR_ZONE_ID;
|
||||||
import static android.app.timezonedetector.PhoneTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET;
|
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET;
|
||||||
import static android.app.timezonedetector.PhoneTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY;
|
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.MATCH_TYPE_NETWORK_COUNTRY_ONLY;
|
||||||
import static android.app.timezonedetector.PhoneTimeZoneSuggestion.MATCH_TYPE_TEST_NETWORK_OFFSET_ONLY;
|
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.MATCH_TYPE_TEST_NETWORK_OFFSET_ONLY;
|
||||||
import static android.app.timezonedetector.PhoneTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS;
|
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS;
|
||||||
import static android.app.timezonedetector.PhoneTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET;
|
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET;
|
||||||
import static android.app.timezonedetector.PhoneTimeZoneSuggestion.QUALITY_SINGLE_ZONE;
|
import static android.app.timezonedetector.TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE;
|
||||||
|
|
||||||
import static com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.PHONE_SCORE_HIGH;
|
import static com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.TELEPHONY_SCORE_HIGH;
|
||||||
import static com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.PHONE_SCORE_HIGHEST;
|
import static com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.TELEPHONY_SCORE_HIGHEST;
|
||||||
import static com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.PHONE_SCORE_LOW;
|
import static com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.TELEPHONY_SCORE_LOW;
|
||||||
import static com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.PHONE_SCORE_MEDIUM;
|
import static com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.TELEPHONY_SCORE_MEDIUM;
|
||||||
import static com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.PHONE_SCORE_NONE;
|
import static com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.TELEPHONY_SCORE_NONE;
|
||||||
import static com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.PHONE_SCORE_USAGE_THRESHOLD;
|
import static com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.TELEPHONY_SCORE_USAGE_THRESHOLD;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -37,11 +37,11 @@ import static org.junit.Assert.assertNull;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import android.app.timezonedetector.ManualTimeZoneSuggestion;
|
import android.app.timezonedetector.ManualTimeZoneSuggestion;
|
||||||
import android.app.timezonedetector.PhoneTimeZoneSuggestion;
|
import android.app.timezonedetector.TelephonyTimeZoneSuggestion;
|
||||||
import android.app.timezonedetector.PhoneTimeZoneSuggestion.MatchType;
|
import android.app.timezonedetector.TelephonyTimeZoneSuggestion.MatchType;
|
||||||
import android.app.timezonedetector.PhoneTimeZoneSuggestion.Quality;
|
import android.app.timezonedetector.TelephonyTimeZoneSuggestion.Quality;
|
||||||
|
|
||||||
import com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.QualifiedPhoneTimeZoneSuggestion;
|
import com.android.server.timezonedetector.TimeZoneDetectorStrategyImpl.QualifiedTelephonyTimeZoneSuggestion;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -58,24 +58,24 @@ public class TimeZoneDetectorStrategyImplTest {
|
|||||||
|
|
||||||
/** A time zone used for initialization that does not occur elsewhere in tests. */
|
/** A time zone used for initialization that does not occur elsewhere in tests. */
|
||||||
private static final String ARBITRARY_TIME_ZONE_ID = "Etc/UTC";
|
private static final String ARBITRARY_TIME_ZONE_ID = "Etc/UTC";
|
||||||
private static final int PHONE1_ID = 10000;
|
private static final int SLOT_INDEX1 = 10000;
|
||||||
private static final int PHONE2_ID = 20000;
|
private static final int SLOT_INDEX2 = 20000;
|
||||||
|
|
||||||
// Suggestion test cases are ordered so that each successive one is of the same or higher score
|
// Suggestion test cases are ordered so that each successive one is of the same or higher score
|
||||||
// than the previous.
|
// than the previous.
|
||||||
private static final SuggestionTestCase[] TEST_CASES = new SuggestionTestCase[] {
|
private static final SuggestionTestCase[] TEST_CASES = new SuggestionTestCase[] {
|
||||||
newTestCase(MATCH_TYPE_NETWORK_COUNTRY_ONLY,
|
newTestCase(MATCH_TYPE_NETWORK_COUNTRY_ONLY,
|
||||||
QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS, PHONE_SCORE_LOW),
|
QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS, TELEPHONY_SCORE_LOW),
|
||||||
newTestCase(MATCH_TYPE_NETWORK_COUNTRY_ONLY, QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET,
|
newTestCase(MATCH_TYPE_NETWORK_COUNTRY_ONLY, QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET,
|
||||||
PHONE_SCORE_MEDIUM),
|
TELEPHONY_SCORE_MEDIUM),
|
||||||
newTestCase(MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET,
|
newTestCase(MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET,
|
||||||
QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET, PHONE_SCORE_MEDIUM),
|
QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET, TELEPHONY_SCORE_MEDIUM),
|
||||||
newTestCase(MATCH_TYPE_NETWORK_COUNTRY_ONLY, QUALITY_SINGLE_ZONE, PHONE_SCORE_HIGH),
|
newTestCase(MATCH_TYPE_NETWORK_COUNTRY_ONLY, QUALITY_SINGLE_ZONE, TELEPHONY_SCORE_HIGH),
|
||||||
newTestCase(MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET, QUALITY_SINGLE_ZONE,
|
newTestCase(MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET, QUALITY_SINGLE_ZONE,
|
||||||
PHONE_SCORE_HIGH),
|
TELEPHONY_SCORE_HIGH),
|
||||||
newTestCase(MATCH_TYPE_TEST_NETWORK_OFFSET_ONLY,
|
newTestCase(MATCH_TYPE_TEST_NETWORK_OFFSET_ONLY,
|
||||||
QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET, PHONE_SCORE_HIGHEST),
|
QUALITY_MULTIPLE_ZONES_WITH_SAME_OFFSET, TELEPHONY_SCORE_HIGHEST),
|
||||||
newTestCase(MATCH_TYPE_EMULATOR_ZONE_ID, QUALITY_SINGLE_ZONE, PHONE_SCORE_HIGHEST),
|
newTestCase(MATCH_TYPE_EMULATOR_ZONE_ID, QUALITY_SINGLE_ZONE, TELEPHONY_SCORE_HIGHEST),
|
||||||
};
|
};
|
||||||
|
|
||||||
private TimeZoneDetectorStrategyImpl mTimeZoneDetectorStrategy;
|
private TimeZoneDetectorStrategyImpl mTimeZoneDetectorStrategy;
|
||||||
@@ -89,76 +89,82 @@ public class TimeZoneDetectorStrategyImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyPhoneSuggestions() {
|
public void testEmptyTelephonySuggestions() {
|
||||||
PhoneTimeZoneSuggestion phone1TimeZoneSuggestion = createEmptyPhone1Suggestion();
|
TelephonyTimeZoneSuggestion slotIndex1TimeZoneSuggestion =
|
||||||
PhoneTimeZoneSuggestion phone2TimeZoneSuggestion = createEmptyPhone2Suggestion();
|
createEmptySlotIndex1Suggestion();
|
||||||
|
TelephonyTimeZoneSuggestion slotIndex2TimeZoneSuggestion =
|
||||||
|
createEmptySlotIndex2Suggestion();
|
||||||
Script script = new Script()
|
Script script = new Script()
|
||||||
.initializeAutoTimeZoneDetection(true)
|
.initializeAutoTimeZoneDetection(true)
|
||||||
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
|
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
|
||||||
|
|
||||||
script.suggestPhoneTimeZone(phone1TimeZoneSuggestion)
|
script.suggestTelephonyTimeZone(slotIndex1TimeZoneSuggestion)
|
||||||
.verifyTimeZoneNotSet();
|
.verifyTimeZoneNotSet();
|
||||||
|
|
||||||
// Assert internal service state.
|
// Assert internal service state.
|
||||||
QualifiedPhoneTimeZoneSuggestion expectedPhone1ScoredSuggestion =
|
QualifiedTelephonyTimeZoneSuggestion expectedSlotIndex1ScoredSuggestion =
|
||||||
new QualifiedPhoneTimeZoneSuggestion(phone1TimeZoneSuggestion, PHONE_SCORE_NONE);
|
new QualifiedTelephonyTimeZoneSuggestion(slotIndex1TimeZoneSuggestion,
|
||||||
assertEquals(expectedPhone1ScoredSuggestion,
|
TELEPHONY_SCORE_NONE);
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE1_ID));
|
assertEquals(expectedSlotIndex1ScoredSuggestion,
|
||||||
assertNull(mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE2_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
|
||||||
assertEquals(expectedPhone1ScoredSuggestion,
|
assertNull(mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX2));
|
||||||
mTimeZoneDetectorStrategy.findBestPhoneSuggestionForTests());
|
assertEquals(expectedSlotIndex1ScoredSuggestion,
|
||||||
|
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
|
||||||
|
|
||||||
script.suggestPhoneTimeZone(phone2TimeZoneSuggestion)
|
script.suggestTelephonyTimeZone(slotIndex2TimeZoneSuggestion)
|
||||||
.verifyTimeZoneNotSet();
|
.verifyTimeZoneNotSet();
|
||||||
|
|
||||||
// Assert internal service state.
|
// Assert internal service state.
|
||||||
QualifiedPhoneTimeZoneSuggestion expectedPhone2ScoredSuggestion =
|
QualifiedTelephonyTimeZoneSuggestion expectedSlotIndex2ScoredSuggestion =
|
||||||
new QualifiedPhoneTimeZoneSuggestion(phone2TimeZoneSuggestion, PHONE_SCORE_NONE);
|
new QualifiedTelephonyTimeZoneSuggestion(slotIndex2TimeZoneSuggestion,
|
||||||
assertEquals(expectedPhone1ScoredSuggestion,
|
TELEPHONY_SCORE_NONE);
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE1_ID));
|
assertEquals(expectedSlotIndex1ScoredSuggestion,
|
||||||
assertEquals(expectedPhone2ScoredSuggestion,
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE2_ID));
|
assertEquals(expectedSlotIndex2ScoredSuggestion,
|
||||||
// Phone 1 should always beat phone 2, all other things being equal.
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX2));
|
||||||
assertEquals(expectedPhone1ScoredSuggestion,
|
// SlotIndex1 should always beat slotIndex2, all other things being equal.
|
||||||
mTimeZoneDetectorStrategy.findBestPhoneSuggestionForTests());
|
assertEquals(expectedSlotIndex1ScoredSuggestion,
|
||||||
|
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFirstPlausiblePhoneSuggestionAcceptedWhenTimeZoneUninitialized() {
|
public void testFirstPlausibleTelephonySuggestionAcceptedWhenTimeZoneUninitialized() {
|
||||||
SuggestionTestCase testCase = newTestCase(MATCH_TYPE_NETWORK_COUNTRY_ONLY,
|
SuggestionTestCase testCase = newTestCase(MATCH_TYPE_NETWORK_COUNTRY_ONLY,
|
||||||
QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS, PHONE_SCORE_LOW);
|
QUALITY_MULTIPLE_ZONES_WITH_DIFFERENT_OFFSETS, TELEPHONY_SCORE_LOW);
|
||||||
PhoneTimeZoneSuggestion lowQualitySuggestion =
|
TelephonyTimeZoneSuggestion lowQualitySuggestion =
|
||||||
testCase.createSuggestion(PHONE1_ID, "America/New_York");
|
testCase.createSuggestion(SLOT_INDEX1, "America/New_York");
|
||||||
|
|
||||||
// The device time zone setting is left uninitialized.
|
// The device time zone setting is left uninitialized.
|
||||||
Script script = new Script()
|
Script script = new Script()
|
||||||
.initializeAutoTimeZoneDetection(true);
|
.initializeAutoTimeZoneDetection(true);
|
||||||
|
|
||||||
// The very first suggestion will be taken.
|
// The very first suggestion will be taken.
|
||||||
script.suggestPhoneTimeZone(lowQualitySuggestion)
|
script.suggestTelephonyTimeZone(lowQualitySuggestion)
|
||||||
.verifyTimeZoneSetAndReset(lowQualitySuggestion);
|
.verifyTimeZoneSetAndReset(lowQualitySuggestion);
|
||||||
|
|
||||||
// Assert internal service state.
|
// Assert internal service state.
|
||||||
QualifiedPhoneTimeZoneSuggestion expectedScoredSuggestion =
|
QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion =
|
||||||
new QualifiedPhoneTimeZoneSuggestion(lowQualitySuggestion, testCase.expectedScore);
|
new QualifiedTelephonyTimeZoneSuggestion(
|
||||||
|
lowQualitySuggestion, testCase.expectedScore);
|
||||||
assertEquals(expectedScoredSuggestion,
|
assertEquals(expectedScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE1_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
|
||||||
assertEquals(expectedScoredSuggestion,
|
assertEquals(expectedScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.findBestPhoneSuggestionForTests());
|
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
|
||||||
|
|
||||||
// Another low quality suggestion will be ignored now that the setting is initialized.
|
// Another low quality suggestion will be ignored now that the setting is initialized.
|
||||||
PhoneTimeZoneSuggestion lowQualitySuggestion2 =
|
TelephonyTimeZoneSuggestion lowQualitySuggestion2 =
|
||||||
testCase.createSuggestion(PHONE1_ID, "America/Los_Angeles");
|
testCase.createSuggestion(SLOT_INDEX1, "America/Los_Angeles");
|
||||||
script.suggestPhoneTimeZone(lowQualitySuggestion2)
|
script.suggestTelephonyTimeZone(lowQualitySuggestion2)
|
||||||
.verifyTimeZoneNotSet();
|
.verifyTimeZoneNotSet();
|
||||||
|
|
||||||
// Assert internal service state.
|
// Assert internal service state.
|
||||||
QualifiedPhoneTimeZoneSuggestion expectedScoredSuggestion2 =
|
QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion2 =
|
||||||
new QualifiedPhoneTimeZoneSuggestion(lowQualitySuggestion2, testCase.expectedScore);
|
new QualifiedTelephonyTimeZoneSuggestion(
|
||||||
|
lowQualitySuggestion2, testCase.expectedScore);
|
||||||
assertEquals(expectedScoredSuggestion2,
|
assertEquals(expectedScoredSuggestion2,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE1_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
|
||||||
assertEquals(expectedScoredSuggestion2,
|
assertEquals(expectedScoredSuggestion2,
|
||||||
mTimeZoneDetectorStrategy.findBestPhoneSuggestionForTests());
|
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -174,28 +180,28 @@ public class TimeZoneDetectorStrategyImplTest {
|
|||||||
script.initializeAutoTimeZoneDetection(false)
|
script.initializeAutoTimeZoneDetection(false)
|
||||||
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
|
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
|
||||||
|
|
||||||
PhoneTimeZoneSuggestion suggestion =
|
TelephonyTimeZoneSuggestion suggestion =
|
||||||
testCase.createSuggestion(PHONE1_ID, "Europe/London");
|
testCase.createSuggestion(SLOT_INDEX1, "Europe/London");
|
||||||
script.suggestPhoneTimeZone(suggestion);
|
script.suggestTelephonyTimeZone(suggestion);
|
||||||
|
|
||||||
// When time zone detection is not enabled, the time zone suggestion will not be set
|
// When time zone detection is not enabled, the time zone suggestion will not be set
|
||||||
// regardless of the score.
|
// regardless of the score.
|
||||||
script.verifyTimeZoneNotSet();
|
script.verifyTimeZoneNotSet();
|
||||||
|
|
||||||
// Assert internal service state.
|
// Assert internal service state.
|
||||||
QualifiedPhoneTimeZoneSuggestion expectedScoredSuggestion =
|
QualifiedTelephonyTimeZoneSuggestion expectedScoredSuggestion =
|
||||||
new QualifiedPhoneTimeZoneSuggestion(suggestion, testCase.expectedScore);
|
new QualifiedTelephonyTimeZoneSuggestion(suggestion, testCase.expectedScore);
|
||||||
assertEquals(expectedScoredSuggestion,
|
assertEquals(expectedScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE1_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
|
||||||
assertEquals(expectedScoredSuggestion,
|
assertEquals(expectedScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.findBestPhoneSuggestionForTests());
|
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
|
||||||
|
|
||||||
// Toggling the time zone setting on should cause the device setting to be set.
|
// Toggling the time zone setting on should cause the device setting to be set.
|
||||||
script.autoTimeZoneDetectionEnabled(true);
|
script.autoTimeZoneDetectionEnabled(true);
|
||||||
|
|
||||||
// When time zone detection is already enabled the suggestion (if it scores highly
|
// When time zone detection is already enabled the suggestion (if it scores highly
|
||||||
// enough) should be set immediately.
|
// enough) should be set immediately.
|
||||||
if (testCase.expectedScore >= PHONE_SCORE_USAGE_THRESHOLD) {
|
if (testCase.expectedScore >= TELEPHONY_SCORE_USAGE_THRESHOLD) {
|
||||||
script.verifyTimeZoneSetAndReset(suggestion);
|
script.verifyTimeZoneSetAndReset(suggestion);
|
||||||
} else {
|
} else {
|
||||||
script.verifyTimeZoneNotSet();
|
script.verifyTimeZoneNotSet();
|
||||||
@@ -203,9 +209,9 @@ public class TimeZoneDetectorStrategyImplTest {
|
|||||||
|
|
||||||
// Assert internal service state.
|
// Assert internal service state.
|
||||||
assertEquals(expectedScoredSuggestion,
|
assertEquals(expectedScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE1_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
|
||||||
assertEquals(expectedScoredSuggestion,
|
assertEquals(expectedScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.findBestPhoneSuggestionForTests());
|
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
|
||||||
|
|
||||||
// Toggling the time zone setting should off should do nothing.
|
// Toggling the time zone setting should off should do nothing.
|
||||||
script.autoTimeZoneDetectionEnabled(false)
|
script.autoTimeZoneDetectionEnabled(false)
|
||||||
@@ -213,20 +219,20 @@ public class TimeZoneDetectorStrategyImplTest {
|
|||||||
|
|
||||||
// Assert internal service state.
|
// Assert internal service state.
|
||||||
assertEquals(expectedScoredSuggestion,
|
assertEquals(expectedScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE1_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
|
||||||
assertEquals(expectedScoredSuggestion,
|
assertEquals(expectedScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.findBestPhoneSuggestionForTests());
|
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPhoneSuggestionsSinglePhone() {
|
public void testTelephonySuggestionsSingleSlotId() {
|
||||||
Script script = new Script()
|
Script script = new Script()
|
||||||
.initializeAutoTimeZoneDetection(true)
|
.initializeAutoTimeZoneDetection(true)
|
||||||
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
|
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID);
|
||||||
|
|
||||||
for (SuggestionTestCase testCase : TEST_CASES) {
|
for (SuggestionTestCase testCase : TEST_CASES) {
|
||||||
makePhone1SuggestionAndCheckState(script, testCase);
|
makeSlotIndex1SuggestionAndCheckState(script, testCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -241,125 +247,128 @@ public class TimeZoneDetectorStrategyImplTest {
|
|||||||
Collections.reverse(descendingCasesByScore);
|
Collections.reverse(descendingCasesByScore);
|
||||||
|
|
||||||
for (SuggestionTestCase testCase : descendingCasesByScore) {
|
for (SuggestionTestCase testCase : descendingCasesByScore) {
|
||||||
makePhone1SuggestionAndCheckState(script, testCase);
|
makeSlotIndex1SuggestionAndCheckState(script, testCase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makePhone1SuggestionAndCheckState(Script script, SuggestionTestCase testCase) {
|
private void makeSlotIndex1SuggestionAndCheckState(Script script, SuggestionTestCase testCase) {
|
||||||
// Give the next suggestion a different zone from the currently set device time zone;
|
// Give the next suggestion a different zone from the currently set device time zone;
|
||||||
String currentZoneId = mFakeTimeZoneDetectorStrategyCallback.getDeviceTimeZone();
|
String currentZoneId = mFakeTimeZoneDetectorStrategyCallback.getDeviceTimeZone();
|
||||||
String suggestionZoneId =
|
String suggestionZoneId =
|
||||||
"Europe/London".equals(currentZoneId) ? "Europe/Paris" : "Europe/London";
|
"Europe/London".equals(currentZoneId) ? "Europe/Paris" : "Europe/London";
|
||||||
PhoneTimeZoneSuggestion zonePhone1Suggestion =
|
TelephonyTimeZoneSuggestion zoneSlotIndex1Suggestion =
|
||||||
testCase.createSuggestion(PHONE1_ID, suggestionZoneId);
|
testCase.createSuggestion(SLOT_INDEX1, suggestionZoneId);
|
||||||
QualifiedPhoneTimeZoneSuggestion expectedZonePhone1ScoredSuggestion =
|
QualifiedTelephonyTimeZoneSuggestion expectedZoneSlotIndex1ScoredSuggestion =
|
||||||
new QualifiedPhoneTimeZoneSuggestion(zonePhone1Suggestion, testCase.expectedScore);
|
new QualifiedTelephonyTimeZoneSuggestion(
|
||||||
|
zoneSlotIndex1Suggestion, testCase.expectedScore);
|
||||||
|
|
||||||
script.suggestPhoneTimeZone(zonePhone1Suggestion);
|
script.suggestTelephonyTimeZone(zoneSlotIndex1Suggestion);
|
||||||
if (testCase.expectedScore >= PHONE_SCORE_USAGE_THRESHOLD) {
|
if (testCase.expectedScore >= TELEPHONY_SCORE_USAGE_THRESHOLD) {
|
||||||
script.verifyTimeZoneSetAndReset(zonePhone1Suggestion);
|
script.verifyTimeZoneSetAndReset(zoneSlotIndex1Suggestion);
|
||||||
} else {
|
} else {
|
||||||
script.verifyTimeZoneNotSet();
|
script.verifyTimeZoneNotSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert internal service state.
|
// Assert internal service state.
|
||||||
assertEquals(expectedZonePhone1ScoredSuggestion,
|
assertEquals(expectedZoneSlotIndex1ScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE1_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
|
||||||
assertEquals(expectedZonePhone1ScoredSuggestion,
|
assertEquals(expectedZoneSlotIndex1ScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.findBestPhoneSuggestionForTests());
|
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries a set of test cases to see if the phone with the lowest ID is given preference. This
|
* Tries a set of test cases to see if the slotIndex with the lowest numeric value is given
|
||||||
* test also confirms that the time zone setting would only be set if a suggestion is of
|
* preference. This test also confirms that the time zone setting would only be set if a
|
||||||
* sufficient quality.
|
* suggestion is of sufficient quality.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMultiplePhoneSuggestionScoringAndPhoneIdBias() {
|
public void testMultipleSlotIndexSuggestionScoringAndSlotIndexBias() {
|
||||||
String[] zoneIds = { "Europe/London", "Europe/Paris" };
|
String[] zoneIds = { "Europe/London", "Europe/Paris" };
|
||||||
PhoneTimeZoneSuggestion emptyPhone1Suggestion = createEmptyPhone1Suggestion();
|
TelephonyTimeZoneSuggestion emptySlotIndex1Suggestion = createEmptySlotIndex1Suggestion();
|
||||||
PhoneTimeZoneSuggestion emptyPhone2Suggestion = createEmptyPhone2Suggestion();
|
TelephonyTimeZoneSuggestion emptySlotIndex2Suggestion = createEmptySlotIndex2Suggestion();
|
||||||
QualifiedPhoneTimeZoneSuggestion expectedEmptyPhone1ScoredSuggestion =
|
QualifiedTelephonyTimeZoneSuggestion expectedEmptySlotIndex1ScoredSuggestion =
|
||||||
new QualifiedPhoneTimeZoneSuggestion(emptyPhone1Suggestion, PHONE_SCORE_NONE);
|
new QualifiedTelephonyTimeZoneSuggestion(emptySlotIndex1Suggestion,
|
||||||
QualifiedPhoneTimeZoneSuggestion expectedEmptyPhone2ScoredSuggestion =
|
TELEPHONY_SCORE_NONE);
|
||||||
new QualifiedPhoneTimeZoneSuggestion(emptyPhone2Suggestion, PHONE_SCORE_NONE);
|
QualifiedTelephonyTimeZoneSuggestion expectedEmptySlotIndex2ScoredSuggestion =
|
||||||
|
new QualifiedTelephonyTimeZoneSuggestion(emptySlotIndex2Suggestion,
|
||||||
|
TELEPHONY_SCORE_NONE);
|
||||||
|
|
||||||
Script script = new Script()
|
Script script = new Script()
|
||||||
.initializeAutoTimeZoneDetection(true)
|
.initializeAutoTimeZoneDetection(true)
|
||||||
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID)
|
.initializeTimeZoneSetting(ARBITRARY_TIME_ZONE_ID)
|
||||||
// Initialize the latest suggestions as empty so we don't need to worry about nulls
|
// Initialize the latest suggestions as empty so we don't need to worry about nulls
|
||||||
// below for the first loop.
|
// below for the first loop.
|
||||||
.suggestPhoneTimeZone(emptyPhone1Suggestion)
|
.suggestTelephonyTimeZone(emptySlotIndex1Suggestion)
|
||||||
.suggestPhoneTimeZone(emptyPhone2Suggestion)
|
.suggestTelephonyTimeZone(emptySlotIndex2Suggestion)
|
||||||
.resetState();
|
.resetState();
|
||||||
|
|
||||||
for (SuggestionTestCase testCase : TEST_CASES) {
|
for (SuggestionTestCase testCase : TEST_CASES) {
|
||||||
PhoneTimeZoneSuggestion zonePhone1Suggestion =
|
TelephonyTimeZoneSuggestion zoneSlotIndex1Suggestion =
|
||||||
testCase.createSuggestion(PHONE1_ID, zoneIds[0]);
|
testCase.createSuggestion(SLOT_INDEX1, zoneIds[0]);
|
||||||
PhoneTimeZoneSuggestion zonePhone2Suggestion =
|
TelephonyTimeZoneSuggestion zoneSlotIndex2Suggestion =
|
||||||
testCase.createSuggestion(PHONE2_ID, zoneIds[1]);
|
testCase.createSuggestion(SLOT_INDEX2, zoneIds[1]);
|
||||||
QualifiedPhoneTimeZoneSuggestion expectedZonePhone1ScoredSuggestion =
|
QualifiedTelephonyTimeZoneSuggestion expectedZoneSlotIndex1ScoredSuggestion =
|
||||||
new QualifiedPhoneTimeZoneSuggestion(zonePhone1Suggestion,
|
new QualifiedTelephonyTimeZoneSuggestion(zoneSlotIndex1Suggestion,
|
||||||
testCase.expectedScore);
|
testCase.expectedScore);
|
||||||
QualifiedPhoneTimeZoneSuggestion expectedZonePhone2ScoredSuggestion =
|
QualifiedTelephonyTimeZoneSuggestion expectedZoneSlotIndex2ScoredSuggestion =
|
||||||
new QualifiedPhoneTimeZoneSuggestion(zonePhone2Suggestion,
|
new QualifiedTelephonyTimeZoneSuggestion(zoneSlotIndex2Suggestion,
|
||||||
testCase.expectedScore);
|
testCase.expectedScore);
|
||||||
|
|
||||||
// Start the test by making a suggestion for phone 1.
|
// Start the test by making a suggestion for slotIndex1.
|
||||||
script.suggestPhoneTimeZone(zonePhone1Suggestion);
|
script.suggestTelephonyTimeZone(zoneSlotIndex1Suggestion);
|
||||||
if (testCase.expectedScore >= PHONE_SCORE_USAGE_THRESHOLD) {
|
if (testCase.expectedScore >= TELEPHONY_SCORE_USAGE_THRESHOLD) {
|
||||||
script.verifyTimeZoneSetAndReset(zonePhone1Suggestion);
|
script.verifyTimeZoneSetAndReset(zoneSlotIndex1Suggestion);
|
||||||
} else {
|
} else {
|
||||||
script.verifyTimeZoneNotSet();
|
script.verifyTimeZoneNotSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert internal service state.
|
// Assert internal service state.
|
||||||
assertEquals(expectedZonePhone1ScoredSuggestion,
|
assertEquals(expectedZoneSlotIndex1ScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE1_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
|
||||||
assertEquals(expectedEmptyPhone2ScoredSuggestion,
|
assertEquals(expectedEmptySlotIndex2ScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE2_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX2));
|
||||||
assertEquals(expectedZonePhone1ScoredSuggestion,
|
assertEquals(expectedZoneSlotIndex1ScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.findBestPhoneSuggestionForTests());
|
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
|
||||||
|
|
||||||
// Phone 2 then makes an alternative suggestion with an identical score. Phone 1's
|
// SlotIndex2 then makes an alternative suggestion with an identical score. SlotIndex1's
|
||||||
// suggestion should still "win" if it is above the required threshold.
|
// suggestion should still "win" if it is above the required threshold.
|
||||||
script.suggestPhoneTimeZone(zonePhone2Suggestion);
|
script.suggestTelephonyTimeZone(zoneSlotIndex2Suggestion);
|
||||||
script.verifyTimeZoneNotSet();
|
script.verifyTimeZoneNotSet();
|
||||||
|
|
||||||
// Assert internal service state.
|
// Assert internal service state.
|
||||||
assertEquals(expectedZonePhone1ScoredSuggestion,
|
assertEquals(expectedZoneSlotIndex1ScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE1_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
|
||||||
assertEquals(expectedZonePhone2ScoredSuggestion,
|
assertEquals(expectedZoneSlotIndex2ScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE2_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX2));
|
||||||
// Phone 1 should always beat phone 2, all other things being equal.
|
// SlotIndex1 should always beat slotIndex2, all other things being equal.
|
||||||
assertEquals(expectedZonePhone1ScoredSuggestion,
|
assertEquals(expectedZoneSlotIndex1ScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.findBestPhoneSuggestionForTests());
|
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
|
||||||
|
|
||||||
// Withdrawing phone 1's suggestion should leave phone 2 as the new winner. Since the
|
// Withdrawing slotIndex1's suggestion should leave slotIndex2 as the new winner. Since
|
||||||
// zoneId is different, the time zone setting should be updated if the score is high
|
// the zoneId is different, the time zone setting should be updated if the score is high
|
||||||
// enough.
|
// enough.
|
||||||
script.suggestPhoneTimeZone(emptyPhone1Suggestion);
|
script.suggestTelephonyTimeZone(emptySlotIndex1Suggestion);
|
||||||
if (testCase.expectedScore >= PHONE_SCORE_USAGE_THRESHOLD) {
|
if (testCase.expectedScore >= TELEPHONY_SCORE_USAGE_THRESHOLD) {
|
||||||
script.verifyTimeZoneSetAndReset(zonePhone2Suggestion);
|
script.verifyTimeZoneSetAndReset(zoneSlotIndex2Suggestion);
|
||||||
} else {
|
} else {
|
||||||
script.verifyTimeZoneNotSet();
|
script.verifyTimeZoneNotSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert internal service state.
|
// Assert internal service state.
|
||||||
assertEquals(expectedEmptyPhone1ScoredSuggestion,
|
assertEquals(expectedEmptySlotIndex1ScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE1_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
|
||||||
assertEquals(expectedZonePhone2ScoredSuggestion,
|
assertEquals(expectedZoneSlotIndex2ScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE2_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX2));
|
||||||
assertEquals(expectedZonePhone2ScoredSuggestion,
|
assertEquals(expectedZoneSlotIndex2ScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.findBestPhoneSuggestionForTests());
|
mTimeZoneDetectorStrategy.findBestTelephonySuggestionForTests());
|
||||||
|
|
||||||
// Reset the state for the next loop.
|
// Reset the state for the next loop.
|
||||||
script.suggestPhoneTimeZone(emptyPhone2Suggestion)
|
script.suggestTelephonyTimeZone(emptySlotIndex2Suggestion)
|
||||||
.verifyTimeZoneNotSet();
|
.verifyTimeZoneNotSet();
|
||||||
assertEquals(expectedEmptyPhone1ScoredSuggestion,
|
assertEquals(expectedEmptySlotIndex1ScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE1_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX1));
|
||||||
assertEquals(expectedEmptyPhone2ScoredSuggestion,
|
assertEquals(expectedEmptySlotIndex2ScoredSuggestion,
|
||||||
mTimeZoneDetectorStrategy.getLatestPhoneSuggestion(PHONE2_ID));
|
mTimeZoneDetectorStrategy.getLatestTelephonySuggestion(SLOT_INDEX2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,21 +384,21 @@ public class TimeZoneDetectorStrategyImplTest {
|
|||||||
|
|
||||||
SuggestionTestCase testCase =
|
SuggestionTestCase testCase =
|
||||||
newTestCase(MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET, QUALITY_SINGLE_ZONE,
|
newTestCase(MATCH_TYPE_NETWORK_COUNTRY_AND_OFFSET, QUALITY_SINGLE_ZONE,
|
||||||
PHONE_SCORE_HIGH);
|
TELEPHONY_SCORE_HIGH);
|
||||||
PhoneTimeZoneSuggestion losAngelesSuggestion =
|
TelephonyTimeZoneSuggestion losAngelesSuggestion =
|
||||||
testCase.createSuggestion(PHONE1_ID, "America/Los_Angeles");
|
testCase.createSuggestion(SLOT_INDEX1, "America/Los_Angeles");
|
||||||
PhoneTimeZoneSuggestion newYorkSuggestion =
|
TelephonyTimeZoneSuggestion newYorkSuggestion =
|
||||||
testCase.createSuggestion(PHONE1_ID, "America/New_York");
|
testCase.createSuggestion(SLOT_INDEX1, "America/New_York");
|
||||||
|
|
||||||
// Initialization.
|
// Initialization.
|
||||||
script.suggestPhoneTimeZone(losAngelesSuggestion)
|
script.suggestTelephonyTimeZone(losAngelesSuggestion)
|
||||||
.verifyTimeZoneSetAndReset(losAngelesSuggestion);
|
.verifyTimeZoneSetAndReset(losAngelesSuggestion);
|
||||||
// Suggest it again - it should not be set because it is already set.
|
// Suggest it again - it should not be set because it is already set.
|
||||||
script.suggestPhoneTimeZone(losAngelesSuggestion)
|
script.suggestTelephonyTimeZone(losAngelesSuggestion)
|
||||||
.verifyTimeZoneNotSet();
|
.verifyTimeZoneNotSet();
|
||||||
|
|
||||||
// Toggling time zone detection should set the device time zone only if the current setting
|
// Toggling time zone detection should set the device time zone only if the current setting
|
||||||
// value is different from the most recent phone suggestion.
|
// value is different from the most recent telephony suggestion.
|
||||||
script.autoTimeZoneDetectionEnabled(false)
|
script.autoTimeZoneDetectionEnabled(false)
|
||||||
.verifyTimeZoneNotSet()
|
.verifyTimeZoneNotSet()
|
||||||
.autoTimeZoneDetectionEnabled(true)
|
.autoTimeZoneDetectionEnabled(true)
|
||||||
@@ -398,7 +407,7 @@ public class TimeZoneDetectorStrategyImplTest {
|
|||||||
// Simulate a user turning auto detection off, a new suggestion being made while auto
|
// Simulate a user turning auto detection off, a new suggestion being made while auto
|
||||||
// detection is off, and the user turning it on again.
|
// detection is off, and the user turning it on again.
|
||||||
script.autoTimeZoneDetectionEnabled(false)
|
script.autoTimeZoneDetectionEnabled(false)
|
||||||
.suggestPhoneTimeZone(newYorkSuggestion)
|
.suggestTelephonyTimeZone(newYorkSuggestion)
|
||||||
.verifyTimeZoneNotSet();
|
.verifyTimeZoneNotSet();
|
||||||
// Latest suggestion should be used.
|
// Latest suggestion should be used.
|
||||||
script.autoTimeZoneDetectionEnabled(true)
|
script.autoTimeZoneDetectionEnabled(true)
|
||||||
@@ -433,12 +442,12 @@ public class TimeZoneDetectorStrategyImplTest {
|
|||||||
return new ManualTimeZoneSuggestion(zoneId);
|
return new ManualTimeZoneSuggestion(zoneId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PhoneTimeZoneSuggestion createEmptyPhone1Suggestion() {
|
private static TelephonyTimeZoneSuggestion createEmptySlotIndex1Suggestion() {
|
||||||
return new PhoneTimeZoneSuggestion.Builder(PHONE1_ID).build();
|
return new TelephonyTimeZoneSuggestion.Builder(SLOT_INDEX1).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PhoneTimeZoneSuggestion createEmptyPhone2Suggestion() {
|
private static TelephonyTimeZoneSuggestion createEmptySlotIndex2Suggestion() {
|
||||||
return new PhoneTimeZoneSuggestion.Builder(PHONE2_ID).build();
|
return new TelephonyTimeZoneSuggestion.Builder(SLOT_INDEX2).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
static class FakeTimeZoneDetectorStrategyCallback
|
static class FakeTimeZoneDetectorStrategyCallback
|
||||||
@@ -565,9 +574,11 @@ public class TimeZoneDetectorStrategyImplTest {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Simulates the time zone detection strategy receiving a phone-originated suggestion. */
|
/**
|
||||||
Script suggestPhoneTimeZone(PhoneTimeZoneSuggestion phoneTimeZoneSuggestion) {
|
* Simulates the time zone detection strategy receiving a telephony-originated suggestion.
|
||||||
mTimeZoneDetectorStrategy.suggestPhoneTimeZone(phoneTimeZoneSuggestion);
|
*/
|
||||||
|
Script suggestTelephonyTimeZone(TelephonyTimeZoneSuggestion timeZoneSuggestion) {
|
||||||
|
mTimeZoneDetectorStrategy.suggestTelephonyTimeZone(timeZoneSuggestion);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -582,7 +593,7 @@ public class TimeZoneDetectorStrategyImplTest {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Script verifyTimeZoneSetAndReset(PhoneTimeZoneSuggestion suggestion) {
|
Script verifyTimeZoneSetAndReset(TelephonyTimeZoneSuggestion suggestion) {
|
||||||
mFakeTimeZoneDetectorStrategyCallback.assertTimeZoneSet(suggestion.getZoneId());
|
mFakeTimeZoneDetectorStrategyCallback.assertTimeZoneSet(suggestion.getZoneId());
|
||||||
mFakeTimeZoneDetectorStrategyCallback.commitAllChanges();
|
mFakeTimeZoneDetectorStrategyCallback.commitAllChanges();
|
||||||
return this;
|
return this;
|
||||||
@@ -611,8 +622,8 @@ public class TimeZoneDetectorStrategyImplTest {
|
|||||||
this.expectedScore = expectedScore;
|
this.expectedScore = expectedScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PhoneTimeZoneSuggestion createSuggestion(int phoneId, String zoneId) {
|
private TelephonyTimeZoneSuggestion createSuggestion(int slotIndex, String zoneId) {
|
||||||
return new PhoneTimeZoneSuggestion.Builder(phoneId)
|
return new TelephonyTimeZoneSuggestion.Builder(slotIndex)
|
||||||
.setZoneId(zoneId)
|
.setZoneId(zoneId)
|
||||||
.setMatchType(matchType)
|
.setMatchType(matchType)
|
||||||
.setQuality(quality)
|
.setQuality(quality)
|
||||||
|
|||||||
Reference in New Issue
Block a user