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

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

Merge "Replace LocationProvider with ProviderProperties"

parents e9adc0bd b76a3541
Loading
Loading
Loading
Loading
+35 −13
Original line number Diff line number Diff line
@@ -19303,9 +19303,11 @@ package android.location {
    method public int getGnssYearOfHardware();
    method @Deprecated @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public android.location.GpsStatus getGpsStatus(@Nullable android.location.GpsStatus);
    method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.ACCESS_COARSE_LOCATION, android.Manifest.permission.ACCESS_FINE_LOCATION}) public android.location.Location getLastKnownLocation(@NonNull String);
    method @Nullable public android.location.LocationProvider getProvider(@NonNull String);
    method @Deprecated @Nullable public android.location.LocationProvider getProvider(@NonNull String);
    method @Nullable public android.location.ProviderProperties getProviderProperties(@NonNull String);
    method @NonNull public java.util.List<java.lang.String> getProviders(boolean);
    method @NonNull public java.util.List<java.lang.String> getProviders(@NonNull android.location.Criteria, boolean);
    method public boolean hasProvider(@NonNull String);
    method public boolean isLocationEnabled();
    method public boolean isProviderEnabled(@NonNull String);
    method @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public boolean registerAntennaInfoListener(@NonNull java.util.concurrent.Executor, @NonNull android.location.GnssAntennaInfo.Listener);
