Skip to content

Commit 6fa9ad4

Browse files
author
Nick Pelly
committed
Location overhaul, major commit.
Themes: Fused Location, Geofencing, LocationRequest. API changes o Fused location is always returned when asking for location by Criteria. o Fused location is never returned as a LocationProvider object, nor returned as a provider String. This wouldn't make sense because the current API design assumes that LocationProvider's have fixed properties (accuracy, power etc). o The fused location engine will tune itself based on the criteria passed by applications. o Deprecate LocationProvider. Apps should use fused location (via Criteria class), instead of enumerating through LocationProvider objects. It is also over-engineered: designed for a world with a plethora of location providers that never materialized. o The Criteria class is also over-engineered, with many methods that aren't currently used, but for now we won't deprecate them since they may have value in the future. It is now used to tune the fused location engine. o Deprecate getBestProvider() and getProvider(). o Add getLastKnownLocation(Criteria), so we can return last known fused locations. o Apps with only ACCESS_COARSE_LOCATION _can_ now use the GPS, but the location they receive will be fudged to a 1km radius. They can also use NETWORK and fused locatoins, which are fudged in the same way if necessary. o Totally deprecate Criteria, in favor of LocationRequest. Criteria was designed to map QOS to a location provider. What we really need is to map QOS to _locations_. The death knell was the conflicting ACCURACY_ constants on Criteria, with values 1, 2, 3, 1, 2. Yes not a typo. o Totally deprecate LocationProvider. o Deprecate test/mock provider support. They require a named provider, which is a concept we are moving away from. We do not yet have a replacement, but I think its ok to deprecate since you also need to have 'allow mock locations' checked in developer settings. They will continue to work. o Deprecate event codes associated with provider status. The fused provider is _always_ available. o Introduce Geofence data object to provide an easier path fowards for polygons etc. Implementation changes o Fused implementation: incoming (GPS and NLP) location fixes are given a weight, that exponentially decays with respect to age and accuracy. The half-life of age is ~60 seconds, and the half-life of accuracy is ~20 meters. The fixes are weighted and combined to output a fused location. o Move Fused Location impl into frameworks/base/packages/FusedLocation o Refactor Fused Location behind the IProvider AIDL interface. This allow us to distribute newer versions of Fused Location in a new APK, at run-time. o Introduce ServiceWatcher.java, to refactor code used for run-time upgrades of Fused Location, and the NLP. o Fused Location is by default run in the system server (but can be moved to any process or pacakge, even at run-time). o Plumb the Criteria requirements through to the Fused Location provider via ILocation.sendExtraCommand(). I re-used this interface to avoid modifying the ILocation interface, which would have broken run-time upgradability of the NLP. o Switch the geofence manager to using fused location. o Clean up 'adb shell dumpsys location' output. o Introduce config_locationProviderPackageNames and config_overlay_locationProviderPackageNames to configure the default and overlay package names for Geocoder, NLP and FLP. o Lots of misc cleanup. o Improve location fudging. Apply random vector then quantize. o Hide internal POJO's from clients of com.android.location.provider.jar (NLP and FLP). Introduce wrappers ProviderRequestUnbundled and ProviderPropertiesUnbundled. o Introduce ProviderProperties to collapse all the provider accuracy/ bearing/altitude/power plumbing (that is deprecated anyway). o DELETE lots of code: DummyLocationProvider, o Rename the (internal) LocationProvider to LocationProviderBase. o Plumb pid, uid and packageName throughout LocationManagerService#Receiver to support future features. TODO: The FLP and Geofencer have a lot of room to be more intelligent TODO: Documentation TODO: test test test Change-Id: Iacefd2f176ed40ce1e23b090a164792aa8819c55
1 parent c47f80f commit 6fa9ad4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4357
-3123
lines changed

Android.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ LOCAL_SRC_FILES += \
197197
location/java/android/location/IGpsStatusProvider.aidl \
198198
location/java/android/location/ILocationListener.aidl \
199199
location/java/android/location/ILocationManager.aidl \
200-
location/java/android/location/ILocationProvider.aidl \
201200
location/java/android/location/INetInitiatedListener.aidl \
201+
location/java/com/android/internal/location/ILocationProvider.aidl \
202202
media/java/android/media/IAudioService.aidl \
203203
media/java/android/media/IAudioFocusDispatcher.aidl \
204204
media/java/android/media/IAudioRoutesObserver.aidl \
@@ -306,7 +306,11 @@ aidl_files := \
306306
frameworks/base/graphics/java/android/graphics/Rect.aidl \
307307
frameworks/base/graphics/java/android/graphics/Region.aidl \
308308
frameworks/base/location/java/android/location/Criteria.aidl \
309+
frameworks/base/location/java/android/location/Geofence.aidl \
309310
frameworks/base/location/java/android/location/Location.aidl \
311+
frameworks/base/location/java/android/location/LocationRequest.aidl \
312+
frameworks/base/location/java/com/android/internal/location/ProviderProperties.aidl \
313+
frameworks/base/location/java/com/android/internal/location/ProviderRequest.aidl \
310314
frameworks/base/telephony/java/android/telephony/ServiceState.aidl \
311315
frameworks/base/telephony/java/com/android/internal/telephony/IPhoneSubInfo.aidl \
312316
frameworks/base/telephony/java/com/android/internal/telephony/ITelephony.aidl \

