Bluetooth : fix for unnecessary device-scan starting

- When trying to pair with any device, if bond state changes
  device scan will be started automatically.

- add some flag to check proper scan time and to prevent unnecessary device scanning.

Signed-off-by: jhtop.kim <jhtop.kim@samsung.com>

Change-Id: I4977ec122105f33cdd25a4f5c9fed59dda916379
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index 4b86a74..9f56f32 100644
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -68,6 +68,7 @@
 
     private PreferenceGroup mAvailableDevicesCategory;
     private boolean mAvailableDevicesCategoryIsPresent;
+    private boolean mActivityStarted;
 
     private TextView mEmptyView;
 
@@ -98,6 +99,7 @@
 
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
+        mActivityStarted = true;
         super.onActivityCreated(savedInstanceState);
 
         mEmptyView = (TextView) getView().findViewById(android.R.id.empty);
@@ -144,7 +146,7 @@
         }
         getActivity().registerReceiver(mReceiver, mIntentFilter);
 
-        updateContent(mLocalAdapter.getBluetoothState());
+        updateContent(mLocalAdapter.getBluetoothState(), mActivityStarted);
     }
 
     @Override
@@ -226,7 +228,7 @@
         preferenceGroup.setEnabled(true);
     }
 
-    private void updateContent(int bluetoothState) {
+    private void updateContent(int bluetoothState, boolean scanState) {
         final PreferenceScreen preferenceScreen = getPreferenceScreen();
         int messageId = 0;
 
@@ -289,7 +291,14 @@
 
                 if (numberOfPairedDevices == 0) {
                     preferenceScreen.removePreference(mPairedDevicesCategory);
-                    startScanning();
+                    if (scanState == true) {
+                        mActivityStarted = false;
+                        startScanning();
+                    } else {
+                        if (!mAvailableDevicesCategoryIsPresent) {
+                            getPreferenceScreen().addPreference(mAvailableDevicesCategory);
+                        }
+                    }
                 }
                 getActivity().invalidateOptionsMenu();
                 return; // not break
@@ -316,7 +325,7 @@
     @Override
     public void onBluetoothStateChanged(int bluetoothState) {
         super.onBluetoothStateChanged(bluetoothState);
-        updateContent(bluetoothState);
+        updateContent(bluetoothState, true);
     }
 
     @Override
@@ -329,7 +338,7 @@
     public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
         setDeviceListGroup(getPreferenceScreen());
         removeAllDevices();
-        updateContent(mLocalAdapter.getBluetoothState());
+        updateContent(mLocalAdapter.getBluetoothState(), false);
     }
 
     private final View.OnClickListener mDeviceProfilesListener = new View.OnClickListener() {