Don't crash if there's no bluetooth functionality (such as in an emulator)

Bug: 6079494
Change-Id: I12f729134407eaa719dc6a25e89a3b48476985e2
This commit is contained in:
Amith Yamasani
2012-02-27 17:09:37 -08:00
parent fffd9f0b11
commit 5fb53f36cb
2 changed files with 13 additions and 4 deletions

View File

@@ -138,21 +138,26 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
public void onResume() { public void onResume() {
// resume BluetoothEnabler before calling super.onResume() so we don't get // resume BluetoothEnabler before calling super.onResume() so we don't get
// any onDeviceAdded() callbacks before setting up view in updateContent() // any onDeviceAdded() callbacks before setting up view in updateContent()
if (mBluetoothEnabler != null) {
mBluetoothEnabler.resume(); mBluetoothEnabler.resume();
}
super.onResume(); super.onResume();
if (mDiscoverableEnabler != null) { if (mDiscoverableEnabler != null) {
mDiscoverableEnabler.resume(); mDiscoverableEnabler.resume();
} }
getActivity().registerReceiver(mReceiver, mIntentFilter); getActivity().registerReceiver(mReceiver, mIntentFilter);
if (mLocalAdapter != null) {
updateContent(mLocalAdapter.getBluetoothState(), mActivityStarted); updateContent(mLocalAdapter.getBluetoothState(), mActivityStarted);
} }
}
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
if (mBluetoothEnabler != null) {
mBluetoothEnabler.pause(); mBluetoothEnabler.pause();
}
getActivity().unregisterReceiver(mReceiver); getActivity().unregisterReceiver(mReceiver);
if (mDiscoverableEnabler != null) { if (mDiscoverableEnabler != null) {
mDiscoverableEnabler.pause(); mDiscoverableEnabler.pause();
@@ -161,6 +166,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment {
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (mLocalAdapter == null) return;
boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON; boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON;
boolean isDiscovering = mLocalAdapter.isDiscovering(); boolean isDiscovering = mLocalAdapter.isDiscovering();
int textId = isDiscovering ? R.string.bluetooth_searching_for_devices : int textId = isDiscovering ? R.string.bluetooth_searching_for_devices :

View File

@@ -96,6 +96,7 @@ public abstract class DeviceListPreferenceFragment extends
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (mLocalManager == null) return;
mLocalManager.setForegroundActivity(getActivity()); mLocalManager.setForegroundActivity(getActivity());
mLocalManager.getEventManager().registerCallback(this); mLocalManager.getEventManager().registerCallback(this);
@@ -106,6 +107,8 @@ public abstract class DeviceListPreferenceFragment extends
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
if (mLocalManager == null) return;
removeAllDevices(); removeAllDevices();
mLocalManager.setForegroundActivity(null); mLocalManager.setForegroundActivity(null);
mLocalManager.getEventManager().unregisterCallback(this); mLocalManager.getEventManager().unregisterCallback(this);