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
@@ -1,4 +1,4 @@
/*
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -115,8 +115,13 @@ class GamesService : BaseService(TAG, GmsService.GAMES) {
return@launchWhenStarted sendSignInRequired(account)
}

if (!performGamesSignIn(this@GamesService, packageName, account, scopes = scopes)) {
Log.d(TAG, "performGamesSignIn fail, sign in required")
try {
if (!performGamesSignIn(this@GamesService, packageName, account, scopes = scopes)) {
Log.d(TAG, "performGamesSignIn fail, sign in required")
return@launchWhenStarted sendSignInRequired(account)
}
} catch (e: Exception) {
Log.w(TAG, "performGamesSignIn exception, sign in required", e)
return@launchWhenStarted sendSignInRequired(account)
}

Expand Down Expand Up @@ -793,4 +798,4 @@ class GamesServiceImpl(val context: Context, override val lifecycle: Lifecycle,

override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean =
warnOnTransactionIssues(code, reply, flags, TAG) { super.onTransact(code, data, reply, flags) }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -78,12 +78,17 @@ class GamesSignInActivity : AppCompatActivity() {
?.getParcelable<GoogleSignInAccount>("googleSignInAccount")?.account
if (account != null) {
lifecycleScope.launchWhenStarted {
signIn(account)
try {
signIn(account)
} catch (e: Exception) {
Log.w(TAG, "signIn failed", e)
finish()
}
}
return
}
}
finish()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -51,6 +51,7 @@ import org.microg.gms.utils.singleInstanceOf
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.suspendCancellableCoroutine

const val SERVICE_GAMES_LITE = "oauth2:https://www.googleapis.com/auth/games_lite"

Expand Down Expand Up @@ -308,13 +309,21 @@ suspend fun performGamesSignIn(
fetchSelfPlayer(context, authResponse.auth, queue)
} catch (e : Exception){
requestGameToken(context, account, scopes, authManager.isPermitted)?.let {
fetchSelfPlayer(context, it, queue)
try {
fetchSelfPlayer(context, it, queue)
} catch (e: Exception) {
return false
}
} ?: return false
}
}
403 -> {
requestGameToken(context, account, scopes, authManager.isPermitted)?.let {
fetchSelfPlayer(context, it, queue)
try {
fetchSelfPlayer(context, it, queue)
} catch (e: Exception) {
return false
}
} ?: return false
}
else -> throw e
Expand All @@ -336,19 +345,19 @@ suspend fun fetchSelfPlayer(
context: Context,
authToken: String,
queue: RequestQueue = singleInstanceOf { Volley.newRequestQueue(context.applicationContext) }
) = suspendCoroutine<JSONObject> { continuation ->
queue.add(
object : JsonObjectRequest(
"https://www.googleapis.com/games/v1/players/me",
{ continuation.resume(it) },
{ continuation.resumeWithException(it) }) {
override fun getHeaders(): MutableMap<String, String> {
return mutableMapOf(
"Authorization" to "OAuth $authToken"
)
}
) = suspendCancellableCoroutine<JSONObject> { continuation ->
val request = object : JsonObjectRequest(
"https://www.googleapis.com/games/v1/players/me",
{ if (continuation.isActive) continuation.resume(it) },
{ if (continuation.isActive) continuation.resumeWithException(it) }) {
override fun getHeaders(): MutableMap<String, String> {
return mutableMapOf(
"Authorization" to "OAuth $authToken"
)
}
)
}
continuation.invokeOnCancellation { request.cancel() }
queue.add(request)
}

suspend fun requestGameToken(
Expand Down