Merge "Use proper string formatting for the "Active device" string"
This commit is contained in:
@@ -250,6 +250,19 @@
|
|||||||
<item>Best Effort (Adaptive Bit Rate)</item>
|
<item>Best Effort (Adaptive Bit Rate)</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<!-- TODO: Enable for translation per b/73007419 -->
|
||||||
|
<!-- Summaries for Bluetooth Audio Active Device status. [CHAR LIMIT=50]-->
|
||||||
|
<string-array name="bluetooth_audio_active_device_summaries" translatable="false" >
|
||||||
|
<!-- Status message when the device is not Active. -->
|
||||||
|
<item></item>
|
||||||
|
<!-- Status message when the device is Active for Media and Phone. -->
|
||||||
|
<item>, active</item>
|
||||||
|
<!-- Status message when the device is Active for Media only. -->
|
||||||
|
<item>, active(media)</item>
|
||||||
|
<!-- Status message when the device is Active for Phone only. -->
|
||||||
|
<item>, active(phone)</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<!-- Titles for logd limit size selection preference. [CHAR LIMIT=14] -->
|
<!-- Titles for logd limit size selection preference. [CHAR LIMIT=14] -->
|
||||||
<string-array name="select_logd_size_titles">
|
<string-array name="select_logd_size_titles">
|
||||||
<item>Off</item>
|
<item>Off</item>
|
||||||
|
|||||||
@@ -128,27 +128,27 @@
|
|||||||
<!-- Bluetooth settings. Message when connecting to a device -->
|
<!-- Bluetooth settings. Message when connecting to a device -->
|
||||||
<string name="bluetooth_connecting">Connecting\u2026</string>
|
<string name="bluetooth_connecting">Connecting\u2026</string>
|
||||||
<!-- Bluetooth settings. Message when connected to a device. [CHAR LIMIT=40] -->
|
<!-- Bluetooth settings. Message when connected to a device. [CHAR LIMIT=40] -->
|
||||||
<string name="bluetooth_connected">Connected</string>
|
<string name="bluetooth_connected">Connected<xliff:g id="active_device">%1$s</xliff:g></string>
|
||||||
<!--Bluetooth settings screen, summary text under individual Bluetooth devices when pairing -->
|
<!--Bluetooth settings screen, summary text under individual Bluetooth devices when pairing -->
|
||||||
<string name="bluetooth_pairing">Pairing\u2026</string>
|
<string name="bluetooth_pairing">Pairing\u2026</string>
|
||||||
|
|
||||||
<!-- Bluetooth settings. Message when connected to a device, except for phone audio. [CHAR LIMIT=40] -->
|
<!-- Bluetooth settings. Message when connected to a device, except for phone audio. [CHAR LIMIT=40] -->
|
||||||
<string name="bluetooth_connected_no_headset">Connected (no phone)</string>
|
<string name="bluetooth_connected_no_headset">Connected (no phone)<xliff:g id="active_device">%1$s</xliff:g></string>
|
||||||
<!-- Bluetooth settings. Message when connected to a device, except for media audio. [CHAR LIMIT=40] -->
|
<!-- Bluetooth settings. Message when connected to a device, except for media audio. [CHAR LIMIT=40] -->
|
||||||
<string name="bluetooth_connected_no_a2dp">Connected (no media)</string>
|
<string name="bluetooth_connected_no_a2dp">Connected (no media)<xliff:g id="active_device">%1$s</xliff:g></string>
|
||||||
<!-- Bluetooth settings. Message when connected to a device, except for map. [CHAR LIMIT=40] -->
|
<!-- Bluetooth settings. Message when connected to a device, except for map. [CHAR LIMIT=40] -->
|
||||||
<string name="bluetooth_connected_no_map">Connected (no message access)</string>
|
<string name="bluetooth_connected_no_map">Connected (no message access)<xliff:g id="active_device">%1$s</xliff:g></string>
|
||||||
<!-- Bluetooth settings. Message when connected to a device, except for phone/media audio. [CHAR LIMIT=40] -->
|
<!-- Bluetooth settings. Message when connected to a device, except for phone/media audio. [CHAR LIMIT=40] -->
|
||||||
<string name="bluetooth_connected_no_headset_no_a2dp">Connected (no phone or media)</string>
|
<string name="bluetooth_connected_no_headset_no_a2dp">Connected (no phone or media)<xliff:g id="active_device">%1$s</xliff:g></string>
|
||||||
|
|
||||||
<!-- Bluetooth settings. Message when connected to a device, showing remote device battery level. [CHAR LIMIT=NONE] -->
|
<!-- Bluetooth settings. Message when connected to a device, showing remote device battery level. [CHAR LIMIT=NONE] -->
|
||||||
<string name="bluetooth_connected_battery_level">Connected, battery <xliff:g id="battery_level_as_percentage">%1$s</xliff:g></string>
|
<string name="bluetooth_connected_battery_level">Connected, battery <xliff:g id="battery_level_as_percentage">%1$s</xliff:g><xliff:g id="active_device">%2$s</xliff:g></string>
|
||||||
<!-- Bluetooth settings. Message when connected to a device, except for phone audio, showing remote device battery level. [CHAR LIMIT=NONE] -->
|
<!-- Bluetooth settings. Message when connected to a device, except for phone audio, showing remote device battery level. [CHAR LIMIT=NONE] -->
|
||||||
<string name="bluetooth_connected_no_headset_battery_level">Connected (no phone), battery <xliff:g id="battery_level_as_percentage">%1$s</xliff:g></string>
|
<string name="bluetooth_connected_no_headset_battery_level">Connected (no phone), battery <xliff:g id="battery_level_as_percentage">%1$s</xliff:g><xliff:g id="active_device">%2$s</xliff:g></string>
|
||||||
<!-- Bluetooth settings. Message when connected to a device, except for media audio, showing remote device battery level. [CHAR LIMIT=NONE] -->
|
<!-- Bluetooth settings. Message when connected to a device, except for media audio, showing remote device battery level. [CHAR LIMIT=NONE] -->
|
||||||
<string name="bluetooth_connected_no_a2dp_battery_level">Connected (no media), battery <xliff:g id="battery_level_as_percentage">%1$s</xliff:g></string>
|
<string name="bluetooth_connected_no_a2dp_battery_level">Connected (no media), battery <xliff:g id="battery_level_as_percentage">%1$s</xliff:g><xliff:g id="active_device">%2$s</xliff:g></string>
|
||||||
<!-- Bluetooth settings. Message when connected to a device, except for phone/media audio, showing remote device battery level. [CHAR LIMIT=NONE] -->
|
<!-- Bluetooth settings. Message when connected to a device, except for phone/media audio, showing remote device battery level. [CHAR LIMIT=NONE] -->
|
||||||
<string name="bluetooth_connected_no_headset_no_a2dp_battery_level">Connected (no phone or media), battery <xliff:g id="battery_level_as_percentage">%1$s</xliff:g></string>
|
<string name="bluetooth_connected_no_headset_no_a2dp_battery_level">Connected (no phone or media), battery <xliff:g id="battery_level_as_percentage">%1$s</xliff:g><xliff:g id="active_device">%2$s</xliff:g></string>
|
||||||
|
|
||||||
<!-- Bluetooth settings. The user-visible string that is used whenever referring to the A2DP profile. -->
|
<!-- Bluetooth settings. The user-visible string that is used whenever referring to the A2DP profile. -->
|
||||||
<string name="bluetooth_profile_a2dp">Media audio</string>
|
<string name="bluetooth_profile_a2dp">Media audio</string>
|
||||||
|
|||||||
@@ -940,60 +940,55 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
com.android.settingslib.Utils.formatPercentage(batteryLevel);
|
com.android.settingslib.Utils.formatPercentage(batteryLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: A temporary workaround solution using string description the device is active.
|
// Prepare the string for the Active Device summary
|
||||||
// Issue tracked by b/72317067 .
|
String[] activeDeviceStringsArray = mContext.getResources().getStringArray(
|
||||||
// An alternative solution would be visual indication.
|
R.array.bluetooth_audio_active_device_summaries);
|
||||||
// Intentionally not adding the strings to strings.xml for now:
|
String activeDeviceString = activeDeviceStringsArray[0]; // Default value: not active
|
||||||
// 1) If this is just a short-term solution, no need to waste translation effort
|
|
||||||
// 2) The number of strings with all possible combinations becomes enormously large.
|
|
||||||
// If string description becomes part of the final solution, we MUST NOT
|
|
||||||
// concatenate the strings here: this does not translate well.
|
|
||||||
String activeString = null;
|
|
||||||
if (mIsActiveDeviceA2dp && mIsActiveDeviceHeadset) {
|
if (mIsActiveDeviceA2dp && mIsActiveDeviceHeadset) {
|
||||||
activeString = ", active";
|
activeDeviceString = activeDeviceStringsArray[1]; // Active for Media and Phone
|
||||||
} else {
|
} else {
|
||||||
if (mIsActiveDeviceA2dp) {
|
if (mIsActiveDeviceA2dp) {
|
||||||
activeString = ", active(media)";
|
activeDeviceString = activeDeviceStringsArray[2]; // Active for Media only
|
||||||
}
|
}
|
||||||
if (mIsActiveDeviceHeadset) {
|
if (mIsActiveDeviceHeadset) {
|
||||||
activeString = ", active(phone)";
|
activeDeviceString = activeDeviceStringsArray[3]; // Active for Phone only
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (activeString == null) activeString = "";
|
|
||||||
|
|
||||||
if (profileConnected) {
|
if (profileConnected) {
|
||||||
if (a2dpNotConnected && hfpNotConnected) {
|
if (a2dpNotConnected && hfpNotConnected) {
|
||||||
if (batteryLevelPercentageString != null) {
|
if (batteryLevelPercentageString != null) {
|
||||||
return mContext.getString(
|
return mContext.getString(
|
||||||
R.string.bluetooth_connected_no_headset_no_a2dp_battery_level,
|
R.string.bluetooth_connected_no_headset_no_a2dp_battery_level,
|
||||||
batteryLevelPercentageString) + activeString;
|
batteryLevelPercentageString, activeDeviceString);
|
||||||
} else {
|
} else {
|
||||||
return mContext.getString(R.string.bluetooth_connected_no_headset_no_a2dp) +
|
return mContext.getString(R.string.bluetooth_connected_no_headset_no_a2dp,
|
||||||
activeString;
|
activeDeviceString);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (a2dpNotConnected) {
|
} else if (a2dpNotConnected) {
|
||||||
if (batteryLevelPercentageString != null) {
|
if (batteryLevelPercentageString != null) {
|
||||||
return mContext.getString(R.string.bluetooth_connected_no_a2dp_battery_level,
|
return mContext.getString(R.string.bluetooth_connected_no_a2dp_battery_level,
|
||||||
batteryLevelPercentageString) + activeString;
|
batteryLevelPercentageString, activeDeviceString);
|
||||||
} else {
|
} else {
|
||||||
return mContext.getString(R.string.bluetooth_connected_no_a2dp) + activeString;
|
return mContext.getString(R.string.bluetooth_connected_no_a2dp,
|
||||||
|
activeDeviceString);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (hfpNotConnected) {
|
} else if (hfpNotConnected) {
|
||||||
if (batteryLevelPercentageString != null) {
|
if (batteryLevelPercentageString != null) {
|
||||||
return mContext.getString(R.string.bluetooth_connected_no_headset_battery_level,
|
return mContext.getString(R.string.bluetooth_connected_no_headset_battery_level,
|
||||||
batteryLevelPercentageString) + activeString;
|
batteryLevelPercentageString, activeDeviceString);
|
||||||
} else {
|
} else {
|
||||||
return mContext.getString(R.string.bluetooth_connected_no_headset)
|
return mContext.getString(R.string.bluetooth_connected_no_headset,
|
||||||
+ activeString;
|
activeDeviceString);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (batteryLevelPercentageString != null) {
|
if (batteryLevelPercentageString != null) {
|
||||||
return mContext.getString(R.string.bluetooth_connected_battery_level,
|
return mContext.getString(R.string.bluetooth_connected_battery_level,
|
||||||
batteryLevelPercentageString) + activeString;
|
batteryLevelPercentageString, activeDeviceString);
|
||||||
} else {
|
} else {
|
||||||
return mContext.getString(R.string.bluetooth_connected) + activeString;
|
return mContext.getString(R.string.bluetooth_connected, activeDeviceString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,22 +80,12 @@ public class CachedBluetoothDeviceTest {
|
|||||||
doAnswer((invocation) -> mBatteryLevel).when(mCachedDevice).getBatteryLevel();
|
doAnswer((invocation) -> mBatteryLevel).when(mCachedDevice).getBatteryLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test to verify the current test context object works so that we are not checking null
|
|
||||||
* against null
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testContextMock() {
|
|
||||||
assertThat(mContext.getString(R.string.bluetooth_connected)).isEqualTo("Connected");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetConnectionSummary_testSingleProfileConnectDisconnect() {
|
public void testGetConnectionSummary_testSingleProfileConnectDisconnect() {
|
||||||
// Test without battery level
|
// Test without battery level
|
||||||
// Set PAN profile to be connected and test connection state summary
|
// Set PAN profile to be connected and test connection state summary
|
||||||
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_CONNECTED);
|
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(mContext.getString(
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected");
|
||||||
R.string.bluetooth_connected));
|
|
||||||
|
|
||||||
// Set PAN profile to be disconnected and test connection state summary
|
// Set PAN profile to be disconnected and test connection state summary
|
||||||
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_DISCONNECTED);
|
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
@@ -105,9 +95,7 @@ public class CachedBluetoothDeviceTest {
|
|||||||
mBatteryLevel = 10;
|
mBatteryLevel = 10;
|
||||||
// Set PAN profile to be connected and test connection state summary
|
// Set PAN profile to be connected and test connection state summary
|
||||||
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_CONNECTED);
|
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(mContext.getString(
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, battery 10%");
|
||||||
R.string.bluetooth_connected_battery_level,
|
|
||||||
com.android.settingslib.Utils.formatPercentage(mBatteryLevel)));
|
|
||||||
|
|
||||||
// Set PAN profile to be disconnected and test connection state summary
|
// Set PAN profile to be disconnected and test connection state summary
|
||||||
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_DISCONNECTED);
|
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
@@ -118,8 +106,7 @@ public class CachedBluetoothDeviceTest {
|
|||||||
|
|
||||||
// Set PAN profile to be connected and test connection state summary
|
// Set PAN profile to be connected and test connection state summary
|
||||||
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_CONNECTED);
|
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(mContext.getString(
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected");
|
||||||
R.string.bluetooth_connected));
|
|
||||||
|
|
||||||
// Set PAN profile to be disconnected and test connection state summary
|
// Set PAN profile to be disconnected and test connection state summary
|
||||||
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_DISCONNECTED);
|
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
@@ -134,34 +121,140 @@ public class CachedBluetoothDeviceTest {
|
|||||||
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
|
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
|
mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_CONNECTED);
|
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(mContext.getString(
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, battery 10%");
|
||||||
R.string.bluetooth_connected_battery_level,
|
|
||||||
com.android.settingslib.Utils.formatPercentage(mBatteryLevel)));
|
|
||||||
|
|
||||||
// Disconnect HFP only and test connection state summary
|
// Disconnect HFP only and test connection state summary
|
||||||
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(mContext.getString(
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
|
||||||
R.string.bluetooth_connected_no_headset_battery_level,
|
"Connected (no phone), battery 10%");
|
||||||
com.android.settingslib.Utils.formatPercentage(mBatteryLevel)));
|
|
||||||
|
|
||||||
// Disconnect A2DP only and test connection state summary
|
// Disconnect A2DP only and test connection state summary
|
||||||
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
|
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(mContext.getString(
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
|
||||||
R.string.bluetooth_connected_no_a2dp_battery_level,
|
"Connected (no media), battery 10%");
|
||||||
com.android.settingslib.Utils.formatPercentage(mBatteryLevel)));
|
|
||||||
|
|
||||||
// Disconnect both HFP and A2DP and test connection state summary
|
// Disconnect both HFP and A2DP and test connection state summary
|
||||||
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(mContext.getString(
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
|
||||||
R.string.bluetooth_connected_no_headset_no_a2dp_battery_level,
|
"Connected (no phone or media), battery 10%");
|
||||||
com.android.settingslib.Utils.formatPercentage(mBatteryLevel)));
|
|
||||||
|
|
||||||
// Disconnect all profiles and test connection state summary
|
// Disconnect all profiles and test connection state summary
|
||||||
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_DISCONNECTED);
|
mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
assertThat(mCachedDevice.getConnectionSummary()).isNull();
|
assertThat(mCachedDevice.getConnectionSummary()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetConnectionSummary_testSingleProfileActiveDeviceA2dp() {
|
||||||
|
// Test without battery level
|
||||||
|
// Set A2DP profile to be connected and test connection state summary
|
||||||
|
mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected");
|
||||||
|
|
||||||
|
// Set device as Active for A2DP and test connection state summary
|
||||||
|
mCachedDevice.setActiveDevice(true, BluetoothProfile.A2DP);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, active(media)");
|
||||||
|
|
||||||
|
// Test with battery level
|
||||||
|
mBatteryLevel = 10;
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
|
||||||
|
"Connected, battery 10%, active(media)");
|
||||||
|
|
||||||
|
// Set A2DP profile to be disconnected and test connection state summary
|
||||||
|
mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isNull();
|
||||||
|
|
||||||
|
// Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level
|
||||||
|
mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
|
||||||
|
// Set A2DP profile to be connected, Active and test connection state summary
|
||||||
|
mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
|
mCachedDevice.setActiveDevice(true, BluetoothProfile.A2DP);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, active(media)");
|
||||||
|
|
||||||
|
// Set A2DP profile to be disconnected and test connection state summary
|
||||||
|
mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetConnectionSummary_testSingleProfileActiveDeviceHfp() {
|
||||||
|
// Test without battery level
|
||||||
|
// Set HFP profile to be connected and test connection state summary
|
||||||
|
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected");
|
||||||
|
|
||||||
|
// Set device as Active for HFP and test connection state summary
|
||||||
|
mCachedDevice.setActiveDevice(true, BluetoothProfile.HEADSET);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, active(phone)");
|
||||||
|
|
||||||
|
// Test with battery level
|
||||||
|
mBatteryLevel = 10;
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
|
||||||
|
"Connected, battery 10%, active(phone)");
|
||||||
|
|
||||||
|
// Set HFP profile to be disconnected and test connection state summary
|
||||||
|
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isNull();
|
||||||
|
|
||||||
|
// Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level
|
||||||
|
mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
|
||||||
|
// Set HFP profile to be connected, Active and test connection state summary
|
||||||
|
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
|
mCachedDevice.setActiveDevice(true, BluetoothProfile.HEADSET);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, active(phone)");
|
||||||
|
|
||||||
|
// Set HFP profile to be disconnected and test connection state summary
|
||||||
|
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetConnectionSummary_testMultipleProfilesActiveDevice() {
|
||||||
|
// Test without battery level
|
||||||
|
// Set A2DP and HFP profiles to be connected and test connection state summary
|
||||||
|
mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
|
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected");
|
||||||
|
|
||||||
|
// Set device as Active for A2DP and HFP and test connection state summary
|
||||||
|
mCachedDevice.setActiveDevice(true, BluetoothProfile.A2DP);
|
||||||
|
mCachedDevice.setActiveDevice(true, BluetoothProfile.HEADSET);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, active");
|
||||||
|
|
||||||
|
// Test with battery level
|
||||||
|
mBatteryLevel = 10;
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
|
||||||
|
"Connected, battery 10%, active");
|
||||||
|
|
||||||
|
// Disconnect A2DP only and test connection state summary
|
||||||
|
mCachedDevice.setActiveDevice(false, BluetoothProfile.A2DP);
|
||||||
|
mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
|
||||||
|
"Connected (no media), battery 10%, active(phone)");
|
||||||
|
|
||||||
|
// Disconnect HFP only and test connection state summary
|
||||||
|
mCachedDevice.setActiveDevice(false, BluetoothProfile.HEADSET);
|
||||||
|
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
|
mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
|
mCachedDevice.setActiveDevice(true, BluetoothProfile.A2DP);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
|
||||||
|
"Connected (no phone), battery 10%, active(media)");
|
||||||
|
|
||||||
|
// Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level
|
||||||
|
mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
|
||||||
|
// Set A2DP and HFP profiles to be connected, Active and test connection state summary
|
||||||
|
mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
|
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
|
||||||
|
mCachedDevice.setActiveDevice(true, BluetoothProfile.A2DP);
|
||||||
|
mCachedDevice.setActiveDevice(true, BluetoothProfile.HEADSET);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, active");
|
||||||
|
|
||||||
|
// Set A2DP and HFP profiles to be disconnected and test connection state summary
|
||||||
|
mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
|
mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
|
||||||
|
assertThat(mCachedDevice.getConnectionSummary()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeviceName_testAliasNameAvailable() {
|
public void testDeviceName_testAliasNameAvailable() {
|
||||||
when(mDevice.getAliasName()).thenReturn(DEVICE_ALIAS);
|
when(mDevice.getAliasName()).thenReturn(DEVICE_ALIAS);
|
||||||
|
|||||||
Reference in New Issue
Block a user