Bluetooth: Only show devices when their names are resolved

* Add a developer menu option to allow name-less devices to be shown
  when a Bluetooth developer needs it, but hide it for non-developer
  users.
* Set BluetoothDevicePreference to invisible when CachedBluetoothDevice
  does not have a name besides MAC address and the above developer option
  is false.
* This affects BluetoothPairingDetail and DevicePickerFragment, but does
  not affect BluetoothSettings. BluetoothSettings will show all paired
  devices regardless whether an user friendly name exists.

Bug: 34685932
Test: pair Bluetooth device, send file over Bluetooth, unit tests
Change-Id: Idd7ad4b1671dfdcf3204efb50eddb6dae1065aa5
This commit is contained in:
Jack He
2017-05-31 18:37:28 -07:00
parent 77bd8c3a73
commit 19ba320263
6 changed files with 102 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ package com.android.settings.bluetooth;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.os.Bundle;
import android.os.SystemProperties;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
@@ -52,6 +53,10 @@ public abstract class DeviceListPreferenceFragment extends
private static final String KEY_BT_SCAN = "bt_scan";
// Copied from DevelopmentSettings.java
private static final String BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY =
"persist.bluetooth.showdeviceswithoutnames";
private BluetoothDeviceFilter.Filter mFilter;
@VisibleForTesting
@@ -68,6 +73,8 @@ public abstract class DeviceListPreferenceFragment extends
final WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference> mDevicePreferenceMap =
new WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference>();
boolean mShowDevicesWithoutNames;
DeviceListPreferenceFragment(String restrictedKey) {
super(restrictedKey);
mFilter = BluetoothDeviceFilter.ALL_FILTER;
@@ -103,6 +110,8 @@ 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());
@@ -181,7 +190,7 @@ public abstract class DeviceListPreferenceFragment extends
BluetoothDevicePreference preference = (BluetoothDevicePreference) getCachedPreference(key);
if (preference == null) {
preference = new BluetoothDevicePreference(getPrefContext(), cachedDevice);
preference = new BluetoothDevicePreference(getPrefContext(), cachedDevice, this);
preference.setKey(key);
mDeviceListGroup.addPreference(preference);
} else {
@@ -271,4 +280,8 @@ public abstract class DeviceListPreferenceFragment extends
* Return the key of the {@link PreferenceGroup} that contains the bluetooth devices
*/
public abstract String getDeviceListKey();
public boolean shouldShowDevicesWithoutNames() {
return mShowDevicesWithoutNames;
}
}