Skip to content

Commit f7ae9f8

Browse files
committed
Auto-consent before phone verification
1 parent 0a22ba0 commit f7ae9f8

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

  • play-services-constellation/core/src/main/kotlin/org/microg/gms/constellation/core

play-services-constellation/core/src/main/kotlin/org/microg/gms/constellation/core/VerifyPhoneNumber.kt

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@ import kotlinx.coroutines.withContext
2323
import org.microg.gms.common.Constants
2424
import org.microg.gms.constellation.core.proto.AsterismClient
2525
import org.microg.gms.constellation.core.proto.Consent
26+
import org.microg.gms.constellation.core.proto.ConsentVersion
2627
import org.microg.gms.constellation.core.proto.DeviceID
2728
import org.microg.gms.constellation.core.proto.GetConsentRequest
2829
import org.microg.gms.constellation.core.proto.GetConsentResponse
30+
import org.microg.gms.constellation.core.proto.Param
31+
import org.microg.gms.constellation.core.proto.RcsConsent
2932
import org.microg.gms.constellation.core.proto.RequestHeader
33+
import org.microg.gms.constellation.core.proto.SetConsentRequest
3034
import org.microg.gms.constellation.core.proto.SyncRequest
3135
import org.microg.gms.constellation.core.proto.Verification
3236
import org.microg.gms.constellation.core.proto.builder.RequestBuildContext
3337
import org.microg.gms.constellation.core.proto.builder.buildImsiToSubscriptionInfoMap
3438
import org.microg.gms.constellation.core.proto.builder.buildRequestContext
39+
import org.microg.gms.constellation.core.proto.builder.getList
3540
import org.microg.gms.constellation.core.proto.builder.invoke
3641
import org.microg.gms.constellation.core.verification.ChallengeProcessor
3742
import org.microg.gms.constellation.core.verification.MtSmsInboxRegistry
@@ -212,7 +217,6 @@ private suspend fun handleVerifyPhoneNumberRequest(
212217
e is PhoneNumberVerificationDisabledException -> Status(5000)
213218
readCallbackMode != ReadCallbackMode.NONE -> Status.INTERNAL_ERROR
214219
e is GrpcException -> handleRpcError(e)
215-
e is NoConsentException -> Status(5001)
216220
else -> Status.INTERNAL_ERROR
217221
}
218222
}
@@ -254,8 +258,6 @@ private fun handleRpcError(error: GrpcException): Status {
254258
return Status(statusCode, error.message)
255259
}
256260

257-
private class NoConsentException : Exception("No consent")
258-
259261
private suspend fun runVerificationFlow(
260262
context: Context,
261263
request: VerifyPhoneNumberRequest,
@@ -287,8 +289,24 @@ private suspend fun runVerificationFlow(
287289
}
288290

289291
if (!consented) {
290-
Log.e(TAG, "Consent has not been set. Not running verification.")
291-
throw NoConsentException()
292+
Log.e(TAG, "Consent has not been set. Auto-setting consent.")
293+
val consentType = parseConsentVersion(request.extras)
294+
val setRequest = SetConsentRequest(
295+
header_ = RequestHeader(context, sessionId, buildContext, "setConsent"),
296+
asterism_client = asterismClient,
297+
rcs_consent = RcsConsent(
298+
consent = Consent.CONSENTED,
299+
consent_version = consentType
300+
),
301+
consent_version = consentType,
302+
api_params = Param.getList(request.extras)
303+
)
304+
try {
305+
RpcClient.phoneDeviceVerificationClient.SetConsent().execute(setRequest)
306+
Log.i(TAG, "Auto-consented for $asterismClient")
307+
} catch (e: Exception) {
308+
Log.w(TAG, "Auto-consent failed", e)
309+
}
292310
}
293311
}
294312

@@ -322,6 +340,14 @@ private suspend fun runVerificationFlow(
322340
return verifications
323341
}
324342

343+
private fun parseConsentVersion(extras: Bundle): ConsentVersion {
344+
val value = extras.getString("consent_type")
345+
val parsed = value?.toIntOrNull()?.let(ConsentVersion::fromValue)
346+
?: value?.let { runCatching { ConsentVersion.valueOf(it) }.getOrNull() }
347+
return parsed?.takeUnless { it == ConsentVersion.CONSENT_VERSION_UNSPECIFIED }
348+
?: ConsentVersion.RCS_DEFAULT_ON_LEGAL_FYI
349+
}
350+
325351
private fun PhoneNumberVerification.toLegacyPhoneNumberInfoOrNull(): PhoneNumberInfo? {
326352
if (
327353
verificationStatus != Verification.Status.STATUS_VERIFIED.toClientStatus() ||

0 commit comments

Comments
 (0)