Expose mac address in bluetooth main page

This mac address means the owned device, not the device
to connect.

Bug: 35875420
Test: RunSettingsRoboTests
Change-Id: I142f49fdca72d8ffbb9b8b2e2666a61aefb80505
This commit is contained in:
jackqdyulei
2017-03-29 16:06:32 -07:00
parent 910f69c62a
commit d2ba0117fc
3 changed files with 74 additions and 10 deletions

View File

@@ -246,6 +246,8 @@
<!-- Bluetooth Visibility message. This message informs the user that their device is now visible to other bluetooth devices. [CHAR LIMIT=NONE] -->
<string name="bluetooth_is_visible_message"><xliff:g id="device_name">%1$s</xliff:g> is visible to nearby devices while Bluetooth settings is open.</string>
<!-- Bluetooth mac address message. This message shows the bluetooth mac address for this device. [CHAR LIMIT=120] -->
<string name="bluetooth_footer_mac_message">Bluetooth MAC address: <xliff:g id="bluetooth_mac_address">%1$s</xliff:g></string>
<!-- Bluetooth Visibility discoonect question. Asks the user if they wish to disconnect a paired bluetooth device. [CHAR LIMIT=50] -->
<string name="bluetooth_is_disconnect_question">Disconnect <xliff:g id="device_name">%1$s</xliff:g>?</string>
<!-- Bluetooth broadcasting settings, option to enable/disable broadcasting -->

View File

@@ -28,6 +28,7 @@ import android.content.res.Resources;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
@@ -57,6 +58,7 @@ import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.SwitchBarController;
import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import java.util.ArrayList;
@@ -70,7 +72,7 @@ import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
* BluetoothSettings is the Settings screen for Bluetooth configuration and
* connection management.
*/
public final class BluetoothSettings extends DeviceListPreferenceFragment implements Indexable {
public class BluetoothSettings extends DeviceListPreferenceFragment implements Indexable {
private static final String TAG = "BluetoothSettings";
private static final int MENU_ID_SCAN = Menu.FIRST;
@@ -361,13 +363,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
startScanning();
}
final Resources res = getResources();
final Locale locale = res.getConfiguration().getLocales().get(0);
final BidiFormatter bidiFormatter = BidiFormatter.getInstance(locale);
mMyDevicePreference.setTitle(res.getString(
R.string.bluetooth_is_visible_message,
bidiFormatter.unicodeWrap(mLocalAdapter.getName())));
updateMyDevicePreference(mMyDevicePreference);
getActivity().invalidateOptionsMenu();
// mLocalAdapter.setScanMode is internally synchronized so it is okay for multiple
@@ -477,6 +473,20 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
}
}
@VisibleForTesting
void updateMyDevicePreference(Preference myDevicePreference) {
final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
myDevicePreference.setTitle(getString(
R.string.bluetooth_footer_mac_message,
bidiFormatter.unicodeWrap(mLocalAdapter.getAddress())));
}
@VisibleForTesting
void setLocalBluetoothAdapter(LocalBluetoothAdapter localAdapter) {
mLocalAdapter = localAdapter;
}
private final GearPreference.OnGearClickListener mDeviceProfilesListener = pref -> {
// User clicked on advanced options icon for a device in the list
if (!(pref instanceof BluetoothDevicePreference)) {

View File

@@ -16,22 +16,74 @@
package com.android.settings.bluetooth;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import android.content.Context;
import android.content.res.Resources;
import android.os.UserManager;
import android.support.v7.preference.Preference;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class BluetoothSettingsTest {
private static final String FOOTAGE_MAC_STRING = "Bluetooth mac: xxxx";
@Mock
private UserManager mUserManager;
@Mock
private Resources mResource;
@Mock
private Context mContext;
@Mock
private LocalBluetoothAdapter mLocalAdapter;
private BluetoothSettings mFragment;
private Preference mMyDevicePreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFragment = spy(new BluetoothSettings());
doReturn(mContext).when(mFragment).getContext();
doReturn(mResource).when(mFragment).getResources();
mMyDevicePreference = new Preference(RuntimeEnvironment.application);
mFragment.setLocalBluetoothAdapter(mLocalAdapter);
}
@Test
public void setTextSpan_notSpannable_shouldNotCrash() {
final String str = "test";
final BluetoothSettings settings = new BluetoothSettings();
settings.setTextSpan(str, "hello");
mFragment.setTextSpan(str, "hello");
}
@Test
public void setUpdateMyDevicePreference_setTitleCorrectly() {
doReturn(FOOTAGE_MAC_STRING).when(mFragment).getString(
eq(R.string.bluetooth_footer_mac_message), any());
mFragment.updateMyDevicePreference(mMyDevicePreference);
assertThat(mMyDevicePreference.getTitle()).isEqualTo(FOOTAGE_MAC_STRING);
}
}