From 7b897cd001376b841b3557b0e98d93ed4cb55e32 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sat, 11 Feb 2017 02:32:16 +0100 Subject: [PATCH] Add dummy SettingsApi --- .../gms/common/api/InstantPendingResult.java | 61 +++++++++++++++++++ .../gms/location/LocationServices.java | 18 ++++++ .../android/gms/location/SettingsApi.java | 41 +++++++++++++ .../microg/gms/location/SettingsApiImpl.java | 33 ++++++++++ 4 files changed, 153 insertions(+) create mode 100644 play-services-base/src/main/java/org/microg/gms/common/api/InstantPendingResult.java create mode 100644 play-services-location/src/main/java/com/google/android/gms/location/SettingsApi.java create mode 100644 play-services-location/src/main/java/org/microg/gms/location/SettingsApiImpl.java diff --git a/play-services-base/src/main/java/org/microg/gms/common/api/InstantPendingResult.java b/play-services-base/src/main/java/org/microg/gms/common/api/InstantPendingResult.java new file mode 100644 index 00000000..ba75725c --- /dev/null +++ b/play-services-base/src/main/java/org/microg/gms/common/api/InstantPendingResult.java @@ -0,0 +1,61 @@ +/* + * 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.common.api; + +import com.google.android.gms.common.api.PendingResult; +import com.google.android.gms.common.api.Result; +import com.google.android.gms.common.api.ResultCallback; + +import java.util.concurrent.TimeUnit; + +public class InstantPendingResult implements PendingResult { + R value; + + public InstantPendingResult(R value) { + this.value = value; + } + + @Override + public R await() { + return value; + } + + @Override + public R await(long time, TimeUnit unit) { + return value; + } + + @Override + public void cancel() { + + } + + @Override + public boolean isCanceled() { + return false; + } + + @Override + public void setResultCallback(ResultCallback callback, long time, TimeUnit unit) { + callback.onResult(value); + } + + @Override + public void setResultCallback(ResultCallback callback) { + callback.onResult(value); + } +} diff --git a/play-services-location/src/main/java/com/google/android/gms/location/LocationServices.java b/play-services-location/src/main/java/com/google/android/gms/location/LocationServices.java index dc575bb9..23fce208 100644 --- a/play-services-location/src/main/java/com/google/android/gms/location/LocationServices.java +++ b/play-services-location/src/main/java/com/google/android/gms/location/LocationServices.java @@ -17,16 +17,34 @@ 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.FusedLocationProviderApiImpl; import org.microg.gms.location.GeofencingApiImpl; import org.microg.gms.location.LocationServicesApiBuilder; +import org.microg.gms.location.SettingsApiImpl; /** * The main entry point for location services integration. */ public class LocationServices { + /** + * Token to pass to {@link Builder#addApi(Api)} to enable LocationServices. + */ public static final Api API = new Api(new LocationServicesApiBuilder()); + + /** + * Entry point to the fused location APIs. + */ public static final FusedLocationProviderApi FusedLocationApi = new FusedLocationProviderApiImpl(); + + /** + * Entry point to the geofencing APIs. + */ public static final GeofencingApi GeofencingApi = new GeofencingApiImpl(); + + /** + * Entry point to the location settings-enabler dialog APIs. + */ + public static final SettingsApi SettingsApi = new SettingsApiImpl(); } diff --git a/play-services-location/src/main/java/com/google/android/gms/location/SettingsApi.java b/play-services-location/src/main/java/com/google/android/gms/location/SettingsApi.java new file mode 100644 index 00000000..708d7d02 --- /dev/null +++ b/play-services-location/src/main/java/com/google/android/gms/location/SettingsApi.java @@ -0,0 +1,41 @@ +/* + * 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.GoogleApiClient; +import com.google.android.gms.common.api.PendingResult; + +/** + * The main entry point for interacting with the location settings-enabler APIs. + *

+ * This API makes it easy for an app to ensure that the device's system settings are properly + * configured for the app's location needs. + */ +public interface SettingsApi { + /** + * Checks if the relevant system settings are enabled on the device to carry out the desired + * location requests. + * + * @param client an existing GoogleApiClient. It does not need to be connected + * at the time of this call, but the result will be delayed until + * the connection is complete. + * @param locationSettingsRequest an object that contains all the location requirements that the + * client is interested in. + * @return result containing the status of the request. + */ + PendingResult checkLocationSettings(GoogleApiClient client, LocationSettingsRequest locationSettingsRequest); +} diff --git a/play-services-location/src/main/java/org/microg/gms/location/SettingsApiImpl.java b/play-services-location/src/main/java/org/microg/gms/location/SettingsApiImpl.java new file mode 100644 index 00000000..b8fe0ffe --- /dev/null +++ b/play-services-location/src/main/java/org/microg/gms/location/SettingsApiImpl.java @@ -0,0 +1,33 @@ +/* + * 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 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.LocationSettingsRequest; +import com.google.android.gms.location.LocationSettingsResult; +import com.google.android.gms.location.SettingsApi; + +import org.microg.gms.common.api.InstantPendingResult; + +public class SettingsApiImpl implements SettingsApi { + @Override + public PendingResult checkLocationSettings(GoogleApiClient client, LocationSettingsRequest locationSettingsRequest) { + return new InstantPendingResult(new LocationSettingsResult(Status.CANCELED)); + } +}