Fix crash when no Bluetooth feature in Settings

- Move PreferenceGroup init method out of isAvailable() condition,
  then PreferenceGroup will not be null.
- Update getAvailabilityStatus(), since the controller now may have usb
  and dock.

Bug: 110712414
Test: make -j42 RunSettingsRoboTests
Change-Id: I4d85a42c26fb20d319e7321177b271933be3fdb0
This commit is contained in:
hughchen
2019-04-17 15:43:22 +08:00
parent 96b534951c
commit ef2c1a1526
8 changed files with 94 additions and 14 deletions

View File

@@ -23,6 +23,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -81,6 +82,7 @@ public class SavedDeviceGroupControllerTest {
verify(mBluetoothDeviceUpdater).registerCallback();
verify(mSavedDockUpdater).registerCallback();
}
@Test
public void testUnregister() {
// unregister the callback in onStop()
@@ -88,16 +90,30 @@ public class SavedDeviceGroupControllerTest {
verify(mBluetoothDeviceUpdater).unregisterCallback();
verify(mSavedDockUpdater).unregisterCallback();
}
@Test
public void testGetAvailabilityStatus_noBluetoothFeature_returnUnSupported() {
public void testGetAvailabilityStatus_noBluetoothDockFeature_returnUnSupported() {
doReturn(false).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
mSavedDeviceGroupController.setSavedDockUpdater(null);
assertThat(mSavedDeviceGroupController.getAvailabilityStatus()).isEqualTo(
UNSUPPORTED_ON_DEVICE);
}
@Test
public void testGetAvailabilityStatus_BluetoothFeature_returnSupported() {
doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
mSavedDeviceGroupController.setSavedDockUpdater(null);
assertThat(mSavedDeviceGroupController.getAvailabilityStatus()).isEqualTo(
AVAILABLE);
}
@Test
public void getAvailabilityStatus_haveDockFeature_returnSupported() {
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)).thenReturn(false);
assertThat(mSavedDeviceGroupController.getAvailabilityStatus()).isEqualTo(
AVAILABLE);
}
}