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:
@@ -18,11 +18,10 @@ package com.android.settings.deviceinfo;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
@@ -30,29 +29,25 @@ import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothAdapter.class})
|
||||
public class DeviceNamePreferenceControllerTest {
|
||||
private static final String TESTING_STRING = "Testing";
|
||||
|
||||
@Mock
|
||||
private LocalBluetoothAdapter mBluetoothAdapter;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private LocalBluetoothManager mBluetoothManager;
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
@@ -60,6 +55,7 @@ public class DeviceNamePreferenceControllerTest {
|
||||
private ValidatedEditTextPreference mPreference;
|
||||
private DeviceNamePreferenceController mController;
|
||||
private Context mContext;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
|
||||
|
||||
@Before
|
||||
@@ -69,14 +65,13 @@ public class DeviceNamePreferenceControllerTest {
|
||||
shadowApplication.setSystemService(Context.WIFI_SERVICE, mWifiManager);
|
||||
mContext = shadowApplication.getApplicationContext();
|
||||
mPreference = new ValidatedEditTextPreference(mContext);
|
||||
when(mBluetoothManager.getBluetoothAdapter()).thenReturn(mBluetoothAdapter);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
final WifiConfiguration configuration = new WifiConfiguration();
|
||||
configuration.SSID = "test-ap";
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(configuration);
|
||||
|
||||
mController = new DeviceNamePreferenceController(mContext);
|
||||
mController.setLocalBluetoothManager(mBluetoothManager);
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,7 +84,6 @@ public class DeviceNamePreferenceControllerTest {
|
||||
Settings.Global.putString(
|
||||
mContext.getContentResolver(), Settings.Global.DEVICE_NAME, "Test");
|
||||
mController = new DeviceNamePreferenceController(mContext);
|
||||
mController.setLocalBluetoothManager(mBluetoothManager);
|
||||
assertThat(mController.getSummary()).isEqualTo("Test");
|
||||
}
|
||||
|
||||
@@ -118,7 +112,7 @@ public class DeviceNamePreferenceControllerTest {
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPreferenceChange(mPreference, TESTING_STRING);
|
||||
|
||||
verify(mBluetoothAdapter).setName(eq(TESTING_STRING));
|
||||
assertThat(mBluetoothAdapter.getName()).isEqualTo(TESTING_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,10 +135,11 @@ public class DeviceNamePreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void setDeviceName_ignoresIfCancelPressed() {
|
||||
forceAcceptDeviceName();
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPreferenceChange(mPreference, TESTING_STRING);
|
||||
|
||||
verify(mBluetoothAdapter, never()).setName(eq(TESTING_STRING));
|
||||
assertThat(mBluetoothAdapter.getName()).isEqualTo(TESTING_STRING);
|
||||
}
|
||||
|
||||
private void forceAcceptDeviceName() {
|
||||
|
||||
Reference in New Issue
Block a user