From 5227caab6c7b571884c2ea9f52ad44e871446aa3 Mon Sep 17 00:00:00 2001 From: mar-v-in Date: Fri, 6 Mar 2015 20:08:47 +0100 Subject: [PATCH] Various update --- AndroidManifest.xml | 8 ++ GmsApi | 2 +- SafeParcel | 2 +- UnifiedNlpLib | 2 +- .../common/ui/SignInButtonCreatorImpl.java | 15 +++- .../gms/auth/AskPermissionActivity.java | 6 +- src/org/microg/gms/auth/AuthManager.java | 4 +- .../gms/auth/AuthManagerServiceImpl.java | 10 +-- .../auth/loginservice/GoogleLoginService.java | 6 +- src/org/microg/gms/common/PackageUtils.java | 89 +++++++++++++++++++ src/org/microg/gms/common/Utils.java | 57 +----------- src/org/microg/gms/gcm/GcmManager.java | 25 ++++-- .../microg/gms/gcm/PushRegisterService.java | 7 +- .../microg/gms/gservices/DatabaseHelper.java | 3 +- src/org/microg/gms/people/DatabaseHelper.java | 72 +++++++++++++++ .../microg/gms/people/PeopleServiceImpl.java | 10 ++- 16 files changed, 234 insertions(+), 84 deletions(-) create mode 100644 src/org/microg/gms/common/PackageUtils.java create mode 100644 src/org/microg/gms/people/DatabaseHelper.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 12de1a5b..69754a92 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -24,6 +24,11 @@ android:minSdkVersion="16" android:targetSdkVersion="21" /> + + + + + + 0) { + for (Signature sig : info.signatures) { + String digest = sha1sum(sig.toByteArray()); + if (digest != null) { + return digest; + } + } + } + return null; + } + + public static String sha1sum(byte[] bytes) { + MessageDigest md; + try { + md = MessageDigest.getInstance("SHA1"); + } catch (final NoSuchAlgorithmException e) { + return null; + } + if (md != null) { + bytes = md.digest(bytes); + if (bytes != null) { + StringBuilder sb = new StringBuilder(2 * bytes.length); + for (byte b : bytes) { + sb.append(String.format("%02x", b)); + } + return sb.toString(); + } + } + return null; + } + + public static int versionCode(Context context, String packageName) { + try { + return context.getPackageManager().getPackageInfo(packageName, 0).versionCode; + } catch (PackageManager.NameNotFoundException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/org/microg/gms/common/Utils.java b/src/org/microg/gms/common/Utils.java index 2ab7ad85..b6641923 100644 --- a/src/org/microg/gms/common/Utils.java +++ b/src/org/microg/gms/common/Utils.java @@ -21,6 +21,8 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.Signature; +import org.microg.gms.checkin.LastCheckinInfo; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -31,7 +33,7 @@ import java.util.Locale; public class Utils { public static String getAndroidIdHex(Context context) { - return null; + return Long.toHexString(LastCheckinInfo.read(context).androidId); } public static Locale getLocale(Context context) { @@ -42,59 +44,6 @@ public class Utils { return new Build(); } - public static void checkPackage(Context context, String packageName, int callingUid) { - String[] packagesForUid = context.getPackageManager().getPackagesForUid(callingUid); - if (packagesForUid != null && !Arrays.asList(packagesForUid).contains(packageName)) { - throw new SecurityException("callingUid [" + callingUid + "] is not related to packageName [" + packageName + "]"); - } - } - - public static void checkPackage(Context context, String packageName, int callerUid, int callingUid) { - if (callerUid != 0 && callerUid != callingUid) { - throw new SecurityException("callerUid [" + callerUid + "] and real calling uid [" + callingUid + "] mismatch!"); - } - checkPackage(context, packageName, callingUid); - } - - public static String getFirstPackageSignatureDigest(Context context, String packageName) { - PackageManager packageManager = context.getPackageManager(); - final PackageInfo info; - try { - info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); - } catch (PackageManager.NameNotFoundException e) { - throw new RuntimeException(e); - } - if (info != null && info.signatures != null && info.signatures.length > 0) { - for (Signature sig : info.signatures) { - String digest = sha1sum(sig.toByteArray()); - if (digest != null) { - return digest; - } - } - } - return null; - } - - public static String sha1sum(byte[] bytes) { - MessageDigest md; - try { - md = MessageDigest.getInstance("SHA1"); - } catch (final NoSuchAlgorithmException e) { - return null; - } - if (md != null) { - bytes = md.digest(bytes); - if (bytes != null) { - StringBuilder sb = new StringBuilder(2 * bytes.length); - for (byte b : bytes) { - sb.append(String.format("%02x", b)); - } - return sb.toString(); - } - } - return null; - } - public static byte[] readStreamToEnd(final InputStream is) throws IOException { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); if (is != null) { diff --git a/src/org/microg/gms/gcm/GcmManager.java b/src/org/microg/gms/gcm/GcmManager.java index ca47370c..07e74c76 100644 --- a/src/org/microg/gms/gcm/GcmManager.java +++ b/src/org/microg/gms/gcm/GcmManager.java @@ -17,16 +17,31 @@ package org.microg.gms.gcm; import android.content.Context; +import android.util.Log; +import org.microg.gms.checkin.LastCheckinInfo; +import org.microg.gms.common.PackageUtils; import org.microg.gms.common.Utils; +import java.io.IOException; + public class GcmManager { + private static final String TAG = "GmsGcmManager"; + public static String register(Context context, String app, String sender, String info) { - new RegisterRequest() - .build(Utils.getBuild(context)) - .sender(sender) - .info(info) - .app(app, Utils.getFirstPackageSignatureDigest(context, app), 0); // TODO + try { + return new RegisterRequest() + .build(Utils.getBuild(context)) + .sender(sender) + .info(info) + .checkin(LastCheckinInfo.read(context)) + .app(app, PackageUtils.firstSignatureDigest(context, app), PackageUtils.versionCode(context, app)) + .getResponse() + .token; + } catch (IOException e) { + Log.w(TAG, e); + } + return null; } } diff --git a/src/org/microg/gms/gcm/PushRegisterService.java b/src/org/microg/gms/gcm/PushRegisterService.java index 3970cc4f..bad9817c 100644 --- a/src/org/microg/gms/gcm/PushRegisterService.java +++ b/src/org/microg/gms/gcm/PushRegisterService.java @@ -20,6 +20,7 @@ import android.app.IntentService; import android.app.PendingIntent; import android.content.Intent; import android.os.Build; +import android.os.Bundle; import android.util.Log; public class PushRegisterService extends IntentService { @@ -58,14 +59,18 @@ public class PushRegisterService extends IntentService { PendingIntent pendingIntent = intent.getParcelableExtra("app"); String sender = intent.getStringExtra("sender"); String app = packageFromPendingIntent(pendingIntent); + Bundle extras = intent.getExtras(); + extras.keySet(); + Log.d(TAG, "register[req]: " + extras); Intent outIntent = new Intent("com.google.android.c2dm.intent.REGISTRATION"); outIntent.setPackage(app); - String regId = GcmManager.register(this, app, sender, null); // TODO + String regId = GcmManager.register(this, app, sender, null); if (regId != null) { outIntent.putExtra("registration_id", regId); } else { outIntent.putExtra("error", "SERVICE_NOT_AVAILABLE"); } + Log.d(TAG, "register[res]: " + outIntent); sendOrderedBroadcast(outIntent, null); } diff --git a/src/org/microg/gms/gservices/DatabaseHelper.java b/src/org/microg/gms/gservices/DatabaseHelper.java index a3857484..be3659bb 100644 --- a/src/org/microg/gms/gservices/DatabaseHelper.java +++ b/src/org/microg/gms/gservices/DatabaseHelper.java @@ -28,9 +28,10 @@ import java.util.Map; public class DatabaseHelper extends SQLiteOpenHelper { private static final int DB_VERSION = 3; private static final int DB_VERSION_OLD = 1; + public static final String DB_NAME = "gservices.db"; public DatabaseHelper(Context context) { - super(context, "gservices.db", null, DB_VERSION); + super(context, DB_NAME, null, DB_VERSION); } @Override diff --git a/src/org/microg/gms/people/DatabaseHelper.java b/src/org/microg/gms/people/DatabaseHelper.java new file mode 100644 index 00000000..fc4c3522 --- /dev/null +++ b/src/org/microg/gms/people/DatabaseHelper.java @@ -0,0 +1,72 @@ +/* + * 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.people; + +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +public class DatabaseHelper extends SQLiteOpenHelper { + private static final int DB_VERSION = 1; + private static final String DB_NAME = "pluscontacts.db"; + private static final String CREATE_OWNERS = "CREATE TABLE owners (" + + "_id INTEGER PRIMARY KEY AUTOINCREMENT," + + "account_name TEXT NOT NULL UNIQUE," + + "gaia_id TEXT," + + "page_gaia_id TEXT," + + "display_name TEXT," + + "avatar TEXT," + + "cover_photo_url TEXT," + + "cover_photo_height INTEGER NOT NULL DEFAULT 0," + + "cover_photo_width INTEGER NOT NULL DEFAULT 0," + + "cover_photo_id TEXT," + + "last_sync_start_time INTEGER NOT NULL DEFAULT 0," + + "last_sync_finish_time INTEGER NOT NULL DEFAULT 0," + + "last_sync_status INTEGER NOT NULL DEFAULT 0," + + "last_successful_sync_time INTEGER NOT NULL DEFAULT 0," + + "sync_to_contacts INTEGER NOT NULL DEFAULT 0," + + "is_dasher INTEGER NOT NULL DEFAULT 0," + + "dasher_domain TEXT," + + "etag TEXT," + + "sync_circles_to_contacts INTEGER NOT NULL DEFAULT 0," + + "sync_evergreen_to_contacts INTEGER NOT NULL DEFAULT 0," + + "last_full_people_sync_time INTEGER NOT NULL DEFAULT 0);"; + + public DatabaseHelper(Context context) { + super(context, DB_NAME, null, DB_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + db.execSQL(CREATE_OWNERS); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + + } + + @Override + public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { + // silently accept + } + + public Cursor getOwners() { + return getReadableDatabase().query("owners", null, null, null, null, null, null); + } +} diff --git a/src/org/microg/gms/people/PeopleServiceImpl.java b/src/org/microg/gms/people/PeopleServiceImpl.java index 94a1bb65..7ff981c6 100644 --- a/src/org/microg/gms/people/PeopleServiceImpl.java +++ b/src/org/microg/gms/people/PeopleServiceImpl.java @@ -27,7 +27,6 @@ import android.util.Log; import com.google.android.gms.common.data.DataHolder; import com.google.android.gms.people.internal.IPeopleCallbacks; import com.google.android.gms.people.internal.IPeopleService; -import com.google.android.gms.people.model.AccountMetadata; public class PeopleServiceImpl extends IPeopleService.Stub { private static final String TAG = "GmsPeopleSvcImpl"; @@ -47,12 +46,15 @@ public class PeopleServiceImpl extends IPeopleService.Stub { Bundle result = new Bundle(); for (Account account : accountManager.getAccountsByType("com.google")) { if (accountName == null || account.name.equals(accountName)) { - result.putParcelable(account.name, new AccountMetadata()); + result.putParcelable(account.name, null); } } try { - callbacks.onDataHolders(0, result, new DataHolder[0]); - } catch (RemoteException e) { + DatabaseHelper databaseHelper = new DatabaseHelper(context); + DataHolder dataHolder = DataHolder.fromCursor(databaseHelper.getOwners(), 0, result); + Log.d(TAG, "loadOwners[result]: " + dataHolder); + callbacks.onDataHolder(0, result, dataHolder); + } catch (Exception e) { Log.w(TAG, e); } }