diff --git a/play-services-constellation/core/src/main/kotlin/org/microg/gms/constellation/core/VerifyPhoneNumber.kt b/play-services-constellation/core/src/main/kotlin/org/microg/gms/constellation/core/VerifyPhoneNumber.kt index 9154d33134..4a20eff097 100644 --- a/play-services-constellation/core/src/main/kotlin/org/microg/gms/constellation/core/VerifyPhoneNumber.kt +++ b/play-services-constellation/core/src/main/kotlin/org/microg/gms/constellation/core/VerifyPhoneNumber.kt @@ -30,6 +30,7 @@ import org.microg.gms.constellation.core.proto.GetConsentResponse import org.microg.gms.constellation.core.proto.Param import org.microg.gms.constellation.core.proto.RcsConsent import org.microg.gms.constellation.core.proto.RequestHeader +import org.microg.gms.constellation.core.proto.RequestTrigger import org.microg.gms.constellation.core.proto.SetConsentRequest import org.microg.gms.constellation.core.proto.SyncRequest import org.microg.gms.constellation.core.proto.Verification @@ -50,6 +51,20 @@ private enum class ReadCallbackMode { TYPED } +internal data class RcsAutoConsentRequestSemantics( + val rcsConsentVersion: ConsentVersion, + val requestConsentVersion: ConsentVersion, + val triggerType: RequestTrigger.Type +) + +internal fun resolveRcsAutoConsentRequestSemantics( + consentType: ConsentVersion +): RcsAutoConsentRequestSemantics = RcsAutoConsentRequestSemantics( + rcsConsentVersion = ConsentVersion.RCS_CONSENT, + requestConsentVersion = consentType, + triggerType = RequestTrigger.Type.CONSENT_API_TRIGGER +) + @Suppress("DEPRECATION") suspend fun handleVerifyPhoneNumberV1( context: Context, @@ -301,14 +316,21 @@ private suspend fun runVerificationFlow( if (!consented) { Log.e(TAG, "Consent has not been set. Auto-setting consent.") val consentType = parseConsentVersion(request.extras) + val semantics = resolveRcsAutoConsentRequestSemantics(consentType) val setRequest = SetConsentRequest( - header_ = RequestHeader(context, sessionId, buildContext, "setConsent"), + header_ = RequestHeader( + context, + sessionId, + buildContext, + "setConsent", + semantics.triggerType + ), asterism_client = asterismClient, rcs_consent = RcsConsent( consent = Consent.CONSENTED, - consent_version = consentType + consent_version = semantics.rcsConsentVersion ), - consent_version = consentType, + consent_version = semantics.requestConsentVersion, api_params = Param.getList(request.extras) ) try { diff --git a/play-services-constellation/core/src/test/kotlin/org/microg/gms/constellation/core/RcsAutoConsentRequestSemanticsTest.kt b/play-services-constellation/core/src/test/kotlin/org/microg/gms/constellation/core/RcsAutoConsentRequestSemanticsTest.kt new file mode 100644 index 0000000000..cf25864acc --- /dev/null +++ b/play-services-constellation/core/src/test/kotlin/org/microg/gms/constellation/core/RcsAutoConsentRequestSemanticsTest.kt @@ -0,0 +1,33 @@ +package org.microg.gms.constellation.core + +import org.junit.Assert.assertEquals +import org.junit.Test +import org.microg.gms.constellation.core.proto.ConsentVersion +import org.microg.gms.constellation.core.proto.RequestTrigger + +class RcsAutoConsentRequestSemanticsTest { + @Test + fun preservesRequestedConsentVersionButUsesRcsConsentRecordVersion() { + val semantics = resolveRcsAutoConsentRequestSemantics( + ConsentVersion.RCS_DEFAULT_ON_LEGAL_FYI + ) + + assertEquals(ConsentVersion.RCS_CONSENT, semantics.rcsConsentVersion) + assertEquals( + ConsentVersion.RCS_DEFAULT_ON_LEGAL_FYI, + semantics.requestConsentVersion + ) + } + + @Test + fun usesConsentApiTrigger() { + val semantics = resolveRcsAutoConsentRequestSemantics( + ConsentVersion.RCS_DEFAULT_ON_OUT_OF_BOX + ) + + assertEquals( + RequestTrigger.Type.CONSENT_API_TRIGGER, + semantics.triggerType + ) + } +}