@@ -23,15 +23,20 @@ import kotlinx.coroutines.withContext
2323import org.microg.gms.common.Constants
2424import org.microg.gms.constellation.core.proto.AsterismClient
2525import org.microg.gms.constellation.core.proto.Consent
26+ import org.microg.gms.constellation.core.proto.ConsentVersion
2627import org.microg.gms.constellation.core.proto.DeviceID
2728import org.microg.gms.constellation.core.proto.GetConsentRequest
2829import 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
2932import org.microg.gms.constellation.core.proto.RequestHeader
33+ import org.microg.gms.constellation.core.proto.SetConsentRequest
3034import org.microg.gms.constellation.core.proto.SyncRequest
3135import org.microg.gms.constellation.core.proto.Verification
3236import org.microg.gms.constellation.core.proto.builder.RequestBuildContext
3337import org.microg.gms.constellation.core.proto.builder.buildImsiToSubscriptionInfoMap
3438import org.microg.gms.constellation.core.proto.builder.buildRequestContext
39+ import org.microg.gms.constellation.core.proto.builder.getList
3540import org.microg.gms.constellation.core.proto.builder.invoke
3641import org.microg.gms.constellation.core.verification.ChallengeProcessor
3742import 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-
259261private 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+
325351private fun PhoneNumberVerification.toLegacyPhoneNumberInfoOrNull (): PhoneNumberInfo ? {
326352 if (
327353 verificationStatus != Verification .Status .STATUS_VERIFIED .toClientStatus() ||
0 commit comments