Loading src/com/android/settings/bluetooth/BluetoothDevicePreference.java +4 −5 Original line number Diff line number Diff line Loading @@ -52,19 +52,19 @@ public final class BluetoothDevicePreference extends GearPreference implements private final CachedBluetoothDevice mCachedDevice; private final UserManager mUserManager; private final boolean mShowDevicesWithoutNames; private AlertDialog mDisconnectDialog; private String contentDescription = null; private DeviceListPreferenceFragment mDeviceListPreferenceFragment; /* Talk-back descriptions for various BT icons */ Resources mResources; public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice, DeviceListPreferenceFragment deviceListPreferenceFragment) { boolean showDeviceWithoutNames) { super(context, null); mResources = getContext().getResources(); mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); mDeviceListPreferenceFragment = deviceListPreferenceFragment; mShowDevicesWithoutNames = showDeviceWithoutNames; if (sDimAlpha == Integer.MIN_VALUE) { TypedValue outValue = new TypedValue(); Loading Loading @@ -134,8 +134,7 @@ public final class BluetoothDevicePreference extends GearPreference implements // Device is only visible in the UI if it has a valid name besides MAC address or when user // allows showing devices without user-friendly name in developer settings setVisible(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames() || mCachedDevice.hasHumanReadableName()); setVisible(mShowDevicesWithoutNames || mCachedDevice.hasHumanReadableName()); // This could affect ordering, so notify that notifyHierarchyChanged(); Loading src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java +4 −3 Original line number Diff line number Diff line Loading @@ -98,6 +98,8 @@ public abstract class DeviceListPreferenceFragment extends return; } mLocalAdapter = mLocalManager.getBluetoothAdapter(); mShowDevicesWithoutNames = SystemProperties.getBoolean( BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, false); initPreferencesFromPreferenceScreen(); Loading @@ -110,8 +112,6 @@ public abstract class DeviceListPreferenceFragment extends @Override public void onStart() { super.onStart(); mShowDevicesWithoutNames = SystemProperties.getBoolean( BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, false); if (mLocalManager == null || isUiRestricted()) return; mLocalManager.setForegroundActivity(getActivity()); Loading Loading @@ -190,7 +190,8 @@ public abstract class DeviceListPreferenceFragment extends BluetoothDevicePreference preference = (BluetoothDevicePreference) getCachedPreference(key); if (preference == null) { preference = new BluetoothDevicePreference(getPrefContext(), cachedDevice, this); preference = new BluetoothDevicePreference(getPrefContext(), cachedDevice, mShowDevicesWithoutNames); preference.setKey(key); mDeviceListGroup.addPreference(preference); } else { Loading tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java +11 −34 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import org.robolectric.util.ReflectionHelpers; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; Loading @@ -51,6 +52,7 @@ import static org.mockito.Mockito.when; @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = SettingsShadowResources.class) public class BluetoothDevicePreferenceTest { private static final boolean SHOW_DEVICES_WITHOUT_NAMES = true; private Context mContext; @Mock Loading @@ -70,7 +72,7 @@ public class BluetoothDevicePreferenceTest { mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider(); mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, mDeviceListPreferenceFragment); SHOW_DEVICES_WITHOUT_NAMES); } @Test Loading Loading @@ -177,47 +179,22 @@ public class BluetoothDevicePreferenceTest { } @Test public void testVisible_notVisibleThenVisible() { when(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()).thenReturn(false); final boolean[] humanReadableName = {false}; doAnswer(invocation -> humanReadableName[0]).when(mCachedBluetoothDevice) .hasHumanReadableName(); public void testVisible_showDeviceWithoutNames_visible() { doReturn(false).when(mCachedBluetoothDevice).hasHumanReadableName(); BluetoothDevicePreference preference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, mDeviceListPreferenceFragment); assertThat(preference.isVisible()).isFalse(); humanReadableName[0] = true; preference.onDeviceAttributesChanged(); assertThat(preference.isVisible()).isTrue(); } SHOW_DEVICES_WITHOUT_NAMES); @Test public void testVisible_visibleThenNotVisible() { when(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()).thenReturn(false); final boolean[] humanReadableName = {true}; doAnswer(invocation -> humanReadableName[0]).when(mCachedBluetoothDevice) .hasHumanReadableName(); BluetoothDevicePreference preference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, mDeviceListPreferenceFragment); assertThat(preference.isVisible()).isTrue(); humanReadableName[0] = false; preference.onDeviceAttributesChanged(); assertThat(preference.isVisible()).isFalse(); } @Test public void testVisible_alwaysVisibleWhenEnabled() { when(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()).thenReturn(true); final boolean[] humanReadableName = {true}; doAnswer(invocation -> humanReadableName[0]).when(mCachedBluetoothDevice) .hasHumanReadableName(); public void testVisible_hideDeviceWithoutNames_invisible() { doReturn(false).when(mCachedBluetoothDevice).hasHumanReadableName(); BluetoothDevicePreference preference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, mDeviceListPreferenceFragment); assertThat(preference.isVisible()).isTrue(); humanReadableName[0] = false; preference.onDeviceAttributesChanged(); assertThat(preference.isVisible()).isTrue(); false); assertThat(preference.isVisible()).isFalse(); } } Loading
src/com/android/settings/bluetooth/BluetoothDevicePreference.java +4 −5 Original line number Diff line number Diff line Loading @@ -52,19 +52,19 @@ public final class BluetoothDevicePreference extends GearPreference implements private final CachedBluetoothDevice mCachedDevice; private final UserManager mUserManager; private final boolean mShowDevicesWithoutNames; private AlertDialog mDisconnectDialog; private String contentDescription = null; private DeviceListPreferenceFragment mDeviceListPreferenceFragment; /* Talk-back descriptions for various BT icons */ Resources mResources; public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice, DeviceListPreferenceFragment deviceListPreferenceFragment) { boolean showDeviceWithoutNames) { super(context, null); mResources = getContext().getResources(); mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); mDeviceListPreferenceFragment = deviceListPreferenceFragment; mShowDevicesWithoutNames = showDeviceWithoutNames; if (sDimAlpha == Integer.MIN_VALUE) { TypedValue outValue = new TypedValue(); Loading Loading @@ -134,8 +134,7 @@ public final class BluetoothDevicePreference extends GearPreference implements // Device is only visible in the UI if it has a valid name besides MAC address or when user // allows showing devices without user-friendly name in developer settings setVisible(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames() || mCachedDevice.hasHumanReadableName()); setVisible(mShowDevicesWithoutNames || mCachedDevice.hasHumanReadableName()); // This could affect ordering, so notify that notifyHierarchyChanged(); Loading
src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java +4 −3 Original line number Diff line number Diff line Loading @@ -98,6 +98,8 @@ public abstract class DeviceListPreferenceFragment extends return; } mLocalAdapter = mLocalManager.getBluetoothAdapter(); mShowDevicesWithoutNames = SystemProperties.getBoolean( BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, false); initPreferencesFromPreferenceScreen(); Loading @@ -110,8 +112,6 @@ public abstract class DeviceListPreferenceFragment extends @Override public void onStart() { super.onStart(); mShowDevicesWithoutNames = SystemProperties.getBoolean( BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY, false); if (mLocalManager == null || isUiRestricted()) return; mLocalManager.setForegroundActivity(getActivity()); Loading Loading @@ -190,7 +190,8 @@ public abstract class DeviceListPreferenceFragment extends BluetoothDevicePreference preference = (BluetoothDevicePreference) getCachedPreference(key); if (preference == null) { preference = new BluetoothDevicePreference(getPrefContext(), cachedDevice, this); preference = new BluetoothDevicePreference(getPrefContext(), cachedDevice, mShowDevicesWithoutNames); preference.setKey(key); mDeviceListGroup.addPreference(preference); } else { Loading
tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java +11 −34 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import org.robolectric.util.ReflectionHelpers; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; Loading @@ -51,6 +52,7 @@ import static org.mockito.Mockito.when; @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = SettingsShadowResources.class) public class BluetoothDevicePreferenceTest { private static final boolean SHOW_DEVICES_WITHOUT_NAMES = true; private Context mContext; @Mock Loading @@ -70,7 +72,7 @@ public class BluetoothDevicePreferenceTest { mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext); mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider(); mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, mDeviceListPreferenceFragment); SHOW_DEVICES_WITHOUT_NAMES); } @Test Loading Loading @@ -177,47 +179,22 @@ public class BluetoothDevicePreferenceTest { } @Test public void testVisible_notVisibleThenVisible() { when(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()).thenReturn(false); final boolean[] humanReadableName = {false}; doAnswer(invocation -> humanReadableName[0]).when(mCachedBluetoothDevice) .hasHumanReadableName(); public void testVisible_showDeviceWithoutNames_visible() { doReturn(false).when(mCachedBluetoothDevice).hasHumanReadableName(); BluetoothDevicePreference preference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, mDeviceListPreferenceFragment); assertThat(preference.isVisible()).isFalse(); humanReadableName[0] = true; preference.onDeviceAttributesChanged(); assertThat(preference.isVisible()).isTrue(); } SHOW_DEVICES_WITHOUT_NAMES); @Test public void testVisible_visibleThenNotVisible() { when(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()).thenReturn(false); final boolean[] humanReadableName = {true}; doAnswer(invocation -> humanReadableName[0]).when(mCachedBluetoothDevice) .hasHumanReadableName(); BluetoothDevicePreference preference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, mDeviceListPreferenceFragment); assertThat(preference.isVisible()).isTrue(); humanReadableName[0] = false; preference.onDeviceAttributesChanged(); assertThat(preference.isVisible()).isFalse(); } @Test public void testVisible_alwaysVisibleWhenEnabled() { when(mDeviceListPreferenceFragment.shouldShowDevicesWithoutNames()).thenReturn(true); final boolean[] humanReadableName = {true}; doAnswer(invocation -> humanReadableName[0]).when(mCachedBluetoothDevice) .hasHumanReadableName(); public void testVisible_hideDeviceWithoutNames_invisible() { doReturn(false).when(mCachedBluetoothDevice).hasHumanReadableName(); BluetoothDevicePreference preference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, mDeviceListPreferenceFragment); assertThat(preference.isVisible()).isTrue(); humanReadableName[0] = false; preference.onDeviceAttributesChanged(); assertThat(preference.isVisible()).isTrue(); false); assertThat(preference.isVisible()).isFalse(); } }