Fields Summary |
---|
private IGeofenceHardware | mService |
static final int | NUM_MONITORS |
public static final int | MONITORING_TYPE_GPS_HARDWAREConstant for geofence monitoring done by the GPS hardware. |
public static final int | MONITORING_TYPE_FUSED_HARDWAREConstant for geofence monitoring done by the Fused hardware. |
public static final int | MONITOR_CURRENTLY_AVAILABLEConstant to indicate that the monitoring system is currently
available for monitoring geofences. |
public static final int | MONITOR_CURRENTLY_UNAVAILABLEConstant to indicate that the monitoring system is currently
unavailable for monitoring geofences. |
public static final int | MONITOR_UNSUPPORTEDConstant to indicate that the monitoring system is unsupported
for hardware geofence monitoring. |
public static final int | GEOFENCE_ENTEREDThe constant to indicate that the user has entered the geofence. |
public static final int | GEOFENCE_EXITEDThe constant to indicate that the user has exited the geofence. |
public static final int | GEOFENCE_UNCERTAINThe constant to indicate that the user is uncertain with respect to a
geofence. |
public static final int | GEOFENCE_SUCCESSThe constant used to indicate success of the particular geofence call |
public static final int | GEOFENCE_ERROR_TOO_MANY_GEOFENCESThe constant used to indicate that too many geofences have been registered. |
public static final int | GEOFENCE_ERROR_ID_EXISTSThe constant used to indicate that the geofence id already exists. |
public static final int | GEOFENCE_ERROR_ID_UNKNOWNThe constant used to indicate that the geofence id is unknown. |
public static final int | GEOFENCE_ERROR_INVALID_TRANSITIONThe constant used to indicate that the transition requested for the geofence is invalid. |
public static final int | GEOFENCE_FAILUREThe constant used to indicate that the geofence operation has failed. |
public static final int | GEOFENCE_ERROR_INSUFFICIENT_MEMORYThe constant used to indicate that the operation failed due to insufficient memory. |
public static final int | SOURCE_TECHNOLOGY_GNSSThe constant used to indicate that the monitoring system supports GNSS. |
public static final int | SOURCE_TECHNOLOGY_WIFIThe constant used to indicate that the monitoring system supports WiFi. |
public static final int | SOURCE_TECHNOLOGY_SENSORSThe constant used to indicate that the monitoring system supports Sensors. |
public static final int | SOURCE_TECHNOLOGY_CELLThe constant used to indicate that the monitoring system supports Cell. |
public static final int | SOURCE_TECHNOLOGY_BLUETOOTHThe constant used to indicate that the monitoring system supports Bluetooth. |
private HashMap | mCallbacks |
private HashMap | mMonitorCallbacks |
Methods Summary |
---|
public boolean | addGeofence(int geofenceId, int monitoringType, GeofenceHardwareRequest geofenceRequest, GeofenceHardwareCallback callback)Creates a circular geofence which is monitored by subsystems in the hardware.
When the device detects that is has entered, exited or is uncertain
about the area specified by the geofence, the given callback will be called.
If this call returns true, it means that the geofence has been sent to the hardware.
{@link GeofenceHardwareCallback#onGeofenceAdd} will be called with the result of the
add call from the hardware. The {@link GeofenceHardwareCallback#onGeofenceAdd} will be
called with the following parameters when a transition event occurs.
- The geofence Id
- The location object indicating the last known location.
- The transition associated with the geofence. One of
{@link #GEOFENCE_ENTERED}, {@link #GEOFENCE_EXITED}, {@link #GEOFENCE_UNCERTAIN}
- The timestamp when the geofence transition occured.
- The monitoring type ({@link #MONITORING_TYPE_GPS_HARDWARE} is one such example)
that was used.
The geofence will be monitored by the subsystem specified by monitoring_type parameter.
The application does not need to hold a wakelock when the monitoring
is being done by the underlying hardware subsystem. If the same geofence Id is being
monitored by two different monitoring systems, the same id can be used for both calls, as
long as the same callback object is used.
Requires {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permission when
{@link #MONITORING_TYPE_GPS_HARDWARE} is used.
Requires {@link android.Manifest.permission#LOCATION_HARDWARE} permission to access
geofencing in hardware.
This API should not be called directly by the app developers. A higher level api
which abstracts the hardware should be used instead. All the checks are done by the higher
level public API. Any needed locking should be handled by the higher level API.
Create a geofence request object using the methods in {@link GeofenceHardwareRequest} to
set all the characteristics of the geofence. Use the created GeofenceHardwareRequest object
in this call.
try {
if (geofenceRequest.getType() == GeofenceHardwareRequest.GEOFENCE_TYPE_CIRCLE) {
return mService.addCircularFence(
monitoringType,
new GeofenceHardwareRequestParcelable(geofenceId, geofenceRequest),
getCallbackWrapper(callback));
} else {
throw new IllegalArgumentException("Geofence Request type not supported");
}
} catch (RemoteException e) {
}
return false;
|
private android.hardware.location.GeofenceHardware$GeofenceHardwareCallbackWrapper | getCallbackWrapper(GeofenceHardwareCallback callback)
synchronized (mCallbacks) {
GeofenceHardwareCallbackWrapper wrapper = mCallbacks.get(callback);
if (wrapper == null) {
wrapper = new GeofenceHardwareCallbackWrapper(callback);
mCallbacks.put(callback, wrapper);
}
return wrapper;
}
|
private android.hardware.location.GeofenceHardware$GeofenceHardwareMonitorCallbackWrapper | getMonitorCallbackWrapper(GeofenceHardwareMonitorCallback callback)
synchronized (mMonitorCallbacks) {
GeofenceHardwareMonitorCallbackWrapper wrapper = mMonitorCallbacks.get(callback);
if (wrapper == null) {
wrapper = new GeofenceHardwareMonitorCallbackWrapper(callback);
mMonitorCallbacks.put(callback, wrapper);
}
return wrapper;
}
|
public int[] | getMonitoringTypes()Returns all the hardware geofence monitoring systems which are supported
Call {@link #getStatusOfMonitoringType(int)} to know the current state
of a monitoring system.
Requires {@link android.Manifest.permission#LOCATION_HARDWARE} permission to access
geofencing in hardware.
try {
return mService.getMonitoringTypes();
} catch (RemoteException e) {
}
return new int[0];
|
public int | getStatusOfMonitoringType(int monitoringType)Returns current status of a hardware geofence monitoring system.
Status can be one of {@link #MONITOR_CURRENTLY_AVAILABLE},
{@link #MONITOR_CURRENTLY_UNAVAILABLE} or {@link #MONITOR_UNSUPPORTED}
Some supported hardware monitoring systems might not be available
for monitoring geofences in certain scenarios. For example, when a user
enters a building, the GPS hardware subsystem might not be able monitor
geofences and will change from {@link #MONITOR_CURRENTLY_AVAILABLE} to
{@link #MONITOR_CURRENTLY_UNAVAILABLE}.
try {
return mService.getStatusOfMonitoringType(monitoringType);
} catch (RemoteException e) {
return MONITOR_UNSUPPORTED;
}
|
public boolean | pauseGeofence(int geofenceId, int monitoringType)Pauses the monitoring of a geofence added by {@link #addGeofence} call.
If this call returns true, it means that the geofence has been sent to the hardware.
{@link GeofenceHardwareCallback#onGeofencePause} will be called with the result of the
pause call from the hardware.
Requires {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permission when
{@link #MONITORING_TYPE_GPS_HARDWARE} is used.
Requires {@link android.Manifest.permission#LOCATION_HARDWARE} permission to access
geofencing in hardware.
This API should not be called directly by the app developers. A higher level api
which abstracts the hardware should be used instead. All the checks are done by the higher
level public API. Any needed locking should be handled by the higher level API.
try {
return mService.pauseGeofence(geofenceId, monitoringType);
} catch (RemoteException e) {
}
return false;
|
public boolean | registerForMonitorStateChangeCallback(int monitoringType, GeofenceHardwareMonitorCallback callback)Register the callback to be notified when the state of a hardware geofence
monitoring system changes. For instance, it can change from
{@link #MONITOR_CURRENTLY_AVAILABLE} to {@link #MONITOR_CURRENTLY_UNAVAILABLE}
Requires {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permission when
{@link #MONITORING_TYPE_GPS_HARDWARE} is used.
Requires {@link android.Manifest.permission#LOCATION_HARDWARE} permission to access
geofencing in hardware.
This API should not be called directly by the app developers. A higher level api
which abstracts the hardware should be used instead. All the checks are done by the higher
level public API. Any needed locking should be handled by the higher level API.
The same callback object can be used to be informed of geofence transitions
and state changes of the underlying hardware subsystem.
try {
return mService.registerForMonitorStateChangeCallback(monitoringType,
getMonitorCallbackWrapper(callback));
} catch (RemoteException e) {
}
return false;
|
private void | removeCallback(GeofenceHardwareCallback callback)
synchronized (mCallbacks) {
mCallbacks.remove(callback);
}
|
public boolean | removeGeofence(int geofenceId, int monitoringType)Removes a geofence added by {@link #addGeofence} call.
If this call returns true, it means that the geofence has been sent to the hardware.
{@link GeofenceHardwareCallback#onGeofenceRemove} will be called with the result of the
remove call from the hardware.
Requires {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permission when
{@link #MONITORING_TYPE_GPS_HARDWARE} is used.
Requires {@link android.Manifest.permission#LOCATION_HARDWARE} permission to access
geofencing in hardware.
This API should not be called directly by the app developers. A higher level api
which abstracts the hardware should be used instead. All the checks are done by the higher
level public API. Any needed locking should be handled by the higher level API.
try {
return mService.removeGeofence(geofenceId, monitoringType);
} catch (RemoteException e) {
}
return false;
|
private void | removeMonitorCallback(GeofenceHardwareMonitorCallback callback)
synchronized (mMonitorCallbacks) {
mMonitorCallbacks.remove(callback);
}
|
public boolean | resumeGeofence(int geofenceId, int monitoringType, int monitorTransition)Resumes the monitoring of a geofence added by {@link #pauseGeofence} call.
If this call returns true, it means that the geofence has been sent to the hardware.
{@link GeofenceHardwareCallback#onGeofenceResume} will be called with the result of the
resume call from the hardware.
Requires {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permission when
{@link #MONITORING_TYPE_GPS_HARDWARE} is used.
Requires {@link android.Manifest.permission#LOCATION_HARDWARE} permission to access
geofencing in hardware.
This API should not be called directly by the app developers. A higher level api
which abstracts the hardware should be used instead. All the checks are done by the higher
level public API. Any needed locking should be handled by the higher level API.
try {
return mService.resumeGeofence(geofenceId, monitoringType, monitorTransition);
} catch (RemoteException e) {
}
return false;
|
public boolean | unregisterForMonitorStateChangeCallback(int monitoringType, GeofenceHardwareMonitorCallback callback)Unregister the callback that was used with {@link #registerForMonitorStateChangeCallback}
to notify when the state of the hardware geofence monitoring system changes.
Requires {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permission when
{@link #MONITORING_TYPE_GPS_HARDWARE} is used.
Requires {@link android.Manifest.permission#LOCATION_HARDWARE} permission to access
geofencing in hardware.
This API should not be called directly by the app developers. A higher level api
which abstracts the hardware should be used instead. All the checks are done by the higher
level public API. Any needed locking should be handled by the higher level API.
boolean result = false;
try {
result = mService.unregisterForMonitorStateChangeCallback(monitoringType,
getMonitorCallbackWrapper(callback));
if (result) removeMonitorCallback(callback);
} catch (RemoteException e) {
}
return result;
|