diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-01-09 17:51:23 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-01-09 17:51:23 -0800 |
commit | b798689749c64baba81f02e10cf2157c747d6b46 (patch) | |
tree | da394a395ddb1a6cf69193314846b03fe47a397e /location | |
parent | f013e1afd1e68af5e3b868c26a653bbfb39538f8 (diff) | |
download | frameworks_base-b798689749c64baba81f02e10cf2157c747d6b46.zip frameworks_base-b798689749c64baba81f02e10cf2157c747d6b46.tar.gz frameworks_base-b798689749c64baba81f02e10cf2157c747d6b46.tar.bz2 |
auto import from //branches/cupcake/...@125939
Diffstat (limited to 'location')
4 files changed, 74 insertions, 26 deletions
diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java index 7c47081..3d4d4a2 100644 --- a/location/java/com/android/internal/location/GpsLocationProvider.java +++ b/location/java/com/android/internal/location/GpsLocationProvider.java @@ -147,6 +147,7 @@ public class GpsLocationProvider extends LocationProviderImpl { // properties loaded from PROPERTIES_FILE private Properties mProperties; + private String mNtpServer; private Context mContext; private Location mLocation = new Location(LocationManager.GPS_PROVIDER); @@ -179,6 +180,7 @@ public class GpsLocationProvider extends LocationProviderImpl { FileInputStream stream = new FileInputStream(file); mProperties.load(stream); stream.close(); + mNtpServer = mProperties.getProperty("NTP_SERVER", null); } catch (IOException e) { Log.e(TAG, "Could not open GPS configuration file " + PROPERTIES_FILE, e); } @@ -192,7 +194,7 @@ public class GpsLocationProvider extends LocationProviderImpl { public boolean requiresNetwork() { // We want updateNetworkState() to get called when the network state changes // for XTRA and NTP time injection support. - return true; + return (mNtpServer != null || native_supports_xtra()); } public void updateNetworkState(int state) { @@ -308,12 +310,14 @@ public class GpsLocationProvider extends LocationProviderImpl { mEventThread = new GpsEventThread(); mEventThread.start(); - // run network thread for NTP and XTRA support - if (mNetworkThread == null) { - mNetworkThread = new GpsNetworkThread(); - mNetworkThread.start(); - } else { - mNetworkThread.signal(); + if (requiresNetwork()) { + // run network thread for NTP and XTRA support + if (mNetworkThread == null) { + mNetworkThread = new GpsNetworkThread(); + mNetworkThread.start(); + } else { + mNetworkThread.signal(); + } } } else { Log.w(TAG, "Failed to enable location provider"); @@ -560,7 +564,7 @@ public class GpsLocationProvider extends LocationProviderImpl { mLastFixTime = System.currentTimeMillis(); // report time to first fix - if (mTTFF == 0) { + if (mTTFF == 0 && (flags & LOCATION_HAS_LAT_LONG) == LOCATION_HAS_LAT_LONG) { mTTFF = (int)(mLastFixTime - mFixRequestTime); if (Config.LOGD) Log.d(TAG, "TTFF: " + mTTFF); @@ -763,25 +767,34 @@ public class GpsLocationProvider extends LocationProviderImpl { synchronized (this) { try { if (!mNetworkAvailable) { - if (Config.LOGD) Log.d(TAG, "NetworkThread wait for network"); + if (Config.LOGD) Log.d(TAG, + "NetworkThread wait for network"); wait(); } else if (waitTime > 0) { - if (Config.LOGD) Log.d(TAG, "NetworkThread wait for " + waitTime + "ms"); + if (Config.LOGD) { + Log.d(TAG, "NetworkThread wait for " + + waitTime + "ms"); + } wait(waitTime); } } catch (InterruptedException e) { - if (Config.LOGD) Log.d(TAG, "InterruptedException in GpsNetworkThread"); + if (Config.LOGD) { + Log.d(TAG, "InterruptedException in GpsNetworkThread"); + } } } waitTime = getWaitTime(); - } while (mEnabled && ((!mXtraDownloadRequested && waitTime > 0) || !mNetworkAvailable)); + } while (mEnabled && ((!mXtraDownloadRequested && waitTime > 0) + || !mNetworkAvailable)); if (Config.LOGD) Log.d(TAG, "NetworkThread out of wake loop"); if (mEnabled) { - if (mNextNtpTime <= System.currentTimeMillis()) { - String ntpServer = mProperties.getProperty("NTP_SERVER", "pool.ntp.org"); - if (Config.LOGD) Log.d(TAG, "Requesting time from NTP server " + ntpServer); - if (client.requestTime(ntpServer, 10000)) { + if (mNtpServer != null && + mNextNtpTime <= System.currentTimeMillis()) { + if (Config.LOGD) { + Log.d(TAG, "Requesting time from NTP server " + mNtpServer); + } + if (client.requestTime(mNtpServer, 10000)) { long time = client.getNtpTime(); long timeReference = client.getNtpTimeReference(); int certainty = (int)(client.getRoundTripTime()/2); @@ -799,11 +812,13 @@ public class GpsLocationProvider extends LocationProviderImpl { } if ((mXtraDownloadRequested || - (mNextXtraTime > 0 && mNextXtraTime <= System.currentTimeMillis())) && - xtraDownloader != null) { + (mNextXtraTime > 0 && mNextXtraTime <= System.currentTimeMillis())) + && xtraDownloader != null) { byte[] data = xtraDownloader.downloadXtraData(); if (data != null) { - if (Config.LOGD) Log.d(TAG, "calling native_inject_xtra_data"); + if (Config.LOGD) { + Log.d(TAG, "calling native_inject_xtra_data"); + } native_inject_xtra_data(data, data.length); mNextXtraTime = 0; mXtraDownloadRequested = false; @@ -827,7 +842,10 @@ public class GpsLocationProvider extends LocationProviderImpl { private long getWaitTime() { long now = System.currentTimeMillis(); - long waitTime = mNextNtpTime - now; + long waitTime = Long.MAX_VALUE; + if (mNtpServer != null) { + waitTime = mNextNtpTime - now; + } if (mNextXtraTime != 0) { long xtraWaitTime = mNextXtraTime - now; if (xtraWaitTime < waitTime) { diff --git a/location/java/com/android/internal/location/GpsXtraDownloader.java b/location/java/com/android/internal/location/GpsXtraDownloader.java index 6efbbf6..b8545a6 100644 --- a/location/java/com/android/internal/location/GpsXtraDownloader.java +++ b/location/java/com/android/internal/location/GpsXtraDownloader.java @@ -28,10 +28,12 @@ import org.apache.http.conn.params.ConnRouteParams; import java.io.DataInputStream; import java.io.IOException; import java.util.Properties; +import java.util.Random; import android.content.Context; import android.net.Proxy; import android.net.http.AndroidHttpClient; +import android.util.Config; import android.util.Log; /** @@ -46,7 +48,7 @@ public class GpsXtraDownloader { private Context mContext; private String[] mXtraServers; // to load balance our server requests - private int mNextServerIndex = 0; + private int mNextServerIndex; GpsXtraDownloader(Context context, Properties properties) { mContext = context; @@ -69,6 +71,10 @@ public class GpsXtraDownloader { if (server2 != null) mXtraServers[count++] = server2; if (server3 != null) mXtraServers[count++] = server3; } + + // randomize first server + Random random = new Random(); + mNextServerIndex = random.nextInt(count); } byte[] downloadXtraData() { @@ -100,6 +106,8 @@ public class GpsXtraDownloader { protected static byte[] doDownload(String url, boolean isProxySet, String proxyHost, int proxyPort) { + if (Config.LOGD) Log.d(TAG, "Downloading XTRA data from " + url); + AndroidHttpClient client = null; try { client = AndroidHttpClient.newInstance("Android"); @@ -121,7 +129,7 @@ public class GpsXtraDownloader { HttpResponse response = client.execute(req); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) { // HTTP 200 is success. - Log.d(TAG, "HTTP error: " + status.getReasonPhrase()); + if (Config.LOGD) Log.d(TAG, "HTTP error: " + status.getReasonPhrase()); return null; } @@ -150,7 +158,7 @@ public class GpsXtraDownloader { } return body; } catch (Exception e) { - Log.d(TAG, "error " + e); + if (Config.LOGD) Log.d(TAG, "error " + e); } finally { if (client != null) { client.close(); diff --git a/location/java/com/android/internal/location/LocationCache.java b/location/java/com/android/internal/location/LocationCache.java index 545d8c9..079c9c7 100644 --- a/location/java/com/android/internal/location/LocationCache.java +++ b/location/java/com/android/internal/location/LocationCache.java @@ -103,6 +103,12 @@ public class LocationCache { cellState.getLac(), cellState.getCid()); Record record = mCellCache.lookup(primaryCellKey); + // Relax MCC/MNC condition + if (record == null) { + primaryCellKey = getCellCacheKey(-1, -1, cellState.getLac(), cellState.getCid()); + record = mCellCache.lookup(primaryCellKey); + } + if (record == null) { // Make a server request if primary cell doesn't exist in DB return false; @@ -121,6 +127,14 @@ public class LocationCache { String historicalCellKey = getCellCacheKey(historicalCell.getMcc(), historicalCell.getMnc(), historicalCell.getLac(), historicalCell.getCid()); Record record = mCellCache.lookup(historicalCellKey); + + // Relax MCC/MNC condition + if (record == null) { + historicalCellKey = getCellCacheKey(-1, -1, historicalCell.getLac(), + historicalCell.getCid()); + record = mCellCache.lookup(historicalCellKey); + } + if (record != null && record.isValid()) { mCellCentroid.addLocation(record.getLat(), record.getLng(), record.getAccuracy(), record.getConfidence()); @@ -561,7 +575,6 @@ public class LocationCache { double cLng = getCentroidLng(); int meanDistanceSum = 0; - int meanRadiiSum = 0; int smallestCircle = MAX_ACCURACY_ALLOWED; int smallestCircleDistance = MAX_ACCURACY_ALLOWED; float[] distance = new float[1]; @@ -577,11 +590,10 @@ public class LocationCache { smallestCircle = mRadii[i]; smallestCircleDistance = (int)distance[0]; } - meanRadiiSum += mRadii[i]; } if (outlierExists) { - return (meanDistanceSum + meanRadiiSum)/mNumber; + return meanDistanceSum/mNumber; } else { return Math.max(smallestCircle, smallestCircleDistance); } diff --git a/location/java/com/android/internal/location/LocationMasfClient.java b/location/java/com/android/internal/location/LocationMasfClient.java index 4efcdd5..179c630 100644 --- a/location/java/com/android/internal/location/LocationMasfClient.java +++ b/location/java/com/android/internal/location/LocationMasfClient.java @@ -1167,6 +1167,10 @@ public class LocationMasfClient { private void addNeighborsToCellProfile(CellState cellState, ProtoBuf cellularProfile) { List<CellState.NeighborCell> neighbors = cellState.getNeighbors(); + + int mPrimaryMcc = cellState.getMcc(); + int mPrimaryMnc = cellState.getMnc(); + if (neighbors != null) { for (CellState.NeighborCell neighbor : neighbors) { ProtoBuf nCell = new ProtoBuf(GcellularMessageTypes.GCELL); @@ -1176,6 +1180,12 @@ public class LocationMasfClient { if (neighbor.getPsc() != -1) { nCell.setInt(GCell.PRIMARY_SCRAMBLING_CODE, neighbor.getPsc()); } + if (mPrimaryMcc != -1) { + nCell.setInt(GCell.MCC, mPrimaryMcc); + } + if (mPrimaryMnc != -1) { + nCell.setInt(GCell.MNC, mPrimaryMnc); + } cellularProfile.addProtoBuf(GCellularProfile.NEIGHBORS, nCell); } } |