Merge "BT: Don't display previously connected devices in BLE_ON" into q-keystone-qcom-dev
diff --git a/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceController.java b/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceController.java
index 5b23d69..b74c79d 100644
--- a/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceController.java
+++ b/src/com/android/settings/connecteddevice/PreviouslyConnectedDevicePreferenceController.java
@@ -22,7 +22,13 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
+import android.bluetooth.BluetoothAdapter;
+import com.android.settingslib.bluetooth.BluetoothCallback;
+import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.bluetooth.CachedBluetoothDevice;
+import com.android.settings.bluetooth.Utils;
import com.android.settings.bluetooth.BluetoothDeviceUpdater;
import com.android.settings.bluetooth.SavedBluetoothDeviceUpdater;
import com.android.settings.connecteddevice.dock.DockUpdater;
@@ -34,11 +40,13 @@
import com.android.settingslib.core.lifecycle.events.OnStop;
public class PreviouslyConnectedDevicePreferenceController extends BasePreferenceController
- implements LifecycleObserver, OnStart, OnStop, DevicePreferenceCallback {
+ implements LifecycleObserver, OnStart, OnStop, DevicePreferenceCallback, BluetoothCallback {
private static final int MAX_DEVICE_NUM = 3;
private PreferenceGroup mPreferenceGroup;
+ private LocalBluetoothAdapter mLocalAdapter;
+ private LocalBluetoothManager manager;
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
private DockUpdater mSavedDockUpdater;
private int mPreferenceSize;
@@ -48,6 +56,10 @@
mSavedDockUpdater = FeatureFactory.getFactory(
context).getDockUpdaterFeatureProvider().getSavedDockUpdater(context, this);
+ manager = Utils.getLocalBtManager(context);
+ if ( manager != null) {
+ mLocalAdapter = manager.getBluetoothAdapter();
+ }
}
@Override
@@ -75,12 +87,15 @@
public void onStart() {
mBluetoothDeviceUpdater.registerCallback();
mSavedDockUpdater.registerCallback();
+ manager.getEventManager().registerCallback(this);
}
@Override
public void onStop() {
mBluetoothDeviceUpdater.unregisterCallback();
mSavedDockUpdater.unregisterCallback();
+ manager.getEventManager().unregisterCallback(this);
+
}
public void init(DashboardFragment fragment) {
@@ -104,6 +119,46 @@
updatePreferenceVisiblity();
}
+ @Override
+ public void onBluetoothStateChanged(int bluetoothState) {
+ updatePreferenceVisiblity();
+ }
+
+ @Override
+ public void onScanningStateChanged(boolean started) {
+ // do nothing
+ }
+
+ @Override
+ public void onDeviceAdded(CachedBluetoothDevice cachedDevice) {
+ // do nothing
+ }
+
+ @Override
+ public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) {
+ // do nothing
+ }
+
+ @Override
+ public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
+ // do nothing
+ }
+
+ @Override
+ public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
+ // do nothing
+ }
+
+ @Override
+ public void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) {
+ // do nothing
+ }
+
+ @Override
+ public void onAudioModeChanged() {
+ // do nothing
+ }
+
@VisibleForTesting
void setBluetoothDeviceUpdater(BluetoothDeviceUpdater bluetoothDeviceUpdater) {
mBluetoothDeviceUpdater = bluetoothDeviceUpdater;
@@ -121,6 +176,12 @@
@VisibleForTesting
void updatePreferenceVisiblity() {
- mPreferenceGroup.setVisible(mPreferenceSize > 0);
+ if ((mLocalAdapter != null) &&
+ (mLocalAdapter.getBluetoothState() == BluetoothAdapter.STATE_ON)) {
+ mPreferenceGroup.setVisible(mPreferenceSize > 0);
+ } else {
+ mPreferenceGroup.setVisible(false);
+ }
}
+
}