Accommodate BATT protocol modifications.

Bug: 380790573
Test: atest com.android.settings.bluetooth.AdvancedBluetoothDetailsHeaderControllerTest and Manual
Flag: com.android.settings.flags.enable_battery_level_display

Change-Id: Ibc4eb66aacedaf3a4111d4a411dada6cde1a5b9c
This commit is contained in:
Chung Tang
2024-12-29 18:03:57 +00:00
parent 047c38856a
commit 8a6ea1a106
2 changed files with 134 additions and 1 deletions

View File

@@ -28,6 +28,7 @@ import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.view.LayoutInflater;
@@ -551,6 +552,104 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
assertThat(button.getVisibility()).isEqualTo(View.GONE);
}
@Test
@EnableFlags(Flags.FLAG_ENABLE_BATTERY_LEVEL_DISPLAY)
public void enableBatt_budsDisconnected_batteryLevelShown() {
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(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY))
.thenReturn(String.valueOf(BATTERY_LEVEL_LEFT).getBytes());
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY))
.thenReturn(String.valueOf(BATTERY_LEVEL_RIGHT).getBytes());
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY))
.thenReturn(String.valueOf(BATTERY_LEVEL_MAIN).getBytes());
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
@DisableFlags(Flags.FLAG_ENABLE_BATTERY_LEVEL_DISPLAY)
public void disableBatt_budsDisconnected_batteryLevelNotShown() {
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(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY))
.thenReturn(String.valueOf(BATTERY_LEVEL_LEFT).getBytes());
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY))
.thenReturn(String.valueOf(BATTERY_LEVEL_RIGHT).getBytes());
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY))
.thenReturn(String.valueOf(BATTERY_LEVEL_MAIN).getBytes());
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)
public void disableFastPairBatt_budsDisconnected_batteryLevelNotShown() {
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(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_LEFT_BATTERY))
.thenReturn(String.valueOf(BATTERY_LEVEL_LEFT).getBytes());
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_RIGHT_BATTERY))
.thenReturn(String.valueOf(BATTERY_LEVEL_RIGHT).getBytes());
when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_UNTETHERED_CASE_BATTERY))
.thenReturn(String.valueOf(BATTERY_LEVEL_MAIN).getBytes());
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);