From 05621504014ab1ca5558f707a0a56414f3d56ac1 Mon Sep 17 00:00:00 2001 From: davinci9196 Date: Mon, 25 Dec 2023 11:24:01 +0800 Subject: [PATCH] take relevant advice, changed some one --- .../safeparcel/AbstractSafeParcelable.java | 10 ----- .../src/main/AndroidManifest.xml | 2 +- .../assistedsignin/AssistedSignInService.kt | 38 ------------------- .../IdentitySignInService.kt} | 28 ++++++++++++-- .../gms/auth/signin/AuthSignInActivity.kt | 16 ++++---- 5 files changed, 33 insertions(+), 61 deletions(-) delete mode 100644 play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/assistedsignin/AssistedSignInService.kt rename play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/{assistedsignin/AssistedSignInServiceImpl.kt => identity/IdentitySignInService.kt} (73%) diff --git a/play-services-basement/src/main/java/com/google/android/gms/common/internal/safeparcel/AbstractSafeParcelable.java b/play-services-basement/src/main/java/com/google/android/gms/common/internal/safeparcel/AbstractSafeParcelable.java index fbf4507c8b..1ccf5ba182 100644 --- a/play-services-basement/src/main/java/com/google/android/gms/common/internal/safeparcel/AbstractSafeParcelable.java +++ b/play-services-basement/src/main/java/com/google/android/gms/common/internal/safeparcel/AbstractSafeParcelable.java @@ -5,8 +5,6 @@ package com.google.android.gms.common.internal.safeparcel; -import android.os.Parcel; - public abstract class AbstractSafeParcelable implements SafeParcelable { @SuppressWarnings("unchecked") @@ -24,12 +22,4 @@ public int describeContents() { return 0; } - public byte[] toByteArray() { - Parcel parcel = Parcel.obtain(); - writeToParcel(parcel, 0); - byte[] arr_b = parcel.marshall(); - parcel.recycle(); - return arr_b; - } - } diff --git a/play-services-core/src/main/AndroidManifest.xml b/play-services-core/src/main/AndroidManifest.xml index ab6b235a5d..4f9fbcab37 100644 --- a/play-services-core/src/main/AndroidManifest.xml +++ b/play-services-core/src/main/AndroidManifest.xml @@ -473,7 +473,7 @@ android:name="org.microg.gms.auth.signin.SignInConfigurationService" android:exported="false" /> - + diff --git a/play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/assistedsignin/AssistedSignInService.kt b/play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/assistedsignin/AssistedSignInService.kt deleted file mode 100644 index 9b67412068..0000000000 --- a/play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/assistedsignin/AssistedSignInService.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 microG Project Team - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.microg.gms.auth.credentials.assistedsignin - -import com.google.android.gms.common.ConnectionResult -import com.google.android.gms.common.Feature -import com.google.android.gms.common.internal.ConnectionInfo -import com.google.android.gms.common.internal.GetServiceRequest -import com.google.android.gms.common.internal.IGmsCallbacks -import org.microg.gms.BaseService -import org.microg.gms.common.GmsService - -const val TAG = "AssistedSignInService" - -class AssistedSignInService : BaseService(TAG, GmsService.IDENTITY_SIGN_IN) { - - override fun handleServiceRequest(callback: IGmsCallbacks, request: GetServiceRequest, service: GmsService) { - val connectionInfo = ConnectionInfo() - connectionInfo.features = arrayOf( - Feature("auth_api_credentials_begin_sign_in", 8L), - Feature("auth_api_credentials_sign_out", 2L), - Feature("auth_api_credentials_authorize", 1L), - Feature("auth_api_credentials_revoke_access", 1L), - Feature("auth_api_credentials_save_password", 4L), - Feature("auth_api_credentials_get_sign_in_intent", 6L), - Feature("auth_api_credentials_save_account_linking_token", 3L), - Feature("auth_api_credentials_get_phone_number_hint_intent", 3L) - ) - callback.onPostInitCompleteWithConnectionInfo( - ConnectionResult.SUCCESS, - AssistedSignInServiceImpl(this, request.packageName).asBinder(), - connectionInfo - ) - } -} \ No newline at end of file diff --git a/play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/assistedsignin/AssistedSignInServiceImpl.kt b/play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/identity/IdentitySignInService.kt similarity index 73% rename from play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/assistedsignin/AssistedSignInServiceImpl.kt rename to play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/identity/IdentitySignInService.kt index f50dc7e9ac..bf09ec5853 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/assistedsignin/AssistedSignInServiceImpl.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/auth/credentials/identity/IdentitySignInService.kt @@ -3,12 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package org.microg.gms.auth.credentials.assistedsignin +package org.microg.gms.auth.credentials.identity import android.app.PendingIntent import android.content.Context import android.content.Intent -import android.os.RemoteException import android.util.Log import com.google.android.gms.auth.api.identity.BeginSignInRequest import com.google.android.gms.auth.api.identity.GetPhoneNumberHintIntentRequest @@ -19,12 +18,34 @@ import com.google.android.gms.auth.api.identity.internal.IGetSignInIntentCallbac import com.google.android.gms.auth.api.identity.internal.ISignInService import com.google.android.gms.auth.api.signin.GoogleSignInOptions import com.google.android.gms.auth.api.signin.internal.SignInConfiguration +import com.google.android.gms.common.ConnectionResult import com.google.android.gms.common.api.Status import com.google.android.gms.common.api.internal.IStatusCallback +import com.google.android.gms.common.internal.ConnectionInfo +import com.google.android.gms.common.internal.GetServiceRequest +import com.google.android.gms.common.internal.IGmsCallbacks +import org.microg.gms.BaseService +import org.microg.gms.auth.credentials.FEATURES import org.microg.gms.auth.signin.AuthSignInActivity import org.microg.gms.common.Constants +import org.microg.gms.common.GmsService -class AssistedSignInServiceImpl(private val mContext: Context, private val clientPackageName: String) : +const val TAG = "IdentitySignInService" + +class IdentitySignInService : BaseService(TAG, GmsService.IDENTITY_SIGN_IN) { + + override fun handleServiceRequest(callback: IGmsCallbacks, request: GetServiceRequest, service: GmsService) { + val connectionInfo = ConnectionInfo() + connectionInfo.features = FEATURES + callback.onPostInitCompleteWithConnectionInfo( + ConnectionResult.SUCCESS, + IdentitySignInServiceImpl(this, request.packageName).asBinder(), + connectionInfo + ) + } +} + +class IdentitySignInServiceImpl(private val mContext: Context, private val clientPackageName: String) : ISignInService.Stub() { override fun beginSignIn(callback: IBeginSignInCallback, request: BeginSignInRequest) { Log.d(TAG, "method 'beginSignIn' not fully implemented, return status is CANCELED") @@ -65,5 +86,4 @@ class AssistedSignInServiceImpl(private val mContext: Context, private val clien Log.w(TAG, "method 'getPhoneNumberHintIntent' not fully implemented, return status is CANCELED.") callback.onResult(Status.CANCELED, null) } - } \ No newline at end of file diff --git a/play-services-core/src/main/kotlin/org/microg/gms/auth/signin/AuthSignInActivity.kt b/play-services-core/src/main/kotlin/org/microg/gms/auth/signin/AuthSignInActivity.kt index de18cc4382..c01034dff6 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/auth/signin/AuthSignInActivity.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/auth/signin/AuthSignInActivity.kt @@ -27,6 +27,7 @@ import com.google.android.gms.auth.api.signin.internal.SignInConfiguration import com.google.android.gms.common.Scopes import com.google.android.gms.common.api.CommonStatusCodes import com.google.android.gms.common.api.Status +import com.google.android.gms.common.internal.safeparcel.SafeParcelableSerializer import com.google.android.gms.databinding.SigninConfirmBinding import com.google.android.gms.databinding.SigninPickerBinding import kotlinx.coroutines.Dispatchers @@ -205,28 +206,27 @@ class AuthSignInActivity : AppCompatActivity() { data.putExtra(AuthConstants.GOOGLE_SIGN_IN_ACCOUNT, googleSignInAccount) val bundle = Bundle() if (googleSignInAccount != null) { - SignInAccount().apply { + val signInAccount = SignInAccount().apply { email = googleSignInAccount.email ?: account?.name this.googleSignInAccount = googleSignInAccount userId = googleSignInAccount.id ?: getSystemService()?.getUserData( account, AuthConstants.GOOGLE_USER_ID ) - }.let { - data.putExtra(AuthConstants.SIGN_IN_ACCOUNT, it) } - SignInCredential().apply { + data.putExtra(AuthConstants.SIGN_IN_ACCOUNT, signInAccount) + val credential = SignInCredential().apply { email = googleSignInAccount.email displayName = googleSignInAccount.displayName familyName = googleSignInAccount.familyName givenName = googleSignInAccount.givenName idToken = googleSignInAccount.idToken - }.let { - bundle.putByteArray(AuthConstants.SIGN_IN_CREDENTIAL, it.toByteArray()) - bundle.putByteArray(AuthConstants.STATUS, Status.SUCCESS.toByteArray()) } + val credentialToBytes = SafeParcelableSerializer.serializeToBytes(credential) + bundle.putByteArray(AuthConstants.SIGN_IN_CREDENTIAL, credentialToBytes) + bundle.putByteArray(AuthConstants.STATUS, SafeParcelableSerializer.serializeToBytes(Status.SUCCESS)) } else { - bundle.putByteArray(AuthConstants.STATUS, Status.CANCELED.toByteArray()) + bundle.putByteArray(AuthConstants.STATUS, SafeParcelableSerializer.serializeToBytes(Status.CANCELED)) } data.putExtras(bundle) Log.d(TAG, "Result: ${data.extras?.also { it.keySet() }}")