diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-02-10 15:44:00 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-02-10 15:44:00 -0800 |
commit | d24b8183b93e781080b2c16c487e60d51c12da31 (patch) | |
tree | fbb89154858984eb8e41556da7e9433040d55cd4 /location | |
parent | f1e484acb594a726fb57ad0ae4cfe902c7f35858 (diff) | |
download | frameworks_base-d24b8183b93e781080b2c16c487e60d51c12da31.zip frameworks_base-d24b8183b93e781080b2c16c487e60d51c12da31.tar.gz frameworks_base-d24b8183b93e781080b2c16c487e60d51c12da31.tar.bz2 |
auto import from //branches/cupcake/...@130745
Diffstat (limited to 'location')
42 files changed, 191 insertions, 4111 deletions
diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java index c6f13c9..6672e29 100644 --- a/location/java/com/android/internal/location/GpsLocationProvider.java +++ b/location/java/com/android/internal/location/GpsLocationProvider.java @@ -164,16 +164,15 @@ public class GpsLocationProvider extends LocationProviderImpl { // current setting - 5 minutes private static final long RETRY_INTERVAL = 5*60*1000; - private LocationCollector mCollector; + private ILocationCollector mCollector; public static boolean isSupported() { return native_is_supported(); } - public GpsLocationProvider(Context context, LocationCollector collector) { + public GpsLocationProvider(Context context) { super(LocationManager.GPS_PROVIDER); mContext = context; - mCollector = collector; mProperties = new Properties(); try { @@ -183,10 +182,14 @@ public class GpsLocationProvider extends LocationProviderImpl { stream.close(); mNtpServer = mProperties.getProperty("NTP_SERVER", null); } catch (IOException e) { - Log.e(TAG, "Could not open GPS configuration file " + PROPERTIES_FILE, e); + Log.w(TAG, "Could not open GPS configuration file " + PROPERTIES_FILE); } } + public void setLocationCollector(ILocationCollector collector) { + mCollector = collector; + } + /** * Returns true if the provider requires access to a * data network (e.g., the Internet), false otherwise. @@ -623,7 +626,8 @@ public class GpsLocationProvider extends LocationProviderImpl { } // Send to collector - if ((flags & LOCATION_HAS_LAT_LONG) == LOCATION_HAS_LAT_LONG) { + if ((flags & LOCATION_HAS_LAT_LONG) == LOCATION_HAS_LAT_LONG + && mCollector != null) { mCollector.updateLocation(mLocation); } } @@ -644,7 +648,7 @@ public class GpsLocationProvider extends LocationProviderImpl { if (Config.LOGV) Log.v(TAG, "reportStatus status: " + status); boolean wasNavigating = mNavigating; - mNavigating = (status == GPS_STATUS_SESSION_BEGIN || status == GPS_STATUS_ENGINE_ON); + mNavigating = (status == GPS_STATUS_SESSION_BEGIN); if (wasNavigating != mNavigating) { synchronized(mListeners) { diff --git a/location/java/com/android/internal/location/ILocationCollector.java b/location/java/com/android/internal/location/ILocationCollector.java new file mode 100644 index 0000000..8a7cdcc --- /dev/null +++ b/location/java/com/android/internal/location/ILocationCollector.java @@ -0,0 +1,73 @@ +/* + * 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 com.android.internal.location; + +import android.location.Location; +import android.net.wifi.ScanResult; + +import com.android.internal.location.CellState; + +import java.util.List; + +/** + * 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} + */ +public interface ILocationCollector { + /** + * Updates GPS location if collection is enabled + * + * @param location location object + */ + abstract public void updateLocation(Location location); + + /** + * Updates wifi scan results if collection is enabled + * + * @param currentScanResults scan results + */ + abstract public void updateWifiScanResults(List<ScanResult> currentScanResults); + + /** + * Updates the status of the network location provider. + * + * @param enabled true if user has enabled network location based on Google's database + * of wifi points and cell towers. + */ + abstract public void updateNetworkProviderStatus(boolean enabled); + + /** + * Updates cell tower state. This is usually always up to date so should be uploaded + * each time a new location is available. + * + * @param newState cell state + */ + abstract public void updateCellState(CellState newState); + + /** + * Updates the battery health. Battery level is healthy if there is greater than + * {@link #MIN_BATTERY_LEVEL} percentage left or if the device is plugged in + * + * @param scale maximum scale for battery + * @param level current level + * @param plugged true if device is plugged in + */ + abstract public void updateBatteryState(int scale, int level, boolean plugged); +} diff --git a/location/java/com/android/internal/location/protocol/GCell.java b/location/java/com/android/internal/location/INetworkLocationManager.java index 21d1c48..83bbe1f 100644 --- a/location/java/com/android/internal/location/protocol/GCell.java +++ b/location/java/com/android/internal/location/INetworkLocationManager.java @@ -1,5 +1,5 @@ -/* - * Copyright (C) 2007 The Android Open Source Project + /* + * 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. @@ -14,16 +14,15 @@ * limitations under the License. */ -package com.android.internal.location.protocol; - -public interface GCell { - static final int LAC = 1; - static final int CELLID = 2; - static final int MNC = 3; - static final int MCC = 4; - static final int RSSI = 5; - static final int AGE = 6; - static final int TIMING_ADVANCE = 7; - static final int PRIMARY_SCRAMBLING_CODE = 8; -} +package com.android.internal.location; +/** + * Used to register network location and collection services + * with the Location Manager Service. + * + * {@hide} + */ +public interface INetworkLocationManager { + void setNetworkLocationProvider(INetworkLocationProvider provider); + void setLocationCollector(ILocationCollector collector); +}
\ No newline at end of file diff --git a/location/java/com/android/internal/location/INetworkLocationProvider.java b/location/java/com/android/internal/location/INetworkLocationProvider.java new file mode 100644 index 0000000..730cb48 --- /dev/null +++ b/location/java/com/android/internal/location/INetworkLocationProvider.java @@ -0,0 +1,95 @@ +/* + * 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 com.android.internal.location; + +import android.location.Address; +import android.location.Location; +import android.net.wifi.ScanResult; + +import com.google.common.io.protocol.ProtoBuf; + +import java.io.IOException; +import java.util.Collection; +import java.util.List; +import java.util.Locale; + +/** + * Interface for network location provider + * + * {@hide} + */ +public interface INetworkLocationProvider { + + public interface Callback { + + /** + * Callback function to notify of a received network location + * + * @param location location object that is received. may be null if not a valid location + * @param successful true if network query was successful, even if no location was found + */ + void locationReceived(Location location, boolean successful); + } + + /** + * Updates the current cell lock status. + * + * @param acquired true if a cell lock has been acquired + */ + abstract public void updateCellLockStatus(boolean acquired); + + /** + * Notifies the provider if Wifi has been enabled or disabled + * by the user + * + * @param enabled true if wifi is enabled; false otherwise + */ + abstract public void updateWifiEnabledState(boolean enabled); + + /** + * Notifies the provider that there are scan results available. + * + * @param scanResults list of wifi scan results + */ + abstract public void updateWifiScanResults(List<ScanResult> scanResults); + + /** + * Adds a list of application clients + * Only used by the NetworkLocationProvider + * + * @param applications list of package names + */ + abstract public void addListener(String[] applications); + + /** + * Removes a list of application clients + * Only used by the NetworkLocationProvider + * + * @param applications list of package names + */ + abstract public void removeListener(String[] applications); + + + abstract public String getFromLocation(double latitude, double longitude, int maxResults, + String language, String country, String variant, String appName, List<Address> addrs); + + abstract 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); + +} diff --git a/location/java/com/android/internal/location/LocationCache.java b/location/java/com/android/internal/location/LocationCache.java deleted file mode 100644 index 079c9c7..0000000 --- a/location/java/com/android/internal/location/LocationCache.java +++ /dev/null @@ -1,608 +0,0 @@ -// Copyright 2007 The Android Open Source Project - -package com.android.internal.location; - -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.DataOutput; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import android.location.Location; -import android.location.LocationManager; -import android.net.wifi.ScanResult; -import android.os.Bundle; -import android.util.Log; - -/** - * Data store to cache cell-id and wifi locations from the network - * - * {@hide} - */ -public class LocationCache { - private static final String TAG = "LocationCache"; - - // Version of cell cache - private static final int CACHE_DB_VERSION = 1; - - // Don't save cache more than once every minute - private static final long SAVE_FREQUENCY = 60 * 1000; - - // Location of the cache file; - private static final String mCellCacheFile = "cache.cell"; - private static final String mWifiCacheFile = "cache.wifi"; - - // Maximum time (in millis) that a record is valid for, before it needs - // to be refreshed from the server. - private static final long MAX_CELL_REFRESH_RECORD_AGE = 12 * 60 * 60 * 1000; // 12 hours - private static final long MAX_WIFI_REFRESH_RECORD_AGE = 48 * 60 * 60 * 1000; // 48 hours - - // Cache sizes - private static final int MAX_CELL_RECORDS = 50; - private static final int MAX_WIFI_RECORDS = 200; - - // Cache constants - private static final long CELL_SMOOTHING_WINDOW = 30 * 1000; // 30 seconds - private static final int WIFI_MIN_AP_REQUIRED = 2; - private static final int WIFI_MAX_MISS_ALLOWED = 5; - private static final int MAX_ACCURACY_ALLOWED = 5000; // 5km - - // Caches - private final Cache<Record> mCellCache; - private final Cache<Record> mWifiCache; - - // Currently calculated centroids - private final LocationCentroid mCellCentroid = new LocationCentroid(); - private final LocationCentroid mWifiCentroid = new LocationCentroid(); - - // Extra key and values - private final String EXTRA_KEY_LOCATION_TYPE = "networkLocationType"; - private final String EXTRA_VALUE_LOCATION_TYPE_CELL = "cell"; - private final String EXTRA_VALUE_LOCATION_TYPE_WIFI = "wifi"; - - public LocationCache() { - mCellCache = new Cache<Record>(LocationManager.SYSTEM_DIR, mCellCacheFile, - MAX_CELL_RECORDS, MAX_CELL_REFRESH_RECORD_AGE); - mWifiCache = new Cache<Record>(LocationManager.SYSTEM_DIR, mWifiCacheFile, - MAX_WIFI_RECORDS, MAX_WIFI_REFRESH_RECORD_AGE); - } - - /** - * Looks up network location on device cache - * - * @param cellState primary cell state - * @param cellHistory history of cell states - * @param scanResults wifi scan results - * @param result location object to fill if location is found - * @return true if cache was able to answer query (successfully or not), false if call to - * server is required - */ - public synchronized boolean lookup(CellState cellState, List<CellState> cellHistory, - List<ScanResult> scanResults, Location result) { - - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.d(TAG, "including cell:" + (cellState != null) + - ", wifi:" + ((scanResults != null)? scanResults.size() : "null")); - } - - long now = System.currentTimeMillis(); - - mCellCentroid.reset(); - mWifiCentroid.reset(); - - if (cellState != null && cellState.isValid()) { - String primaryCellKey = getCellCacheKey(cellState.getMcc(), cellState.getMnc(), - 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; - } - - if (record.isValid()) { - mCellCentroid.addLocation(record.getLat(), record.getLng(), record.getAccuracy(), - record.getConfidence()); - } - } - - if (cellHistory != null) { - for (CellState historicalCell : cellHistory) { - // Cell location might need to be smoothed if you are on the border of two cells - if (now - historicalCell.getTime() < CELL_SMOOTHING_WINDOW) { - 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()); - } - } - } - } - - if (scanResults != null) { - int miss = 0; - for (ScanResult scanResult : scanResults) { - String wifiKey = scanResult.BSSID; - Record record = mWifiCache.lookup(wifiKey); - if (record == null) { - miss++; - } else { - if (record.isValid()) { - mWifiCentroid.addLocation(record.getLat(), record.getLng(), - record.getAccuracy(), record.getConfidence()); - } - } - } - - if (mWifiCentroid.getNumber() >= WIFI_MIN_AP_REQUIRED) { - // Try to return best out of the available cell or wifi location - } else if (miss > Math.min(WIFI_MAX_MISS_ALLOWED, (scanResults.size()+1)/2)) { - // Make a server request - return false; - } else { - // Don't use wifi location, only consider using cell location - mWifiCache.save(); - mWifiCentroid.reset(); - } - } - - if (mCellCentroid.getNumber() > 0) { - mCellCache.save(); - } - if (mWifiCentroid.getNumber() > 0) { - mWifiCache.save(); - } - - int cellAccuracy = mCellCentroid.getAccuracy(); - int wifiAccuracy = mWifiCentroid.getAccuracy(); - - int cellConfidence = mCellCentroid.getConfidence(); - int wifiConfidence = mWifiCentroid.getConfidence(); - - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.d(TAG, "cellAccuracy:" + cellAccuracy+ ", wifiAccuracy:" + wifiAccuracy); - } - - if ((mCellCentroid.getNumber() == 0 || cellAccuracy > MAX_ACCURACY_ALLOWED) && - (mWifiCentroid.getNumber() == 0 || wifiAccuracy > MAX_ACCURACY_ALLOWED)) { - // Return invalid location if neither location is valid - result.setAccuracy(-1); - - // don't make server request - return true; - } - - float[] distance = new float[1]; - Location.distanceBetween(mCellCentroid.getCentroidLat(), mCellCentroid.getCentroidLng(), - mWifiCentroid.getCentroidLat(), mWifiCentroid.getCentroidLng(), - distance); - - boolean consistent = distance[0] <= (cellAccuracy + wifiAccuracy); - - boolean useCell = true; - - if (consistent) { - // If consistent locations, use one with greater accuracy - useCell = (cellAccuracy <= wifiAccuracy); - } else { - // If inconsistent locations, use one with greater confidence - useCell = (cellConfidence >= wifiConfidence); - } - - if (useCell) { - // Use cell results - result.setAccuracy(cellAccuracy); - result.setLatitude(mCellCentroid.getCentroidLat()); - result.setLongitude(mCellCentroid.getCentroidLng()); - result.setTime(now); - - Bundle extras = result.getExtras() == null ? new Bundle() : result.getExtras(); - extras.putString(EXTRA_KEY_LOCATION_TYPE, EXTRA_VALUE_LOCATION_TYPE_CELL); - result.setExtras(extras); - - } else { - // Use wifi results - result.setAccuracy(wifiAccuracy); - result.setLatitude(mWifiCentroid.getCentroidLat()); - result.setLongitude(mWifiCentroid.getCentroidLng()); - result.setTime(now); - - Bundle extras = result.getExtras() == null ? new Bundle() : result.getExtras(); - extras.putString(EXTRA_KEY_LOCATION_TYPE, EXTRA_VALUE_LOCATION_TYPE_WIFI); - result.setExtras(extras); - - } - - // don't make a server request - return true; - } - - public synchronized void insert(int mcc, int mnc, int lac, int cid, double lat, double lng, - int accuracy, int confidence, long time) { - String key = getCellCacheKey(mcc, mnc, lac, cid); - if (accuracy <= 0) { - mCellCache.insert(key, new Record()); - } else { - mCellCache.insert(key, new Record(accuracy, confidence, lat, lng, time)); - } - } - - public synchronized void insert(String bssid, double lat, double lng, int accuracy, - int confidence, long time) { - if (accuracy <= 0) { - mWifiCache.insert(bssid, new Record()); - } else { - mWifiCache.insert(bssid, new Record(accuracy, confidence, lat, lng, time)); - } - } - - public synchronized void save() { - mCellCache.save(); - mWifiCache.save(); - } - - /** - * Cell or Wifi location record - */ - public static class Record { - - private final double lat; - private final double lng; - private final int accuracy; - private final int confidence; - - // Time (since the epoch) of original reading. - private final long originTime; - - public static Record read(DataInput dataInput) throws IOException { - final int accuracy = dataInput.readInt(); - final int confidence = dataInput.readInt(); - final double lat = dataInput.readDouble(); - final double lng = dataInput.readDouble(); - final long readingTime = dataInput.readLong(); - return new Record(accuracy, confidence, lat, lng, readingTime); - } - - /** - * Creates an "invalid" record indicating there was no location data - * available for the given data - */ - public Record() { - this(-1, 0, 0, 0, System.currentTimeMillis()); - } - - /** - * Creates a Record - * - * @param accuracy acuracy in meters. If < 0, then this is an invalid record. - * @param confidence confidence (0-100) - * @param lat latitude - * @param lng longitude - * @param time Time of the original location reading from the server - */ - public Record(int accuracy, int confidence, double lat, double lng, long time) { - this.accuracy = accuracy; - this.confidence = confidence; - this.originTime = time; - this.lat = lat; - this.lng = lng; - } - - public double getLat() { - return lat; - } - - public double getLng() { - return lng; - } - - public int getAccuracy() { - return accuracy; - } - - public int getConfidence() { - return confidence; - } - - public boolean isValid() { - return accuracy > 0; - } - - public long getTime() { - return originTime; - } - - public void write(DataOutput dataOut) throws IOException { - dataOut.writeInt(accuracy); - dataOut.writeInt(confidence); - dataOut.writeDouble(lat); - dataOut.writeDouble(lng); - dataOut.writeLong(originTime); - } - - @Override - public String toString() { - return lat + "," + lng + "," + originTime +"," + accuracy + "," + confidence; - } - } - - public class Cache<T> extends LinkedHashMap { - private final long mMaxAge; - private final int mCapacity; - private final String mDir; - private final String mFile; - private long mLastSaveTime = 0; - - public Cache(String dir, String file, int capacity, long maxAge) { - super(capacity + 1, 1.1f, true); - this.mCapacity = capacity; - this.mDir = dir; - this.mFile = file; - this.mMaxAge = maxAge; - load(); - } - - private LocationCache.Record lookup(String key) { - LocationCache.Record result = (LocationCache.Record) get(key); - - if (result == null) { - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.d(TAG, "lookup: " + key + " failed"); - } - return null; - } - - // Cache entry needs refresh - if (result.getTime() + mMaxAge < System.currentTimeMillis()) { - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.d(TAG, "lookup: " + key + " expired"); - } - return null; - } - - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.d(TAG, "lookup: " + key + " " + result.toString()); - } - - return result; - } - - private void insert(String key, LocationCache.Record record) { - remove(key); - put(key, record); - - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.d(TAG, "insert: " + key + " " + record.toString()); - } - } - - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - // Remove cache entries when it has more than capacity - return size() > mCapacity; - } - - private void load() { - FileInputStream istream; - try { - File f = new File(mDir, mFile); - istream = new FileInputStream(f); - } catch (FileNotFoundException e) { - // No existing DB - return new CellCache - return; - } - - DataInputStream dataInput = new DataInputStream(istream); - - try { - int version = dataInput.readUnsignedShort(); - if (version != CACHE_DB_VERSION) { - // Ignore records - invalid version ID. - dataInput.close(); - return; - } - int records = dataInput.readUnsignedShort(); - - for (int i = 0; i < records; i++) { - final String key = dataInput.readUTF(); - final LocationCache.Record record = LocationCache.Record.read(dataInput); - //Log.d(TAG, key + " " + record.toString()); - put(key, record); - } - - dataInput.close(); - } catch (IOException e) { - // Something's corrupted - return a new CellCache - } - } - - private void save() { - long now = System.currentTimeMillis(); - if (mLastSaveTime != 0 && (now - mLastSaveTime < SAVE_FREQUENCY)) { - // Don't save to file more often than SAVE_FREQUENCY - return; - } - - FileOutputStream ostream; - - File systemDir = new File(mDir); - if (!systemDir.exists()) { - if (!systemDir.mkdirs()) { - Log.e(TAG, "Cache.save(): couldn't create directory"); - return; - } - } - - try { - File f = new File(mDir, mFile); - ostream = new FileOutputStream(f); - } catch (FileNotFoundException e) { - Log.d(TAG, "Cache.save(): unable to create cache file", e); - return; - } - - DataOutputStream dataOut = new DataOutputStream(ostream); - try { - dataOut.writeShort(CACHE_DB_VERSION); - - dataOut.writeShort(size()); - - for (Iterator iter = entrySet().iterator(); iter.hasNext();) { - Map.Entry entry = (Map.Entry) iter.next(); - String key = (String) entry.getKey(); - LocationCache.Record record = (LocationCache.Record) entry.getValue(); - dataOut.writeUTF(key); - record.write(dataOut); - } - - dataOut.close(); - mLastSaveTime = now; - - } catch (IOException e) { - Log.e(TAG, "Cache.save(): unable to write cache", e); - // This should never happen - } - } - } - - public class LocationCentroid { - - double mLatSum = 0; - double mLngSum = 0; - int mNumber = 0; - int mConfidence = 0; - - double mCentroidLat = 0; - double mCentroidLng = 0; - - // Probably never have to calculate centroid for more than 10 locations - final static int MAX_SIZE = 10; - double[] mLats = new double[MAX_SIZE]; - double[] mLngs = new double[MAX_SIZE]; - int[] mRadii = new int[MAX_SIZE]; - - LocationCentroid() { - reset(); - } - - public void reset() { - mLatSum = 0; - mLngSum = 0; - mNumber = 0; - mConfidence = 0; - - mCentroidLat = 0; - mCentroidLng = 0; - - for (int i = 0; i < MAX_SIZE; i++) { - mLats[i] = 0; - mLngs[i] = 0; - mRadii[i] = 0; - } - } - - public void addLocation(double lat, double lng, int accuracy, int confidence) { - if (mNumber < MAX_SIZE && accuracy <= MAX_ACCURACY_ALLOWED) { - mLatSum += lat; - mLngSum += lng; - if (confidence > mConfidence) { - mConfidence = confidence; - } - - mLats[mNumber] = lat; - mLngs[mNumber] = lng; - mRadii[mNumber] = accuracy; - mNumber++; - } - } - - public int getNumber() { - return mNumber; - } - - public double getCentroidLat() { - if (mCentroidLat == 0 && mNumber != 0) { - mCentroidLat = mLatSum/mNumber; - } - return mCentroidLat; - } - - public double getCentroidLng() { - if (mCentroidLng == 0 && mNumber != 0) { - mCentroidLng = mLngSum/mNumber; - } - return mCentroidLng; - } - - public int getConfidence() { - return mConfidence; - } - - public int getAccuracy() { - if (mNumber == 0) { - return 0; - } - - if (mNumber == 1) { - return mRadii[0]; - } - - double cLat = getCentroidLat(); - double cLng = getCentroidLng(); - - int meanDistanceSum = 0; - int smallestCircle = MAX_ACCURACY_ALLOWED; - int smallestCircleDistance = MAX_ACCURACY_ALLOWED; - float[] distance = new float[1]; - boolean outlierExists = false; - - for (int i = 0; i < mNumber; i++) { - Location.distanceBetween(cLat, cLng, mLats[i], mLngs[i], distance); - meanDistanceSum += (int)distance[0]; - if (distance[0] > mRadii[i]) { - outlierExists = true; - } - if (mRadii[i] < smallestCircle) { - smallestCircle = mRadii[i]; - smallestCircleDistance = (int)distance[0]; - } - } - - if (outlierExists) { - return meanDistanceSum/mNumber; - } else { - return Math.max(smallestCircle, smallestCircleDistance); - } - } - - } - - private String getCellCacheKey(int mcc, int mnc, int lac, int cid) { - return mcc + ":" + mnc + ":" + lac + ":" + cid; - } - -} diff --git a/location/java/com/android/internal/location/LocationCollector.java b/location/java/com/android/internal/location/LocationCollector.java deleted file mode 100644 index 39f432f..0000000 --- a/location/java/com/android/internal/location/LocationCollector.java +++ /dev/null @@ -1,499 +0,0 @@ -/* - * 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 com.android.internal.location; - -import com.android.internal.location.protocol.GDebugProfile; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; - -import android.location.Location; -import android.net.wifi.ScanResult; -import android.os.SystemClock; -import android.os.SystemProperties; -import android.util.Log; - -/** - * 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} - */ -public class LocationCollector { - - private static final String TAG = "LocationCollector"; - - // last location valid for 12 minutes - private static final long MIN_VALID_LOCATION_TIME = 12 * 60 * 1000L; - - // don't send wifi more than every 10 min - private static final long MIN_TIME_BETWEEN_WIFI_REPORTS = 10 * 60 * 1000L; - - // atleast 5 changed APs for wifi collection - private static final int MIN_CHANGED_WIFI_POINTS = 5; - - // don't collect if distance moved less than 200 meters - private static final int MIN_DISTANCE_BETWEEN_REPORTS = 200; - - // don't collect if battery level less than 20% - private static final double MIN_BATTERY_LEVEL = 0.2; - - // if battery level is greater than 90% and plugged in, collect more frequently - private static final double CHARGED_BATTERY_LEVEL = 0.9; - - // collect bursts every 15 minutes (running on battery) - private static final long BURST_REST_TIME_ON_BATTERY = 15 * 60 * 1000L; - - // collect bursts every 8 minutes (when plugged in) - private static final long BURST_REST_TIME_PLUGGED = 8 * 60 * 1000L; - - // collect burst samples every 12 seconds - private static final int BURST_MEASUREMENT_INTERVAL = 12 * 1000; - - // collect 11 burst samples before resting (11 samples every 12 seconds = 2 minute bursts) - private static final int BURST_NUM_SAMPLES = 11; - - // don't collect bursts if user in same loc for 2 bursts - private static final int MAX_BURSTS_FROM_SAME_LOCATION = 2; - - // don't send more than 2 bursts if user hasn't moved more than 25 meters - private static final int MIN_DISTANCE_BETWEEN_BURSTS = 25; - - // Cell State - private CellState mCellState = null; - private CellUploads mCellUploads = new CellUploads(); - - // GPS state - private Location mLastKnownLocation = null; - private Location mLastUploadedLocation = null; - private long mLastKnownLocationTime = 0; - private long mLastUploadedLocationTime = 0; - - // Burst state - private Location mLastBurstLocation = null; - private long mLastBurstEndTime = 0; - private long mCurrentBurstStartTime = 0; - private int mCurrentBurstNumSamples = 0; - private int mNumBurstsFromLastLocation = 0; - - // WiFi state - private List<ScanResult> mWifiLastScanResults = null; - private List<ScanResult> mWifiCurrentScanResults = null; - private long mLastWifiScanElapsedTime = 0; - private long mLastWifiScanRealTime = 0; - private boolean mWifiUploadedWithoutLocation = false; - - // Collection state - private boolean mNetworkProviderIsEnabled = true; - private boolean mBatteryLevelIsHealthy = true; - private boolean mBatteryChargedAndPlugged = false; - - // Location masf service - private LocationMasfClient mMasfClient; - - public LocationCollector(LocationMasfClient masfClient) { - mMasfClient = masfClient; - } - - /** - * Updates cell tower state. This is usually always up to date so should be uploaded - * each time a new location is available. - * - * @param newState cell state - */ - public synchronized void updateCellState(CellState newState) { - if (newState == null) { - throw new IllegalArgumentException("cell state is null"); - } - - if (!newState.isValid()) { - return; - } - - if (mCellState != null && mCellState.equals(newState)) { - return; - } - - mCellState = newState; - log("updateCellState(): Updated to " + mCellState.getCid() + "," + mCellState.getLac()); - - if (isCollectionEnabled()) { - addToQueue(GDebugProfile.TRIGGER_CELL_CHANGE); - } - } - - /** - * Updates GPS location if collection is enabled - * - * @param location location object - */ - public synchronized void updateLocation(Location location) { - - // Don't do anything if collection is disabled - if (!isCollectionEnabled()) { - return; - } - - long now = SystemClock.elapsedRealtime(); - - // Update last known location - if (mLastKnownLocation == null) { - mLastKnownLocation = new Location(location); - } else { - mLastKnownLocation.set(location); - } - mLastKnownLocationTime = now; - - // Burst rest time depends on battery state - long restTime = BURST_REST_TIME_ON_BATTERY; - if (mBatteryChargedAndPlugged) { - restTime = BURST_REST_TIME_PLUGGED; - } - - int trigger; - - // In burst mode if either first burst or enough time has passed since last burst - if (mLastBurstEndTime == 0 || (now - mLastBurstEndTime > restTime)) { - - // If location is too recent, then don't do anything! - if (now - mLastUploadedLocationTime < BURST_MEASUREMENT_INTERVAL) { - return; - } - - int distanceFromLastBurst = -1; - if (mLastBurstLocation != null) { - distanceFromLastBurst = (int) mLastBurstLocation.distanceTo(location); - - // Too many bursts from same location, don't upload - if (distanceFromLastBurst < MIN_DISTANCE_BETWEEN_BURSTS && - mNumBurstsFromLastLocation >= MAX_BURSTS_FROM_SAME_LOCATION) { - log("NO UPLOAD: Too many bursts from same location."); - return; - } - } - - if (mCurrentBurstStartTime == 0) { - // Start the burst! - mCurrentBurstStartTime = now; - mCurrentBurstNumSamples = 1; - trigger = GDebugProfile.TRIGGER_COLLECTION_START_BURST; - - } else if (now - mCurrentBurstStartTime > restTime) { - // Burst got old, start a new one - mCurrentBurstStartTime = now; - mCurrentBurstNumSamples = 1; - trigger = GDebugProfile.TRIGGER_COLLECTION_RESTART_BURST; - - } else if (mCurrentBurstNumSamples == BURST_NUM_SAMPLES - 1) { - // Finished a burst - mLastBurstEndTime = now; - mCurrentBurstStartTime = 0; - mCurrentBurstNumSamples = 0; - - // Make sure we don't upload too many bursts from same location - if (mLastBurstLocation == null) { - mLastBurstLocation = new Location(location); - mNumBurstsFromLastLocation = 1; - trigger = GDebugProfile.TRIGGER_COLLECTION_END_BURST; - - } else { - - if (distanceFromLastBurst != -1 && - distanceFromLastBurst < MIN_DISTANCE_BETWEEN_BURSTS) { - // User hasnt moved much from last location, keep track of count, - // don't update last burst loc - mNumBurstsFromLastLocation++; - trigger = GDebugProfile.TRIGGER_COLLECTION_END_BURST_AT_SAME_LOCATION; - - } else { - // User has moved enough, update last burst loc - mLastBurstLocation.set(location); - mNumBurstsFromLastLocation = 1; - trigger = GDebugProfile.TRIGGER_COLLECTION_END_BURST; - } - } - - } else { - // Increment burst sample count - mCurrentBurstNumSamples++; - trigger = GDebugProfile.TRIGGER_COLLECTION_CONTINUE_BURST; - } - - } else if (mLastUploadedLocation != null - && (mLastUploadedLocation.distanceTo(location) > MIN_DISTANCE_BETWEEN_REPORTS)) { - // If not in burst mode but has moved a reasonable distance, upload! - trigger = GDebugProfile.TRIGGER_COLLECTION_MOVED_DISTANCE; - - } else { - // Not in burst mode or hasn't moved enough - log("NO UPLOAD: Not in burst or moving mode. Resting for " + restTime + " ms"); - return; - } - - log("updateLocation(): Updated location with trigger " + trigger); - addToQueue(trigger); - } - - /** - * Updates wifi scan results if collection is enabled - * - * @param currentScanResults scan results - */ - public synchronized void updateWifiScanResults(List<ScanResult> currentScanResults) { - if (!isCollectionEnabled()) { - return; - } - - if (currentScanResults == null || currentScanResults.size() == 0) { - return; - } - - long now = SystemClock.elapsedRealtime(); - - // If wifi scan recently received, then don't upload - if ((mLastWifiScanElapsedTime != 0) - && ((now - mLastWifiScanElapsedTime) <= MIN_TIME_BETWEEN_WIFI_REPORTS)) { - return; - } - - if (mWifiCurrentScanResults == null) { - mWifiCurrentScanResults = new ArrayList<ScanResult>(); - } else { - mWifiCurrentScanResults.clear(); - } - mWifiCurrentScanResults.addAll(currentScanResults); - - // If wifi has changed enough - boolean wifiHasChanged = false; - - if (mWifiLastScanResults == null) { - wifiHasChanged = true; - } else { - // Calculate the number of new AP points received - HashSet<String> previous = new HashSet<String>(); - HashSet<String> current = new HashSet<String>(); - for (ScanResult s : mWifiLastScanResults) { - previous.add(s.BSSID); - } - for (ScanResult s : mWifiCurrentScanResults) { - current.add(s.BSSID); - } - current.removeAll(previous); - - if (current.size() > - Math.min(MIN_CHANGED_WIFI_POINTS, ((mWifiCurrentScanResults.size()+1)/2))) { - wifiHasChanged = true; - } - } - - if (!wifiHasChanged) { - log("updateWifiScanResults(): Wifi results haven't changed much"); - return; - } - - if (mWifiLastScanResults == null) { - mWifiLastScanResults = new ArrayList<ScanResult>(); - } else { - mWifiLastScanResults.clear(); - } - mWifiLastScanResults.addAll(mWifiCurrentScanResults); - - mLastWifiScanElapsedTime = now; - mLastWifiScanRealTime = System.currentTimeMillis(); - - log("updateWifiScanResults(): Updated " + mWifiLastScanResults.size() + " APs"); - addToQueue(GDebugProfile.TRIGGER_WIFI_CHANGE); - } - - /** - * Updates the status of the network location provider. - * - * @param enabled true if user has enabled network location based on Google's database - * of wifi points and cell towers. - */ - public void updateNetworkProviderStatus(boolean enabled) { - mNetworkProviderIsEnabled = enabled; - } - - /** - * Updates the battery health. Battery level is healthy if there is greater than - * {@link #MIN_BATTERY_LEVEL} percentage left or if the device is plugged in - * - * @param scale maximum scale for battery - * @param level current level - * @param plugged true if device is plugged in - */ - public void updateBatteryState(int scale, int level, boolean plugged) { - mBatteryLevelIsHealthy = (plugged || (level >= (MIN_BATTERY_LEVEL * scale))); - mBatteryChargedAndPlugged = (plugged && (level >= (CHARGED_BATTERY_LEVEL * scale))); - } - - /** - * Anonymous data collection is only enabled when the user has enabled the network - * location provider, i.e. is making use of the service and if the device battery level - * is healthy. - * - * Additionally, data collection will *never* happen if the system - * property ro.com.google.locationfeatures is not set. - * - * @return true if anonymous location collection is enabled - */ - private boolean isCollectionEnabled() { - // This class provides a Google-specific location feature, so it's enabled only - // when the system property ro.com.google.locationfeatures is set. - if (!SystemProperties.get("ro.com.google.locationfeatures").equals("1")) { - return false; - } - return mBatteryLevelIsHealthy && mNetworkProviderIsEnabled; - } - - /** - * Adds to the MASF request queue - * - * @param trigger the event that triggered this collection event - */ - private synchronized void addToQueue(int trigger) { - - long now = SystemClock.elapsedRealtime(); - - // Include location if: - // It has been received in the last 12 minutes. - boolean includeLocation = false; - if (mLastKnownLocation != null && - (now - mLastKnownLocationTime <= MIN_VALID_LOCATION_TIME)) { - includeLocation = true; - } - - // Include wifi if: - // Wifi is new OR - // Wifi is old but last wifi upload was without location - boolean includeWifi = false; - if (trigger == GDebugProfile.TRIGGER_WIFI_CHANGE || (mWifiUploadedWithoutLocation && - includeLocation && (now - mLastWifiScanElapsedTime < MIN_VALID_LOCATION_TIME))) { - includeWifi = true; - mWifiUploadedWithoutLocation = !includeLocation; - } - - // Include cell if: - // Wifi or location information is already being included - // The cell hasn't been uploaded with the same location recently - boolean includeCell = false; - - if (mCellState != null && (includeWifi || includeLocation)) { - includeCell = true; - - if (!includeWifi && includeLocation) { - if (mCellUploads.contains(mCellState, mLastKnownLocation)) { - includeCell = false; - } - } - } - - if (!includeLocation && !includeWifi) { - log("NO UPLOAD: includeLocation=false, includeWifi=false"); - return; - } else if (!includeCell && trigger == GDebugProfile.TRIGGER_CELL_CHANGE) { - log("NO UPLOAD: includeCell=false"); - return; - } else { - log("UPLOAD: includeLocation=" + includeLocation + ", includeWifi=" + - includeWifi + ", includeCell=" + includeCell); - } - - if (includeLocation) { - // Update last uploaded location - if (mLastUploadedLocation == null) { - mLastUploadedLocation = new Location(mLastKnownLocation); - } else { - mLastUploadedLocation.set(mLastKnownLocation); - } - mLastUploadedLocationTime = now; - } - - // Immediately send output if finishing a burst for live traffic requirements - boolean immediate = false; - if (trigger == GDebugProfile.TRIGGER_COLLECTION_END_BURST|| - trigger == GDebugProfile.TRIGGER_COLLECTION_END_BURST_AT_SAME_LOCATION) { - immediate = true; - } - - try { - CellState cell = includeCell ? mCellState : null; - List<ScanResult> wifi = includeWifi ? mWifiLastScanResults : null; - Location loc = includeLocation ? mLastUploadedLocation : null; - - mMasfClient.queueCollectionReport( - trigger, loc, cell, wifi, mLastWifiScanRealTime, immediate); - - } catch(Exception e) { - Log.e(TAG, "addToQueue got exception:", e); - } - } - - private class CellUploads { - - private final int MIN_DISTANCE = MIN_DISTANCE_BETWEEN_REPORTS / 4; // 50 meters - private final int SIZE = 5; - private final String[] cells = new String[SIZE]; - private final boolean[] valid = new boolean[SIZE]; - private final double[] latitudes = new double[SIZE]; - private final double[] longitudes = new double[SIZE]; - private final float[] distance = new float[1]; - private int index = 0; - - private CellUploads() { - for (int i = 0; i < SIZE; i++) { - valid[i] = false; - } - } - - private boolean contains(CellState cellState, Location loc) { - String cell = - cellState.getCid() + ":" + cellState.getLac() + ":" + - cellState.getMnc() + ":" + cellState.getMcc(); - double lat = loc.getLatitude(); - double lng = loc.getLongitude(); - - for (int i = 0; i < SIZE; i++) { - if (valid[i] && cells[i].equals(cell)) { - Location.distanceBetween(latitudes[i], longitudes[i], lat, lng, distance); - if (distance[0] < MIN_DISTANCE) { - return true; - } - } - } - cells[index] = cell; - latitudes[index] = lat; - longitudes[index] = lng; - valid[index] = true; - - index++; - if (index == SIZE) { - index = 0; - } - return false; - } - } - - private void log(String string) { - if (Log.isLoggable(TAG, Log.VERBOSE)) { - Log.d(TAG, string); - } - } -} diff --git a/location/java/com/android/internal/location/LocationMasfClient.java b/location/java/com/android/internal/location/LocationMasfClient.java deleted file mode 100644 index 179c630..0000000 --- a/location/java/com/android/internal/location/LocationMasfClient.java +++ /dev/null @@ -1,1194 +0,0 @@ -// Copyright 2008 The Android Open Source Project - -package com.android.internal.location; - -import com.google.common.Config; -import com.google.common.android.AndroidConfig; -import com.google.common.io.protocol.ProtoBuf; -import com.google.masf.MobileServiceMux; -import com.google.masf.ServiceCallback; -import com.google.masf.protocol.PlainRequest; -import com.google.masf.protocol.Request; - -import com.android.internal.location.protocol.GAddress; -import com.android.internal.location.protocol.GAddressComponent; -import com.android.internal.location.protocol.GAppProfile; -import com.android.internal.location.protocol.GCell; -import com.android.internal.location.protocol.GCellularPlatformProfile; -import com.android.internal.location.protocol.GCellularProfile; -import com.android.internal.location.protocol.GDebugProfile; -import com.android.internal.location.protocol.GDeviceLocation; -import com.android.internal.location.protocol.GFeature; -import com.android.internal.location.protocol.GGeocodeRequest; -import com.android.internal.location.protocol.GLatLng; -import com.android.internal.location.protocol.GLocReply; -import com.android.internal.location.protocol.GLocReplyElement; -import com.android.internal.location.protocol.GLocRequest; -import com.android.internal.location.protocol.GLocRequestElement; -import com.android.internal.location.protocol.GLocation; -import com.android.internal.location.protocol.GPlatformProfile; -import com.android.internal.location.protocol.GPrefetchMode; -import com.android.internal.location.protocol.GRectangle; -import com.android.internal.location.protocol.GWifiDevice; -import com.android.internal.location.protocol.GWifiProfile; -import com.android.internal.location.protocol.GcellularMessageTypes; -import com.android.internal.location.protocol.GdebugprofileMessageTypes; -import com.android.internal.location.protocol.GlatlngMessageTypes; -import com.android.internal.location.protocol.GlocationMessageTypes; -import com.android.internal.location.protocol.GrectangleMessageTypes; -import com.android.internal.location.protocol.GwifiMessageTypes; -import com.android.internal.location.protocol.LocserverMessageTypes; -import com.android.internal.location.protocol.ResponseCodes; - -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Locale; - -import android.content.Context; -import android.location.Address; -import android.location.Location; -import android.location.LocationManager; -import android.net.wifi.ScanResult; -import android.os.Build; -import android.os.Bundle; -import android.os.SystemClock; -import android.text.TextUtils; -import android.util.EventLog; -import android.util.Log; -import android.telephony.NeighboringCellInfo; - -/** - * Service to communicate to the Google Location Server (GLS) via MASF server - * - * {@hide} - */ -public class LocationMasfClient { - - static final String TAG = "LocationMasfClient"; - - // Address of the MASF server to connect to. - private static final String MASF_SERVER_ADDRESS = "http://www.google.com/loc/m/api"; - - // MobileServiceMux app/platform-specific values (application name matters!) - private static final String APPLICATION_NAME = "location"; - private static final String APPLICATION_VERSION = "1.0"; - private static final String PLATFORM_ID = "android"; - private static final String DISTRIBUTION_CHANNEL = "android"; - private static String PLATFORM_BUILD = null; - - // Methods exposed by the MASF server - private static final String REQUEST_QUERY_LOC = "g:loc/ql"; - private static final String REQUEST_UPLOAD_LOC = "g:loc/ul"; - - // Max time to wait for request to end - private static final long REQUEST_TIMEOUT = 5000; - - // Constant to divide Lat, Lng returned by server - private static final double E7 = 10000000.0; - - // Max wifi points to include - private static final int MAX_WIFI_TO_INCLUDE = 25; - - // Location of GLS cookie - private static final String PLATFORM_KEY_FILE = "gls.platform.key"; - private String mPlatformKey; - - // Cell cache - private LocationCache mLocationCache; - - // Location object that the cache manages - private Location mLocation = new Location(LocationManager.NETWORK_PROVIDER); - - // ProtoBuf objects we can reuse for subsequent requests - private final int MAX_COLLECTION_BUFFER_SIZE = 30; - private final long MIN_COLLECTION_INTERVAL = 15 * 60 * 1000; // 15 minutes - private ProtoBuf mPlatformProfile = null; - private ProtoBuf mCellularPlatformProfile = null; - private ProtoBuf mCurrentCollectionRequest = null; - private long mLastCollectionUploadTime = 0; - - // Objects for current request - private List<ScanResult> mWifiScanResults = new ArrayList<ScanResult>(); - private CellState mCellState = null; - private List<CellState> mCellHistory; - - // This tag is used for the event log. - private static final int COLLECTION_EVENT_LOG_TAG = 2740; - - // Extra values to designate whether location is from cache or network request - private static final String EXTRA_KEY_LOCATION_SOURCE = "networkLocationSource"; - private static final String EXTRA_VALUE_LOCATION_SOURCE_CACHED = "cached"; - private static final String EXTRA_VALUE_LOCATION_SOURCE_SERVER = "server"; - - // Maximum accuracy tolerated for a valid location - private static final int MAX_ACCURACY_ALLOWED = 5000; // 5km - - // Indicates whether this is the first message after a device restart - private boolean mDeviceRestart = true; - - /** - * Initializes the MobileServiceMux. Must be called before using any other function in the - * class. - */ - public LocationMasfClient(Context context) { - MobileServiceMux mux = MobileServiceMux.getSingleton(); - if (mux == null) { - AndroidConfig config = new AndroidConfig(context); - Config.setConfig(config); - - MobileServiceMux.initialize - (MASF_SERVER_ADDRESS, - APPLICATION_NAME, - APPLICATION_VERSION, - PLATFORM_ID, - DISTRIBUTION_CHANNEL); - } - mLocationCache = new LocationCache(); - - if (Build.FINGERPRINT != null) { - PLATFORM_BUILD = PLATFORM_ID + "/" + Build.FINGERPRINT; - } else { - PLATFORM_BUILD = PLATFORM_ID; - } - } - - /** - * Returns the location for the given cell or wifi information. - * - * @param apps list of apps requesting location - * @param trigger event that triggered this network request - * @param cellState cell tower state - * @param cellHistory history of acquired cell states - * @param scanResults list of wifi scan results - * @param scanTime time at which wireless scan was triggered - * @param callback function to call with received location - */ - public synchronized void getNetworkLocation(Collection<String> apps, int trigger, - CellState cellState, List<CellState> cellHistory, List<ScanResult> scanResults, - long scanTime, NetworkLocationProvider.Callback callback) { - - final NetworkLocationProvider.Callback finalCallback = callback; - - boolean foundInCache = - mLocationCache.lookup(cellState, cellHistory, scanResults, mLocation); - - if (foundInCache) { - - if (SystemClock.elapsedRealtime() - mLastCollectionUploadTime > MIN_COLLECTION_INTERVAL) { - uploadCollectionReport(true); - } - - Bundle extras = mLocation.getExtras() == null ? new Bundle() : mLocation.getExtras(); - extras.putString(EXTRA_KEY_LOCATION_SOURCE, EXTRA_VALUE_LOCATION_SOURCE_CACHED); - mLocation.setExtras(extras); - - Log.d(TAG, "getNetworkLocation(): Returning cache location with accuracy " + - mLocation.getAccuracy()); - finalCallback.locationReceived(mLocation, true); - return; - } - - Log.d(TAG, "getNetworkLocation(): Location not found in cache, making network request"); - - // Copy over to objects for this request - mWifiScanResults.clear(); - if (scanResults != null) { - mWifiScanResults.addAll(scanResults); - } - mCellState = cellState; - mCellHistory = cellHistory; - - // Create a RequestElement - ProtoBuf requestElement = new ProtoBuf(LocserverMessageTypes.GLOC_REQUEST_ELEMENT); - - // Debug profile - ProtoBuf debugProfile = new ProtoBuf(GdebugprofileMessageTypes.GDEBUG_PROFILE); - requestElement.setProtoBuf(GLocRequestElement.DEBUG_PROFILE, debugProfile); - - if (mDeviceRestart) { - debugProfile.setBool(GDebugProfile.DEVICE_RESTART, true); - mDeviceRestart = false; - } - - if (trigger != -1) { - debugProfile.setInt(GDebugProfile.TRIGGER, trigger); - } - - // Cellular profile - if (mCellState != null && mCellState.isValid()) { - ProtoBuf cellularProfile = new ProtoBuf(GcellularMessageTypes.GCELLULAR_PROFILE); - cellularProfile.setLong(GCellularProfile.TIMESTAMP, mCellState.getTime()); - cellularProfile.setInt(GCellularProfile.PREFETCH_MODE, - GPrefetchMode.PREFETCH_MODE_MORE_NEIGHBORS); - - // Primary cell - ProtoBuf primaryCell = new ProtoBuf(GcellularMessageTypes.GCELL); - primaryCell.setInt(GCell.LAC, mCellState.getLac()); - primaryCell.setInt(GCell.CELLID, mCellState.getCid()); - - if ((mCellState.getMcc() != -1) && (mCellState.getMnc() != -1)) { - primaryCell.setInt(GCell.MCC, mCellState.getMcc()); - primaryCell.setInt(GCell.MNC, mCellState.getMnc()); - } - - if (mCellState.getSignalStrength() != -1) { - primaryCell.setInt(GCell.RSSI, mCellState.getSignalStrength()); - } - - cellularProfile.setProtoBuf(GCellularProfile.PRIMARY_CELL, primaryCell); - - // History of cells - for (CellState c : cellHistory) { - ProtoBuf pastCell = new ProtoBuf(GcellularMessageTypes.GCELL); - pastCell.setInt(GCell.LAC, c.getLac()); - pastCell.setInt(GCell.CELLID, c.getCid()); - if ((c.getMcc() != -1) && (c.getMnc() != -1)) { - pastCell.setInt(GCell.MCC, c.getMcc()); - pastCell.setInt(GCell.MNC, c.getMnc()); - } - - if (c.getSignalStrength() != -1) { - pastCell.setInt(GCell.RSSI, c.getSignalStrength()); - } - - pastCell.setInt(GCell.AGE, (int)(mCellState.getTime() - c.getTime())); - cellularProfile.addProtoBuf(GCellularProfile.HISTORICAL_CELLS, pastCell); - } - - // Neighboring Cells - addNeighborsToCellProfile(mCellState, cellularProfile); - - requestElement.setProtoBuf(GLocRequestElement.CELLULAR_PROFILE, cellularProfile); - } - - // Wifi profile - if (mWifiScanResults != null && mWifiScanResults.size() > 0) { - ProtoBuf wifiProfile = new ProtoBuf(GwifiMessageTypes.GWIFI_PROFILE); - wifiProfile.setLong(GWifiProfile.TIMESTAMP, scanTime); - wifiProfile.setInt(GWifiProfile.PREFETCH_MODE, - GPrefetchMode.PREFETCH_MODE_MORE_NEIGHBORS); - - int count = 0; - for (ScanResult s : mWifiScanResults) { - ProtoBuf wifiDevice = new ProtoBuf(GwifiMessageTypes.GWIFI_DEVICE); - wifiDevice.setString(GWifiDevice.MAC, s.BSSID); - wifiProfile.addProtoBuf(GWifiProfile.WIFI_DEVICES, wifiDevice); - count++; - if (count >= MAX_WIFI_TO_INCLUDE) { - break; - } - } - - requestElement.setProtoBuf(GLocRequestElement.WIFI_PROFILE, wifiProfile); - } - - // Request to send over wire - ProtoBuf request = new ProtoBuf(LocserverMessageTypes.GLOC_REQUEST); - request.addProtoBuf(GLocRequest.REQUEST_ELEMENTS, requestElement); - - // Create a Platform Profile - ProtoBuf platformProfile = createPlatformProfile(); - if (mCellState != null && mCellState.isValid()) { - // Include cellular platform Profile - ProtoBuf cellularPlatform = createCellularPlatformProfile(mCellState); - platformProfile.setProtoBuf(GPlatformProfile.CELLULAR_PLATFORM_PROFILE, - cellularPlatform); - } - request.setProtoBuf(GLocRequest.PLATFORM_PROFILE, platformProfile); - - // Include App Profiles - if (apps != null) { - for (String app : apps) { - ProtoBuf appProfile = new ProtoBuf(GlocationMessageTypes.GAPP_PROFILE); - appProfile.setString(GAppProfile.APP_NAME, app); - request.addProtoBuf(GLocRequest.APP_PROFILES, appProfile); - } - } - - // Queue any waiting collection events as well - uploadCollectionReport(false); - - ByteArrayOutputStream payload = new ByteArrayOutputStream(); - try { - request.outputTo(payload); - } catch (IOException e) { - Log.e(TAG, "getNetworkLocation(): unable to write request to payload", e); - return; - } - - // Creates request and a listener with a call back function - ProtoBuf reply = new ProtoBuf(LocserverMessageTypes.GLOC_REPLY); - Request plainRequest = - new PlainRequest(REQUEST_QUERY_LOC, (short)0, payload.toByteArray()); - - ProtoRequestListener listener = new ProtoRequestListener(reply, new ServiceCallback() { - public void onRequestComplete(Object result) { - ProtoBuf response = (ProtoBuf) result; - boolean successful = parseNetworkLocationReply(response); - finalCallback.locationReceived(mLocation, successful); - - } - }); - plainRequest.setListener(listener); - - // Send request - MobileServiceMux serviceMux = MobileServiceMux.getSingleton(); - serviceMux.submitRequest(plainRequest, true); - } - - private synchronized boolean parseNetworkLocationReply(ProtoBuf response) { - if (response == null) { - Log.e(TAG, "getNetworkLocation(): response is null"); - return false; - } - - int status1 = response.getInt(GLocReply.STATUS); - if (status1 != ResponseCodes.STATUS_STATUS_SUCCESS) { - Log.e(TAG, "getNetworkLocation(): RPC failed with status " + status1); - return false; - } - - if (response.has(GLocReply.PLATFORM_KEY)) { - String platformKey = response.getString(GLocReply.PLATFORM_KEY); - if (!TextUtils.isEmpty(platformKey)) { - setPlatformKey(platformKey); - } - } - - if (!response.has(GLocReply.REPLY_ELEMENTS)) { - Log.e(TAG, "getNetworkLocation(): no ReplyElement"); - return false; - } - ProtoBuf replyElement = response.getProtoBuf(GLocReply.REPLY_ELEMENTS); - - // Get prefetched data to add to the device cache - Log.d(TAG, "getNetworkLocation(): Number of prefetched entries " + - replyElement.getCount(GLocReplyElement.DEVICE_LOCATION)); - long now = System.currentTimeMillis(); - for (int i = 0; i < replyElement.getCount(GLocReplyElement.DEVICE_LOCATION); i++ ) { - ProtoBuf device = replyElement.getProtoBuf(GLocReplyElement.DEVICE_LOCATION, i); - double lat = 0; - double lng = 0; - int accuracy = -1; - int confidence = -1; - int locType = -1; - if (device.has(GDeviceLocation.LOCATION)) { - ProtoBuf deviceLocation = device.getProtoBuf(GDeviceLocation.LOCATION); - if (deviceLocation.has(GLocation.ACCURACY) && - deviceLocation.has(GLocation.LAT_LNG) - && deviceLocation.has(GLocation.CONFIDENCE)) { - lat = deviceLocation.getProtoBuf(GLocation.LAT_LNG). - getInt(GLatLng.LAT_E7) / E7; - lng = deviceLocation.getProtoBuf(GLocation.LAT_LNG). - getInt(GLatLng.LNG_E7) / E7; - accuracy = deviceLocation.getInt(GLocation.ACCURACY); - confidence = deviceLocation.getInt(GLocation.CONFIDENCE); - } - if (deviceLocation.has(GLocation.LOC_TYPE)) { - locType = deviceLocation.getInt(GLocation.LOC_TYPE); - } - } - - // Get cell key - if (device.has(GDeviceLocation.CELL) && locType != GLocation.LOCTYPE_TOWER_LOCATION) { - ProtoBuf deviceCell = device.getProtoBuf(GDeviceLocation.CELL); - int cid = deviceCell.getInt(GCell.CELLID); - int lac = deviceCell.getInt(GCell.LAC); - int mcc = -1; - int mnc = -1; - if (deviceCell.has(GCell.MNC) && deviceCell.has(GCell.MCC)) { - mcc = deviceCell.getInt(GCell.MCC); - mnc = deviceCell.getInt(GCell.MNC); - } - mLocationCache. - insert(mcc, mnc, lac, cid, lat, lng, accuracy, confidence, now); - } - - // Get wifi key - if (device.has(GDeviceLocation.WIFI_DEVICE)) { - ProtoBuf deviceWifi = device.getProtoBuf(GDeviceLocation.WIFI_DEVICE); - String bssid = deviceWifi.getString(GWifiDevice.MAC); - mLocationCache.insert(bssid, lat, lng, accuracy, confidence, now); - } - } - - mLocationCache.save(); - - int status2 = replyElement.getInt(GLocReplyElement.STATUS); - if (status2 != ResponseCodes.STATUS_STATUS_SUCCESS && - status2 != ResponseCodes.STATUS_STATUS_FAILED) { - Log.e(TAG, "getNetworkLocation(): GLS failed with status " + status2); - return false; - } - - // For consistent results for user, always return cache computed location - boolean foundInCache = - mLocationCache.lookup(mCellState, mCellHistory, mWifiScanResults, mLocation); - - if (foundInCache) { - - Bundle extras = mLocation.getExtras() == null ? new Bundle() : mLocation.getExtras(); - extras.putString(EXTRA_KEY_LOCATION_SOURCE, EXTRA_VALUE_LOCATION_SOURCE_SERVER); - mLocation.setExtras(extras); - - Log.d(TAG, "getNetworkLocation(): Returning network location with accuracy " + - mLocation.getAccuracy()); - return true; - } - - if (status2 == ResponseCodes.STATUS_STATUS_FAILED) { - Log.e(TAG, "getNetworkLocation(): GLS does not have location"); - // We return true here since even though there is no location, there is no need to retry - // since server doesn't have location - return true; - } - - // Get server computed location to return for now - if (!replyElement.has(GLocReplyElement.LOCATION)) { - Log.e(TAG, "getNetworkLocation(): no location in ReplyElement"); - return false; - } - ProtoBuf location = replyElement.getProtoBuf(GLocReplyElement.LOCATION); - - if (!location.has(GLocation.LAT_LNG)) { - Log.e(TAG, "getNetworkLocation(): no Lat,Lng in location"); - return false; - } - - ProtoBuf point = location.getProtoBuf(GLocation.LAT_LNG); - double lat = point.getInt(GLatLng.LAT_E7) / E7; - double lng = point.getInt(GLatLng.LNG_E7) / E7; - - int accuracy = 0; - if (location.has(GLocation.ACCURACY)) { - accuracy = location.getInt(GLocation.ACCURACY); - } - - if (accuracy > MAX_ACCURACY_ALLOWED) { - Log.e(TAG, "getNetworkLocation(): accuracy is too high " + accuracy); - return false; - } - - mLocation.setLatitude(lat); - mLocation.setLongitude(lng); - mLocation.setTime(System.currentTimeMillis()); - mLocation.setAccuracy(accuracy); - - Bundle extras = mLocation.getExtras() == null ? new Bundle() : mLocation.getExtras(); - extras.putString(EXTRA_KEY_LOCATION_SOURCE, EXTRA_VALUE_LOCATION_SOURCE_SERVER); - mLocation.setExtras(extras); - - Log.e(TAG, "getNetworkLocation(): Returning *server* computed location with accuracy " + - accuracy); - - return true; - } - - /** - * Gets a reverse geocoded location from the given lat,lng point. Also attaches the name - * of the requesting application with the request - * - * @param locale locale for geocoded location - * @param appPackageName name of the package, may be null - * @param lat latitude - * @param lng longitude - * @param maxResults maximum number of addresses to return - * @param addrs the list of addresses to fill up - * @throws IOException if network is unavailable or some other issue - */ - public void reverseGeocode(Locale locale, String appPackageName, - double lat, double lng, int maxResults, List<Address> addrs) throws IOException { - - // Reverse geocoding request element - ProtoBuf requestElement = new ProtoBuf(LocserverMessageTypes.GLOC_REQUEST_ELEMENT); - - ProtoBuf latlngElement = new ProtoBuf(GlatlngMessageTypes.GLAT_LNG); - latlngElement.setInt(GLatLng.LAT_E7, (int)(lat * E7)); - latlngElement.setInt(GLatLng.LNG_E7, (int)(lng * E7)); - - ProtoBuf locationElement = new ProtoBuf(GlocationMessageTypes.GLOCATION); - locationElement.setProtoBuf(GLocation.LAT_LNG, latlngElement); - locationElement.setLong(GLocation.TIMESTAMP, System.currentTimeMillis()); - requestElement.setProtoBuf(GLocRequestElement.LOCATION, locationElement); - - ProtoBuf geocodeElement = - new ProtoBuf(LocserverMessageTypes.GGEOCODE_REQUEST); - geocodeElement.setInt(GGeocodeRequest.NUM_FEATURE_LIMIT, maxResults); - requestElement.setProtoBuf(GLocRequestElement.GEOCODE, geocodeElement); - - // Request to send over wire - ProtoBuf request = new ProtoBuf(LocserverMessageTypes.GLOC_REQUEST); - request.addProtoBuf(GLocRequest.REQUEST_ELEMENTS, requestElement); - - // Create platform profile - ProtoBuf platformProfile = createPlatformProfile(locale); - request.setProtoBuf(GLocRequest.PLATFORM_PROFILE, platformProfile); - - // Include app name - if (appPackageName != null) { - ProtoBuf appProfile = new ProtoBuf(GlocationMessageTypes.GAPP_PROFILE); - appProfile.setString(GAppProfile.APP_NAME, appPackageName); - request.setProtoBuf(GLocRequest.APP_PROFILES, appProfile); - } - - // Queue any waiting collection events as well - uploadCollectionReport(false); - - ByteArrayOutputStream payload = new ByteArrayOutputStream(); - try { - request.outputTo(payload); - } catch (IOException e) { - Log.e(TAG, "reverseGeocode(): unable to write request to payload"); - throw e; - } - - // Creates request and a listener with no callback function - ProtoBuf reply = new ProtoBuf(LocserverMessageTypes.GLOC_REPLY); - Request plainRequest = - new PlainRequest(REQUEST_QUERY_LOC, (short)0, payload.toByteArray()); - ProtoRequestListener listener = new ProtoRequestListener(reply, null); - plainRequest.setListener(listener); - - // Immediately send request and block for response until REQUEST_TIMEOUT - MobileServiceMux serviceMux = MobileServiceMux.getSingleton(); - serviceMux.submitRequest(plainRequest, true); - ProtoBuf response; - try { - response = (ProtoBuf)listener.getAsyncResult().get(REQUEST_TIMEOUT); - } catch (InterruptedException e) { - Log.e(TAG, "reverseGeocode(): response timeout"); - throw new IOException("response time-out"); - } - - if (response == null) { - throw new IOException("Unable to parse response from server"); - } - - // Parse the response - int status1 = response.getInt(GLocReply.STATUS); - if (status1 != ResponseCodes.STATUS_STATUS_SUCCESS) { - Log.e(TAG, "reverseGeocode(): RPC failed with status " + status1); - throw new IOException("RPC failed with status " + status1); - } - - if (response.has(GLocReply.PLATFORM_KEY)) { - String platformKey = response.getString(GLocReply.PLATFORM_KEY); - if (!TextUtils.isEmpty(platformKey)) { - setPlatformKey(platformKey); - } - } - - if (!response.has(GLocReply.REPLY_ELEMENTS)) { - Log.e(TAG, "reverseGeocode(): no ReplyElement"); - return; - } - ProtoBuf replyElement = response.getProtoBuf(GLocReply.REPLY_ELEMENTS); - - int status2 = replyElement.getInt(GLocReplyElement.STATUS); - if (status2 != ResponseCodes.STATUS_STATUS_SUCCESS) { - Log.e(TAG, "reverseGeocode(): GLS failed with status " + status2); - return; - } - - if (!replyElement.has(GLocReplyElement.LOCATION)) { - Log.e(TAG, "reverseGeocode(): no location in ReplyElement"); - return; - } - - ProtoBuf location = replyElement.getProtoBuf(GLocReplyElement.LOCATION); - if (!location.has(GLocation.FEATURE)) { - Log.e(TAG, "reverseGeocode(): no feature in GLocation"); - return; - } - - getAddressFromProtoBuf(location, locale, addrs); - } - - /** - * Gets a forward geocoded location from the given location string. Also attaches the name - * of the requesting application with the request - * - * Optionally, can specify the bounding box that the search results should be restricted to - * - * @param locale locale for geocoded location - * @param appPackageName name of the package, may be null - * @param locationString string to forward geocode - * @param lowerLeftLatitude latitude of lower left point of bounding box - * @param lowerLeftLongitude longitude of lower left point of bounding box - * @param upperRightLatitude latitude of upper right point of bounding box - * @param upperRightLongitude longitude of upper right point of bounding box - * @param maxResults maximum number of results to return - * @param addrs the list of addresses to fill up - * @throws IOException if network is unavailable or some other issue - */ - public void forwardGeocode(Locale locale, String appPackageName, String locationString, - double lowerLeftLatitude, double lowerLeftLongitude, - double upperRightLatitude, double upperRightLongitude, int maxResults, List<Address> addrs) - throws IOException { - - // Forward geocoding request element - ProtoBuf requestElement = new ProtoBuf(LocserverMessageTypes.GLOC_REQUEST_ELEMENT); - - ProtoBuf locationElement = new ProtoBuf(GlocationMessageTypes.GLOCATION); - locationElement.setLong(GLocation.TIMESTAMP, System.currentTimeMillis()); - locationElement.setString(GLocation.LOCATION_STRING, locationString); - requestElement.setProtoBuf(GLocRequestElement.LOCATION, locationElement); - - ProtoBuf geocodeElement = - new ProtoBuf(LocserverMessageTypes.GGEOCODE_REQUEST); - geocodeElement.setInt(GGeocodeRequest.NUM_FEATURE_LIMIT, maxResults); - - if (lowerLeftLatitude != 0 && lowerLeftLongitude !=0 && - upperRightLatitude !=0 && upperRightLongitude !=0) { - ProtoBuf lowerLeft = new ProtoBuf(GlatlngMessageTypes.GLAT_LNG); - lowerLeft.setInt(GLatLng.LAT_E7, (int)(lowerLeftLatitude * E7)); - lowerLeft.setInt(GLatLng.LNG_E7, (int)(lowerLeftLongitude * E7)); - - ProtoBuf upperRight = new ProtoBuf(GlatlngMessageTypes.GLAT_LNG); - upperRight.setInt(GLatLng.LAT_E7, (int)(upperRightLatitude * E7)); - upperRight.setInt(GLatLng.LNG_E7, (int)(upperRightLongitude * E7)); - - ProtoBuf boundingBox = new ProtoBuf(GrectangleMessageTypes.GRECTANGLE); - boundingBox.setProtoBuf(GRectangle.LOWER_LEFT, lowerLeft); - boundingBox.setProtoBuf(GRectangle.UPPER_RIGHT, upperRight); - geocodeElement.setProtoBuf(GGeocodeRequest.BOUNDING_BOX, boundingBox); - } - requestElement.setProtoBuf(GLocRequestElement.GEOCODE, geocodeElement); - - // Request to send over wire - ProtoBuf request = new ProtoBuf(LocserverMessageTypes.GLOC_REQUEST); - request.addProtoBuf(GLocRequest.REQUEST_ELEMENTS, requestElement); - - // Create platform profile - ProtoBuf platformProfile = createPlatformProfile(locale); - request.setProtoBuf(GLocRequest.PLATFORM_PROFILE, platformProfile); - - // Include app name - if (appPackageName != null) { - ProtoBuf appProfile = new ProtoBuf(GlocationMessageTypes.GAPP_PROFILE); - appProfile.setString(GAppProfile.APP_NAME, appPackageName); - request.setProtoBuf(GLocRequest.APP_PROFILES, appProfile); - } - - // Queue any waiting collection events as well - uploadCollectionReport(false); - - ByteArrayOutputStream payload = new ByteArrayOutputStream(); - try { - request.outputTo(payload); - } catch (IOException e) { - Log.e(TAG, "forwardGeocode(): unable to write request to payload"); - throw e; - } - - // Creates request and a listener with no callback function - ProtoBuf reply = new ProtoBuf(LocserverMessageTypes.GLOC_REPLY); - Request plainRequest = - new PlainRequest(REQUEST_QUERY_LOC, (short)0, payload.toByteArray()); - ProtoRequestListener listener = new ProtoRequestListener(reply, null); - plainRequest.setListener(listener); - - // Immediately send request and block for response until REQUEST_TIMEOUT - MobileServiceMux serviceMux = MobileServiceMux.getSingleton(); - serviceMux.submitRequest(plainRequest, true); - ProtoBuf response; - try { - response = (ProtoBuf)listener.getAsyncResult().get(REQUEST_TIMEOUT); - } catch (InterruptedException e) { - Log.e(TAG, "forwardGeocode(): response timeout"); - throw new IOException("response time-out"); - } - - if (response == null) { - throw new IOException("Unable to parse response from server"); - } - - // Parse the response - int status1 = response.getInt(GLocReply.STATUS); - if (status1 != ResponseCodes.STATUS_STATUS_SUCCESS) { - Log.e(TAG, "forwardGeocode(): RPC failed with status " + status1); - throw new IOException("RPC failed with status " + status1); - } - - if (response.has(GLocReply.PLATFORM_KEY)) { - String platformKey = response.getString(GLocReply.PLATFORM_KEY); - if (!TextUtils.isEmpty(platformKey)) { - setPlatformKey(platformKey); - } - } - - if (!response.has(GLocReply.REPLY_ELEMENTS)) { - Log.e(TAG, "forwardGeocode(): no ReplyElement"); - return; - } - ProtoBuf replyElement = response.getProtoBuf(GLocReply.REPLY_ELEMENTS); - - int status2 = replyElement.getInt(GLocReplyElement.STATUS); - if (status2 != ResponseCodes.STATUS_STATUS_SUCCESS) { - Log.e(TAG, "forwardGeocode(): GLS failed with status " + status2); - return; - } - - if (!replyElement.has(GLocReplyElement.LOCATION)) { - Log.e(TAG, "forwardGeocode(): no location in ReplyElement"); - return; - } - - ProtoBuf location = replyElement.getProtoBuf(GLocReplyElement.LOCATION); - if (!location.has(GLocation.FEATURE)) { - Log.e(TAG, "forwardGeocode(): no feature in GLocation"); - return; - } - - getAddressFromProtoBuf(location, locale, addrs); - } - - /** - * Queues a location collection request to be sent to the server - * - * @param trigger what triggered this collection event - * @param location last known location - * @param cellState cell tower state - * @param scanResults list of wifi points - * @param scanTime real time at which wifi scan happened - * @param immediate true if request should be sent immediately instead of being queued - */ - public synchronized void queueCollectionReport(int trigger, Location location, - CellState cellState, List<ScanResult> scanResults, long scanTime, boolean immediate) { - - // Create a RequestElement - ProtoBuf requestElement = new ProtoBuf(LocserverMessageTypes.GLOC_REQUEST_ELEMENT); - - // Include debug profile - ProtoBuf debugProfile = new ProtoBuf(GdebugprofileMessageTypes.GDEBUG_PROFILE); - requestElement.setProtoBuf(GLocRequestElement.DEBUG_PROFILE, debugProfile); - - if (mDeviceRestart) { - debugProfile.setBool(GDebugProfile.DEVICE_RESTART, true); - mDeviceRestart = false; - } - - if (trigger != -1) { - debugProfile.setInt(GDebugProfile.TRIGGER, trigger); - EventLog.writeEvent(COLLECTION_EVENT_LOG_TAG, trigger); - } - - // Include cell profile - if (cellState != null && cellState.isValid()) { - ProtoBuf cellularProfile = new ProtoBuf(GcellularMessageTypes.GCELLULAR_PROFILE); - cellularProfile.setLong(GCellularProfile.TIMESTAMP, cellState.getTime()); - - // Primary cell - ProtoBuf primaryCell = new ProtoBuf(GcellularMessageTypes.GCELL); - primaryCell.setInt(GCell.LAC, cellState.getLac()); - primaryCell.setInt(GCell.CELLID, cellState.getCid()); - if ((cellState.getMcc() != -1) && (cellState.getMnc() != -1)) { - primaryCell.setInt(GCell.MCC, cellState.getMcc()); - primaryCell.setInt(GCell.MNC, cellState.getMnc()); - } - - if (cellState.getSignalStrength() != -1) { - primaryCell.setInt(GCell.RSSI, cellState.getSignalStrength()); - } - - cellularProfile.setProtoBuf(GCellularProfile.PRIMARY_CELL, primaryCell); - - // Cell neighbors - addNeighborsToCellProfile(cellState, cellularProfile); - - requestElement.setProtoBuf(GLocRequestElement.CELLULAR_PROFILE, cellularProfile); - } - - // Include Wifi profile - if (scanResults != null && scanResults.size() > 0) { - ProtoBuf wifiProfile = new ProtoBuf(GwifiMessageTypes.GWIFI_PROFILE); - wifiProfile.setLong(GWifiProfile.TIMESTAMP, scanTime); - - int count = 0; - for (ScanResult s : scanResults) { - ProtoBuf wifiDevice = new ProtoBuf(GwifiMessageTypes.GWIFI_DEVICE); - wifiDevice.setString(GWifiDevice.MAC, s.BSSID); - wifiDevice.setString(GWifiDevice.SSID, s.SSID); - wifiDevice.setInt(GWifiDevice.RSSI, s.level); - wifiProfile.addProtoBuf(GWifiProfile.WIFI_DEVICES, wifiDevice); - count++; - if (count >= MAX_WIFI_TO_INCLUDE) { - break; - } - } - - requestElement.setProtoBuf(GLocRequestElement.WIFI_PROFILE, wifiProfile); - } - - // Location information - if (location != null) { - ProtoBuf latlngElement = new ProtoBuf(GlatlngMessageTypes.GLAT_LNG); - latlngElement.setInt(GLatLng.LAT_E7, (int)(location.getLatitude() * E7)); - latlngElement.setInt(GLatLng.LNG_E7, (int)(location.getLongitude() * E7)); - - ProtoBuf locationElement = new ProtoBuf(GlocationMessageTypes.GLOCATION); - locationElement.setProtoBuf(GLocation.LAT_LNG, latlngElement); - locationElement.setInt(GLocation.LOC_TYPE, GLocation.LOCTYPE_GPS); - locationElement.setLong(GLocation.TIMESTAMP, location.getTime()); - if (location.hasAccuracy()) { - locationElement.setInt(GLocation.ACCURACY, (int)location.getAccuracy()); - } - if (location.hasSpeed()) { - locationElement.setInt(GLocation.VELOCITY, (int)location.getSpeed()); - } - if (location.hasBearing()) { - locationElement.setInt(GLocation.HEADING, (int)location.getBearing()); - } - - requestElement.setProtoBuf(GLocRequestElement.LOCATION, locationElement); - } - - if (mCurrentCollectionRequest == null) { - mCurrentCollectionRequest = new ProtoBuf(LocserverMessageTypes.GLOC_REQUEST); - - // Create a Platform Profile - ProtoBuf platformProfile = createPlatformProfile(); - if (cellState != null && cellState.isValid()) { - ProtoBuf cellularPlatform = createCellularPlatformProfile(cellState); - platformProfile.setProtoBuf(GPlatformProfile.CELLULAR_PLATFORM_PROFILE, - cellularPlatform); - } - - mCurrentCollectionRequest.setProtoBuf(GLocRequest.PLATFORM_PROFILE, platformProfile); - - } else { - - ProtoBuf platformProfile = - mCurrentCollectionRequest.getProtoBuf(GLocRequest.PLATFORM_PROFILE); - if (platformProfile == null) { - platformProfile = createPlatformProfile(); - mCurrentCollectionRequest.setProtoBuf( - GLocRequest.PLATFORM_PROFILE, platformProfile); - } - - // Add cellular platform profile is not already included - if (platformProfile.getProtoBuf(GPlatformProfile.CELLULAR_PLATFORM_PROFILE) == null && - cellState != null && cellState.isValid()) { - ProtoBuf cellularPlatform = createCellularPlatformProfile(cellState); - platformProfile.setProtoBuf(GPlatformProfile.CELLULAR_PLATFORM_PROFILE, - cellularPlatform); - } - } - - mCurrentCollectionRequest.addProtoBuf(GLocRequest.REQUEST_ELEMENTS, requestElement); - - // Immediately upload collection events if buffer exceeds certain size - if (mCurrentCollectionRequest.getCount(GLocRequest.REQUEST_ELEMENTS) - >= MAX_COLLECTION_BUFFER_SIZE) { - immediate = true; - } - - if (immediate) { - // Request to send over wire - uploadCollectionReport(immediate); - } - } - - /** - * Uploads the collection report either immediately or based on MASF's queueing logic. - * Does not need a reply back - * - * @param immediate true if request should be sent immediately instead of being queued - */ - private synchronized void uploadCollectionReport(boolean immediate) { - // There may be nothing to upload - if (mCurrentCollectionRequest == null || - mCurrentCollectionRequest.getCount(GLocRequest.REQUEST_ELEMENTS) == 0) { - return; - } - - ByteArrayOutputStream payload = new ByteArrayOutputStream(); - try { - mCurrentCollectionRequest.outputTo(payload); - } catch (IOException e) { - Log.e(TAG, "uploadCollectionReport(): unable to write request to payload"); - return; - } - - mLastCollectionUploadTime = SystemClock.elapsedRealtime(); - - // Since this has already been written to the wire, we can clear this request - int count = mCurrentCollectionRequest.getCount(GLocRequest.REQUEST_ELEMENTS); - while (count > 0) { - mCurrentCollectionRequest.remove(GLocRequest.REQUEST_ELEMENTS, count - 1); - count--; - } - - // Creates request and a listener with a call back function - ProtoBuf reply = new ProtoBuf(LocserverMessageTypes.GLOC_REPLY); - Request plainRequest = - new PlainRequest(REQUEST_UPLOAD_LOC, (short)0, payload.toByteArray()); - - ProtoRequestListener listener = new ProtoRequestListener(reply, new ServiceCallback() { - public void onRequestComplete(Object result) { - ProtoBuf response = (ProtoBuf) result; - - if (response == null) { - Log.e(TAG, "uploadCollectionReport(): response is null"); - return; - } - - int status1 = response.getInt(GLocReply.STATUS); - if (status1 != ResponseCodes.STATUS_STATUS_SUCCESS) { - Log.w(TAG, "uploadCollectionReport(): RPC failed with status " + status1); - return; - } - - if (response.has(GLocReply.PLATFORM_KEY)) { - String platformKey = response.getString(GLocReply.PLATFORM_KEY); - if (!TextUtils.isEmpty(platformKey)) { - setPlatformKey(platformKey); - } - } - - if (!response.has(GLocReply.REPLY_ELEMENTS)) { - Log.w(TAG, "uploadCollectionReport(): no ReplyElement"); - return; - } - - int count = response.getCount(GLocReply.REPLY_ELEMENTS); - for (int i = 0; i < count; i++) { - ProtoBuf replyElement = response.getProtoBuf(GLocReply.REPLY_ELEMENTS, i); - int status2 = replyElement.getInt(GLocReplyElement.STATUS); - if (status2 != ResponseCodes.STATUS_STATUS_SUCCESS) { - Log.w(TAG, "uploadCollectionReport(): GLS failed with " + status2); - } - } - - } - }); - plainRequest.setListener(listener); - - // Send request - MobileServiceMux serviceMux = MobileServiceMux.getSingleton(); - serviceMux.submitRequest(plainRequest, immediate); - - } - - private String getPlatformKey() { - if (mPlatformKey != null) { - return mPlatformKey; - } - - try { - File file = new File(LocationManager.SYSTEM_DIR, PLATFORM_KEY_FILE); - FileInputStream istream = new FileInputStream(file); - DataInputStream dataInput = new DataInputStream(istream); - String platformKey = dataInput.readUTF(); - dataInput.close(); - mPlatformKey = platformKey; - return mPlatformKey; - } catch(FileNotFoundException e) { - // No file, just ignore - return null; - } catch(IOException e) { - // Unable to read from file, just ignore - return null; - } - } - - private void setPlatformKey(String platformKey) { - File systemDir = new File(LocationManager.SYSTEM_DIR); - if (!systemDir.exists()) { - if (!systemDir.mkdirs()) { - Log.w(TAG, "setPlatformKey(): couldn't create directory"); - return; - } - } - - try { - File file = new File(LocationManager.SYSTEM_DIR, PLATFORM_KEY_FILE); - FileOutputStream ostream = new FileOutputStream(file); - DataOutputStream dataOut = new DataOutputStream(ostream); - dataOut.writeUTF(platformKey); - dataOut.close(); - mPlatformKey = platformKey; - } catch (FileNotFoundException e) { - Log.w(TAG, "setPlatformKey(): unable to create platform key file"); - } catch (IOException e) { - Log.w(TAG, "setPlatformKey(): unable to write to platform key"); - } - } - - private ProtoBuf createPlatformProfile() { - Locale locale = Locale.getDefault(); - return createPlatformProfile(locale); - } - - private ProtoBuf createPlatformProfile(Locale locale) { - if (mPlatformProfile == null) { - mPlatformProfile = new ProtoBuf(GlocationMessageTypes.GPLATFORM_PROFILE); - mPlatformProfile.setString(GPlatformProfile.VERSION, APPLICATION_VERSION); - mPlatformProfile.setString(GPlatformProfile.PLATFORM, PLATFORM_BUILD); - } - - // Add Locale - if ((locale != null) && (locale.toString() != null)) { - mPlatformProfile.setString(GPlatformProfile.LOCALE, locale.toString()); - } - - // Add Platform Key - String platformKey = getPlatformKey(); - if (!TextUtils.isEmpty(platformKey)) { - mPlatformProfile.setString(GPlatformProfile.PLATFORM_KEY, platformKey); - } - - // Clear out cellular platform profile - mPlatformProfile.setProtoBuf(GPlatformProfile.CELLULAR_PLATFORM_PROFILE, null); - - return mPlatformProfile; - } - - private ProtoBuf createCellularPlatformProfile(CellState cellState) { - // Radio type - int radioType = -1; - if (cellState.getRadioType() == CellState.RADIO_TYPE_GPRS) { - radioType = GCellularPlatformProfile.RADIO_TYPE_GPRS; - } else if (cellState.getRadioType() == CellState.RADIO_TYPE_CDMA) { - radioType = GCellularPlatformProfile.RADIO_TYPE_CDMA; - } else if (cellState.getRadioType() == CellState.RADIO_TYPE_WCDMA) { - radioType = GCellularPlatformProfile.RADIO_TYPE_WCDMA; - } - - if (mCellularPlatformProfile == null) { - mCellularPlatformProfile = - new ProtoBuf(GlocationMessageTypes.GCELLULAR_PLATFORM_PROFILE); - } - - mCellularPlatformProfile.setInt(GCellularPlatformProfile.RADIO_TYPE, radioType); - if ((cellState.getHomeMcc() != -1) && (cellState.getHomeMnc() != -1)) { - mCellularPlatformProfile.setInt(GCellularPlatformProfile.HOME_MCC, - cellState.getHomeMcc()); - mCellularPlatformProfile.setInt(GCellularPlatformProfile.HOME_MNC, - cellState.getHomeMnc()); - } - if (cellState.getCarrier() != null) { - mCellularPlatformProfile.setString(GCellularPlatformProfile.CARRIER, - cellState.getCarrier()); - } - - return mCellularPlatformProfile; - } - - private void getAddressFromProtoBuf(ProtoBuf location, Locale locale, List<Address> addrs) { - - double lat = -1; - double lng = -1; - - if (location.has(GLocation.LAT_LNG)) { - ProtoBuf latlng = location.getProtoBuf(GLocation.LAT_LNG); - lat = latlng.getInt(GLatLng.LAT_E7)/E7; - lng = latlng.getInt(GLatLng.LNG_E7)/E7; - } - - for (int a = 0; a < location.getCount(GLocation.FEATURE); a++) { - - Address output = new Address(locale); - - ProtoBuf feature = location.getProtoBuf(GLocation.FEATURE, a); - output.setFeatureName(feature.getString(GFeature.NAME)); - - if (feature.has(GFeature.CENTER)) { - ProtoBuf center = feature.getProtoBuf(GFeature.CENTER); - output.setLatitude(center.getInt(GLatLng.LAT_E7)/E7); - output.setLongitude(center.getInt(GLatLng.LNG_E7)/E7); - - } else if (location.has(GLocation.LAT_LNG)) { - output.setLatitude(lat); - output.setLongitude(lng); - } - - ProtoBuf address = feature.getProtoBuf(GFeature.ADDRESS); - - for (int i = 0; i < address.getCount(GAddress.FORMATTED_ADDRESS_LINE); i++) { - String line = address.getString(GAddress.FORMATTED_ADDRESS_LINE, i); - output.setAddressLine(i, line); - } - - for (int i = 0; i < address.getCount(GAddress.COMPONENT); i++) { - ProtoBuf component = address.getProtoBuf(GAddress.COMPONENT, i); - int type = component.getInt(GAddressComponent.FEATURE_TYPE); - String name = component.getString(GAddressComponent.NAME); - - switch(type) { - case GFeature.FEATURE_TYPE_ADMINISTRATIVE_AREA : - output.setAdminArea(name); - break; - - case GFeature.FEATURE_TYPE_SUB_ADMINISTRATIVE_AREA : - output.setSubAdminArea(name); - break; - - case GFeature.FEATURE_TYPE_LOCALITY : - output.setLocality(name); - break; - - case GFeature.FEATURE_TYPE_THOROUGHFARE : - output.setThoroughfare(name); - break; - - case GFeature.FEATURE_TYPE_POST_CODE : - output.setPostalCode(name); - break; - - case GFeature.FEATURE_TYPE_COUNTRY : - output.setCountryName(name); - break; - - case GFeature.FEATURE_TYPE_COUNTRY_CODE : - output.setCountryCode(name); - break; - - default : - if (android.util.Config.LOGD) { - Log.d(TAG, "getAddressFromProtoBuf(): Ignore feature " + type + "," + name); - } - break; - } - } - - addrs.add(output); - } - } - - 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); - nCell.setInt(GCell.CELLID, neighbor.getCid()); - nCell.setInt(GCell.LAC, neighbor.getLac()); - nCell.setInt(GCell.RSSI, neighbor.getRssi()); - 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); - } - } - } - -} diff --git a/location/java/com/android/internal/location/NetworkLocationProvider.java b/location/java/com/android/internal/location/NetworkLocationProvider.java deleted file mode 100644 index d0a59b9..0000000 --- a/location/java/com/android/internal/location/NetworkLocationProvider.java +++ /dev/null @@ -1,561 +0,0 @@ -/* - * 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 com.android.internal.location; - -import com.android.internal.location.protocol.GDebugProfile; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; - -import android.content.Context; -import android.location.Criteria; -import android.location.Location; -import android.location.LocationManager; -import android.location.LocationProviderImpl; -import android.net.wifi.ScanResult; -import android.net.wifi.WifiManager; -import android.os.Bundle; -import android.os.SystemClock; -import android.os.SystemProperties; -import android.util.Log; - -/** - * A location provider which gets approximate location from Google's - * database of cell-tower and wi-fi locations. - * - * <p> It is the responsibility of the LocationManagerService to - * notify this class of any changes in the radio information - * by calling {@link #updateCellState} and of data state - * changes by calling {@link #updateNetworkState} - * - * <p> The LocationManagerService must also notify the provider - * of Wifi updates using the {@link #updateWifiScanResults} - * and {@link #updateWifiEnabledState} - * methods. - * - * <p> The provider uses whichever radio is available - Cell - * or WiFi. If neither is available, it does NOT attempt to - * switch them on. - * - * {@hide} - */ -public class NetworkLocationProvider extends LocationProviderImpl { - private static final String TAG = "NetworkLocationProvider"; - - // Wait at least 60 seconds between network queries - private static final int MIN_NETWORK_RETRY_MILLIS = 60000; - - // Max time to wait for radio update - private static final long MAX_TIME_TO_WAIT_FOR_RADIO = 5 * 1000; // 5 seconds - - // State of entire provider - private int mStatus = AVAILABLE; - private long mStatusUpdateTime = 0; - - // Network state - private int mNetworkState = TEMPORARILY_UNAVAILABLE; - - // Cell state - private static final int MAX_CELL_HISTORY_TO_KEEP = 4; - private LinkedList<CellState> mCellHistory = new LinkedList<CellState>(); - private CellState mCellState = null; - private long mLastCellStateChangeTime = 0; - private long mLastCellLockTime = 0; - - // Wifi state - private static final long MIN_TIME_BETWEEN_WIFI_REPORTS = 45 * 1000; // 45 seconds - private List<ScanResult> mWifiLastScanResults = null; - private long mLastWifiScanTriggerTime = 0; - private long mLastWifiScanElapsedTime = 0; - private long mLastWifiScanRealTime = 0; - private long mWifiScanFrequency = MIN_TIME_BETWEEN_WIFI_REPORTS; - private boolean mWifiEnabled = false; - - // Last known location state - private Location mLocation = new Location(LocationManager.NETWORK_PROVIDER); - private long mLastNetworkQueryTime = 0; // Last network request, successful or not - private long mLastSuccessfulNetworkQueryTime = 0; // Last successful network query time - - // Is provider enabled by user -- ignored by this class - private boolean mEnabled; - - // Is provider being used by an application - private HashSet<String> mApplications = new HashSet<String>(); - private boolean mTracking = false; - - // Location masf service - private LocationMasfClient mMasfClient; - - // Context of location manager service - private Context mContext; - - public static boolean isSupported() { - // This class provides a Google-specific location feature, so it's enabled only - // when the system property ro.com.google.locationfeatures is set. - if (!SystemProperties.get("ro.com.google.locationfeatures").equals("1")) { - return false; - } - - // Otherwise, assume cell location should work if we are not running in the emulator - return !SystemProperties.get("ro.kernel.qemu").equals("1"); - } - - public NetworkLocationProvider(Context context, LocationMasfClient masfClient) { - super(LocationManager.NETWORK_PROVIDER); - mContext = context; - mMasfClient = masfClient; - } - - @Override - public void updateNetworkState(int state) { - if (state == mNetworkState) { - return; - } - log("updateNetworkState(): Updating network state to " + state); - mNetworkState = state; - - updateStatus(mNetworkState); - } - - @Override - public void updateCellState(CellState newState) { - if (newState == null) { - log("updateCellState(): Cell state is invalid"); - return; - } - - if (mCellState != null && mCellState.equals(newState)) { - log("updateCellState(): Cell state is the same"); - return; - } - - // Add previous state to history - if ((mCellState != null) && mCellState.isValid()) { - if (mCellHistory.size() >= MAX_CELL_HISTORY_TO_KEEP) { - mCellHistory.remove(0); - } - mCellHistory.add(mCellState); - } - - mCellState = newState; - log("updateCellState(): Received"); - - mLastCellLockTime = 0; - mLastCellStateChangeTime = SystemClock.elapsedRealtime(); - } - - public void updateCellLockStatus(boolean acquired) { - if (acquired) { - mLastCellLockTime = SystemClock.elapsedRealtime(); - } else { - mLastCellLockTime = 0; - } - } - - @Override - public boolean requiresNetwork() { - return true; - } - - @Override - public boolean requiresSatellite() { - return false; - } - - @Override - public boolean requiresCell() { - return true; - } - - @Override - public boolean hasMonetaryCost() { - return true; - } - - @Override - public boolean supportsAltitude() { - return false; - } - - @Override - public boolean supportsSpeed() { - return false; - } - - @Override - public boolean supportsBearing() { - return false; - } - - @Override - public int getPowerRequirement() { - return Criteria.POWER_LOW; - } - - @Override - public void enable() { - // Nothing else needs to be done - mEnabled = true; - } - - @Override - public void disable() { - // Nothing else needs to be done - mEnabled = false; - } - - @Override - public boolean isEnabled() { - return mEnabled; - } - - @Override - public int getAccuracy() { - return Criteria.ACCURACY_COARSE; - } - - @Override - public int getStatus(Bundle extras) { - return mStatus; - } - - @Override - public long getStatusUpdateTime() { - return mStatusUpdateTime; - } - - @Override - public void setMinTime(long minTime) { - if (minTime < MIN_TIME_BETWEEN_WIFI_REPORTS) { - mWifiScanFrequency = MIN_TIME_BETWEEN_WIFI_REPORTS; - } else { - mWifiScanFrequency = minTime; - } - super.setMinTime(minTime); - } - - @Override - public boolean getLocation(Location l) { - - long now = SystemClock.elapsedRealtime(); - - // Trigger a wifi scan and wait for its results if necessary - if ((mWifiEnabled) && - (mWifiLastScanResults == null || - ((now - mLastWifiScanElapsedTime) > mWifiScanFrequency))) { - - boolean fallback = false; - - // If scan has been recently triggered - if (mLastWifiScanTriggerTime != 0 && - ((now - mLastWifiScanTriggerTime) < mWifiScanFrequency)) { - if ((now - mLastWifiScanTriggerTime) > MAX_TIME_TO_WAIT_FOR_RADIO) { - // If no results from last trigger available, use cell results - // This will also trigger a new scan - log("getLocation(): falling back to cell"); - fallback = true; - } else { - // Just wait for the Wifi results to be available - return false; - } - } - - WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); - log("getLocation(): triggering a wifi scan"); - mLastWifiScanTriggerTime = now; - boolean succeeded = wifiManager.startScan(); - if (!succeeded) { - log("getLocation(): wifi scan did not succeed"); - // Wifi trigger failed, use cell results - fallback = true; - } - - // Wait for scan results - if (!fallback) { - return false; - } - } - - // If waiting for cell location - if (mLastCellLockTime != 0 && ((now - mLastCellLockTime) < MAX_TIME_TO_WAIT_FOR_RADIO)) { - return false; - } - - // Update Location - // 1) If there has been a cell state change - // 2) If there was no successful reply for last network request - if (mLastCellStateChangeTime > mLastNetworkQueryTime) { - updateLocation(); - return false; - - } else if ((mLastNetworkQueryTime != 0) - && (mLastNetworkQueryTime > mLastSuccessfulNetworkQueryTime) - && ((now - mLastNetworkQueryTime) > MIN_NETWORK_RETRY_MILLIS)) { - updateLocation(); - return false; - } - - if (mLocation != null && mLocation.getAccuracy() > 0) { - - // We could have a Cell Id location which hasn't changed in a - // while because we haven't switched towers so if the last location - // time + mWifiScanFrequency is less than current time update the - // locations time. - long currentTime = System.currentTimeMillis(); - if ((mLocation.getTime() + mWifiScanFrequency) < currentTime) { - mLocation.setTime(currentTime); - } - l.set(mLocation); - return true; - } else { - return false; - } - } - - @Override - public void enableLocationTracking(boolean enable) { - if (enable == mTracking) { - return; - } - - log("enableLocationTracking(): " + enable); - mTracking = enable; - - if (!enable) { - // When disabling the location provider, be sure to clear out old location - clearLocation(); - } else { - // When enabling provider, force location - forceLocation(); - } - } - - @Override - public boolean isLocationTracking() { - return mTracking; - } - - /** - * Notifies the provider that there are scan results available. - * - * @param scanResults list of wifi scan results - */ - public void updateWifiScanResults(List<ScanResult> scanResults) { - if (!mTracking) { - return; - } - - long now = SystemClock.elapsedRealtime(); - - if (scanResults == null) { - mWifiLastScanResults = null; - mLastWifiScanElapsedTime = now; - mLastWifiScanRealTime = System.currentTimeMillis(); - - log("updateWifIScanResults(): NULL APs"); - - // Force cell location since no wifi results available - if (mWifiEnabled) { - mLastCellLockTime = 0; - mLastCellStateChangeTime = SystemClock.elapsedRealtime(); - } - - } else if ((mWifiLastScanResults == null) - || (mWifiLastScanResults.size() <= 2 && scanResults.size() > mWifiLastScanResults.size()) - || ((now - mLastWifiScanElapsedTime) > mWifiScanFrequency)) { - - if (mWifiLastScanResults == null) { - mWifiLastScanResults = new ArrayList<ScanResult>(); - } else { - mWifiLastScanResults.clear(); - } - mWifiLastScanResults.addAll(scanResults); - mLastWifiScanElapsedTime = now; - mLastWifiScanRealTime = System.currentTimeMillis(); - - log("updateWifIScanResults(): " + mWifiLastScanResults.size() + " APs"); - updateLocation(); - - } - } - - /** - * Notifies the provider if Wifi has been enabled or disabled - * by the user - * - * @param enabled true if wifi is enabled; false otherwise - */ - public void updateWifiEnabledState(boolean enabled) { - mWifiEnabled = enabled; - - log("updateWifiEnabledState(): " + enabled); - - // Force location update - forceLocation(); - } - - public void addListener(String[] applications) { - if (applications != null) { - for (String app : applications) { - String a = app.replaceAll("com.google.android.", ""); - a = a.replaceAll("com.android.", ""); - mApplications.add(a); - log("addListener(): " + a); - } - } - } - - public void removeListener(String[] applications) { - if (applications != null) { - for (String app : applications) { - String a = app.replaceAll("com.google.android.", ""); - a = a.replaceAll("com.android.", ""); - mApplications.remove(a); - log("removeListener(): " + a); - } - } - } - - private void clearLocation() { - mLocation.setAccuracy(-1); - updateStatus(TEMPORARILY_UNAVAILABLE); - } - - private void forceLocation() { - if (mWifiEnabled) { - // Force another wifi scan - mWifiLastScanResults = null; - mLastWifiScanTriggerTime = 0; - mLastWifiScanElapsedTime = 0; - mLastWifiScanRealTime = 0; - } else { - // Force another cell location request - mLastCellLockTime = 0; - mLastCellStateChangeTime = SystemClock.elapsedRealtime(); - } - } - - private void updateStatus(int status) { - if (status != mStatus) { - mStatus = status; - mStatusUpdateTime = SystemClock.elapsedRealtime(); - } - } - - /** - * Gets location from the server is applications are tracking this provider - * - */ - private void updateLocation() { - - // If not being tracked, no need to do anything. - if (!mTracking) { - return; - } - - // If network is not available, can't do anything - if (mNetworkState != AVAILABLE) { - return; - } - - final long now = SystemClock.elapsedRealtime(); - - // There is a pending network request - if ((mLastNetworkQueryTime != 0) && - (mLastNetworkQueryTime > mLastSuccessfulNetworkQueryTime) && - ((now - mLastNetworkQueryTime) <= MIN_NETWORK_RETRY_MILLIS)) { - return; - } - - // Don't include wifi points if they're too old - List<ScanResult> scanResults = null; - if (mWifiEnabled && (mWifiLastScanResults != null && - ((now - mLastWifiScanElapsedTime) < (mWifiScanFrequency + MAX_TIME_TO_WAIT_FOR_RADIO)))) { - scanResults = mWifiLastScanResults; - } - - // If no valid cell information available - boolean noCell = mCellState == null || !mCellState.isValid(); - - // If no valid wifi information available - boolean noWifi = scanResults == null || (scanResults.size() == 0); - - // If no cell-id or wi-fi update, just return invalid location - if (noCell && noWifi) { - clearLocation(); - return; - } - - // What kind of a network location request was it - int trigger; - if (!mWifiEnabled) { - if (!noCell) { - trigger = GDebugProfile.TRIGGER_CELL_AND_WIFI_CHANGE; - } else { - trigger = GDebugProfile.TRIGGER_WIFI_CHANGE; - } - } else { - trigger = GDebugProfile.TRIGGER_CELL_CHANGE; - } - - try { - mLastNetworkQueryTime = now; - mMasfClient.getNetworkLocation(mApplications, trigger, mCellState, mCellHistory, - scanResults, mLastWifiScanRealTime, new Callback() { - public void locationReceived(Location location, boolean networkSuccessful) { - // If location is valid and not the same as previously known location - if ((location != null) && (location.getAccuracy() > 0) && - (location.getTime() != mLocation.getTime())) { - mLocation.set(location); - updateStatus(AVAILABLE); - } else { - // Location is unavailable - clearLocation(); - } - - // Even if no location is available, network request could have succeeded - if (networkSuccessful) { - mLastSuccessfulNetworkQueryTime = SystemClock.elapsedRealtime(); - } - - } - }); - } catch(Exception e) { - Log.e(TAG, "updateLocation got exception:", e); - } - } - - public interface Callback { - - /** - * Callback function to notify of a received network location - * - * @param location location object that is received. may be null if not a valid location - * @param successful true if network query was successful, even if no location was found - */ - void locationReceived(Location location, boolean successful); - } - - private void log(String log) { - if (Log.isLoggable(TAG, Log.DEBUG)) { - Log.d(TAG, log); - } - } - -} diff --git a/location/java/com/android/internal/location/ProtoRequestListener.java b/location/java/com/android/internal/location/ProtoRequestListener.java deleted file mode 100644 index d73cd05..0000000 --- a/location/java/com/android/internal/location/ProtoRequestListener.java +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2007 The Android Open Source Project - -package com.android.internal.location; - -import com.google.common.io.GoogleHttpConnection; -import com.google.common.io.protocol.ProtoBuf; -import com.google.masf.ServiceCallback; -import com.google.masf.protocol.Request; -import com.google.masf.protocol.Response; -import com.google.masf.services.AsyncResult; - -import java.io.IOException; -import java.io.InputStream; - -import android.util.Log; - -/** - * Listener for protocol buffer requests - * - * {@hide} - */ - -public class ProtoRequestListener implements Request.Listener { - private final static String TAG = "ProtoRequestListener"; - private AsyncResult result; - private ProtoBuf protoResponse; - - /** - * @return the asynchronous result object - */ - public AsyncResult getAsyncResult() { - return result; - } - - /** - * Constructor for a ProtoRequestListener - * - * @param protoResponse ProtoBuf with correct type to fill response with - * @param callback function to call after completed request (may be null) - */ - public ProtoRequestListener(ProtoBuf protoResponse, ServiceCallback callback) { - this.result = new AsyncResult(callback); - this.protoResponse = protoResponse; - } - - public boolean requestComplete(Request request, Response response) - throws IOException { - InputStream is = response.getInputStream(); - if (response.getStatusCode() == GoogleHttpConnection.HTTP_OK) { - protoResponse.parse(is); - result.setResult(protoResponse); - } else { - result.setResult(null); - } - return true; - } - - public void requestException(Request request, Exception exception) { - Log.e(TAG, "requestException()", exception); - } -} diff --git a/location/java/com/android/internal/location/protocol/GAddress.java b/location/java/com/android/internal/location/protocol/GAddress.java deleted file mode 100644 index 86a3912..0000000 --- a/location/java/com/android/internal/location/protocol/GAddress.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GAddress { - static final int FORMATTED_ADDRESS_LINE = 1; - static final int COMPONENT = 2; -} - diff --git a/location/java/com/android/internal/location/protocol/GAddressComponent.java b/location/java/com/android/internal/location/protocol/GAddressComponent.java deleted file mode 100644 index a06a23d..0000000 --- a/location/java/com/android/internal/location/protocol/GAddressComponent.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GAddressComponent { - static final int NAME = 1; - static final int FEATURE_TYPE = 2; -} - diff --git a/location/java/com/android/internal/location/protocol/GAppProfile.java b/location/java/com/android/internal/location/protocol/GAppProfile.java deleted file mode 100644 index e3332eb..0000000 --- a/location/java/com/android/internal/location/protocol/GAppProfile.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GAppProfile { - static final int APP_NAME = 1; - static final int APP_KEY = 2; - static final int REQUEST_TYPE = 3; - static final int SEARCH_TYPE = 4; - static final int SEARCH_TERM = 5; -} - diff --git a/location/java/com/android/internal/location/protocol/GCellularPlatformProfile.java b/location/java/com/android/internal/location/protocol/GCellularPlatformProfile.java deleted file mode 100644 index a17da20..0000000 --- a/location/java/com/android/internal/location/protocol/GCellularPlatformProfile.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GCellularPlatformProfile { - static final int RADIO_TYPE_GPRS = 3; - static final int RADIO_TYPE_CDMA = 4; - static final int RADIO_TYPE_WCDMA = 5; - - static final int RADIO_TYPE = 1; - static final int CARRIER = 2; - static final int IP = 3; - static final int HOME_MNC = 4; - static final int HOME_MCC = 5; -} - diff --git a/location/java/com/android/internal/location/protocol/GCellularProfile.java b/location/java/com/android/internal/location/protocol/GCellularProfile.java deleted file mode 100644 index 8c85bf7..0000000 --- a/location/java/com/android/internal/location/protocol/GCellularProfile.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GCellularProfile { - static final int PRIMARY_CELL = 1; - static final int TIMESTAMP = 2; - static final int NEIGHBORS = 3; - static final int HISTORICAL_CELLS = 4; - static final int PREFETCH_MODE = 5; -} - diff --git a/location/java/com/android/internal/location/protocol/GDebugProfile.java b/location/java/com/android/internal/location/protocol/GDebugProfile.java deleted file mode 100644 index b964387..0000000 --- a/location/java/com/android/internal/location/protocol/GDebugProfile.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GDebugProfile { - static final int TRIGGER_CELL_CHANGE = 1; - static final int TRIGGER_WIFI_CHANGE = 2; - static final int TRIGGER_CELL_AND_WIFI_CHANGE = 3; - static final int TRIGGER_GPS_CHANGE = 4; - static final int TRIGGER_OTHER = 5; - static final int TRIGGER_COLLECTION_START_BURST = 6; - static final int TRIGGER_COLLECTION_RESTART_BURST = 7; - static final int TRIGGER_COLLECTION_CONTINUE_BURST = 8; - static final int TRIGGER_COLLECTION_END_BURST = 9; - static final int TRIGGER_COLLECTION_END_BURST_AT_SAME_LOCATION = 10; - static final int TRIGGER_COLLECTION_MOVED_DISTANCE = 11; - - static final int TRIGGER = 1; - static final int ACTUAL_REQUEST = 2; - static final int CACHE_LOCATION = 3; - static final int DEVICE_RESTART = 4; -} - diff --git a/location/java/com/android/internal/location/protocol/GDeviceLocation.java b/location/java/com/android/internal/location/protocol/GDeviceLocation.java deleted file mode 100644 index 462ab07..0000000 --- a/location/java/com/android/internal/location/protocol/GDeviceLocation.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GDeviceLocation { - static final int LOCATION = 1; - static final int CELL = 2; - static final int WIFI_DEVICE = 3; -} - diff --git a/location/java/com/android/internal/location/protocol/GFeature.java b/location/java/com/android/internal/location/protocol/GFeature.java deleted file mode 100644 index 73fc1b3..0000000 --- a/location/java/com/android/internal/location/protocol/GFeature.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GFeature { - static final int NAME = 1; - static final int FEATURE_TYPE = 2; - static final int ADDRESS = 3; - static final int BOUNDS = 4; - static final int CENTER = 5; - - static final int FEATURE_TYPE_UNKNOWN_TYPE = 0; - static final int FEATURE_TYPE_COUNTRY = 1; - static final int FEATURE_TYPE_COUNTRY_CODE = 2; - static final int FEATURE_TYPE_ADMINISTRATIVE_AREA = 3; - static final int FEATURE_TYPE_SUB_ADMINISTRATIVE_AREA = 4; - static final int FEATURE_TYPE_LOCALITY = 5; - static final int FEATURE_TYPE_SUB_LOCALITY = 6; - static final int FEATURE_TYPE_PREMISES = 7; - static final int FEATURE_TYPE_THOROUGHFARE = 8; - static final int FEATURE_TYPE_SUB_THOROUGHFARE = 9; - static final int FEATURE_TYPE_POST_CODE = 10; -} - diff --git a/location/java/com/android/internal/location/protocol/GGeocodeRequest.java b/location/java/com/android/internal/location/protocol/GGeocodeRequest.java deleted file mode 100644 index 4d56cc0..0000000 --- a/location/java/com/android/internal/location/protocol/GGeocodeRequest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GGeocodeRequest { - static final int NUM_FEATURE_LIMIT = 1; - static final int INCLUDE_BOUNDING_BOXES = 2; - static final int BOUNDING_BOX = 3; -} - diff --git a/location/java/com/android/internal/location/protocol/GGpsProfile.java b/location/java/com/android/internal/location/protocol/GGpsProfile.java deleted file mode 100644 index be69eb0..0000000 --- a/location/java/com/android/internal/location/protocol/GGpsProfile.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GGpsProfile { - static final int FIX_QUALITY_INVALID = 0; - static final int FIX_QUALITY_GPS_FIX = 1; - static final int FIX_QUALITY_DGPS_FIX = 2; - - static final int GPS_FIX_TYPE = 1; - static final int PDOP = 2; - static final int HDOP = 3; - static final int VDOP = 4; -} - diff --git a/location/java/com/android/internal/location/protocol/GLatLng.java b/location/java/com/android/internal/location/protocol/GLatLng.java deleted file mode 100644 index 90e23df..0000000 --- a/location/java/com/android/internal/location/protocol/GLatLng.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GLatLng { - static final int LAT_E7 = 1; - static final int LNG_E7 = 2; -} - diff --git a/location/java/com/android/internal/location/protocol/GLocReply.java b/location/java/com/android/internal/location/protocol/GLocReply.java deleted file mode 100644 index 7a0504f..0000000 --- a/location/java/com/android/internal/location/protocol/GLocReply.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GLocReply { - static final int STATUS = 1; - static final int REPLY_ELEMENTS = 2; - static final int PLATFORM_KEY = 3; -} - diff --git a/location/java/com/android/internal/location/protocol/GLocReplyElement.java b/location/java/com/android/internal/location/protocol/GLocReplyElement.java deleted file mode 100644 index bc47fcf..0000000 --- a/location/java/com/android/internal/location/protocol/GLocReplyElement.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GLocReplyElement { - static final int STATUS = 1; - static final int LOCATION = 2; - static final int DEVICE_LOCATION = 3; -} - diff --git a/location/java/com/android/internal/location/protocol/GLocRequest.java b/location/java/com/android/internal/location/protocol/GLocRequest.java deleted file mode 100644 index 7761c11..0000000 --- a/location/java/com/android/internal/location/protocol/GLocRequest.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GLocRequest { - static final int PLATFORM_PROFILE = 1; - static final int APP_PROFILES = 2; - static final int USER_PROFILE = 3; - static final int REQUEST_ELEMENTS = 4; - static final int MASF_CLIENT_INFO = 257; -} - diff --git a/location/java/com/android/internal/location/protocol/GLocRequestElement.java b/location/java/com/android/internal/location/protocol/GLocRequestElement.java deleted file mode 100644 index d758953..0000000 --- a/location/java/com/android/internal/location/protocol/GLocRequestElement.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GLocRequestElement { - static final int CELLULAR_PROFILE = 1; - static final int WIFI_PROFILE = 2; - static final int LOCATION = 3; - static final int GEOCODE = 4; - static final int DEBUG_PROFILE = 99; -} - diff --git a/location/java/com/android/internal/location/protocol/GLocation.java b/location/java/com/android/internal/location/protocol/GLocation.java deleted file mode 100644 index 9a1eb1f..0000000 --- a/location/java/com/android/internal/location/protocol/GLocation.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GLocation { - static final int LOCTYPE_GPS = 0; - static final int LOCTYPE_MAPCENTER = 1; - static final int LOCTYPE_CENTROID = 2; - static final int LOCTYPE_TOWER_LOCATION = 3; - - static final int LAT_LNG = 1; - static final int SOURCE = 2; - static final int ACCURACY = 3; - static final int CONFIDENCE = 4; - static final int FEATURE = 5; - static final int TIMESTAMP = 6; - static final int OBSOLETE = 7; - static final int LOC_TYPE = 8; - static final int MISC = 9; - static final int ALTITUDE = 10; - static final int VERTICAL_ACCURACY = 11; - static final int VELOCITY = 12; - static final int HEADING = 13; - static final int GPS_PROFILE = 14; - static final int LOCATION_STRING = 15; -} - diff --git a/location/java/com/android/internal/location/protocol/GPlatformProfile.java b/location/java/com/android/internal/location/protocol/GPlatformProfile.java deleted file mode 100644 index 32a1f8f..0000000 --- a/location/java/com/android/internal/location/protocol/GPlatformProfile.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GPlatformProfile { - static final int VERSION = 1; - static final int PLATFORM = 2; - static final int PLATFORM_KEY = 3; - static final int DISTRIBUTION_CHANNEL = 4; - static final int LOCALE = 5; - static final int CELLULAR_PLATFORM_PROFILE = 6; - static final int WIFI_PLATFORM_PROFILE = 7; -} - diff --git a/location/java/com/android/internal/location/protocol/GPrefetchMode.java b/location/java/com/android/internal/location/protocol/GPrefetchMode.java deleted file mode 100644 index 041b686..0000000 --- a/location/java/com/android/internal/location/protocol/GPrefetchMode.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GPrefetchMode { - static final int PREFETCH_MODE_NO_PREFETCH = 0; - static final int PREFETCH_MODE_REQUESTED_NEIGHBORS_ONLY = 1; - static final int PREFETCH_MODE_MORE_NEIGHBORS = 2; - -} - diff --git a/location/java/com/android/internal/location/protocol/GRectangle.java b/location/java/com/android/internal/location/protocol/GRectangle.java deleted file mode 100644 index b8412e6..0000000 --- a/location/java/com/android/internal/location/protocol/GRectangle.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GRectangle { - static final int LOWER_LEFT = 1; - static final int UPPER_RIGHT = 2; -} - diff --git a/location/java/com/android/internal/location/protocol/GUserProfile.java b/location/java/com/android/internal/location/protocol/GUserProfile.java deleted file mode 100644 index 2ce962c..0000000 --- a/location/java/com/android/internal/location/protocol/GUserProfile.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GUserProfile { - static final int USER_NAME = 1; - static final int AUTH_TOKEN = 2; -} - diff --git a/location/java/com/android/internal/location/protocol/GWifiDevice.java b/location/java/com/android/internal/location/protocol/GWifiDevice.java deleted file mode 100644 index 62bd03a..0000000 --- a/location/java/com/android/internal/location/protocol/GWifiDevice.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GWifiDevice { - static final int MAC = 1; - static final int SSID = 2; - static final int CHANNEL = 3; - static final int RSSI = 4; - static final int NOISE = 5; -} - diff --git a/location/java/com/android/internal/location/protocol/GWifiPlatformProfile.java b/location/java/com/android/internal/location/protocol/GWifiPlatformProfile.java deleted file mode 100644 index 7f1efcb..0000000 --- a/location/java/com/android/internal/location/protocol/GWifiPlatformProfile.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GWifiPlatformProfile { - static final int RADIO_TYPE_WIFI802_11_A = 1; - static final int RADIO_TYPE_WIFI802_11_B = 2; - static final int RADIO_TYPE_WIFI802_11_G = 3; - static final int RADIO_TYPE_WIFI802_11_N = 4; - - static final int SCANNER_MAC = 1; - static final int SCANNER_IP = 2; - static final int RADIO_TYPE = 3; -} - diff --git a/location/java/com/android/internal/location/protocol/GWifiProfile.java b/location/java/com/android/internal/location/protocol/GWifiProfile.java deleted file mode 100644 index e731027..0000000 --- a/location/java/com/android/internal/location/protocol/GWifiProfile.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface GWifiProfile { - static final int TIMESTAMP = 1; - static final int WIFI_DEVICES = 2; - static final int PREFETCH_MODE = 3; -} - diff --git a/location/java/com/android/internal/location/protocol/GaddressMessageTypes.java b/location/java/com/android/internal/location/protocol/GaddressMessageTypes.java deleted file mode 100644 index 7b6ffd0..0000000 --- a/location/java/com/android/internal/location/protocol/GaddressMessageTypes.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -import com.google.common.io.protocol.ProtoBufType; - -public class GaddressMessageTypes { - public static final ProtoBufType GADDRESS = new ProtoBufType(); - public static final ProtoBufType GADDRESS_COMPONENT = new ProtoBufType(); - - static { - GADDRESS - .addElement(ProtoBufType.REPEATED | ProtoBufType.TYPE_DATA, - GAddress.FORMATTED_ADDRESS_LINE, null) - .addElement(ProtoBufType.REPEATED | ProtoBufType.TYPE_MESSAGE, - GAddress.COMPONENT, GADDRESS_COMPONENT); - - GADDRESS_COMPONENT - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_DATA, - GAddressComponent.NAME, null) - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_INT32, - GAddressComponent.FEATURE_TYPE, null); - - } -} diff --git a/location/java/com/android/internal/location/protocol/GcellularMessageTypes.java b/location/java/com/android/internal/location/protocol/GcellularMessageTypes.java deleted file mode 100644 index 37a6d52..0000000 --- a/location/java/com/android/internal/location/protocol/GcellularMessageTypes.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -import com.google.common.io.protocol.ProtoBufType; - -public class GcellularMessageTypes { - public static final ProtoBufType GCELL = new ProtoBufType(); - public static final ProtoBufType GCELLULAR_PROFILE = new ProtoBufType(); - - static { - GCELL - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_INT32, - GCell.LAC, null) - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_INT32, - GCell.CELLID, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GCell.MNC, new Long(-1)) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GCell.MCC, new Long(-1)) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GCell.RSSI, new Long(-9999)) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GCell.AGE, new Long(0)) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GCell.TIMING_ADVANCE, new Long(-1)) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GCell.PRIMARY_SCRAMBLING_CODE, null); - - GCELLULAR_PROFILE - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_MESSAGE, - GCellularProfile.PRIMARY_CELL, GCELL) - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_INT64, - GCellularProfile.TIMESTAMP, null) - .addElement(ProtoBufType.REPEATED | ProtoBufType.TYPE_MESSAGE, - GCellularProfile.NEIGHBORS, GCELL) - .addElement(ProtoBufType.REPEATED | ProtoBufType.TYPE_MESSAGE, - GCellularProfile.HISTORICAL_CELLS, GCELL) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GCellularProfile.PREFETCH_MODE, null); - - } -} diff --git a/location/java/com/android/internal/location/protocol/GdebugprofileMessageTypes.java b/location/java/com/android/internal/location/protocol/GdebugprofileMessageTypes.java deleted file mode 100644 index 9a51efe..0000000 --- a/location/java/com/android/internal/location/protocol/GdebugprofileMessageTypes.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -import com.google.common.io.protocol.ProtoBuf; -import com.google.common.io.protocol.ProtoBufType; - -public class GdebugprofileMessageTypes { - public static final ProtoBufType GDEBUG_PROFILE = new ProtoBufType(); - - static { - GDEBUG_PROFILE - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GDebugProfile.TRIGGER, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_BOOL, - GDebugProfile.ACTUAL_REQUEST, ProtoBuf.TRUE) - .addElement(ProtoBufType.REPEATED | ProtoBufType.TYPE_MESSAGE, - GDebugProfile.CACHE_LOCATION, GlocationMessageTypes.GDEVICE_LOCATION) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_BOOL, - GDebugProfile.DEVICE_RESTART, ProtoBuf.FALSE); - - } -} diff --git a/location/java/com/android/internal/location/protocol/GfeatureMessageTypes.java b/location/java/com/android/internal/location/protocol/GfeatureMessageTypes.java deleted file mode 100644 index 24b182a..0000000 --- a/location/java/com/android/internal/location/protocol/GfeatureMessageTypes.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -import com.google.common.io.protocol.ProtoBufType; - -public class GfeatureMessageTypes { - public static final ProtoBufType GFEATURE_TYPE = new ProtoBufType(); - public static final ProtoBufType GFEATURE = new ProtoBufType(); - - static { - GFEATURE - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_DATA, - GFeature.NAME, null) - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_INT32, - GFeature.FEATURE_TYPE, null) - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_MESSAGE, - GFeature.ADDRESS, GaddressMessageTypes.GADDRESS) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GFeature.BOUNDS, GrectangleMessageTypes.GRECTANGLE) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GFeature.CENTER, GlatlngMessageTypes.GLAT_LNG); - - } -} diff --git a/location/java/com/android/internal/location/protocol/GlatlngMessageTypes.java b/location/java/com/android/internal/location/protocol/GlatlngMessageTypes.java deleted file mode 100644 index b6a9086..0000000 --- a/location/java/com/android/internal/location/protocol/GlatlngMessageTypes.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -import com.google.common.io.protocol.ProtoBufType; - -public class GlatlngMessageTypes { - public static final ProtoBufType GLAT_LNG = new ProtoBufType(); - - static { - GLAT_LNG - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_FIXED32, - GLatLng.LAT_E7, null) - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_FIXED32, - GLatLng.LNG_E7, null); - - } -} diff --git a/location/java/com/android/internal/location/protocol/GlocationMessageTypes.java b/location/java/com/android/internal/location/protocol/GlocationMessageTypes.java deleted file mode 100644 index 067d47c..0000000 --- a/location/java/com/android/internal/location/protocol/GlocationMessageTypes.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -import com.google.common.io.protocol.ProtoBufType; - -public class GlocationMessageTypes { - public static final ProtoBufType GGPS_PROFILE = new ProtoBufType(); - public static final ProtoBufType GLOCATION = new ProtoBufType(); - public static final ProtoBufType GDEVICE_LOCATION = new ProtoBufType(); - public static final ProtoBufType GCELLULAR_PLATFORM_PROFILE = new ProtoBufType(); - public static final ProtoBufType GWIFI_PLATFORM_PROFILE = new ProtoBufType(); - public static final ProtoBufType GPREFETCH_MODE = new ProtoBufType(); - public static final ProtoBufType GPLATFORM_PROFILE = new ProtoBufType(); - public static final ProtoBufType GAPP_PROFILE = new ProtoBufType(); - public static final ProtoBufType GUSER_PROFILE = new ProtoBufType(); - - static { - GGPS_PROFILE - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GGpsProfile.GPS_FIX_TYPE, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GGpsProfile.PDOP, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GGpsProfile.HDOP, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GGpsProfile.VDOP, null); - - GLOCATION - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GLocation.LAT_LNG, GlatlngMessageTypes.GLAT_LNG) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GLocation.SOURCE, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GLocation.ACCURACY, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GLocation.CONFIDENCE, null) - .addElement(ProtoBufType.REPEATED | ProtoBufType.TYPE_MESSAGE, - GLocation.FEATURE, GfeatureMessageTypes.GFEATURE) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT64, - GLocation.TIMESTAMP, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_BOOL, - GLocation.OBSOLETE, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GLocation.LOC_TYPE, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GLocation.MISC, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GLocation.ALTITUDE, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GLocation.VERTICAL_ACCURACY, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GLocation.VELOCITY, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GLocation.HEADING, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GLocation.GPS_PROFILE, GGPS_PROFILE) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GLocation.LOCATION_STRING, null); - - GDEVICE_LOCATION - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GDeviceLocation.LOCATION, GLOCATION) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GDeviceLocation.CELL, GcellularMessageTypes.GCELL) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GDeviceLocation.WIFI_DEVICE, GwifiMessageTypes.GWIFI_DEVICE); - - GCELLULAR_PLATFORM_PROFILE - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GCellularPlatformProfile.RADIO_TYPE, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GCellularPlatformProfile.CARRIER, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GCellularPlatformProfile.IP, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GCellularPlatformProfile.HOME_MNC, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GCellularPlatformProfile.HOME_MCC, null); - - GWIFI_PLATFORM_PROFILE - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GWifiPlatformProfile.SCANNER_MAC, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GWifiPlatformProfile.SCANNER_IP, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GWifiPlatformProfile.RADIO_TYPE, null); - - GPLATFORM_PROFILE - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_DATA, - GPlatformProfile.VERSION, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GPlatformProfile.PLATFORM, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GPlatformProfile.PLATFORM_KEY, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GPlatformProfile.DISTRIBUTION_CHANNEL, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GPlatformProfile.LOCALE, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GPlatformProfile.CELLULAR_PLATFORM_PROFILE, GCELLULAR_PLATFORM_PROFILE) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GPlatformProfile.WIFI_PLATFORM_PROFILE, GWIFI_PLATFORM_PROFILE); - - GAPP_PROFILE - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GAppProfile.APP_NAME, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GAppProfile.APP_KEY, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GAppProfile.REQUEST_TYPE, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GAppProfile.SEARCH_TYPE, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GAppProfile.SEARCH_TERM, null); - - GUSER_PROFILE - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GUserProfile.USER_NAME, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GUserProfile.AUTH_TOKEN, null); - - } -} diff --git a/location/java/com/android/internal/location/protocol/GrectangleMessageTypes.java b/location/java/com/android/internal/location/protocol/GrectangleMessageTypes.java deleted file mode 100644 index aeb0047..0000000 --- a/location/java/com/android/internal/location/protocol/GrectangleMessageTypes.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -import com.google.common.io.protocol.ProtoBufType; - -public class GrectangleMessageTypes { - public static final ProtoBufType GRECTANGLE = new ProtoBufType(); - - static { - GRECTANGLE - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_MESSAGE, - GRectangle.LOWER_LEFT, GlatlngMessageTypes.GLAT_LNG) - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_MESSAGE, - GRectangle.UPPER_RIGHT, GlatlngMessageTypes.GLAT_LNG); - - } -} diff --git a/location/java/com/android/internal/location/protocol/GwifiMessageTypes.java b/location/java/com/android/internal/location/protocol/GwifiMessageTypes.java deleted file mode 100644 index cd7119b..0000000 --- a/location/java/com/android/internal/location/protocol/GwifiMessageTypes.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -import com.google.common.io.protocol.ProtoBufType; - -public class GwifiMessageTypes { - public static final ProtoBufType GWIFI_DEVICE = new ProtoBufType(); - public static final ProtoBufType GWIFI_PROFILE = new ProtoBufType(); - - static { - GWIFI_DEVICE - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_DATA, - GWifiDevice.MAC, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GWifiDevice.SSID, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GWifiDevice.CHANNEL, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GWifiDevice.RSSI, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GWifiDevice.NOISE, null); - - GWIFI_PROFILE - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_INT64, - GWifiProfile.TIMESTAMP, null) - .addElement(ProtoBufType.REPEATED | ProtoBufType.TYPE_MESSAGE, - GWifiProfile.WIFI_DEVICES, GWIFI_DEVICE) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_INT32, - GWifiProfile.PREFETCH_MODE, null); - - } -} diff --git a/location/java/com/android/internal/location/protocol/LocserverMessageTypes.java b/location/java/com/android/internal/location/protocol/LocserverMessageTypes.java deleted file mode 100644 index 8ffd004..0000000 --- a/location/java/com/android/internal/location/protocol/LocserverMessageTypes.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -import com.google.common.io.protocol.ProtoBuf; -import com.google.common.io.protocol.ProtoBufType; - -public class LocserverMessageTypes { - public static final ProtoBufType RESPONSE_CODES = new ProtoBufType(); - public static final ProtoBufType GLOC_REQUEST_ELEMENT = new ProtoBufType(); - public static final ProtoBufType GLOC_REQUEST = new ProtoBufType(); - public static final ProtoBufType GGEOCODE_REQUEST = new ProtoBufType(); - public static final ProtoBufType GLOC_REPLY_ELEMENT = new ProtoBufType(); - public static final ProtoBufType GLOC_REPLY = new ProtoBufType(); - - static { - GLOC_REQUEST_ELEMENT - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GLocRequestElement.CELLULAR_PROFILE, GcellularMessageTypes.GCELLULAR_PROFILE) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GLocRequestElement.WIFI_PROFILE, GwifiMessageTypes.GWIFI_PROFILE) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GLocRequestElement.LOCATION, GlocationMessageTypes.GLOCATION) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GLocRequestElement.GEOCODE, GGEOCODE_REQUEST) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GLocRequestElement.DEBUG_PROFILE, GdebugprofileMessageTypes.GDEBUG_PROFILE); - - GLOC_REQUEST - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_MESSAGE, - GLocRequest.PLATFORM_PROFILE, GlocationMessageTypes.GPLATFORM_PROFILE) - .addElement(ProtoBufType.REPEATED | ProtoBufType.TYPE_MESSAGE, - GLocRequest.APP_PROFILES, GlocationMessageTypes.GAPP_PROFILE) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GLocRequest.USER_PROFILE, GlocationMessageTypes.GUSER_PROFILE) - .addElement(ProtoBufType.REPEATED | ProtoBufType.TYPE_MESSAGE, - GLocRequest.REQUEST_ELEMENTS, GLOC_REQUEST_ELEMENT) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GLocRequest.MASF_CLIENT_INFO, null); - - GGEOCODE_REQUEST - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_FIXED32, - GGeocodeRequest.NUM_FEATURE_LIMIT, new Long(1)) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_BOOL, - GGeocodeRequest.INCLUDE_BOUNDING_BOXES, ProtoBuf.FALSE) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GGeocodeRequest.BOUNDING_BOX, GrectangleMessageTypes.GRECTANGLE); - - GLOC_REPLY_ELEMENT - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_INT32, - GLocReplyElement.STATUS, null) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_MESSAGE, - GLocReplyElement.LOCATION, GlocationMessageTypes.GLOCATION) - .addElement(ProtoBufType.REPEATED | ProtoBufType.TYPE_MESSAGE, - GLocReplyElement.DEVICE_LOCATION, GlocationMessageTypes.GDEVICE_LOCATION); - - GLOC_REPLY - .addElement(ProtoBufType.REQUIRED | ProtoBufType.TYPE_INT32, - GLocReply.STATUS, null) - .addElement(ProtoBufType.REPEATED | ProtoBufType.TYPE_MESSAGE, - GLocReply.REPLY_ELEMENTS, GLOC_REPLY_ELEMENT) - .addElement(ProtoBufType.OPTIONAL | ProtoBufType.TYPE_DATA, - GLocReply.PLATFORM_KEY, null); - - } -} diff --git a/location/java/com/android/internal/location/protocol/ResponseCodes.java b/location/java/com/android/internal/location/protocol/ResponseCodes.java deleted file mode 100644 index 2ea9318..0000000 --- a/location/java/com/android/internal/location/protocol/ResponseCodes.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 com.android.internal.location.protocol; - -public interface ResponseCodes { - static final int STATUS_STATUS_SUCCESS = 0; - static final int STATUS_STATUS_FAILED = 1; - static final int STATUS_AUTHORIZATION_REJECTED = 2; - static final int STATUS_NO_SOURCE_EXISTS = 3; - static final int STATUS_SIGNAL_TOO_WEAK = 4; - static final int STATUS_INVALID_REQUEST = 5; - static final int STATUS_INVALID_NUM_REQUESTS = 6; - static final int STATUS_INVALID_USERLOCATION_FORMAT = 7; - static final int STATUS_INVALID_OPERATION_CODE = 8; - static final int STATUS_INVALID_MAC_STRING_FORMAT = 9; - static final int STATUS_INVALID_CELLID_STRING_FORMAT = 10; - static final int STATUS_NON_EXISTENT_AP = 11; - static final int STATUS_NON_EXISTENT_CELLID = 12; - static final int STATUS_STATUS_FAILED_NO_SOURCE = 13; - static final int STATUS_STATUS_FAILED_NO_SAVE = 14; - static final int STATUS_PLATFORM_KEY_EXPIRED = 15; - static final int STATUS_NO_STORE_EXISTS = 16; - static final int STATUS_NO_CELLIDDATA_FOR_UPDATE = 17; - static final int STATUS_NON_SUPPORTED_OPERATION_IN_UPDATE = 18; - static final int STATUS_NON_SUPPORTED_OPERATION = 19; - static final int STATUS_STATUS_FAILED_NO_GEOCODE = 20; - static final int STATUS_BLACKLISTED_IP_CELLID = 100; - static final int STATUS_BLACKLISTED_IP_WIFI = 101; - -} - |