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

Unverified Commit 02b7abc3 authored by S1m's avatar S1m Committed by GitHub
Browse files

Fido: fix support when targetSdk>=35 (#2887)



Co-authored-by: default avatarMarvin W <git@larma.de>
parent 2bb0a9c4
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -6,12 +6,14 @@
package org.microg.gms.fido.core.transport.nfc

import android.app.Activity
import android.app.ActivityOptions
import android.app.PendingIntent
import android.content.Intent
import android.content.IntentFilter
import android.nfc.NfcAdapter
import android.nfc.Tag
import android.nfc.tech.IsoDep
import android.os.Build.VERSION.SDK_INT
import android.util.Log
import androidx.core.app.OnNewIntentProvider
import androidx.core.app.PendingIntentCompat
@@ -39,7 +41,17 @@ class NfcTransportHandler(private val activity: Activity, callback: TransportHan

    private suspend fun waitForNewNfcTag(adapter: NfcAdapter): Tag {
        val intent = Intent(activity, activity.javaClass).apply { addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) }
        val pendingIntent: PendingIntent = PendingIntentCompat.getActivity(activity, 0, intent, 0, true)!!
        val piOptions = if (SDK_INT >= 34) {
            ActivityOptions.makeBasic().apply {
                pendingIntentCreatorBackgroundActivityStartMode =
                    ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED
            }.toBundle()
        } else null
        val pendingIntent: PendingIntent = PendingIntentCompat.getActivity(
            activity, 0, intent,
            0,
            piOptions,
            true)!!
        adapter.enableForegroundDispatch(
            activity,
            pendingIntent,
+3 −3
Original line number Diff line number Diff line
@@ -5,15 +5,15 @@

package org.microg.gms.fido.core.transport.usb

import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.hardware.usb.UsbDevice
import android.hardware.usb.UsbManager
import android.os.Build.VERSION.SDK_INT
import androidx.core.app.PendingIntentCompat
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.RECEIVER_NOT_EXPORTED
import kotlinx.coroutines.CompletableDeferred

private val Context.usbPermissionCallbackAction
@@ -25,7 +25,7 @@ private object UsbDevicePermissionReceiver : BroadcastReceiver() {

    fun register(context: Context) = synchronized(this) {
        if (!registered) {
            context.registerReceiver(this, IntentFilter(context.usbPermissionCallbackAction))
            ContextCompat.registerReceiver(context, this, IntentFilter(context.usbPermissionCallbackAction), RECEIVER_NOT_EXPORTED)
            registered = true
        }
    }
+3 −7
Original line number Diff line number Diff line
@@ -17,20 +17,16 @@ import android.os.Bundle
import android.util.Base64
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.RECEIVER_NOT_EXPORTED
import com.google.android.gms.fido.fido2.api.common.*
import com.upokecenter.cbor.CBORObject
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.delay
import org.microg.gms.fido.core.*
import org.microg.gms.fido.core.protocol.*
import org.microg.gms.fido.core.protocol.msgs.*
import org.microg.gms.fido.core.transport.CtapConnection
import org.microg.gms.fido.core.transport.Transport
import org.microg.gms.fido.core.transport.TransportHandler
import org.microg.gms.fido.core.transport.TransportHandlerCallback
import org.microg.gms.fido.core.transport.usb.ctaphid.CtapHidConnection
import org.microg.gms.fido.core.transport.usb.ctaphid.CtapHidMessageStatusException
import org.microg.gms.utils.toBase64

@RequiresApi(21)
@@ -112,7 +108,7 @@ class UsbTransportHandler(private val context: Context, callback: TransportHandl
                deferred.complete(device)
            }
        }
        context.registerReceiver(receiver, IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED))
        ContextCompat.registerReceiver(context, receiver, IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED), RECEIVER_NOT_EXPORTED)
        invokeStatusChanged(TransportHandlerCallback.STATUS_WAITING_FOR_DEVICE)
        val device = deferred.await()
        context.unregisterReceiver(receiver)