Turning Bluetooth on will make the device discoverable.

Bug: 17368189
Change-Id: Ic526fb1ff9dcc15e6fe1db055a471cc570b6a2e1
This commit is contained in:
PauloftheWest
2014-09-04 14:45:40 -07:00
parent ebe496ea7b
commit 469c812878

View File

@@ -83,6 +83,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
private boolean mAvailableDevicesCategoryIsPresent; private boolean mAvailableDevicesCategoryIsPresent;
private boolean mInitialScanStarted; private boolean mInitialScanStarted;
private boolean mInitiateDiscoverable;
private TextView mEmptyView; private TextView mEmptyView;
private SwitchBar mSwitchBar; private SwitchBar mSwitchBar;
@@ -119,6 +120,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
mInitialScanStarted = (savedInstanceState != null); // don't auto start scan after rotation mInitialScanStarted = (savedInstanceState != null); // don't auto start scan after rotation
mInitiateDiscoverable = true;
mEmptyView = (TextView) getView().findViewById(android.R.id.empty); mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
getListView().setEmptyView(mEmptyView); getListView().setEmptyView(mEmptyView);
@@ -153,8 +155,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
} }
super.onResume(); super.onResume();
// Make the device visible to other devices. mInitiateDiscoverable = true;
mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
if (isUiRestricted()) { if (isUiRestricted()) {
setDeviceListGroup(getPreferenceScreen()); setDeviceListGroup(getPreferenceScreen());
@@ -325,6 +326,14 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
preferenceScreen.addPreference(mMyDevicePreference); preferenceScreen.addPreference(mMyDevicePreference);
getActivity().invalidateOptionsMenu(); getActivity().invalidateOptionsMenu();
// mLocalAdapter.setScanMode is internally synchronized so it is okay for multiple
// threads to execute.
if (mInitiateDiscoverable) {
// Make the device visible to other devices.
mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
mInitiateDiscoverable = false;
}
return; // not break return; // not break
case BluetoothAdapter.STATE_TURNING_OFF: case BluetoothAdapter.STATE_TURNING_OFF: