[Rohan]The battery level show up "-1%", not sync with Rohan.
-Hide battery information when it is unknown Bug: 184017556 Test: make -j50 RunSettingsRoboTests ROBOTEST_FILTER=AdvancedBluetoothDetailsHeaderControllerTest Change-Id: I5f94ccae364f1420e04af21ba425c29ac6a11dd2
This commit is contained in:
@@ -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);
|
||||
|
@@ -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(
|
||||
|
Reference in New Issue
Block a user