api/current.txt

Lines changed: 83 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10451,7 +10451,7 @@ package android.location {
1045110451
field public static final android.os.Parcelable.Creator CREATOR;
1045210452
}
1045310453

10454-
public class Criteria implements android.os.Parcelable {
10454+
public deprecated class Criteria implements android.os.Parcelable {
1045510455
ctor public Criteria();
1045610456
ctor public Criteria(android.location.Criteria);
1045710457
method public int describeContents();
@@ -10497,6 +10497,13 @@ package android.location {
1049710497
method public static boolean isPresent();
1049810498
}
1049910499

10500+
public final class Geofence implements android.os.Parcelable {
10501+
method public static android.location.Geofence createCircle(double, double, float);
10502+
method public int describeContents();
10503+
method public void writeToParcel(android.os.Parcel, int);
10504+
field public static final android.os.Parcelable.Creator CREATOR;
10505+
}
10506+
1050010507
public final class GpsSatellite {
1050110508
method public float getAzimuth();
1050210509
method public float getElevation();
@@ -10534,7 +10541,7 @@ package android.location {
1053410541
method public int describeContents();
1053510542
method public static void distanceBetween(double, double, double, double, float[]);
1053610543
method public float distanceTo(android.location.Location);
10537-
method public void dump(android.util.Printer, java.lang.String);
10544+
method public deprecated void dump(android.util.Printer, java.lang.String);
1053810545
method public float getAccuracy();
1053910546
method public double getAltitude();
1054010547
method public float getBearing();
@@ -10582,65 +10589,96 @@ package android.location {
1058210589
public class LocationManager {
1058310590
method public boolean addGpsStatusListener(android.location.GpsStatus.Listener);
1058410591
method public boolean addNmeaListener(android.location.GpsStatus.NmeaListener);
10585-
method public void addProximityAlert(double, double, float, long, android.app.PendingIntent);
10586-
method public void addTestProvider(java.lang.String, boolean, boolean, boolean, boolean, boolean, boolean, boolean, int, int);
10587-
method public void clearTestProviderEnabled(java.lang.String);
10588-
method public void clearTestProviderLocation(java.lang.String);
10589-
method public void clearTestProviderStatus(java.lang.String);
10590-
method public java.util.List<java.lang.String> getAllProviders();
10591-
method public java.lang.String getBestProvider(android.location.Criteria, boolean);
10592+
method public deprecated void addProximityAlert(double, double, float, long, android.app.PendingIntent);
10593+
method public deprecated void addTestProvider(java.lang.String, boolean, boolean, boolean, boolean, boolean, boolean, boolean, int, int);
10594+
method public deprecated void clearTestProviderEnabled(java.lang.String);
10595+
method public deprecated void clearTestProviderLocation(java.lang.String);
10596+
method public deprecated void clearTestProviderStatus(java.lang.String);
10597+
method public deprecated java.util.List<java.lang.String> getAllProviders();
10598+
method public deprecated java.lang.String getBestProvider(android.location.Criteria, boolean);
1059210599
method public android.location.GpsStatus getGpsStatus(android.location.GpsStatus);
10593-
method public android.location.Location getLastKnownLocation(java.lang.String);
10594-
method public android.location.LocationProvider getProvider(java.lang.String);
10595-
method public java.util.List<java.lang.String> getProviders(boolean);
10596-
method public java.util.List<java.lang.String> getProviders(android.location.Criteria, boolean);
10597-
method public boolean isProviderEnabled(java.lang.String);
10600+
method public deprecated android.location.Location getLastKnownLocation(java.lang.String);
10601+
method public deprecated android.location.Location getLastKnownLocation(android.location.Criteria);
10602+
method public android.location.Location getLastLocation(android.location.LocationRequest);
10603+
method public deprecated android.location.LocationProvider getProvider(java.lang.String);
10604+
method public deprecated java.util.List<java.lang.String> getProviders(boolean);
10605+
method public deprecated java.util.List<java.lang.String> getProviders(android.location.Criteria, boolean);
10606+
method public deprecated boolean isProviderEnabled(java.lang.String);
10607+
method public void removeAllGeofences(android.app.PendingIntent);
10608+
method public void removeGeofence(android.location.Geofence, android.app.PendingIntent);
1059810609
method public void removeGpsStatusListener(android.location.GpsStatus.Listener);
1059910610
method public void removeNmeaListener(android.location.GpsStatus.NmeaListener);
10600-
method public void removeProximityAlert(android.app.PendingIntent);
10601-
method public void removeTestProvider(java.lang.String);
10611+
method public deprecated void removeProximityAlert(android.app.PendingIntent);
10612+
method public deprecated void removeTestProvider(java.lang.String);
1060210613
method public void removeUpdates(android.location.LocationListener);
1060310614
method public void removeUpdates(android.app.PendingIntent);
10604-
method public void requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener);
10605-
method public void requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener, android.os.Looper);
10606-
method public void requestLocationUpdates(long, float, android.location.Criteria, android.location.LocationListener, android.os.Looper);
10607-
method public void requestLocationUpdates(java.lang.String, long, float, android.app.PendingIntent);
10608-
method public void requestLocationUpdates(long, float, android.location.Criteria, android.app.PendingIntent);
10609-
method public void requestSingleUpdate(java.lang.String, android.location.LocationListener, android.os.Looper);
10610-
method public void requestSingleUpdate(android.location.Criteria, android.location.LocationListener, android.os.Looper);
10611-
method public void requestSingleUpdate(java.lang.String, android.app.PendingIntent);
10612-
method public void requestSingleUpdate(android.location.Criteria, android.app.PendingIntent);
10613-
method public boolean sendExtraCommand(java.lang.String, java.lang.String, android.os.Bundle);
10614-
method public void setTestProviderEnabled(java.lang.String, boolean);
10615-
method public void setTestProviderLocation(java.lang.String, android.location.Location);
10616-
method public void setTestProviderStatus(java.lang.String, int, android.os.Bundle, long);
10617-
field public static final java.lang.String GPS_PROVIDER = "gps";
10615+
method public void requestGeofence(android.location.LocationRequest, android.location.Geofence, android.app.PendingIntent);
10616+
method public deprecated void requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener);
10617+
method public deprecated void requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener, android.os.Looper);
10618+
method public deprecated void requestLocationUpdates(long, float, android.location.Criteria, android.location.LocationListener, android.os.Looper);
10619+
method public deprecated void requestLocationUpdates(java.lang.String, long, float, android.app.PendingIntent);
10620+
method public deprecated void requestLocationUpdates(long, float, android.location.Criteria, android.app.PendingIntent);
10621+
method public void requestLocationUpdates(android.location.LocationRequest, android.location.LocationListener, android.os.Looper);
10622+
method public void requestLocationUpdates(android.location.LocationRequest, android.app.PendingIntent);
10623+
method public deprecated void requestSingleUpdate(java.lang.String, android.location.LocationListener, android.os.Looper);
10624+
method public deprecated void requestSingleUpdate(android.location.Criteria, android.location.LocationListener, android.os.Looper);
10625+
method public deprecated void requestSingleUpdate(java.lang.String, android.app.PendingIntent);
10626+
method public deprecated void requestSingleUpdate(android.location.Criteria, android.app.PendingIntent);
10627+
method public deprecated boolean sendExtraCommand(java.lang.String, java.lang.String, android.os.Bundle);
10628+
method public deprecated void setTestProviderEnabled(java.lang.String, boolean);
10629+
method public deprecated void setTestProviderLocation(java.lang.String, android.location.Location);
10630+
method public deprecated void setTestProviderStatus(java.lang.String, int, android.os.Bundle, long);
10631+
field public static final deprecated java.lang.String GPS_PROVIDER = "gps";
1061810632
field public static final java.lang.String KEY_LOCATION_CHANGED = "location";
10619-
field public static final java.lang.String KEY_PROVIDER_ENABLED = "providerEnabled";
10633+
field public static final deprecated java.lang.String KEY_PROVIDER_ENABLED = "providerEnabled";
1062010634
field public static final java.lang.String KEY_PROXIMITY_ENTERING = "entering";
10621-
field public static final java.lang.String KEY_STATUS_CHANGED = "status";
10622-
field public static final java.lang.String NETWORK_PROVIDER = "network";
10623-
field public static final java.lang.String PASSIVE_PROVIDER = "passive";
10624-
field public static final java.lang.String PROVIDERS_CHANGED_ACTION = "android.location.PROVIDERS_CHANGED";
10635+
field public static final deprecated java.lang.String KEY_STATUS_CHANGED = "status";
10636+
field public static final deprecated java.lang.String NETWORK_PROVIDER = "network";
10637+
field public static final deprecated java.lang.String PASSIVE_PROVIDER = "passive";
10638+
field public static final deprecated java.lang.String PROVIDERS_CHANGED_ACTION = "android.location.PROVIDERS_CHANGED";
1062510639
}
1062610640

10627-
public abstract class LocationProvider {
10628-
method public abstract int getAccuracy();
10641+
public deprecated class LocationProvider {
10642+
method public int getAccuracy();
1062910643
method public java.lang.String getName();
10630-
method public abstract int getPowerRequirement();
10631-
method public abstract boolean hasMonetaryCost();
10644+
method public int getPowerRequirement();
10645+
method public boolean hasMonetaryCost();
1063210646
method public boolean meetsCriteria(android.location.Criteria);
10633-
method public abstract boolean requiresCell();
10634-
method public abstract boolean requiresNetwork();
10635-
method public abstract boolean requiresSatellite();
10636-
method public abstract boolean supportsAltitude();
10637-
method public abstract boolean supportsBearing();
10638-
method public abstract boolean supportsSpeed();
10647+
method public boolean requiresCell();
10648+
method public boolean requiresNetwork();
10649+
method public boolean requiresSatellite();
10650+
method public boolean supportsAltitude();
10651+
method public boolean supportsBearing();
10652+
method public boolean supportsSpeed();
1063910653
field public static final int AVAILABLE = 2; // 0x2
1064010654
field public static final int OUT_OF_SERVICE = 0; // 0x0
1064110655
field public static final int TEMPORARILY_UNAVAILABLE = 1; // 0x1
1064210656
}
1064310657

10658+
public final class LocationRequest implements android.os.Parcelable {
10659+
method public static android.location.LocationRequest create();
10660+
method public int describeContents();
10661+
method public long getExpireAt();
10662+
method public long getFastestInterval();
10663+
method public long getInterval();
10664+
method public int getNumUpdates();
10665+
method public int getQuality();
10666+
method public android.location.LocationRequest setExpireAt(long);
10667+
method public android.location.LocationRequest setExpireIn(long);
10668+
method public android.location.LocationRequest setFastestInterval(long);
10669+
method public android.location.LocationRequest setInterval(long);
10670+
method public android.location.LocationRequest setNumUpdates(int);
10671+
method public android.location.LocationRequest setQuality(int);
10672+
method public void writeToParcel(android.os.Parcel, int);
10673+
field public static final int ACCURACY_BLOCK = 102; // 0x66
10674+
field public static final int ACCURACY_CITY = 104; // 0x68
10675+
field public static final int ACCURACY_FINE = 100; // 0x64
10676+
field public static final android.os.Parcelable.Creator CREATOR;
10677+
field public static final int POWER_HIGH = 203; // 0xcb
10678+
field public static final int POWER_LOW = 201; // 0xc9
10679+
field public static final int POWER_NONE = 200; // 0xc8
10680+
}
10681+
1064410682
}
1064510683

1064610684
package android.media {

core/res/res/values/config.xml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,30 @@
592592
<!-- True if WallpaperService is enabled -->
593593
<bool name="config_enableWallpaperService">true</bool>
594594

595-
<!-- Package name providing network location support. -->
596-
<string name="config_networkLocationProviderPackageName" translatable="false">@null</string>
595+
<!-- Package name(s) containing location provider support.
596+
These packages can contain services implementing location providers,
597+
such as the Geocode Provider, Network Location Provider, and
598+
Fused Location Provider. They will each be searched for
599+
service components implementing these providers.
600+
It is strongly recommended that the packages explicitly named
601+
below are on the system image, so that they will not map to
602+
a 3rd party application.
603+
The location framework also has support for installation
604+
of new location providers at run-time. The new package does not
605+
have to be explicitly listed here, however it must have a signature
606+
that matches the signature of at least one package on this list.
607+
Platforms should overlay additional packages in
608+
config_overlay_locationProviderPackageNames, instead of overlaying
609+
this config, if they only want to append packages and not replace
610+
the entire array.
611+
-->
612+
<string-array name="config_locationProviderPackageNames" translatable="false">
613+
<item>com.android.location.fused</item>
614+
</string-array>
597615

598-
<!-- Package name providing geocoder API support. -->
599-
<string name="config_geocodeProviderPackageName" translatable="false">@null</string>
616+
<!-- Pacakge name(s) supplied by overlay, and appended to
617+
config_locationProviderPackageNames. -->
618+
<string-array name="config_overlay_locationProviderPackageNames" translatable="false" />
600619

601620
<!-- Boolean indicating if current platform supports bluetooth SCO for off call
602621
use cases -->

core/res/res/values/public.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,8 @@
14151415
<java-symbol type="array" name="config_serialPorts" />
14161416
<java-symbol type="array" name="radioAttributes" />
14171417
<java-symbol type="array" name="config_oemUsbModeOverride" />
1418+
<java-symbol type="array" name="config_locationProviderPackageNames" />
1419+
<java-symbol type="array" name="config_overlay_locationProviderPackageNames" />
14181420
<java-symbol type="bool" name="config_animateScreenLights" />
14191421
<java-symbol type="bool" name="config_automatic_brightness_available" />
14201422
<java-symbol type="bool" name="config_sf_limitedAlpha" />
@@ -1493,8 +1495,6 @@
14931495
<java-symbol type="string" name="car_mode_disable_notification_title" />
14941496
<java-symbol type="string" name="chooser_wallpaper" />
14951497
<java-symbol type="string" name="config_datause_iface" />
1496-
<java-symbol type="string" name="config_geocodeProviderPackageName" />
1497-
<java-symbol type="string" name="config_networkLocationProviderPackageName" />
14981498
<java-symbol type="string" name="config_wimaxManagerClassname" />
14991499
<java-symbol type="string" name="config_wimaxNativeLibLocation" />
15001500
<java-symbol type="string" name="config_wimaxServiceClassname" />

location/java/android/location/Criteria.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
* location provider. Providers maybe ordered according to accuracy,
2525
* power usage, ability to report altitude, speed,
2626
* and bearing, and monetary cost.
27+
* @deprecated {@link LocationRequest} instead
2728
*/
29+
@Deprecated
2830
public class Criteria implements Parcelable {
2931
/**
3032
* A constant indicating that the application does not choose to
@@ -326,6 +328,7 @@ public boolean isBearingRequired() {
326328

327329
public static final Parcelable.Creator<Criteria> CREATOR =
328330
new Parcelable.Creator<Criteria>() {
331+
@Override
329332
public Criteria createFromParcel(Parcel in) {
330333
Criteria c = new Criteria();
331334
c.mHorizontalAccuracy = in.readInt();
@@ -340,15 +343,18 @@ public Criteria createFromParcel(Parcel in) {
340343
return c;
341344
}
342345

346+
@Override
343347
public Criteria[] newArray(int size) {
344348
return new Criteria[size];
345349
}
346350
};
347351

352+
@Override
348353
public int describeContents() {
349354
return 0;
350355
}
351356

357+
@Override
352358
public void writeToParcel(Parcel parcel, int flags) {
353359
parcel.writeInt(mHorizontalAccuracy);
354360
parcel.writeInt(mVerticalAccuracy);
@@ -360,4 +366,43 @@ public void writeToParcel(Parcel parcel, int flags) {
360366
parcel.writeInt(mSpeedRequired ? 1 : 0);
361367
parcel.writeInt(mCostAllowed ? 1 : 0);
362368
}
369+
370+
private static String powerToString(int power) {
371+
switch (power) {
372+
case NO_REQUIREMENT:
373+
return "NO_REQ";
374+
case POWER_LOW:
375+
return "LOW";
376+
case POWER_MEDIUM:
377+
return "MEDIUM";
378+
case POWER_HIGH:
379+
return "HIGH";
380+
default:
381+
return "???";
382+
}
383+
}
384+
385+
private static String accuracyToString(int accuracy) {
386+
switch (accuracy) {
387+
case NO_REQUIREMENT:
388+
return "---";
389+
case ACCURACY_HIGH:
390+
return "HIGH";
391+
case ACCURACY_MEDIUM:
392+
return "MEDIUM";
393+
case ACCURACY_LOW:
394+
return "LOW";
395+
default:
396+
return "???";
397+
}
398+
}
399+
400+
@Override
401+
public String toString() {
402+
StringBuilder s = new StringBuilder();
403+
s.append("Criteria[power=").append(powerToString(mPowerRequirement));
404+
s.append(" acc=").append(accuracyToString(mHorizontalAccuracy));
405+
s.append(']');
406+
return s.toString();
407+
}
363408
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (C) 2012, The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.location;
18+
19+
parcelable Geofence;

0 commit comments

Comments
 (0)