Merge "Accommodate BATT protocol modifications." into main
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user