@@ -19366,18 +19368,18 @@ package android.location {
    field public static final String PROVIDERS_CHANGED_ACTION = "android.location.PROVIDERS_CHANGED";
  }
  public class LocationProvider {
    method public int getAccuracy();
    method public String getName();
    method public int getPowerRequirement();
    method public boolean hasMonetaryCost();
    method public boolean meetsCriteria(android.location.Criteria);
    method public boolean requiresCell();
    method public boolean requiresNetwork();
    method public boolean requiresSatellite();
    method public boolean supportsAltitude();
    method public boolean supportsBearing();
    method public boolean supportsSpeed();
  @Deprecated public class LocationProvider {
    method @Deprecated public int getAccuracy();
    method @Deprecated public String getName();
    method @Deprecated public int getPowerRequirement();
    method @Deprecated public boolean hasMonetaryCost();
    method @Deprecated public boolean meetsCriteria(android.location.Criteria);
    method @Deprecated public boolean requiresCell();
    method @Deprecated public boolean requiresNetwork();
    method @Deprecated public boolean requiresSatellite();
    method @Deprecated public boolean supportsAltitude();
    method @Deprecated public boolean supportsBearing();
    method @Deprecated public boolean supportsSpeed();
    field @Deprecated public static final int AVAILABLE = 2; // 0x2
    field @Deprecated public static final int OUT_OF_SERVICE = 0; // 0x0
    field @Deprecated public static final int TEMPORARILY_UNAVAILABLE = 1; // 0x1
@@ -19430,6 +19432,26 @@ package android.location {
    method public void onNmeaMessage(String, long);
  }
  public final class ProviderProperties implements android.os.Parcelable {
    method public int describeContents();
    method public int getAccuracy();
    method public int getPowerUsage();
    method public boolean hasAltitudeSupport();
    method public boolean hasBearingSupport();
    method public boolean hasCellRequirement();
    method public boolean hasMonetaryCost();
    method public boolean hasNetworkRequirement();
    method public boolean hasSatelliteRequirement();
    method public boolean hasSpeedSupport();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field public static final int ACCURACY_COARSE = 2; // 0x2
    field public static final int ACCURACY_FINE = 1; // 0x1
    field @NonNull public static final android.os.Parcelable.Creator<android.location.ProviderProperties> CREATOR;
    field public static final int POWER_USAGE_HIGH = 3; // 0x3
    field public static final int POWER_USAGE_LOW = 1; // 0x1
    field public static final int POWER_USAGE_MEDIUM = 2; // 0x2
  }
  public abstract class SettingInjectorService extends android.app.Service {
    ctor public SettingInjectorService(String);
    method public final android.os.IBinder onBind(android.content.Intent);
+2 −2
Original line number Diff line number Diff line
@@ -34,11 +34,10 @@ import android.location.LastLocationRequest;
import android.location.Location;
import android.location.LocationRequest;
import android.location.LocationTime;
import android.location.ProviderProperties;
import android.os.Bundle;
import android.os.ICancellationSignal;

import com.android.internal.location.ProviderProperties;

/**
 * System private API for talking with the location service.
 *
@@ -93,6 +92,7 @@ interface ILocationManager
    void flushGnssBatch();
    void stopGnssBatch();

    boolean hasProvider(String provider);
    List<String> getAllProviders();
    List<String> getProviders(in Criteria criteria, boolean enabledOnly);
    String getBestProvider(in Criteria criteria, boolean enabledOnly);
+53 −6
Original line number Diff line number Diff line
@@ -61,7 +61,6 @@ import android.os.UserHandle;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.listeners.ListenerExecutor;
import com.android.internal.listeners.ListenerTransportMultiplexer;
import com.android.internal.location.ProviderProperties;
import com.android.internal.util.Preconditions;

import java.lang.ref.WeakReference;
@@ -1615,6 +1614,25 @@ public class LocationManager {
        }
    }

    /**
     * Returns true if the given location provider exists on this device, irrespective of whether
     * it is currently enabled or not.
     *
     * @param provider a potential location provider
     * @return true if the location provider exists, false otherwise
     *
     * @throws IllegalArgumentException if provider is null
     */
    public boolean hasProvider(@NonNull String provider) {
        Preconditions.checkArgument(provider != null, "invalid null provider");

        try {
            return mService.hasProvider(provider);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns a list of the names of all available location providers. All providers are returned,
     * including those that are currently disabled.
@@ -1703,7 +1721,12 @@ public class LocationManager {
     * @return location provider information, or null if provider does not exist
     *
     * @throws IllegalArgumentException if provider is null
     *
     * @deprecated This method has no way to indicate that a provider's properties are unknown, and
     * so may return incorrect results on rare occasions. Use {@link #getProviderProperties(String)}
     * instead.
     */
    @Deprecated
    public @Nullable LocationProvider getProvider(@NonNull String provider) {
        Preconditions.checkArgument(provider != null, "invalid null provider");

@@ -1723,11 +1746,33 @@ public class LocationManager {
        }

        try {

            ProviderProperties properties = mService.getProviderProperties(provider);
            if (properties == null) {
            return new LocationProvider(provider, properties);
        } catch (IllegalArgumentException e) {
            // provider does not exist
            return null;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
            return new LocationProvider(provider, properties);
    }

    /**
     * Returns the properties of the given provider, or null if the properties are currently
     * unknown. Provider properties may change over time, although this is discouraged, and should
     * be rare. The most common transition is when provider properties go from being unknown to
     * known, which is most common near boot time.
     *
     * @param provider a provider listed by {@link #getAllProviders()}
     * @return location provider properties, or null if properties are currently unknown
     *
     * @throws IllegalArgumentException if provider is null or does not exist
     */
    public @Nullable ProviderProperties getProviderProperties(@NonNull String provider) {
        Preconditions.checkArgument(provider != null, "invalid null provider");

        try {
            return mService.getProviderProperties(provider);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1826,12 +1871,14 @@ public class LocationManager {
    public void addTestProvider(
            @NonNull String provider, boolean requiresNetwork, boolean requiresSatellite,
            boolean requiresCell, boolean hasMonetaryCost, boolean supportsAltitude,
            boolean supportsSpeed, boolean supportsBearing, int powerRequirement, int accuracy) {
            boolean supportsSpeed, boolean supportsBearing,
            @ProviderProperties.PowerUsage int powerUsage,
            @ProviderProperties.Accuracy int accuracy) {
        Preconditions.checkArgument(provider != null, "invalid null provider");

        ProviderProperties properties = new ProviderProperties(requiresNetwork,
                requiresSatellite, requiresCell, hasMonetaryCost, supportsAltitude, supportsSpeed,
                supportsBearing, powerRequirement, accuracy);
                supportsBearing, powerUsage, accuracy);
        try {
            mService.addTestProvider(provider, properties, mContext.getOpPackageName(),
                    mContext.getFeatureId());
+56 −28
Original line number Diff line number Diff line
@@ -16,23 +16,15 @@

package android.location;


import com.android.internal.location.ProviderProperties;
import android.annotation.Nullable;

/**
 * An abstract superclass for location providers.  A location provider
 * provides periodic reports on the geographical location of the
 * device.
 * Information about the properties of a location provider.
 *
 * <p> Each provider has a set of criteria under which it may be used;
 * for example, some providers require GPS hardware and visibility to
 * a number of satellites; others require the use of the cellular
 * radio, or access to a specific carrier's network, or to the
 * internet.  They may also have different battery consumption
 * characteristics or monetary costs to the user.  The {@link
 * Criteria} class allows providers to be selected based on
 * user-specified criteria.
 * @deprecated This class is incapable of representing unknown provider properties and may return
 * incorrect results when the properties are unknown.
 */
@Deprecated
public class LocationProvider {

    /**
@@ -54,9 +46,9 @@ public class LocationProvider {
    public static final int AVAILABLE = 2;

    private final String mName;
    private final ProviderProperties mProperties;
    private final @Nullable ProviderProperties mProperties;

    LocationProvider(String name, ProviderProperties properties) {
    LocationProvider(String name, @Nullable ProviderProperties properties) {
        mName = name;
        mProperties = properties;
    }
@@ -96,7 +88,7 @@ public class LocationProvider {
            return false;
        }
        if (criteria.getPowerRequirement() != Criteria.NO_REQUIREMENT &&
                criteria.getPowerRequirement() < properties.getPowerRequirement()) {
                criteria.getPowerRequirement() < properties.getPowerUsage()) {
            return false;
        }
        if (criteria.isAltitudeRequired() && !properties.hasAltitudeSupport()) {
@@ -119,8 +111,12 @@ public class LocationProvider {
     * data network (e.g., the Internet), false otherwise.
     */
    public boolean requiresNetwork() {
        if (mProperties == null) {
            return false;
        } else {
            return mProperties.hasNetworkRequirement();
        }
    }

    /**
     * Returns true if the provider requires access to a
@@ -128,8 +124,12 @@ public class LocationProvider {
     * otherwise.
     */
    public boolean requiresSatellite() {
        if (mProperties == null) {
            return false;
        } else {
            return mProperties.hasSatelliteRequirement();
        }
    }

    /**
     * Returns true if the provider requires access to an appropriate
@@ -137,8 +137,12 @@ public class LocationProvider {
     * otherwise.
     */
    public boolean requiresCell() {
        if (mProperties == null) {
            return false;
        } else {
            return mProperties.hasCellRequirement();
        }
    }

    /**
     * Returns true if the use of this provider may result in a
@@ -146,8 +150,12 @@ public class LocationProvider {
     * each provider to give accurate information.
     */
    public boolean hasMonetaryCost() {
        if (mProperties == null) {
            return false;
        } else {
            return mProperties.hasMonetaryCost();
        }
    }

    /**
     * Returns true if the provider is able to provide altitude
@@ -156,8 +164,12 @@ public class LocationProvider {
     * should return true.
     */
    public boolean supportsAltitude() {
        if (mProperties == null) {
            return false;
        } else {
            return mProperties.hasAltitudeSupport();
        }
    }

    /**
     * Returns true if the provider is able to provide speed
@@ -166,8 +178,12 @@ public class LocationProvider {
     * should return true.
     */
    public boolean supportsSpeed() {
        if (mProperties == null) {
            return false;
        } else {
            return mProperties.hasSpeedSupport();
        }
    }

    /**
     * Returns true if the provider is able to provide bearing
@@ -176,27 +192,39 @@ public class LocationProvider {
     * should return true.
     */
    public boolean supportsBearing() {
        if (mProperties == null) {
            return false;
        } else {
            return mProperties.hasBearingSupport();
        }
    }

    /**
     * Returns the power requirement for this provider.
     *
     * @return the power requirement for this provider, as one of the
     * constants Criteria.POWER_REQUIREMENT_*.
     * constants ProviderProperties.POWER_USAGE_*.
     */
    public int getPowerRequirement() {
        return mProperties.getPowerRequirement();
        if (mProperties == null) {
            return ProviderProperties.POWER_USAGE_HIGH;
        } else {
            return mProperties.getPowerUsage();
        }
    }

    /**
     * Returns a constant describing horizontal accuracy of this provider.
     * If the provider returns finer grain or exact location,
     * {@link Criteria#ACCURACY_FINE} is returned, otherwise if the
     * location is only approximate then {@link Criteria#ACCURACY_COARSE}
     * {@link ProviderProperties#ACCURACY_FINE} is returned, otherwise if the
     * location is only approximate then {@link ProviderProperties#ACCURACY_COARSE}
     * is returned.
     */
    public int getAccuracy() {
        if (mProperties == null) {
            return ProviderProperties.ACCURACY_COARSE;
        } else {
            return mProperties.getAccuracy();
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -14,6 +14,6 @@
 * limitations under the License.
 */

package com.android.internal.location;
package android.location;

parcelable ProviderProperties;
Loading