diff --git a/extern/GmsApi b/extern/GmsApi index 0b4f43c6..c61a147d 160000 --- a/extern/GmsApi +++ b/extern/GmsApi @@ -1 +1 @@ -Subproject commit 0b4f43c6a6a091dbdeb0ec544d533373a83ea319 +Subproject commit c61a147de29456270bce1203c9f6700268b068c5 diff --git a/play-services-location/src/main/java/com/google/android/gms/location/ActivityRecognition.java b/play-services-location/src/main/java/com/google/android/gms/location/ActivityRecognition.java new file mode 100644 index 00000000..ef9d76c3 --- /dev/null +++ b/play-services-location/src/main/java/com/google/android/gms/location/ActivityRecognition.java @@ -0,0 +1,40 @@ +/* + * 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 com.google.android.gms.common.api.Api; +import com.google.android.gms.common.api.GoogleApiClient.Builder; + +import org.microg.gms.location.ActivityRecognitionApiBuilder; +import org.microg.gms.location.ActivityRecognitionApiImpl; + +/** + * The main entry point for activity recognition integration. + */ +public class ActivityRecognition { + public static final String CLIENT_NAME = "activity_recognition"; + + /** + * Token to pass to {@link Builder#addApi(Api)} to enable ContextServices. + */ + public static final Api API = new Api(new ActivityRecognitionApiBuilder()); + + /** + * Entry point to the activity recognition APIs. + */ + public static final ActivityRecognitionApi ActivityRecognitionApi = new ActivityRecognitionApiImpl(); +} diff --git a/play-services-location/src/main/java/com/google/android/gms/location/ActivityRecognitionApi.java b/play-services-location/src/main/java/com/google/android/gms/location/ActivityRecognitionApi.java new file mode 100644 index 00000000..08bc50b9 --- /dev/null +++ b/play-services-location/src/main/java/com/google/android/gms/location/ActivityRecognitionApi.java @@ -0,0 +1,115 @@ +/* + * 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.app.PendingIntent; +import android.os.Bundle; + +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; +import com.google.android.gms.common.api.PendingResult; +import com.google.android.gms.common.api.Status; + +/** + * The main entry point for interacting with activity recognition. + *

+ * The methods must be used in conjunction with a GoogleApiClient. E.g. + *

+ *  new GoogleApiClient.Builder(context)
+ *          .addApi(ActivityRecognition.API)
+ *          .addConnectionCallbacks(this)
+ *          .addOnConnectionFailedListener(this)
+ *          .build()
+ * 
+ */ +public interface ActivityRecognitionApi { + /** + * Removes all activity updates for the specified PendingIntent. + *

+ * Calling this function requires the com.google.android.gms.permission.ACTIVITY_RECOGNITION + * permission. + * + * @param client An existing GoogleApiClient. It must be connected at the time of this + * call, which is normally achieved by calling {@link GoogleApiClient#connect()} + * and waiting for {@link ConnectionCallbacks#onConnected(Bundle)} to be + * called. + * @param callbackIntent the PendingIntent that was used in {@code #requestActivityUpdates(GoogleApiClient, long, PendingIntent)} + * or is equal as defined by {@link Object#equals(Object)}. + * @return a PendingResult for the call, check {@link Status#isSuccess()} to determine if it + * was successful. + */ + PendingResult removeActivityUpdates(GoogleApiClient client, PendingIntent callbackIntent); + + /** + * Register for activity recognition updates. + *

+ * The activities are detected by periodically waking up the device and reading short bursts of + * sensor data. It only makes use of low power sensors in order to keep the power usage to a + * minimum. For example, it can detect if the user is currently on foot, in a car, on a bicycle + * or still. See {@link DetectedActivity} for more details. + *

+ * The activity detection update interval can be controlled with the detectionIntervalMillis + * parameter. Larger values will result in fewer activity detections while improving battery + * life. Smaller values will result in more frequent activity detections but will consume more + * power since the device must be woken up more frequently. {@code Long.MAX_VALUE} means it only + * monitors the results requested by other clients without consuming additional power. + *

+ * Activities may be received more frequently than the detectionIntervalMillis parameter if + * another application has also requested activity updates at a faster rate. It may also receive + * updates faster when the activity detection service receives a signal that the current + * activity may change, such as if the device has been still for a long period of time and is + * then unplugged from a phone charger. + *

+ * Activities may arrive several seconds after the requested detectionIntervalMillis if the + * activity detection service requires more samples to make a more accurate prediction. + *

+ * To conserve battery, activity reporting may stop when the device is 'STILL' for an extended + * period of time. It will resume once the device moves again. This only happens on devices that + * support the Sensor.TYPE_SIGNIFICANT_MOTION hardware. + *

+ * Beginning in API 21, activities may be received less frequently than the + * detectionIntervalMillis parameter if the device is in power save mode and the screen is off. + *

+ * A common use case is that an application wants to monitor activities in the background and + * perform an action when a specific activity is detected. To do this without needing a service + * that is always on in the background consuming resources, detected activities are delivered + * via an intent. The application specifies a PendingIntent callback (typically an + * IntentService) which will be called with an intent when activities are detected. The intent + * recipient can extract the {@link ActivityRecognitionResult} using {@link ActivityRecognitionResult#extractResult(android.content.Intent)}. + * See the documentation of {@link PendingIntent} for more details. + *

+ * Any requests previously registered with {@link #requestActivityUpdates(GoogleApiClient, long, PendingIntent)} + * that have the same PendingIntent (as defined by {@link Object#equals(Object)}) will be + * replaced by this request. + *

+ * Calling this function requires the com.google.android.gms.permission.ACTIVITY_RECOGNITION + * permission. + * + * @param client An existing GoogleApiClient. It must be connected at the time + * of this call, which is normally achieved by calling {@link GoogleApiClient#connect()} + * and waiting for {@link ConnectionCallbacks#onConnected(Bundle)} + * to be called. + * @param detectionIntervalMillis the desired time between activity detections. Larger values + * will result in fewer activity detections while improving + * battery life. A value of 0 will result in activity detections + * at the fastest possible rate. + * @param callbackIntent a PendingIntent to be sent for each activity detection. + * @return a PendingResult for the call, check {@link Status#isSuccess()} to determine if it + * was successful. + */ + PendingResult requestActivityUpdates(GoogleApiClient client, long detectionIntervalMillis, PendingIntent callbackIntent); +} diff --git a/play-services-location/src/main/java/com/google/android/gms/location/FusedLocationProviderApi.java b/play-services-location/src/main/java/com/google/android/gms/location/FusedLocationProviderApi.java index 14a92352..0e2fb00e 100644 --- a/play-services-location/src/main/java/com/google/android/gms/location/FusedLocationProviderApi.java +++ b/play-services-location/src/main/java/com/google/android/gms/location/FusedLocationProviderApi.java @@ -22,30 +22,32 @@ import android.os.Looper; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.common.api.PendingResult; +import com.google.android.gms.common.api.Status; import org.microg.gms.location.LocationConstants; public interface FusedLocationProviderApi { + @Deprecated String KEY_LOCATION_CHANGED = "com.google.android.location.LOCATION"; String KEY_MOCK_LOCATION = LocationConstants.KEY_MOCK_LOCATION; Location getLastLocation(GoogleApiClient client); - PendingResult requestLocationUpdates(GoogleApiClient client, LocationRequest request, - LocationListener listener); + PendingResult requestLocationUpdates(GoogleApiClient client, LocationRequest request, + LocationListener listener); - PendingResult requestLocationUpdates(GoogleApiClient client, LocationRequest request, + PendingResult requestLocationUpdates(GoogleApiClient client, LocationRequest request, LocationListener listener, Looper looper); - PendingResult requestLocationUpdates(GoogleApiClient client, LocationRequest request, + PendingResult requestLocationUpdates(GoogleApiClient client, LocationRequest request, PendingIntent callbackIntent); - PendingResult removeLocationUpdates(GoogleApiClient client, LocationListener listener); + PendingResult removeLocationUpdates(GoogleApiClient client, LocationListener listener); - PendingResult removeLocationUpdates(GoogleApiClient client, + PendingResult removeLocationUpdates(GoogleApiClient client, PendingIntent callbackIntent); - PendingResult setMockMode(GoogleApiClient client, boolean isMockMode); + PendingResult setMockMode(GoogleApiClient client, boolean isMockMode); - PendingResult setMockLocation(GoogleApiClient client, Location mockLocation); + PendingResult setMockLocation(GoogleApiClient client, Location mockLocation); } diff --git a/play-services-location/src/main/java/com/google/android/gms/location/LocationStatusCodes.java b/play-services-location/src/main/java/com/google/android/gms/location/LocationStatusCodes.java new file mode 100644 index 00000000..4e3f7d54 --- /dev/null +++ b/play-services-location/src/main/java/com/google/android/gms/location/LocationStatusCodes.java @@ -0,0 +1,26 @@ +/* + * 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; + +@Deprecated +public class LocationStatusCodes { + public static final int ERROR = 1; + public static final int GEOFENCE_NOT_AVAILABLE = 1000; + public static final int GEOFENCE_TOO_MANY_GEOFENCES = 1001; + public static final int GEOFENCE_TOO_MANY_PENDING_INTENTS = 1002; + public static final int SUCCESS = 0; +} diff --git a/play-services-location/src/main/java/org/microg/gms/location/ActivityRecognitionApiBuilder.java b/play-services-location/src/main/java/org/microg/gms/location/ActivityRecognitionApiBuilder.java new file mode 100644 index 00000000..f36ed0c0 --- /dev/null +++ b/play-services-location/src/main/java/org/microg/gms/location/ActivityRecognitionApiBuilder.java @@ -0,0 +1,34 @@ +/* + * 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 org.microg.gms.location; + +import android.content.Context; +import android.os.Looper; + +import com.google.android.gms.common.api.AccountInfo; +import com.google.android.gms.common.api.Api; +import com.google.android.gms.common.api.GoogleApiClient; + +import org.microg.gms.common.api.ApiBuilder; +import org.microg.gms.common.api.ApiConnection; + +public class ActivityRecognitionApiBuilder implements ApiBuilder { + @Override + public ApiConnection build(Context context, Looper looper, Api.ApiOptions.NoOptions options, AccountInfo accountInfo, GoogleApiClient.ConnectionCallbacks callbacks, GoogleApiClient.OnConnectionFailedListener connectionFailedListener) { + return new ActivityRecognitionClientImpl(context, callbacks, connectionFailedListener); + } +} diff --git a/play-services-location/src/main/java/org/microg/gms/location/ActivityRecognitionApiImpl.java b/play-services-location/src/main/java/org/microg/gms/location/ActivityRecognitionApiImpl.java new file mode 100644 index 00000000..5c09eefd --- /dev/null +++ b/play-services-location/src/main/java/org/microg/gms/location/ActivityRecognitionApiImpl.java @@ -0,0 +1,67 @@ +/* + * 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 org.microg.gms.location; + +import android.app.PendingIntent; +import android.os.RemoteException; +import android.util.Log; + +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.common.api.PendingResult; +import com.google.android.gms.common.api.Status; +import com.google.android.gms.location.ActivityRecognition; +import com.google.android.gms.location.ActivityRecognitionApi; + +import org.microg.gms.common.GmsConnector; + +public class ActivityRecognitionApiImpl implements ActivityRecognitionApi { + private static final String TAG = "GmsActivityApiImpl"; + + @Override + public PendingResult removeActivityUpdates(GoogleApiClient client, final PendingIntent callbackIntent) { + return callVoid(client, new Runnable() { + @Override + public void run(ActivityRecognitionClientImpl client) throws RemoteException { + client.removeActivityUpdates(callbackIntent); + } + }); + } + + @Override + public PendingResult requestActivityUpdates(GoogleApiClient client, final long detectionIntervalMillis, final PendingIntent callbackIntent) { + return callVoid(client, new Runnable() { + @Override + public void run(ActivityRecognitionClientImpl client) throws RemoteException { + client.requestActivityUpdates(detectionIntervalMillis, callbackIntent); + } + }); + } + + private PendingResult callVoid(GoogleApiClient client, final Runnable runnable) { + return GmsConnector.call(client, ActivityRecognition.API, new GmsConnector.Callback() { + @Override + public void onClientAvailable(ActivityRecognitionClientImpl client, ResultProvider resultProvider) throws RemoteException { + runnable.run(client); + resultProvider.onResultAvailable(Status.SUCCESS); + } + }); + } + + private interface Runnable { + void run(ActivityRecognitionClientImpl client) throws RemoteException; + } +} diff --git a/play-services-location/src/main/java/org/microg/gms/location/ActivityRecognitionClientImpl.java b/play-services-location/src/main/java/org/microg/gms/location/ActivityRecognitionClientImpl.java new file mode 100644 index 00000000..cf065fc9 --- /dev/null +++ b/play-services-location/src/main/java/org/microg/gms/location/ActivityRecognitionClientImpl.java @@ -0,0 +1,37 @@ +/* + * 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 org.microg.gms.location; + +import android.app.PendingIntent; +import android.content.Context; +import android.os.RemoteException; + +import com.google.android.gms.common.api.GoogleApiClient; + +public class ActivityRecognitionClientImpl extends GoogleLocationManagerClient { + public ActivityRecognitionClientImpl(Context context, GoogleApiClient.ConnectionCallbacks callbacks, GoogleApiClient.OnConnectionFailedListener connectionFailedListener) { + super(context, callbacks, connectionFailedListener); + } + + public void requestActivityUpdates(long detectionIntervalMillis, PendingIntent callbackIntent) throws RemoteException { + getServiceInterface().requestActivityUpdates(detectionIntervalMillis, true, callbackIntent); + } + + public void removeActivityUpdates(PendingIntent callbackIntent) throws RemoteException { + getServiceInterface().removeActivityUpdates(callbackIntent); + } +} diff --git a/play-services-location/src/main/java/org/microg/gms/location/FusedLocationProviderApiImpl.java b/play-services-location/src/main/java/org/microg/gms/location/FusedLocationProviderApiImpl.java index 5ce97ba8..4da06a0a 100644 --- a/play-services-location/src/main/java/org/microg/gms/location/FusedLocationProviderApiImpl.java +++ b/play-services-location/src/main/java/org/microg/gms/location/FusedLocationProviderApiImpl.java @@ -49,7 +49,7 @@ public class FusedLocationProviderApiImpl implements FusedLocationProviderApi { } @Override - public PendingResult requestLocationUpdates(GoogleApiClient client, + public PendingResult requestLocationUpdates(GoogleApiClient client, final LocationRequest request, final LocationListener listener) { return callVoid(client, new Runnable() { @Override @@ -60,7 +60,7 @@ public class FusedLocationProviderApiImpl implements FusedLocationProviderApi { } @Override - public PendingResult requestLocationUpdates(GoogleApiClient client, + public PendingResult requestLocationUpdates(GoogleApiClient client, final LocationRequest request, final LocationListener listener, final Looper looper) { return callVoid(client, new Runnable() { @@ -72,7 +72,7 @@ public class FusedLocationProviderApiImpl implements FusedLocationProviderApi { } @Override - public PendingResult requestLocationUpdates(GoogleApiClient client, + public PendingResult requestLocationUpdates(GoogleApiClient client, final LocationRequest request, final PendingIntent callbackIntent) { return callVoid(client, new Runnable() { @Override @@ -83,7 +83,7 @@ public class FusedLocationProviderApiImpl implements FusedLocationProviderApi { } @Override - public PendingResult removeLocationUpdates(GoogleApiClient client, + public PendingResult removeLocationUpdates(GoogleApiClient client, final LocationListener listener) { return callVoid(client, new Runnable() { @Override @@ -94,7 +94,7 @@ public class FusedLocationProviderApiImpl implements FusedLocationProviderApi { } @Override - public PendingResult removeLocationUpdates(GoogleApiClient client, + public PendingResult removeLocationUpdates(GoogleApiClient client, final PendingIntent callbackIntent) { return callVoid(client, new Runnable() { @Override @@ -105,7 +105,7 @@ public class FusedLocationProviderApiImpl implements FusedLocationProviderApi { } @Override - public PendingResult setMockMode(GoogleApiClient client, final boolean isMockMode) { + public PendingResult setMockMode(GoogleApiClient client, final boolean isMockMode) { return callVoid(client, new Runnable() { @Override public void run(LocationClientImpl client) throws RemoteException { @@ -115,7 +115,7 @@ public class FusedLocationProviderApiImpl implements FusedLocationProviderApi { } @Override - public PendingResult setMockLocation(GoogleApiClient client, final Location mockLocation) { + public PendingResult setMockLocation(GoogleApiClient client, final Location mockLocation) { return callVoid(client, new Runnable() { @Override public void run(LocationClientImpl client) throws RemoteException { @@ -124,10 +124,10 @@ public class FusedLocationProviderApiImpl implements FusedLocationProviderApi { }); } - private PendingResult callVoid(GoogleApiClient client, final Runnable runnable) { - return GmsConnector.call(client, LocationServices.API, new GmsConnector.Callback() { + private PendingResult callVoid(GoogleApiClient client, final Runnable runnable) { + return GmsConnector.call(client, LocationServices.API, new GmsConnector.Callback() { @Override - public void onClientAvailable(LocationClientImpl client, ResultProvider resultProvider) throws RemoteException { + public void onClientAvailable(LocationClientImpl client, ResultProvider resultProvider) throws RemoteException { runnable.run(client); resultProvider.onResultAvailable(Status.SUCCESS); }