@@ -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 }
@@ -264,8 +268,6 @@ private fun handleRpcError(error: GrpcException): Status {
264268 return Status (statusCode, error.message)
265269}
266270
267- private class NoConsentException : Exception (" No consent" )
268-
269271private suspend fun runVerificationFlow (
270272 context : Context ,
271273 request : VerifyPhoneNumberRequest ,
@@ -297,8 +299,24 @@ private suspend fun runVerificationFlow(
297299 }
298300
299301 if (! consented) {
300- Log .e(TAG , " Consent has not been set. Not running verification." )
301- throw NoConsentException ()
302+ Log .e(TAG , " Consent has not been set. Auto-setting consent." )
303+ val consentType = parseConsentVersion(request.extras)
304+ val setRequest = SetConsentRequest (
305+ header_ = RequestHeader (context, sessionId, buildContext, " setConsent" ),
306+ asterism_client = asterismClient,
307+ rcs_consent = RcsConsent (
308+ consent = Consent .CONSENTED ,
309+ consent_version = consentType
310+ ),
311+ consent_version = consentType,
312+ api_params = Param .getList(request.extras)
313+ )
314+ try {
315+ RpcClient .phoneDeviceVerificationClient.SetConsent ().execute(setRequest)
316+ Log .i(TAG , " Auto-consented for $asterismClient " )
317+ } catch (e: Exception ) {
318+ Log .w(TAG , " Auto-consent failed" , e)
319+ }
302320 }
303321 }
304322
@@ -332,6 +350,14 @@ private suspend fun runVerificationFlow(
332350 return verifications
333351}
334352
353+ private fun parseConsentVersion (extras : Bundle ): ConsentVersion {
354+ val value = extras.getString(" consent_type" )
355+ val parsed = value?.toIntOrNull()?.let (ConsentVersion ::fromValue)
356+ ? : value?.let { runCatching { ConsentVersion .valueOf(it) }.getOrNull() }
357+ return parsed?.takeUnless { it == ConsentVersion .CONSENT_VERSION_UNSPECIFIED }
358+ ? : ConsentVersion .RCS_DEFAULT_ON_LEGAL_FYI
359+ }
360+
335361private fun PhoneNumberVerification.toLegacyPhoneNumberInfoOrNull (): PhoneNumberInfo ? {
336362 if (
337363 verificationStatus != Verification .Status .STATUS_VERIFIED .toClientStatus() ||
0 commit comments