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

Commit d43ff4f4 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Do not update connection policies when service discovery fails

Application initiated service discovery starts a 6 second timer to
generate an ACTION_UUID intent if service discovery does not conclude.
This also results in internal modules, namely PhonePolicy, being updated
with again with already known service UUIDs. PhonePolicy should not try
to update the connection policies of the already discovered profiles.

Test: mmm packages/modules/Bluetooth
Flag: com.android.bluetooth.flags.prevent_duplicate_uuid_intent
Bug: 340322814
Bug: 361182196
Change-Id: I7669e89cbf15b5fff7c4603142ce78889814411d
parent d9a9502b
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -76,6 +76,8 @@ public class RemoteDevices {

    private static final int UUID_INTENT_DELAY = 6000;
    private static final int MESSAGE_UUID_INTENT = 1;
    private static final int MESSAGE_UUID_STATUS_SUCCESS = 0;
    private static final int MESSAGE_UUID_STATUS_TIMEOUT = 1;
    private static final String LOG_SOURCE_DIS = "DIS";

    private final HashMap<String, DeviceProperties> mDevices;
@@ -116,12 +118,13 @@ public class RemoteDevices {
                case MESSAGE_UUID_INTENT:
                    BluetoothDevice device = (BluetoothDevice) msg.obj;
                    if (device != null) {
                        boolean success = (msg.arg1 == MESSAGE_UUID_STATUS_SUCCESS);
                        debugLog("MESSAGE_UUID_INTENT: " + device);
                        // SDP Sending delayed SDP UUID intent
                        MetricsLogger.getInstance()
                                .cacheCount(BluetoothProtoEnums.SDP_SENDING_DELAYED_UUID, 1);
                        DeviceProperties prop = getDeviceProperties(device);
                        sendUuidIntent(device, prop);
                        sendUuidIntent(device, prop, success);
                    } else {
                        // SDP Not sending delayed SDP UUID intent b/c device is not there
                        MetricsLogger.getInstance()
@@ -723,10 +726,13 @@ public class RemoteDevices {
        }
    }

    private void sendUuidIntent(BluetoothDevice device, DeviceProperties prop) {
    private void sendUuidIntent(BluetoothDevice device, DeviceProperties prop, boolean success) {
        // Send uuids within the stack before the broadcast is sent out
        ParcelUuid[] uuids = prop == null ? null : prop.getUuids();

        if (!Flags.preventDuplicateUuidIntent() || success) {
            mAdapterService.sendUuidsInternal(device, uuids);
        }

        Intent intent = new Intent(BluetoothDevice.ACTION_UUID);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
@@ -998,7 +1004,7 @@ public class RemoteDevices {
                                        .cacheCount(
                                                BluetoothProtoEnums.SDP_ADD_UUID_WITH_INTENT, 1);
                                mAdapterService.deviceUuidUpdated(bdDevice);
                                sendUuidIntent(bdDevice, deviceProperties);
                                sendUuidIntent(bdDevice, deviceProperties, true);
                            } else if (mAdapterService.getState()
                                    == BluetoothAdapter.STATE_BLE_ON) {
                                // SDP Adding UUIDs to property cache but with no intent
@@ -1419,6 +1425,7 @@ public class RemoteDevices {

        Message message = mHandler.obtainMessage(MESSAGE_UUID_INTENT);
        message.obj = device;
        message.arg1 = MESSAGE_UUID_STATUS_TIMEOUT;
        mHandler.sendMessageDelayed(message, UUID_INTENT_DELAY);

        // Uses cached UUIDs if we are bonding. If not, we fetch the UUIDs with SDP.
@@ -1438,6 +1445,7 @@ public class RemoteDevices {
    void updateUuids(BluetoothDevice device) {
        Message message = mHandler.obtainMessage(MESSAGE_UUID_INTENT);
        message.obj = device;
        message.arg1 = MESSAGE_UUID_STATUS_SUCCESS;
        mHandler.sendMessage(message);
    }