Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 205c81ed authored by Ze Li's avatar Ze Li
Browse files

[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
parent 0f6baa17
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -331,7 +331,9 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                                    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);
                renameButton.setVisibility(View.VISIBLE);
                renameButton.setOnClickListener(view -> {
+13 −9
Original line number Diff line number Diff line
@@ -89,6 +89,9 @@ public class GeneralBluetoothDetailsHeaderController extends BluetoothDetailsCon
        if (summary != null) {
            summary.setText(mCachedDevice.getConnectionSummary());
        }
        boolean isTempBond = com.android.settingslib.flags.Flags.enableTemporaryBondDevicesUi()
                && BluetoothUtils.isTemporaryBondDevice(mCachedDevice.getDevice());
        if (!isTempBond) {
            ImageButton renameButton = mLayoutPreference.findViewById(R.id.rename_button);
            renameButton.setVisibility(View.VISIBLE);
            renameButton.setOnClickListener(
@@ -99,6 +102,7 @@ public class GeneralBluetoothDetailsHeaderController extends BluetoothDetailsCon
                                        RemoteDeviceNameDialogFragment.TAG);
                    });
        }
    }

    @Override
    @NonNull
+3 −1
Original line number Diff line number Diff line
@@ -168,7 +168,9 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
        if (mLayoutPreference == null || mCachedDevice == null) {
            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);
            renameButton.setVisibility(View.VISIBLE);
            renameButton.setOnClickListener(view -> {
+20 −0
Original line number Diff line number Diff line
@@ -79,9 +79,12 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
    private static final int LOW_BATTERY_LEVEL_THRESHOLD = 15;
    private static final int BATTERY_LEVEL_5 = 5;
    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 MAC_ADDRESS = "04:52:C7:0B:D8:3C";
    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;

@@ -531,6 +534,23 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
        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) {
        final TextView textView = linearLayout.findViewById(R.id.bt_battery_prediction);
        assertThat(textView.getVisibility()).isEqualTo(visible);