Skip to content

Commit

Permalink
Specify mutability for USB and NFC intents
Browse files Browse the repository at this point in the history
Required for Android >= 12 as per [1]. Intents must be mutable to allow the platform framework to specify NFC/USB device extras.

[1] https://developer.android.com/guide/components/intents-filters#DeclareMutabilityPendingIntent
  • Loading branch information
pp3345 committed Jun 4, 2023
1 parent 65b7b76 commit a51405d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/src/main/java/net/pp3345/ykdroid/ConnectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.IsoDep;
import android.os.Build;
import android.os.Bundle;

import net.pp3345.ykdroid.yubikey.NfcYubiKey;
Expand Down Expand Up @@ -110,7 +111,7 @@ public void onActivityResumed(final Activity activity) {
final IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);

NfcAdapter.getDefaultAdapter(this.activity).enableForegroundDispatch(this.activity,
PendingIntent.getActivity(this.activity, -1, new Intent(this.activity, this.activity.getClass()), 0),
PendingIntent.getActivity(this.activity, -1, new Intent(this.activity, this.activity.getClass()), Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_MUTABLE : 0),
new IntentFilter[]{filter},
new String[][]{new String[]{IsoDep.class.getName()}});
this.isActivityResumed = true;
Expand Down Expand Up @@ -215,7 +216,7 @@ private void requestPermission(final UsbDevice device) {
this.connectReceiver.onYubiKeyConnected(new UsbYubiKey(device, usbManager.openDevice(device)));
this.connectReceiver = null;
} else {
usbManager.requestPermission(device, PendingIntent.getBroadcast(this.activity, 0, new Intent(ACTION_USB_PERMISSION_REQUEST), 0));
usbManager.requestPermission(device, PendingIntent.getBroadcast(this.activity, 0, new Intent(ACTION_USB_PERMISSION_REQUEST), Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_MUTABLE : 0));
}
}

Expand Down

0 comments on commit a51405d

Please sign in to comment.