From 3f1fa81390d67053d3aa50b0bc3537953396bcf6 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sat, 11 Feb 2017 02:13:42 +0100 Subject: [PATCH] Add Geofencing API details --- .../internal/IGeofencerCallbacks.aidl | 5 + .../gms/location/DetectedActivity.java | 12 ++ .../android/gms/location/GeofencingEvent.java | 132 ++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 play-services-location-api/src/main/java/com/google/android/gms/location/GeofencingEvent.java diff --git a/play-services-location-api/src/main/aidl/com/google/android/gms/location/internal/IGeofencerCallbacks.aidl b/play-services-location-api/src/main/aidl/com/google/android/gms/location/internal/IGeofencerCallbacks.aidl index b8e03066..ac3950f5 100644 --- a/play-services-location-api/src/main/aidl/com/google/android/gms/location/internal/IGeofencerCallbacks.aidl +++ b/play-services-location-api/src/main/aidl/com/google/android/gms/location/internal/IGeofencerCallbacks.aidl @@ -1,4 +1,9 @@ package com.google.android.gms.location.internal; +import android.app.PendingIntent; + interface IGeofencerCallbacks { + void onAddGeofenceResult(int statusCode, in String[] requestIds) = 0; + void onRemoveGeofencesByRequestIdsResult(int statusCode, in String[] requestIds) = 1; + void onRemoveGeofencesByPendingIntentResult(int statusCode, in PendingIntent pendingIntent) = 2; } diff --git a/play-services-location-api/src/main/java/com/google/android/gms/location/DetectedActivity.java b/play-services-location-api/src/main/java/com/google/android/gms/location/DetectedActivity.java index 36744730..4a75a4d2 100644 --- a/play-services-location-api/src/main/java/com/google/android/gms/location/DetectedActivity.java +++ b/play-services-location-api/src/main/java/com/google/android/gms/location/DetectedActivity.java @@ -92,6 +92,13 @@ public class DetectedActivity extends AutoSafeParcelable { this.confidence = confidence; } + @PublicApi(exclude = true) + public DetectedActivity(int versionCode, int type, int confidence) { + this.versionCode = versionCode; + this.type = type; + this.confidence = confidence; + } + /** * Returns a value from 0 to 100 indicating the likelihood that the user is performing this * activity. @@ -120,6 +127,11 @@ public class DetectedActivity extends AutoSafeParcelable { return type; } + @PublicApi(exclude = true) + public int getVersionCode() { + return versionCode; + } + @Override public String toString() { return "DetectedActivity [type=" + typeToString(getType()) + ", confidence=" + getConfidence() + "]"; diff --git a/play-services-location-api/src/main/java/com/google/android/gms/location/GeofencingEvent.java b/play-services-location-api/src/main/java/com/google/android/gms/location/GeofencingEvent.java new file mode 100644 index 00000000..82b3a107 --- /dev/null +++ b/play-services-location-api/src/main/java/com/google/android/gms/location/GeofencingEvent.java @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2017 microG Project Team + * + * 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 com.google.android.gms.location; + +import android.content.Intent; +import android.location.Location; + +import com.google.android.gms.location.internal.ParcelableGeofence; + +import org.microg.gms.common.PublicApi; +import org.microg.safeparcel.SafeParcelUtil; + +import java.util.ArrayList; +import java.util.List; + +/** + * Represents an event from the GeofencingApi API. The event can be + *

+ * A geofence triggering event generated when a geofence transition happens. + * An error happens after geofences are registered and being monitored. + */ +@PublicApi +public class GeofencingEvent { + @PublicApi(exclude = true) + public static final String EXTRA_ERROR_CODE = "gms_error_code"; + @PublicApi(exclude = true) + public static final String EXTRA_TRIGGERING_LOCATION = "com.google.android.location.intent.extra.triggering_location"; + @PublicApi(exclude = true) + public static final String EXTRA_TRANSITION = "com.google.android.location.intent.extra.transition"; + @PublicApi(exclude = true) + public static final String EXTRA_GEOFENCE_LIST = "com.google.android.location.intent.extra.geofence_list"; + + private int errorCode; + private int geofenceTransition; + private List triggeringGeofences; + private Location triggeringLocation; + + /** + * Creates a {@link GeofencingEvent} object from the given intent. + * + * @param intent the intent to extract the geofencing event data from + * @return a {@link GeofencingEvent} object or {@code null} if the given intent is {@code null} + */ + public static GeofencingEvent fromIntent(Intent intent) { + if (intent == null) { + return null; + } + GeofencingEvent event = new GeofencingEvent(); + event.errorCode = intent.getIntExtra(EXTRA_ERROR_CODE, -1); + event.geofenceTransition = intent.getIntExtra(EXTRA_TRANSITION, -1); + if (event.geofenceTransition != 1 && event.geofenceTransition != 2 && event.geofenceTransition != 4) + event.geofenceTransition = -1; + ArrayList parceledGeofences = (ArrayList) intent.getSerializableExtra(EXTRA_GEOFENCE_LIST); + if (parceledGeofences != null) { + event.triggeringGeofences = new ArrayList(); + for (byte[] parceledGeofence : parceledGeofences) { + event.triggeringGeofences.add(SafeParcelUtil.fromByteArray(parceledGeofence, ParcelableGeofence.CREATOR)); + } + } + event.triggeringLocation = intent.getParcelableExtra(EXTRA_TRIGGERING_LOCATION); + return event; + } + + /** + * Returns the error code that explains the error that triggered the intent specified in + * {@link #fromIntent(Intent)}. + * + * @return the error code specified in {@link GeofenceStatusCodes} or {@code -1} if + * {@link #hasError()} returns false. + */ + public int getErrorCode() { + return errorCode; + } + + /** + * Returns the transition type of the geofence transition alert. + * + * @return -1 if the intent specified in {@link #fromIntent(Intent)} is not generated for a + * transition alert; Otherwise returns the GEOFENCE_TRANSITION_ flags value defined in + * {@link Geofence}. + */ + public int getGeofenceTransition() { + return geofenceTransition; + } + + + /** + * Returns a list of geofences that triggered this geofence transition alert. + * + * @return a list of geofences that triggered this geofence transition alert or {@code null} if + * the intent specified in {@link #fromIntent(Intent)} is not generated for a geofence + * transition alert + */ + public List getTriggeringGeofences() { + return triggeringGeofences; + } + + /** + * Gets the location that triggered the geofence transition. Triggering location is only + * available if the calling app links against Google Play services 5.0 SDK. + * + * @return the location that triggered this geofence alert or {@code null} if it's not included + * in the intent specified in {@link #fromIntent(Intent)} + */ + public Location getTriggeringLocation() { + return triggeringLocation; + } + + /** + * Whether an error triggered this intent. + * + * @return {@code true} if an error triggered the intent specified in + * {@link #fromIntent(Intent)}, otherwise {@code false} + */ + public boolean hasError() { + return errorCode != -1; + } +}