Use BluetoothAdapter instead of LocalBluetoothAdapter
LocalBluetoothAdapter only has a few APIs that is not supported by BluetoothAdapter, and lots of LocalBluetoothAdapter function pass parameter to BluetoothAdapter directly. Do the refactor in Settings, use BluetoothAdapter instead of LocalBluetoothAdapter. Bug: 111769754 Test: make -j42 RunSettingsRoboTests Change-Id: I88e5a8377b5d1106c7679e6a8c3fd1ca1a80ea6f
This commit is contained in:
@@ -22,8 +22,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
/** Helper class, intended to be used by an Activity, to keep the local Bluetooth adapter in
|
||||
@@ -35,15 +33,15 @@ public class AlwaysDiscoverable extends BroadcastReceiver {
|
||||
private static final String TAG = "AlwaysDiscoverable";
|
||||
|
||||
private Context mContext;
|
||||
private LocalBluetoothAdapter mLocalAdapter;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private IntentFilter mIntentFilter;
|
||||
|
||||
@VisibleForTesting
|
||||
boolean mStarted;
|
||||
|
||||
public AlwaysDiscoverable(Context context, LocalBluetoothAdapter localAdapter) {
|
||||
public AlwaysDiscoverable(Context context) {
|
||||
mContext = context;
|
||||
mLocalAdapter = localAdapter;
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mIntentFilter = new IntentFilter();
|
||||
mIntentFilter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
|
||||
}
|
||||
@@ -56,8 +54,9 @@ public class AlwaysDiscoverable extends BroadcastReceiver {
|
||||
}
|
||||
mContext.registerReceiver(this, mIntentFilter);
|
||||
mStarted = true;
|
||||
if (mLocalAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||
mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
if (mBluetoothAdapter.getScanMode()
|
||||
!= BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||
mBluetoothAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +66,7 @@ public class AlwaysDiscoverable extends BroadcastReceiver {
|
||||
}
|
||||
mContext.unregisterReceiver(this);
|
||||
mStarted = false;
|
||||
mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
|
||||
mBluetoothAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,8 +75,9 @@ public class AlwaysDiscoverable extends BroadcastReceiver {
|
||||
if (action != BluetoothAdapter.ACTION_SCAN_MODE_CHANGED) {
|
||||
return;
|
||||
}
|
||||
if (mLocalAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||
mLocalAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
if (mBluetoothAdapter.getScanMode()
|
||||
!= BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||
mBluetoothAdapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user