Handle class and name changed actions with DeviceFound signals.
When the class or name of a device changed, due to name resolution or otherwise, we were not updating the cache.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import android.bluetooth.BluetoothA2dp;
|
||||
import android.bluetooth.BluetoothClass;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothError;
|
||||
import android.bluetooth.BluetoothHeadset;
|
||||
@@ -62,7 +63,9 @@ public class BluetoothEventRedirector {
|
||||
|
||||
} else if (action.equals(BluetoothIntent.REMOTE_DEVICE_FOUND_ACTION)) {
|
||||
short rssi = intent.getShortExtra(BluetoothIntent.RSSI, Short.MIN_VALUE);
|
||||
mManager.getLocalDeviceManager().onDeviceAppeared(address, rssi);
|
||||
int btClass = intent.getIntExtra(BluetoothIntent.CLASS, BluetoothClass.ERROR);
|
||||
String name = intent.getStringExtra(BluetoothIntent.NAME);
|
||||
mManager.getLocalDeviceManager().onDeviceAppeared(address, rssi, btClass, name);
|
||||
|
||||
} else if (action.equals(BluetoothIntent.REMOTE_DEVICE_DISAPPEARED_ACTION)) {
|
||||
mManager.getLocalDeviceManager().onDeviceDisappeared(address);
|
||||
|
@@ -494,6 +494,17 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
||||
return mName;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
if (!mName.equals(name)) {
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
mName = mAddress;
|
||||
} else {
|
||||
mName = name;
|
||||
}
|
||||
dispatchAttributesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshName() {
|
||||
fetchName();
|
||||
dispatchAttributesChanged();
|
||||
@@ -607,6 +618,14 @@ public class LocalBluetoothDevice implements Comparable<LocalBluetoothDevice> {
|
||||
dispatchAttributesChanged();
|
||||
}
|
||||
|
||||
public void setBtClass(int btClass) {
|
||||
if (mBtClass != btClass && btClass != BluetoothClass.ERROR) {
|
||||
mBtClass = btClass;
|
||||
LocalBluetoothProfileManager.fill(mBtClass, mProfiles);
|
||||
dispatchAttributesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public int getSummary() {
|
||||
// TODO: clean up
|
||||
int oneOffSummary = getOneOffSummary();
|
||||
|
@@ -72,7 +72,8 @@ public class LocalBluetoothDeviceManager {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void onDeviceAppeared(String address, short rssi) {
|
||||
public synchronized void onDeviceAppeared(String address, short rssi, int btClass,
|
||||
String name) {
|
||||
boolean deviceAdded = false;
|
||||
|
||||
LocalBluetoothDevice device = findDevice(address);
|
||||
@@ -83,6 +84,8 @@ public class LocalBluetoothDeviceManager {
|
||||
}
|
||||
|
||||
device.setRssi(rssi);
|
||||
device.setBtClass(btClass);
|
||||
device.setName(name);
|
||||
device.setVisible(true);
|
||||
|
||||
if (deviceAdded) {
|
||||
|
Reference in New Issue
Block a user