Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f9a274c9 authored by destradaa's avatar destradaa Committed by Daniel Estrada Alva
Browse files

Add support for sources in Geofencing APIs.

Support setting the source when adding geofences.
b/14117199

Surface the source when FLP geofence changes state.
b/14119200

Change-Id: I50dc40a9caee400594e1778c98e284e0db0d5e66
parent 6a7d8c42
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -13278,6 +13278,11 @@ package android.hardware.location {
    field public static final int MONITOR_CURRENTLY_AVAILABLE = 0; // 0x0
    field public static final int MONITOR_CURRENTLY_UNAVAILABLE = 1; // 0x1
    field public static final int MONITOR_UNSUPPORTED = 2; // 0x2
    field public static final int SOURCE_TECHNOLOGY_BLUETOOTH = 16; // 0x10
    field public static final int SOURCE_TECHNOLOGY_CELL = 8; // 0x8
    field public static final int SOURCE_TECHNOLOGY_GNSS = 1; // 0x1
    field public static final int SOURCE_TECHNOLOGY_SENSORS = 4; // 0x4
    field public static final int SOURCE_TECHNOLOGY_WIFI = 2; // 0x2
  }
  public abstract class GeofenceHardwareCallback {
@@ -13291,7 +13296,19 @@ package android.hardware.location {
  public abstract class GeofenceHardwareMonitorCallback {
    ctor public GeofenceHardwareMonitorCallback();
    method public void onMonitoringSystemChange(int, boolean, android.location.Location);
    method public deprecated void onMonitoringSystemChange(int, boolean, android.location.Location);
    method public void onMonitoringSystemChange(android.hardware.location.GeofenceHardwareMonitorEvent);
  }
  public class GeofenceHardwareMonitorEvent implements android.os.Parcelable {
    ctor public GeofenceHardwareMonitorEvent(int, int, int, android.location.Location);
    method public int describeContents();
    method public android.location.Location getLocation();
    method public int getMonitoringStatus();
    method public int getMonitoringType();
    method public int getSourceTechnologies();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  public final class GeofenceHardwareRequest {
@@ -13303,10 +13320,12 @@ package android.hardware.location {
    method public int getMonitorTransitions();
    method public int getNotificationResponsiveness();
    method public double getRadius();
    method public int getSourceTechnologies();
    method public int getUnknownTimer();
    method public void setLastTransition(int);
    method public void setMonitorTransitions(int);
    method public void setNotificationResponsiveness(int);
    method public void setSourceTechnologies(int);
    method public void setUnknownTimer(int);
  }
+48 −13
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package android.hardware.location;

import android.location.Location;
import android.os.Build;
import android.os.RemoteException;

import java.lang.ref.WeakReference;
@@ -60,19 +61,19 @@ public final class GeofenceHardware {
    public static final int MONITORING_TYPE_FUSED_HARDWARE = 1;

    /**
     * Constant to indiciate that the monitoring system is currently
     * Constant to indicate that the monitoring system is currently
     * available for monitoring geofences.
     */
    public static final int MONITOR_CURRENTLY_AVAILABLE = 0;

    /**
     * Constant to indiciate that the monitoring system is currently
     * Constant to indicate that the monitoring system is currently
     * unavailable for monitoring geofences.
     */
    public static final int MONITOR_CURRENTLY_UNAVAILABLE = 1;

    /**
     * Constant to indiciate that the monitoring system is unsupported
     * Constant to indicate that the monitoring system is unsupported
     * for hardware geofence monitoring.
     */
    public static final int MONITOR_UNSUPPORTED = 2;
@@ -129,6 +130,33 @@ public final class GeofenceHardware {
     */
    public static final int GEOFENCE_ERROR_INSUFFICIENT_MEMORY = 6;

    // the following values must match the definitions in fused_location.h

    /**
     * The constant used to indicate that the monitoring system supports GNSS.
     */
    public static final int SOURCE_TECHNOLOGY_GNSS = (1<<0);

    /**
     * The constant used to indicate that the monitoring system supports WiFi.
     */
    public static final int SOURCE_TECHNOLOGY_WIFI = (1<<1);

    /**
     * The constant used to indicate that the monitoring system supports Sensors.
     */
    public static final int SOURCE_TECHNOLOGY_SENSORS = (1<<2);

    /**
     * The constant used to indicate that the monitoring system supports Cell.
     */
    public static final int SOURCE_TECHNOLOGY_CELL = (1<<3);

    /**
     * The constant used to indicate that the monitoring system supports Bluetooth.
     */
    public static final int SOURCE_TECHNOLOGY_BLUETOOTH = (1<<4);

    private HashMap<GeofenceHardwareCallback, GeofenceHardwareCallbackWrapper>
            mCallbacks = new HashMap<GeofenceHardwareCallback, GeofenceHardwareCallbackWrapper>();
    private HashMap<GeofenceHardwareMonitorCallback, GeofenceHardwareMonitorCallbackWrapper>
@@ -238,13 +266,9 @@ public final class GeofenceHardware {
            geofenceRequest, GeofenceHardwareCallback callback) {
        try {
            if (geofenceRequest.getType() == GeofenceHardwareRequest.GEOFENCE_TYPE_CIRCLE) {
                return mService.addCircularFence(geofenceId, monitoringType,
                        geofenceRequest.getLatitude(),
                        geofenceRequest.getLongitude(), geofenceRequest.getRadius(),
                        geofenceRequest.getLastTransition(),
                        geofenceRequest.getMonitorTransitions(),
                        geofenceRequest.getNotificationResponsiveness(),
                        geofenceRequest.getUnknownTimer(),
                return mService.addCircularFence(
                        monitoringType,
                        new GeofenceHardwareRequestParcelable(geofenceId, geofenceRequest),
                        getCallbackWrapper(callback));
            } else {
                throw new IllegalArgumentException("Geofence Request type not supported");
@@ -452,10 +476,21 @@ public final class GeofenceHardware {
            mCallback = new WeakReference<GeofenceHardwareMonitorCallback>(c);
        }

        public void onMonitoringSystemChange(int monitoringType, boolean available,
                Location location) {
        public void onMonitoringSystemChange(GeofenceHardwareMonitorEvent event) {
            GeofenceHardwareMonitorCallback c = mCallback.get();
            if (c != null) c.onMonitoringSystemChange(monitoringType, available, location);
            if (c == null) return;

            // report the legacy event first, so older clients are not broken
            c.onMonitoringSystemChange(
                    event.getMonitoringType(),
                    event.getMonitoringStatus() == GeofenceHardware.MONITOR_CURRENTLY_AVAILABLE,
                    event.getLocation());

            // and only call the updated callback on on L and above, this complies with the
            // documentation of GeofenceHardwareMonitorCallback
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.L) {
                c.onMonitoringSystemChange(event);
            }
        }
    }

+35 −39
Original line number Diff line number Diff line
@@ -210,18 +210,20 @@ public final class GeofenceHardwareImpl {
        }
    }

    public boolean addCircularFence(int geofenceId,  int monitoringType, double latitude,
            double longitude, double radius, int lastTransition,int monitorTransitions,
            int notificationResponsivenes, int unknownTimer, IGeofenceHardwareCallback callback) {
    public boolean addCircularFence(
            int monitoringType,
            GeofenceHardwareRequestParcelable request,
            IGeofenceHardwareCallback callback) {
        int geofenceId = request.getId();

        // This API is not thread safe. Operations on the same geofence need to be serialized
        // by upper layers
        if (DEBUG) {
            Log.d(TAG, "addCircularFence: GeofenceId: " + geofenceId + " Latitude: " + latitude +
                    " Longitude: " + longitude + " Radius: " + radius + " LastTransition: "
                    + lastTransition + " MonitorTransition: " + monitorTransitions +
                    " NotificationResponsiveness: " + notificationResponsivenes +
                    " UnKnown Timer: " + unknownTimer + " MonitoringType: " + monitoringType);

            String message = String.format(
                    "addCircularFence: monitoringType=%d, %s",
                    monitoringType,
                    request);
            Log.d(TAG, message);
        }
        boolean result;

@@ -237,9 +239,15 @@ public final class GeofenceHardwareImpl {
            case GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE:
                if (mGpsService == null) return false;
                try {
                    result = mGpsService.addCircularHardwareGeofence(geofenceId, latitude,
                            longitude, radius, lastTransition, monitorTransitions,
                            notificationResponsivenes, unknownTimer);
                    result = mGpsService.addCircularHardwareGeofence(
                            request.getId(),
                            request.getLatitude(),
                            request.getLongitude(),
                            request.getRadius(),
                            request.getLastTransition(),
                            request.getMonitorTransitions(),
                            request.getNotificationResponsiveness(),
                            request.getUnknownTimer());
                } catch (RemoteException e) {
                    Log.e(TAG, "AddGeofence: Remote Exception calling LocationManagerService");
                    result = false;
@@ -249,20 +257,9 @@ public final class GeofenceHardwareImpl {
                if(mFusedService == null) {
                    return false;
                }
                GeofenceHardwareRequest request = GeofenceHardwareRequest.createCircularGeofence(
                        latitude,
                        longitude,
                        radius);
                request.setUnknownTimer(unknownTimer);
                request.setNotificationResponsiveness(notificationResponsivenes);
                request.setMonitorTransitions(monitorTransitions);
                request.setLastTransition(lastTransition);

                GeofenceHardwareRequestParcelable parcelableRequest =
                        new GeofenceHardwareRequestParcelable(geofenceId, request);
                try {
                    mFusedService.addGeofences(
                            new GeofenceHardwareRequestParcelable[] { parcelableRequest });
                            new GeofenceHardwareRequestParcelable[] { request });
                    result = true;
                } catch(RemoteException e) {
                    Log.e(TAG, "AddGeofence: RemoteException calling LocationManagerService");
@@ -471,12 +468,14 @@ public final class GeofenceHardwareImpl {
            int monitoringStatus,
            Location location,
            int source) {
        // TODO: use the source if needed in the future
        setMonitorAvailability(monitoringType, monitoringStatus);
        acquireWakeLock();
        Message message = mCallbacksHandler.obtainMessage(GEOFENCE_STATUS, location);
        message.arg1 = monitoringStatus;
        message.arg2 = monitoringType;
        GeofenceHardwareMonitorEvent event = new GeofenceHardwareMonitorEvent(
                monitoringType,
                monitoringStatus,
                source,
                location);
        Message message = mCallbacksHandler.obtainMessage(GEOFENCE_STATUS, event);
        message.sendToTarget();
    }

@@ -644,20 +643,17 @@ public final class GeofenceHardwareImpl {

            switch (msg.what) {
                case GEOFENCE_STATUS:
                    Location location = (Location) msg.obj;
                    int val = msg.arg1;
                    monitoringType = msg.arg2;
                    boolean available;
                    available = (val == GeofenceHardware.MONITOR_CURRENTLY_AVAILABLE ?
                            true : false);
                    callbackList = mCallbacks[monitoringType];
                    GeofenceHardwareMonitorEvent event = (GeofenceHardwareMonitorEvent) msg.obj;
                    callbackList = mCallbacks[event.getMonitoringType()];
                    if (callbackList != null) {
                        if (DEBUG) Log.d(TAG, "MonitoringSystemChangeCallback: GPS : " + available);
                        if (DEBUG) Log.d(TAG, "MonitoringSystemChangeCallback: " + event);

                        for (IGeofenceHardwareMonitorCallback c : callbackList) {
                            try {
                                c.onMonitoringSystemChange(monitoringType, available, location);
                            } catch (RemoteException e) {}
                                c.onMonitoringSystemChange(event);
                            } catch (RemoteException e) {
                                Log.d(TAG, "Error reporting onMonitoringSystemChange.", e);
                            }
                        }
                    }
                    releaseWakeLock();
+23 −3
Original line number Diff line number Diff line
@@ -19,19 +19,39 @@ package android.hardware.location;
import android.location.Location;

/**
 * The callback class associated with the status change of hardware montiors
 * The callback class associated with the status change of hardware monitors
 * in {@link GeofenceHardware}
 */
public abstract class GeofenceHardwareMonitorCallback {
    /**
     * The callback called when the state of a monitoring system changes.
     * {@link GeofenceHardware#MONITORING_TYPE_GPS_HARDWARE} is an example of a
     * monitoring system
     * monitoring system.
     *
     * @deprecated use {@link #onMonitoringSystemChange(GeofenceHardwareMonitorEvent)} instead.
     * NOTE: this API is will remain to be called on Android API 21 and above for backwards
     * compatibility. But clients must stop implementing it when updating their code.
     *
     * @param monitoringType The type of the monitoring system.
     * @param available Indicates whether the system is currenty available or not.
     * @param available Indicates whether the system is currently available or not.
     * @param location The last known location according to the monitoring system.
     */
    @Deprecated
    public void onMonitoringSystemChange(int monitoringType, boolean available, Location location) {
    }

    /**
     * The callback called when the sate of a monitoring system changes.
     * {@link GeofenceHardware#MONITORING_TYPE_GPS_HARDWARE} is an example of a monitoring system.
     * {@link GeofenceHardware#MONITOR_CURRENTLY_AVAILABLE} is an example of a monitoring status.
     * {@link GeofenceHardware#SOURCE_TECHNOLOGY_GNSS} is an example of a source.
     *
     * This callback must be used instead of
     * {@link #onMonitoringSystemChange(int, boolean, android.location.Location)}.
     *
     * NOTE: this API is only called on Android API 21 and above.
     *
     * @param event An object representing the monitoring system change event.
     */
    public void onMonitoringSystemChange(GeofenceHardwareMonitorEvent event) {}
}
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.hardware.location;

parcelable GeofenceHardwareMonitorEvent;
 No newline at end of file
Loading