Merge "Update dialog text for untethered BT device" into qt-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5716ed9..ef8a1fc 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1786,6 +1786,9 @@
<!-- Bluetooth device details. The body of a confirmation dialog for unpairing a paired device. -->
<string name="bluetooth_unpair_dialog_body" product="device">Your device will no longer be paired with <xliff:g id="device_name">%1$s</xliff:g></string>
+ <!-- Bluetooth device details. The body of a confirmation dialog for unpairing a paired device. [CHAR LIMIT=NONE] -->
+ <string name="bluetooth_untethered_unpair_dialog_body"><xliff:g id="device_name" example="Jack's headphone">%1$s</xliff:g> will no longer be paired with any device linked to this account</string>
+
<!-- Bluetooth device details. In the confirmation dialog for unpairing a paired device, this is the label on the button that will complete the unpairing action. -->
<string name="bluetooth_unpair_dialog_forget_confirm_button">Forget device</string>
diff --git a/src/com/android/settings/bluetooth/ForgetDeviceDialogFragment.java b/src/com/android/settings/bluetooth/ForgetDeviceDialogFragment.java
index db6b832..6d8fb33 100644
--- a/src/com/android/settings/bluetooth/ForgetDeviceDialogFragment.java
+++ b/src/com/android/settings/bluetooth/ForgetDeviceDialogFragment.java
@@ -29,6 +29,7 @@
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -72,13 +73,18 @@
};
Context context = getContext();
mDevice = getDevice(context);
+ final boolean untetheredHeadset = BluetoothUtils.getBooleanMetaData(
+ mDevice.getDevice(), BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET);
+
AlertDialog dialog = new AlertDialog.Builder(context)
.setPositiveButton(R.string.bluetooth_unpair_dialog_forget_confirm_button,
onConfirm)
.setNegativeButton(android.R.string.cancel, null)
.create();
dialog.setTitle(R.string.bluetooth_unpair_dialog_title);
- dialog.setMessage(context.getString(R.string.bluetooth_unpair_dialog_body,
+ dialog.setMessage(context.getString(untetheredHeadset
+ ? R.string.bluetooth_untethered_unpair_dialog_body
+ : R.string.bluetooth_unpair_dialog_body,
mDevice.getName()));
return dialog;
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java b/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java
index 44ffa54..b4f4f97 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/ForgetDeviceDialogFragmentTest.java
@@ -25,10 +25,15 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
+import com.android.settings.R;
import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import org.junit.Before;
@@ -39,33 +44,46 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowDialog;
+import org.robolectric.shadows.androidx.fragment.FragmentController;
@RunWith(RobolectricTestRunner.class)
+@Config(shadows = {ShadowAlertDialogCompat.class})
public class ForgetDeviceDialogFragmentTest {
+ private static final String DEVICE_NAME = "Nightshade";
+
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private CachedBluetoothDevice mCachedDevice;
+ @Mock
+ private BluetoothDevice mBluetoothDevice;
private ForgetDeviceDialogFragment mFragment;
private FragmentActivity mActivity;
private AlertDialog mDialog;
+ private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+
+ mContext = RuntimeEnvironment.application;
FakeFeatureFactory.setupForTest();
String deviceAddress = "55:66:77:88:99:AA";
when(mCachedDevice.getAddress()).thenReturn(deviceAddress);
+ when(mCachedDevice.getDevice()).thenReturn(mBluetoothDevice);
+ when(mCachedDevice.getName()).thenReturn(DEVICE_NAME);
mFragment = spy(ForgetDeviceDialogFragment.newInstance(deviceAddress));
doReturn(mCachedDevice).when(mFragment).getDevice(any());
mActivity = Robolectric.setupActivity(FragmentActivity.class);
- mActivity.getSupportFragmentManager().beginTransaction().add(mFragment, null).commit();
- mDialog = (AlertDialog) ShadowDialog.getLatestDialog();
}
@Test
public void cancelDialog() {
+ initDialog();
+
mDialog.getButton(AlertDialog.BUTTON_NEGATIVE).performClick();
verify(mCachedDevice, never()).unpair();
assertThat(mActivity.isFinishing()).isFalse();
@@ -73,8 +91,43 @@
@Test
public void confirmDialog() {
+ initDialog();
+
mDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
verify(mCachedDevice).unpair();
assertThat(mActivity.isFinishing()).isTrue();
}
+
+ @Test
+ public void createDialog_untetheredDevice_showUntetheredMessage() {
+ when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
+ .thenReturn("true".getBytes());
+
+ FragmentController.setupFragment(mFragment, FragmentActivity.class,
+ 0 /* containerViewId */, null /* bundle */);
+ final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
+ ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
+
+ assertThat(shadowDialog.getMessage()).isEqualTo(
+ mContext.getString(R.string.bluetooth_untethered_unpair_dialog_body, DEVICE_NAME));
+ }
+
+ @Test
+ public void createDialog_normalDevice_showNormalMessage() {
+ when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
+ .thenReturn("false".getBytes());
+
+ FragmentController.setupFragment(mFragment, FragmentActivity.class,
+ 0 /* containerViewId */, null /* bundle */);
+ final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
+ ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
+
+ assertThat(shadowDialog.getMessage()).isEqualTo(
+ mContext.getString(R.string.bluetooth_unpair_dialog_body, DEVICE_NAME));
+ }
+
+ private void initDialog() {
+ mActivity.getSupportFragmentManager().beginTransaction().add(mFragment, null).commit();
+ mDialog = (AlertDialog) ShadowDialog.getLatestDialog();
+ }
}