Fixing lint's and add gradle support

This commit is contained in:
mar-v-in 2015-01-02 19:59:03 +01:00
parent b9967ca999
commit 342a828cf8
21 changed files with 3123 additions and 194 deletions

View File

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.microg.nlp"
android:versionName="1.1.2"
android:versionCode="1102">
android:versionName="1.1.3"
android:versionCode="1103">
<uses-sdk
android:minSdkVersion="9" />
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<permission
android:name="org.microg.permission.FORCE_COARSE_LOCATION"
@ -21,12 +22,14 @@
<application
android:icon="@drawable/nlp_app_icon"
android:theme="@style/AppTheme"
android:allowBackup="true"
android:label="@string/nlp_app_name">
<uses-library android:name="com.android.location.provider" />
<!-- Gingerbread / Ice Cream Sandwich -->
<service
android:name="org.microg.nlp.location.LocationServiceV1"
android:permission="android.permission.ACCESS_COARSE_LOCATION"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.location.NetworkLocationProvider" />
@ -43,6 +46,7 @@
<!-- Jelly Bean / KitKat -->
<service
android:name="org.microg.nlp.location.LocationServiceV2"
android:permission="android.permission.ACCESS_COARSE_LOCATION"
android:exported="true">
<intent-filter>
<!-- KitKat changed the action name but nothing else, hence we handle it the same -->

63
build.gradle Normal file
View File

@ -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'
}
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.microg.nlp.compat">
<!-- This is not needed, it's just here to stop build systems from complaining -->
</manifest>

24
compat/build.gradle Normal file
View File

@ -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']
}
}
}

View File

@ -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<GeocoderParams> CREATOR =
new Parcelable.Creator<GeocoderParams>() {
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) {
}
}

View File

@ -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.
*
* <p>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<Geofence> CREATOR = new Parcelable.Creator<Geofence>() {
@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;
}
}

View File

@ -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.
* <p/>
* <p>A location can consist of a latitude, longitude, timestamp,
* and other information such as bearing, altitude and velocity.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p> 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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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}.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>Following this call {@link #hasAltitude} will return true.
*/
public void setAltitude(double altitude) {
}
/**
* Remove the altitude from this location.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>Following this call {@link #hasSpeed} will return true.
*/
public void setSpeed(float speed) {
}
/**
* Remove the speed from this location.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>If this location does not have a bearing then 0.0 is returned.
*/
public float getBearing() {
return 0;
}
/**
* Set the bearing, in degrees.
* <p/>
* <p>Bearing is the horizontal direction of travel of this device,
* and is not related to the device orientation.
* <p/>
* <p>The input will be wrapped into the range (0.0, 360.0].
*/
public void setBearing(float bearing) {
}
/**
* Remove the bearing from this location.
* <p/>
* <p>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.
* <p/>
* <p>All locations generated by the {@link LocationManager} have an
* accuracy.
*/
public boolean hasAccuracy() {
return false;
}
/**
* Get the estimated accuracy of this location, in meters.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>See {@link #getAccuracy} for the definition of accuracy.
* <p/>
* <p>Following this call {@link #hasAccuracy} will return true.
*/
public void setAccuracy(float accuracy) {
}
/**
* Remove the accuracy from this location.
* <p/>
* <p>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.
* <p/>
* <p>A location object is currently considered complete if it has
* a valid provider, accuracy, wall-clock time and elapsed real-time.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p> 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.
* <p/>
* <ul>
* <li> satellites - the number of satellites used to derive the fix
* </ul>
*/
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<Location> CREATOR =
new Parcelable.Creator<Location>() {
@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) {
}
}

File diff suppressed because it is too large Load Diff

View File

@ -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}.
* <p/>
* <p>LocationRequest objects are used to request a quality of service
* for location updates from the Location Manager.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>Applications cannot specify the exact location sources that are
* used by Android's <em>Fusion Engine</em>. In fact, the system
* may have multiple location sources (providers) running and may
* fuse the results from several sources into a single Location object.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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).
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>This location request will allow high power location work.
*/
public static final int POWER_HIGH = 203;
/**
* Create a location request with default parameters.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>{@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.
* <p/>
* <p>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.
* <p/>
* <p>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}.
* <p/>
* <p>Applications with only the coarse location permission may have their
* interval silently throttled.
* <p/>
* <p>An interval of 0 is allowed, but not recommended, since
* location updates may be extremely fast on future implementations.
* <p/>
* <p>{@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.
* <p/>
* <p>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).
* <p/>
* <p>This allows your application to passively acquire locations
* at a rate faster than it actively acquires locations, saving power.
* <p/>
* <p>Unlike {@link #setInterval}, this parameter is exact. Your
* application will never receive updates faster than this value.
* <p/>
* <p>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}).
* <p/>
* <p>An interval of 0 is allowed, but not recommended, since
* location updates may be extremely fast on future implementations.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>The location manager will automatically stop updates after
* the request expires.
* <p/>
* <p>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.
* <p/>
* <p>This expiration time uses the same time base as {@link SystemClock#elapsedRealtime}.
* <p/>
* <p>The location manager will automatically stop updates after
* the request expires.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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<LocationRequest> CREATOR =
new Parcelable.Creator<LocationRequest>() {
@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;
}
}

View File

@ -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<ProviderProperties> CREATOR =
new Parcelable.Creator<ProviderProperties>() {
@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) {
}
}

View File

@ -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.
* <p>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<LocationRequest> locationRequests = null;
public ProviderRequest() {
}
public static final Parcelable.Creator<ProviderRequest> CREATOR =
new Parcelable.Creator<ProviderRequest>() {
@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) {
}
}

View File

@ -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.
* <p/>
* <p>Geocode providers can be implemented as services and return the result of
* {@link GeocodeProvider#getBinder()} in its getBinder() method.
* <p/>
* <p>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<Address> 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<Address> 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;
}
}

View File

@ -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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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
* <p/>
* Requires the android.permission.INSTALL_LOCATION_PROVIDER permission.
*/
public final void reportLocation(Location location) {
}
/**
* Enable the location provider.
* <p>The provider may initialize resources, but does
* not yet need to report locations.
*/
public abstract void onEnable();
/**
* Disable the location provider.
* <p>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.
* <p>Each call to this method overrides all previous requests.
* <p>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.
* <p>{@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.
* <p/>
* <p>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;
}
}

View File

@ -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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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).
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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.
* <p/>
* <p>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;
}
}

View File

@ -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.
* <p/>
* <p>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;
}
}

View File

@ -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.
* <p/>
* <p>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<LocationRequestUnbundled> getLocationRequests() {
return null;
}
}

View File

@ -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);
}

View File

@ -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.
* <p/>
* 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.
*
* <p/>
* <p> 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);
}

1
settings.gradle Normal file
View File

@ -0,0 +1 @@
include ':compat'

View File

@ -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 {

View File

@ -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 {