summaryrefslogtreecommitdiffstats
path: root/location
diff options
context:
space:
mode:
authordestradaa <destradaa@google.com>2014-11-06 23:22:41 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-11-06 23:22:46 +0000
commit992b9aa37b0b7dba45505593cc4715d5be5aecbb (patch)
tree3741dd0710d344cde4644442f45ba2c36e213e62 /location
parenta11bb7427171418681428754051d5ee4dce851ee (diff)
parent6568d709e78d6ccaf256b7d0e4a19cdfb26deafb (diff)
downloadframeworks_base-992b9aa37b0b7dba45505593cc4715d5be5aecbb.zip
frameworks_base-992b9aa37b0b7dba45505593cc4715d5be5aecbb.tar.gz
frameworks_base-992b9aa37b0b7dba45505593cc4715d5be5aecbb.tar.bz2
Merge "Add support for GPS measurement/navigation message capabilities. b/16727892 b/16815124" into lmp-mr1-dev
Diffstat (limited to 'location')
-rw-r--r--location/java/android/location/GpsMeasurementListenerTransport.java17
-rw-r--r--location/java/android/location/GpsMeasurementsEvent.java31
-rw-r--r--location/java/android/location/GpsNavigationMessageEvent.java30
-rw-r--r--location/java/android/location/GpsNavigationMessageListenerTransport.java18
-rw-r--r--location/java/android/location/IGpsMeasurementsListener.aidl1
-rw-r--r--location/java/android/location/IGpsNavigationMessageListener.aidl1
-rw-r--r--location/java/android/location/ILocationManager.aidl4
-rw-r--r--location/java/android/location/LocalListenerHelper.java25
-rw-r--r--location/java/android/location/LocationManager.java4
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
*/