Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 73a8c708 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

feat: introduce CredentialProviderService implementation

parent 320e71e0
Loading
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
  -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.PROVIDE_DEFAULT_ENABLED_CREDENTIAL_SERVICE" />

    <permission
        android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"
@@ -581,6 +582,23 @@
            </intent-filter>
        </service>

        <service
            android:name="org.microg.gms.credential.MicrogCredentialProviderService"
            android:exported="true"
            android:permission="android.permission.BIND_CREDENTIAL_PROVIDER_SERVICE"
            android:label="@string/gms_app_name">
            <intent-filter>
                <action android:name="android.service.credentials.CredentialProviderService" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <meta-data
                android:name="android.credentials.provider"
                android:resource="@xml/credential_provider_platform" />
            <meta-data
                android:name="android.service.credentials.CredentialProviderService"
                android:resource="@xml/credential_provider_platform" />
        </service>

        <activity
            android:name="org.microg.gms.auth.signin.AuthSignInActivity"
            android:theme="@style/Theme.App.DayNight.Dialog.Alert.NoActionBar"
+62 −0
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2025 microG Project Team
 * SPDX-License-Identifier: Apache-2.0
 */

package org.microg.gms.credential

import android.credentials.ClearCredentialStateException
import android.credentials.CreateCredentialException
import android.credentials.GetCredentialException
import android.os.Build
import android.os.CancellationSignal
import android.os.OutcomeReceiver
import android.service.credentials.BeginCreateCredentialRequest
import android.service.credentials.BeginCreateCredentialResponse
import android.service.credentials.BeginGetCredentialRequest
import android.service.credentials.BeginGetCredentialResponse
import android.service.credentials.ClearCredentialStateRequest
import android.service.credentials.CredentialProviderService
import android.util.Log
import androidx.annotation.RequiresApi

@RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
class MicrogCredentialProviderService : CredentialProviderService() {
    override fun onCreate() {
        super.onCreate()
        Log.i(TAG, "onCreate")
    }

    @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
    override fun onBeginGetCredential(
        request: BeginGetCredentialRequest,
        cancellationSignal: CancellationSignal,
        callback: OutcomeReceiver<BeginGetCredentialResponse, GetCredentialException>
    ) {
        Log.i(TAG, "onBeginGetCredential: unsupported request=$request")
        callback.onError(GetCredentialException(GetCredentialException.TYPE_NO_CREDENTIAL))
    }

    @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
    override fun onBeginCreateCredential(
        request: BeginCreateCredentialRequest,
        cancellationSignal: CancellationSignal,
        callback: OutcomeReceiver<BeginCreateCredentialResponse, CreateCredentialException>
    ) {
        Log.i(TAG, "onBeginCreateCredential: unsupported request=$request")
        callback.onError(CreateCredentialException(CreateCredentialException.TYPE_NO_CREATE_OPTIONS))
    }

    override fun onClearCredentialState(
        request: ClearCredentialStateRequest,
        cancellationSignal: CancellationSignal,
        callback: OutcomeReceiver<Void, ClearCredentialStateException>
    ) {
        Log.i(TAG, "onClearCredentialState: no-op request=$request")
        callback.onResult(null)
    }

    companion object {
        private const val TAG = "CredentialProvider"
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -460,4 +460,6 @@ Please set up a password, PIN, or pattern lock screen."</string>
    <string name="location_sharing_turn_off_confirm">Turn off</string>
    <string name="location_sharing_confirm_dialog_title">Enable Location Sharing</string>
    <string name="location_sharing_confirm_dialog_text">People you share your location with can always see:\n·Your name and photo\n·Your device\'s recent location,even when you\'re not using a Google service\n·Your device\'s battery power,and if it\'s charging\n·Your arrival and departure time,if they add a Location Sharing notification</string>

    <string name="credential_provider_subtitle">microG credential provider</string>
</resources>
+8 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<credential-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:settingsSubtitle="@string/credential_provider_subtitle">
    <capabilities>
        <capability>android.credentials.TYPE_PASSWORD_CREDENTIAL</capability>
        <capability>android.credentials.TYPE_PUBLIC_KEY_CREDENTIAL</capability>
    </capabilities>
</credential-provider>