From 25f845a70ed69abccf870b8cc12178f68f53de79 Mon Sep 17 00:00:00 2001 From: mar-v-in Date: Wed, 11 Mar 2015 22:47:41 +0100 Subject: [PATCH] Start adding Icing Index Service and implementing serious Auth:hasFeatures --- AndroidManifest.xml | 8 +++ GmsApi | 2 +- .../microg/gms/AbstractGmsServiceBroker.java | 54 +++++++++++-------- .../auth/loginservice/GoogleLoginService.java | 22 ++++++-- .../microg/gms/icing/AppDataSearchImpl.java | 47 ++++++++++++++++ src/org/microg/gms/icing/IndexService.java | 45 ++++++++++++++++ 6 files changed, 152 insertions(+), 26 deletions(-) create mode 100644 src/org/microg/gms/icing/AppDataSearchImpl.java create mode 100644 src/org/microg/gms/icing/IndexService.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2a424d9d..56b63f51 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -238,5 +238,13 @@ + + + + + + diff --git a/GmsApi b/GmsApi index cee8188d..1510aa1b 160000 --- a/GmsApi +++ b/GmsApi @@ -1 +1 @@ -Subproject commit cee8188daef20716b4879be8f34c3ad730161e17 +Subproject commit 1510aa1b0adeeed9dbe591b25ad75b015f968d82 diff --git a/src/org/microg/gms/AbstractGmsServiceBroker.java b/src/org/microg/gms/AbstractGmsServiceBroker.java index 8dea77eb..546c324c 100644 --- a/src/org/microg/gms/AbstractGmsServiceBroker.java +++ b/src/org/microg/gms/AbstractGmsServiceBroker.java @@ -18,21 +18,26 @@ package org.microg.gms; import android.os.Bundle; import android.os.IBinder; +import android.os.Parcel; import android.os.RemoteException; +import android.util.Log; + import com.google.android.gms.common.internal.IGmsCallbacks; import com.google.android.gms.common.internal.IGmsServiceBroker; public abstract class AbstractGmsServiceBroker extends IGmsServiceBroker.Stub { + private static final String TAG = "GmsServiceBroker"; + @Override public void getPlusService(IGmsCallbacks callback, int versionCode, String packageName, - String str2, String[] paramArrayOfString, String str3, Bundle params) + String str2, String[] paramArrayOfString, String str3, Bundle params) throws RemoteException { throw new IllegalArgumentException("Plus service not supported"); } @Override public void getPanoramaService(IGmsCallbacks callback, int versionCode, String packageName, - Bundle params) throws RemoteException { + Bundle params) throws RemoteException { throw new IllegalArgumentException("Panorama service not supported"); } @@ -49,116 +54,116 @@ public abstract class AbstractGmsServiceBroker extends IGmsServiceBroker.Stub { @Override public void getPeopleService(IGmsCallbacks callback, int versionCode, String packageName, - Bundle params) throws RemoteException { + Bundle params) throws RemoteException { throw new IllegalArgumentException("People service not supported"); } @Override public void getReportingService(IGmsCallbacks callback, int versionCode, String packageName, - Bundle params) throws RemoteException { + Bundle params) throws RemoteException { throw new IllegalArgumentException("Reporting service not supported"); } @Override public void getLocationService(IGmsCallbacks callback, int versionCode, String packageName, - Bundle params) throws RemoteException { + Bundle params) throws RemoteException { throw new IllegalArgumentException("Location service not supported"); } @Override public void getGoogleLocationManagerService(IGmsCallbacks callback, int versionCode, - String packageName, Bundle params) throws RemoteException { + String packageName, Bundle params) throws RemoteException { throw new IllegalArgumentException("Google Location Manager service not supported"); } @Override public void getGamesService(IGmsCallbacks callback, int versionCode, String packageName, - String str2, String[] args, String str3, IBinder binder, String str4, Bundle params) + String str2, String[] args, String str3, IBinder binder, String str4, Bundle params) throws RemoteException { throw new IllegalArgumentException("Games service not supported"); } @Override public void getAppStateService(IGmsCallbacks callback, int versionCode, String packageName, - String str2, String[] args) throws RemoteException { + String str2, String[] args) throws RemoteException { throw new IllegalArgumentException("App State service not supported"); } @Override public void getPlayLogService(IGmsCallbacks callback, int versionCode, String packageName, - Bundle params) throws RemoteException { + Bundle params) throws RemoteException { throw new IllegalArgumentException("Play Log service not supported"); } @Override public void getAdMobService(IGmsCallbacks callback, int versionCode, String packageName, - Bundle params) throws RemoteException { + Bundle params) throws RemoteException { throw new IllegalArgumentException("AdMob service not supported"); } @Override public void getDroidGuardService(IGmsCallbacks callback, int versionCode, String packageName, - Bundle params) throws RemoteException { + Bundle params) throws RemoteException { throw new IllegalArgumentException("DroidGuard service not supported"); } @Override public void getLockboxService(IGmsCallbacks callback, int versionCode, String packageName, - Bundle params) throws RemoteException { + Bundle params) throws RemoteException { throw new IllegalArgumentException("Lockbox service not supported"); } @Override public void getCastMirroringService(IGmsCallbacks callback, int versionCode, String packageName, - Bundle params) throws RemoteException { + Bundle params) throws RemoteException { throw new IllegalArgumentException("Cast Mirroring service not supported"); } @Override public void getNetworkQualityService(IGmsCallbacks callback, int versionCode, - String packageName, Bundle params) throws RemoteException { + String packageName, Bundle params) throws RemoteException { throw new IllegalArgumentException("Network Quality service not supported"); } @Override public void getGoogleIdentityService(IGmsCallbacks callback, int versionCode, - String packageName, Bundle params) throws RemoteException { + String packageName, Bundle params) throws RemoteException { throw new IllegalArgumentException("Google Identity service not supported"); } @Override public void getGoogleFeedbackService(IGmsCallbacks callback, int versionCode, - String packageName, Bundle params) throws RemoteException { + String packageName, Bundle params) throws RemoteException { throw new IllegalArgumentException("Google Feedback service not supported"); } @Override public void getCastService(IGmsCallbacks callback, int versionCode, String packageName, - IBinder binder, Bundle params) throws RemoteException { + IBinder binder, Bundle params) throws RemoteException { throw new IllegalArgumentException("Cast service not supported"); } @Override public void getDriveService(IGmsCallbacks callback, int versionCode, String packageName, - String[] args, String str2, Bundle params) throws RemoteException { + String[] args, String str2, Bundle params) throws RemoteException { throw new IllegalArgumentException("Drive service not supported"); } @Override public void getLightweightAppDataSearchService(IGmsCallbacks callback, int versionCode, - String packageName) throws RemoteException { + String packageName) throws RemoteException { throw new IllegalArgumentException("Lightweight App Data Search service not supported"); } @Override public void getSearchAdministrationService(IGmsCallbacks callback, int versionCode, - String packageName) throws RemoteException { + String packageName) throws RemoteException { throw new IllegalArgumentException("Search Administration service not supported"); } @Override public void getAutoBackupService(IGmsCallbacks callback, int versionCode, String packageName, - Bundle params) throws RemoteException { + Bundle params) throws RemoteException { throw new IllegalArgumentException("Auto Backup service not supported"); } @@ -167,4 +172,11 @@ public abstract class AbstractGmsServiceBroker extends IGmsServiceBroker.Stub { throws RemoteException { throw new IllegalArgumentException("Address service not supported"); } + + @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; + } } diff --git a/src/org/microg/gms/auth/loginservice/GoogleLoginService.java b/src/org/microg/gms/auth/loginservice/GoogleLoginService.java index 12ba16e1..60e1b9d3 100644 --- a/src/org/microg/gms/auth/loginservice/GoogleLoginService.java +++ b/src/org/microg/gms/auth/loginservice/GoogleLoginService.java @@ -19,6 +19,7 @@ package org.microg.gms.auth.loginservice; import android.accounts.AbstractAccountAuthenticator; import android.accounts.Account; import android.accounts.AccountAuthenticatorResponse; +import android.accounts.AccountManager; import android.accounts.NetworkErrorException; import android.app.Service; import android.content.Intent; @@ -36,6 +37,7 @@ import org.microg.gms.auth.login.LoginActivity; import org.microg.gms.common.PackageUtils; import java.util.Arrays; +import java.util.List; import static android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT; import static android.accounts.AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE; @@ -95,21 +97,33 @@ public class GoogleLoginService extends Service { @Override public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { + Log.d(TAG, "updateCredentials: " + account + ", " + authTokenType + ", " + options); return null; } @Override public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException { - Log.d(TAG, "hasFeatures: " + account + ", " + Arrays.toString(features)); - Bundle result = new Bundle(); - result.putBoolean(KEY_BOOLEAN_RESULT, true); - return result; + return GoogleLoginService.this.hasFeatures(account, features); } }.getIBinder(); } return null; } + private Bundle hasFeatures(Account account, String[] features) { + Log.d(TAG, "hasFeatures: " + account + ", " + Arrays.toString(features)); + AccountManager accountManager = AccountManager.get(this); + List services = Arrays.asList(accountManager.getUserData(account, "services").split(",")); + boolean res = true; + for (String feature : features) { + if (feature.startsWith("service_") && !services.contains(feature.substring(8))) + res = false; + } + Bundle result = new Bundle(); + result.putBoolean(KEY_BOOLEAN_RESULT, res); + return result; + } + private Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) { options.keySet(); Log.d(TAG, "getAuthToken: " + account + ", " + authTokenType + ", " + options); diff --git a/src/org/microg/gms/icing/AppDataSearchImpl.java b/src/org/microg/gms/icing/AppDataSearchImpl.java new file mode 100644 index 00000000..6477ec57 --- /dev/null +++ b/src/org/microg/gms/icing/AppDataSearchImpl.java @@ -0,0 +1,47 @@ +/* + * Copyright 2013-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.icing; + +import android.os.Parcel; +import android.os.RemoteException; +import android.util.Log; + +import com.google.android.gms.appdatasearch.CorpusStatus; +import com.google.android.gms.appdatasearch.SuggestSpecification; +import com.google.android.gms.appdatasearch.SuggestionResults; +import com.google.android.gms.appdatasearch.internal.IAppDataSearch; + +public class AppDataSearchImpl extends IAppDataSearch.Stub { + private static final String TAG = "GmsIcingSearchImpl"; + + @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; + } + + @Override + public SuggestionResults getSuggestions(String var1, String packageName, String[] accounts, int maxNum, SuggestSpecification specs) throws RemoteException { + return new SuggestionResults("Unknown error"); + } + + @Override + public CorpusStatus getStatus(String packageName, String accountName) throws RemoteException { + return new CorpusStatus(); + } +} diff --git a/src/org/microg/gms/icing/IndexService.java b/src/org/microg/gms/icing/IndexService.java new file mode 100644 index 00000000..5d45d34e --- /dev/null +++ b/src/org/microg/gms/icing/IndexService.java @@ -0,0 +1,45 @@ +/* + * Copyright 2013-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.icing; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.os.RemoteException; +import android.util.Log; + +import com.google.android.gms.common.internal.IGmsCallbacks; + +import org.microg.gms.AbstractGmsServiceBroker; + +public class IndexService extends Service { + private static final String TAG = "GmsIcingIndexSvc"; + + private AppDataSearchImpl appDataSearch = new AppDataSearchImpl(); + private AbstractGmsServiceBroker broker = new AbstractGmsServiceBroker() { + @Override + public void getAppDataSearchService(IGmsCallbacks callback, int versionCode, String packageName) throws RemoteException { + Log.d(TAG, "bound by: " + packageName); + callback.onPostInitComplete(0, appDataSearch.asBinder(), null); + } + }; + + @Override + public IBinder onBind(Intent intent) { + return broker.asBinder(); + } +}