Annotate Locations coming from mock providers

LocationManagerService now annotates incoming Location objects that
have come from mock location providers. The new isFromMockProvider()
method can be called on any Location to determine whether the
provider that supplied the Location was a mock location provider.

Bug: 6813235
Change-Id: Ib5140e93ea427f2e0b0036151047f87a02b4d23a
This commit is contained in:
Victoria Lease
2013-01-08 09:39:50 -08:00
parent f25febf014
commit 54ca7aef2e
4 changed files with 48 additions and 6 deletions

View File

@@ -91,6 +91,7 @@ public class Location implements Parcelable {
private boolean mHasAccuracy = false;
private float mAccuracy = 0.0f;
private Bundle mExtras = null;
private boolean mIsFromMockProvider = false;
// Cache the inputs and outputs of computeDistanceAndBearing
// so calls to distanceTo() and bearingTo() can share work
@@ -140,6 +141,7 @@ public class Location implements Parcelable {
mHasAccuracy = l.mHasAccuracy;
mAccuracy = l.mAccuracy;
mExtras = (l.mExtras == null) ? null : new Bundle(l.mExtras);
mIsFromMockProvider = l.mIsFromMockProvider;
}
/**
@@ -160,6 +162,7 @@ public class Location implements Parcelable {
mHasAccuracy = false;
mAccuracy = 0;
mExtras = null;
mIsFromMockProvider = false;
}
/**
@@ -840,6 +843,7 @@ public class Location implements Parcelable {
if (mHasAltitude) s.append(" alt=").append(mAltitude);
if (mHasSpeed) s.append(" vel=").append(mSpeed);
if (mHasBearing) s.append(" bear=").append(mBearing);
if (mIsFromMockProvider) s.append(" mock");
if (mExtras != null) {
s.append(" {").append(mExtras).append('}');
@@ -871,6 +875,7 @@ public class Location implements Parcelable {
l.mHasAccuracy = in.readInt() != 0;
l.mAccuracy = in.readFloat();
l.mExtras = in.readBundle();
l.mIsFromMockProvider = in.readInt() != 0;
return l;
}
@@ -901,6 +906,7 @@ public class Location implements Parcelable {
parcel.writeInt(mHasAccuracy ? 1 : 0);
parcel.writeFloat(mAccuracy);
parcel.writeBundle(mExtras);
parcel.writeInt(mIsFromMockProvider? 1 : 0);
}
/**
@@ -934,4 +940,23 @@ public class Location implements Parcelable {
}
mExtras.putParcelable(key, value);
}
/**
* Returns true if the Location came from a mock provider.
*
* @return true if this Location came from a mock provider, false otherwise
*/
public boolean isFromMockProvider() {
return mIsFromMockProvider;
}
/**
* Flag this Location as having come from a mock provider or not.
*
* @param isFromMockProvider true if this Location came from a mock provider, false otherwise
* @hide
*/
public void setIsFromMockProvider(boolean isFromMockProvider) {
mIsFromMockProvider = isFromMockProvider;
}
}