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

Bug: 6079494

(cherry picked from commit 5fb53f36cb77c3d924b3fe5c305ce7d082ecdfb8)

Change-Id: Ia0d3a638f93c7c7923ce6e85f3555af0aeda96f9
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index 6899bc3..7c8cb6e 100755
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -138,21 +138,26 @@
     public void onResume() {
         // resume BluetoothEnabler before calling super.onResume() so we don't get
         // any onDeviceAdded() callbacks before setting up view in updateContent()
-        mBluetoothEnabler.resume();
+        if (mBluetoothEnabler != null) {
+            mBluetoothEnabler.resume();
+        }
         super.onResume();
 
         if (mDiscoverableEnabler != null) {
             mDiscoverableEnabler.resume();
         }
         getActivity().registerReceiver(mReceiver, mIntentFilter);
-
-        updateContent(mLocalAdapter.getBluetoothState(), mActivityStarted);
+        if (mLocalAdapter != null) {
+            updateContent(mLocalAdapter.getBluetoothState(), mActivityStarted);
+        }
     }
 
     @Override
     public void onPause() {
         super.onPause();
-        mBluetoothEnabler.pause();
+        if (mBluetoothEnabler != null) {
+            mBluetoothEnabler.pause();
+        }
         getActivity().unregisterReceiver(mReceiver);
         if (mDiscoverableEnabler != null) {
             mDiscoverableEnabler.pause();
@@ -161,6 +166,7 @@
 
     @Override
     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+        if (mLocalAdapter == null) return;
         boolean bluetoothIsEnabled = mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON;
         boolean isDiscovering = mLocalAdapter.isDiscovering();
         int textId = isDiscovering ? R.string.bluetooth_searching_for_devices :
diff --git a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
index 061f2c9..90f8de5 100644
--- a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
+++ b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
@@ -96,6 +96,7 @@
     @Override
     public void onResume() {
         super.onResume();
+        if (mLocalManager == null) return;
 
         mLocalManager.setForegroundActivity(getActivity());
         mLocalManager.getEventManager().registerCallback(this);
@@ -106,6 +107,8 @@
     @Override
     public void onPause() {
         super.onPause();
+        if (mLocalManager == null) return;
+
         removeAllDevices();
         mLocalManager.setForegroundActivity(null);
         mLocalManager.getEventManager().unregisterCallback(this);