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

@@ -27,8 +27,6 @@ import android.util.Log;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
@@ -46,8 +44,7 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
@VisibleForTesting
Preference mPreference;
private LocalBluetoothManager mLocalManager;
protected LocalBluetoothAdapter mLocalAdapter;
protected BluetoothAdapter mBluetoothAdapter;
/**
* Constructor exclusively used for Slice.
@@ -55,19 +52,11 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
public BluetoothDeviceNamePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
mLocalManager = Utils.getLocalBtManager(context);
if (mLocalManager == null) {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
Log.e(TAG, "Bluetooth is not supported on this device");
return;
}
mLocalAdapter = mLocalManager.getBluetoothAdapter();
}
@VisibleForTesting
BluetoothDeviceNamePreferenceController(Context context, LocalBluetoothAdapter localAdapter,
String preferenceKey) {
super(context, preferenceKey);
mLocalAdapter = localAdapter;
}
@Override
@@ -91,7 +80,7 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
@Override
public int getAvailabilityStatus() {
return mLocalAdapter != null ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
return mBluetoothAdapter != null ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
@@ -138,7 +127,7 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
}
protected String getDeviceName() {
return mLocalAdapter.getName();
return mBluetoothAdapter.getName();
}
/**
@@ -152,7 +141,8 @@ public class BluetoothDeviceNamePreferenceController extends BasePreferenceContr
final String action = intent.getAction();
if (TextUtils.equals(action, BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED)) {
if (mPreference != null && mLocalAdapter != null && mLocalAdapter.isEnabled()) {
if (mPreference != null && mBluetoothAdapter != null
&& mBluetoothAdapter.isEnabled()) {
updatePreferenceState(mPreference);
}
} else if (TextUtils.equals(action, BluetoothAdapter.ACTION_STATE_CHANGED)) {