[Temp bonding] Hide rename button from device details page for temp bond device

Test: com.android.settings.bluetooth.AdvancedBluetoothDetailsHeaderControllerTest
Bug: 362859132
Flag: com.android.settingslib.flags.enable_temporary_bond_devices_ui
Change-Id: I22d54c322029c606425c8f48b091ad1b53e100de
This commit is contained in:
Ze Li
2025-01-07 14:38:04 +08:00
parent 0f6baa17c2
commit 205c81ed3a
4 changed files with 39 additions and 11 deletions

View File

@@ -331,7 +331,9 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
MAIN_DEVICE_ID); MAIN_DEVICE_ID);
} }
}); });
if (Flags.enableBluetoothDeviceDetailsPolish()) { boolean isTempBond = com.android.settingslib.flags.Flags.enableTemporaryBondDevicesUi()
&& BluetoothUtils.isTemporaryBondDevice(mCachedDevice.getDevice());
if (Flags.enableBluetoothDeviceDetailsPolish() && !isTempBond) {
ImageButton renameButton = mLayoutPreference.findViewById(R.id.rename_button); ImageButton renameButton = mLayoutPreference.findViewById(R.id.rename_button);
renameButton.setVisibility(View.VISIBLE); renameButton.setVisibility(View.VISIBLE);
renameButton.setOnClickListener(view -> { renameButton.setOnClickListener(view -> {

View File

@@ -89,15 +89,19 @@ public class GeneralBluetoothDetailsHeaderController extends BluetoothDetailsCon
if (summary != null) { if (summary != null) {
summary.setText(mCachedDevice.getConnectionSummary()); summary.setText(mCachedDevice.getConnectionSummary());
} }
ImageButton renameButton = mLayoutPreference.findViewById(R.id.rename_button); boolean isTempBond = com.android.settingslib.flags.Flags.enableTemporaryBondDevicesUi()
renameButton.setVisibility(View.VISIBLE); && BluetoothUtils.isTemporaryBondDevice(mCachedDevice.getDevice());
renameButton.setOnClickListener( if (!isTempBond) {
view -> { ImageButton renameButton = mLayoutPreference.findViewById(R.id.rename_button);
RemoteDeviceNameDialogFragment.newInstance(mCachedDevice) renameButton.setVisibility(View.VISIBLE);
.show( renameButton.setOnClickListener(
mFragment.getFragmentManager(), view -> {
RemoteDeviceNameDialogFragment.TAG); RemoteDeviceNameDialogFragment.newInstance(mCachedDevice)
}); .show(
mFragment.getFragmentManager(),
RemoteDeviceNameDialogFragment.TAG);
});
}
} }
@Override @Override

View File

@@ -168,7 +168,9 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
if (mLayoutPreference == null || mCachedDevice == null) { if (mLayoutPreference == null || mCachedDevice == null) {
return; return;
} }
if (Flags.enableBluetoothDeviceDetailsPolish()) { boolean isTempBond = com.android.settingslib.flags.Flags.enableTemporaryBondDevicesUi()
&& BluetoothUtils.isTemporaryBondDevice(mCachedDevice.getDevice());
if (Flags.enableBluetoothDeviceDetailsPolish() && !isTempBond) {
ImageButton renameButton = mLayoutPreference.findViewById(R.id.rename_button); ImageButton renameButton = mLayoutPreference.findViewById(R.id.rename_button);
renameButton.setVisibility(View.VISIBLE); renameButton.setVisibility(View.VISIBLE);
renameButton.setOnClickListener(view -> { renameButton.setOnClickListener(view -> {

View File

@@ -79,9 +79,12 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
private static final int LOW_BATTERY_LEVEL_THRESHOLD = 15; private static final int LOW_BATTERY_LEVEL_THRESHOLD = 15;
private static final int BATTERY_LEVEL_5 = 5; private static final int BATTERY_LEVEL_5 = 5;
private static final int BATTERY_LEVEL_50 = 50; private static final int BATTERY_LEVEL_50 = 50;
private static final int METADATA_FAST_PAIR_CUSTOMIZED_FIELDS = 25;
private static final String ICON_URI = "content://test.provider/icon.png"; private static final String ICON_URI = "content://test.provider/icon.png";
private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C"; private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C";
private static final String DEVICE_SUMMARY = "test summary"; private static final String DEVICE_SUMMARY = "test summary";
private static final String TEMP_BOND_METADATA =
"<TEMP_BOND_TYPE>le_audio_sharing</TEMP_BOND_TYPE>";
private Context mContext; private Context mContext;
@@ -531,6 +534,23 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
assertThat(button.getVisibility()).isEqualTo(View.VISIBLE); assertThat(button.getVisibility()).isEqualTo(View.VISIBLE);
} }
@Test
@EnableFlags({Flags.FLAG_ENABLE_BLUETOOTH_DEVICE_DETAILS_POLISH,
com.android.settingslib.flags.Flags.FLAG_ENABLE_TEMPORARY_BOND_DEVICES_UI})
public void temporaryBondDevice_renameButtonNotShown() {
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
.thenReturn("true".getBytes());
when(mBluetoothDevice.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS))
.thenReturn(TEMP_BOND_METADATA.getBytes());
Set<CachedBluetoothDevice> cacheBluetoothDevices = new HashSet<>();
when(mCachedDevice.getMemberDevice()).thenReturn(cacheBluetoothDevices);
mController.onStart();
ImageButton button = mLayoutPreference.findViewById(R.id.rename_button);
assertThat(button.getVisibility()).isEqualTo(View.GONE);
}
private void assertBatteryPredictionVisible(LinearLayout linearLayout, int visible) { private void assertBatteryPredictionVisible(LinearLayout linearLayout, int visible) {
final TextView textView = linearLayout.findViewById(R.id.bt_battery_prediction); final TextView textView = linearLayout.findViewById(R.id.bt_battery_prediction);
assertThat(textView.getVisibility()).isEqualTo(visible); assertThat(textView.getVisibility()).isEqualTo(visible);