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

Commit 8a0782fb authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Log pairing related API interactions" into main

parents 00f90ae8 c863ad89
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -3137,6 +3137,7 @@ public class AdapterService extends Service {
            // Only allow setting a pin in bonding state, or bonded state in case of security
            // upgrade.
            if (deviceProp == null || !deviceProp.isBondingOrBonded()) {
                Log.e(TAG, "setPin: device=" + device + ", not bonding");
                return false;
            }
            if (pinCode.length != len) {
@@ -3146,6 +3147,14 @@ public class AdapterService extends Service {
            }
            service.logUserBondResponse(
                    device, accept, BluetoothProtoEnums.BOND_SUB_STATE_LOCAL_PIN_REPLIED);
            Log.i(
                    TAG,
                    "setPin: device="
                            + device
                            + ", accept="
                            + accept
                            + ", from "
                            + Utils.getUidPidString());
            return service.mNativeInterface.pinReply(
                    getBytesFromAddress(device.getAddress()), accept, len, pinCode);
        }
@@ -3167,6 +3176,7 @@ public class AdapterService extends Service {

            DeviceProperties deviceProp = service.mRemoteDevices.getDeviceProperties(device);
            if (deviceProp == null || !deviceProp.isBonding()) {
                Log.e(TAG, "setPasskey: device=" + device + ", not bonding");
                return false;
            }
            if (passkey.length != len) {
@@ -3176,6 +3186,15 @@ public class AdapterService extends Service {
            }
            service.logUserBondResponse(
                    device, accept, BluetoothProtoEnums.BOND_SUB_STATE_LOCAL_SSP_REPLIED);
            Log.i(
                    TAG,
                    "setPasskey: device="
                            + device
                            + ", accept="
                            + accept
                            + ", from "
                            + Utils.getUidPidString());

            return service.mNativeInterface.sspReply(
                    getBytesFromAddress(device.getAddress()),
                    AbstractionLayer.BT_SSP_VARIANT_PASSKEY_ENTRY,
@@ -3197,10 +3216,20 @@ public class AdapterService extends Service {

            DeviceProperties deviceProp = service.mRemoteDevices.getDeviceProperties(device);
            if (deviceProp == null || !deviceProp.isBonding()) {
                Log.e(TAG, "setPairingConfirmation: device=" + device + ", not bonding");
                return false;
            }
            service.logUserBondResponse(
                    device, accept, BluetoothProtoEnums.BOND_SUB_STATE_LOCAL_SSP_REPLIED);
            Log.i(
                    TAG,
                    "setPairingConfirmation: device="
                            + device
                            + ", accept="
                            + accept
                            + ", from "
                            + Utils.getUidPidString());

            return service.mNativeInterface.sspReply(
                    getBytesFromAddress(device.getAddress()),
                    AbstractionLayer.BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
+3 −1
Original line number Diff line number Diff line
@@ -488,13 +488,15 @@ final class BondStateMachine extends StateMachine {
    }

    private void sendDisplayPinIntent(byte[] address, Optional<Integer> maybePin, int variant) {
        BluetoothDevice device = mRemoteDevices.getDevice(address);
        Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mRemoteDevices.getDevice(address));
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        maybePin.ifPresent(pin -> intent.putExtra(BluetoothDevice.EXTRA_PAIRING_KEY, pin));
        intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, variant);
        intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        // Workaround for Android Auto until pre-accepting pairing requests is added.
        intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        Log.i(TAG, "sendDisplayPinIntent: device=" + device + ", variant=" + variant);
        mAdapterService.sendOrderedBroadcast(
                intent,
                BLUETOOTH_CONNECT,
+20 −12
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ import android.os.RemoteException;
import android.os.SystemProperties;
import android.util.Log;

import androidx.annotation.NonNull;

import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.R;
import com.android.bluetooth.Utils;
@@ -1012,19 +1014,19 @@ public class RemoteDevices {
        // The device properties are already registered - we can send the intent
        // now
        BluetoothDevice device = getDevice(address);
        debugLog("deviceFoundCallback: Remote Address is:" + device);
        DeviceProperties deviceProp = getDeviceProperties(device);
        if (deviceProp == null) {
            errorLog("Device Properties is null for Device:" + device);
            errorLog("deviceFoundCallback: Device Properties is null for Device:" + device);
            return;
        }
        boolean restrict_device_found =
                SystemProperties.getBoolean("bluetooth.restrict_discovered_device.enabled", false);
        if (restrict_device_found && (deviceProp.mName == null || deviceProp.mName.isEmpty())) {
            debugLog("Device name is null or empty: " + device);
            warnLog("deviceFoundCallback: Device name is null or empty: " + device);
            return;
        }

        infoLog("deviceFoundCallback: Remote Address is:" + device);
        Intent intent = new Intent(BluetoothDevice.ACTION_FOUND);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        intent.putExtra(
@@ -1173,15 +1175,7 @@ public class RemoteDevices {
            deviceProperties.setConnectionHandle(BluetoothDevice.ERROR, transportLinkType);
            if (device.getBondState() == BluetoothDevice.BOND_BONDING) {
                // Send PAIRING_CANCEL intent to dismiss any dialog requesting bonding.
                intent = new Intent(BluetoothDevice.ACTION_PAIRING_CANCEL);
                intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
                intent.setPackage(
                        SystemProperties.get(
                                Utils.PAIRING_UI_PROPERTY,
                                mAdapterService.getString(R.string.pairing_ui_package)));

                mAdapterService.sendBroadcast(
                        intent, BLUETOOTH_CONNECT, Utils.getTempBroadcastOptions().toBundle());
                sendPairingCancelIntent(device);
            } else if (device.getBondState() == BluetoothDevice.BOND_NONE) {
                removeAddressMapping(Utils.getAddressStringFromByte(address));
            }
@@ -1278,6 +1272,20 @@ public class RemoteDevices {
        }
    }

    @NonNull
    private void sendPairingCancelIntent(BluetoothDevice device) {
        Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_CANCEL);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        intent.setPackage(
                SystemProperties.get(
                        Utils.PAIRING_UI_PROPERTY,
                        mAdapterService.getString(R.string.pairing_ui_package)));

        Log.i(TAG, "sendPairingCancelIntent: device=" + device);
        mAdapterService.sendBroadcast(
                intent, BLUETOOTH_CONNECT, Utils.getTempBroadcastOptions().toBundle());
    }

    private void removeAddressMapping(String address) {
        if (Flags.temporaryPairingDeviceProperties()) {
            DeviceProperties deviceProperties = mDevices.get(address);