Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c8d82dd6 authored by Victoria Lease's avatar Victoria Lease Committed by Android Git Automerger
Browse files

am de07d41f: Merge "Annotate Locations coming from mock providers"

# Via Android (Google) Code Review (1) and Victoria Lease (1)
* commit 'de07d41f':
  Annotate Locations coming from mock providers
parents 28a068e0 de07d41f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10701,6 +10701,7 @@ package android.location {
    method public boolean hasAltitude();
    method public boolean hasBearing();
    method public boolean hasSpeed();
    method public boolean isFromMockProvider();
    method public void removeAccuracy();
    method public void removeAltitude();
    method public void removeBearing();
+25 −0
Original line number Diff line number Diff line
@@ -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;
    }
}
+19 −3
Original line number Diff line number Diff line
@@ -1792,17 +1792,33 @@ public class LocationManagerService extends ILocationManager.Stub {
        }
    }

    private boolean isMockProvider(String provider) {
        synchronized (mLock) {
            return mMockProviders.containsKey(provider);
        }
    }

    private void handleLocationChanged(Location location, boolean passive) {
        String provider = location.getProvider();
        // create a working copy of the incoming Location so that the service can modify it without
        // disturbing the caller's copy
        Location myLocation = new Location(location);
        String provider = myLocation.getProvider();

        // set "isFromMockProvider" bit if location came from a mock provider. we do not clear this
        // bit if location did not come from a mock provider because passive/fused providers can
        // forward locations from mock providers, and should not grant them legitimacy in doing so.
        if (!myLocation.isFromMockProvider() && isMockProvider(provider)) {
            myLocation.setIsFromMockProvider(true);
        }

        if (!passive) {
            // notify passive provider of the new location
            mPassiveProvider.updateLocation(location);
            mPassiveProvider.updateLocation(myLocation);
        }

        synchronized (mLock) {
            if (isAllowedBySettingsLocked(provider, mCurrentUserId)) {
                handleLocationChangedLocked(location, passive);
                handleLocationChangedLocked(myLocation, passive);
            }
        }
    }
+3 −3

File changed.

Contains only whitespace changes.