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

Commit 8df81e3e authored by hughchen's avatar hughchen
Browse files

Remove the local cached BluetoothClass

Use BluetoothDevice.getBluetoothClass() to get the cached Bluetooth class
instead of use mBtClass that is local cached.

Bug: 112517004
Test: make -j42 RunSettingsLibRoboTests ROBOTEST_FILTER=CachedBluetoothDeviceTest
Change-Id: I48b974e7ac4e813b498cea0257253f02b4c07dd2
parent cb6e197e
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -276,7 +276,6 @@ public class BluetoothEventManager {
        public void onReceive(Context context, Intent intent,
                BluetoothDevice device) {
            short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE);
            BluetoothClass btClass = intent.getParcelableExtra(BluetoothDevice.EXTRA_CLASS);
            String name = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
            // TODO Pick up UUID. They should be available for 2.1 devices.
            // Skip for now, there's a bluez problem and we are not getting uuids even for 2.1.
@@ -287,7 +286,6 @@ public class BluetoothEventManager {
                        + cachedDevice);
            }
            cachedDevice.setRssi(rssi);
            cachedDevice.setBtClass(btClass);
            cachedDevice.setJustDiscovered(true);
        }
    }
+2 −28
Original line number Diff line number Diff line
@@ -54,8 +54,6 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
    private long mHiSyncId;
    // Need this since there is no method for getting RSSI
    private short mRssi;
    //TODO: consider remove, BluetoothDevice.getBluetoothClass() is already cached
    private BluetoothClass mBtClass;
    private HashMap<LocalBluetoothProfile, Integer> mProfileConnectionState;

    private final List<LocalBluetoothProfile> mProfiles =
@@ -374,7 +372,6 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>

    // TODO: do any of these need to run async on a background thread?
    private void fillData() {
        fetchBtClass();
        updateProfiles();
        fetchActiveDevices();
        migratePhonebookPermissionChoice();
@@ -587,13 +584,6 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        return getBondState() == BluetoothDevice.BOND_BONDING;
    }

    /**
     * Fetches a new value for the cached BT class.
     */
    private void fetchBtClass() {
        mBtClass = mDevice.getBluetoothClass();
    }

    private boolean updateProfiles() {
        ParcelUuid[] uuids = mDevice.getUuids();
        if (uuids == null) return false;
@@ -637,15 +627,6 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        }
    }

    /**
     * Refreshes the UI for the BT class, including fetching the latest value
     * for the class.
     */
    void refreshBtClass() {
        fetchBtClass();
        dispatchAttributesChanged();
    }

    /**
     * Refreshes the UI when framework alerts us of a UUID change.
     */
@@ -696,15 +677,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        }
    }

    void setBtClass(BluetoothClass btClass) {
        if (btClass != null && mBtClass != btClass) {
            mBtClass = btClass;
            dispatchAttributesChanged();
        }
    }

    public BluetoothClass getBtClass() {
        return mBtClass;
        return mDevice.getBluetoothClass();
    }

    public List<LocalBluetoothProfile> getProfiles() {
@@ -738,7 +712,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        }
    }

    private void dispatchAttributesChanged() {
    void dispatchAttributesChanged() {
        synchronized (mCallbacks) {
            for (Callback callback : mCallbacks) {
                callback.onDeviceAttributesChanged();
+1 −1
Original line number Diff line number Diff line
@@ -260,7 +260,7 @@ public class CachedBluetoothDeviceManager {
    public synchronized void onBtClassChanged(BluetoothDevice device) {
        CachedBluetoothDevice cachedDevice = findDevice(device);
        if (cachedDevice != null) {
            cachedDevice.refreshBtClass();
            cachedDevice.dispatchAttributesChanged();
        }
    }