RESTRICT AUTOMERGE Fix make Bluetooth discoverable without additional permission
- Only enable device can be discoverable when the user launch
"Connected Devices settings" through settings and systemui
Bug: 194695497
Test: make -j42 RunSettingsRoboTests and use test apk to manually test
to verify the device is not discoversable when open "Connected settings"
through test apk.
Change-Id: Ia04ab759b737acf30b782f5c5831dd59f25fb257
(cherry picked from commit d3abbb9821
)
This commit is contained in:
@@ -18,6 +18,7 @@ package com.android.settings.connecteddevice;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -104,7 +105,8 @@ public class DiscoverableFooterPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldRegisterBluetoothChanged() {
|
||||
public void onStart_setAlwaysDiscoverableAsTrue_shouldRegisterBluetoothChanged() {
|
||||
mDiscoverableFooterPreferenceController.setAlwaysDiscoverable(true);
|
||||
mDiscoverableFooterPreferenceController.onStart();
|
||||
|
||||
assertThat(getRegisteredBroadcastReceivers()).contains(mBluetoothChangedReceiver);
|
||||
@@ -112,7 +114,8 @@ public class DiscoverableFooterPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStop_shouldUnregisterBluetoothChanged() {
|
||||
public void onStop_setAlwaysDiscoverableAsTrue_shouldUnregisterBluetoothChanged() {
|
||||
mDiscoverableFooterPreferenceController.setAlwaysDiscoverable(true);
|
||||
mDiscoverableFooterPreferenceController.onStart();
|
||||
mDiscoverableFooterPreferenceController.onStop();
|
||||
|
||||
@@ -120,6 +123,25 @@ public class DiscoverableFooterPreferenceControllerTest {
|
||||
verify(mAlwaysDiscoverable).stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_setAlwaysDiscoverableAsFalse_shouldNotRegisterBluetoothChanged() {
|
||||
mDiscoverableFooterPreferenceController.setAlwaysDiscoverable(false);
|
||||
mDiscoverableFooterPreferenceController.onStart();
|
||||
|
||||
assertThat(getRegisteredBroadcastReceivers()).contains(mBluetoothChangedReceiver);
|
||||
verify(mAlwaysDiscoverable, never()).start();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStop_setAlwaysDiscoverableAsFalse_shouldNotUnregisterBluetoothChanged() {
|
||||
mDiscoverableFooterPreferenceController.setAlwaysDiscoverable(false);
|
||||
mDiscoverableFooterPreferenceController.onStart();
|
||||
mDiscoverableFooterPreferenceController.onStop();
|
||||
|
||||
assertThat(getRegisteredBroadcastReceivers()).doesNotContain(mBluetoothChangedReceiver);
|
||||
verify(mAlwaysDiscoverable, never()).stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBluetoothStateChanged_bluetoothOn_updateTitle() {
|
||||
BluetoothAdapter.getDefaultAdapter().setName(DEVICE_NAME);
|
||||
|
Reference in New Issue
Block a user