From d89518e3c555f8ebe045cb3975f7d654de19b816 Mon Sep 17 00:00:00 2001 From: hughchen Date: Thu, 26 Dec 2019 11:32:58 +0800 Subject: [PATCH] Finish bluetooth detail fragment if device is BOND_NONE This CL is used to check the bluetooth bond state when fragment is onResume. The bluetooth detail fragment will finish if the bluetooth bond state is BOND_NONE when fragment is onResume. Bug: 146621601 Test: make -j42 RunSettingsRoboTests Change-Id: I157e1da925dcf527ce2b49ad431079d90b7c4fc3 --- .../bluetooth/BluetoothDeviceDetailsFragment.java | 15 +++++++++++++++ .../BluetoothDeviceDetailsFragmentTest.java | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java index 59c5078dbce..a8812475ace 100644 --- a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java +++ b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java @@ -16,6 +16,7 @@ package com.android.settings.bluetooth; +import static android.bluetooth.BluetoothDevice.BOND_NONE; import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH; import android.app.settings.SettingsEnums; @@ -127,6 +128,20 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment : null); } + @Override + public void onResume() { + super.onResume(); + finishFragmentIfNecessary(); + } + + @VisibleForTesting + void finishFragmentIfNecessary() { + if (mCachedDevice.getBondState() == BOND_NONE) { + finish(); + return; + } + } + @Override public int getMetricsCategory() { return SettingsEnums.BLUETOOTH_DEVICE_DETAILS; diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java index c9d82011d12..ce41a8d7ca8 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragmentTest.java @@ -16,6 +16,8 @@ package com.android.settings.bluetooth; +import static android.bluetooth.BluetoothDevice.BOND_NONE; + import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -126,4 +128,13 @@ public class BluetoothDeviceDetailsFragmentTest { RemoteDeviceNameDialogFragment dialog = (RemoteDeviceNameDialogFragment) captor.getValue(); assertThat(dialog).isNotNull(); } + + @Test + public void finishFragmentIfNecessary_deviceIsBondNone_finishFragment() { + when(mCachedDevice.getBondState()).thenReturn(BOND_NONE); + + mFragment.finishFragmentIfNecessary(); + + verify(mFragment).finish(); + } }