Loading packages/CredentialManager/shared/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ android_library { manifest: "AndroidManifest.xml", srcs: ["src/**/*.kt"], static_libs: [ "androidx.activity_activity-compose", "androidx.core_core-ktx", "androidx.credentials_credentials", "guava", Loading packages/CredentialManager/shared/src/com/android/credentialmanager/ApiConstants.kt 0 → 100644 +19 −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.0N * * 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 const val IS_AUTO_SELECTED_KEY = "IS_AUTO_SELECTED" packages/CredentialManager/shared/src/com/android/credentialmanager/IntentParser.kt +13 −2 Original line number Diff line number Diff line Loading @@ -17,14 +17,25 @@ package com.android.credentialmanager import android.content.Intent import android.content.pm.PackageManager import android.credentials.ui.RequestInfo import com.android.credentialmanager.ktx.requestInfo import com.android.credentialmanager.mapper.toGet import com.android.credentialmanager.mapper.toRequestCancel import com.android.credentialmanager.mapper.toRequestClose import com.android.credentialmanager.model.Request fun Intent.parse(): Request { this.toRequestCancel()?.let { return it } fun Intent.parse( packageManager: PackageManager, previousIntent: Intent? = null, ): Request { this.toRequestClose(packageManager, previousIntent)?.let { closeRequest -> return closeRequest } this.toRequestCancel(packageManager)?.let { cancelRequest -> return cancelRequest } return when (requestInfo?.type) { RequestInfo.TYPE_CREATE -> { Loading packages/CredentialManager/shared/src/com/android/credentialmanager/activity/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.activity 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 packages/CredentialManager/shared/src/com/android/credentialmanager/ktx/IntentKtx.kt +8 −0 Original line number Diff line number Diff line Loading @@ -18,10 +18,12 @@ package com.android.credentialmanager.ktx import android.content.Intent import android.credentials.ui.CancelUiRequest import android.credentials.ui.Constants import android.credentials.ui.CreateCredentialProviderData import android.credentials.ui.GetCredentialProviderData import android.credentials.ui.ProviderData import android.credentials.ui.RequestInfo import android.os.ResultReceiver val Intent.cancelUiRequest: CancelUiRequest? get() = this.extras?.getParcelable( Loading @@ -46,3 +48,9 @@ val Intent.createCredentialProviderDataList: List<ProviderData> ProviderData.EXTRA_ENABLED_PROVIDER_DATA_LIST, CreateCredentialProviderData::class.java ) ?: emptyList() val Intent.resultReceiver: ResultReceiver? get() = this.getParcelableExtra( Constants.EXTRA_RESULT_RECEIVER, ResultReceiver::class.java ) Loading
packages/CredentialManager/shared/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ android_library { manifest: "AndroidManifest.xml", srcs: ["src/**/*.kt"], static_libs: [ "androidx.activity_activity-compose", "androidx.core_core-ktx", "androidx.credentials_credentials", "guava", Loading
packages/CredentialManager/shared/src/com/android/credentialmanager/ApiConstants.kt 0 → 100644 +19 −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.0N * * 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 const val IS_AUTO_SELECTED_KEY = "IS_AUTO_SELECTED"
packages/CredentialManager/shared/src/com/android/credentialmanager/IntentParser.kt +13 −2 Original line number Diff line number Diff line Loading @@ -17,14 +17,25 @@ package com.android.credentialmanager import android.content.Intent import android.content.pm.PackageManager import android.credentials.ui.RequestInfo import com.android.credentialmanager.ktx.requestInfo import com.android.credentialmanager.mapper.toGet import com.android.credentialmanager.mapper.toRequestCancel import com.android.credentialmanager.mapper.toRequestClose import com.android.credentialmanager.model.Request fun Intent.parse(): Request { this.toRequestCancel()?.let { return it } fun Intent.parse( packageManager: PackageManager, previousIntent: Intent? = null, ): Request { this.toRequestClose(packageManager, previousIntent)?.let { closeRequest -> return closeRequest } this.toRequestCancel(packageManager)?.let { cancelRequest -> return cancelRequest } return when (requestInfo?.type) { RequestInfo.TYPE_CREATE -> { Loading
packages/CredentialManager/shared/src/com/android/credentialmanager/activity/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.activity 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
packages/CredentialManager/shared/src/com/android/credentialmanager/ktx/IntentKtx.kt +8 −0 Original line number Diff line number Diff line Loading @@ -18,10 +18,12 @@ package com.android.credentialmanager.ktx import android.content.Intent import android.credentials.ui.CancelUiRequest import android.credentials.ui.Constants import android.credentials.ui.CreateCredentialProviderData import android.credentials.ui.GetCredentialProviderData import android.credentials.ui.ProviderData import android.credentials.ui.RequestInfo import android.os.ResultReceiver val Intent.cancelUiRequest: CancelUiRequest? get() = this.extras?.getParcelable( Loading @@ -46,3 +48,9 @@ val Intent.createCredentialProviderDataList: List<ProviderData> ProviderData.EXTRA_ENABLED_PROVIDER_DATA_LIST, CreateCredentialProviderData::class.java ) ?: emptyList() val Intent.resultReceiver: ResultReceiver? get() = this.getParcelableExtra( Constants.EXTRA_RESULT_RECEIVER, ResultReceiver::class.java )