Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +16 −3 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHearingAid; import android.bluetooth.BluetoothLeAudio; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.content.Context; Loading Loading @@ -1131,9 +1130,18 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } /** * @return resource for android auto string that describes the connection state of this device. * See {@link #getCarConnectionSummary(boolean)} */ public String getCarConnectionSummary() { return getCarConnectionSummary(false); } /** * Returns android auto string that describes the connection state of this device. * * @param shortSummary {@code true} if need to return short version summary */ public String getCarConnectionSummary(boolean shortSummary) { boolean profileConnected = false; // at least one profile is connected boolean a2dpNotConnected = false; // A2DP is preferred but not connected boolean hfpNotConnected = false; // HFP is preferred but not connected Loading @@ -1151,6 +1159,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> BluetoothUtils.getConnectionStateSummary(connectionStatus)); case BluetoothProfile.STATE_CONNECTED: if (shortSummary) { return mContext.getString(BluetoothUtils.getConnectionStateSummary( connectionStatus), /* formatArgs= */ ""); } profileConnected = true; break; Loading Loading @@ -1248,7 +1260,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } return getBondState() == BluetoothDevice.BOND_BONDING ? mContext.getString(R.string.bluetooth_pairing) : null; mContext.getString(R.string.bluetooth_pairing) : mContext.getString(R.string.bluetooth_disconnected); } /** Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +33 −10 Original line number Diff line number Diff line Loading @@ -527,7 +527,7 @@ public class CachedBluetoothDeviceTest { // Set PAN profile to be disconnected and test connection state summary updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); // Test with battery level mBatteryLevel = 10; Loading @@ -537,7 +537,7 @@ public class CachedBluetoothDeviceTest { // Set PAN profile to be disconnected and test connection state summary updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); // Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN; Loading @@ -548,7 +548,7 @@ public class CachedBluetoothDeviceTest { // Set PAN profile to be disconnected and test connection state summary updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test Loading Loading @@ -579,7 +579,7 @@ public class CachedBluetoothDeviceTest { // Disconnect all profiles and test connection state summary updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test Loading @@ -600,7 +600,7 @@ public class CachedBluetoothDeviceTest { // Set A2DP profile to be disconnected and test connection state summary updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); // Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN; Loading @@ -611,7 +611,7 @@ public class CachedBluetoothDeviceTest { // Set A2DP profile to be disconnected and test connection state summary updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test Loading @@ -632,7 +632,7 @@ public class CachedBluetoothDeviceTest { // Set HFP profile to be disconnected and test connection state summary updateProfileStatus(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); // Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN; Loading @@ -643,7 +643,7 @@ public class CachedBluetoothDeviceTest { // Set HFP profile to be disconnected and test connection state summary updateProfileStatus(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test Loading @@ -660,7 +660,7 @@ public class CachedBluetoothDeviceTest { // Set Hearing Aid profile to be disconnected and test connection state summary mCachedDevice.onActiveDeviceChanged(false, BluetoothProfile.HEARING_AID); updateProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test Loading Loading @@ -707,9 +707,32 @@ public class CachedBluetoothDeviceTest { // Set A2DP and HFP profiles to be disconnected and test connection state summary updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); updateProfileStatus(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test public void getCarConnectionSummary_shortSummary_returnShortSummary() { // Test without battery level // Set A2DP profile to be connected and test connection state summary updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); assertThat(mCachedDevice.getCarConnectionSummary(true /* shortSummary */)) .isEqualTo("Connected"); // Set device as Active for A2DP and test connection state summary mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP); assertThat(mCachedDevice.getCarConnectionSummary(true /* shortSummary */)) .isEqualTo("Connected"); // Test with battery level mBatteryLevel = 10; assertThat(mCachedDevice.getCarConnectionSummary(true /* shortSummary */)) .isEqualTo("Connected"); // Set A2DP profile to be disconnected and test connection state summary updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary(true /* shortSummary */)) .isEqualTo("Disconnected"); } @Test public void deviceName_testAliasNameAvailable() { Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +16 −3 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHearingAid; import android.bluetooth.BluetoothLeAudio; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.content.Context; Loading Loading @@ -1131,9 +1130,18 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } /** * @return resource for android auto string that describes the connection state of this device. * See {@link #getCarConnectionSummary(boolean)} */ public String getCarConnectionSummary() { return getCarConnectionSummary(false); } /** * Returns android auto string that describes the connection state of this device. * * @param shortSummary {@code true} if need to return short version summary */ public String getCarConnectionSummary(boolean shortSummary) { boolean profileConnected = false; // at least one profile is connected boolean a2dpNotConnected = false; // A2DP is preferred but not connected boolean hfpNotConnected = false; // HFP is preferred but not connected Loading @@ -1151,6 +1159,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> BluetoothUtils.getConnectionStateSummary(connectionStatus)); case BluetoothProfile.STATE_CONNECTED: if (shortSummary) { return mContext.getString(BluetoothUtils.getConnectionStateSummary( connectionStatus), /* formatArgs= */ ""); } profileConnected = true; break; Loading Loading @@ -1248,7 +1260,8 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } return getBondState() == BluetoothDevice.BOND_BONDING ? mContext.getString(R.string.bluetooth_pairing) : null; mContext.getString(R.string.bluetooth_pairing) : mContext.getString(R.string.bluetooth_disconnected); } /** Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +33 −10 Original line number Diff line number Diff line Loading @@ -527,7 +527,7 @@ public class CachedBluetoothDeviceTest { // Set PAN profile to be disconnected and test connection state summary updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); // Test with battery level mBatteryLevel = 10; Loading @@ -537,7 +537,7 @@ public class CachedBluetoothDeviceTest { // Set PAN profile to be disconnected and test connection state summary updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); // Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN; Loading @@ -548,7 +548,7 @@ public class CachedBluetoothDeviceTest { // Set PAN profile to be disconnected and test connection state summary updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test Loading Loading @@ -579,7 +579,7 @@ public class CachedBluetoothDeviceTest { // Disconnect all profiles and test connection state summary updateProfileStatus(mPanProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test Loading @@ -600,7 +600,7 @@ public class CachedBluetoothDeviceTest { // Set A2DP profile to be disconnected and test connection state summary updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); // Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN; Loading @@ -611,7 +611,7 @@ public class CachedBluetoothDeviceTest { // Set A2DP profile to be disconnected and test connection state summary updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test Loading @@ -632,7 +632,7 @@ public class CachedBluetoothDeviceTest { // Set HFP profile to be disconnected and test connection state summary updateProfileStatus(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); // Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN; Loading @@ -643,7 +643,7 @@ public class CachedBluetoothDeviceTest { // Set HFP profile to be disconnected and test connection state summary updateProfileStatus(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test Loading @@ -660,7 +660,7 @@ public class CachedBluetoothDeviceTest { // Set Hearing Aid profile to be disconnected and test connection state summary mCachedDevice.onActiveDeviceChanged(false, BluetoothProfile.HEARING_AID); updateProfileStatus(mHearingAidProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test Loading Loading @@ -707,9 +707,32 @@ public class CachedBluetoothDeviceTest { // Set A2DP and HFP profiles to be disconnected and test connection state summary updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); updateProfileStatus(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary()).isNull(); assertThat(mCachedDevice.getCarConnectionSummary()).isEqualTo("Disconnected"); } @Test public void getCarConnectionSummary_shortSummary_returnShortSummary() { // Test without battery level // Set A2DP profile to be connected and test connection state summary updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); assertThat(mCachedDevice.getCarConnectionSummary(true /* shortSummary */)) .isEqualTo("Connected"); // Set device as Active for A2DP and test connection state summary mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP); assertThat(mCachedDevice.getCarConnectionSummary(true /* shortSummary */)) .isEqualTo("Connected"); // Test with battery level mBatteryLevel = 10; assertThat(mCachedDevice.getCarConnectionSummary(true /* shortSummary */)) .isEqualTo("Connected"); // Set A2DP profile to be disconnected and test connection state summary updateProfileStatus(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.getCarConnectionSummary(true /* shortSummary */)) .isEqualTo("Disconnected"); } @Test public void deviceName_testAliasNameAvailable() { Loading