Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public Bundle getAuthToken(AccountAuthenticatorResponse response, Account accoun
}
} catch (Exception e) {
Log.w(TAG, e);
return null;
throw new NetworkErrorException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -68,7 +68,7 @@ private inline fun <reified S : Service> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GunsGmscoreApiServiceClient>(baseUrl = GMS_NOTS_BASE_URL, oauthToken = oauthToken)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -32,7 +32,7 @@ class AuthHeaderInterceptor(

inline fun <reified S : Service> createGrpcClient(
baseUrl: String,
oauthToken: String,
oauthToken: String?,
minMessageToCompress: Long = Long.MAX_VALUE
): S {
val client = OkHttpClient.Builder().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()}")
Expand Down