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

Commit 3570e72d authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Revert "Prevent sending broadcasts for non-changing properties.""

parents b1de0939 4e94a7fa
Loading
Loading
Loading
Loading
+2 −49
Original line number Diff line number Diff line
@@ -39,10 +39,8 @@ import com.android.bluetooth.hfp.HeadsetHalConstants;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;

final class RemoteDevices {
    private static final boolean DBG = false;
@@ -457,32 +455,6 @@ final class RemoteDevices {
        sAdapterService.sendBroadcast(intent, AdapterService.BLUETOOTH_PERM);
    }

    private static boolean areUuidsEqual(ParcelUuid[] uuids1, ParcelUuid[] uuids2) {
        final int length1 = uuids1 == null ? 0 : uuids1.length;
        final int length2 = uuids2 == null ? 0 : uuids2.length;
        if (length1 != length2) {
            return false;
        }
        Set<ParcelUuid> set = new HashSet<>();
        for (int i = 0; i < length1; ++i) {
            set.add(uuids1[i]);
        }
        for (int i = 0; i < length2; ++i) {
            set.remove(uuids2[i]);
        }
        return set.isEmpty();
    }

    private static boolean areStringsEqual(String string1, String string2) {
        if (string1 == null && string2 == null) {
            return true;
        }
        if (string1 == null || string2 == null) {
            return false;
        }
        return string1.equals(string2);
    }

    void devicePropertyChangedCallback(byte[] address, int[] types, byte[][] values) {
        Intent intent;
        byte[] val;
@@ -510,12 +482,7 @@ final class RemoteDevices {
                    debugLog("Property type: " + type);
                    switch (type) {
                        case AbstractionLayer.BT_PROPERTY_BDNAME:
                            final String newName = new String(val);
                            if (areStringsEqual(newName, device.mName)) {
                                if (DBG) Log.d(TAG, "Skip name update for " + bdDevice);
                                break;
                            }
                            device.mName = newName;
                            device.mName = new String(val);
                            intent = new Intent(BluetoothDevice.ACTION_NAME_CHANGED);
                            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, bdDevice);
                            intent.putExtra(BluetoothDevice.EXTRA_NAME, device.mName);
@@ -535,11 +502,6 @@ final class RemoteDevices {
                            debugLog("Remote Address is:" + Utils.getAddressStringFromByte(val));
                            break;
                        case AbstractionLayer.BT_PROPERTY_CLASS_OF_DEVICE:
                            final int newClass = Utils.byteArrayToInt(val);
                            if (newClass == device.mBluetoothClass) {
                                if (DBG) Log.d(TAG, "Skip class update for " + bdDevice);
                                break;
                            }
                            device.mBluetoothClass = Utils.byteArrayToInt(val);
                            intent = new Intent(BluetoothDevice.ACTION_CLASS_CHANGED);
                            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, bdDevice);
@@ -551,16 +513,7 @@ final class RemoteDevices {
                            break;
                        case AbstractionLayer.BT_PROPERTY_UUIDS:
                            int numUuids = val.length / AbstractionLayer.BT_UUID_SIZE;
                            final ParcelUuid[] newUuids = device.mUuids =
                                    Utils.byteArrayToUuid(val);
                            if (areUuidsEqual(newUuids, device.mUuids)) {
                                if (DBG) {
                                    Log.d(TAG, "Skip uuids update for "
                                            + bdDevice.getAddress());
                                }
                                break;
                            }
                            device.mUuids = newUuids;
                            device.mUuids = Utils.byteArrayToUuid(val);
                            if (sAdapterService.getState() == BluetoothAdapter.STATE_ON) {
                                sendUuidIntent(bdDevice);
                            }