Repository: android/compose-samples
File: Jetsurvey/app/src/main/java/com/example/compose/jetsurvey/survey/SurveyQuestions.kt (Kotlin)

Code before:
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.compose.jetsurvey.R
import com.example.compose.jetsurvey.theme.JetsurveyTheme
import com.google.accompanist.coil.rememberCoilPainter
import com.google.accompanist.permissions.rememberMultiplePermissionsState
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

@Composable
fun Question(
    question: Question,
    answer: Answer<*>?,
    shouldAskPermissions: Boolean,
    onAnswer: (Answer<*>) -> Unit,
    onAction: (Int, SurveyActionType) -> Unit,
    onDoNotAskForPermissions: () -> Unit,
    openSettings: () -> Unit,
    modifier: Modifier = Modifier
) {
    if (question.permissionsRequired == null || question.permissionsRequired.isEmpty()) {
        QuestionContent(question, answer, onAnswer, onAction, modifier)
    } else {
        val permissionsContentModifier = modifier.padding(horizontal = 20.dp)

        // When true, the permissions request must be presented to the user.
        var launchPermissionsRequest by rememberSaveable { mutableStateOf(false) }

        val multiplePermissionsState =
            rememberMultiplePermissionsState(question.permissionsRequired)

        when {
            // If all permissions are granted, then show the question
            multiplePermissionsState.allPermissionsGranted -> {
                QuestionContent(question, answer, onAnswer, onAction, modifier)
            }
            // The user denied some permissions but a rationale should be shown
            multiplePermissionsState.shouldShowRationale -> {
                if (!shouldAskPermissions) {
                    PermissionsDenied(
                        question.questionText,
                        openSettings,
                        permissionsContentModifier
                    )
                } else {
                    Column(permissionsContentModifier) {

Review comment (security):
see comment above about making `permissionsRequired` nonnull

Code after:
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.compose.jetsurvey.R
import com.example.compose.jetsurvey.theme.JetsurveyTheme
import com.google.accompanist.coil.rememberCoilPainter
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.MultiplePermissionsState
import com.google.accompanist.permissions.rememberMultiplePermissionsState
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

@OptIn(ExperimentalPermissionsApi::class)
@Composable
fun Question(
    question: Question,
    answer: Answer<*>?,
    shouldAskPermissions: Boolean,
    onAnswer: (Answer<*>) -> Unit,
    onAction: (Int, SurveyActionType) -> Unit,
    onDoNotAskForPermissions: () -> Unit,
    openSettings: () -> Unit,
    modifier: Modifier = Modifier
) {
    if (question.permissionsRequired.isEmpty()) {
        QuestionContent(question, answer, onAnswer, onAction, modifier)
    } else {
        val permissionsContentModifier = modifier.padding(horizontal = 20.dp)

        // When true, the permissions request must be presented to the user.
        var launchPermissionsRequest by rememberSaveable { mutableStateOf(false) }

        val multiplePermissionsState =
            rememberMultiplePermissionsState(question.permissionsRequired)

        when {
            // If all permissions are granted, then show the question
            multiplePermissionsState.allPermissionsGranted -> {
                QuestionContent(question, answer, onAnswer, onAction, modifier)
            }
            // The user denied some permissions but a rationale should be shown
            multiplePermissionsState.shouldShowRationale -> {
                if (!shouldAskPermissions) {
                    PermissionsDenied(
                        question.questionText,
                        openSettings,
                        permissionsContentModifier