2015-01-11 23:08:51 +00:00
|
|
|
/*
|
2015-10-03 20:47:05 +00:00
|
|
|
* Copyright 2013-2015 microG Project Team
|
2015-01-11 23:08:51 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2015-01-28 14:29:50 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-01-11 23:08:51 +00:00
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
import android.accounts.Account;
|
2015-01-11 23:08:51 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.IBinder;
|
2015-03-11 21:47:41 +00:00
|
|
|
import android.os.Parcel;
|
2015-01-11 23:08:51 +00:00
|
|
|
import android.os.RemoteException;
|
2015-03-11 21:47:41 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
import com.google.android.gms.common.api.Scope;
|
|
|
|
import com.google.android.gms.common.internal.GetServiceRequest;
|
2015-01-11 23:08:51 +00:00
|
|
|
import com.google.android.gms.common.internal.IGmsCallbacks;
|
|
|
|
import com.google.android.gms.common.internal.IGmsServiceBroker;
|
2015-04-09 21:12:08 +00:00
|
|
|
import com.google.android.gms.common.internal.ValidateAccountRequest;
|
|
|
|
|
|
|
|
import org.microg.gms.common.Services;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2015-01-11 23:08:51 +00:00
|
|
|
|
|
|
|
public abstract class AbstractGmsServiceBroker extends IGmsServiceBroker.Stub {
|
2015-06-22 21:26:35 +00:00
|
|
|
public static final int ID_ACCEPT_ALL = -1;
|
|
|
|
|
2015-03-11 21:47:41 +00:00
|
|
|
private static final String TAG = "GmsServiceBroker";
|
2015-04-09 21:12:08 +00:00
|
|
|
private final Set<Integer> supportedServiceIds;
|
|
|
|
|
|
|
|
public AbstractGmsServiceBroker(Integer supportedServiceId, Integer... supportedServiceIds) {
|
2015-04-13 21:57:18 +00:00
|
|
|
this(combine(supportedServiceId, supportedServiceIds));
|
2015-04-09 21:12:08 +00:00
|
|
|
}
|
2015-03-11 21:47:41 +00:00
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
private static Set<Integer> combine(Integer i, Integer... is) {
|
2015-04-13 21:57:18 +00:00
|
|
|
Set<Integer> integers = new HashSet<Integer>(Arrays.asList(is));
|
2015-04-09 21:12:08 +00:00
|
|
|
integers.add(i);
|
|
|
|
return integers;
|
|
|
|
}
|
|
|
|
|
|
|
|
public AbstractGmsServiceBroker(Set<Integer> supportedServiceIds) {
|
|
|
|
this.supportedServiceIds = supportedServiceIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getPlusService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-04-09 21:12:08 +00:00
|
|
|
String authPackage, String[] scopes, String accountName, Bundle params)
|
2015-01-11 23:08:51 +00:00
|
|
|
throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
Bundle extras = params == null ? new Bundle() : params;
|
|
|
|
extras.putString("auth_package", authPackage);
|
|
|
|
callGetService(Services.PLUS.SERVICE_ID, callback, versionCode, packageName, extras, accountName, scopes);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getPanoramaService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-03-11 21:47:41 +00:00
|
|
|
Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.PANORAMA.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getAppDataSearchService(IGmsCallbacks callback, int versionCode, String packageName)
|
|
|
|
throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.INDEX.SERVICE_ID, callback, versionCode, packageName);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getWalletService(IGmsCallbacks callback, int versionCode) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
getWalletServiceWithPackageName(callback, versionCode, null);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getPeopleService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-03-11 21:47:41 +00:00
|
|
|
Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.PEOPLE.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getReportingService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-03-11 21:47:41 +00:00
|
|
|
Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.LOCATION_REPORTING.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getLocationService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-03-11 21:47:41 +00:00
|
|
|
Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.LOCATION.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getGoogleLocationManagerService(IGmsCallbacks callback, int versionCode,
|
2015-03-11 21:47:41 +00:00
|
|
|
String packageName, Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.LOCATION_MANAGER.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getGamesService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-04-09 21:12:08 +00:00
|
|
|
String accountName, String[] scopes, String gamePackageName,
|
|
|
|
IBinder popupWindowToken, String desiredLocale, Bundle params)
|
2015-01-11 23:08:51 +00:00
|
|
|
throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
Bundle extras = params == null ? new Bundle() : params;
|
|
|
|
extras.putString("com.google.android.gms.games.key.gamePackageName", gamePackageName);
|
|
|
|
extras.putString("com.google.android.gms.games.key.desiredLocale", desiredLocale);
|
|
|
|
//extras.putParcelable("com.google.android.gms.games.key.popupWindowToken", popupWindowToken);
|
|
|
|
callGetService(Services.GAMES.SERVICE_ID, callback, versionCode, packageName, extras, accountName, scopes);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getAppStateService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-04-09 21:12:08 +00:00
|
|
|
String accountName, String[] scopes) throws RemoteException {
|
|
|
|
callGetService(Services.APPSTATE.SERVICE_ID, callback, versionCode, packageName, null, accountName, scopes);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getPlayLogService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-03-11 21:47:41 +00:00
|
|
|
Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.PLAY_LOG.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getAdMobService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-03-11 21:47:41 +00:00
|
|
|
Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.ADREQUEST.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getDroidGuardService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-03-11 21:47:41 +00:00
|
|
|
Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.DROIDGUARD.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getLockboxService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-03-11 21:47:41 +00:00
|
|
|
Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.LOCKBOX.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getCastMirroringService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-03-11 21:47:41 +00:00
|
|
|
Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.CAST_MIRRORING.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getNetworkQualityService(IGmsCallbacks callback, int versionCode,
|
2015-03-11 21:47:41 +00:00
|
|
|
String packageName, Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.NETWORK_QUALITY.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getGoogleIdentityService(IGmsCallbacks callback, int versionCode,
|
2015-03-11 21:47:41 +00:00
|
|
|
String packageName, Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.ACCOUNT.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getGoogleFeedbackService(IGmsCallbacks callback, int versionCode,
|
2015-03-11 21:47:41 +00:00
|
|
|
String packageName, Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.FEEDBACK.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getCastService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-03-11 21:47:41 +00:00
|
|
|
IBinder binder, Bundle params) throws RemoteException {
|
2015-01-11 23:08:51 +00:00
|
|
|
throw new IllegalArgumentException("Cast service not supported");
|
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getDriveService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-04-09 21:12:08 +00:00
|
|
|
String[] scopes, String accountName, Bundle params) throws RemoteException {
|
|
|
|
callGetService(Services.DRIVE.SERVICE_ID, callback, versionCode, packageName, params, accountName, scopes);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getLightweightAppDataSearchService(IGmsCallbacks callback, int versionCode,
|
2015-03-11 21:47:41 +00:00
|
|
|
String packageName) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.LIGHTWEIGHT_INDEX.SERVICE_ID, callback, versionCode, packageName);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getSearchAdministrationService(IGmsCallbacks callback, int versionCode,
|
2015-03-11 21:47:41 +00:00
|
|
|
String packageName) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.SEARCH_ADMINISTRATION.SERVICE_ID, callback, versionCode, packageName);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getAutoBackupService(IGmsCallbacks callback, int versionCode, String packageName,
|
2015-03-11 21:47:41 +00:00
|
|
|
Bundle params) throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.PHOTO_AUTO_BACKUP.SERVICE_ID, callback, versionCode, packageName, params);
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 21:12:08 +00:00
|
|
|
@Deprecated
|
2015-01-11 23:08:51 +00:00
|
|
|
@Override
|
|
|
|
public void getAddressService(IGmsCallbacks callback, int versionCode, String packageName)
|
|
|
|
throws RemoteException {
|
2015-04-09 21:12:08 +00:00
|
|
|
callGetService(Services.ADDRESS.SERVICE_ID, callback, versionCode, packageName);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
@Override
|
|
|
|
public void getWalletServiceWithPackageName(IGmsCallbacks callback, int versionCode, String packageName) throws RemoteException {
|
|
|
|
callGetService(Services.WALLET.SERVICE_ID, callback, versionCode, packageName);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void callGetService(int serviceId, IGmsCallbacks callback, int gmsVersion,
|
|
|
|
String packageName) throws RemoteException {
|
|
|
|
callGetService(serviceId, callback, gmsVersion, packageName, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void callGetService(int serviceId, IGmsCallbacks callback, int gmsVersion,
|
|
|
|
String packageName, Bundle extras) throws RemoteException {
|
|
|
|
callGetService(serviceId, callback, gmsVersion, packageName, extras, null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void callGetService(int serviceId, IGmsCallbacks callback, int gmsVersion, String packageName, Bundle extras, String accountName, String[] scopes) throws RemoteException {
|
|
|
|
GetServiceRequest request = new GetServiceRequest(serviceId);
|
|
|
|
request.gmsVersion = gmsVersion;
|
|
|
|
request.packageName = packageName;
|
|
|
|
request.extras = extras;
|
|
|
|
request.account = accountName == null ? null : new Account(accountName, "com.google");
|
|
|
|
request.scopes = scopes == null ? null : scopesFromStringArray(scopes);
|
|
|
|
getService(callback, request);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Scope[] scopesFromStringArray(String[] arr) {
|
|
|
|
Scope[] scopes = new Scope[arr.length];
|
|
|
|
for (int i = 0; i < arr.length; i++) {
|
|
|
|
scopes[i] = new Scope(arr[i]);
|
|
|
|
}
|
|
|
|
return scopes;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void getService(IGmsCallbacks callback, GetServiceRequest request) throws RemoteException {
|
2015-06-22 21:26:35 +00:00
|
|
|
if (supportedServiceIds.contains(request.serviceId) || supportedServiceIds.contains(ID_ACCEPT_ALL)) {
|
2015-04-09 21:12:08 +00:00
|
|
|
handleServiceRequest(callback, request);
|
|
|
|
} else {
|
|
|
|
Log.d(TAG, "Service not supported: " + request);
|
|
|
|
throw new IllegalArgumentException("Service not supported: " + request.serviceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract void handleServiceRequest(IGmsCallbacks callback, GetServiceRequest request) throws RemoteException;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void validateAccount(IGmsCallbacks callback, ValidateAccountRequest request) throws RemoteException {
|
|
|
|
throw new IllegalArgumentException("ValidateAccountRequest not supported");
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|
2015-03-11 21:47:41 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
|
|
|
|
if (super.onTransact(code, data, reply, flags)) return true;
|
|
|
|
Log.d(TAG, "onTransact [unknown]: " + code + ", " + data + ", " + flags);
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-11 23:08:51 +00:00
|
|
|
}
|