From 342a828cf82c93ca9ff2e8177d8ab5574fa47c66 Mon Sep 17 00:00:00 2001 From: mar-v-in Date: Fri, 2 Jan 2015 19:59:03 +0100 Subject: [PATCH] Fixing lint's and add gradle support --- AndroidManifest.xml | 10 +- build.gradle | 63 + compat/AndroidManifest.xml | 4 + compat/build.gradle | 24 + .../src/android/location/GeocoderParams.java | 75 ++ .../src/android/location/Geofence.java | 182 +++ .../src/android/location/Location.java | 565 +++++++++ .../src/android/location/LocationManager.java | 1061 +++++++++++++++++ .../src/android/location/LocationRequest.java | 482 ++++++++ .../internal/location/ProviderProperties.java | 134 +++ .../internal/location/ProviderRequest.java | 72 ++ .../location/provider/GeocodeProvider.java | 64 + .../provider/LocationProviderBase.java | 145 +++ .../provider/LocationRequestUnbundled.java | 117 ++ .../provider/ProviderPropertiesUnbundled.java | 39 + .../provider/ProviderRequestUnbundled.java | 48 + .../android/location/ILocationProvider.aidl | 53 - .../location/provider/LocationProvider.java | 136 +-- settings.gradle | 1 + .../microg/nlp/location/BackendHelper.java | 13 +- .../nlp/ui/AbstractBackendPreference.java | 29 +- 21 files changed, 3123 insertions(+), 194 deletions(-) create mode 100644 build.gradle create mode 100644 compat/AndroidManifest.xml create mode 100644 compat/build.gradle create mode 100644 compat/current/src/android/location/GeocoderParams.java create mode 100644 compat/current/src/android/location/Geofence.java create mode 100644 compat/current/src/android/location/Location.java create mode 100644 compat/current/src/android/location/LocationManager.java create mode 100644 compat/current/src/android/location/LocationRequest.java create mode 100644 compat/current/src/com/android/internal/location/ProviderProperties.java create mode 100644 compat/current/src/com/android/internal/location/ProviderRequest.java create mode 100644 compat/current/src/com/android/location/provider/GeocodeProvider.java create mode 100644 compat/current/src/com/android/location/provider/LocationProviderBase.java create mode 100644 compat/current/src/com/android/location/provider/LocationRequestUnbundled.java create mode 100644 compat/current/src/com/android/location/provider/ProviderPropertiesUnbundled.java create mode 100644 compat/current/src/com/android/location/provider/ProviderRequestUnbundled.java delete mode 100644 compat/v9/src/android/location/ILocationProvider.aidl create mode 100644 settings.gradle diff --git a/AndroidManifest.xml b/AndroidManifest.xml index b7fb42e..3287235 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,11 +1,12 @@ + android:versionName="1.1.3" + android:versionCode="1103"> + android:minSdkVersion="9" + android:targetSdkVersion="21" /> @@ -43,6 +46,7 @@ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..9755fa2 --- /dev/null +++ b/build.gradle @@ -0,0 +1,63 @@ +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.0.0' + } +} + +apply plugin: 'com.android.application' + +dependencies { + compile 'com.android.support:support-v4:21.0.2' + compile 'com.android.support:appcompat-v7:21.0.2' +} + +/** + * This is a dirty approach to add a compile-time module that is not build into the APK. + * Doing everything in the beginning will break other dependencies, so we first compile the module + * and then configure gradle to change the compile classpath before compiling + */ + +tasks.findByPath(':preBuild').dependsOn += ':compatSetup' + +task compatSetup (dependsOn: [':compat:assembleDebug',':compat:assembleRelease']) << { + final java.util.concurrent.atomic.AtomicBoolean classpathSet = new java.util.concurrent.atomic.AtomicBoolean(false); + tasks.findAll{it.path.startsWith(':compile') && it.path.endsWith('Java')}.each{it.doFirst { + if (!classpathSet.get()) { + android.applicationVariants.all { + variant -> variant.javaCompile.classpath += project(':compat').files('build/intermediates/bundles/' + (variant.name.endsWith('ebug') ? 'debug' : 'release') + '/classes.jar'); + }; + classpathSet.set(true); + } + }}; +} + + +android { + compileSdkVersion 21 + buildToolsVersion "21.0.2" + lintOptions.abortOnError false + + sourceSets { + main { + manifest.srcFile 'AndroidManifest.xml' + java.srcDirs = ['src', 'api/src'] + aidl.srcDirs = ['src', 'api/src'] + res.srcDirs = ['res'] + } + } + + productFlavors { + NetworkLocation { + applicationId = 'com.google.android.gms' + } + LegacyNetworkLocation { + applicationId = 'com.google.android.location' + } + UnifiedNlp { + applicationId = 'org.microg.nlp' + } + } +} diff --git a/compat/AndroidManifest.xml b/compat/AndroidManifest.xml new file mode 100644 index 0000000..9597beb --- /dev/null +++ b/compat/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + diff --git a/compat/build.gradle b/compat/build.gradle new file mode 100644 index 0000000..a60e989 --- /dev/null +++ b/compat/build.gradle @@ -0,0 +1,24 @@ +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.0.0' + } +} + +apply plugin: 'com.android.library' + +android { + compileSdkVersion 21 + buildToolsVersion "21.0.2" + lintOptions.abortOnError false + + sourceSets { + main { + manifest.srcFile 'AndroidManifest.xml' + java.srcDirs = ['v9/src', 'current/src'] + aidl.srcDirs = ['v9/src', 'current/src'] + } + } +} diff --git a/compat/current/src/android/location/GeocoderParams.java b/compat/current/src/android/location/GeocoderParams.java new file mode 100644 index 0000000..a3d38e0 --- /dev/null +++ b/compat/current/src/android/location/GeocoderParams.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.location; + +import android.content.Context; +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.Locale; + +/** + * This class contains extra parameters to pass to an IGeocodeProvider + * implementation from the Geocoder class. Currently this contains the + * language, country and variant information from the Geocoder's locale + * as well as the Geocoder client's package name for geocoder server + * logging. This information is kept in a separate class to allow for + * future expansion of the IGeocodeProvider interface. + * + * @hide + */ +public class GeocoderParams implements Parcelable { + /** + * This object is only constructed by the Geocoder class + * + * @hide + */ + public GeocoderParams(Context context, Locale locale) { + } + + /** + * returns the Geocoder's locale + */ + public Locale getLocale() { + return null; + } + + /** + * returns the package name of the Geocoder's client + */ + public String getClientPackage() { + return null; + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + public GeocoderParams createFromParcel(Parcel in) { + return null; + } + + public GeocoderParams[] newArray(int size) { + return null; + } + }; + + public int describeContents() { + return 0; + } + + public void writeToParcel(Parcel parcel, int flags) { + } +} diff --git a/compat/current/src/android/location/Geofence.java b/compat/current/src/android/location/Geofence.java new file mode 100644 index 0000000..5de779a --- /dev/null +++ b/compat/current/src/android/location/Geofence.java @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.location; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * Represents a geographical boundary, also known as a geofence. + * + *

Currently only circular geofences are supported and they do not support altitude changes. + * + * @hide + */ +public final class Geofence implements Parcelable { + /** @hide */ + public static final int TYPE_HORIZONTAL_CIRCLE = 1; + + private final int mType; + private final double mLatitude; + private final double mLongitude; + private final float mRadius; + + /** + * Create a circular geofence (on a flat, horizontal plane). + * + * @param latitude latitude in degrees, between -90 and +90 inclusive + * @param longitude longitude in degrees, between -180 and +180 inclusive + * @param radius radius in meters + * @return a new geofence + * @throws IllegalArgumentException if any parameters are out of range + */ + public static Geofence createCircle(double latitude, double longitude, float radius) { + return new Geofence(latitude, longitude, radius); + } + + private Geofence(double latitude, double longitude, float radius) { + checkRadius(radius); + checkLatLong(latitude, longitude); + mType = TYPE_HORIZONTAL_CIRCLE; + mLatitude = latitude; + mLongitude = longitude; + mRadius = radius; + } + + /** @hide */ + public int getType() { + return mType; + } + + /** @hide */ + public double getLatitude() { + return mLatitude; + } + + /** @hide */ + public double getLongitude() { + return mLongitude; + } + + /** @hide */ + public float getRadius() { + return mRadius; + } + + private static void checkRadius(float radius) { + if (radius <= 0) { + throw new IllegalArgumentException("invalid radius: " + radius); + } + } + + private static void checkLatLong(double latitude, double longitude) { + if (latitude > 90.0 || latitude < -90.0) { + throw new IllegalArgumentException("invalid latitude: " + latitude); + } + if (longitude > 180.0 || longitude < -180.0) { + throw new IllegalArgumentException("invalid longitude: " + longitude); + } + } + + private static void checkType(int type) { + if (type != TYPE_HORIZONTAL_CIRCLE) { + throw new IllegalArgumentException("invalid type: " + type); + } + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override + public Geofence createFromParcel(Parcel in) { + int type = in.readInt(); + double latitude = in.readDouble(); + double longitude = in.readDouble(); + float radius = in.readFloat(); + checkType(type); + return Geofence.createCircle(latitude, longitude, radius); + } + @Override + public Geofence[] newArray(int size) { + return new Geofence[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int flags) { + parcel.writeInt(mType); + parcel.writeDouble(mLatitude); + parcel.writeDouble(mLongitude); + parcel.writeFloat(mRadius); + } + + private static String typeToString(int type) { + switch (type) { + case TYPE_HORIZONTAL_CIRCLE: + return "CIRCLE"; + default: + checkType(type); + return null; + } + } + + @Override + public String toString() { + return String.format("Geofence[%s %.6f, %.6f %.0fm]", + typeToString(mType), mLatitude, mLongitude, mRadius); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(mLatitude); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(mLongitude); + result = prime * result + (int) (temp ^ (temp >>> 32)); + result = prime * result + Float.floatToIntBits(mRadius); + result = prime * result + mType; + return result; + } + + /** + * Two geofences are equal if they have identical properties. + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof Geofence)) + return false; + Geofence other = (Geofence) obj; + if (mRadius != other.mRadius) + return false; + if (mLatitude != other.mLatitude) + return false; + if (mLongitude != other.mLongitude) + return false; + if (mType != other.mType) + return false; + return true; + } +} diff --git a/compat/current/src/android/location/Location.java b/compat/current/src/android/location/Location.java new file mode 100644 index 0000000..194d8c7 --- /dev/null +++ b/compat/current/src/android/location/Location.java @@ -0,0 +1,565 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.location; + +import android.os.Bundle; +import android.os.Parcel; +import android.os.Parcelable; +import android.util.Printer; + +/** + * A data class representing a geographic location. + *

+ *

A location can consist of a latitude, longitude, timestamp, + * and other information such as bearing, altitude and velocity. + *

+ *

All locations generated by the {@link LocationManager} are + * guaranteed to have a valid latitude, longitude, and timestamp + * (both UTC time and elapsed real-time since boot), all other + * parameters are optional. + */ +public class Location implements Parcelable { + /** + * Constant used to specify formatting of a latitude or longitude + * in the form "[+-]DDD.DDDDD where D indicates degrees. + */ + public static final int FORMAT_DEGREES = 0; + + /** + * Constant used to specify formatting of a latitude or longitude + * in the form "[+-]DDD:MM.MMMMM" where D indicates degrees and + * M indicates minutes of arc (1 minute = 1/60th of a degree). + */ + public static final int FORMAT_MINUTES = 1; + + /** + * Constant used to specify formatting of a latitude or longitude + * in the form "DDD:MM:SS.SSSSS" where D indicates degrees, M + * indicates minutes of arc, and S indicates seconds of arc (1 + * minute = 1/60th of a degree, 1 second = 1/3600th of a degree). + */ + public static final int FORMAT_SECONDS = 2; + + /** + * Bundle key for a version of the location that has been fed through + * LocationFudger. Allows location providers to flag locations as being + * safe for use with ACCESS_COARSE_LOCATION permission. + * + * @hide + */ + public static final String EXTRA_COARSE_LOCATION = "coarseLocation"; + + /** + * Bundle key for a version of the location containing no GPS data. + * Allows location providers to flag locations as being safe to + * feed to LocationFudger. + * + * @hide + */ + public static final String EXTRA_NO_GPS_LOCATION = "noGPSLocation"; + + /** + * Construct a new Location with a named provider. + *

+ *

By default time, latitude and longitude are 0, and the location + * has no bearing, altitude, speed, accuracy or extras. + * + * @param provider the name of the provider that generated this location + */ + public Location(String provider) { + } + + /** + * Construct a new Location object that is copied from an existing one. + */ + public Location(Location l) { + } + + /** + * Sets the contents of the location to the values from the given location. + */ + public void set(Location l) { + } + + /** + * Clears the contents of the location. + */ + public void reset() { + } + + /** + * Converts a coordinate to a String representation. The outputType + * may be one of FORMAT_DEGREES, FORMAT_MINUTES, or FORMAT_SECONDS. + * The coordinate must be a valid double between -180.0 and 180.0. + * + * @throws IllegalArgumentException if coordinate is less than + * -180.0, greater than 180.0, or is not a number. + * @throws IllegalArgumentException if outputType is not one of + * FORMAT_DEGREES, FORMAT_MINUTES, or FORMAT_SECONDS. + */ + public static String convert(double coordinate, int outputType) { + return null; + } + + /** + * Converts a String in one of the formats described by + * FORMAT_DEGREES, FORMAT_MINUTES, or FORMAT_SECONDS into a + * double. + * + * @throws NullPointerException if coordinate is null + * @throws IllegalArgumentException if the coordinate is not + * in one of the valid formats. + */ + public static double convert(String coordinate) { + return 0; + } + + private static void computeDistanceAndBearing(double lat1, double lon1, + double lat2, double lon2, float[] results) { + } + + /** + * Computes the approximate distance in meters between two + * locations, and optionally the initial and final bearings of the + * shortest path between them. Distance and bearing are defined using the + * WGS84 ellipsoid. + *

+ *

The computed distance is stored in results[0]. If results has length + * 2 or greater, the initial bearing is stored in results[1]. If results has + * length 3 or greater, the final bearing is stored in results[2]. + * + * @param startLatitude the starting latitude + * @param startLongitude the starting longitude + * @param endLatitude the ending latitude + * @param endLongitude the ending longitude + * @param results an array of floats to hold the results + * @throws IllegalArgumentException if results is null or has length < 1 + */ + public static void distanceBetween(double startLatitude, double startLongitude, + double endLatitude, double endLongitude, float[] results) { + } + + /** + * Returns the approximate distance in meters between this + * location and the given location. Distance is defined using + * the WGS84 ellipsoid. + * + * @param dest the destination location + * @return the approximate distance in meters + */ + public float distanceTo(Location dest) { + return 0; + } + + /** + * Returns the approximate initial bearing in degrees East of true + * North when traveling along the shortest path between this + * location and the given location. The shortest path is defined + * using the WGS84 ellipsoid. Locations that are (nearly) + * antipodal may produce meaningless results. + * + * @param dest the destination location + * @return the initial bearing in degrees + */ + public float bearingTo(Location dest) { + return 0; + } + + /** + * Returns the name of the provider that generated this fix. + * + * @return the provider, or null if it has not been set + */ + public String getProvider() { + return null; + } + + /** + * Sets the name of the provider that generated this fix. + */ + public void setProvider(String provider) { + } + + /** + * Return the UTC time of this fix, in milliseconds since January 1, 1970. + *

+ *

Note that the UTC time on a device is not monotonic: it + * can jump forwards or backwards unpredictably. So always use + * {@link #getElapsedRealtimeNanos} when calculating time deltas. + *

+ *

On the other hand, {@link #getTime} is useful for presenting + * a human readable time to the user, or for carefully comparing + * location fixes across reboot or across devices. + *

+ *

All locations generated by the {@link LocationManager} + * are guaranteed to have a valid UTC time, however remember that + * the system time may have changed since the location was generated. + * + * @return time of fix, in milliseconds since January 1, 1970. + */ + public long getTime() { + return 0; + } + + /** + * Set the UTC time of this fix, in milliseconds since January 1, + * 1970. + * + * @param time UTC time of this fix, in milliseconds since January 1, 1970 + */ + public void setTime(long time) { + } + + /** + * Return the time of this fix, in elapsed real-time since system boot. + *

+ *

This value can be reliably compared to + * {@link android.os.SystemClock#elapsedRealtimeNanos}, + * to calculate the age of a fix and to compare Location fixes. This + * is reliable because elapsed real-time is guaranteed monotonic for + * each system boot and continues to increment even when the system + * is in deep sleep (unlike {@link #getTime}. + *

+ *

All locations generated by the {@link LocationManager} + * are guaranteed to have a valid elapsed real-time. + * + * @return elapsed real-time of fix, in nanoseconds since system boot. + */ + public long getElapsedRealtimeNanos() { + return 0; + } + + /** + * Set the time of this fix, in elapsed real-time since system boot. + * + * @param time elapsed real-time of fix, in nanoseconds since system boot. + */ + public void setElapsedRealtimeNanos(long time) { + } + + /** + * Get the latitude, in degrees. + *

+ *

All locations generated by the {@link LocationManager} + * will have a valid latitude. + */ + public double getLatitude() { + return 0; + } + + /** + * Set the latitude, in degrees. + */ + public void setLatitude(double latitude) { + } + + /** + * Get the longitude, in degrees. + *

+ *

All locations generated by the {@link LocationManager} + * will have a valid longitude. + */ + public double getLongitude() { + return 0; + } + + /** + * Set the longitude, in degrees. + */ + public void setLongitude(double longitude) { + } + + /** + * True if this location has an altitude. + */ + public boolean hasAltitude() { + return false; + } + + /** + * Get the altitude if available, in meters above the WGS 84 reference + * ellipsoid. + *

+ *

If this location does not have an altitude then 0.0 is returned. + */ + public double getAltitude() { + return 0; + } + + /** + * Set the altitude, in meters above the WGS 84 reference ellipsoid. + *

+ *

Following this call {@link #hasAltitude} will return true. + */ + public void setAltitude(double altitude) { + } + + /** + * Remove the altitude from this location. + *

+ *

Following this call {@link #hasAltitude} will return false, + * and {@link #getAltitude} will return 0.0. + */ + public void removeAltitude() { + } + + /** + * True if this location has a speed. + */ + public boolean hasSpeed() { + return false; + } + + /** + * Get the speed if it is available, in meters/second over ground. + *

+ *

If this location does not have a speed then 0.0 is returned. + */ + public float getSpeed() { + return 0; + } + + /** + * Set the speed, in meters/second over ground. + *

+ *

Following this call {@link #hasSpeed} will return true. + */ + public void setSpeed(float speed) { + } + + /** + * Remove the speed from this location. + *

+ *

Following this call {@link #hasSpeed} will return false, + * and {@link #getSpeed} will return 0.0. + */ + public void removeSpeed() { + } + + /** + * True if this location has a bearing. + */ + public boolean hasBearing() { + return false; + } + + /** + * Get the bearing, in degrees. + *

+ *

Bearing is the horizontal direction of travel of this device, + * and is not related to the device orientation. It is guaranteed to + * be in the range (0.0, 360.0] if the device has a bearing. + *

+ *

If this location does not have a bearing then 0.0 is returned. + */ + public float getBearing() { + return 0; + } + + /** + * Set the bearing, in degrees. + *

+ *

Bearing is the horizontal direction of travel of this device, + * and is not related to the device orientation. + *

+ *

The input will be wrapped into the range (0.0, 360.0]. + */ + public void setBearing(float bearing) { + } + + /** + * Remove the bearing from this location. + *

+ *

Following this call {@link #hasBearing} will return false, + * and {@link #getBearing} will return 0.0. + */ + public void removeBearing() { + } + + /** + * True if this location has an accuracy. + *

+ *

All locations generated by the {@link LocationManager} have an + * accuracy. + */ + public boolean hasAccuracy() { + return false; + } + + /** + * Get the estimated accuracy of this location, in meters. + *

+ *

We define accuracy as the radius of 68% confidence. In other + * words, if you draw a circle centered at this location's + * latitude and longitude, and with a radius equal to the accuracy, + * then there is a 68% probability that the true location is inside + * the circle. + *

+ *

In statistical terms, it is assumed that location errors + * are random with a normal distribution, so the 68% confidence circle + * represents one standard deviation. Note that in practice, location + * errors do not always follow such a simple distribution. + *

+ *

This accuracy estimation is only concerned with horizontal + * accuracy, and does not indicate the accuracy of bearing, + * velocity or altitude if those are included in this Location. + *

+ *

If this location does not have an accuracy, then 0.0 is returned. + * All locations generated by the {@link LocationManager} include + * an accuracy. + */ + public float getAccuracy() { + return 0; + } + + /** + * Set the estimated accuracy of this location, meters. + *

+ *

See {@link #getAccuracy} for the definition of accuracy. + *

+ *

Following this call {@link #hasAccuracy} will return true. + */ + public void setAccuracy(float accuracy) { + } + + /** + * Remove the accuracy from this location. + *

+ *

Following this call {@link #hasAccuracy} will return false, and + * {@link #getAccuracy} will return 0.0. + */ + public void removeAccuracy() { + } + + /** + * Return true if this Location object is complete. + *

+ *

A location object is currently considered complete if it has + * a valid provider, accuracy, wall-clock time and elapsed real-time. + *

+ *

All locations supplied by the {@link LocationManager} to + * applications must be complete. + * + * @hide + * @see #makeComplete + */ + public boolean isComplete() { + return false; + } + + /** + * Helper to fill incomplete fields. + *

+ *

Used to assist in backwards compatibility with + * Location objects received from applications. + * + * @hide + * @see #isComplete + */ + public void makeComplete() { + } + + /** + * Returns additional provider-specific information about the + * location fix as a Bundle. The keys and values are determined + * by the provider. If no additional information is available, + * null is returned. + *

+ *

A number of common key/value pairs are listed + * below. Providers that use any of the keys on this list must + * provide the corresponding value as described below. + *

+ *

    + *
  • satellites - the number of satellites used to derive the fix + *
+ */ + public Bundle getExtras() { + return null; + } + + /** + * Sets the extra information associated with this fix to the + * given Bundle. + */ + public void setExtras(Bundle extras) { + } + + public void dump(Printer pw, String prefix) { + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public Location createFromParcel(Parcel in) { + return null; + } + + @Override + public Location[] newArray(int size) { + return null; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int flags) { + } + + /** + * Returns one of the optional extra {@link Location}s that can be attached + * to this Location. + * + * @param key the key associated with the desired extra Location + * @return the extra Location, or null if unavailable + * @hide + */ + public Location getExtraLocation(String key) { + return null; + } + + /** + * Attaches an extra {@link Location} to this Location. + * + * @param key the key associated with the Location extra + * @param location the Location to attach + * @hide + */ + public void setExtraLocation(String key, Location 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 false; + } + + /** + * 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) { + } +} diff --git a/compat/current/src/android/location/LocationManager.java b/compat/current/src/android/location/LocationManager.java new file mode 100644 index 0000000..dedc0c7 --- /dev/null +++ b/compat/current/src/android/location/LocationManager.java @@ -0,0 +1,1061 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.location; + +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.os.Looper; + +import java.util.List; + +/** + * This class provides access to the system location services. These + * services allow applications to obtain periodic updates of the + * device's geographical location, or to fire an application-specified + * {@link Intent} when the device enters the proximity of a given + * geographical location. + *

+ *

You do not + * instantiate this class directly; instead, retrieve it through + * {@link android.content.Context#getSystemService + * Context.getSystemService(Context.LOCATION_SERVICE)}. + *

+ *

Unless noted, all Location API methods require + * the {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} or + * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permissions. + * If your application only has the coarse permission then it will not have + * access to the GPS or passive location providers. Other providers will still + * return location results, but the update rate will be throttled and the exact + * location will be obfuscated to a coarse level of accuracy. + */ +public class LocationManager { + + /** + * Name of the network location provider. + *

This provider determines location based on + * availability of cell tower and WiFi access points. Results are retrieved + * by means of a network lookup. + */ + public static final String NETWORK_PROVIDER = "network"; + + /** + * Name of the GPS location provider. + *

+ *

This provider determines location using + * satellites. Depending on conditions, this provider may take a while to return + * a location fix. Requires the permission + * {@link android.Manifest.permission#ACCESS_FINE_LOCATION}. + *

+ *

The extras Bundle for the GPS location provider can contain the + * following key/value pairs: + *

    + *
  • satellites - the number of satellites used to derive the fix + *
+ */ + public static final String GPS_PROVIDER = "gps"; + + /** + * A special location provider for receiving locations without actually initiating + * a location fix. + *

+ *

This provider can be used to passively receive location updates + * when other applications or services request them without actually requesting + * the locations yourself. This provider will return locations generated by other + * providers. You can query the {@link Location#getProvider()} method to determine + * the origin of the location update. Requires the permission + * {@link android.Manifest.permission#ACCESS_FINE_LOCATION}, although if the GPS is + * not enabled this provider might only return coarse fixes. + */ + public static final String PASSIVE_PROVIDER = "passive"; + + /** + * Name of the Fused location provider. + *

+ *

This provider combines inputs for all possible location sources + * to provide the best possible Location fix. It is implicitly + * used for all API's that involve the {@link LocationRequest} + * object. + * + * @hide + */ + public static final String FUSED_PROVIDER = "fused"; + + /** + * Key used for the Bundle extra holding a boolean indicating whether + * a proximity alert is entering (true) or exiting (false).. + */ + public static final String KEY_PROXIMITY_ENTERING = "entering"; + + /** + * Key used for a Bundle extra holding an Integer status value + * when a status change is broadcast using a PendingIntent. + */ + public static final String KEY_STATUS_CHANGED = "status"; + + /** + * Key used for a Bundle extra holding an Boolean status value + * when a provider enabled/disabled event is broadcast using a PendingIntent. + */ + public static final String KEY_PROVIDER_ENABLED = "providerEnabled"; + + /** + * Key used for a Bundle extra holding a Location value + * when a location change is broadcast using a PendingIntent. + */ + public static final String KEY_LOCATION_CHANGED = "location"; + + /** + * Broadcast intent action indicating that the GPS has either been + * enabled or disabled. An intent extra provides this state as a boolean, + * where {@code true} means enabled. + * + * @hide + * @see #EXTRA_GPS_ENABLED + */ + public static final String GPS_ENABLED_CHANGE_ACTION = + "android.location.GPS_ENABLED_CHANGE"; + + /** + * Broadcast intent action when the configured location providers + * change. For use with {@link #isProviderEnabled(String)}. If you're interacting with the + * {@link android.provider.Settings.Secure#LOCATION_MODE} API, use {@link #MODE_CHANGED_ACTION} + * instead. + */ + public static final String PROVIDERS_CHANGED_ACTION = + "android.location.PROVIDERS_CHANGED"; + + /** + * Broadcast intent action when {@link android.provider.Settings.Secure#LOCATION_MODE} changes. + * For use with the {@link android.provider.Settings.Secure#LOCATION_MODE} API. + * If you're interacting with {@link #isProviderEnabled(String)}, use + * {@link #PROVIDERS_CHANGED_ACTION} instead. + *

+ * In the future, there may be mode changes that do not result in + * {@link #PROVIDERS_CHANGED_ACTION} broadcasts. + */ + public static final String MODE_CHANGED_ACTION = "android.location.MODE_CHANGED"; + + /** + * Broadcast intent action indicating that the GPS has either started or + * stopped receiving GPS fixes. An intent extra provides this state as a + * boolean, where {@code true} means that the GPS is actively receiving fixes. + * + * @hide + * @see #EXTRA_GPS_ENABLED + */ + public static final String GPS_FIX_CHANGE_ACTION = + "android.location.GPS_FIX_CHANGE"; + + /** + * The lookup key for a boolean that indicates whether GPS is enabled or + * disabled. {@code true} means GPS is enabled. Retrieve it with + * {@link android.content.Intent#getBooleanExtra(String, boolean)}. + * + * @hide + */ + public static final String EXTRA_GPS_ENABLED = "enabled"; + + /** + * Broadcast intent action indicating that a high power location requests + * has either started or stopped being active. The current state of + * active location requests should be read from AppOpsManager using + * {@code OP_MONITOR_HIGH_POWER_LOCATION}. + * + * @hide + */ + public static final String HIGH_POWER_REQUEST_CHANGE_ACTION = + "android.location.HIGH_POWER_REQUEST_CHANGE"; + + /** + * @hide - hide this constructor because it has a parameter + * of type ILocationManager, which is a system private class. The + * right way to create an instance of this class is using the + * factory Context.getSystemService. + */ + public LocationManager(Context context, Object service) { + } + + /** + * Returns a list of the names of all known location providers. + *

All providers are returned, including ones that are not permitted to + * be accessed by the calling activity or are currently disabled. + * + * @return list of Strings containing names of the provider + */ + public List getAllProviders() { + return null; + } + + /** + * Returns a list of the names of location providers. + * + * @param enabledOnly if true then only the providers which are currently + * enabled are returned. + * @return list of Strings containing names of the providers + */ + public List getProviders(boolean enabledOnly) { + return null; + } + + /** + * Returns the information associated with the location provider of the + * given name, or null if no provider exists by that name. + * + * @param name the provider name + * @return a LocationProvider, or null + * @throws IllegalArgumentException if name is null or does not exist + * @throws SecurityException if the caller is not permitted to access the + * given provider. + */ + public LocationProvider getProvider(String name) { + return null; + } + + /** + * Returns a list of the names of LocationProviders that satisfy the given + * criteria, or null if none do. Only providers that are permitted to be + * accessed by the calling activity will be returned. + * + * @param criteria the criteria that the returned providers must match + * @param enabledOnly if true then only the providers which are currently + * enabled are returned. + * @return list of Strings containing names of the providers + */ + public List getProviders(Criteria criteria, boolean enabledOnly) { + return null; + } + + /** + * Returns the name of the provider that best meets the given criteria. Only providers + * that are permitted to be accessed by the calling activity will be + * returned. If several providers meet the criteria, the one with the best + * accuracy is returned. If no provider meets the criteria, + * the criteria are loosened in the following sequence: + *

+ *

    + *
  • power requirement + *
  • accuracy + *
  • bearing + *
  • speed + *
  • altitude + *
+ *

+ *

Note that the requirement on monetary cost is not removed + * in this process. + * + * @param criteria the criteria that need to be matched + * @param enabledOnly if true then only a provider that is currently enabled is returned + * @return name of the provider that best matches the requirements + */ + public String getBestProvider(Criteria criteria, boolean enabledOnly) { + return null; + } + + /** + * Register for location updates using the named provider, and a + * pending intent. + *

+ *

See {@link #requestLocationUpdates(long, float, Criteria, PendingIntent)} + * for more detail on how to use this method. + * + * @param provider the name of the provider with which to register + * @param minTime minimum time interval between location updates, in milliseconds + * @param minDistance minimum distance between location updates, in meters + * @param listener a {@link LocationListener} whose + * {@link LocationListener#onLocationChanged} method will be called for + * each location update + * @throws IllegalArgumentException if provider is null or doesn't exist + * on this device + * @throws IllegalArgumentException if listener is null + * @throws RuntimeException if the calling thread has no Looper + * @throws SecurityException if no suitable permission is present + */ + public void requestLocationUpdates(String provider, long minTime, float minDistance, + LocationListener listener) { + } + + /** + * Register for location updates using the named provider, and a callback on + * the specified looper thread. + *

+ *

See {@link #requestLocationUpdates(long, float, Criteria, PendingIntent)} + * for more detail on how to use this method. + * + * @param provider the name of the provider with which to register + * @param minTime minimum time interval between location updates, in milliseconds + * @param minDistance minimum distance between location updates, in meters + * @param listener a {@link LocationListener} whose + * {@link LocationListener#onLocationChanged} method will be called for + * each location update + * @param looper a Looper object whose message queue will be used to + * implement the callback mechanism, or null to make callbacks on the calling + * thread + * @throws IllegalArgumentException if provider is null or doesn't exist + * @throws IllegalArgumentException if listener is null + * @throws SecurityException if no suitable permission is present + */ + public void requestLocationUpdates(String provider, long minTime, float minDistance, + LocationListener listener, Looper looper) { + } + + /** + * Register for location updates using a Criteria, and a callback + * on the specified looper thread. + *

+ *

See {@link #requestLocationUpdates(long, float, Criteria, PendingIntent)} + * for more detail on how to use this method. + * + * @param minTime minimum time interval between location updates, in milliseconds + * @param minDistance minimum distance between location updates, in meters + * @param criteria contains parameters for the location manager to choose the + * appropriate provider and parameters to compute the location + * @param listener a {@link LocationListener} whose + * {@link LocationListener#onLocationChanged} method will be called for + * each location update + * @param looper a Looper object whose message queue will be used to + * implement the callback mechanism, or null to make callbacks on the calling + * thread + * @throws IllegalArgumentException if criteria is null + * @throws IllegalArgumentException if listener is null + * @throws SecurityException if no suitable permission is present + */ + public void requestLocationUpdates(long minTime, float minDistance, Criteria criteria, + LocationListener listener, Looper looper) { + } + + /** + * Register for location updates using the named provider, and a + * pending intent. + *

+ *

See {@link #requestLocationUpdates(long, float, Criteria, PendingIntent)} + * for more detail on how to use this method. + * + * @param provider the name of the provider with which to register + * @param minTime minimum time interval between location updates, in milliseconds + * @param minDistance minimum distance between location updates, in meters + * @param intent a {@link PendingIntent} to be sent for each location update + * @throws IllegalArgumentException if provider is null or doesn't exist + * on this device + * @throws IllegalArgumentException if intent is null + * @throws SecurityException if no suitable permission is present + */ + public void requestLocationUpdates(String provider, long minTime, float minDistance, + PendingIntent intent) { + } + + /** + * Register for location updates using a Criteria and pending intent. + *

+ *

The requestLocationUpdates() and + * requestSingleUpdate() register the current activity to be + * updated periodically by the named provider, or by the provider matching + * the specified {@link Criteria}, with location and status updates. + *

+ *

It may take a while to receive the first location update. If + * an immediate location is required, applications may use the + * {@link #getLastKnownLocation(String)} method. + *

+ *

Location updates are received either by {@link LocationListener} + * callbacks, or by broadcast intents to a supplied {@link PendingIntent}. + *

+ *

If the caller supplied a pending intent, then location updates + * are sent with a key of {@link #KEY_LOCATION_CHANGED} and a + * {@link android.location.Location} value. + *

+ *

The location update interval can be controlled using the minTime parameter. + * The elapsed time between location updates will never be less than + * minTime, although it can be more depending on the Location Provider + * implementation and the update interval requested by other applications. + *

+ *

Choosing a sensible value for minTime is important to conserve + * battery life. Each location update requires power from + * GPS, WIFI, Cell and other radios. Select a minTime value as high as + * possible while still providing a reasonable user experience. + * If your application is not in the foreground and showing + * location to the user then your application should avoid using an active + * provider (such as {@link #NETWORK_PROVIDER} or {@link #GPS_PROVIDER}), + * but if you insist then select a minTime of 5 * 60 * 1000 (5 minutes) + * or greater. If your application is in the foreground and showing + * location to the user then it is appropriate to select a faster + * update interval. + *

+ *

The minDistance parameter can also be used to control the + * frequency of location updates. If it is greater than 0 then the + * location provider will only send your application an update when + * the location has changed by at least minDistance meters, AND + * at least minTime milliseconds have passed. However it is more + * difficult for location providers to save power using the minDistance + * parameter, so minTime should be the primary tool to conserving battery + * life. + *

+ *

If your application wants to passively observe location + * updates triggered by other applications, but not consume + * any additional power otherwise, then use the {@link #PASSIVE_PROVIDER} + * This provider does not actively turn on or modify active location + * providers, so you do not need to be as careful about minTime and + * minDistance. However if your application performs heavy work + * on a location update (such as network activity) then you should + * select non-zero values for minTime and/or minDistance to rate-limit + * your update frequency in the case another application enables a + * location provider with extremely fast updates. + *

+ *

In case the provider is disabled by the user, updates will stop, + * and a provider availability update will be sent. + * As soon as the provider is enabled again, + * location updates will immediately resume and a provider availability + * update sent. Providers can also send status updates, at any time, + * with extra's specific to the provider. If a callback was supplied + * then status and availability updates are via + * {@link LocationListener#onProviderDisabled}, + * {@link LocationListener#onProviderEnabled} or + * {@link LocationListener#onStatusChanged}. Alternately, if a + * pending intent was supplied then status and availability updates + * are broadcast intents with extra keys of + * {@link #KEY_PROVIDER_ENABLED} or {@link #KEY_STATUS_CHANGED}. + *

+ *

If a {@link LocationListener} is used but with no Looper specified + * then the calling thread must already + * be a {@link android.os.Looper} thread such as the main thread of the + * calling Activity. If a Looper is specified with a {@link LocationListener} + * then callbacks are made on the supplied Looper thread. + *

+ *

Prior to Jellybean, the minTime parameter was + * only a hint, and some location provider implementations ignored it. + * From Jellybean and onwards it is mandatory for Android compatible + * devices to observe both the minTime and minDistance parameters. + * + * @param minTime minimum time interval between location updates, in milliseconds + * @param minDistance minimum distance between location updates, in meters + * @param criteria contains parameters for the location manager to choose the + * appropriate provider and parameters to compute the location + * @param intent a {@link PendingIntent} to be sent for each location update + * @throws IllegalArgumentException if criteria is null + * @throws IllegalArgumentException if intent is null + * @throws SecurityException if no suitable permission is present + */ + public void requestLocationUpdates(long minTime, float minDistance, Criteria criteria, + PendingIntent intent) { + } + + /** + * Register for a single location update using the named provider and + * a callback. + *

+ *

See {@link #requestLocationUpdates(long, float, Criteria, PendingIntent)} + * for more detail on how to use this method. + * + * @param provider the name of the provider with which to register + * @param listener a {@link LocationListener} whose + * {@link LocationListener#onLocationChanged} method will be called when + * the location update is available + * @param looper a Looper object whose message queue will be used to + * implement the callback mechanism, or null to make callbacks on the calling + * thread + * @throws IllegalArgumentException if provider is null or doesn't exist + * @throws IllegalArgumentException if listener is null + * @throws SecurityException if no suitable permission is present + */ + public void requestSingleUpdate(String provider, LocationListener listener, Looper looper) { + } + + /** + * Register for a single location update using a Criteria and + * a callback. + *

+ *

See {@link #requestLocationUpdates(long, float, Criteria, PendingIntent)} + * for more detail on how to use this method. + * + * @param criteria contains parameters for the location manager to choose the + * appropriate provider and parameters to compute the location + * @param listener a {@link LocationListener} whose + * {@link LocationListener#onLocationChanged} method will be called when + * the location update is available + * @param looper a Looper object whose message queue will be used to + * implement the callback mechanism, or null to make callbacks on the calling + * thread + * @throws IllegalArgumentException if criteria is null + * @throws IllegalArgumentException if listener is null + * @throws SecurityException if no suitable permission is present + */ + public void requestSingleUpdate(Criteria criteria, LocationListener listener, Looper looper) { + } + + /** + * Register for a single location update using a named provider and pending intent. + *

+ *

See {@link #requestLocationUpdates(long, float, Criteria, PendingIntent)} + * for more detail on how to use this method. + * + * @param provider the name of the provider with which to register + * @param intent a {@link PendingIntent} to be sent for the location update + * @throws IllegalArgumentException if provider is null or doesn't exist + * @throws IllegalArgumentException if intent is null + * @throws SecurityException if no suitable permission is present + */ + public void requestSingleUpdate(String provider, PendingIntent intent) { + } + + /** + * Register for a single location update using a Criteria and pending intent. + *

+ *

See {@link #requestLocationUpdates(long, float, Criteria, PendingIntent)} + * for more detail on how to use this method. + * + * @param criteria contains parameters for the location manager to choose the + * appropriate provider and parameters to compute the location + * @param intent a {@link PendingIntent} to be sent for the location update + * @throws IllegalArgumentException if provider is null or doesn't exist + * @throws IllegalArgumentException if intent is null + * @throws SecurityException if no suitable permission is present + */ + public void requestSingleUpdate(Criteria criteria, PendingIntent intent) { + } + + /** + * Register for fused location updates using a LocationRequest and callback. + *

+ *

Upon a location update, the system delivers the new {@link Location} to the + * provided {@link LocationListener}, by calling its {@link + * LocationListener#onLocationChanged} method.

+ *

+ *

The system will automatically select and enable the best providers + * to compute a location for your application. It may use only passive + * locations, or just a single location source, or it may fuse together + * multiple location sources in order to produce the best possible + * result, depending on the quality of service requested in the + * {@link LocationRequest}. + *

+ *

LocationRequest can be null, in which case the system will choose + * default, low power parameters for location updates. You will occasionally + * receive location updates as available, without a major power impact on the + * system. If your application just needs an occasional location update + * without any strict demands, then pass a null LocationRequest. + *

+ *

Only one LocationRequest can be registered for each unique callback + * or pending intent. So a subsequent request with the same callback or + * pending intent will over-write the previous LocationRequest. + *

+ *

If a pending intent is supplied then location updates + * are sent with a key of {@link #KEY_LOCATION_CHANGED} and a + * {@link android.location.Location} value. If a callback is supplied + * then location updates are made using the + * {@link LocationListener#onLocationChanged} callback, on the specified + * Looper thread. If a {@link LocationListener} is used + * but with a null Looper then the calling thread must already + * be a {@link android.os.Looper} thread (such as the main thread) and + * callbacks will occur on this thread. + *

+ *

Provider status updates and availability updates are deprecated + * because the system is performing provider fusion on the applications + * behalf. So {@link LocationListener#onProviderDisabled}, + * {@link LocationListener#onProviderEnabled}, {@link LocationListener#onStatusChanged} + * will not be called, and intents with extra keys of + * {@link #KEY_PROVIDER_ENABLED} or {@link #KEY_STATUS_CHANGED} will not + * be received. + *

+ *

To unregister for Location updates, use: {@link #removeUpdates(LocationListener)}. + * + * @param request quality of service required, null for default low power + * @param listener a {@link LocationListener} whose + * {@link LocationListener#onLocationChanged} method will be called when + * the location update is available + * @param looper a Looper object whose message queue will be used to + * implement the callback mechanism, or null to make callbacks on the calling + * thread + * @throws IllegalArgumentException if listener is null + * @throws SecurityException if no suitable permission is present + * @hide + */ + public void requestLocationUpdates(LocationRequest request, LocationListener listener, + Looper looper) { + } + + /** + * Register for fused location updates using a LocationRequest and a pending intent. + *

+ *

Upon a location update, the system delivers the new {@link Location} with your provided + * {@link PendingIntent}, as the value for {@link LocationManager#KEY_LOCATION_CHANGED} + * in the intent's extras.

+ *

+ *

To unregister for Location updates, use: {@link #removeUpdates(PendingIntent)}. + *

+ *

See {@link #requestLocationUpdates(LocationRequest, LocationListener, Looper)} + * for more detail. + * + * @param request quality of service required, null for default low power + * @param intent a {@link PendingIntent} to be sent for the location update + * @throws IllegalArgumentException if intent is null + * @throws SecurityException if no suitable permission is present + * @hide + */ + public void requestLocationUpdates(LocationRequest request, PendingIntent intent) { + } + + /** + * Removes all location updates for the specified LocationListener. + *

+ *

Following this call, updates will no longer + * occur for this listener. + * + * @param listener listener object that no longer needs location updates + * @throws IllegalArgumentException if listener is null + */ + public void removeUpdates(LocationListener listener) { + } + + /** + * Removes all location updates for the specified pending intent. + *

+ *

Following this call, updates will no longer for this pending intent. + * + * @param intent pending intent object that no longer needs location updates + * @throws IllegalArgumentException if intent is null + */ + public void removeUpdates(PendingIntent intent) { + } + + /** + * Set a proximity alert for the location given by the position + * (latitude, longitude) and the given radius. + *

+ *

When the device + * detects that it has entered or exited the area surrounding the + * location, the given PendingIntent will be used to create an Intent + * to be fired. + *

+ *

The fired Intent will have a boolean extra added with key + * {@link #KEY_PROXIMITY_ENTERING}. If the value is true, the device is + * entering the proximity region; if false, it is exiting. + *

+ *

Due to the approximate nature of position estimation, if the + * device passes through the given area briefly, it is possible + * that no Intent will be fired. Similarly, an Intent could be + * fired if the device passes very close to the given area but + * does not actually enter it. + *

+ *

After the number of milliseconds given by the expiration + * parameter, the location manager will delete this proximity + * alert and no longer monitor it. A value of -1 indicates that + * there should be no expiration time. + *

+ *

Internally, this method uses both {@link #NETWORK_PROVIDER} + * and {@link #GPS_PROVIDER}. + *

+ *

Before API version 17, this method could be used with + * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or + * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. + * From API version 17 and onwards, this method requires + * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permission. + * + * @param latitude the latitude of the central point of the + * alert region + * @param longitude the longitude of the central point of the + * alert region + * @param radius the radius of the central point of the + * alert region, in meters + * @param expiration time for this proximity alert, in milliseconds, + * or -1 to indicate no expiration + * @param intent a PendingIntent that will be used to generate an Intent to + * fire when entry to or exit from the alert region is detected + * @throws SecurityException if {@link android.Manifest.permission#ACCESS_FINE_LOCATION} + * permission is not present + */ + public void addProximityAlert(double latitude, double longitude, float radius, long expiration, + PendingIntent intent) { + } + + /** + * Add a geofence with the specified LocationRequest quality of service. + *

+ *

When the device + * detects that it has entered or exited the area surrounding the + * location, the given PendingIntent will be used to create an Intent + * to be fired. + *

+ *

The fired Intent will have a boolean extra added with key + * {@link #KEY_PROXIMITY_ENTERING}. If the value is true, the device is + * entering the proximity region; if false, it is exiting. + *

+ *

The geofence engine fuses results from all location providers to + * provide the best balance between accuracy and power. Applications + * can choose the quality of service required using the + * {@link LocationRequest} object. If it is null then a default, + * low power geo-fencing implementation is used. It is possible to cross + * a geo-fence without notification, but the system will do its best + * to detect, using {@link LocationRequest} as a hint to trade-off + * accuracy and power. + *

+ *

The power required by the geofence engine can depend on many factors, + * such as quality and interval requested in {@link LocationRequest}, + * distance to nearest geofence and current device velocity. + * + * @param request quality of service required, null for default low power + * @param fence a geographical description of the geofence area + * @param intent pending intent to receive geofence updates + * @throws IllegalArgumentException if fence is null + * @throws IllegalArgumentException if intent is null + * @throws SecurityException if {@link android.Manifest.permission#ACCESS_FINE_LOCATION} + * permission is not present + * @hide + */ + public void addGeofence(LocationRequest request, Geofence fence, PendingIntent intent) { + } + + /** + * Removes the proximity alert with the given PendingIntent. + *

+ *

Before API version 17, this method could be used with + * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} or + * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. + * From API version 17 and onwards, this method requires + * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permission. + * + * @param intent the PendingIntent that no longer needs to be notified of + * proximity alerts + * @throws IllegalArgumentException if intent is null + * @throws SecurityException if {@link android.Manifest.permission#ACCESS_FINE_LOCATION} + * permission is not present + */ + public void removeProximityAlert(PendingIntent intent) { + } + + /** + * Remove a single geofence. + *

+ *

This removes only the specified geofence associated with the + * specified pending intent. All other geofences remain unchanged. + * + * @param fence a geofence previously passed to {@link #addGeofence} + * @param intent a pending intent previously passed to {@link #addGeofence} + * @throws IllegalArgumentException if fence is null + * @throws IllegalArgumentException if intent is null + * @throws SecurityException if {@link android.Manifest.permission#ACCESS_FINE_LOCATION} + * permission is not present + * @hide + */ + public void removeGeofence(Geofence fence, PendingIntent intent) { + } + + /** + * Remove all geofences registered to the specified pending intent. + * + * @param intent a pending intent previously passed to {@link #addGeofence} + * @throws IllegalArgumentException if intent is null + * @throws SecurityException if {@link android.Manifest.permission#ACCESS_FINE_LOCATION} + * permission is not present + * @hide + */ + public void removeAllGeofences(PendingIntent intent) { + } + + /** + * Returns the current enabled/disabled status of the given provider. + *

+ *

If the user has enabled this provider in the Settings menu, true + * is returned otherwise false is returned + *

+ *

Callers should instead use + * {@link android.provider.Settings.Secure#LOCATION_MODE} + * unless they depend on provider-specific APIs such as + * {@link #requestLocationUpdates(String, long, float, LocationListener)}. + *

+ *

+ * Before API version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this + * method would throw {@link SecurityException} if the location permissions + * were not sufficient to use the specified provider. + * + * @param provider the name of the provider + * @return true if the provider exists and is enabled + * @throws IllegalArgumentException if provider is null + */ + public boolean isProviderEnabled(String provider) { + return false; + } + + /** + * Get the last known location. + *

+ *

This location could be very old so use + * {@link Location#getElapsedRealtimeNanos} to calculate its age. It can + * also return null if no previous location is available. + *

+ *

Always returns immediately. + * + * @return The last known location, or null if not available + * @throws SecurityException if no suitable permission is present + * @hide + */ + public Location getLastLocation() { + return null; + } + + /** + * Returns a Location indicating the data from the last known + * location fix obtained from the given provider. + *

+ *

This can be done + * without starting the provider. Note that this location could + * be out-of-date, for example if the device was turned off and + * moved to another location. + *

+ *

If the provider is currently disabled, null is returned. + * + * @param provider the name of the provider + * @return the last known location for the provider, or null + * @throws SecurityException if no suitable permission is present + * @throws IllegalArgumentException if provider is null or doesn't exist + */ + public Location getLastKnownLocation(String provider) { + return null; + } + + // --- Mock provider support --- + // TODO: It would be fantastic to deprecate mock providers entirely, and replace + // with something closer to LocationProviderBase.java + + /** + * Creates a mock location provider and adds it to the set of active providers. + * + * @param name the provider name + * @throws SecurityException if the ACCESS_MOCK_LOCATION permission is not present + * or the {@link android.provider.Settings.Secure#ALLOW_MOCK_LOCATION + * Settings.Secure.ALLOW_MOCK_LOCATION} system setting is not enabled + * @throws IllegalArgumentException if a provider with the given name already exists + */ + public void addTestProvider(String name, boolean requiresNetwork, boolean requiresSatellite, + boolean requiresCell, boolean hasMonetaryCost, boolean supportsAltitude, + boolean supportsSpeed, boolean supportsBearing, int powerRequirement, int accuracy) { + } + + /** + * Removes the mock location provider with the given name. + * + * @param provider the provider name + * @throws SecurityException if the ACCESS_MOCK_LOCATION permission is not present + * or the {@link android.provider.Settings.Secure#ALLOW_MOCK_LOCATION + * Settings.Secure.ALLOW_MOCK_LOCATION}} system setting is not enabled + * @throws IllegalArgumentException if no provider with the given name exists + */ + public void removeTestProvider(String provider) { + } + + /** + * Sets a mock location for the given provider. + *

This location will be used in place of any actual location from the provider. + * The location object must have a minimum number of fields set to be + * considered a valid LocationProvider Location, as per documentation + * on {@link Location} class. + * + * @param provider the provider name + * @param loc the mock location + * @throws SecurityException if the ACCESS_MOCK_LOCATION permission is not present + * or the {@link android.provider.Settings.Secure#ALLOW_MOCK_LOCATION + * Settings.Secure.ALLOW_MOCK_LOCATION}} system setting is not enabled + * @throws IllegalArgumentException if no provider with the given name exists + * @throws IllegalArgumentException if the location is incomplete + */ + public void setTestProviderLocation(String provider, Location loc) { + } + + /** + * Removes any mock location associated with the given provider. + * + * @param provider the provider name + * @throws SecurityException if the ACCESS_MOCK_LOCATION permission is not present + * or the {@link android.provider.Settings.Secure#ALLOW_MOCK_LOCATION + * Settings.Secure.ALLOW_MOCK_LOCATION}} system setting is not enabled + * @throws IllegalArgumentException if no provider with the given name exists + */ + public void clearTestProviderLocation(String provider) { + } + + /** + * Sets a mock enabled value for the given provider. This value will be used in place + * of any actual value from the provider. + * + * @param provider the provider name + * @param enabled the mock enabled value + * @throws SecurityException if the ACCESS_MOCK_LOCATION permission is not present + * or the {@link android.provider.Settings.Secure#ALLOW_MOCK_LOCATION + * Settings.Secure.ALLOW_MOCK_LOCATION}} system setting is not enabled + * @throws IllegalArgumentException if no provider with the given name exists + */ + public void setTestProviderEnabled(String provider, boolean enabled) { + } + + /** + * Removes any mock enabled value associated with the given provider. + * + * @param provider the provider name + * @throws SecurityException if the ACCESS_MOCK_LOCATION permission is not present + * or the {@link android.provider.Settings.Secure#ALLOW_MOCK_LOCATION + * Settings.Secure.ALLOW_MOCK_LOCATION}} system setting is not enabled + * @throws IllegalArgumentException if no provider with the given name exists + */ + public void clearTestProviderEnabled(String provider) { + } + + /** + * Sets mock status values for the given provider. These values will be used in place + * of any actual values from the provider. + * + * @param provider the provider name + * @param status the mock status + * @param extras a Bundle containing mock extras + * @param updateTime the mock update time + * @throws SecurityException if the ACCESS_MOCK_LOCATION permission is not present + * or the {@link android.provider.Settings.Secure#ALLOW_MOCK_LOCATION + * Settings.Secure.ALLOW_MOCK_LOCATION}} system setting is not enabled + * @throws IllegalArgumentException if no provider with the given name exists + */ + public void setTestProviderStatus(String provider, int status, Bundle extras, long updateTime) { + } + + /** + * Removes any mock status values associated with the given provider. + * + * @param provider the provider name + * @throws SecurityException if the ACCESS_MOCK_LOCATION permission is not present + * or the {@link android.provider.Settings.Secure#ALLOW_MOCK_LOCATION + * Settings.Secure.ALLOW_MOCK_LOCATION}} system setting is not enabled + * @throws IllegalArgumentException if no provider with the given name exists + */ + public void clearTestProviderStatus(String provider) { + } + + // --- GPS-specific support --- + + /** + * Adds a GPS status listener. + * + * @param listener GPS status listener object to register + * @return true if the listener was successfully added + * @throws SecurityException if the ACCESS_FINE_LOCATION permission is not present + */ + public boolean addGpsStatusListener(GpsStatus.Listener listener) { + return false; + } + + /** + * Removes a GPS status listener. + * + * @param listener GPS status listener object to remove + */ + public void removeGpsStatusListener(GpsStatus.Listener listener) { + } + + /** + * Adds an NMEA listener. + * + * @param listener a {@link GpsStatus.NmeaListener} object to register + * @return true if the listener was successfully added + * @throws SecurityException if the ACCESS_FINE_LOCATION permission is not present + */ + public boolean addNmeaListener(GpsStatus.NmeaListener listener) { + return false; + } + + /** + * Removes an NMEA listener. + * + * @param listener a {@link GpsStatus.NmeaListener} object to remove + */ + public void removeNmeaListener(GpsStatus.NmeaListener listener) { + } + +// /** +// * Adds a GPS Measurement listener. +// * +// * @param listener a {@link GpsMeasurementsEvent.Listener} object to register. +// * @return {@code true} if the listener was successfully registered, {@code false} otherwise. +// * @hide +// */ +// public boolean addGpsMeasurementListener(GpsMeasurementsEvent.Listener listener) { +// return false; +// } +// +// /** +// * Removes a GPS Measurement listener. +// * +// * @param listener a {@link GpsMeasurementsEvent.Listener} object to remove. +// * @hide +// */ +// public void removeGpsMeasurementListener(GpsMeasurementsEvent.Listener listener) { +// } +// +// /** +// * Adds a GPS Navigation Message listener. +// * +// * @param listener a {@link GpsNavigationMessageEvent.Listener} object to register. +// * @return {@code true} if the listener was successfully registered, {@code false} otherwise. +// * @hide +// */ +// public boolean addGpsNavigationMessageListener(GpsNavigationMessageEvent.Listener listener) { +// return false; +// } +// +// /** +// * Removes a GPS Navigation Message listener. +// * +// * @param listener a {@link GpsNavigationMessageEvent.Listener} object to remove. +// * @hide +// */ +// public void removeGpsNavigationMessageListener( +// GpsNavigationMessageEvent.Listener listener) { +// } + + /** + * Retrieves information about the current status of the GPS engine. + * This should only be called from the {@link GpsStatus.Listener#onGpsStatusChanged} + * callback to ensure that the data is copied atomically. + *

+ * The caller may either pass in a {@link GpsStatus} object to set with the latest + * status information, or pass null to create a new {@link GpsStatus} object. + * + * @param status object containing GPS status details, or null. + * @return status object containing updated GPS status. + */ + public GpsStatus getGpsStatus(GpsStatus status) { + return null; + } + + /** + * Sends additional commands to a location provider. + * Can be used to support provider specific extensions to the Location Manager API + * + * @param provider name of the location provider. + * @param command name of the command to send to the provider. + * @param extras optional arguments for the command (or null). + * The provider may optionally fill the extras Bundle with results from the command. + * @return true if the command succeeds. + */ + public boolean sendExtraCommand(String provider, String command, Bundle extras) { + return false; + } + + /** + * Used by NetInitiatedActivity to report user response + * for network initiated GPS fix requests. + * + * @hide + */ + public boolean sendNiResponse(int notifId, int userResponse) { + return false; + } +} diff --git a/compat/current/src/android/location/LocationRequest.java b/compat/current/src/android/location/LocationRequest.java new file mode 100644 index 0000000..1085ad5 --- /dev/null +++ b/compat/current/src/android/location/LocationRequest.java @@ -0,0 +1,482 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.location; + +import android.os.Parcel; +import android.os.Parcelable; +import android.os.SystemClock; +import android.os.WorkSource; + +/** + * A data object that contains quality of service parameters for requests + * to the {@link LocationManager}. + *

+ *

LocationRequest objects are used to request a quality of service + * for location updates from the Location Manager. + *

+ *

For example, if your application wants high accuracy location + * it should create a location request with {@link #setQuality} set to + * {@link #ACCURACY_FINE} or {@link #POWER_HIGH}, and it should set + * {@link #setInterval} to less than one second. This would be + * appropriate for mapping applications that are showing your location + * in real-time. + *

+ *

At the other extreme, if you want negligible power + * impact, but to still receive location updates when available, then use + * {@link #setQuality} with {@link #POWER_NONE}. With this request your + * application will not trigger (and therefore will not receive any + * power blame) any location updates, but will receive locations + * triggered by other applications. This would be appropriate for + * applications that have no firm requirement for location, but can + * take advantage when available. + *

+ *

In between these two extremes is a very common use-case, where + * applications definitely want to receive + * updates at a specified interval, and can receive them faster when + * available, but still want a low power impact. These applications + * should consider {@link #POWER_LOW} combined with a faster + * {@link #setFastestInterval} (such as 1 minute) and a slower + * {@link #setInterval} (such as 60 minutes). They will only be assigned + * power blame for the interval set by {@link #setInterval}, but can + * still receive locations triggered by other applications at a rate up + * to {@link #setFastestInterval}. This style of request is appropriate for + * many location aware applications, including background usage. Do be + * careful to also throttle {@link #setFastestInterval} if you perform + * heavy-weight work after receiving an update - such as using the network. + *

+ *

Activities should strongly consider removing all location + * request when entering the background + * (for example at {@link android.app.Activity#onPause}), or + * at least swap the request to a larger interval and lower quality. + * Future version of the location manager may automatically perform background + * throttling on behalf of applications. + *

+ *

Applications cannot specify the exact location sources that are + * used by Android's Fusion Engine. In fact, the system + * may have multiple location sources (providers) running and may + * fuse the results from several sources into a single Location object. + *

+ *

Location requests from applications with + * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} and not + * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} will + * be automatically throttled to a slower interval, and the location + * object will be obfuscated to only show a coarse level of accuracy. + *

+ *

All location requests are considered hints, and you may receive + * locations that are more accurate, less accurate, and slower + * than requested. + * + * @hide + */ +public final class LocationRequest implements Parcelable { + /** + * Used with {@link #setQuality} to request the most accurate locations available. + *

+ *

This may be up to 1 meter accuracy, although this is implementation dependent. + */ + public static final int ACCURACY_FINE = 100; + + /** + * Used with {@link #setQuality} to request "block" level accuracy. + *

+ *

Block level accuracy is considered to be about 100 meter accuracy, + * although this is implementation dependent. Using a coarse accuracy + * such as this often consumes less power. + */ + public static final int ACCURACY_BLOCK = 102; + + /** + * Used with {@link #setQuality} to request "city" level accuracy. + *

+ *

City level accuracy is considered to be about 10km accuracy, + * although this is implementation dependent. Using a coarse accuracy + * such as this often consumes less power. + */ + public static final int ACCURACY_CITY = 104; + + /** + * Used with {@link #setQuality} to require no direct power impact (passive locations). + *

+ *

This location request will not trigger any active location requests, + * but will receive locations triggered by other applications. Your application + * will not receive any direct power blame for location work. + */ + public static final int POWER_NONE = 200; + + /** + * Used with {@link #setQuality} to request low power impact. + *

+ *

This location request will avoid high power location work where + * possible. + */ + public static final int POWER_LOW = 201; + + /** + * Used with {@link #setQuality} to allow high power consumption for location. + *

+ *

This location request will allow high power location work. + */ + public static final int POWER_HIGH = 203; + + /** + * Create a location request with default parameters. + *

+ *

Default parameters are for a low power, slowly updated location. + * It can then be adjusted as required by the applications before passing + * to the {@link LocationManager} + * + * @return a new location request + */ + public static LocationRequest create() { + return null; + } + + /** + * @hide + */ + public static LocationRequest createFromDeprecatedProvider(String provider, long minTime, + float minDistance, boolean singleShot) { + return null; + } + + /** + * @hide + */ + public static LocationRequest createFromDeprecatedCriteria(Criteria criteria, long minTime, + float minDistance, boolean singleShot) { + return null; + } + + /** + * @hide + */ + public LocationRequest() { + } + + /** + * @hide + */ + public LocationRequest(LocationRequest src) { + } + + /** + * Set the quality of the request. + *

+ *

Use with a accuracy constant such as {@link #ACCURACY_FINE}, or a power + * constant such as {@link #POWER_LOW}. You cannot request both and accuracy and + * power, only one or the other can be specified. The system will then + * maximize accuracy or minimize power as appropriate. + *

+ *

The quality of the request is a strong hint to the system for which + * location sources to use. For example, {@link #ACCURACY_FINE} is more likely + * to use GPS, and {@link #POWER_LOW} is more likely to use WIFI & Cell tower + * positioning, but it also depends on many other factors (such as which sources + * are available) and is implementation dependent. + *

+ *

{@link #setQuality} and {@link #setInterval} are the most important parameters + * on a location request. + * + * @param quality an accuracy or power constant + * @return the same object, so that setters can be chained + * @throws InvalidArgumentException if the quality constant is not valid + */ + public LocationRequest setQuality(int quality) { + return null; + } + + /** + * Get the quality of the request. + * + * @return an accuracy or power constant + */ + public int getQuality() { + return 0; + } + + /** + * Set the desired interval for active location updates, in milliseconds. + *

+ *

The location manager will actively try to obtain location updates + * for your application at this interval, so it has a + * direct influence on the amount of power used by your application. + * Choose your interval wisely. + *

+ *

This interval is inexact. You may not receive updates at all (if + * no location sources are available), or you may receive them + * slower than requested. You may also receive them faster than + * requested (if other applications are requesting location at a + * faster interval). The fastest rate that that you will receive + * updates can be controlled with {@link #setFastestInterval}. + *

+ *

Applications with only the coarse location permission may have their + * interval silently throttled. + *

+ *

An interval of 0 is allowed, but not recommended, since + * location updates may be extremely fast on future implementations. + *

+ *

{@link #setQuality} and {@link #setInterval} are the most important parameters + * on a location request. + * + * @param millis desired interval in millisecond, inexact + * @return the same object, so that setters can be chained + * @throws InvalidArgumentException if the interval is less than zero + */ + public LocationRequest setInterval(long millis) { + return null; + } + + /** + * Get the desired interval of this request, in milliseconds. + * + * @return desired interval in milliseconds, inexact + */ + public long getInterval() { + return 0; + } + + /** + * Explicitly set the fastest interval for location updates, in + * milliseconds. + *

+ *

This controls the fastest rate at which your application will + * receive location updates, which might be faster than + * {@link #setInterval} in some situations (for example, if other + * applications are triggering location updates). + *

+ *

This allows your application to passively acquire locations + * at a rate faster than it actively acquires locations, saving power. + *

+ *

Unlike {@link #setInterval}, this parameter is exact. Your + * application will never receive updates faster than this value. + *

+ *

If you don't call this method, a fastest interval + * will be selected for you. It will be a value faster than your + * active interval ({@link #setInterval}). + *

+ *

An interval of 0 is allowed, but not recommended, since + * location updates may be extremely fast on future implementations. + *

+ *

If {@link #setFastestInterval} is set slower than {@link #setInterval}, + * then your effective fastest interval is {@link #setInterval}. + * + * @param millis fastest interval for updates in milliseconds, exact + * @return the same object, so that setters can be chained + * @throws InvalidArgumentException if the interval is less than zero + */ + public LocationRequest setFastestInterval(long millis) { + return null; + } + + /** + * Get the fastest interval of this request, in milliseconds. + *

+ *

The system will never provide location updates faster + * than the minimum of {@link #getFastestInterval} and + * {@link #getInterval}. + * + * @return fastest interval in milliseconds, exact + */ + public long getFastestInterval() { + return 0; + } + + /** + * Set the duration of this request, in milliseconds. + *

+ *

The duration begins immediately (and not when the request + * is passed to the location manager), so call this method again + * if the request is re-used at a later time. + *

+ *

The location manager will automatically stop updates after + * the request expires. + *

+ *

The duration includes suspend time. Values less than 0 + * are allowed, but indicate that the request has already expired. + * + * @param millis duration of request in milliseconds + * @return the same object, so that setters can be chained + */ + public LocationRequest setExpireIn(long millis) { + return null; + } + + /** + * Set the request expiration time, in millisecond since boot. + *

+ *

This expiration time uses the same time base as {@link SystemClock#elapsedRealtime}. + *

+ *

The location manager will automatically stop updates after + * the request expires. + *

+ *

The duration includes suspend time. Values before {@link SystemClock#elapsedRealtime} + * are allowed, but indicate that the request has already expired. + * + * @param millis expiration time of request, in milliseconds since boot including suspend + * @return the same object, so that setters can be chained + */ + public LocationRequest setExpireAt(long millis) { + return null; + } + + /** + * Get the request expiration time, in milliseconds since boot. + *

+ *

This value can be compared to {@link SystemClock#elapsedRealtime} to determine + * the time until expiration. + * + * @return expiration time of request, in milliseconds since boot including suspend + */ + public long getExpireAt() { + return 0; + } + + /** + * Set the number of location updates. + *

+ *

By default locations are continuously updated until the request is explicitly + * removed, however you can optionally request a set number of updates. + * For example, if your application only needs a single fresh location, + * then call this method with a value of 1 before passing the request + * to the location manager. + * + * @param numUpdates the number of location updates requested + * @return the same object, so that setters can be chained + * @throws InvalidArgumentException if numUpdates is 0 or less + */ + public LocationRequest setNumUpdates(int numUpdates) { + return null; + } + + /** + * Get the number of updates requested. + *

+ *

By default this is {@link Integer#MAX_VALUE}, which indicates that + * locations are updated until the request is explicitly removed. + * + * @return number of updates + */ + public int getNumUpdates() { + return 0; + } + + /** + * @hide + */ + public void decrementNumUpdates() { + } + + /** + * @hide + */ + public LocationRequest setProvider(String provider) { + return null; + } + + /** + * @hide + */ + public String getProvider() { + return null; + } + + /** + * @hide + */ + public LocationRequest setSmallestDisplacement(float meters) { + return null; + } + + /** + * @hide + */ + public float getSmallestDisplacement() { + return 0; + } + + /** + * Sets the WorkSource to use for power blaming of this location request. + *

+ *

No permissions are required to make this call, however the LocationManager + * will throw a SecurityException when requesting location updates if the caller + * doesn't have the {@link android.Manifest.permission#UPDATE_DEVICE_STATS} permission. + * + * @param workSource WorkSource defining power blame for this location request. + * @hide + */ + public void setWorkSource(WorkSource workSource) { + } + + /** + * @hide + */ + public WorkSource getWorkSource() { + return null; + } + + /** + * Sets whether or not this location request should be hidden from AppOps. + *

+ *

Hiding a location request from AppOps will remove user visibility in the UI as to this + * request's existence. It does not affect power blaming in the Battery page. + *

+ *

No permissions are required to make this call, however the LocationManager + * will throw a SecurityException when requesting location updates if the caller + * doesn't have the {@link android.Manifest.permission#UPDATE_APP_OPS_STATS} permission. + * + * @param hideFromAppOps If true AppOps won't keep track of this location request. + * @hide + * @see android.app.AppOpsManager + */ + public void setHideFromAppOps(boolean hideFromAppOps) { + } + + /** + * @hide + */ + public boolean getHideFromAppOps() { + return false; + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public LocationRequest createFromParcel(Parcel in) { + return null; + } + + @Override + public LocationRequest[] newArray(int size) { + return null; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int flags) { + } + + /** + * @hide + */ + public static String qualityToString(int quality) { + return null; + } +} diff --git a/compat/current/src/com/android/internal/location/ProviderProperties.java b/compat/current/src/com/android/internal/location/ProviderProperties.java new file mode 100644 index 0000000..d66a219 --- /dev/null +++ b/compat/current/src/com/android/internal/location/ProviderProperties.java @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.location; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * A Parcelable containing (legacy) location provider properties. + * This object is just used inside the framework and system services. + * + * @hide + */ +public final class ProviderProperties implements Parcelable { + /** + * True if provider requires access to a + * data network (e.g., the Internet), false otherwise. + */ + public final boolean mRequiresNetwork; + + /** + * True if the provider requires access to a + * satellite-based positioning system (e.g., GPS), false + * otherwise. + */ + public final boolean mRequiresSatellite; + + /** + * True if the provider requires access to an appropriate + * cellular network (e.g., to make use of cell tower IDs), false + * otherwise. + */ + public final boolean mRequiresCell; + + /** + * True if the use of this provider may result in a + * monetary charge to the user, false if use is free. It is up to + * each provider to give accurate information. Cell (network) usage + * is not considered monetary cost. + */ + public final boolean mHasMonetaryCost; + + /** + * True if the provider is able to provide altitude + * information, false otherwise. A provider that reports altitude + * under most circumstances but may occasionally not report it + * should return true. + */ + public final boolean mSupportsAltitude; + + /** + * True if the provider is able to provide speed + * information, false otherwise. A provider that reports speed + * under most circumstances but may occasionally not report it + * should return true. + */ + public final boolean mSupportsSpeed; + + /** + * True if the provider is able to provide bearing + * information, false otherwise. A provider that reports bearing + * under most circumstances but may occasionally not report it + * should return true. + */ + public final boolean mSupportsBearing; + + /** + * Power requirement for this provider. + * + * @return the power requirement for this provider, as one of the + * constants Criteria.POWER_*. + */ + public final int mPowerRequirement; + + /** + * Constant describing the horizontal accuracy returned + * by this provider. + * + * @return the horizontal accuracy for this provider, as one of the + * constants Criteria.ACCURACY_COARSE or Criteria.ACCURACY_FINE + */ + public final int mAccuracy; + + public ProviderProperties(boolean mRequiresNetwork, + boolean mRequiresSatellite, boolean mRequiresCell, boolean mHasMonetaryCost, + boolean mSupportsAltitude, boolean mSupportsSpeed, boolean mSupportsBearing, + int mPowerRequirement, int mAccuracy) { + this.mRequiresNetwork = mRequiresNetwork; + this.mRequiresSatellite = mRequiresSatellite; + this.mRequiresCell = mRequiresCell; + this.mHasMonetaryCost = mHasMonetaryCost; + this.mSupportsAltitude = mSupportsAltitude; + this.mSupportsSpeed = mSupportsSpeed; + this.mSupportsBearing = mSupportsBearing; + this.mPowerRequirement = mPowerRequirement; + this.mAccuracy = mAccuracy; + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public ProviderProperties createFromParcel(Parcel in) { + return null; + } + + @Override + public ProviderProperties[] newArray(int size) { + return null; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int flags) { + } +} diff --git a/compat/current/src/com/android/internal/location/ProviderRequest.java b/compat/current/src/com/android/internal/location/ProviderRequest.java new file mode 100644 index 0000000..bd4d515 --- /dev/null +++ b/compat/current/src/com/android/internal/location/ProviderRequest.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.location; + +import android.location.LocationRequest; +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.List; + +/** + * @hide + */ +public final class ProviderRequest implements Parcelable { + /** + * Location reporting is requested (true) + */ + public boolean reportLocation = false; + + /** + * The smallest requested interval + */ + public long interval = Long.MAX_VALUE; + + /** + * A more detailed set of requests. + *

Location Providers can optionally use this to + * fine tune location updates, for example when there + * is a high power slow interval request and a + * low power fast interval request. + */ + public List locationRequests = null; + + public ProviderRequest() { + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public ProviderRequest createFromParcel(Parcel in) { + return null; + } + + @Override + public ProviderRequest[] newArray(int size) { + return null; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int flags) { + } +} diff --git a/compat/current/src/com/android/location/provider/GeocodeProvider.java b/compat/current/src/com/android/location/provider/GeocodeProvider.java new file mode 100644 index 0000000..c35d7e9 --- /dev/null +++ b/compat/current/src/com/android/location/provider/GeocodeProvider.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.location.provider; + +import android.location.Address; +import android.location.GeocoderParams; +import android.os.IBinder; + +import java.util.List; + +/** + * Base class for geocode providers implemented as unbundled services. + *

+ *

Geocode providers can be implemented as services and return the result of + * {@link GeocodeProvider#getBinder()} in its getBinder() method. + *

+ *

IMPORTANT: This class is effectively a public API for unbundled + * applications, and must remain API stable. See README.txt in the root + * of this package for more information. + */ +public abstract class GeocodeProvider { + /** + * This method is overridden to implement the + * {@link android.location.Geocoder#getFromLocation(double, double, int)} method. + * Classes implementing this method should not hold a reference to the params parameter. + */ + public abstract String onGetFromLocation(double latitude, double longitude, int maxResults, + GeocoderParams params, List

addrs); + + /** + * This method is overridden to implement the + * {@link android.location.Geocoder#getFromLocationName(String, int, double, double, double, double)} method. + * Classes implementing this method should not hold a reference to the params parameter. + */ + public abstract String onGetFromLocationName(String locationName, + double lowerLeftLatitude, double lowerLeftLongitude, + double upperRightLatitude, double upperRightLongitude, int maxResults, + GeocoderParams params, List
addrs); + + /** + * Returns the Binder interface for the geocode provider. + * This is intended to be used for the onBind() method of + * a service that implements a geocoder service. + * + * @return the IBinder instance for the provider + */ + public IBinder getBinder() { + return null; + } +} diff --git a/compat/current/src/com/android/location/provider/LocationProviderBase.java b/compat/current/src/com/android/location/provider/LocationProviderBase.java new file mode 100644 index 0000000..30d5170 --- /dev/null +++ b/compat/current/src/com/android/location/provider/LocationProviderBase.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.location.provider; + +import android.location.Location; +import android.location.LocationManager; +import android.os.Bundle; +import android.os.IBinder; +import android.os.WorkSource; + +import java.io.FileDescriptor; +import java.io.PrintWriter; + +/** + * Base class for location providers implemented as unbundled services. + *

+ *

The network location provider must export a service with action + * "com.android.location.service.v2.NetworkLocationProvider" + * and a valid minor version in a meta-data field on the service, and + * then return the result of {@link #getBinder()} on service binding. + *

+ *

The fused location provider must export a service with action + * "com.android.location.service.FusedLocationProvider" + * and a valid minor version in a meta-data field on the service, and + * then return the result of {@link #getBinder()} on service binding. + *

+ *

IMPORTANT: This class is effectively a public API for unbundled + * applications, and must remain API stable. See README.txt in the root + * of this package for more information. + */ +public abstract class LocationProviderBase { + + /** + * Bundle key for a version of the location containing no GPS data. + * Allows location providers to flag locations as being safe to + * feed to LocationFudger. + */ + public static final String EXTRA_NO_GPS_LOCATION = Location.EXTRA_NO_GPS_LOCATION; + + /** + * Name of the Fused location provider. + *

+ *

This provider combines inputs for all possible location sources + * to provide the best possible Location fix. + */ + public static final String FUSED_PROVIDER = LocationManager.FUSED_PROVIDER; + + public LocationProviderBase(String tag, ProviderPropertiesUnbundled properties) { + } + + public IBinder getBinder() { + return null; + } + + /** + * Used by the location provider to report new locations. + * + * @param location new Location to report + *

+ * Requires the android.permission.INSTALL_LOCATION_PROVIDER permission. + */ + public final void reportLocation(Location location) { + } + + /** + * Enable the location provider. + *

The provider may initialize resources, but does + * not yet need to report locations. + */ + public abstract void onEnable(); + + /** + * Disable the location provider. + *

The provider must release resources, and stop + * performing work. It may no longer report locations. + */ + public abstract void onDisable(); + + /** + * Set the {@link ProviderRequest} requirements for this provider. + *

Each call to this method overrides all previous requests. + *

This method might trigger the provider to start returning + * locations, or to stop returning locations, depending on the + * parameters in the request. + */ + public abstract void onSetRequest(ProviderRequestUnbundled request, WorkSource source); + + /** + * Dump debug information. + */ + public void onDump(FileDescriptor fd, PrintWriter pw, String[] args) { + } + + /** + * Returns a information on the status of this provider. + *

{@link android.location.LocationProvider#OUT_OF_SERVICE} is returned if the provider is + * out of service, and this is not expected to change in the near + * future; {@link android.location.LocationProvider#TEMPORARILY_UNAVAILABLE} is returned if + * the provider is temporarily unavailable but is expected to be + * available shortly; and {@link android.location.LocationProvider#AVAILABLE} is returned + * if the provider is currently available. + *

+ *

If extras is non-null, additional status information may be + * added to it in the form of provider-specific key/value pairs. + */ + public abstract int onGetStatus(Bundle extras); + + /** + * Returns the time at which the status was last updated. It is the + * responsibility of the provider to appropriately set this value using + * {@link android.os.SystemClock#elapsedRealtime SystemClock.elapsedRealtime()}. + * there is a status update that it wishes to broadcast to all its + * listeners. The provider should be careful not to broadcast + * the same status again. + * + * @return time of last status update in millis since last reboot + */ + public abstract long onGetStatusUpdateTime(); + + /** + * Implements addditional location provider specific additional commands. + * + * @param command name of the command to send to the provider. + * @param extras optional arguments for the command (or null). + * The provider may optionally fill the extras Bundle with results from the command. + * @return true if the command succeeds. + */ + public boolean onSendExtraCommand(String command, Bundle extras) { + return false; + } +} diff --git a/compat/current/src/com/android/location/provider/LocationRequestUnbundled.java b/compat/current/src/com/android/location/provider/LocationRequestUnbundled.java new file mode 100644 index 0000000..71b5ca4 --- /dev/null +++ b/compat/current/src/com/android/location/provider/LocationRequestUnbundled.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.location.provider; + +import android.location.LocationRequest; + +/** + * This class is an interface to LocationRequests for unbundled applications. + *

+ *

IMPORTANT: This class is effectively a public API for unbundled + * applications, and must remain API stable. See README.txt in the root + * of this package for more information. + */ +public final class LocationRequestUnbundled { + /** + * Returned by {@link #getQuality} when requesting the most accurate locations available. + *

+ *

This may be up to 1 meter accuracy, although this is implementation dependent. + */ + public static final int ACCURACY_FINE = LocationRequest.ACCURACY_FINE; + + /** + * Returned by {@link #getQuality} when requesting "block" level accuracy. + *

+ *

Block level accuracy is considered to be about 100 meter accuracy, + * although this is implementation dependent. Using a coarse accuracy + * such as this often consumes less power. + */ + public static final int ACCURACY_BLOCK = LocationRequest.ACCURACY_BLOCK; + + /** + * Returned by {@link #getQuality} when requesting "city" level accuracy. + *

+ *

City level accuracy is considered to be about 10km accuracy, + * although this is implementation dependent. Using a coarse accuracy + * such as this often consumes less power. + */ + public static final int ACCURACY_CITY = LocationRequest.ACCURACY_CITY; + + /** + * Returned by {@link #getQuality} when requiring no direct power impact (passive locations). + *

+ *

This location request will not trigger any active location requests, + * but will receive locations triggered by other applications. Your application + * will not receive any direct power blame for location work. + */ + public static final int POWER_NONE = LocationRequest.POWER_NONE; + + /** + * Returned by {@link #getQuality} when requesting low power impact. + *

+ *

This location request will avoid high power location work where + * possible. + */ + public static final int POWER_LOW = LocationRequest.POWER_LOW; + + /** + * Returned by {@link #getQuality} when allowing high power consumption for location. + *

+ *

This location request will allow high power location work. + */ + public static final int POWER_HIGH = LocationRequest.POWER_HIGH; + + /** + * Get the desired interval of this request, in milliseconds. + * + * @return desired interval in milliseconds, inexact + */ + public long getInterval() { + return 0; + } + + /** + * Get the fastest interval of this request, in milliseconds. + *

+ *

The system will never provide location updates faster + * than the minimum of {@link #getFastestInterval} and + * {@link #getInterval}. + * + * @return fastest interval in milliseconds, exact + */ + public long getFastestInterval() { + return 0; + } + + /** + * Get the quality of the request. + * + * @return an accuracy or power constant + */ + public int getQuality() { + return 0; + } + + /** + * Get the minimum distance between location updates, in meters. + * + * @return minimum distance between location updates in meters + */ + public float getSmallestDisplacement() { + return 0; + } +} diff --git a/compat/current/src/com/android/location/provider/ProviderPropertiesUnbundled.java b/compat/current/src/com/android/location/provider/ProviderPropertiesUnbundled.java new file mode 100644 index 0000000..0c3893d --- /dev/null +++ b/compat/current/src/com/android/location/provider/ProviderPropertiesUnbundled.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.location.provider; + +import com.android.internal.location.ProviderProperties; + +/** + * This class is an interface to Provider Properties for unbundled applications. + *

+ *

IMPORTANT: This class is effectively a public API for unbundled + * applications, and must remain API stable. See README.txt in the root + * of this package for more information. + */ +public final class ProviderPropertiesUnbundled { + public static ProviderPropertiesUnbundled create(boolean requiresNetwork, + boolean requiresSatellite, boolean requiresCell, boolean hasMonetaryCost, + boolean supportsAltitude, boolean supportsSpeed, boolean supportsBearing, + int powerRequirement, int accuracy) { + return null; + } + + public ProviderProperties getProviderProperties() { + return null; + } +} diff --git a/compat/current/src/com/android/location/provider/ProviderRequestUnbundled.java b/compat/current/src/com/android/location/provider/ProviderRequestUnbundled.java new file mode 100644 index 0000000..fca34db --- /dev/null +++ b/compat/current/src/com/android/location/provider/ProviderRequestUnbundled.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.location.provider; + +import com.android.internal.location.ProviderRequest; + +import java.util.List; + +/** + * This class is an interface to Provider Requests for unbundled applications. + *

+ *

IMPORTANT: This class is effectively a public API for unbundled + * applications, and must remain API stable. See README.txt in the root + * of this package for more information. + */ +public final class ProviderRequestUnbundled { + public ProviderRequestUnbundled(ProviderRequest request) { + } + + public boolean getReportLocation() { + return false; + } + + public long getInterval() { + return 0; + } + + /** + * Never null. + */ + public List getLocationRequests() { + return null; + } +} diff --git a/compat/v9/src/android/location/ILocationProvider.aidl b/compat/v9/src/android/location/ILocationProvider.aidl deleted file mode 100644 index ecf6789..0000000 --- a/compat/v9/src/android/location/ILocationProvider.aidl +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.location; - -import android.location.Criteria; -import android.location.Location; -import android.net.NetworkInfo; -import android.os.Bundle; -import android.os.WorkSource; - -/** - * Binder interface for services that implement location providers. - * - * {@hide} - */ -interface ILocationProvider { - boolean requiresNetwork(); - boolean requiresSatellite(); - boolean requiresCell(); - boolean hasMonetaryCost(); - boolean supportsAltitude(); - boolean supportsSpeed(); - boolean supportsBearing(); - int getPowerRequirement(); - boolean meetsCriteria(in Criteria criteria); - int getAccuracy(); - void enable(); - void disable(); - int getStatus(out Bundle extras); - long getStatusUpdateTime(); - String getInternalState(); - void enableLocationTracking(boolean enable); - void setMinTime(long minTime, in WorkSource ws); - void updateNetworkState(int state, in NetworkInfo info); - void updateLocation(in Location location); - boolean sendExtraCommand(String command, inout Bundle extras); - void addListener(int uid); - void removeListener(int uid); -} diff --git a/compat/v9/src/com/android/location/provider/LocationProvider.java b/compat/v9/src/com/android/location/provider/LocationProvider.java index 3714f40..0e71404 100644 --- a/compat/v9/src/com/android/location/provider/LocationProvider.java +++ b/compat/v9/src/com/android/location/provider/LocationProvider.java @@ -16,18 +16,12 @@ package com.android.location.provider; -import android.content.Context; -import android.net.NetworkInfo; import android.location.Criteria; -import android.location.ILocationManager; -import android.location.ILocationProvider; import android.location.Location; +import android.net.NetworkInfo; import android.os.Bundle; import android.os.IBinder; -import android.os.RemoteException; -import android.os.ServiceManager; import android.os.WorkSource; -import android.util.Log; /** * An abstract superclass for location providers that are implemented @@ -39,111 +33,7 @@ import android.util.Log; */ public abstract class LocationProvider { - private static final String TAG = "LocationProvider"; - - private ILocationManager mLocationManager; - - private ILocationProvider.Stub mProvider = new ILocationProvider.Stub() { - - public boolean requiresNetwork() { - return LocationProvider.this.onRequiresNetwork(); - } - - public boolean requiresSatellite() { - return LocationProvider.this.onRequiresSatellite(); - } - - public boolean requiresCell() { - return LocationProvider.this.onRequiresCell(); - } - - public boolean hasMonetaryCost() { - return LocationProvider.this.onHasMonetaryCost(); - } - - public boolean supportsAltitude() { - return LocationProvider.this.onSupportsAltitude(); - } - - public boolean supportsSpeed() { - return LocationProvider.this.onSupportsSpeed(); - } - - public boolean supportsBearing() { - return LocationProvider.this.onSupportsBearing(); - } - - public int getPowerRequirement() { - return LocationProvider.this.onGetPowerRequirement(); - } - - public boolean meetsCriteria(Criteria criteria) { - return LocationProvider.this.onMeetsCriteria(criteria); - } - - public int getAccuracy() { - return LocationProvider.this.onGetAccuracy(); - } - - public void enable() { - LocationProvider.this.onEnable(); - } - - public void disable() { - LocationProvider.this.onDisable(); - } - - public int getStatus(Bundle extras) { - return LocationProvider.this.onGetStatus(extras); - } - - public long getStatusUpdateTime() { - return LocationProvider.this.onGetStatusUpdateTime(); - } - - public String getInternalState() { - return LocationProvider.this.onGetInternalState(); - } - - public void enableLocationTracking(boolean enable) { - LocationProvider.this.onEnableLocationTracking(enable); - } - - public void setMinTime(long minTime, WorkSource ws) { - LocationProvider.this.onSetMinTime(minTime, ws); - } - - public void updateNetworkState(int state, NetworkInfo info) { - LocationProvider.this.onUpdateNetworkState(state, info); - } - - public void updateLocation(Location location) { - LocationProvider.this.onUpdateLocation(location); - } - - public boolean sendExtraCommand(String command, Bundle extras) { - return LocationProvider.this.onSendExtraCommand(command, extras); - } - - public void addListener(int uid) { - LocationProvider.this.onAddListener(uid, new WorkSource(uid)); - } - - public void removeListener(int uid) { - LocationProvider.this.onRemoveListener(uid, new WorkSource(uid)); - } - }; - public LocationProvider() { - IBinder b = ServiceManager.getService(Context.LOCATION_SERVICE); - mLocationManager = ILocationManager.Stub.asInterface(b); - } - - /** - * {@hide} - */ - /* package */ ILocationProvider getInterface() { - return mProvider; } /** @@ -154,22 +44,17 @@ public abstract class LocationProvider { * @return the IBinder instance for the provider */ public IBinder getBinder() { - return mProvider; + return null; } /** * Used by the location provider to report new locations. * * @param location new Location to report - * - * Requires the android.permission.INSTALL_LOCATION_PROVIDER permission. + *

+ * Requires the android.permission.INSTALL_LOCATION_PROVIDER permission. */ public void reportLocation(Location location) { - try { - mLocationManager.reportLocation(location, false); - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in reportLocation: ", e); - } } /** @@ -264,7 +149,7 @@ public abstract class LocationProvider { * the provider is temporarily unavailable but is expected to be * available shortly; and {@link android.location.LocationProvider#AVAILABLE} is returned * if the provider is currently available. - * + *

*

If extras is non-null, additional status information may be * added to it in the form of provider-specific key/value pairs. */ @@ -306,7 +191,7 @@ public abstract class LocationProvider { * the frequency of updates to match the requested frequency. * * @param minTime the smallest minTime value over all listeners for this provider. - * @param ws the source this work is coming from. + * @param ws the source this work is coming from. */ public abstract void onSetMinTime(long minTime, WorkSource ws); @@ -333,9 +218,8 @@ public abstract class LocationProvider { * Implements addditional location provider specific additional commands. * * @param command name of the command to send to the provider. - * @param extras optional arguments for the command (or null). - * The provider may optionally fill the extras Bundle with results from the command. - * + * @param extras optional arguments for the command (or null). + * The provider may optionally fill the extras Bundle with results from the command. * @return true if the command succeeds. */ public abstract boolean onSendExtraCommand(String command, Bundle extras); @@ -344,7 +228,7 @@ public abstract class LocationProvider { * Notifies the location provider when a new client is listening for locations. * * @param uid user ID of the new client. - * @param ws a WorkSource representation of the client. + * @param ws a WorkSource representation of the client. */ public abstract void onAddListener(int uid, WorkSource ws); @@ -352,7 +236,7 @@ public abstract class LocationProvider { * Notifies the location provider when a client is no longer listening for locations. * * @param uid user ID of the client no longer listening. - * @param ws a WorkSource representation of the client. + * @param ws a WorkSource representation of the client. */ public abstract void onRemoveListener(int uid, WorkSource ws); } diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..503a85a --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':compat' diff --git a/src/org/microg/nlp/location/BackendHelper.java b/src/org/microg/nlp/location/BackendHelper.java index ca534a3..287129b 100644 --- a/src/org/microg/nlp/location/BackendHelper.java +++ b/src/org/microg/nlp/location/BackendHelper.java @@ -1,5 +1,7 @@ package org.microg.nlp.location; +import android.annotation.SuppressLint; +import android.annotation.TargetApi; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -68,15 +70,20 @@ class BackendHelper extends AbstractBackendHelper { location.setTime(System.currentTimeMillis()); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - if (location.getElapsedRealtimeNanos() <= 0) { - location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); - } + updateElapsedRealtimeNanos(location); } location.getExtras() .putParcelable(LocationProviderBase.EXTRA_NO_GPS_LOCATION, new Location(location)); lastLocation = location; return lastLocation; } + + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) + private void updateElapsedRealtimeNanos(Location location) { + if (location.getElapsedRealtimeNanos() <= 0) { + location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos()); + } + } @Override public void close() throws RemoteException { diff --git a/src/org/microg/nlp/ui/AbstractBackendPreference.java b/src/org/microg/nlp/ui/AbstractBackendPreference.java index 337bf77..7d44b36 100644 --- a/src/org/microg/nlp/ui/AbstractBackendPreference.java +++ b/src/org/microg/nlp/ui/AbstractBackendPreference.java @@ -7,11 +7,13 @@ import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.preference.DialogPreference; import android.util.AttributeSet; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.*; +import android.widget.ArrayAdapter; +import android.widget.CheckBox; +import android.widget.ListView; +import android.widget.TextView; import org.microg.nlp.Preferences; import org.microg.nlp.R; @@ -55,7 +57,9 @@ public abstract class AbstractBackendPreference extends DialogPreference { private void resetAdapter() { adapter.clear(); - adapter.addAll(knownBackends); + for (BackendInfo backend : knownBackends) { + adapter.add(backend); + } listView.setAdapter(adapter); } @@ -67,7 +71,8 @@ public abstract class AbstractBackendPreference extends DialogPreference { if (sb.length() != 0) { sb.append("|"); } - sb.append(backend.serviceInfo.packageName).append("/").append(backend.serviceInfo.name); + sb.append(backend.serviceInfo.packageName).append("/") + .append(backend.serviceInfo.name); } } return sb.toString(); @@ -116,9 +121,14 @@ public abstract class AbstractBackendPreference extends DialogPreference { @Override public View getView(int position, View convertView, ViewGroup parent) { - View v = ((LayoutInflater) getContext() - .getSystemService(Context.LAYOUT_INFLATER_SERVICE)) - .inflate(R.layout.backend_list_entry, null); + View v; + if (convertView != null) { + v = convertView; + } else { + v = ((LayoutInflater) getContext().getSystemService( + Context.LAYOUT_INFLATER_SERVICE)).inflate( + R.layout.backend_list_entry, parent, false); + } final BackendInfo backend = getItem(position); TextView title = (TextView) v.findViewById(android.R.id.text1); title.setText(backend.simpleName); @@ -161,7 +171,6 @@ public abstract class AbstractBackendPreference extends DialogPreference { } } } - @Override protected void onDialogClosed(boolean positiveResult) { @@ -170,9 +179,11 @@ public abstract class AbstractBackendPreference extends DialogPreference { onValueChanged(); } } - + protected abstract void onValueChanged(); + protected abstract Intent buildBackendIntent(); + protected abstract String defaultValue(); private class BackendInfo {