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

This commit is contained in:
tim peng
2021-04-01 13:25:31 +00:00
committed by Android (Google) Code Review
2 changed files with 35 additions and 3 deletions

View File

@@ -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);

View File

@@ -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(