mirror of
https://github.com/YTVanced/VancedMicroG
synced 2024-11-30 23:23:01 +00:00
Some work...
This commit is contained in:
parent
d2fb7d569b
commit
6af3c0b700
10 changed files with 173 additions and 30 deletions
|
@ -1,7 +1,6 @@
|
||||||
package com.google.android.gms.common.api;
|
package com.google.android.gms.common.api;
|
||||||
|
|
||||||
import android.content.Context;
|
import org.microg.gms.common.api.ApiBuilder;
|
||||||
import android.os.Looper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes a section of the Google Play Services API that should be made available. Instances of
|
* Describes a section of the Google Play Services API that should be made available. Instances of
|
||||||
|
@ -17,13 +16,13 @@ import android.os.Looper;
|
||||||
*/
|
*/
|
||||||
public final class Api<O extends Api.ApiOptions> {
|
public final class Api<O extends Api.ApiOptions> {
|
||||||
|
|
||||||
private final Builder<O> builder;
|
private final ApiBuilder<O> builder;
|
||||||
|
|
||||||
public Api(Builder<O> builder) {
|
public Api(ApiBuilder<O> builder) {
|
||||||
this.builder = builder;
|
this.builder = builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder<O> getBuilder() {
|
public ApiBuilder<O> getBuilder() {
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,15 +56,4 @@ public final class Api<O extends Api.ApiOptions> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Connection {
|
|
||||||
public void connect();
|
|
||||||
public void disconnect();
|
|
||||||
public boolean isConnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface Builder<O extends ApiOptions> {
|
|
||||||
Connection build(Context context, Looper looper, O options, AccountInfo accountInfo,
|
|
||||||
GoogleApiClient.ConnectionCallbacks callbacks,
|
|
||||||
GoogleApiClient.OnConnectionFailedListener connectionFailedListener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,9 @@ import android.content.Context;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import com.google.android.gms.common.api.AccountInfo;
|
import com.google.android.gms.common.api.AccountInfo;
|
||||||
import com.google.android.gms.common.api.Api;
|
import com.google.android.gms.common.api.Api;
|
||||||
|
import org.microg.gms.common.api.ApiConnection;
|
||||||
|
|
||||||
|
import org.microg.gms.common.api.ApiBuilder;
|
||||||
import com.google.android.gms.common.api.GoogleApiClient;
|
import com.google.android.gms.common.api.GoogleApiClient;
|
||||||
import org.microg.gms.location.FusedLocationProviderApiImpl;
|
import org.microg.gms.location.FusedLocationProviderApiImpl;
|
||||||
import org.microg.gms.location.GeofencingApiImpl;
|
import org.microg.gms.location.GeofencingApiImpl;
|
||||||
|
@ -14,9 +17,9 @@ import org.microg.gms.location.LocationClientImpl;
|
||||||
*/
|
*/
|
||||||
public class LocationServices {
|
public class LocationServices {
|
||||||
public static final Api<Api.ApiOptions.NoOptions> API = new Api<>(
|
public static final Api<Api.ApiOptions.NoOptions> API = new Api<>(
|
||||||
new Api.Builder<Api.ApiOptions.NoOptions>() {
|
new ApiBuilder<Api.ApiOptions.NoOptions>() {
|
||||||
@Override
|
@Override
|
||||||
public Api.Connection build(Context context, Looper looper,
|
public ApiConnection build(Context context, Looper looper,
|
||||||
Api.ApiOptions.NoOptions options,
|
Api.ApiOptions.NoOptions options,
|
||||||
AccountInfo accountInfo, GoogleApiClient.ConnectionCallbacks callbacks,
|
AccountInfo accountInfo, GoogleApiClient.ConnectionCallbacks callbacks,
|
||||||
GoogleApiClient.OnConnectionFailedListener connectionFailedListener) {
|
GoogleApiClient.OnConnectionFailedListener connectionFailedListener) {
|
||||||
|
|
|
@ -9,11 +9,11 @@ import android.os.IInterface;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import com.google.android.gms.common.ConnectionResult;
|
import com.google.android.gms.common.ConnectionResult;
|
||||||
import com.google.android.gms.common.GooglePlayServicesUtil;
|
import com.google.android.gms.common.GooglePlayServicesUtil;
|
||||||
import com.google.android.gms.common.api.Api;
|
import org.microg.gms.common.api.ApiConnection;
|
||||||
import com.google.android.gms.common.internal.IGmsCallbacks;
|
import com.google.android.gms.common.internal.IGmsCallbacks;
|
||||||
import com.google.android.gms.common.internal.IGmsServiceBroker;
|
import com.google.android.gms.common.internal.IGmsServiceBroker;
|
||||||
|
|
||||||
public abstract class GmsClient<I extends IInterface> implements Api.Connection {
|
public abstract class GmsClient<I extends IInterface> implements ApiConnection {
|
||||||
private static final String TAG = "GmsClient";
|
private static final String TAG = "GmsClient";
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
79
src/org/microg/gms/common/GmsConnector.java
Normal file
79
src/org/microg/gms/common/GmsConnector.java
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* 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.common;
|
||||||
|
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
|
||||||
|
import com.google.android.gms.common.api.Api;
|
||||||
|
|
||||||
|
import org.microg.gms.common.api.AbstractPendingResult;
|
||||||
|
import org.microg.gms.common.api.ApiConnection;
|
||||||
|
|
||||||
|
import com.google.android.gms.common.api.GoogleApiClient;
|
||||||
|
import com.google.android.gms.common.api.Result;
|
||||||
|
|
||||||
|
import org.microg.gms.common.api.GoogleApiClientImpl;
|
||||||
|
|
||||||
|
public class GmsConnector {
|
||||||
|
public static <C extends ApiConnection, R extends Result, O extends Api.ApiOptions>
|
||||||
|
AbstractPendingResult<R> connect(GoogleApiClient apiClient, Api<O> api, Callback<C, R> callback) {
|
||||||
|
Looper looper = ((GoogleApiClientImpl) apiClient).getLooper();
|
||||||
|
final AbstractPendingResult<R> result = new AbstractPendingResult<>(looper);
|
||||||
|
Message msg = new Message();
|
||||||
|
msg.obj = new ConnectRequest<C, R, O>((GoogleApiClientImpl) apiClient, api, result, callback);
|
||||||
|
new Handler<C, R, O>(looper).sendMessage(msg);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface Callback<C, R> {
|
||||||
|
public R onClientAvailable(C client) throws RemoteException;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Handler<C extends ApiConnection, R extends Result, O extends Api.ApiOptions> extends android.os.Handler {
|
||||||
|
private Handler(Looper looper) {
|
||||||
|
super(looper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
ConnectRequest<C, R, O> request = (ConnectRequest<C, R, O>) msg.obj;
|
||||||
|
ApiConnection apiConnection = request.apiClient.getApiConnection(request.api);
|
||||||
|
apiConnection.connect();
|
||||||
|
try {
|
||||||
|
request.result.setResult(request.callback.onClientAvailable((C) apiConnection));
|
||||||
|
} catch (RemoteException ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ConnectRequest<C extends ApiConnection, R extends Result, O extends Api.ApiOptions> {
|
||||||
|
GoogleApiClientImpl apiClient;
|
||||||
|
Api<O> api;
|
||||||
|
AbstractPendingResult<R> result;
|
||||||
|
Callback<C, R> callback;
|
||||||
|
|
||||||
|
private ConnectRequest(GoogleApiClientImpl apiClient, Api<O> api, AbstractPendingResult<R> result, Callback<C, R> callback) {
|
||||||
|
this.apiClient = apiClient;
|
||||||
|
this.api = api;
|
||||||
|
this.result = result;
|
||||||
|
this.callback = callback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,13 +11,13 @@ import java.util.concurrent.TimeUnit;
|
||||||
public class AbstractPendingResult<R extends Result> implements PendingResult<R> {
|
public class AbstractPendingResult<R extends Result> implements PendingResult<R> {
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
private final CountDownLatch countDownLatch = new CountDownLatch(1);
|
private final CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||||
private final CallbackHandler handler;
|
private final CallbackHandler<R> handler;
|
||||||
private boolean canceled;
|
private boolean canceled;
|
||||||
private R result;
|
private R result;
|
||||||
private ResultCallback<R> resultCallback;
|
private ResultCallback<R> resultCallback;
|
||||||
|
|
||||||
public AbstractPendingResult(Looper looper) {
|
public AbstractPendingResult(Looper looper) {
|
||||||
handler = new CallbackHandler(looper);
|
handler = new CallbackHandler<R>(looper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private R getResult() {
|
private R getResult() {
|
||||||
|
@ -92,4 +92,7 @@ public class AbstractPendingResult<R extends Result> implements PendingResult<R>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setResult(R result) {
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
32
src/org/microg/gms/common/api/ApiBuilder.java
Normal file
32
src/org/microg/gms/common/api/ApiBuilder.java
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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.common.api;
|
||||||
|
|
||||||
|
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.ApiConnection;
|
||||||
|
|
||||||
|
public interface ApiBuilder<O extends Api.ApiOptions> {
|
||||||
|
ApiConnection build(Context context, Looper looper, O options, AccountInfo accountInfo,
|
||||||
|
GoogleApiClient.ConnectionCallbacks callbacks,
|
||||||
|
GoogleApiClient.OnConnectionFailedListener connectionFailedListener);
|
||||||
|
}
|
23
src/org/microg/gms/common/api/ApiConnection.java
Normal file
23
src/org/microg/gms/common/api/ApiConnection.java
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* 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.common.api;
|
||||||
|
|
||||||
|
public interface ApiConnection {
|
||||||
|
public void connect();
|
||||||
|
public void disconnect();
|
||||||
|
public boolean isConnected();
|
||||||
|
}
|
|
@ -28,7 +28,10 @@ class CallbackHandler<R extends Result> extends Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendResultCallback(ResultCallback<R> callback, R result) {
|
public void sendResultCallback(ResultCallback<R> callback, R result) {
|
||||||
|
Message message = new Message();
|
||||||
|
message.what = CALLBACK_ON_COMPLETE;
|
||||||
|
message.obj = new OnCompleteObject<R>(callback, result);
|
||||||
|
sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendTimeoutResultCallback(AbstractPendingResult pendingResult, long millis) {
|
public void sendTimeoutResultCallback(AbstractPendingResult pendingResult, long millis) {
|
||||||
|
@ -38,5 +41,10 @@ class CallbackHandler<R extends Result> extends Handler {
|
||||||
public static class OnCompleteObject<R extends Result> {
|
public static class OnCompleteObject<R extends Result> {
|
||||||
public ResultCallback<R> callback;
|
public ResultCallback<R> callback;
|
||||||
public R result;
|
public R result;
|
||||||
|
|
||||||
|
public OnCompleteObject(ResultCallback<R> callback, R result) {
|
||||||
|
this.callback = callback;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,10 @@ public class GoogleApiClientImpl implements GoogleApiClient {
|
||||||
private final Looper looper;
|
private final Looper looper;
|
||||||
private final AccountInfo accountInfo;
|
private final AccountInfo accountInfo;
|
||||||
private final Map<Api, Api.ApiOptions> apis = new HashMap<>();
|
private final Map<Api, Api.ApiOptions> apis = new HashMap<>();
|
||||||
private final Map<Api, Api.Connection> apiConnections = new HashMap<>();
|
private final Map<Api, ApiConnection> apiConnections = new HashMap<>();
|
||||||
private final Set<ConnectionCallbacks> connectionCallbacks = new HashSet<>();
|
private final Set<ConnectionCallbacks> connectionCallbacks = new HashSet<>();
|
||||||
private final Set<OnConnectionFailedListener> connectionFailedListeners = new HashSet<>();
|
private final Set<OnConnectionFailedListener> connectionFailedListeners = new HashSet<>();
|
||||||
|
private final int clientId;
|
||||||
private final ConnectionCallbacks baseConnectionCallbacks = new ConnectionCallbacks() {
|
private final ConnectionCallbacks baseConnectionCallbacks = new ConnectionCallbacks() {
|
||||||
@Override
|
@Override
|
||||||
public void onConnected(Bundle connectionHint) {
|
public void onConnected(Bundle connectionHint) {
|
||||||
|
@ -44,7 +45,6 @@ public class GoogleApiClientImpl implements GoogleApiClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
private final int clientId;
|
|
||||||
|
|
||||||
public GoogleApiClientImpl(Context context, Looper looper, AccountInfo accountInfo,
|
public GoogleApiClientImpl(Context context, Looper looper, AccountInfo accountInfo,
|
||||||
Map<Api, Api.ApiOptions> apis,
|
Map<Api, Api.ApiOptions> apis,
|
||||||
|
@ -64,8 +64,12 @@ public class GoogleApiClientImpl implements GoogleApiClient {
|
||||||
baseConnectionFailedListener));
|
baseConnectionFailedListener));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Api.Connection getApiConnection(Api api) {
|
public Looper getLooper() {
|
||||||
|
return looper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiConnection getApiConnection(Api api) {
|
||||||
return apiConnections.get(api);
|
return apiConnections.get(api);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,21 +90,21 @@ public class GoogleApiClientImpl implements GoogleApiClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect() {
|
public void connect() {
|
||||||
for (Api.Connection connection : apiConnections.values()) {
|
for (ApiConnection connection : apiConnections.values()) {
|
||||||
connection.connect();
|
connection.connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
for (Api.Connection connection : apiConnections.values()) {
|
for (ApiConnection connection : apiConnections.values()) {
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
for (Api.Connection connection : apiConnections.values()) {
|
for (ApiConnection connection : apiConnections.values()) {
|
||||||
if (!connection.isConnected()) return false;
|
if (!connection.isConnected()) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -11,6 +11,8 @@ import com.google.android.gms.location.FusedLocationProviderApi;
|
||||||
import com.google.android.gms.location.LocationListener;
|
import com.google.android.gms.location.LocationListener;
|
||||||
import com.google.android.gms.location.LocationRequest;
|
import com.google.android.gms.location.LocationRequest;
|
||||||
|
|
||||||
|
import org.microg.gms.common.GmsConnector;
|
||||||
|
|
||||||
public class FusedLocationProviderApiImpl implements FusedLocationProviderApi {
|
public class FusedLocationProviderApiImpl implements FusedLocationProviderApi {
|
||||||
private static final String TAG = "GmsFusedApiImpl";
|
private static final String TAG = "GmsFusedApiImpl";
|
||||||
|
|
||||||
|
@ -27,6 +29,7 @@ public class FusedLocationProviderApiImpl implements FusedLocationProviderApi {
|
||||||
@Override
|
@Override
|
||||||
public PendingResult requestLocationUpdates(GoogleApiClient client, LocationRequest request,
|
public PendingResult requestLocationUpdates(GoogleApiClient client, LocationRequest request,
|
||||||
LocationListener listener) {
|
LocationListener listener) {
|
||||||
|
|
||||||
//LocationClientImpl.get(client).requestLocationUpdates(request, listener);
|
//LocationClientImpl.get(client).requestLocationUpdates(request, listener);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue