Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +23 −0 Original line number Diff line number Diff line Loading @@ -416,6 +416,29 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } } /** * Set this device as active device * @return true if at least one profile on this device is set to active, false otherwise */ public boolean setActive() { boolean result = false; A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile(); if (a2dpProfile != null && isConnectedProfile(a2dpProfile)) { if (a2dpProfile.setActiveDevice(getDevice())) { Log.i(TAG, "OnPreferenceClickListener: A2DP active device=" + this); result = true; } } HeadsetProfile headsetProfile = mProfileManager.getHeadsetProfile(); if ((headsetProfile != null) && isConnectedProfile(headsetProfile)) { if (headsetProfile.setActiveDevice(getDevice())) { Log.i(TAG, "OnPreferenceClickListener: Headset active device=" + this); result = true; } } return result; } void refreshName() { fetchName(); dispatchAttributesChanged(); Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -294,4 +294,24 @@ public class CachedBluetoothDeviceTest { // Verify new alias is returned on getName assertThat(cachedBluetoothDevice.getName()).isEqualTo(DEVICE_ALIAS_NEW); } @Test public void testSetActive() { when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile); when(mProfileManager.getHeadsetProfile()).thenReturn(mHfpProfile); when(mA2dpProfile.setActiveDevice(any(BluetoothDevice.class))).thenReturn(true); when(mHfpProfile.setActiveDevice(any(BluetoothDevice.class))).thenReturn(true); assertThat(mCachedDevice.setActive()).isFalse(); mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); assertThat(mCachedDevice.setActive()).isTrue(); mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED); assertThat(mCachedDevice.setActive()).isTrue(); mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.setActive()).isFalse(); } } Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +23 −0 Original line number Diff line number Diff line Loading @@ -416,6 +416,29 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> } } /** * Set this device as active device * @return true if at least one profile on this device is set to active, false otherwise */ public boolean setActive() { boolean result = false; A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile(); if (a2dpProfile != null && isConnectedProfile(a2dpProfile)) { if (a2dpProfile.setActiveDevice(getDevice())) { Log.i(TAG, "OnPreferenceClickListener: A2DP active device=" + this); result = true; } } HeadsetProfile headsetProfile = mProfileManager.getHeadsetProfile(); if ((headsetProfile != null) && isConnectedProfile(headsetProfile)) { if (headsetProfile.setActiveDevice(getDevice())) { Log.i(TAG, "OnPreferenceClickListener: Headset active device=" + this); result = true; } } return result; } void refreshName() { fetchName(); dispatchAttributesChanged(); Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -294,4 +294,24 @@ public class CachedBluetoothDeviceTest { // Verify new alias is returned on getName assertThat(cachedBluetoothDevice.getName()).isEqualTo(DEVICE_ALIAS_NEW); } @Test public void testSetActive() { when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile); when(mProfileManager.getHeadsetProfile()).thenReturn(mHfpProfile); when(mA2dpProfile.setActiveDevice(any(BluetoothDevice.class))).thenReturn(true); when(mHfpProfile.setActiveDevice(any(BluetoothDevice.class))).thenReturn(true); assertThat(mCachedDevice.setActive()).isFalse(); mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED); assertThat(mCachedDevice.setActive()).isTrue(); mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED); mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED); assertThat(mCachedDevice.setActive()).isTrue(); mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED); assertThat(mCachedDevice.setActive()).isFalse(); } }