Skip to content

Commit b7d91f0

Browse files
committed
Auto-consent before phone verification
1 parent 395864f commit b7d91f0

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
}
@@ -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-
269271
private 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+
335361
private fun PhoneNumberVerification.toLegacyPhoneNumberInfoOrNull(): PhoneNumberInfo? {
336362
if (
337363
verificationStatus != Verification.Status.STATUS_VERIFIED.toClientStatus() ||

0 commit comments

Comments
 (0)