Merge "Show battery info for mono audio location device" into main

This commit is contained in:
Angela Wang
2024-12-10 03:38:31 +00:00
committed by Android (Google) Code Review
4 changed files with 43 additions and 12 deletions

View File

@@ -176,5 +176,23 @@
android:padding="@dimen/le_bluetooth_summary_padding"
android:drawablePadding="@dimen/le_bluetooth_summary_drawable_padding"/>
</LinearLayout>
<LinearLayout
android:id="@+id/bt_battery_mono"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/le_bluetooth_battery_start_margin"
android:layout_marginTop="@dimen/le_bluetooth_battery_top_margin"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:visibility="gone"
android:focusable="true">
<TextView
android:id="@+id/bt_battery_mono_summary"
style="@style/TextAppearance.EntityHeaderSummary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/le_bluetooth_summary_padding"
android:drawablePadding="@dimen/le_bluetooth_summary_drawable_padding"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@@ -162,18 +162,13 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
}
final int side = device.getDeviceSide();
if (side == HearingAidInfo.DeviceSide.SIDE_LEFT_AND_RIGHT) {
return mContext.getString(
R.string.accessibility_hearingaid_left_and_right_side_device_summary, name);
} else if (side == HearingAidInfo.DeviceSide.SIDE_LEFT) {
if (side == HearingAidInfo.DeviceSide.SIDE_LEFT) {
return mContext.getString(
R.string.accessibility_hearingaid_left_side_device_summary, name);
} else if (side == HearingAidInfo.DeviceSide.SIDE_RIGHT) {
return mContext.getString(
R.string.accessibility_hearingaid_right_side_device_summary, name);
}
// Invalid side
return mContext.getString(
R.string.accessibility_hearingaid_active_device_summary, name);
}

View File

@@ -225,6 +225,8 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
return R.id.bt_battery_left_summary;
} else if (containerId == R.id.bt_battery_right) {
return R.id.bt_battery_right_summary;
} else if (containerId == R.id.bt_battery_mono) {
return R.id.bt_battery_mono_summary;
}
Log.d(TAG, "No summary resource id. The containerId is " + containerId);
return INVALID_RESOURCE_ID;
@@ -237,6 +239,8 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
updateBatteryLayout(R.id.bt_battery_left, BluetoothUtils.META_INT_ERROR);
// hide the right
updateBatteryLayout(R.id.bt_battery_right, BluetoothUtils.META_INT_ERROR);
// hide the mono
updateBatteryLayout(R.id.bt_battery_mono, BluetoothUtils.META_INT_ERROR);
}
private void updateBatteryLayout() {
@@ -261,11 +265,6 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
int deviceId = leAudioProfile.getAudioLocation(cachedDevice.getDevice());
Log.d(TAG, "LeAudioDevices:" + cachedDevice.getDevice().getAnonymizedAddress()
+ ", deviceId:" + deviceId);
if (deviceId == BluetoothLeAudio.AUDIO_LOCATION_INVALID) {
Log.d(TAG, "The device does not support the AUDIO_LOCATION.");
return;
}
boolean isLeft = (deviceId & LEFT_DEVICE_ID) != 0;
boolean isRight = (deviceId & RIGHT_DEVICE_ID) != 0;
boolean isLeftRight = isLeft && isRight;
@@ -280,6 +279,8 @@ public class LeAudioBluetoothDetailsHeaderController extends BasePreferenceContr
updateBatteryLayout(R.id.bt_battery_left, cachedDevice.getBatteryLevel());
} else if (isRight) {
updateBatteryLayout(R.id.bt_battery_right, cachedDevice.getBatteryLevel());
} else if (deviceId == BluetoothLeAudio.AUDIO_LOCATION_MONO) {
updateBatteryLayout(R.id.bt_battery_mono, cachedDevice.getBatteryLevel());
} else {
Log.d(TAG, "The device id is other Audio Location. Do nothing.");
}

View File

@@ -208,7 +208,24 @@ public class AccessibilityHearingAidPreferenceControllerTest {
ShadowLooper.idleMainLooper();
assertThat(mHearingAidPreference.getSummary().toString().contentEquals(
"TEST_HEARING_AID_BT_DEVICE_NAME / Left and right")).isTrue();
"TEST_HEARING_AID_BT_DEVICE_NAME active")).isTrue();
}
@Test
public void getSummary_connectedLeAudioHearingAidMonoSide_connectedSummary() {
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidInfo.DeviceSide.SIDE_MONO);
when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(new HashSet<>());
when(mHapClientProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
mPreferenceController.onStart();
Intent intent = new Intent(BluetoothHapClient.ACTION_HAP_CONNECTION_STATE_CHANGED);
intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHapClient.STATE_CONNECTED);
sendIntent(intent);
ShadowLooper.idleMainLooper();
assertThat(mHearingAidPreference.getSummary().toString().contentEquals(
"TEST_HEARING_AID_BT_DEVICE_NAME active")).isTrue();
}
@Test