Make Bluetooth settings page can be discoverable
Bug: 118760361 Test: make -j42 RunSettingsRoboTests Change-Id: I2f663197f3c0f6c58529609845bab4dd7e714348
This commit is contained in:
@@ -46,6 +46,9 @@ public class BluetoothSwitchPreferenceController
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private FooterPreference mFooterPreference;
|
private FooterPreference mFooterPreference;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
AlwaysDiscoverable mAlwaysDiscoverable;
|
||||||
|
|
||||||
public BluetoothSwitchPreferenceController(Context context,
|
public BluetoothSwitchPreferenceController(Context context,
|
||||||
SwitchWidgetController switchController,
|
SwitchWidgetController switchController,
|
||||||
FooterPreference footerPreference) {
|
FooterPreference footerPreference) {
|
||||||
@@ -69,11 +72,13 @@ public class BluetoothSwitchPreferenceController
|
|||||||
SettingsEnums.ACTION_SETTINGS_MASTER_SWITCH_BLUETOOTH_TOGGLE,
|
SettingsEnums.ACTION_SETTINGS_MASTER_SWITCH_BLUETOOTH_TOGGLE,
|
||||||
mRestrictionUtils);
|
mRestrictionUtils);
|
||||||
mBluetoothEnabler.setToggleCallback(this);
|
mBluetoothEnabler.setToggleCallback(this);
|
||||||
|
mAlwaysDiscoverable = new AlwaysDiscoverable(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
mBluetoothEnabler.resume(mContext);
|
mBluetoothEnabler.resume(mContext);
|
||||||
|
mAlwaysDiscoverable.start();
|
||||||
if (mSwitch != null) {
|
if (mSwitch != null) {
|
||||||
updateText(mSwitch.isChecked());
|
updateText(mSwitch.isChecked());
|
||||||
}
|
}
|
||||||
@@ -82,6 +87,7 @@ public class BluetoothSwitchPreferenceController
|
|||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
mBluetoothEnabler.pause();
|
mBluetoothEnabler.pause();
|
||||||
|
mAlwaysDiscoverable.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.bluetooth;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -47,6 +48,8 @@ public class BluetoothSwitchPreferenceControllerTest {
|
|||||||
private RestrictionUtils mRestrictionUtils;
|
private RestrictionUtils mRestrictionUtils;
|
||||||
@Mock
|
@Mock
|
||||||
private SwitchWidgetController mSwitchController;
|
private SwitchWidgetController mSwitchController;
|
||||||
|
@Mock
|
||||||
|
private AlwaysDiscoverable mAlwaysDiscoverable;
|
||||||
|
|
||||||
private FooterPreference mFooterPreference;
|
private FooterPreference mFooterPreference;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@@ -62,6 +65,7 @@ public class BluetoothSwitchPreferenceControllerTest {
|
|||||||
mController =
|
mController =
|
||||||
new BluetoothSwitchPreferenceController(mContext, mRestrictionUtils,
|
new BluetoothSwitchPreferenceController(mContext, mRestrictionUtils,
|
||||||
mSwitchController, mFooterPreference);
|
mSwitchController, mFooterPreference);
|
||||||
|
mController.mAlwaysDiscoverable = mAlwaysDiscoverable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -103,4 +107,18 @@ public class BluetoothSwitchPreferenceControllerTest {
|
|||||||
|
|
||||||
assertThat(mFooterPreference.getTitle()).isEqualTo(BLUETOOTH_INFO_STRING);
|
assertThat(mFooterPreference.getTitle()).isEqualTo(BLUETOOTH_INFO_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onStart_shouldStartAlwaysDiscoverable() {
|
||||||
|
mController.onStart();
|
||||||
|
|
||||||
|
verify(mAlwaysDiscoverable).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onStop_shouldStopAlwaysDiscoverable() {
|
||||||
|
mController.onStop();
|
||||||
|
|
||||||
|
verify(mAlwaysDiscoverable).stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user