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

Commit 6f96226f authored by tim peng's avatar tim peng Committed by Android (Google) Code Review
Browse files

Merge "[Rohan]The battery level show up "-1%", not sync with Rohan." into sc-dev

parents e949d0f8 7246a4f8
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -289,10 +289,15 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
        } else {
            if (deviceId == MAIN_DEVICE_ID) {
                linearLayout.setVisibility(View.VISIBLE);
                batterySummaryView.setText(com.android.settings.Utils.formatPercentage(
                        bluetoothDevice.getBatteryLevel()));
                batterySummaryView.setVisibility(View.VISIBLE);
                linearLayout.findViewById(R.id.bt_battery_icon).setVisibility(View.GONE);
                int level = bluetoothDevice.getBatteryLevel();
                if (level != BluetoothDevice.BATTERY_LEVEL_UNKNOWN
                        && level != BluetoothDevice.BATTERY_LEVEL_BLUETOOTH_OFF) {
                    batterySummaryView.setText(com.android.settings.Utils.formatPercentage(level));
                    batterySummaryView.setVisibility(View.VISIBLE);
                } else {
                    batterySummaryView.setVisibility(View.GONE);
                }
            } else {
                // Hide it if it doesn't have battery information
                linearLayout.setVisibility(View.GONE);
+27 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.settings.core.SettingsUIDeviceConfig;
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.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.utils.StringUtil;
import com.android.settingslib.widget.LayoutPreference;
@@ -135,6 +136,32 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
        assertBatteryLevel(mLayoutPreference.findViewById(R.id.layout_middle), BATTERY_LEVEL_MAIN);
    }

    @Test
    public void refresh_connectedWatch_unknownBatteryLevel_shouldNotShowBatteryLevel() {
        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(mBluetoothDevice.getMetadata(
                BluetoothDevice.METADATA_MAIN_BATTERY)).thenReturn(
                String.valueOf(BluetoothUtils.META_INT_ERROR).getBytes());
        when(mBluetoothDevice.getBatteryLevel()).thenReturn(BluetoothDevice.BATTERY_LEVEL_UNKNOWN);
        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
    public void refresh_connectedUntetheredHeadset_behaveAsExpected() {
        when(mBluetoothDevice.getMetadata(