Skip to content

Commit

Permalink
Play Integrity: Handle null callbacks and default to androidId 1 (ins…
Browse files Browse the repository at this point in the history
…tead 0)
  • Loading branch information
mar-v-in committed Dec 20, 2024
1 parent 9af8fb6 commit d2fcb09
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ suspend fun getAuthToken(context: Context, authTokenType: String): String {
}

suspend fun requestIntegritySyncData(context: Context, authToken: String, request: IntegrityRequest): IntegrityResponse {
val androidId = GServices.getString(context.contentResolver, "android_id", "0")?.toLong() ?: 1
val androidId = GServices.getString(context.contentResolver, "android_id", "1")?.toLong() ?: 1
return HttpClient(context).post(
url = "https://play-fe.googleapis.com/fdfe/integrity",
headers = getRequestHeaders(authToken, androidId),
Expand All @@ -438,7 +438,7 @@ suspend fun requestIntegritySyncData(context: Context, authToken: String, reques
}

suspend fun requestExpressSyncData(context: Context, authToken: String, request: TokenRequestWrapper): TokenResponse {
val androidId = GServices.getString(context.contentResolver, "android_id", "0")?.toLong() ?: 1
val androidId = GServices.getString(context.contentResolver, "android_id", "1")?.toLong() ?: 1
return HttpClient(context).post(
url = "https://play-fe.googleapis.com/fdfe/sync?nocache_qos=lt",
headers = getRequestHeaders(authToken, androidId),
Expand All @@ -450,7 +450,7 @@ suspend fun requestExpressSyncData(context: Context, authToken: String, request:
suspend fun requestIntermediateIntegrity(
context: Context, authToken: String, request: IntermediateIntegrityRequest
): IntermediateIntegrityResponseWrapperExtend {
val androidId = GServices.getString(context.contentResolver, "android_id", "0")?.toLong() ?: 1
val androidId = GServices.getString(context.contentResolver, "android_id", "1")?.toLong() ?: 1
return HttpClient(context).post(
url = "https://play-fe.googleapis.com/fdfe/intermediateIntegrity",
headers = getRequestHeaders(authToken, androidId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ExpressIntegrityService : LifecycleService() {

private class ExpressIntegrityServiceImpl(private val context: Context, override val lifecycle: Lifecycle) : IExpressIntegrityService.Stub(), LifecycleOwner {

override fun warmUpIntegrityToken(bundle: Bundle, callback: IExpressIntegrityServiceCallback) {
override fun warmUpIntegrityToken(bundle: Bundle, callback: IExpressIntegrityServiceCallback?) {
lifecycleScope.launchWhenCreated {
runCatching {
val authToken = getAuthToken(context, AUTH_TOKEN_SCOPE)
Expand Down Expand Up @@ -219,14 +219,14 @@ private class ExpressIntegrityServiceImpl(private val context: Context, override

updateLocalExpressFilePB(context, intermediateIntegrityResponseData)

callback.onWarmResult(bundleOf(KEY_WARM_UP_SID to sessionId))
callback?.onWarmResult(bundleOf(KEY_WARM_UP_SID to sessionId))
}.onFailure {
callback.onWarmResult(bundleOf(KEY_ERROR to IntegrityErrorCode.INTEGRITY_TOKEN_PROVIDER_INVALID))
callback?.onWarmResult(bundleOf(KEY_ERROR to IntegrityErrorCode.INTEGRITY_TOKEN_PROVIDER_INVALID))
}
}
}

override fun requestExpressIntegrityToken(bundle: Bundle, callback: IExpressIntegrityServiceCallback) {
override fun requestExpressIntegrityToken(bundle: Bundle, callback: IExpressIntegrityServiceCallback?) {
Log.d(TAG, "requestExpressIntegrityToken bundle:$bundle")
lifecycleScope.launchWhenCreated {
val expressIntegritySession = ExpressIntegritySession(
Expand All @@ -241,19 +241,19 @@ private class ExpressIntegrityServiceImpl(private val context: Context, override

if (TextUtils.isEmpty(expressIntegritySession.packageName)) {
Log.w(TAG, "packageName is empty.")
callback.onRequestResult(bundleOf(KEY_ERROR to IntegrityErrorCode.INTERNAL_ERROR))
callback?.onRequestResult(bundleOf(KEY_ERROR to IntegrityErrorCode.INTERNAL_ERROR))
return@launchWhenCreated
}

if (expressIntegritySession.cloudProjectVersion <= 0L) {
Log.w(TAG, "cloudProjectVersion error")
callback.onRequestResult(bundleOf(KEY_ERROR to IntegrityErrorCode.CLOUD_PROJECT_NUMBER_IS_INVALID))
callback?.onRequestResult(bundleOf(KEY_ERROR to IntegrityErrorCode.CLOUD_PROJECT_NUMBER_IS_INVALID))
return@launchWhenCreated
}

if (expressIntegritySession.requestHash?.length!! > 500) {
Log.w(TAG, "requestHash error")
callback.onRequestResult(bundleOf(KEY_ERROR to IntegrityErrorCode.REQUEST_HASH_TOO_LONG))
callback?.onRequestResult(bundleOf(KEY_ERROR to IntegrityErrorCode.REQUEST_HASH_TOO_LONG))
return@launchWhenCreated
}

Expand All @@ -270,7 +270,7 @@ private class ExpressIntegrityServiceImpl(private val context: Context, override
val integrityRequestWrapper = getIntegrityRequestWrapper(context, expressIntegritySession, defaultAccountName)
if (integrityRequestWrapper == null) {
Log.w(TAG, "integrityRequestWrapper is null")
callback.onRequestResult(bundleOf(KEY_ERROR to IntegrityErrorCode.INTEGRITY_TOKEN_PROVIDER_INVALID))
callback?.onRequestResult(bundleOf(KEY_ERROR to IntegrityErrorCode.INTEGRITY_TOKEN_PROVIDER_INVALID))
return@launchWhenCreated
}

Expand All @@ -289,7 +289,7 @@ private class ExpressIntegrityServiceImpl(private val context: Context, override
expressIntegrityResponse.encode(), Base64.NO_PADDING or Base64.NO_WRAP or Base64.URL_SAFE
)

callback.onRequestResult(
callback?.onRequestResult(
bundleOf(
KEY_TOKEN to token,
KEY_REQUEST_TOKEN_SID to expressIntegritySession.sessionId,
Expand All @@ -299,7 +299,7 @@ private class ExpressIntegrityServiceImpl(private val context: Context, override
Log.d(TAG, "requestExpressIntegrityToken token: $token, sid: ${expressIntegritySession.sessionId}, mode: ${expressIntegritySession.webViewRequestMode}")
} catch (exception: RemoteException) {
Log.e(TAG, "requesting token has failed for ${expressIntegritySession.packageName}.")
callback.onRequestResult(bundleOf(KEY_ERROR to IntegrityErrorCode.INTEGRITY_TOKEN_PROVIDER_INVALID))
callback?.onRequestResult(bundleOf(KEY_ERROR to IntegrityErrorCode.INTEGRITY_TOKEN_PROVIDER_INVALID))
}
}
}
Expand Down

0 comments on commit d2fcb09

Please sign in to comment.