From ad1d47e1cf3f45752b5ae3bf7691bfa187d4ab8d Mon Sep 17 00:00:00 2001 From: mar-v-in Date: Mon, 26 Jan 2015 00:43:41 +0100 Subject: [PATCH] Start adding support for wearable API --- GmsApi | 2 +- .../gms/common/GooglePlayServicesUtil.java | 2 + .../google/android/gms/common/api/Api.java | 9 ++++ .../gms/common/api/GoogleApiClient.java | 5 ++ .../android/gms/location/LocationClient.java | 4 ++ .../gms/location/LocationServices.java | 21 ++------- .../google/android/gms/wearable/DataApi.java | 20 ++++++++ .../android/gms/wearable/MessageApi.java | 20 ++++++++ .../google/android/gms/wearable/NodeApi.java | 20 ++++++++ .../google/android/gms/wearable/Wearable.java | 47 +++++++++++++++++++ .../location/LocationServicesApiBuilder.java | 37 +++++++++++++++ src/org/microg/gms/wearable/DataApiImpl.java | 22 +++++++++ .../microg/gms/wearable/MessageApiImpl.java | 22 +++++++++ src/org/microg/gms/wearable/NodeApiImpl.java | 22 +++++++++ .../gms/wearable/WearableApiBuilder.java | 40 ++++++++++++++++ 15 files changed, 274 insertions(+), 19 deletions(-) create mode 100644 src/com/google/android/gms/wearable/DataApi.java create mode 100644 src/com/google/android/gms/wearable/MessageApi.java create mode 100644 src/com/google/android/gms/wearable/NodeApi.java create mode 100644 src/com/google/android/gms/wearable/Wearable.java create mode 100644 src/org/microg/gms/location/LocationServicesApiBuilder.java create mode 100644 src/org/microg/gms/wearable/DataApiImpl.java create mode 100644 src/org/microg/gms/wearable/MessageApiImpl.java create mode 100644 src/org/microg/gms/wearable/NodeApiImpl.java create mode 100644 src/org/microg/gms/wearable/WearableApiBuilder.java diff --git a/GmsApi b/GmsApi index c4db81d..3c19d84 160000 --- a/GmsApi +++ b/GmsApi @@ -1 +1 @@ -Subproject commit c4db81d1fcf5c301f34e12d5675b9b50c507bd42 +Subproject commit 3c19d84eaa9842a2526166a38ad445125dbd2300 diff --git a/src/com/google/android/gms/common/GooglePlayServicesUtil.java b/src/com/google/android/gms/common/GooglePlayServicesUtil.java index f1dc70c..6da29c4 100644 --- a/src/com/google/android/gms/common/GooglePlayServicesUtil.java +++ b/src/com/google/android/gms/common/GooglePlayServicesUtil.java @@ -10,6 +10,7 @@ import android.content.pm.PackageManager; import android.util.Log; import org.microg.gms.Constants; +import org.microg.gms.PublicApi; /** * Utility class for verifying that the Google Play services APK is available and up-to-date on @@ -19,6 +20,7 @@ import org.microg.gms.Constants; * TODO: methods :) */ public class GooglePlayServicesUtil { + @PublicApi(exclude = true) private static final String TAG = "GooglePlayServicesUtil"; public static final String GMS_ERROR_DIALOG = "GooglePlayServicesErrorDialog"; diff --git a/src/com/google/android/gms/common/api/Api.java b/src/com/google/android/gms/common/api/Api.java index ffbeedd..3e5482a 100644 --- a/src/com/google/android/gms/common/api/Api.java +++ b/src/com/google/android/gms/common/api/Api.java @@ -1,5 +1,6 @@ package com.google.android.gms.common.api; +import org.microg.gms.PublicApi; import org.microg.gms.common.api.ApiBuilder; /** @@ -14,14 +15,17 @@ import org.microg.gms.common.api.ApiBuilder; *

* See {@link GoogleApiClient.Builder} for usage examples. */ +@PublicApi public final class Api { private final ApiBuilder builder; + @PublicApi(exclude = true) public Api(ApiBuilder builder) { this.builder = builder; } + @PublicApi(exclude = true) public ApiBuilder getBuilder() { return builder; } @@ -30,28 +34,33 @@ public final class Api { * Base interface for API options. These are used to configure specific parameters for * individual API surfaces. The default implementation has no parameters. */ + @PublicApi public interface ApiOptions { /** * Base interface for {@link ApiOptions} in {@link Api}s that have options. */ + @PublicApi public interface HasOptions extends ApiOptions { } /** * Base interface for {@link ApiOptions} that are not required, don't exist. */ + @PublicApi public interface NotRequiredOptions extends ApiOptions { } /** * {@link ApiOptions} implementation for {@link Api}s that do not take any options. */ + @PublicApi public final class NoOptions implements NotRequiredOptions { } /** * Base interface for {@link ApiOptions} that are optional. */ + @PublicApi public interface Optional extends HasOptions, NotRequiredOptions { } } diff --git a/src/com/google/android/gms/common/api/GoogleApiClient.java b/src/com/google/android/gms/common/api/GoogleApiClient.java index 92a2ee6..672a1a7 100644 --- a/src/com/google/android/gms/common/api/GoogleApiClient.java +++ b/src/com/google/android/gms/common/api/GoogleApiClient.java @@ -11,6 +11,7 @@ import android.view.View; import com.google.android.gms.common.ConnectionResult; import org.microg.gms.Constants; +import org.microg.gms.PublicApi; import org.microg.gms.common.api.GoogleApiClientImpl; import java.util.HashMap; @@ -37,6 +38,7 @@ import java.util.concurrent.TimeUnit; * method and then call {@link #connect()} in {@link Activity#onStart()} and {@link #disconnect()} * in {@link Activity#onStop()}, regardless of the state. */ +@PublicApi public interface GoogleApiClient { /** * Connects the client to Google Play services. Blocks until the connection either succeeds or @@ -217,6 +219,7 @@ public interface GoogleApiClient { /** * Builder to configure a {@link GoogleApiClient}. */ + @PublicApi public class Builder { private final Context context; private final Map apis = new HashMap<>(); @@ -412,6 +415,7 @@ public interface GoogleApiClient { * Provides callbacks that are called when the client is connected or disconnected from the * service. Most applications implement {@link #onConnected(Bundle)} to start making requests. */ + @PublicApi public interface ConnectionCallbacks { /** * A suspension cause informing that the service has been killed. @@ -456,6 +460,7 @@ public interface GoogleApiClient { * the service. See {@link ConnectionResult} for a list of error codes and suggestions for * resolution. */ + @PublicApi public interface OnConnectionFailedListener { /** * Called when there was an error connecting the client to the service. diff --git a/src/com/google/android/gms/location/LocationClient.java b/src/com/google/android/gms/location/LocationClient.java index 130c9ed..06b766d 100644 --- a/src/com/google/android/gms/location/LocationClient.java +++ b/src/com/google/android/gms/location/LocationClient.java @@ -12,6 +12,10 @@ import org.microg.gms.common.ForwardConnectionCallbacks; import org.microg.gms.common.ForwardConnectionFailedListener; import org.microg.gms.common.api.AbstractPlayServicesClient; +/** + * This class is deprecated as of play services 6.5, do not use it in production systems, + * it's just a forwarder for the {@link FusedLocationProviderApi}. + */ @Deprecated public class LocationClient extends AbstractPlayServicesClient { public static final String KEY_LOCATION_CHANGED = "com.google.android.location.LOCATION"; diff --git a/src/com/google/android/gms/location/LocationServices.java b/src/com/google/android/gms/location/LocationServices.java index c0949f4..5dddd2b 100644 --- a/src/com/google/android/gms/location/LocationServices.java +++ b/src/com/google/android/gms/location/LocationServices.java @@ -1,32 +1,17 @@ package com.google.android.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; import org.microg.gms.location.FusedLocationProviderApiImpl; import org.microg.gms.location.GeofencingApiImpl; -import org.microg.gms.location.LocationClientImpl; +import org.microg.gms.location.LocationServicesApiBuilder; /** * The main entry point for location services integration. */ public class LocationServices { - public static final Api API = new Api<>( - new ApiBuilder() { - @Override - public ApiConnection build(Context context, Looper looper, - Api.ApiOptions.NoOptions options, - AccountInfo accountInfo, GoogleApiClient.ConnectionCallbacks callbacks, - GoogleApiClient.OnConnectionFailedListener connectionFailedListener) { - return new LocationClientImpl(context, callbacks, connectionFailedListener); - } - }); + public static final Api API = new Api<>(new + LocationServicesApiBuilder()); public static final FusedLocationProviderApi FusedLocationApi = new FusedLocationProviderApiImpl(); public static final GeofencingApi GeofencingApi = new GeofencingApiImpl(); diff --git a/src/com/google/android/gms/wearable/DataApi.java b/src/com/google/android/gms/wearable/DataApi.java new file mode 100644 index 0000000..c26bdf2 --- /dev/null +++ b/src/com/google/android/gms/wearable/DataApi.java @@ -0,0 +1,20 @@ +/* + * Copyright 2014-2015 µg 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.wearable; + +public interface DataApi { +} diff --git a/src/com/google/android/gms/wearable/MessageApi.java b/src/com/google/android/gms/wearable/MessageApi.java new file mode 100644 index 0000000..730ebe4 --- /dev/null +++ b/src/com/google/android/gms/wearable/MessageApi.java @@ -0,0 +1,20 @@ +/* + * Copyright 2014-2015 µg 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.wearable; + +public interface MessageApi { +} diff --git a/src/com/google/android/gms/wearable/NodeApi.java b/src/com/google/android/gms/wearable/NodeApi.java new file mode 100644 index 0000000..4aa5728 --- /dev/null +++ b/src/com/google/android/gms/wearable/NodeApi.java @@ -0,0 +1,20 @@ +/* + * Copyright 2014-2015 µg 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.wearable; + +public interface NodeApi { +} diff --git a/src/com/google/android/gms/wearable/Wearable.java b/src/com/google/android/gms/wearable/Wearable.java new file mode 100644 index 0000000..7200323 --- /dev/null +++ b/src/com/google/android/gms/wearable/Wearable.java @@ -0,0 +1,47 @@ +/* + * Copyright 2014-2015 µg 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.wearable; + +import com.google.android.gms.common.api.Api; +import com.google.android.gms.common.api.GoogleApiClient; + +import org.microg.gms.wearable.DataApiImpl; +import org.microg.gms.wearable.MessageApiImpl; +import org.microg.gms.wearable.NodeApiImpl; +import org.microg.gms.wearable.WearableApiBuilder; + +/** + * An API for the Android Wear platform. + */ +public class Wearable { + /** + * Token to pass to {@link GoogleApiClient.Builder#addApi(Api)} to enable the Wearable features. + */ + public static final Api API = new Api<>(new WearableApiBuilder()); + + public static final DataApi DataApi = new DataApiImpl(); + public static final MessageApi MessageApi = new MessageApiImpl(); + public static final NodeApi NodeApi = new NodeApiImpl(); + + public static class WearableOptions implements Api.ApiOptions.Optional { + public static class Builder { + public WearableOptions build() { + return new WearableOptions(); + } + } + } +} diff --git a/src/org/microg/gms/location/LocationServicesApiBuilder.java b/src/org/microg/gms/location/LocationServicesApiBuilder.java new file mode 100644 index 0000000..6876e63 --- /dev/null +++ b/src/org/microg/gms/location/LocationServicesApiBuilder.java @@ -0,0 +1,37 @@ +/* + * Copyright 2014-2015 µg 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 LocationServicesApiBuilder implements ApiBuilder { + @Override + public ApiConnection build(Context context, Looper looper, + Api.ApiOptions.NoOptions options, + AccountInfo accountInfo, GoogleApiClient.ConnectionCallbacks callbacks, + GoogleApiClient.OnConnectionFailedListener connectionFailedListener) { + return new LocationClientImpl(context, callbacks, connectionFailedListener); + } +} diff --git a/src/org/microg/gms/wearable/DataApiImpl.java b/src/org/microg/gms/wearable/DataApiImpl.java new file mode 100644 index 0000000..5d8f07e --- /dev/null +++ b/src/org/microg/gms/wearable/DataApiImpl.java @@ -0,0 +1,22 @@ +/* + * Copyright 2014-2015 µg 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.wearable; + +import com.google.android.gms.wearable.DataApi; + +public class DataApiImpl implements DataApi { +} diff --git a/src/org/microg/gms/wearable/MessageApiImpl.java b/src/org/microg/gms/wearable/MessageApiImpl.java new file mode 100644 index 0000000..6f055d5 --- /dev/null +++ b/src/org/microg/gms/wearable/MessageApiImpl.java @@ -0,0 +1,22 @@ +/* + * Copyright 2014-2015 µg 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.wearable; + +import com.google.android.gms.wearable.MessageApi; + +public class MessageApiImpl implements MessageApi { +} diff --git a/src/org/microg/gms/wearable/NodeApiImpl.java b/src/org/microg/gms/wearable/NodeApiImpl.java new file mode 100644 index 0000000..bf8bf5e --- /dev/null +++ b/src/org/microg/gms/wearable/NodeApiImpl.java @@ -0,0 +1,22 @@ +/* + * Copyright 2014-2015 µg 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.wearable; + +import com.google.android.gms.wearable.NodeApi; + +public class NodeApiImpl implements NodeApi { +} diff --git a/src/org/microg/gms/wearable/WearableApiBuilder.java b/src/org/microg/gms/wearable/WearableApiBuilder.java new file mode 100644 index 0000000..c19f5da --- /dev/null +++ b/src/org/microg/gms/wearable/WearableApiBuilder.java @@ -0,0 +1,40 @@ +/* + * Copyright 2014-2015 µg 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.wearable; + +import android.content.Context; +import android.os.Looper; +import android.util.Log; + +import com.google.android.gms.common.api.AccountInfo; +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.wearable.Wearable; + +import org.microg.gms.common.api.ApiBuilder; +import org.microg.gms.common.api.ApiConnection; + +public class WearableApiBuilder implements ApiBuilder { + private static final String TAG = "GmsWearableApi"; + + @Override + public ApiConnection build(Context context, Looper looper, Wearable.WearableOptions options, + AccountInfo accountInfo, GoogleApiClient.ConnectionCallbacks callbacks, + GoogleApiClient.OnConnectionFailedListener connectionFailedListener) { + Log.d(TAG, "Wearables not supported"); + return null; + } +}