yathaarth batra
yathaarth batra

Reputation: 11

Credential Provider Service does not have the required capabilities

Recently android has introduced support for passkeys and I want to create an app which should provide or create passkeys. For this android has given CredentialProviderService to use. I have made my CredentiaProviderService and extended it with CredentialProviderService provided by the credential jetpack library. I also declared the service in AndroidManifest file but the problem is that I am not able to declare the capabilities. According to the documentation, I have declared the capabilities in meta-data of the service but log says that Credential Provider Service does not have the required capabilities. Here is the documentation for more reference: https://developer.android.com/reference/android/service/credentials/CredentialProviderService#SERVICE_META_DATA

Here is my CredentialProvider Service Code:

class CustomCredentialProviderService : CredentialProviderService() {
    private val TAG = "CredentialProviderService"
    override fun onBeginCreateCredentialRequest(
        request: BeginCreateCredentialRequest,
        cancellationSignal: CancellationSignal,
        callback: OutcomeReceiver<BeginCreateCredentialResponse, CreateCredentialException>
    ) {
        Log.d(TAG,"onBeginCreateCredentialRequest called")
    }

    override fun onBeginGetCredentialRequest(
        request: BeginGetCredentialRequest,
        cancellationSignal: CancellationSignal,
        callback: OutcomeReceiver<BeginGetCredentialResponse, GetCredentialException>
    ) {
        Log.d(TAG,"onBeginGetCredentialRequest called")
    }

    override fun onClearCredentialStateRequest(
        request: ProviderClearCredentialStateRequest,
        cancellationSignal: CancellationSignal,
        callback: OutcomeReceiver<Void?, ClearCredentialException>
    ) {
        Log.d(TAG,"onClearCredentialStateRequest called")
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        return super.onStartCommand(intent, flags, startId)
    }

    override fun onCreate() {
        super.onCreate()
    }

    override fun onUnbind(intent: Intent?): Boolean {
        return super.onUnbind(intent)
    }

    override fun onRebind(intent: Intent?) {
        super.onRebind(intent)
    }

    override fun onDestroy() {
        super.onDestroy()
    }


}

Here is my AndroidManifest code:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.PassKeysDemo"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service android:name=".CustomCredentialProviderService"
            android:permission="android.permission.BIND_CREDENTIAL_PROVIDER_SERVICE"
            android:exported="false">
           <intent-filter>
               <action android:name="android.service.credentials.CredentialProviderService"/>
           </intent-filter>
           <meta-data android:name="android.credentials.provider"
               android:resource="@xml/provider"/>
        </service>
    </application>

</manifest>

Here is my @xml/provider.xml file:

<?xml version="1.0" encoding="utf-8"?>
<credential-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:settingsSubtitle="Use Passkeys"
    android:capability="android.credentials.TYPE_PUBLIC_KEY_CREDENTIAL"/>

`Also the android logs:
? I/CredManSysService: starting executeCreateCredential with callingPackage: com.dashlane.dashlanepasskeydemo
? I/CredManSysServiceImpl: Service does not have the required capabilities
? I/CredManSysServiceImpl: Service does not have the required capabilities
? I/CreateRequestSession: Provider session created and being added for: ComponentInfo{com.google.android.gms/com.google.android.gms.auth.api.credentials.credman.service.RemoteService}`

Upvotes: 1

Views: 808

Answers (1)

agi
agi

Reputation: 516

A bit late, but it may help others stumbling on this:

There is a small error in your @xml/provider.xml file, it should read:

<?xml version="1.0" encoding="utf-8"?>
<credential-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:settingsSubtitle="@string/providerSubtitle"
    >
    <capabilities>
        <capability name="androidx.credentials.TYPE_PUBLIC_KEY_CREDENTIAL" />
    </capabilities>
</credential-provider>

Upvotes: 0

Related Questions