Loading packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt +2 −2 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ import android.util.Log import androidx.activity.ComponentActivity import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.compose.setContent import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.runtime.Composable Loading @@ -35,6 +34,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel import com.android.credentialmanager.common.Constants import com.android.credentialmanager.common.DialogState import com.android.credentialmanager.common.ProviderActivityResult import com.android.credentialmanager.common.StartBalIntentSenderForResultContract import com.android.credentialmanager.createflow.CreateCredentialScreen import com.android.credentialmanager.getflow.GetCredentialScreen import com.android.credentialmanager.ui.theme.CredentialSelectorTheme Loading Loading @@ -84,7 +84,7 @@ class CredentialSelectorActivity : ComponentActivity() { CredentialSelectorViewModel(credManRepo, userConfigRepo) } val launcher = rememberLauncherForActivityResult( ActivityResultContracts.StartIntentSenderForResult() StartBalIntentSenderForResultContract() ) { viewModel.onProviderActivityResult(ProviderActivityResult(it.resultCode, it.data)) } Loading packages/CredentialManager/src/com/android/credentialmanager/common/StartBalIntentSenderForResultContract.kt 0 → 100644 +53 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.credentialmanager.common import android.app.ActivityOptions import android.content.Context import android.content.Intent import androidx.activity.result.ActivityResult import androidx.activity.result.IntentSenderRequest import androidx.activity.result.contract.ActivityResultContract import androidx.activity.result.contract.ActivityResultContracts /** * A custom StartIntentSenderForResult contract implementation that attaches an [ActivityOptions] * that opts in for background activity launch. */ class StartBalIntentSenderForResultContract : ActivityResultContract<IntentSenderRequest, ActivityResult>() { override fun createIntent(context: Context, input: IntentSenderRequest): Intent { val activityOptionBundle = ActivityOptions.makeBasic().setPendingIntentBackgroundActivityStartMode( ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED ).toBundle() return Intent( ActivityResultContracts.StartIntentSenderForResult.ACTION_INTENT_SENDER_REQUEST ).putExtra( ActivityResultContracts.StartActivityForResult.EXTRA_ACTIVITY_OPTIONS_BUNDLE, activityOptionBundle ).putExtra( ActivityResultContracts.StartIntentSenderForResult.EXTRA_INTENT_SENDER_REQUEST, input ) } override fun parseResult( resultCode: Int, intent: Intent? ): ActivityResult = ActivityResult(resultCode, intent) } No newline at end of file Loading
packages/CredentialManager/src/com/android/credentialmanager/CredentialSelectorActivity.kt +2 −2 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ import android.util.Log import androidx.activity.ComponentActivity import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.compose.setContent import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.runtime.Composable Loading @@ -35,6 +34,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel import com.android.credentialmanager.common.Constants import com.android.credentialmanager.common.DialogState import com.android.credentialmanager.common.ProviderActivityResult import com.android.credentialmanager.common.StartBalIntentSenderForResultContract import com.android.credentialmanager.createflow.CreateCredentialScreen import com.android.credentialmanager.getflow.GetCredentialScreen import com.android.credentialmanager.ui.theme.CredentialSelectorTheme Loading Loading @@ -84,7 +84,7 @@ class CredentialSelectorActivity : ComponentActivity() { CredentialSelectorViewModel(credManRepo, userConfigRepo) } val launcher = rememberLauncherForActivityResult( ActivityResultContracts.StartIntentSenderForResult() StartBalIntentSenderForResultContract() ) { viewModel.onProviderActivityResult(ProviderActivityResult(it.resultCode, it.data)) } Loading
packages/CredentialManager/src/com/android/credentialmanager/common/StartBalIntentSenderForResultContract.kt 0 → 100644 +53 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.credentialmanager.common import android.app.ActivityOptions import android.content.Context import android.content.Intent import androidx.activity.result.ActivityResult import androidx.activity.result.IntentSenderRequest import androidx.activity.result.contract.ActivityResultContract import androidx.activity.result.contract.ActivityResultContracts /** * A custom StartIntentSenderForResult contract implementation that attaches an [ActivityOptions] * that opts in for background activity launch. */ class StartBalIntentSenderForResultContract : ActivityResultContract<IntentSenderRequest, ActivityResult>() { override fun createIntent(context: Context, input: IntentSenderRequest): Intent { val activityOptionBundle = ActivityOptions.makeBasic().setPendingIntentBackgroundActivityStartMode( ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED ).toBundle() return Intent( ActivityResultContracts.StartIntentSenderForResult.ACTION_INTENT_SENDER_REQUEST ).putExtra( ActivityResultContracts.StartActivityForResult.EXTRA_ACTIVITY_OPTIONS_BUNDLE, activityOptionBundle ).putExtra( ActivityResultContracts.StartIntentSenderForResult.EXTRA_INTENT_SENDER_REQUEST, input ) } override fun parseResult( resultCode: Int, intent: Intent? ): ActivityResult = ActivityResult(resultCode, intent) } No newline at end of file