summaryrefslogtreecommitdiffstats
path: root/location
diff options
context:
space:
mode:
Diffstat (limited to 'location')
-rw-r--r--location/java/android/location/Geocoder.java6
-rw-r--r--location/java/android/location/IGeocodeProvider.aidl35
-rw-r--r--location/java/android/location/ILocationManager.aidl4
-rw-r--r--location/java/android/location/ILocationProvider.aidl16
-rw-r--r--location/java/android/location/LocationProviderImpl.java28
-rw-r--r--location/java/com/android/internal/location/GpsLocationProvider.java136
-rw-r--r--location/java/com/android/internal/location/LocationProviderProxy.java37
7 files changed, 196 insertions, 66 deletions
diff --git a/location/java/android/location/Geocoder.java b/location/java/android/location/Geocoder.java
index 53e46b7..2ce1273 100644
--- a/location/java/android/location/Geocoder.java
+++ b/location/java/android/location/Geocoder.java
@@ -36,11 +36,11 @@ import java.util.List;
* coordinate into a (partial) address. The amount of detail in a
* reverse geocoded location description may vary, for example one
* might contain the full street address of the closest building, while
- * another might contain only a city name and postal code.
+ * another might contain only a city name and postal code.
*
* The Geocoder class requires a backend service that is not included in
- * the core android framework. The Geocoder query methods will return an
- * empty list if there no backend service in the platform.
+ * the core android framework. The Geocoder query methods will return an
+ * empty list if there no backend service in the platform.
*/
public final class Geocoder {
private static final String TAG = "Geocoder";
diff --git a/location/java/android/location/IGeocodeProvider.aidl b/location/java/android/location/IGeocodeProvider.aidl
new file mode 100644
index 0000000..e79e8d2
--- /dev/null
+++ b/location/java/android/location/IGeocodeProvider.aidl
@@ -0,0 +1,35 @@
+/*
+ * 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.Address;
+
+/**
+ * An interface for location providers implementing the Geocoder services.
+ *
+ * {@hide}
+ */
+interface IGeocodeProvider {
+
+ String getFromLocation(double latitude, double longitude, int maxResults,
+ String language, String country, String variant, String appName, out List<Address> addrs);
+
+ String getFromLocationName(String locationName,
+ double lowerLeftLatitude, double lowerLeftLongitude,
+ double upperRightLatitude, double upperRightLongitude, int maxResults,
+ String language, String country, String variant, String appName, out List<Address> addrs);
+}
diff --git a/location/java/android/location/ILocationManager.aidl b/location/java/android/location/ILocationManager.aidl
index 86bd8b6..7d35814 100644
--- a/location/java/android/location/ILocationManager.aidl
+++ b/location/java/android/location/ILocationManager.aidl
@@ -18,6 +18,7 @@ package android.location;
import android.app.PendingIntent;
import android.location.Address;
+import android.location.IGeocodeProvider;
import android.location.IGpsStatusListener;
import android.location.ILocationCollector;
import android.location.ILocationListener;
@@ -77,7 +78,8 @@ interface ILocationManager
void setTestProviderStatus(String provider, int status, in Bundle extras, long updateTime);
void clearTestProviderStatus(String provider);
- /* for installing Network Location Provider */
+ /* for installing external Location Providers */
void setNetworkLocationProvider(ILocationProvider provider);
void setLocationCollector(ILocationCollector collector);
+ void setGeocodeProvider(IGeocodeProvider provider);
}
diff --git a/location/java/android/location/ILocationProvider.aidl b/location/java/android/location/ILocationProvider.aidl
index 6f9daff..82533a5 100644
--- a/location/java/android/location/ILocationProvider.aidl
+++ b/location/java/android/location/ILocationProvider.aidl
@@ -16,7 +16,6 @@
package android.location;
-import android.location.Address;
import android.os.Bundle;
/**
@@ -47,15 +46,8 @@ interface ILocationProvider {
void setMinTime(long minTime);
void updateNetworkState(int state);
boolean sendExtraCommand(String command, inout Bundle extras);
-
- /* the following are only used for NetworkLocationProvider */
- void updateCellLockStatus(boolean acquired);
- void addListener(in String[] applications);
- void removeListener(in String[] applications);
- String getFromLocation(double latitude, double longitude, int maxResults,
- String language, String country, String variant, String appName, out List<Address> addrs);
- String getFromLocationName(String locationName,
- double lowerLeftLatitude, double lowerLeftLongitude,
- double upperRightLatitude, double upperRightLongitude, int maxResults,
- String language, String country, String variant, String appName, out List<Address> addrs);
+ void addListener(int uid);
+ void removeListener(int uid);
+ void wakeLockAcquired();
+ void wakeLockReleased();
}
diff --git a/location/java/android/location/LocationProviderImpl.java b/location/java/android/location/LocationProviderImpl.java
index 2a9199e..a20aa3c 100644
--- a/location/java/android/location/LocationProviderImpl.java
+++ b/location/java/android/location/LocationProviderImpl.java
@@ -249,4 +249,32 @@ public abstract class LocationProviderImpl extends LocationProvider {
public boolean sendExtraCommand(String command, Bundle extras) {
return false;
}
+
+ /**
+ * Informs the location provider when a new client is listening for location information
+ *
+ * @param uid the uid of the client proces
+ */
+ public void addListener(int uid) {
+ }
+
+ /**
+ * Informs the location provider when a client is no longer listening for location information
+ *
+ * @param uid the uid of the client proces
+ */
+ public void removeListener(int uid) {
+ }
+
+ /**
+ * Informs the location provider when the location manager service has acquired its wake lock
+ */
+ public void wakeLockAcquired() {
+ }
+
+ /**
+ * Informs the location provider when the location manager service has released its wake lock
+ */
+ public void wakeLockReleased() {
+ }
}
diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java
index 8a33574..924641c 100644
--- a/location/java/com/android/internal/location/GpsLocationProvider.java
+++ b/location/java/com/android/internal/location/GpsLocationProvider.java
@@ -22,20 +22,23 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.location.Criteria;
import android.location.IGpsStatusListener;
-import android.location.ILocationCollector;
import android.location.ILocationManager;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.location.LocationProviderImpl;
+import android.net.ConnectivityManager;
import android.net.SntpClient;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
+import android.os.ServiceManager;
import android.os.SystemClock;
import android.util.Config;
import android.util.Log;
+import android.util.SparseIntArray;
+import com.android.internal.app.IBatteryStats;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.TelephonyIntents;
@@ -99,6 +102,14 @@ public class GpsLocationProvider extends LocationProviderImpl {
private static final int GPS_STATUS_ENGINE_ON = 3;
private static final int GPS_STATUS_ENGINE_OFF = 4;
+ // these need to match GpsSuplStatusValue defines in gps.h
+ /** SUPL status event values. */
+ private static final int GPS_REQUEST_SUPL_DATA_CONN = 1;
+ private static final int GPS_RELEASE_SUPL_DATA_CONN = 2;
+ private static final int GPS_SUPL_DATA_CONNECTED = 3;
+ private static final int GPS_SUPL_DATA_CONN_DONE = 4;
+ private static final int GPS_SUPL_DATA_CONN_FAILED = 5;
+
// these need to match GpsLocationFlags enum in gps.h
private static final int LOCATION_INVALID = 0;
private static final int LOCATION_HAS_LAT_LONG = 1;
@@ -122,6 +133,11 @@ public class GpsLocationProvider extends LocationProviderImpl {
private static final int GPS_DELETE_CELLDB_INFO = 0x8000;
private static final int GPS_DELETE_ALL = 0xFFFF;
+ // for mSuplDataConnectionState
+ private static final int SUPL_DATA_CONNECTION_CLOSED = 0;
+ private static final int SUPL_DATA_CONNECTION_OPENING = 1;
+ private static final int SUPL_DATA_CONNECTION_OPEN = 2;
+
private static final String PROPERTIES_FILE = "/etc/gps.conf";
private int mLocationFlags = LOCATION_INVALID;
@@ -176,6 +192,12 @@ public class GpsLocationProvider extends LocationProviderImpl {
private String mSuplHost;
private int mSuplPort;
private boolean mSetSuplServer;
+ private String mSuplApn;
+ private int mSuplDataConnectionState;
+ private final ConnectivityManager mConnMgr;
+
+ private final IBatteryStats mBatteryStats;
+ private final SparseIntArray mClientUids = new SparseIntArray();
// how often to request NTP time, in milliseconds
// current setting 4 hours
@@ -184,8 +206,6 @@ public class GpsLocationProvider extends LocationProviderImpl {
// current setting - 5 minutes
private static final long RETRY_INTERVAL = 5*60*1000;
- private ILocationCollector mCollector;
-
private class TelephonyBroadcastReceiver extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
@@ -198,10 +218,12 @@ public class GpsLocationProvider extends LocationProviderImpl {
if (Config.LOGD) {
Log.d(TAG, "state: " + state + " apnName: " + apnName + " reason: " + reason);
}
- if ("CONNECTED".equals(state)) {
- native_set_supl_apn(apnName);
- } else {
- native_set_supl_apn("");
+ if ("CONNECTED".equals(state) && apnName != null && apnName.length() > 0) {
+ mSuplApn = apnName;
+ if (mSuplDataConnectionState == SUPL_DATA_CONNECTION_OPENING) {
+ native_supl_data_conn_open(mSuplApn);
+ mSuplDataConnectionState = SUPL_DATA_CONNECTION_OPEN;
+ }
}
}
}
@@ -220,6 +242,11 @@ public class GpsLocationProvider extends LocationProviderImpl {
intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
context.registerReceiver(receiver, intentFilter);
+ mConnMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
+
+ // Battery statistics service to be notified when GPS turns on or off
+ mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService("batteryinfo"));
+
mProperties = new Properties();
try {
File file = new File(PROPERTIES_FILE);
@@ -242,10 +269,6 @@ public class GpsLocationProvider extends LocationProviderImpl {
}
}
- public void setLocationCollector(ILocationCollector collector) {
- mCollector = collector;
- }
-
/**
* Returns true if the provider requires access to a
* data network (e.g., the Internet), false otherwise.
@@ -547,6 +570,30 @@ public class GpsLocationProvider extends LocationProviderImpl {
}
@Override
+ public void addListener(int uid) {
+ mClientUids.put(uid, 0);
+ if (mNavigating) {
+ try {
+ mBatteryStats.noteStartGps(uid);
+ } catch (RemoteException e) {
+ Log.w(TAG, "RemoteException in addListener");
+ }
+ }
+ }
+
+ @Override
+ public void removeListener(int uid) {
+ mClientUids.delete(uid);
+ if (mNavigating) {
+ try {
+ mBatteryStats.noteStopGps(uid);
+ } catch (RemoteException e) {
+ Log.w(TAG, "RemoteException in removeListener");
+ }
+ }
+ }
+
+ @Override
public boolean sendExtraCommand(String command, Bundle extras) {
if ("delete_aiding_data".equals(command)) {
@@ -675,16 +722,6 @@ public class GpsLocationProvider extends LocationProviderImpl {
}
reportLocationChanged(mLocation);
-
- // Send to collector
- if ((flags & LOCATION_HAS_LAT_LONG) == LOCATION_HAS_LAT_LONG
- && mCollector != null) {
- try {
- mCollector.updateLocation(mLocation);
- } catch (RemoteException e) {
- Log.w(TAG, "mCollector.updateLocation failed");
- }
- }
}
if (mStarted && mStatus != AVAILABLE) {
@@ -725,6 +762,20 @@ public class GpsLocationProvider extends LocationProviderImpl {
}
}
+ try {
+ // update battery stats
+ for (int i=mClientUids.size() - 1; i >= 0; i--) {
+ int uid = mClientUids.keyAt(i);
+ if (mNavigating) {
+ mBatteryStats.noteStartGps(uid);
+ } else {
+ mBatteryStats.noteStopGps(uid);
+ }
+ }
+ } catch (RemoteException e) {
+ Log.w(TAG, "RemoteException in reportStatus");
+ }
+
// send an intent to notify that the GPS has been enabled or disabled.
Intent intent = new Intent(GPS_ENABLED_CHANGE_ACTION);
intent.putExtra(EXTRA_ENABLED, mNavigating);
@@ -782,7 +833,44 @@ public class GpsLocationProvider extends LocationProviderImpl {
updateStatus(TEMPORARILY_UNAVAILABLE, mSvCount);
}
}
-
+
+ /**
+ * called from native code to update SUPL status
+ */
+ private void reportSuplStatus(int status) {
+ switch (status) {
+ case GPS_REQUEST_SUPL_DATA_CONN:
+ int result = mConnMgr.startUsingNetworkFeature(
+ ConnectivityManager.TYPE_MOBILE, Phone.FEATURE_ENABLE_SUPL);
+ if (result == Phone.APN_ALREADY_ACTIVE) {
+ native_supl_data_conn_open(mSuplApn);
+ mSuplDataConnectionState = SUPL_DATA_CONNECTION_OPEN;
+ } else if (result == Phone.APN_REQUEST_STARTED) {
+ mSuplDataConnectionState = SUPL_DATA_CONNECTION_OPENING;
+ } else {
+ native_supl_data_conn_failed();
+ }
+ break;
+ case GPS_RELEASE_SUPL_DATA_CONN:
+ if (mSuplDataConnectionState != SUPL_DATA_CONNECTION_CLOSED) {
+ mConnMgr.stopUsingNetworkFeature(
+ ConnectivityManager.TYPE_MOBILE, Phone.FEATURE_ENABLE_SUPL);
+ native_supl_data_conn_closed();
+ mSuplDataConnectionState = SUPL_DATA_CONNECTION_CLOSED;
+ }
+ break;
+ case GPS_SUPL_DATA_CONNECTED:
+ // Log.d(TAG, "GPS_SUPL_DATA_CONNECTED");
+ break;
+ case GPS_SUPL_DATA_CONN_DONE:
+ // Log.d(TAG, "GPS_SUPL_DATA_CONN_DONE");
+ break;
+ case GPS_SUPL_DATA_CONN_FAILED:
+ // Log.d(TAG, "GPS_SUPL_DATA_CONN_FAILED");
+ break;
+ }
+ }
+
private void xtraDownloadRequest() {
if (Config.LOGD) Log.d(TAG, "xtraDownloadRequest");
if (mNetworkThread != null) {
@@ -1002,6 +1090,8 @@ public class GpsLocationProvider extends LocationProviderImpl {
private native void native_inject_xtra_data(byte[] data, int length);
// SUPL Support
+ private native void native_supl_data_conn_open(String apn);
+ private native void native_supl_data_conn_closed();
+ private native void native_supl_data_conn_failed();
private native void native_set_supl_server(int addr, int port);
- private native void native_set_supl_apn(String apn);
}
diff --git a/location/java/com/android/internal/location/LocationProviderProxy.java b/location/java/com/android/internal/location/LocationProviderProxy.java
index 1f4940f..72dd07d 100644
--- a/location/java/com/android/internal/location/LocationProviderProxy.java
+++ b/location/java/com/android/internal/location/LocationProviderProxy.java
@@ -222,52 +222,35 @@ public class LocationProviderProxy extends LocationProviderImpl {
}
}
- public void updateCellLockStatus(boolean acquired) {
+ public void addListener(int uid) {
try {
- mProvider.updateCellLockStatus(acquired);
- } catch (RemoteException e) {
- Log.e(TAG, "updateCellLockStatus failed", e);
- }
- }
-
- public void addListener(String[] applications) {
- try {
- mProvider.addListener(applications);
+ mProvider.addListener(uid);
} catch (RemoteException e) {
Log.e(TAG, "addListener failed", e);
}
}
- public void removeListener(String[] applications) {
+ public void removeListener(int uid) {
try {
- mProvider.removeListener(applications);
+ mProvider.removeListener(uid);
} catch (RemoteException e) {
Log.e(TAG, "removeListener failed", e);
}
}
- public String getFromLocation(double latitude, double longitude, int maxResults,
- String language, String country, String variant, String appName, List<Address> addrs) {
+ public void wakeLockAcquired() {
try {
- return mProvider.getFromLocation(latitude, longitude, maxResults, language, country,
- variant, appName, addrs);
+ mProvider.wakeLockAcquired();
} catch (RemoteException e) {
- Log.e(TAG, "getFromLocation failed", e);
- return null;
+ Log.e(TAG, "wakeLockAcquired failed", e);
}
}
- public String getFromLocationName(String locationName,
- double lowerLeftLatitude, double lowerLeftLongitude,
- double upperRightLatitude, double upperRightLongitude, int maxResults,
- String language, String country, String variant, String appName, List<Address> addrs) {
+ public void wakeLockReleased() {
try {
- return mProvider.getFromLocationName(locationName, lowerLeftLatitude,
- lowerLeftLongitude, upperRightLatitude, upperRightLongitude,
- maxResults, language, country, variant, appName, addrs);
+ mProvider.wakeLockReleased();
} catch (RemoteException e) {
- Log.e(TAG, "getFromLocationName failed", e);
- return null;
+ Log.e(TAG, "wakeLockReleased failed", e);
}
}
}