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:
hughchen
2018-07-26 11:22:01 +08:00
parent 75bafefa49
commit e94b02206e
32 changed files with 327 additions and 341 deletions

View File

@@ -28,7 +28,6 @@ import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import java.util.Collection;
@@ -64,7 +63,7 @@ public abstract class DeviceListPreferenceFragment extends
BluetoothDevice mSelectedDevice;
LocalBluetoothAdapter mLocalAdapter;
BluetoothAdapter mBluetoothAdapter;
LocalBluetoothManager mLocalManager;
@VisibleForTesting
@@ -97,7 +96,7 @@ public abstract class DeviceListPreferenceFragment extends
Log.e(TAG, "Bluetooth is not supported on this device");
return;
}
mLocalAdapter = mLocalManager.getBluetoothAdapter();
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mShowDevicesWithoutNames = SystemProperties.getBoolean(
BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, false);
@@ -146,7 +145,7 @@ public abstract class DeviceListPreferenceFragment extends
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (KEY_BT_SCAN.equals(preference.getKey())) {
mLocalAdapter.startScanning(true);
startScanning();
return true;
}
@@ -172,7 +171,7 @@ public abstract class DeviceListPreferenceFragment extends
}
// Prevent updates while the list shows one of the state messages
if (mLocalAdapter.getBluetoothState() != BluetoothAdapter.STATE_ON) return;
if (mBluetoothAdapter.getState() != BluetoothAdapter.STATE_ON) return;
if (mFilter.matches(cachedDevice.getDevice())) {
createDevicePreference(cachedDevice);
@@ -214,7 +213,7 @@ public abstract class DeviceListPreferenceFragment extends
myDevicePreference.setTitle(getString(
R.string.bluetooth_footer_mac_message,
bidiFormatter.unicodeWrap(mLocalAdapter.getAddress())));
bidiFormatter.unicodeWrap(mBluetoothAdapter.getAddress())));
}
@Override
@@ -227,21 +226,21 @@ public abstract class DeviceListPreferenceFragment extends
@VisibleForTesting
void enableScanning() {
// LocalBluetoothAdapter already handles repeated scan requests
mLocalAdapter.startScanning(true);
// BluetoothAdapter already handles repeated scan requests
startScanning();
mScanEnabled = true;
}
@VisibleForTesting
void disableScanning() {
mLocalAdapter.stopScanning();
stopScanning();
mScanEnabled = false;
}
@Override
public void onScanningStateChanged(boolean started) {
if (!started && mScanEnabled) {
mLocalAdapter.startScanning(true);
startScanning();
}
}
@@ -287,4 +286,16 @@ public abstract class DeviceListPreferenceFragment extends
public boolean shouldShowDevicesWithoutNames() {
return mShowDevicesWithoutNames;
}
void startScanning() {
if (!mBluetoothAdapter.isDiscovering()) {
mBluetoothAdapter.startDiscovery();
}
}
void stopScanning() {
if (mBluetoothAdapter.isDiscovering()) {
mBluetoothAdapter.cancelDiscovery();
}
}
}