diff options
author | Makoto Onuki <omakoto@google.com> | 2011-12-13 14:02:32 -0800 |
---|---|---|
committer | Makoto Onuki <omakoto@google.com> | 2011-12-13 14:02:32 -0800 |
commit | d73b79bb314dde86cf8ff9300fefc133b31841d1 (patch) | |
tree | a53994afb14a9a58be2a5088aa903fbe7495ff71 /location | |
parent | 19a06fe93cccb4b1dd224b8456969821a19b07ef (diff) | |
download | frameworks_base-d73b79bb314dde86cf8ff9300fefc133b31841d1.zip frameworks_base-d73b79bb314dde86cf8ff9300fefc133b31841d1.tar.gz frameworks_base-d73b79bb314dde86cf8ff9300fefc133b31841d1.tar.bz2 |
Cherry-picking Id45abeba and Ia065dec6 for MR1
-------------------------------------------------------
MCC detection fixes for CountryDetector
- Don't get and cache phone tpe at the initialization time. At this point
TelephonyManager is probably not ready yet.
- Refresh MCC whenever we get the service state changed callback, even when
the state hasn't actually changed, in order to make sure we get refresh
country properly when MCC changes.
- Also remove the initialization of mPhoneStateListener, which prevented us from
registering phone state listener properly.
- Also fix tests which were already failing.
Bug 5670680
-------------------------------------------------------
Add logging to country detector logic
This is for debugging purposes to verify the effects of
change Id45abeba1b1e843053ac2c946861b439ca568de4.
Bug: 5670680
Change-Id: I238d953484e2c8135f7dac70fce8662c8300a286
Diffstat (limited to 'location')
-rwxr-xr-x | location/java/android/location/Country.java | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/location/java/android/location/Country.java b/location/java/android/location/Country.java index 939bd4a..7c1485d 100755 --- a/location/java/android/location/Country.java +++ b/location/java/android/location/Country.java @@ -18,6 +18,7 @@ package android.location; import android.os.Parcel; import android.os.Parcelable; +import android.os.SystemClock; import java.util.Locale; @@ -58,8 +59,14 @@ public class Country implements Parcelable { private final int mSource; private int mHashCode; + + /** + * Time that this object was created (which we assume to be the time that the source was + * consulted). This time is in milliseconds since boot up. + */ + private final long mTimestamp; + /** - * * @param countryIso the ISO 3166-1 two letters country code. * @param source where the countryIso came from, could be one of below * values @@ -78,11 +85,23 @@ public class Country implements Parcelable { } mCountryIso = countryIso.toUpperCase(Locale.US); mSource = source; + mTimestamp = SystemClock.elapsedRealtime(); + } + + private Country(final String countryIso, final int source, long timestamp) { + if (countryIso == null || source < COUNTRY_SOURCE_NETWORK + || source > COUNTRY_SOURCE_LOCALE) { + throw new IllegalArgumentException(); + } + mCountryIso = countryIso.toUpperCase(Locale.US); + mSource = source; + mTimestamp = timestamp; } public Country(Country country) { mCountryIso = country.mCountryIso; mSource = country.mSource; + mTimestamp = country.mTimestamp; } /** @@ -106,9 +125,17 @@ public class Country implements Parcelable { return mSource; } + /** + * Returns the time that this object was created (which we assume to be the time that the source + * was consulted). + */ + public final long getTimestamp() { + return mTimestamp; + } + public static final Parcelable.Creator<Country> CREATOR = new Parcelable.Creator<Country>() { public Country createFromParcel(Parcel in) { - return new Country(in.readString(), in.readInt()); + return new Country(in.readString(), in.readInt(), in.readLong()); } public Country[] newArray(int size) { @@ -123,8 +150,14 @@ public class Country implements Parcelable { public void writeToParcel(Parcel parcel, int flags) { parcel.writeString(mCountryIso); parcel.writeInt(mSource); + parcel.writeLong(mTimestamp); } + /** + * Returns true if this {@link Country} is equivalent to the given object. This ignores + * the timestamp value and just checks for equivalence of countryIso and source values. + * Returns false otherwise. + */ @Override public boolean equals(Object object) { if (object == this) { @@ -132,6 +165,7 @@ public class Country implements Parcelable { } if (object instanceof Country) { Country c = (Country) object; + // No need to check the equivalence of the timestamp return mCountryIso.equals(c.getCountryIso()) && mSource == c.getSource(); } return false; @@ -150,8 +184,8 @@ public class Country implements Parcelable { } /** - * Compare the specified country to this country object ignoring the mSource - * field, return true if the countryIso fields are equal + * Compare the specified country to this country object ignoring the source + * and timestamp fields, return true if the countryIso fields are equal * * @param country the country to compare * @return true if the specified country's countryIso field is equal to this @@ -160,4 +194,9 @@ public class Country implements Parcelable { public boolean equalsIgnoreSource(Country country) { return country != null && mCountryIso.equals(country.getCountryIso()); } + + @Override + public String toString() { + return "Country {ISO=" + mCountryIso + ", source=" + mSource + ", time=" + mTimestamp + "}"; + } } |