diff --git a/play-services-core/src/main/java/org/microg/gms/auth/loginservice/AccountAuthenticator.java b/play-services-core/src/main/java/org/microg/gms/auth/loginservice/AccountAuthenticator.java index e6cce7b0b4..88ede1e6f1 100644 --- a/play-services-core/src/main/java/org/microg/gms/auth/loginservice/AccountAuthenticator.java +++ b/play-services-core/src/main/java/org/microg/gms/auth/loginservice/AccountAuthenticator.java @@ -157,7 +157,7 @@ public Bundle getAuthToken(AccountAuthenticatorResponse response, Account accoun } } catch (Exception e) { Log.w(TAG, e); - return null; + throw new NetworkErrorException(e); } } diff --git a/play-services-core/src/main/kotlin/com/google/android/gms/locationsharingreporter/service/LocationSharingReporterExtensions.kt b/play-services-core/src/main/kotlin/com/google/android/gms/locationsharingreporter/service/LocationSharingReporterExtensions.kt index 7da2e1e72e..bd7ac13b1e 100644 --- a/play-services-core/src/main/kotlin/com/google/android/gms/locationsharingreporter/service/LocationSharingReporterExtensions.kt +++ b/play-services-core/src/main/kotlin/com/google/android/gms/locationsharingreporter/service/LocationSharingReporterExtensions.kt @@ -56,7 +56,7 @@ private const val STATE_DISABLED = 2 private class HeaderInterceptor( - private val oauthToken: String, + private val oauthToken: String?, ) : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { val original = chain.request().newBuilder().header("authorization", "Bearer $oauthToken") @@ -68,7 +68,7 @@ private inline fun grpcClient( account: Account, accountManager: AccountManager ): S { - val token = accountManager.blockingGetAuthToken(account, AUTH_TOKEN_SCOPE, true) + val token = runCatching { accountManager.blockingGetAuthToken(account, AUTH_TOKEN_SCOPE, true) }.getOrNull() val client = OkHttpClient().newBuilder() .addInterceptor(HeaderInterceptor(token)) .build() diff --git a/play-services-core/src/main/kotlin/org/microg/gms/gcm/GcmInGmsService.kt b/play-services-core/src/main/kotlin/org/microg/gms/gcm/GcmInGmsService.kt index 8304c24463..1bd86d49fe 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/gcm/GcmInGmsService.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/gcm/GcmInGmsService.kt @@ -490,7 +490,7 @@ class GcmInGmsService : LifecycleService() { } private fun getGunsApiServiceClient(account: Account, accountManager: AccountManager): GunsGmscoreApiServiceClient { - val oauthToken = accountManager.blockingGetAuthToken(account, GMS_NOTS_OAUTH_SERVICE, true) + val oauthToken = runCatching { accountManager.blockingGetAuthToken(account, GMS_NOTS_OAUTH_SERVICE, true) }.getOrNull() return createGrpcClient(baseUrl = GMS_NOTS_BASE_URL, oauthToken = oauthToken) } } diff --git a/play-services-core/src/main/kotlin/org/microg/gms/gcm/extensions.kt b/play-services-core/src/main/kotlin/org/microg/gms/gcm/extensions.kt index 428a9bdd7a..741580050d 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/gcm/extensions.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/gcm/extensions.kt @@ -22,7 +22,7 @@ const val GMS_NOTS_OAUTH_SERVICE = "oauth2:https://www.googleapis.com/auth/notif const val GMS_NOTS_BASE_URL = "https://notifications-pa.googleapis.com" class AuthHeaderInterceptor( - private val oauthToken: String, + private val oauthToken: String?, ) : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { val original = chain.request().newBuilder().header("Authorization", "Bearer $oauthToken") @@ -32,7 +32,7 @@ class AuthHeaderInterceptor( inline fun createGrpcClient( baseUrl: String, - oauthToken: String, + oauthToken: String?, minMessageToCompress: Long = Long.MAX_VALUE ): S { val client = OkHttpClient.Builder().apply { diff --git a/play-services-core/src/main/kotlin/org/microg/gms/gcm/registeration/ChimeGmsRegistrationHelper.kt b/play-services-core/src/main/kotlin/org/microg/gms/gcm/registeration/ChimeGmsRegistrationHelper.kt index 6131b492d2..3a390a8da3 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/gcm/registeration/ChimeGmsRegistrationHelper.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/gcm/registeration/ChimeGmsRegistrationHelper.kt @@ -60,12 +60,13 @@ class ChimeGmsRegistrationHelper(val context: Context) { Log.d(TAG, "handleRegistration: needRegistration: ${accounts.joinToString("|") { it.name }}") if (accounts.isEmpty()) return emptyList() val authTokens = withContext(Dispatchers.IO) { - accounts.map { - val authToken = AccountManager.get(context).blockingGetAuthToken(it, GMS_NOTS_OAUTH_SERVICE, true) - Pair(it.name, authToken) + accounts.mapNotNull { + val authToken = runCatching { AccountManager.get(context).blockingGetAuthToken(it, GMS_NOTS_OAUTH_SERVICE, true) }.getOrNull() + if (authToken != null) Pair(it.name, authToken) else null } } Log.d(TAG, "authTokens: $authTokens") + if (authTokens.isEmpty()) return emptyList() val response = withContext(Dispatchers.IO) { val request = buildRegistrationRequest(authTokens, reason, regId) Log.d(TAG, "Registration request: ${request.encode().toBase64()}")