Refreshing Bluetooth devices will clear all available devices.

Bug: 16851309
Change-Id: I9ffb1ddaeb8e785be145ea79467fc361a022d8d7
This commit is contained in:
PauloftheWest
2014-08-11 06:18:32 -07:00
parent 898671f141
commit f42a0a27e3
3 changed files with 16 additions and 2 deletions

View File

@@ -249,6 +249,8 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
if (!mAvailableDevicesCategoryIsPresent) { if (!mAvailableDevicesCategoryIsPresent) {
getPreferenceScreen().addPreference(mAvailableDevicesCategory); getPreferenceScreen().addPreference(mAvailableDevicesCategory);
} }
mLocalManager.getCachedDeviceManager().clearCachedDevices();
mAvailableDevicesCategory.removeAll();
mLocalAdapter.startScanning(true); mLocalAdapter.startScanning(true);
} }
@@ -405,7 +407,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
LayoutInflater inflater = getActivity().getLayoutInflater(); LayoutInflater inflater = getActivity().getLayoutInflater();
mSettingsDialogView = inflater.inflate(R.layout.bluetooth_device_picker, null); mSettingsDialogView = inflater.inflate(R.layout.bluetooth_device_picker, null);
profileFrag = (DeviceProfilesSettings)activity.getFragmentManager() profileFrag = (DeviceProfilesSettings)activity.getFragmentManager()
.findFragmentById(R.id.bluetooth_fragment_settings); .findFragmentById(R.id.bluetooth_fragment_settings);
} }
final View dialogLayout = mSettingsDialogView; final View dialogLayout = mSettingsDialogView;

View File

@@ -86,7 +86,9 @@ final class CachedBluetoothDeviceManager {
BluetoothDevice device) { BluetoothDevice device) {
CachedBluetoothDevice newDevice = new CachedBluetoothDevice(mContext, adapter, CachedBluetoothDevice newDevice = new CachedBluetoothDevice(mContext, adapter,
profileManager, device); profileManager, device);
mCachedDevices.add(newDevice); synchronized (mCachedDevices) {
mCachedDevices.add(newDevice);
}
return newDevice; return newDevice;
} }
@@ -110,6 +112,10 @@ final class CachedBluetoothDeviceManager {
return device.getAddress(); return device.getAddress();
} }
public synchronized void clearCachedDevices() {
mCachedDevices.clear();
}
public synchronized void onScanningStateChanged(boolean started) { public synchronized void onScanningStateChanged(boolean started) {
if (!started) return; if (!started) return;

View File

@@ -167,6 +167,12 @@ public abstract class DeviceListPreferenceFragment extends
} }
void createDevicePreference(CachedBluetoothDevice cachedDevice) { void createDevicePreference(CachedBluetoothDevice cachedDevice) {
if (mDeviceListGroup == null) {
Log.w(TAG, "Trying to create a device preference before the list group/category "
+ "exists!");
return;
}
BluetoothDevicePreference preference = new BluetoothDevicePreference( BluetoothDevicePreference preference = new BluetoothDevicePreference(
getActivity(), cachedDevice); getActivity(), cachedDevice);