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

Commit 275fd7ed authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Extract LocationProviderManager"

parents 736e4b06 d6158258
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.location.util.identity.CallerIdentity;

import java.util.List;

/**
 * Location manager local system service interface.
 *
@@ -28,6 +30,16 @@ import android.location.util.identity.CallerIdentity;
 */
public abstract class LocationManagerInternal {

    /**
     * Listener for changes in provider enabled state.
     */
    public interface ProviderEnabledListener {
        /**
         * Called when the provider enabled state changes for a particular user.
         */
        void onProviderEnabledChanged(String provider, int userId, boolean enabled);
    }

    /**
     * Returns true if the given provider is enabled for the given user.
     *
@@ -37,6 +49,24 @@ public abstract class LocationManagerInternal {
     */
    public abstract boolean isProviderEnabledForUser(@NonNull String provider, int userId);

    /**
     * Adds a provider enabled listener. The given provider must exist.
     *
     * @param provider The provider to listen for changes
     * @param listener The listener
     */
    public abstract void addProviderEnabledListener(String provider,
            ProviderEnabledListener listener);

    /**
     * Removes a provider enabled listener. The given provider must exist.
     *
     * @param provider The provider to listen for changes
     * @param listener The listener
     */
    public abstract void removeProviderEnabledListener(String provider,
            ProviderEnabledListener listener);

    /**
     * Returns true if the given identity is a location provider.
     *
@@ -52,4 +82,10 @@ public abstract class LocationManagerInternal {
     */
    // TODO: there is no reason for this to exist as part of any API. move all the logic into gnss
    public abstract void sendNiResponse(int notifId, int userResponse);

    /**
     * Should only be used by GNSS code.
     */
    // TODO: there is no reason for this to exist as part of any API. create a real batching API
    public abstract void reportGnssBatchLocations(List<Location> locations);
}
+33 −23
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import android.util.TimeUtils;

import com.android.internal.util.Preconditions;

import java.util.Objects;


/**
 * A data object that contains quality of service parameters for requests
@@ -150,8 +152,6 @@ public final class LocationRequest implements Parcelable {

    @UnsupportedAppUsage
    private String mProvider;
    // if true, client requests coarse location, if false, client requests fine location
    private boolean mCoarseLocation;
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    private int mQuality;
    @UnsupportedAppUsage
@@ -257,7 +257,6 @@ public final class LocationRequest implements Parcelable {
    public LocationRequest() {
        this(
                /* provider= */ LocationManager.FUSED_PROVIDER,
                /* coarseLocation= */ false,
                /* quality= */ POWER_LOW,
                /* interval= */ DEFAULT_INTERVAL_MS,
                /* fastestInterval= */ (long) (DEFAULT_INTERVAL_MS / FASTEST_INTERVAL_FACTOR),
@@ -276,7 +275,6 @@ public final class LocationRequest implements Parcelable {
    public LocationRequest(LocationRequest src) {
        this(
                src.mProvider,
                src.mCoarseLocation,
                src.mQuality,
                src.mInterval,
                src.mFastestInterval,
@@ -293,7 +291,6 @@ public final class LocationRequest implements Parcelable {

    private LocationRequest(
            @NonNull String provider,
            boolean coarseLocation,
            int quality,
            long intervalMs,
            long fastestIntervalMs,
@@ -310,7 +307,6 @@ public final class LocationRequest implements Parcelable {
        checkQuality(quality);

        mProvider = provider;
        mCoarseLocation = coarseLocation;
        mQuality = quality;
        mInterval = intervalMs;
        mFastestInterval = fastestIntervalMs;
@@ -326,20 +322,6 @@ public final class LocationRequest implements Parcelable {
        mWorkSource = workSource;
    }

    /**
     * @hide
     */
    public boolean isCoarse() {
        return mCoarseLocation;
    }

    /**
     * @hide
     */
    public void setCoarse(boolean coarse) {
        mCoarseLocation = coarse;
    }

    /**
     * Set the quality of the request.
     *
@@ -720,7 +702,6 @@ public final class LocationRequest implements Parcelable {
                public LocationRequest createFromParcel(Parcel in) {
                    return new LocationRequest(
                            /* provider= */ in.readString(),
                            /* coarseLocation= */ in.readBoolean(),
                            /* quality= */ in.readInt(),
                            /* interval= */ in.readLong(),
                            /* fastestInterval= */ in.readLong(),
@@ -749,7 +730,6 @@ public final class LocationRequest implements Parcelable {
    @Override
    public void writeToParcel(Parcel parcel, int flags) {
        parcel.writeString(mProvider);
        parcel.writeBoolean(mCoarseLocation);
        parcel.writeInt(mQuality);
        parcel.writeLong(mInterval);
        parcel.writeLong(mFastestInterval);
@@ -784,6 +764,36 @@ public final class LocationRequest implements Parcelable {
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        LocationRequest that = (LocationRequest) o;
        return mQuality == that.mQuality
                && mInterval == that.mInterval
                && mFastestInterval == that.mFastestInterval
                && mExplicitFastestInterval == that.mExplicitFastestInterval
                && mExpireAt == that.mExpireAt
                && mExpireIn == that.mExpireIn
                && mNumUpdates == that.mNumUpdates
                && Float.compare(that.mSmallestDisplacement, mSmallestDisplacement) == 0
                && mHideFromAppOps == that.mHideFromAppOps
                && mLocationSettingsIgnored == that.mLocationSettingsIgnored
                && mLowPowerMode == that.mLowPowerMode
                && mProvider.equals(that.mProvider)
                && Objects.equals(mWorkSource, that.mWorkSource);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mProvider, mInterval, mWorkSource);
    }

    @NonNull
    @Override
    public String toString() {
@@ -794,7 +804,7 @@ public final class LocationRequest implements Parcelable {
        if (mQuality != POWER_NONE) {
            s.append(" interval=");
            TimeUtils.formatDuration(mInterval, s);
            if (mExplicitFastestInterval) {
            if (mExplicitFastestInterval && mFastestInterval != mInterval) {
                s.append(" fastestInterval=");
                TimeUtils.formatDuration(mFastestInterval, s);
            }
+2 −2
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ public class LocationFudger {
    public Location createCoarse(Location fine) {
        synchronized (this) {
            if (fine == mCachedFineLocation) {
                return new Location(mCachedCoarseLocation);
                return mCachedCoarseLocation;
            }
        }

@@ -154,7 +154,7 @@ public class LocationFudger {
            mCachedCoarseLocation = coarse;
        }

        return new Location(mCachedCoarseLocation);
        return mCachedCoarseLocation;
    }

    /**
+366 −2050

File changed.

Preview size limit exceeded, changes collapsed.

+1951 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading