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

Commit 37de3cb8 authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Gerrit Code Review
Browse files

Merge "Add ENCRYPTION_CHANGE broadcast" into main

parents 85028554 55bdbd84
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -1440,6 +1440,30 @@ public class RemoteDevices {
                        + secureConnection
                        + ", keySize: "
                        + keySize);

        int algorithm = BluetoothDevice.ENCRYPTION_ALGORITHM_NONE;
        if (encryptionEnable) {
            if (secureConnection || transport == BluetoothDevice.TRANSPORT_LE) {
                /* LE link or Classic Secure Connections */
                algorithm = BluetoothDevice.ENCRYPTION_ALGORITHM_AES;
            } else {
                /* Classic link using non-secure connections mode */
                algorithm = BluetoothDevice.ENCRYPTION_ALGORITHM_E0;
            }
        }

        Intent intent =
                new Intent(BluetoothDevice.ACTION_ENCRYPTION_CHANGE)
                        .putExtra(BluetoothDevice.EXTRA_DEVICE, bluetoothDevice)
                        .putExtra(BluetoothDevice.EXTRA_TRANSPORT, transport)
                        .putExtra(BluetoothDevice.EXTRA_ENCRYPTION_STATUS, status)
                        .putExtra(BluetoothDevice.EXTRA_ENCRYPTION_ENABLED, encryptionEnable)
                        .putExtra(BluetoothDevice.EXTRA_KEY_SIZE, keySize)
                        .putExtra(BluetoothDevice.EXTRA_ENCRYPTION_ALGORITHM, algorithm);

        if (com.android.bluetooth.flags.Flags.encryptionChangeBroadcast()) {
            mAdapterService.sendBroadcast(intent, BLUETOOTH_CONNECT);
        }
    }

    void fetchUuids(BluetoothDevice device, int transport) {
+8 −0
Original line number Diff line number Diff line
@@ -89,3 +89,11 @@ flag {
    description: "Add a new API to BluetoothDevice to retrieve Identity Address Type"
    bug: "377171798"
}

flag {
    name: "encryption_change_broadcast"
    is_exported: true
    namespace: "bluetooth"
    description: "Broadcast when remote device encryption changes"
    bug: "369753860"
}
+8 −0
Original line number Diff line number Diff line
@@ -553,6 +553,7 @@ package android.bluetooth {
    field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_ALIAS_CHANGED = "android.bluetooth.device.action.ALIAS_CHANGED";
    field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_BOND_STATE_CHANGED = "android.bluetooth.device.action.BOND_STATE_CHANGED";
    field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_CLASS_CHANGED = "android.bluetooth.device.action.CLASS_CHANGED";
    field @FlaggedApi("com.android.bluetooth.flags.encryption_change_broadcast") @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_ENCRYPTION_CHANGE = "android.bluetooth.device.action.ENCRYPTION_CHANGE";
    field @RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN) public static final String ACTION_FOUND = "android.bluetooth.device.action.FOUND";
    field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_NAME_CHANGED = "android.bluetooth.device.action.NAME_CHANGED";
    field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_PAIRING_REQUEST = "android.bluetooth.device.action.PAIRING_REQUEST";
@@ -569,11 +570,18 @@ package android.bluetooth {
    field public static final int DEVICE_TYPE_DUAL = 3; // 0x3
    field public static final int DEVICE_TYPE_LE = 2; // 0x2
    field public static final int DEVICE_TYPE_UNKNOWN = 0; // 0x0
    field @FlaggedApi("com.android.bluetooth.flags.encryption_change_broadcast") public static final int ENCRYPTION_ALGORITHM_AES = 2; // 0x2
    field @FlaggedApi("com.android.bluetooth.flags.encryption_change_broadcast") public static final int ENCRYPTION_ALGORITHM_E0 = 1; // 0x1
    field @FlaggedApi("com.android.bluetooth.flags.encryption_change_broadcast") public static final int ENCRYPTION_ALGORITHM_NONE = 0; // 0x0
    field public static final int ERROR = -2147483648; // 0x80000000
    field public static final String EXTRA_BOND_STATE = "android.bluetooth.device.extra.BOND_STATE";
    field public static final String EXTRA_CLASS = "android.bluetooth.device.extra.CLASS";
    field public static final String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE";
    field @FlaggedApi("com.android.bluetooth.flags.encryption_change_broadcast") public static final String EXTRA_ENCRYPTION_ALGORITHM = "android.bluetooth.device.extra.EXTRA_ENCRYPTION_ALGORITHM";
    field @FlaggedApi("com.android.bluetooth.flags.encryption_change_broadcast") public static final String EXTRA_ENCRYPTION_ENABLED = "android.bluetooth.device.extra.ENCRYPTION_ENABLED";
    field @FlaggedApi("com.android.bluetooth.flags.encryption_change_broadcast") public static final String EXTRA_ENCRYPTION_STATUS = "android.bluetooth.device.extra.ENCRYPTION_STATUS";
    field public static final String EXTRA_IS_COORDINATED_SET_MEMBER = "android.bluetooth.extra.IS_COORDINATED_SET_MEMBER";
    field @FlaggedApi("com.android.bluetooth.flags.encryption_change_broadcast") public static final String EXTRA_KEY_SIZE = "android.bluetooth.device.extra.KEY_SIZE";
    field public static final String EXTRA_NAME = "android.bluetooth.device.extra.NAME";
    field public static final String EXTRA_PAIRING_KEY = "android.bluetooth.device.extra.PAIRING_KEY";
    field public static final String EXTRA_PAIRING_VARIANT = "android.bluetooth.device.extra.PAIRING_VARIANT";
+77 −3
Original line number Diff line number Diff line
@@ -309,6 +309,29 @@ public final class BluetoothDevice implements Parcelable, Attributable {
    @BroadcastBehavior(includeBackground = true, protectedBroadcast = true)
    public static final String ACTION_KEY_MISSING = "android.bluetooth.device.action.KEY_MISSING";

    /**
     * Broadcast Action: Indicates that encryption state changed
     *
     * <p>Always contains the extra field {@link #EXTRA_DEVICE}
     *
     * <p>Always contains the extra field {@link #EXTRA_TRANSPORT}
     *
     * <p>Always contains the extra field {@link #EXTRA_ENCRYPTION_STATUS}
     *
     * <p>Always contains the extra field {@link #EXTRA_ENCRYPTION_ENABLED}
     *
     * <p>Always contains the extra field {@link #EXTRA_KEY_SIZE}
     *
     * <p>Always contains the extra field {@link #EXTRA_ENCRYPTION_ALGORITHM}
     */
    @FlaggedApi(Flags.FLAG_ENCRYPTION_CHANGE_BROADCAST)
    @SuppressLint("ActionValue")
    @RequiresPermission(BLUETOOTH_CONNECT)
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    @BroadcastBehavior(protectedBroadcast = true)
    public static final String ACTION_ENCRYPTION_CHANGE =
            "android.bluetooth.device.action.ENCRYPTION_CHANGE";

    /**
     * Used as an Integer extra field in {@link #ACTION_BATTERY_LEVEL_CHANGED} intent. It contains
     * the most recently retrieved battery level information ranging from 0% to 100% for a remote
@@ -477,6 +500,57 @@ public final class BluetoothDevice implements Parcelable, Attributable {
    public static final String EXTRA_PAIRING_INITIATOR =
            "android.bluetooth.device.extra.PAIRING_INITIATOR";

    /**
     * Used as an int extra field in {@link #ACTION_ENCRYPTION_CHANGE} intents as the size of the
     * encryption key, in number of bytes. i.e. value of 16 means 16-byte, or 128 bit key size.
     */
    @FlaggedApi(Flags.FLAG_ENCRYPTION_CHANGE_BROADCAST)
    @SuppressLint("ActionValue")
    public static final String EXTRA_KEY_SIZE = "android.bluetooth.device.extra.KEY_SIZE";

    /**
     * Used as an int extra field in {@link #ACTION_ENCRYPTION_CHANGE} intents as the algorithm used
     * for encryption.
     *
     * <p>Possible values are: {@link #ENCRYPTION_ALGORITHM_NONE}, {@link #ENCRYPTION_ALGORITHM_E0},
     * {@link #ENCRYPTION_ALGORITHM_AES}.
     */
    @FlaggedApi(Flags.FLAG_ENCRYPTION_CHANGE_BROADCAST)
    @SuppressLint("ActionValue")
    public static final String EXTRA_ENCRYPTION_ALGORITHM =
            "android.bluetooth.device.extra.EXTRA_ENCRYPTION_ALGORITHM";

    /** Indicates that link was not encrypted using any algorithm */
    @FlaggedApi(Flags.FLAG_ENCRYPTION_CHANGE_BROADCAST)
    public static final int ENCRYPTION_ALGORITHM_NONE = 0;

    /** Indicates link was encrypted using E0 algorithm */
    @FlaggedApi(Flags.FLAG_ENCRYPTION_CHANGE_BROADCAST)
    public static final int ENCRYPTION_ALGORITHM_E0 = 1;

    /** Indicates link was encrypted using AES algorithm */
    @FlaggedApi(Flags.FLAG_ENCRYPTION_CHANGE_BROADCAST)
    public static final int ENCRYPTION_ALGORITHM_AES = 2;

    /**
     * Used as an int extra field in {@link #ACTION_ENCRYPTION_CHANGE} intent. This is the status
     * value as returned from controller in "HCI Encryption Change event" i.e. value of 0 means
     * success.
     */
    @FlaggedApi(Flags.FLAG_ENCRYPTION_CHANGE_BROADCAST)
    @SuppressLint("ActionValue")
    public static final String EXTRA_ENCRYPTION_STATUS =
            "android.bluetooth.device.extra.ENCRYPTION_STATUS";

    /**
     * Used as a boolean extra field in {@link #ACTION_ENCRYPTION_CHANGE} intent. false mean
     * encryption is OFF, true means encryption is ON
     */
    @FlaggedApi(Flags.FLAG_ENCRYPTION_CHANGE_BROADCAST)
    @SuppressLint("ActionValue")
    public static final String EXTRA_ENCRYPTION_ENABLED =
            "android.bluetooth.device.extra.ENCRYPTION_ENABLED";

    /**
     * Bluetooth pairing initiator, Foreground App
     *
@@ -1380,9 +1454,9 @@ public final class BluetoothDevice implements Parcelable, Attributable {
    public static final String EXTRA_MAS_INSTANCE = "android.bluetooth.device.extra.MAS_INSTANCE";

    /**
     * Used as an int extra field in {@link #ACTION_ACL_CONNECTED} and {@link
     * #ACTION_ACL_DISCONNECTED} intents to indicate which transport is connected. Possible values
     * are: {@link #TRANSPORT_BREDR} and {@link #TRANSPORT_LE}.
     * Used as an int extra field in {@link #ACTION_ACL_CONNECTED}, {@link #ACTION_ACL_DISCONNECTED}
     * and {@link #ACTION_ENCRYPTION_CHANGE} intents to indicate which transport is connected.
     * Possible values are: {@link #TRANSPORT_BREDR} and {@link #TRANSPORT_LE}.
     */
    @SuppressLint("ActionValue")
    public static final String EXTRA_TRANSPORT = "android.bluetooth.device.extra.TRANSPORT";