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

Commit 74b7a28a authored by Ze Li's avatar Ze Li Committed by Android (Google) Code Review
Browse files

Merge "[Battery refactor] Change the data source of battery info in Advanced header." into main

parents 8fe15cb2 d2dc00cb
Loading
Loading
Loading
Loading
+79 −21
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.bluetooth;

import static com.android.settings.bluetooth.Utils.preloadAndRun;
import static com.android.settingslib.flags.Flags.refactorBatteryLevelDisplay;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@@ -51,6 +52,7 @@ import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.flags.Flags;
import com.android.settings.fuelgauge.BatteryMeterView;
import com.android.settingslib.bluetooth.BatteryLevelsInfo;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -256,6 +258,8 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                    Suppliers.memoize(() -> !mCachedDevice.isConnected() || mCachedDevice.isBusy());
            Supplier<Boolean> isUntetheredHeadset =
                    Suppliers.memoize(() -> isUntetheredHeadset(mCachedDevice.getDevice()));
            Supplier<BatteryLevelsInfo> battery =
                    Suppliers.memoize(() -> mCachedDevice.getBatteryLevelsInfo());
            Supplier<String> summaryText =
                    Suppliers.memoize(
                            () -> {
@@ -263,6 +267,13 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                                    return mCachedDevice.getConnectionSummary(
                                            /* shortSummary= */ true);
                                }
                                if (refactorBatteryLevelDisplay()) {
                                    return mCachedDevice.getConnectionSummary(
                                            battery.get() != null
                                                    && battery.get().getOverallBatteryLevel()
                                                            > BluetoothDevice
                                                                    .BATTERY_LEVEL_UNKNOWN);
                                }
                                return mCachedDevice.getConnectionSummary(
                                        BluetoothUtils.getIntMetaData(
                                                        mCachedDevice.getDevice(),
@@ -294,7 +305,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                                            mCachedDevice.getDevice(),
                                            BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY));
            preloadAndRun(
                    List.of(deviceName, disconnected, isUntetheredHeadset, summaryText),
                    List.of(deviceName, disconnected, isUntetheredHeadset, summaryText, battery),
                    () -> {
                        final TextView title =
                                mLayoutPreference.findViewById(R.id.entity_header_title);
@@ -302,14 +313,25 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                        final TextView summary =
                                mLayoutPreference.findViewById(R.id.entity_header_summary);

                        final boolean isBatteryLevelAvailable =
                        final boolean isBatteryLevelAvailable;
                        if (refactorBatteryLevelDisplay()) {
                            isBatteryLevelAvailable =
                                    Flags.enableBatteryLevelDisplay()
                                            && isBattEnabled.get()
                                            && battery.get() != null
                                            && battery.get().getOverallBatteryLevel()
                                                    > BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
                        } else {
                            isBatteryLevelAvailable =
                                    Flags.enableBatteryLevelDisplay()
                                            && isBattEnabled.get()
                                        && (leftBatteryLevel.get() > BluetoothUtils.META_INT_ERROR
                                            && (leftBatteryLevel.get()
                                                            > BluetoothUtils.META_INT_ERROR
                                                    || rightBatteryLevel.get()
                                                            > BluetoothUtils.META_INT_ERROR
                                                    || caseBatteryLevel.get()
                                                            > BluetoothUtils.META_INT_ERROR);
                        }

                        if (disconnected.get() && !isBatteryLevelAvailable) {
                            summary.setText(summaryText.get());
@@ -322,6 +344,9 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                                    mLayoutPreference.findViewById(R.id.layout_left),
                                    BluetoothDevice.METADATA_UNTETHERED_LEFT_ICON,
                                    BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY,
                                    battery.get() != null
                                            ? battery.get().getLeftBatteryLevel()
                                            : BluetoothDevice.BATTERY_LEVEL_UNKNOWN,
                                    BluetoothDevice.METADATA_UNTETHERED_LEFT_LOW_BATTERY_THRESHOLD,
                                    BluetoothDevice.METADATA_UNTETHERED_LEFT_CHARGING,
                                    R.string.bluetooth_left_name,
@@ -331,6 +356,9 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                                    mLayoutPreference.findViewById(R.id.layout_middle),
                                    BluetoothDevice.METADATA_UNTETHERED_CASE_ICON,
                                    BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY,
                                    battery.get() != null
                                            ? battery.get().getCaseBatteryLevel()
                                            : BluetoothDevice.BATTERY_LEVEL_UNKNOWN,
                                    BluetoothDevice.METADATA_UNTETHERED_CASE_LOW_BATTERY_THRESHOLD,
                                    BluetoothDevice.METADATA_UNTETHERED_CASE_CHARGING,
                                    R.string.bluetooth_middle_name,
@@ -340,6 +368,9 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                                    mLayoutPreference.findViewById(R.id.layout_right),
                                    BluetoothDevice.METADATA_UNTETHERED_RIGHT_ICON,
                                    BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY,
                                    battery.get() != null
                                            ? battery.get().getRightBatteryLevel()
                                            : BluetoothDevice.BATTERY_LEVEL_UNKNOWN,
                                    BluetoothDevice.METADATA_UNTETHERED_RIGHT_LOW_BATTERY_THRESHOLD,
                                    BluetoothDevice.METADATA_UNTETHERED_RIGHT_CHARGING,
                                    R.string.bluetooth_right_name,
@@ -359,6 +390,9 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                                    mLayoutPreference.findViewById(R.id.layout_middle),
                                    BluetoothDevice.METADATA_MAIN_ICON,
                                    BluetoothDevice.METADATA_MAIN_BATTERY,
                                    battery.get() != null
                                            ? battery.get().getOverallBatteryLevel()
                                            : BluetoothDevice.BATTERY_LEVEL_UNKNOWN,
                                    BluetoothDevice.METADATA_MAIN_LOW_BATTERY_THRESHOLD,
                                    BluetoothDevice.METADATA_MAIN_CHARGING,
                                    /* titleResId= */ 0,
@@ -401,6 +435,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
            LinearLayout linearLayout,
            int iconMetaKey,
            int batteryMetaKey,
            int batteryValue,
            int lowBatteryMetaKey,
            int chargeMetaKey,
            int titleResId,
@@ -425,8 +460,14 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                                    BluetoothUtils.getIntMetaData(
                                            bluetoothDevice, lowBatteryMetaKey);
                            if (level == BluetoothUtils.META_INT_ERROR) {
                                if (batteryMetaKey
                                        == BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY) {
                                if ((refactorBatteryLevelDisplay()
                                        && lowBatteryMetaKey
                                        == BluetoothDevice
                                        .METADATA_UNTETHERED_CASE_LOW_BATTERY_THRESHOLD)
                                        || (!refactorBatteryLevelDisplay()
                                        && batteryMetaKey
                                        == BluetoothDevice
                                        .METADATA_UNTETHERED_CASE_BATTERY)) {
                                    level = CASE_LOW_BATTERY_LEVEL;
                                } else {
                                    level = LOW_BATTERY_LEVEL;
@@ -454,6 +495,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                                chargeMetaKey,
                                titleResId,
                                deviceId,
                                batteryValue,
                                iconUri,
                                batteryLevel,
                                charging,
@@ -470,6 +512,7 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
            int chargeMetaKey,
            int titleResId,
            int deviceId,
            int batteryValue,
            Supplier<String> preloadedIconUri,
            Supplier<Integer> preloadedBatteryLevel,
            Supplier<Boolean> preloadedCharging,
@@ -488,7 +531,12 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
            imageView.setImageDrawable(pair.first);
            imageView.setContentDescription(pair.second);
        }
        final int batteryLevel = preloadedBatteryLevel.get();
        final int batteryLevel;
        if (refactorBatteryLevelDisplay()) {
            batteryLevel = batteryValue;
        } else {
            batteryLevel = preloadedBatteryLevel.get();
        }
        final boolean charging = preloadedCharging.get();
        int lowBatteryLevel = preloadedLowBatteryLevel.get();

@@ -496,7 +544,8 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                + ", updateSubLayout() icon : " + iconMetaKey + ", battery : " + batteryMetaKey
                + ", charge : " + chargeMetaKey + ", batteryLevel : " + batteryLevel
                + ", charging : " + charging + ", iconUri : " + iconUri
                + ", lowBatteryLevel : " + lowBatteryLevel);
                + ", lowBatteryLevel : " + lowBatteryLevel
                + ", refactored : " + refactorBatteryLevelDisplay());

        if (deviceId == LEFT_DEVICE_ID || deviceId == RIGHT_DEVICE_ID) {
            showBatteryPredictionIfNecessary(linearLayout, deviceId, batteryLevel);
@@ -515,6 +564,12 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                    linearLayout.setVisibility(View.VISIBLE);
                    linearLayout.findViewById(R.id.bt_battery_icon).setVisibility(View.GONE);

                    if (refactorBatteryLevelDisplay()) {
                        batterySummaryView.setVisibility(View.GONE);
                        if (Flags.enableBluetoothDeviceDetailsPolish()) {
                            linearLayout.findViewById(R.id.battery_ring).setVisibility(View.GONE);
                        }
                    } else {
                        int level = preloadedNativeBatteryLevel.get();
                        if (level != BluetoothDevice.BATTERY_LEVEL_UNKNOWN
                                && level != BluetoothDevice.BATTERY_LEVEL_BLUETOOTH_OFF) {
@@ -525,7 +580,10 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
                        } else {
                            batterySummaryView.setVisibility(View.GONE);
                            if (Flags.enableBluetoothDeviceDetailsPolish()) {
                            linearLayout.findViewById(R.id.battery_ring).setVisibility(View.GONE);
                                linearLayout
                                        .findViewById(R.id.battery_ring)
                                        .setVisibility(View.GONE);
                            }
                        }
                    }
                } else {
+176 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings.bluetooth;

import static com.android.settingslib.flags.Flags.FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.never;
@@ -48,6 +50,7 @@ import com.android.settings.flags.Flags;
import com.android.settings.fuelgauge.BatteryMeterView;
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settingslib.bluetooth.BatteryLevelsInfo;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.utils.StringUtil;
@@ -110,7 +113,6 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {

        mContext = Robolectric.buildActivity(SettingsActivity.class).get();
        mController = new AdvancedBluetoothDetailsHeaderController(mContext, "pref_Key");
        when(mCachedDevice.getDevice()).thenReturn(mBluetoothDevice);
        mController.init(mCachedDevice, mFragment);
        mLayoutPreference = new LayoutPreference(mContext,
                LayoutInflater.from(mContext).inflate(R.layout.advanced_bt_entity_header, null));
@@ -155,6 +157,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
    }

    @Test
    @DisableFlags(FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY)
    public void refresh_connectedWatch_unknownBatteryLevel_shouldNotShowBatteryLevel() {
        when(mBluetoothDevice.getMetadata(
                BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn(
@@ -221,6 +224,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
    }

    @Test
    @DisableFlags(FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY)
    public void refresh_connectedUntetheredHeadset_behaveAsExpected() {
        when(mBluetoothDevice.getMetadata(
                BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn(
@@ -247,6 +251,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
    }

    @Test
    @DisableFlags(FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY)
    public void refresh_connected_updateCorrectInfo() {
        when(mBluetoothDevice.getMetadata(
                BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn(
@@ -307,6 +312,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
    }

    @Test
    @DisableFlags(FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY)
    public void refresh_withLowBatteryAndUncharged_showAlertIcon() {
        when(mBluetoothDevice.getMetadata(
                BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn(
@@ -345,6 +351,82 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
                false);
    }

    @Test
    @EnableFlags(FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY)
    public void refresh_connectedWatch_unknownBatteryLevel_shouldNotShowBatteryDisplay() {
        when(mBluetoothDevice.getMetadata(
                BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn(
                BluetoothDevice.DEVICE_TYPE_WATCH.getBytes());
        when(mBluetoothDevice.getMetadata(
                BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn(
                String.valueOf(false).getBytes());
        when(mCachedDevice.getBatteryLevelsInfo()).thenReturn(null);
        when(mCachedDevice.isConnected()).thenReturn(true);

        mController.refresh();

        assertThat(mLayoutPreference.findViewById(R.id.layout_left).getVisibility()).isEqualTo(
                View.GONE);
        assertThat(mLayoutPreference.findViewById(R.id.layout_right).getVisibility()).isEqualTo(
                View.GONE);
        assertThat(mLayoutPreference.findViewById(R.id.layout_middle).getVisibility()).isEqualTo(
                View.VISIBLE);
        assertThat(mLayoutPreference.findViewById(R.id.layout_middle)
                .requireViewById(R.id.bt_battery_summary).getVisibility()).isEqualTo(View.GONE);
    }

    @Test
    @EnableFlags(FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY)
    public void refresh_connected_updateCorrectBatteryDisplay() {
        when(mBluetoothDevice.getMetadata(
                BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn(
                String.valueOf(true).getBytes());
        when(mCachedDevice.getBatteryLevelsInfo()).thenReturn(
                new BatteryLevelsInfo(BATTERY_LEVEL_LEFT, BATTERY_LEVEL_RIGHT, BATTERY_LEVEL_MAIN,
                        BATTERY_LEVEL_LEFT));
        when(mCachedDevice.isConnected()).thenReturn(true);

        mController.refresh();

        assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_left), BATTERY_LEVEL_LEFT);
        assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_right), BATTERY_LEVEL_RIGHT);
        assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_middle), BATTERY_LEVEL_MAIN);
    }

    @Test
    @EnableFlags(FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY)
    public void refresh_withLowBatteryLevelsAndUncharged_showAlertIcon() {
        when(mBluetoothDevice.getMetadata(
                BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)).thenReturn(
                String.valueOf(true).getBytes());
        when(mCachedDevice.getBatteryLevelsInfo()).thenReturn(
                new BatteryLevelsInfo(LOW_BATTERY_LEVEL, LOW_BATTERY_LEVEL, LOW_BATTERY_LEVEL,
                        LOW_BATTERY_LEVEL));
        when(mBluetoothDevice.getMetadata(
                BluetoothDevice.METADATA_UNTETHERED_LEFT_CHARGING)).thenReturn(
                String.valueOf(false).getBytes());
        when(mBluetoothDevice.getMetadata(
                BluetoothDevice.METADATA_UNTETHERED_RIGHT_CHARGING)).thenReturn(
                String.valueOf(true).getBytes());
        when(mBluetoothDevice.getMetadata(
                BluetoothDevice.METADATA_UNTETHERED_CASE_CHARGING)).thenReturn(
                String.valueOf(false).getBytes());
        when(mCachedDevice.isConnected()).thenReturn(true);

        mController.refresh();

        assertBatteryIcon(
                mLayoutPreference.findViewById(R.id.layout_left),
                R.drawable.ic_battery_alert_24dp,
                false);
        assertBatteryIcon(
                mLayoutPreference.findViewById(R.id.layout_right), /* resId= */ -1, true);
        assertBatteryIcon(
                mLayoutPreference.findViewById(R.id.layout_middle),
                R.drawable.ic_battery_alert_24dp,
                false);
    }

    @Test
    public void getAvailabilityStatus_untetheredHeadset_returnAvailable() {
        when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
@@ -554,6 +636,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_BATTERY_LEVEL_DISPLAY)
    @DisableFlags(FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY)
    public void enableBatt_budsDisconnected_batteryLevelShown() {
        when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE))
                .thenReturn(BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes());
@@ -577,7 +660,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_ENABLE_BATTERY_LEVEL_DISPLAY)
    @DisableFlags({Flags.FLAG_ENABLE_BATTERY_LEVEL_DISPLAY, FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY})
    public void disableBatt_budsDisconnected_batteryLevelNotShown() {
        when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE))
                .thenReturn(BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes());
@@ -615,6 +698,7 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_BATTERY_LEVEL_DISPLAY)
    @DisableFlags(FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY)
    public void disableFastPairBatt_budsDisconnected_batteryLevelNotShown() {
        when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE))
                .thenReturn(BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes());
@@ -650,6 +734,96 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
                .isNotEqualTo(View.VISIBLE);
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_BATTERY_LEVEL_DISPLAY, FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY})
    public void enableBatt_budsDisconnected_batteryDisplayShown() {
        when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE))
                .thenReturn(BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes());
        when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
                .thenReturn(String.valueOf(false).getBytes());
        when(mCachedDevice.getBatteryLevelsInfo()).thenReturn(
                new BatteryLevelsInfo(BATTERY_LEVEL_LEFT, BATTERY_LEVEL_RIGHT, BATTERY_LEVEL_MAIN,
                        BATTERY_LEVEL_LEFT));
        when(mBluetoothDevice.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS))
                .thenReturn("<BATT>true</BATT>".getBytes());
        when(mCachedDevice.isConnected()).thenReturn(false);

        mController.refresh();

        assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_left), BATTERY_LEVEL_LEFT);
        assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_right), BATTERY_LEVEL_RIGHT);
        assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_middle), BATTERY_LEVEL_MAIN);
    }

    @Test
    @EnableFlags(FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY)
    @DisableFlags(Flags.FLAG_ENABLE_BATTERY_LEVEL_DISPLAY)
    public void disableBatt_budsDisconnected_batteryDisplayNotShown() {
        when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE))
                .thenReturn(BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes());
        when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
                .thenReturn(String.valueOf(false).getBytes());
        when(mCachedDevice.getBatteryLevelsInfo()).thenReturn(
                new BatteryLevelsInfo(BATTERY_LEVEL_LEFT, BATTERY_LEVEL_RIGHT, BATTERY_LEVEL_MAIN,
                        BATTERY_LEVEL_LEFT));
        when(mBluetoothDevice.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS))
                .thenReturn("<BATT>true</BATT>".getBytes());
        when(mCachedDevice.isConnected()).thenReturn(false);

        mController.refresh();

        assertThat(mLayoutPreference.findViewById(R.id.layout_left).getVisibility())
                .isNotEqualTo(View.VISIBLE);
        assertThat(mLayoutPreference.findViewById(R.id.layout_right).getVisibility())
                .isNotEqualTo(View.VISIBLE);
        assertThat(
                mLayoutPreference
                        .findViewById(R.id.layout_middle)
                        .findViewById(R.id.bt_battery_summary)
                        .getVisibility())
                .isNotEqualTo(View.VISIBLE);
        assertThat(
                mLayoutPreference
                        .findViewById(R.id.layout_middle)
                        .findViewById(R.id.bt_battery_icon)
                        .getVisibility())
                .isNotEqualTo(View.VISIBLE);
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_BATTERY_LEVEL_DISPLAY, FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY})
    public void disableFastPairBatt_budsDisconnected_batteryDisplayNotShown() {
        when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE))
                .thenReturn(BluetoothDevice.DEVICE_TYPE_UNTETHERED_HEADSET.getBytes());
        when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET))
                .thenReturn(String.valueOf(false).getBytes());
        when(mCachedDevice.getBatteryLevelsInfo()).thenReturn(
                new BatteryLevelsInfo(BATTERY_LEVEL_LEFT, BATTERY_LEVEL_RIGHT, BATTERY_LEVEL_MAIN,
                        BATTERY_LEVEL_LEFT));
        when(mBluetoothDevice.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS))
                .thenReturn("<BATT>false</BATT>".getBytes());
        when(mCachedDevice.isConnected()).thenReturn(false);

        mController.refresh();

        assertThat(mLayoutPreference.findViewById(R.id.layout_left).getVisibility())
                .isNotEqualTo(View.VISIBLE);
        assertThat(mLayoutPreference.findViewById(R.id.layout_right).getVisibility())
                .isNotEqualTo(View.VISIBLE);
        assertThat(
                mLayoutPreference
                        .findViewById(R.id.layout_middle)
                        .findViewById(R.id.bt_battery_summary)
                        .getVisibility())
                .isNotEqualTo(View.VISIBLE);
        assertThat(
                mLayoutPreference
                        .findViewById(R.id.layout_middle)
                        .findViewById(R.id.bt_battery_icon)
                        .getVisibility())
                .isNotEqualTo(View.VISIBLE);
    }

    private void assertBatteryPredictionVisible(LinearLayout linearLayout, int visible) {
        final TextView textView = linearLayout.findViewById(R.id.bt_battery_prediction);
        assertThat(textView.getVisibility()).isEqualTo(visible);