From 9db3d07b9620b4269ab33f78604a36327e536ce1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Queru Date: Thu, 12 Nov 2009 18:45:53 -0800 Subject: eclair snapshot --- location/java/android/location/Geocoder.java | 6 +- location/java/android/location/GpsStatus.java | 12 ++ .../java/android/location/IGpsStatusListener.aidl | 1 + .../java/android/location/ILocationManager.aidl | 3 + .../java/android/location/ILocationProvider.aidl | 3 +- .../android/location/INetInitiatedListener.aidl | 26 ++++ .../java/android/location/LocationManager.java | 163 ++++++++++++++++++--- 7 files changed, 186 insertions(+), 28 deletions(-) create mode 100755 location/java/android/location/INetInitiatedListener.aidl (limited to 'location/java/android') diff --git a/location/java/android/location/Geocoder.java b/location/java/android/location/Geocoder.java index 53e46b7..2ce1273 100644 --- a/location/java/android/location/Geocoder.java +++ b/location/java/android/location/Geocoder.java @@ -36,11 +36,11 @@ import java.util.List; * coordinate into a (partial) address. The amount of detail in a * reverse geocoded location description may vary, for example one * might contain the full street address of the closest building, while - * another might contain only a city name and postal code. + * another might contain only a city name and postal code. * * The Geocoder class requires a backend service that is not included in - * the core android framework. The Geocoder query methods will return an - * empty list if there no backend service in the platform. + * the core android framework. The Geocoder query methods will return an + * empty list if there no backend service in the platform. */ public final class Geocoder { private static final String TAG = "Geocoder"; diff --git a/location/java/android/location/GpsStatus.java b/location/java/android/location/GpsStatus.java index 2cda7fa..ce69ac1 100644 --- a/location/java/android/location/GpsStatus.java +++ b/location/java/android/location/GpsStatus.java @@ -115,6 +115,18 @@ public final class GpsStatus { void onGpsStatusChanged(int event); } + /** + * Used for receiving NMEA sentences from the GPS. + * NMEA 0183 is a standard for communicating with marine electronic devices + * and is a common method for receiving data from a GPS, typically over a serial port. + * See NMEA 0183 for more details. + * You can implement this interface and call {@link LocationManager#addNmeaListener} + * to receive NMEA data from the GPS engine. + */ + public interface NmeaListener { + void onNmeaReceived(long timestamp, String nmea); + } + GpsStatus() { for (int i = 0; i < mSatellites.length; i++) { mSatellites[i] = new GpsSatellite(i + 1); diff --git a/location/java/android/location/IGpsStatusListener.aidl b/location/java/android/location/IGpsStatusListener.aidl index 5dc0fe8..62b1c6b 100644 --- a/location/java/android/location/IGpsStatusListener.aidl +++ b/location/java/android/location/IGpsStatusListener.aidl @@ -29,4 +29,5 @@ oneway interface IGpsStatusListener void onSvStatusChanged(int svCount, in int[] prns, in float[] snrs, in float[] elevations, in float[] azimuths, int ephemerisMask, int almanacMask, int usedInFixMask); + void onNmeaReceived(long timestamp, String nmea); } diff --git a/location/java/android/location/ILocationManager.aidl b/location/java/android/location/ILocationManager.aidl index caf9516..b6c59d6 100644 --- a/location/java/android/location/ILocationManager.aidl +++ b/location/java/android/location/ILocationManager.aidl @@ -83,4 +83,7 @@ interface ILocationManager /* for installing external Location Providers */ void installLocationProvider(String name, ILocationProvider provider); void installGeocodeProvider(IGeocodeProvider provider); + + // for NI support + boolean sendNiResponse(int notifId, int userResponse); } diff --git a/location/java/android/location/ILocationProvider.aidl b/location/java/android/location/ILocationProvider.aidl index 4fe0494..7da16e4 100644 --- a/location/java/android/location/ILocationProvider.aidl +++ b/location/java/android/location/ILocationProvider.aidl @@ -17,6 +17,7 @@ package android.location; import android.location.Location; +import android.net.NetworkInfo; import android.os.Bundle; /** @@ -41,7 +42,7 @@ interface ILocationProvider { long getStatusUpdateTime(); void enableLocationTracking(boolean enable); void setMinTime(long minTime); - void updateNetworkState(int state); + void updateNetworkState(int state, in NetworkInfo info); void updateLocation(in Location location); boolean sendExtraCommand(String command, inout Bundle extras); void addListener(int uid); diff --git a/location/java/android/location/INetInitiatedListener.aidl b/location/java/android/location/INetInitiatedListener.aidl new file mode 100755 index 0000000..f2f5a32 --- /dev/null +++ b/location/java/android/location/INetInitiatedListener.aidl @@ -0,0 +1,26 @@ +/* +** +** Copyright 2008, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +package android.location; + +/** + * {@hide} + */ +interface INetInitiatedListener +{ + boolean sendNiResponse(int notifId, int userResponse); +} diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java index 86ea66f..94ced22 100644 --- a/location/java/android/location/LocationManager.java +++ b/location/java/android/location/LocationManager.java @@ -51,6 +51,8 @@ public class LocationManager { private ILocationManager mService; private final HashMap mGpsStatusListeners = new HashMap(); + private final HashMap mNmeaListeners = + new HashMap(); private final GpsStatus mGpsStatus = new GpsStatus(); /** @@ -68,7 +70,7 @@ public class LocationManager { * satellites. Depending on conditions, this provider may take a while to return * a location fix. * - * Requires the permission android.permissions.ACCESS_FINE_LOCATION. + * Requires the permission android.permission.ACCESS_FINE_LOCATION. * *

The extras Bundle for the GPS location provider can contain the * following key/value pairs: @@ -103,9 +105,6 @@ public class LocationManager { */ public static final String KEY_LOCATION_CHANGED = "location"; - /** @hide */ - public static final String SYSTEM_DIR = "/data/system/location"; - // Map from LocationListeners to their associated ListenerTransport objects private HashMap mListeners = new HashMap(); @@ -1123,49 +1122,103 @@ public class LocationManager { private class GpsStatusListenerTransport extends IGpsStatusListener.Stub { private final GpsStatus.Listener mListener; + private final GpsStatus.NmeaListener mNmeaListener; + + // This must not equal any of the GpsStatus event IDs + private static final int NMEA_RECEIVED = 1000; + + private class Nmea { + long mTimestamp; + String mNmea; + + Nmea(long timestamp, String nmea) { + mTimestamp = timestamp; + mNmea = nmea; + } + } + private ArrayList mNmeaBuffer; GpsStatusListenerTransport(GpsStatus.Listener listener) { mListener = listener; + mNmeaListener = null; + } + + GpsStatusListenerTransport(GpsStatus.NmeaListener listener) { + mNmeaListener = listener; + mListener = null; + mNmeaBuffer = new ArrayList(); } public void onGpsStarted() { - Message msg = Message.obtain(); - msg.what = GpsStatus.GPS_EVENT_STARTED; - mGpsHandler.sendMessage(msg); + if (mListener != null) { + Message msg = Message.obtain(); + msg.what = GpsStatus.GPS_EVENT_STARTED; + mGpsHandler.sendMessage(msg); + } } public void onGpsStopped() { - Message msg = Message.obtain(); - msg.what = GpsStatus.GPS_EVENT_STOPPED; - mGpsHandler.sendMessage(msg); + if (mListener != null) { + Message msg = Message.obtain(); + msg.what = GpsStatus.GPS_EVENT_STOPPED; + mGpsHandler.sendMessage(msg); + } } public void onFirstFix(int ttff) { - mGpsStatus.setTimeToFirstFix(ttff); - Message msg = Message.obtain(); - msg.what = GpsStatus.GPS_EVENT_FIRST_FIX; - mGpsHandler.sendMessage(msg); + if (mListener != null) { + mGpsStatus.setTimeToFirstFix(ttff); + Message msg = Message.obtain(); + msg.what = GpsStatus.GPS_EVENT_FIRST_FIX; + mGpsHandler.sendMessage(msg); + } } public void onSvStatusChanged(int svCount, int[] prns, float[] snrs, float[] elevations, float[] azimuths, int ephemerisMask, int almanacMask, int usedInFixMask) { - mGpsStatus.setStatus(svCount, prns, snrs, elevations, azimuths, - ephemerisMask, almanacMask, usedInFixMask); + if (mListener != null) { + mGpsStatus.setStatus(svCount, prns, snrs, elevations, azimuths, + ephemerisMask, almanacMask, usedInFixMask); + + Message msg = Message.obtain(); + msg.what = GpsStatus.GPS_EVENT_SATELLITE_STATUS; + // remove any SV status messages already in the queue + mGpsHandler.removeMessages(GpsStatus.GPS_EVENT_SATELLITE_STATUS); + mGpsHandler.sendMessage(msg); + } + } - Message msg = Message.obtain(); - msg.what = GpsStatus.GPS_EVENT_SATELLITE_STATUS; - // remove any SV status messages already in the queue - mGpsHandler.removeMessages(GpsStatus.GPS_EVENT_SATELLITE_STATUS); - mGpsHandler.sendMessage(msg); + public void onNmeaReceived(long timestamp, String nmea) { + if (mNmeaListener != null) { + synchronized (mNmeaBuffer) { + mNmeaBuffer.add(new Nmea(timestamp, nmea)); + } + Message msg = Message.obtain(); + msg.what = NMEA_RECEIVED; + // remove any NMEA_RECEIVED messages already in the queue + mGpsHandler.removeMessages(NMEA_RECEIVED); + mGpsHandler.sendMessage(msg); + } } private final Handler mGpsHandler = new Handler() { @Override public void handleMessage(Message msg) { - // synchronize on mGpsStatus to ensure the data is copied atomically. - synchronized(mGpsStatus) { - mListener.onGpsStatusChanged(msg.what); + if (msg.what == NMEA_RECEIVED) { + synchronized (mNmeaBuffer) { + int length = mNmeaBuffer.size(); + for (int i = 0; i < length; i++) { + Nmea nmea = mNmeaBuffer.get(i); + mNmeaListener.onNmeaReceived(nmea.mTimestamp, nmea.mNmea); + } + mNmeaBuffer.clear(); + } + } else { + // synchronize on mGpsStatus to ensure the data is copied atomically. + synchronized(mGpsStatus) { + mListener.onGpsStatusChanged(msg.what); + } } } }; @@ -1217,6 +1270,52 @@ public class LocationManager { } } + /** + * Adds an NMEA listener. + * + * @param listener a {#link GpsStatus.NmeaListener} object to register + * + * @return true if the listener was successfully added + * + * @throws SecurityException if the ACCESS_FINE_LOCATION permission is not present + */ + public boolean addNmeaListener(GpsStatus.NmeaListener listener) { + boolean result; + + if (mNmeaListeners.get(listener) != null) { + // listener is already registered + return true; + } + try { + GpsStatusListenerTransport transport = new GpsStatusListenerTransport(listener); + result = mService.addGpsStatusListener(transport); + if (result) { + mNmeaListeners.put(listener, transport); + } + } catch (RemoteException e) { + Log.e(TAG, "RemoteException in registerGpsStatusListener: ", e); + result = false; + } + + return result; + } + + /** + * Removes an NMEA listener. + * + * @param listener a {#link GpsStatus.NmeaListener} object to remove + */ + public void removeNmeaListener(GpsStatus.NmeaListener listener) { + try { + GpsStatusListenerTransport transport = mNmeaListeners.remove(listener); + if (transport != null) { + mService.removeGpsStatusListener(transport); + } + } catch (RemoteException e) { + Log.e(TAG, "RemoteException in unregisterGpsStatusListener: ", e); + } + } + /** * Retrieves information about the current status of the GPS engine. * This should only be called from the {@link GpsStatus.Listener#onGpsStatusChanged} @@ -1315,4 +1414,20 @@ public class LocationManager { Log.e(TAG, "RemoteException in reportLocation: ", e); } } + + /** + * Used by NetInitiatedActivity to report user response + * for network initiated GPS fix requests. + * + * {@hide} + */ + public boolean sendNiResponse(int notifId, int userResponse) { + try { + return mService.sendNiResponse(notifId, userResponse); + } catch (RemoteException e) { + Log.e(TAG, "RemoteException in sendNiResponse: ", e); + return false; + } + } + } -- cgit v1.1