diff options
author | destradaa <destradaa@google.com> | 2014-11-07 00:07:30 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-11-07 00:07:30 +0000 |
commit | 031550a31e56bb8300ba9d1225004581ec156777 (patch) | |
tree | 7ff7ec53077c87bfda0f28fd6ca0ff64bb7f2007 /location | |
parent | 587cdde2e2bf7e833e433c1edd6e8078832e327c (diff) | |
parent | 9ed36c42d8c3731b8ca631292881110eb8897cec (diff) | |
download | frameworks_base-031550a31e56bb8300ba9d1225004581ec156777.zip frameworks_base-031550a31e56bb8300ba9d1225004581ec156777.tar.gz frameworks_base-031550a31e56bb8300ba9d1225004581ec156777.tar.bz2 |
am 9ed36c42: Merge "Add support for GPS measurement/navigation message capabilities. b/16727892 b/16815124" into lmp-mr1-dev automerge: 992b9aa
* commit '9ed36c42d8c3731b8ca631292881110eb8897cec':
Add support for GPS measurement/navigation message capabilities. b/16727892 b/16815124
Diffstat (limited to 'location')
9 files changed, 104 insertions, 27 deletions
diff --git a/location/java/android/location/GpsMeasurementListenerTransport.java b/location/java/android/location/GpsMeasurementListenerTransport.java index 2d9a372..610da96 100644 --- a/location/java/android/location/GpsMeasurementListenerTransport.java +++ b/location/java/android/location/GpsMeasurementListenerTransport.java @@ -26,14 +26,12 @@ import android.os.RemoteException; */ class GpsMeasurementListenerTransport extends LocalListenerHelper<GpsMeasurementsEvent.Listener> { - private final Context mContext; private final ILocationManager mLocationManager; private final IGpsMeasurementsListener mListenerTransport = new ListenerTransport(); public GpsMeasurementListenerTransport(Context context, ILocationManager locationManager) { - super("GpsMeasurementListenerTransport"); - mContext = context; + super(context, "GpsMeasurementListenerTransport"); mLocationManager = locationManager; } @@ -41,7 +39,7 @@ class GpsMeasurementListenerTransport protected boolean registerWithServer() throws RemoteException { return mLocationManager.addGpsMeasurementsListener( mListenerTransport, - mContext.getPackageName()); + getContext().getPackageName()); } @Override @@ -59,7 +57,18 @@ class GpsMeasurementListenerTransport listener.onGpsMeasurementsReceived(event); } }; + foreach(operation); + } + @Override + public void onStatusChanged(final int status) { + ListenerOperation<GpsMeasurementsEvent.Listener> operation = + new ListenerOperation<GpsMeasurementsEvent.Listener>() { + @Override + public void execute(GpsMeasurementsEvent.Listener listener) throws RemoteException { + listener.onStatusChanged(status); + } + }; foreach(operation); } } diff --git a/location/java/android/location/GpsMeasurementsEvent.java b/location/java/android/location/GpsMeasurementsEvent.java index e04ed81..94ca920 100644 --- a/location/java/android/location/GpsMeasurementsEvent.java +++ b/location/java/android/location/GpsMeasurementsEvent.java @@ -32,6 +32,24 @@ import java.util.Collections; * @hide */ public class GpsMeasurementsEvent implements Parcelable { + + /** + * The system does not support tracking of GPS Measurements. This status will not change in the + * future. + */ + public static final int STATUS_NOT_SUPPORTED = 0; + + /** + * GPS Measurements are successfully being tracked, it will receive updates once they are + * available. + */ + public static final int STATUS_READY = 1; + + /** + * GPS provider or Location is disabled, updates will not be received until they are enabled. + */ + public static final int STATUS_GPS_LOCATION_DISABLED = 2; + private final GpsClock mClock; private final Collection<GpsMeasurement> mReadOnlyMeasurements; @@ -43,7 +61,16 @@ public class GpsMeasurementsEvent implements Parcelable { * @hide */ public interface Listener { + + /** + * Returns the latest collected GPS Measurements. + */ void onGpsMeasurementsReceived(GpsMeasurementsEvent eventArgs); + + /** + * Returns the latest status of the GPS Measurements sub-system. + */ + void onStatusChanged(int status); } public GpsMeasurementsEvent(GpsClock clock, GpsMeasurement[] measurements) { @@ -103,7 +130,9 @@ public class GpsMeasurementsEvent implements Parcelable { public void writeToParcel(Parcel parcel, int flags) { parcel.writeParcelable(mClock, flags); - GpsMeasurement[] measurementsArray = mReadOnlyMeasurements.toArray(new GpsMeasurement[0]); + int measurementsCount = mReadOnlyMeasurements.size(); + GpsMeasurement[] measurementsArray = + mReadOnlyMeasurements.toArray(new GpsMeasurement[measurementsCount]); parcel.writeInt(measurementsArray.length); parcel.writeTypedArray(measurementsArray, flags); } diff --git a/location/java/android/location/GpsNavigationMessageEvent.java b/location/java/android/location/GpsNavigationMessageEvent.java index 50ffa75..b61dac0 100644 --- a/location/java/android/location/GpsNavigationMessageEvent.java +++ b/location/java/android/location/GpsNavigationMessageEvent.java @@ -21,9 +21,6 @@ import android.os.Parcel; import android.os.Parcelable; import java.security.InvalidParameterException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; /** * A class implementing a container for data associated with a navigation message event. @@ -32,6 +29,24 @@ import java.util.Collections; * @hide */ public class GpsNavigationMessageEvent implements Parcelable { + + /** + * The system does not support tracking of GPS Navigation Messages. This status will not change + * in the future. + */ + public static int STATUS_NOT_SUPPORTED = 0; + + /** + * GPS Navigation Messages are successfully being tracked, it will receive updates once they are + * available. + */ + public static int STATUS_READY = 1; + + /** + * GPS provider or Location is disabled, updated will not be received until they are enabled. + */ + public static int STATUS_GPS_LOCATION_DISABLED = 2; + private final GpsNavigationMessage mNavigationMessage; /** @@ -42,7 +57,16 @@ public class GpsNavigationMessageEvent implements Parcelable { * @hide */ public interface Listener { + + /** + * Returns the latest collected GPS Navigation Message. + */ void onGpsNavigationMessageReceived(GpsNavigationMessageEvent event); + + /** + * Returns the latest status of the GPS Navigation Messages sub-system. + */ + void onStatusChanged(int status); } public GpsNavigationMessageEvent(GpsNavigationMessage message) { diff --git a/location/java/android/location/GpsNavigationMessageListenerTransport.java b/location/java/android/location/GpsNavigationMessageListenerTransport.java index ec4812b..f6ba407 100644 --- a/location/java/android/location/GpsNavigationMessageListenerTransport.java +++ b/location/java/android/location/GpsNavigationMessageListenerTransport.java @@ -26,7 +26,6 @@ import android.os.RemoteException; */ class GpsNavigationMessageListenerTransport extends LocalListenerHelper<GpsNavigationMessageEvent.Listener> { - private final Context mContext; private final ILocationManager mLocationManager; private final IGpsNavigationMessageListener mListenerTransport = new ListenerTransport(); @@ -34,8 +33,7 @@ class GpsNavigationMessageListenerTransport public GpsNavigationMessageListenerTransport( Context context, ILocationManager locationManager) { - super("GpsNavigationMessageListenerTransport"); - mContext = context; + super(context, "GpsNavigationMessageListenerTransport"); mLocationManager = locationManager; } @@ -43,7 +41,7 @@ class GpsNavigationMessageListenerTransport protected boolean registerWithServer() throws RemoteException { return mLocationManager.addGpsNavigationMessageListener( mListenerTransport, - mContext.getPackageName()); + getContext().getPackageName()); } @Override @@ -62,7 +60,19 @@ class GpsNavigationMessageListenerTransport listener.onGpsNavigationMessageReceived(event); } }; + foreach(operation); + } + @Override + public void onStatusChanged(final int status) { + ListenerOperation<GpsNavigationMessageEvent.Listener> operation = + new ListenerOperation<GpsNavigationMessageEvent.Listener>() { + @Override + public void execute(GpsNavigationMessageEvent.Listener listener) + throws RemoteException { + listener.onStatusChanged(status); + } + }; foreach(operation); } } diff --git a/location/java/android/location/IGpsMeasurementsListener.aidl b/location/java/android/location/IGpsMeasurementsListener.aidl index b34bb6c..cbd3100 100644 --- a/location/java/android/location/IGpsMeasurementsListener.aidl +++ b/location/java/android/location/IGpsMeasurementsListener.aidl @@ -23,4 +23,5 @@ import android.location.GpsMeasurementsEvent; */ oneway interface IGpsMeasurementsListener { void onGpsMeasurementsReceived(in GpsMeasurementsEvent event); + void onStatusChanged(in int status); } diff --git a/location/java/android/location/IGpsNavigationMessageListener.aidl b/location/java/android/location/IGpsNavigationMessageListener.aidl index 18603fe..a708ea6 100644 --- a/location/java/android/location/IGpsNavigationMessageListener.aidl +++ b/location/java/android/location/IGpsNavigationMessageListener.aidl @@ -23,4 +23,5 @@ import android.location.GpsNavigationMessageEvent; */ oneway interface IGpsNavigationMessageListener { void onGpsNavigationMessageReceived(in GpsNavigationMessageEvent event); + void onStatusChanged(in int status); } diff --git a/location/java/android/location/ILocationManager.aidl b/location/java/android/location/ILocationManager.aidl index 1501710..af76175 100644 --- a/location/java/android/location/ILocationManager.aidl +++ b/location/java/android/location/ILocationManager.aidl @@ -62,12 +62,12 @@ interface ILocationManager boolean sendNiResponse(int notifId, int userResponse); boolean addGpsMeasurementsListener(in IGpsMeasurementsListener listener, in String packageName); - boolean removeGpsMeasurementsListener(in IGpsMeasurementsListener listener); + void removeGpsMeasurementsListener(in IGpsMeasurementsListener listener); boolean addGpsNavigationMessageListener( in IGpsNavigationMessageListener listener, in String packageName); - boolean removeGpsNavigationMessageListener(in IGpsNavigationMessageListener listener); + void removeGpsNavigationMessageListener(in IGpsNavigationMessageListener listener); // --- deprecated --- List<String> getAllProviders(); diff --git a/location/java/android/location/LocalListenerHelper.java b/location/java/android/location/LocalListenerHelper.java index 1f3bf67..458c451 100644 --- a/location/java/android/location/LocalListenerHelper.java +++ b/location/java/android/location/LocalListenerHelper.java @@ -19,6 +19,7 @@ package android.location; import com.android.internal.util.Preconditions; import android.annotation.NonNull; +import android.content.Context; import android.os.RemoteException; import android.util.Log; @@ -32,17 +33,19 @@ import java.util.HashSet; * @hide */ abstract class LocalListenerHelper<TListener> { - private final HashSet<TListener> mListeners = new HashSet<TListener>(); + private final HashSet<TListener> mListeners = new HashSet<>(); + private final String mTag; + private final Context mContext; - protected LocalListenerHelper(String name) { + protected LocalListenerHelper(Context context, String name) { Preconditions.checkNotNull(name); + mContext = context; mTag = name; } public boolean add(@NonNull TListener listener) { Preconditions.checkNotNull(listener); - synchronized (mListeners) { // we need to register with the service first, because we need to find out if the // service will actually support the request before we attempt anything @@ -59,18 +62,15 @@ abstract class LocalListenerHelper<TListener> { return false; } } - if (mListeners.contains(listener)) { return true; } - mListeners.add(listener); + return mListeners.add(listener); } - return true; } public void remove(@NonNull TListener listener) { Preconditions.checkNotNull(listener); - synchronized (mListeners) { boolean removed = mListeners.remove(listener); boolean isLastRemoved = removed && mListeners.isEmpty(); @@ -78,7 +78,7 @@ abstract class LocalListenerHelper<TListener> { try { unregisterFromServer(); } catch (RemoteException e) { - + Log.v(mTag, "Error handling last listener removal", e); } } } @@ -91,12 +91,15 @@ abstract class LocalListenerHelper<TListener> { void execute(TListener listener) throws RemoteException; } - protected void foreach(ListenerOperation operation) { + protected Context getContext() { + return mContext; + } + + protected void foreach(ListenerOperation<TListener> operation) { Collection<TListener> listeners; synchronized (mListeners) { - listeners = new ArrayList<TListener>(mListeners); + listeners = new ArrayList<>(mListeners); } - for (TListener listener : listeners) { try { operation.execute(listener); diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java index ed408e0..513a627 100644 --- a/location/java/android/location/LocationManager.java +++ b/location/java/android/location/LocationManager.java @@ -1579,7 +1579,7 @@ public class LocationManager { * Adds a GPS Measurement listener. * * @param listener a {@link GpsMeasurementsEvent.Listener} object to register. - * @return {@code true} if the listener was successfully registered, {@code false} otherwise. + * @return {@code true} if the listener was added successfully, {@code false} otherwise. * * @hide */ @@ -1602,7 +1602,7 @@ public class LocationManager { * Adds a GPS Navigation Message listener. * * @param listener a {@link GpsNavigationMessageEvent.Listener} object to register. - * @return {@code true} if the listener was successfully registered, {@code false} otherwise. + * @return {@code true} if the listener was added successfully, {@code false} otherwise. * * @hide */ |