diff options
author | Jean-Baptiste Queru <jbq@google.com> | 2009-07-21 11:16:54 -0700 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2009-07-21 11:16:54 -0700 |
commit | cf4550c3198d6b3d92cdc52707fe70d7cc0caa9f (patch) | |
tree | 6510f35ad004f1a4640b48264c290926e8596d7a /location/java | |
parent | 4cf03d381b2dff908857fceff0bec445f8d44f36 (diff) | |
download | frameworks_base-cf4550c3198d6b3d92cdc52707fe70d7cc0caa9f.zip frameworks_base-cf4550c3198d6b3d92cdc52707fe70d7cc0caa9f.tar.gz frameworks_base-cf4550c3198d6b3d92cdc52707fe70d7cc0caa9f.tar.bz2 |
donut snapshot
Diffstat (limited to 'location/java')
7 files changed, 134 insertions, 150 deletions
diff --git a/location/java/android/location/ILocationCollector.aidl b/location/java/android/location/ILocationCollector.aidl deleted file mode 100644 index b2e1796..0000000 --- a/location/java/android/location/ILocationCollector.aidl +++ /dev/null @@ -1,36 +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.Location; - -/** - * Listens for GPS and cell/wifi changes and anonymously uploads to server - * for improving quality of service of NetworkLocationProvider. - * This service is only enabled when the user has enabled the - * network location provider. - * - * {@hide} - */ -oneway interface ILocationCollector { - /** - * Updates GPS location if collection is enabled - * - * @param location location object - */ - void updateLocation(in Location location); -} diff --git a/location/java/android/location/ILocationManager.aidl b/location/java/android/location/ILocationManager.aidl index 2c214c9..caf9516 100644 --- a/location/java/android/location/ILocationManager.aidl +++ b/location/java/android/location/ILocationManager.aidl @@ -20,7 +20,6 @@ import android.app.PendingIntent; import android.location.Address; import android.location.IGeocodeProvider; import android.location.IGpsStatusListener; -import android.location.ILocationCollector; import android.location.ILocationListener; import android.location.ILocationProvider; import android.location.Location; @@ -83,6 +82,5 @@ interface ILocationManager /* for installing external Location Providers */ void installLocationProvider(String name, ILocationProvider provider); - void installLocationCollector(ILocationCollector collector); void installGeocodeProvider(IGeocodeProvider provider); } diff --git a/location/java/android/location/ILocationProvider.aidl b/location/java/android/location/ILocationProvider.aidl index 6c23f83..4fe0494 100644 --- a/location/java/android/location/ILocationProvider.aidl +++ b/location/java/android/location/ILocationProvider.aidl @@ -16,6 +16,7 @@ package android.location; +import android.location.Location; import android.os.Bundle; /** @@ -41,6 +42,7 @@ interface ILocationProvider { void enableLocationTracking(boolean enable); void setMinTime(long minTime); void updateNetworkState(int state); + void updateLocation(in Location location); boolean sendExtraCommand(String command, inout Bundle extras); void addListener(int uid); void removeListener(int uid); diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java index 872838c..86ea66f 100644 --- a/location/java/android/location/LocationManager.java +++ b/location/java/android/location/LocationManager.java @@ -1279,27 +1279,6 @@ public class LocationManager { } /** - * Installs a location collector. - * - * @param provider Binder interface for the location collector - * - * @return true if the command succeeds. - * - * Requires the android.permission.INSTALL_LOCATION_COLLECTOR permission. - * - * {@hide} - */ - public boolean installLocationCollector(ILocationCollector collector) { - try { - mService.installLocationCollector(collector); - return true; - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in setLocationCollector: ", e); - return false; - } - } - - /** * Installs a geocoder server. * * @param provider Binder interface for the geocoder provider diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java index 565859c..4a51e31 100644..100755 --- a/location/java/com/android/internal/location/GpsLocationProvider.java +++ b/location/java/com/android/internal/location/GpsLocationProvider.java @@ -208,12 +208,6 @@ public class GpsLocationProvider extends ILocationProvider.Stub { private GpsNetworkThread mNetworkThread; private Object mNetworkThreadLock = new Object(); - private String mSuplHost; - private int mSuplPort; - private String mC2KHost; - private int mC2KPort; - private boolean mSetSuplServer; - private boolean mSetC2KServer; private String mAGpsApn; private int mAGpsDataConnectionState; private final ConnectivityManager mConnMgr; @@ -355,23 +349,27 @@ public class GpsLocationProvider extends ILocationProvider.Stub { stream.close(); mNtpServer = mProperties.getProperty("NTP_SERVER", null); - mSuplHost = mProperties.getProperty("SUPL_HOST"); + String host = mProperties.getProperty("SUPL_HOST"); String portString = mProperties.getProperty("SUPL_PORT"); - if (mSuplHost != null && portString != null) { + if (host != null && portString != null) { try { - mSuplPort = Integer.parseInt(portString); - mSetSuplServer = true; + int port = Integer.parseInt(portString); + native_set_agps_server(AGPS_TYPE_SUPL, host, port); + // use MS-Based position mode if SUPL support is enabled + mPositionMode = GPS_POSITION_MODE_MS_BASED; } catch (NumberFormatException e) { Log.e(TAG, "unable to parse SUPL_PORT: " + portString); } } - mC2KHost = mProperties.getProperty("C2K_HOST"); + host = mProperties.getProperty("C2K_HOST"); portString = mProperties.getProperty("C2K_PORT"); - if (mC2KHost != null && portString != null) { + if (host != null && portString != null) { try { - mC2KPort = Integer.parseInt(portString); - mSetC2KServer = true; + int port = Integer.parseInt(portString); + native_set_agps_server(AGPS_TYPE_C2K, host, port); + // use MS-Based position mode if SUPL support is enabled + mPositionMode = GPS_POSITION_MODE_MS_BASED; } catch (NumberFormatException e) { Log.e(TAG, "unable to parse C2K_PORT: " + portString); } @@ -386,10 +384,7 @@ public class GpsLocationProvider extends ILocationProvider.Stub { * data network (e.g., the Internet), false otherwise. */ public boolean requiresNetwork() { - // We want updateNetworkState() to get called when the network state changes - // for XTRA and NTP time injection support. - return (mNtpServer != null || native_supports_xtra() || - mSuplHost != null || mC2KHost != null); + return true; } public void updateNetworkState(int state) { @@ -406,6 +401,17 @@ public class GpsLocationProvider extends ILocationProvider.Stub { } /** + * This is called to inform us when another location provider returns a location. + * Someday we might use this for network location injection to aid the GPS + */ + public void updateLocation(Location location) { + if (location.hasAccuracy()) { + native_inject_location(location.getLatitude(), location.getLongitude(), + location.getAccuracy()); + } + } + + /** * Returns true if the provider requires access to a * satellite-based positioning system (e.g., GPS), false * otherwise. @@ -611,27 +617,44 @@ public class GpsLocationProvider extends ILocationProvider.Stub { synchronized(mListeners) { mListeners.remove(this); } + if (mListener != null) { + mListener.asBinder().unlinkToDeath(this, 0); + } } } public void addListener(int uid) { - mClientUids.put(uid, 0); - if (mNavigating) { - try { - mBatteryStats.noteStartGps(uid); - } catch (RemoteException e) { - Log.w(TAG, "RemoteException in addListener"); + synchronized(mListeners) { + if (mClientUids.indexOfKey(uid) >= 0) { + // Shouldn't be here -- already have this uid. + Log.w(TAG, "Duplicate add listener for uid " + uid); + return; + } + mClientUids.put(uid, 0); + if (mNavigating) { + try { + mBatteryStats.noteStartGps(uid); + } catch (RemoteException e) { + Log.w(TAG, "RemoteException in addListener"); + } } } } public void removeListener(int uid) { - mClientUids.delete(uid); - if (mNavigating) { - try { - mBatteryStats.noteStopGps(uid); - } catch (RemoteException e) { - Log.w(TAG, "RemoteException in removeListener"); + synchronized(mListeners) { + if (mClientUids.indexOfKey(uid) < 0) { + // Shouldn't be here -- don't have this uid. + Log.w(TAG, "Unneeded remove listener for uid " + uid); + return; + } + mClientUids.delete(uid); + if (mNavigating) { + try { + mBatteryStats.noteStopGps(uid); + } catch (RemoteException e) { + Log.w(TAG, "RemoteException in removeListener"); + } } } } @@ -641,6 +664,16 @@ public class GpsLocationProvider extends ILocationProvider.Stub { if ("delete_aiding_data".equals(command)) { return deleteAidingData(extras); } + if ("force_time_injection".equals(command)) { + return forceTimeInjection(); + } + if ("force_xtra_injection".equals(command)) { + if (native_supports_xtra() && mNetworkThread != null) { + xtraDownloadRequest(); + return true; + } + return false; + } Log.w(TAG, "sendExtraCommand: unknown command " + command); return false; @@ -676,6 +709,15 @@ public class GpsLocationProvider extends ILocationProvider.Stub { return false; } + private boolean forceTimeInjection() { + if (Config.LOGD) Log.d(TAG, "forceTimeInjection"); + if (mNetworkThread != null) { + mNetworkThread.timeInjectRequest(); + return true; + } + return false; + } + public void startNavigating() { if (!mStarted) { if (DEBUG) Log.d(TAG, "startNavigating"); @@ -811,30 +853,33 @@ public class GpsLocationProvider extends ILocationProvider.Stub { private void reportStatus(int status) { if (VERBOSE) Log.v(TAG, "reportStatus status: " + status); - boolean wasNavigating = mNavigating; - mNavigating = (status == GPS_STATUS_SESSION_BEGIN); - - if (wasNavigating != mNavigating) { + synchronized(mListeners) { + boolean wasNavigating = mNavigating; + mNavigating = (status == GPS_STATUS_SESSION_BEGIN); + + if (wasNavigating == mNavigating) { + return; + } + if (mNavigating) { if (DEBUG) Log.d(TAG, "Acquiring wakelock"); mWakeLock.acquire(); } - synchronized(mListeners) { - int size = mListeners.size(); - for (int i = 0; i < size; i++) { - Listener listener = mListeners.get(i); - try { - if (mNavigating) { - listener.mListener.onGpsStarted(); - } else { - listener.mListener.onGpsStopped(); - } - } catch (RemoteException e) { - Log.w(TAG, "RemoteException in reportStatus"); - mListeners.remove(listener); - // adjust for size of list changing - size--; + + int size = mListeners.size(); + for (int i = 0; i < size; i++) { + Listener listener = mListeners.get(i); + try { + if (mNavigating) { + listener.mListener.onGpsStarted(); + } else { + listener.mListener.onGpsStopped(); } + } catch (RemoteException e) { + Log.w(TAG, "RemoteException in reportStatus"); + mListeners.remove(listener); + // adjust for size of list changing + size--; } } @@ -924,8 +969,13 @@ public class GpsLocationProvider extends ILocationProvider.Stub { int result = mConnMgr.startUsingNetworkFeature( ConnectivityManager.TYPE_MOBILE, Phone.FEATURE_ENABLE_SUPL); if (result == Phone.APN_ALREADY_ACTIVE) { - native_agps_data_conn_open(mAGpsApn); - mAGpsDataConnectionState = AGPS_DATA_CONNECTION_OPEN; + if (mAGpsApn != null) { + native_agps_data_conn_open(mAGpsApn); + mAGpsDataConnectionState = AGPS_DATA_CONNECTION_OPEN; + } else { + Log.e(TAG, "mAGpsApn not set when receiving Phone.APN_ALREADY_ACTIVE"); + native_agps_data_conn_failed(); + } } else if (result == Phone.APN_REQUEST_STARTED) { mAGpsDataConnectionState = AGPS_DATA_CONNECTION_OPENING; } else { @@ -959,29 +1009,6 @@ public class GpsLocationProvider extends ILocationProvider.Stub { } } - private boolean setAGpsServer(int type, String host, int port) { - try { - InetAddress inetAddress = InetAddress.getByName(host); - if (inetAddress != null) { - byte[] addrBytes = inetAddress.getAddress(); - long addr = 0; - for (int i = 0; i < addrBytes.length; i++) { - int temp = addrBytes[i]; - // signed -> unsigned - if (temp < 0) temp = 256 + temp; - addr = addr * 256 + temp; - } - // use MS-Based position mode if SUPL support is enabled - mPositionMode = GPS_POSITION_MODE_MS_BASED; - native_set_agps_server(type, (int)addr, port); - } - } catch (UnknownHostException e) { - Log.e(TAG, "unknown host for server " + host); - return false; - } - return true; - } - private class GpsEventThread extends Thread { public GpsEventThread() { @@ -1004,6 +1031,7 @@ public class GpsLocationProvider extends ILocationProvider.Stub { private long mNextNtpTime = 0; private long mNextXtraTime = 0; + private boolean mTimeInjectRequested = false; private boolean mXtraDownloadRequested = false; private boolean mDone = false; @@ -1054,16 +1082,17 @@ public class GpsLocationProvider extends ILocationProvider.Stub { } waitTime = getWaitTime(); } while (!mDone && ((!mXtraDownloadRequested && - !mSetSuplServer && !mSetC2KServer && waitTime > 0) + !mTimeInjectRequested && waitTime > 0) || !mNetworkAvailable)); if (Config.LOGD) Log.d(TAG, "NetworkThread out of wake loop"); if (!mDone) { if (mNtpServer != null && - mNextNtpTime <= System.currentTimeMillis()) { + (mTimeInjectRequested || mNextNtpTime <= System.currentTimeMillis())) { if (Config.LOGD) { Log.d(TAG, "Requesting time from NTP server " + mNtpServer); } + mTimeInjectRequested = false; if (client.requestTime(mNtpServer, 10000)) { long time = client.getNtpTime(); long timeReference = client.getNtpTimeReference(); @@ -1081,21 +1110,10 @@ public class GpsLocationProvider extends ILocationProvider.Stub { } } - // Set the AGPS server addresses if we have not yet - if (mSetSuplServer) { - if (setAGpsServer(AGPS_TYPE_SUPL, mSuplHost, mSuplPort)) { - mSetSuplServer = false; - } - } - if (mSetC2KServer) { - if (setAGpsServer(AGPS_TYPE_C2K, mC2KHost, mC2KPort)) { - mSetC2KServer = false; - } - } - if ((mXtraDownloadRequested || (mNextXtraTime > 0 && mNextXtraTime <= System.currentTimeMillis())) && xtraDownloader != null) { + mXtraDownloadRequested = false; byte[] data = xtraDownloader.downloadXtraData(); if (data != null) { if (Config.LOGD) { @@ -1103,7 +1121,6 @@ public class GpsLocationProvider extends ILocationProvider.Stub { } native_inject_xtra_data(data, data.length); mNextXtraTime = 0; - mXtraDownloadRequested = false; } else { mNextXtraTime = System.currentTimeMillis() + RETRY_INTERVAL; } @@ -1118,6 +1135,11 @@ public class GpsLocationProvider extends ILocationProvider.Stub { notify(); } + synchronized void timeInjectRequest() { + mTimeInjectRequested = true; + notify(); + } + synchronized void signal() { notify(); } @@ -1177,7 +1199,8 @@ public class GpsLocationProvider extends ILocationProvider.Stub { // mask[0] is ephemeris mask and mask[1] is almanac mask private native int native_read_sv_status(int[] svs, float[] snrs, float[] elevations, float[] azimuths, int[] masks); - + private native void native_inject_location(double latitude, double longitude, float accuracy); + // XTRA Support private native void native_inject_time(long time, long timeReference, int uncertainty); private native boolean native_supports_xtra(); @@ -1187,5 +1210,5 @@ public class GpsLocationProvider extends ILocationProvider.Stub { private native void native_agps_data_conn_open(String apn); private native void native_agps_data_conn_closed(); private native void native_agps_data_conn_failed(); - private native void native_set_agps_server(int type, int addr, int port); + private native void native_set_agps_server(int type, String hostname, int port); } diff --git a/location/java/com/android/internal/location/LocationProviderProxy.java b/location/java/com/android/internal/location/LocationProviderProxy.java index b40cdca..4ae424a 100644 --- a/location/java/com/android/internal/location/LocationProviderProxy.java +++ b/location/java/com/android/internal/location/LocationProviderProxy.java @@ -53,6 +53,12 @@ public class LocationProviderProxy implements IBinder.DeathRecipient { } } + public void unlinkProvider() { + if (mProvider != null) { + mProvider.asBinder().unlinkToDeath(this, 0); + } + } + public String getName() { return mName; } @@ -219,6 +225,14 @@ public class LocationProviderProxy implements IBinder.DeathRecipient { } } + public void updateLocation(Location location) { + try { + mProvider.updateLocation(location); + } catch (RemoteException e) { + Log.e(TAG, "updateLocation failed", e); + } + } + public boolean sendExtraCommand(String command, Bundle extras) { try { return mProvider.sendExtraCommand(command, extras); @@ -247,5 +261,6 @@ public class LocationProviderProxy implements IBinder.DeathRecipient { public void binderDied() { Log.w(TAG, "Location Provider " + mName + " died"); mDead = true; + mProvider.asBinder().unlinkToDeath(this, 0); } } diff --git a/location/java/com/android/internal/location/MockProvider.java b/location/java/com/android/internal/location/MockProvider.java index f167a44..e2e0562 100644 --- a/location/java/com/android/internal/location/MockProvider.java +++ b/location/java/com/android/internal/location/MockProvider.java @@ -172,6 +172,9 @@ public class MockProvider extends ILocationProvider.Stub { public void updateNetworkState(int state) { } + public void updateLocation(Location location) { + } + public boolean sendExtraCommand(String command, Bundle extras) { return false; } |