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

Commit 5d47f1e2 authored by Soonil Nagarkar's avatar Soonil Nagarkar
Browse files

Various location fixes

-Prevent PendingIntents from using LocationRequest SystemApis. We don't
track permission removal, so we don't current reset the request if the
permission is lost.
-Make LocationRequest.getWorkSource() NonNull. Small quality of life
change to reduce null checks all over.
-Don't spend CPU coarsening location until we actually need to. The vast
majority of locations will never need to be coarsened. Don't bother
doing so until we actually need to.

Bug: 169887240
Test: manual + presubmit
Change-Id: I7ad6fe886eaede3ed9f46cebe4246d29d6b6e187
parent a7578af1
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -4171,7 +4171,7 @@ package android.location {
    method @Deprecated @NonNull public String getProvider();
    method @Deprecated @NonNull public String getProvider();
    method public int getQuality();
    method public int getQuality();
    method @Deprecated public float getSmallestDisplacement();
    method @Deprecated public float getSmallestDisplacement();
    method @Nullable public android.os.WorkSource getWorkSource();
    method @NonNull public android.os.WorkSource getWorkSource();
    method public boolean isHiddenFromAppOps();
    method public boolean isHiddenFromAppOps();
    method public boolean isLocationSettingsIgnored();
    method public boolean isLocationSettingsIgnored();
    method public boolean isLowPower();
    method public boolean isLowPower();
+1 −1
Original line number Original line Diff line number Diff line
@@ -1717,7 +1717,7 @@ package android.location {
  }
  }


  public final class LocationRequest implements android.os.Parcelable {
  public final class LocationRequest implements android.os.Parcelable {
    method @Nullable public android.os.WorkSource getWorkSource();
    method @NonNull public android.os.WorkSource getWorkSource();
    method public boolean isHiddenFromAppOps();
    method public boolean isHiddenFromAppOps();
    method public boolean isLocationSettingsIgnored();
    method public boolean isLocationSettingsIgnored();
    method public boolean isLowPower();
    method public boolean isLowPower();
+10 −0
Original line number Original line Diff line number Diff line
@@ -88,6 +88,16 @@ import java.util.function.Consumer;
@RequiresFeature(PackageManager.FEATURE_LOCATION)
@RequiresFeature(PackageManager.FEATURE_LOCATION)
public class LocationManager {
public class LocationManager {


    /**
     * For apps targeting Android S and above, LocationRequest system APIs may not be used with
     * PendingIntent location requests.
     *
     * @hide
     */
    @ChangeId
    @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.R)
    public static final long PREVENT_PENDING_INTENT_SYSTEM_API_USAGE = 169887240L;

    /**
    /**
     * For apps targeting Android S and above, location clients may receive historical locations
     * For apps targeting Android S and above, location clients may receive historical locations
     * (from before the present time) under some circumstances.
     * (from before the present time) under some circumstances.
+12 −9
Original line number Original line Diff line number Diff line
@@ -250,7 +250,7 @@ public final class LocationRequest implements Parcelable {
            boolean hiddenFromAppOps,
            boolean hiddenFromAppOps,
            boolean locationSettingsIgnored,
            boolean locationSettingsIgnored,
            boolean lowPower,
            boolean lowPower,
            @Nullable WorkSource workSource) {
            WorkSource workSource) {
        Preconditions.checkArgument(intervalMillis != PASSIVE_INTERVAL || quality == POWER_NONE);
        Preconditions.checkArgument(intervalMillis != PASSIVE_INTERVAL || quality == POWER_NONE);
        Preconditions.checkArgument(minUpdateIntervalMillis <= intervalMillis);
        Preconditions.checkArgument(minUpdateIntervalMillis <= intervalMillis);


@@ -265,7 +265,7 @@ public final class LocationRequest implements Parcelable {
        mHideFromAppOps = hiddenFromAppOps;
        mHideFromAppOps = hiddenFromAppOps;
        mLowPower = lowPower;
        mLowPower = lowPower;
        mLocationSettingsIgnored = locationSettingsIgnored;
        mLocationSettingsIgnored = locationSettingsIgnored;
        mWorkSource = workSource;
        mWorkSource = Objects.requireNonNull(workSource);
    }
    }


    /**
    /**
@@ -645,12 +645,15 @@ public final class LocationRequest implements Parcelable {
    @SystemApi
    @SystemApi
    @Deprecated
    @Deprecated
    public void setWorkSource(@Nullable WorkSource workSource) {
    public void setWorkSource(@Nullable WorkSource workSource) {
        if (workSource == null) {
            workSource = new WorkSource();
        }
        mWorkSource = workSource;
        mWorkSource = workSource;
    }
    }


    /**
    /**
     * Returns the work source used for power blame for this request. If null, the system is free to
     * Returns the work source used for power blame for this request. If empty, the system is free
     * assign power blame as it deems most appropriate.
     * to assign power blame as it deems most appropriate.
     *
     *
     * @return the work source used for power blame for this request
     * @return the work source used for power blame for this request
     *
     *
@@ -658,7 +661,7 @@ public final class LocationRequest implements Parcelable {
     */
     */
    @TestApi
    @TestApi
    @SystemApi
    @SystemApi
    public @Nullable WorkSource getWorkSource() {
    public @NonNull WorkSource getWorkSource() {
        return mWorkSource;
        return mWorkSource;
    }
    }


@@ -1062,9 +1065,9 @@ public final class LocationRequest implements Parcelable {
        }
        }


        /**
        /**
         * Sets the work source to use for power blame for this location request. Defaults to null,
         * Sets the work source to use for power blame for this location request. Defaults to an
         * which implies the system is free to assign power blame as it determines best for this
         * empty WorkSource, which implies the system is free to assign power blame as it determines
         * request (which usually means blaming the owner of the location listener).
         * best for this request (which usually means blaming the owner of the location listener).
         *
         *
         * <p>Permissions enforcement occurs when resulting location request is actually used, not
         * <p>Permissions enforcement occurs when resulting location request is actually used, not
         * when this method is invoked.
         * when this method is invoked.
@@ -1108,7 +1111,7 @@ public final class LocationRequest implements Parcelable {
                    mHiddenFromAppOps,
                    mHiddenFromAppOps,
                    mLocationSettingsIgnored,
                    mLocationSettingsIgnored,
                    mLowPower,
                    mLowPower,
                    mWorkSource);
                    new WorkSource(mWorkSource));
        }
        }
    }
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -4111,7 +4111,7 @@ package android.location {
    method @Deprecated @NonNull public String getProvider();
    method @Deprecated @NonNull public String getProvider();
    method public int getQuality();
    method public int getQuality();
    method @Deprecated public float getSmallestDisplacement();
    method @Deprecated public float getSmallestDisplacement();
    method @Nullable public android.os.WorkSource getWorkSource();
    method @NonNull public android.os.WorkSource getWorkSource();
    method public boolean isHiddenFromAppOps();
    method public boolean isHiddenFromAppOps();
    method public boolean isLocationSettingsIgnored();
    method public boolean isLocationSettingsIgnored();
    method public boolean isLowPower();
    method public boolean isLowPower();
Loading