Loading src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java +4 −6 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll profilePref.setChecked(profile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED); } else { profilePref.setChecked(profile.isPreferred(device)); profilePref.setChecked(profile.isEnabled(device)); } if (profile instanceof A2dpProfile) { Loading @@ -117,7 +117,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll SwitchPreference highQualityPref = (SwitchPreference) mProfilesContainer.findPreference( HIGH_QUALITY_AUDIO_PREF_TAG); if (highQualityPref != null) { if (a2dp.isPreferred(device) && a2dp.supportsHighQualityAudio(device)) { if (a2dp.isEnabled(device) && a2dp.supportsHighQualityAudio(device)) { highQualityPref.setVisible(true); highQualityPref.setTitle(a2dp.getHighQualityAudioOptionLabel(device)); highQualityPref.setChecked(a2dp.isHighQualityAudioEnabled(device)); Loading @@ -142,8 +142,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll if (profile instanceof MapProfile) { bluetoothDevice.setMessageAccessPermission(BluetoothDevice.ACCESS_ALLOWED); } profile.setPreferred(bluetoothDevice, true); mCachedDevice.connectProfile(profile); profile.setEnabled(bluetoothDevice, true); } /** Loading @@ -151,8 +150,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll */ private void disableProfile(LocalBluetoothProfile profile) { final BluetoothDevice bluetoothDevice = mCachedDevice.getDevice(); mCachedDevice.disconnect(profile); profile.setPreferred(bluetoothDevice, false); profile.setEnabled(bluetoothDevice, false); if (profile instanceof MapProfile) { bluetoothDevice.setMessageAccessPermission(BluetoothDevice.ACCESS_REJECTED); } else if (profile instanceof PbapServerProfile) { Loading tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java +15 −26 Original line number Diff line number Diff line Loading @@ -114,18 +114,6 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont return true; } @Override public boolean connect(BluetoothDevice device) { mConnectedDevices.add(device); return true; } @Override public boolean disconnect(BluetoothDevice device) { mConnectedDevices.remove(device); return false; } @Override public int getConnectionStatus(BluetoothDevice device) { if (mConnectedDevices.contains(device)) { Loading @@ -136,20 +124,21 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont } @Override public boolean isPreferred(BluetoothDevice device) { public boolean isEnabled(BluetoothDevice device) { return mPreferred.getOrDefault(device, false); } @Override public int getPreferred(BluetoothDevice device) { return isPreferred(device) ? BluetoothProfile.CONNECTION_POLICY_ALLOWED public int getConnectionPolicy(BluetoothDevice device) { return isEnabled(device) ? BluetoothProfile.CONNECTION_POLICY_ALLOWED : BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; } @Override public void setPreferred(BluetoothDevice device, boolean preferred) { mPreferred.put(device, preferred); public boolean setEnabled(BluetoothDevice device, boolean enabled) { mPreferred.put(device, enabled); return true; } @Override Loading Loading @@ -192,7 +181,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont private LocalBluetoothProfile addFakeProfile(int profileNameResId, boolean deviceIsPreferred) { LocalBluetoothProfile profile = new FakeBluetoothProfile(mContext, profileNameResId); profile.setPreferred(mDevice, deviceIsPreferred); profile.setEnabled(mDevice, deviceIsPreferred); mConnectableProfiles.add(profile); when(mProfileManager.getProfileByName(eq(profile.toString()))).thenReturn(profile); return profile; Loading Loading @@ -266,7 +255,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont assertThat(pref.isChecked()).isTrue(); pref.performClick(); assertThat(pref.isChecked()).isFalse(); assertThat(mConnectableProfiles.get(0).isPreferred(mDevice)).isFalse(); assertThat(mConnectableProfiles.get(0).isEnabled(mDevice)).isFalse(); // Make sure no new preferences were added. assertThat(mProfiles.getPreferenceCount()).isEqualTo(2); Loading @@ -274,7 +263,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont // Clicking the pref again should make the profile once again preferred. pref.performClick(); assertThat(pref.isChecked()).isTrue(); assertThat(mConnectableProfiles.get(0).isPreferred(mDevice)).isTrue(); assertThat(mConnectableProfiles.get(0).isEnabled(mDevice)).isTrue(); // Make sure we still haven't gotten any new preferences added. assertThat(mProfiles.getPreferenceCount()).isEqualTo(2); Loading Loading @@ -364,7 +353,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont mContext.getString(R.string.bluetooth_profile_a2dp_high_quality_unknown_codec)); when(profile.supportsHighQualityAudio(mDevice)).thenReturn(supportsHighQualityAudio); when(profile.isHighQualityAudioEnabled(mDevice)).thenReturn(highQualityAudioEnabled); when(profile.isPreferred(mDevice)).thenReturn(preferred); when(profile.isEnabled(mDevice)).thenReturn(preferred); when(profile.isProfileReady()).thenReturn(true); mConnectableProfiles.add(profile); return profile; Loading Loading @@ -426,8 +415,8 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont SwitchPreference audioPref = (SwitchPreference) mScreen.findPreference(audioProfile.toString()); audioPref.performClick(); verify(audioProfile).setPreferred(mDevice, false); when(audioProfile.isPreferred(mDevice)).thenReturn(false); verify(audioProfile).setEnabled(mDevice, false); when(audioProfile.isEnabled(mDevice)).thenReturn(false); mController.onDeviceAttributesChanged(); assertThat(audioPref.isVisible()).isTrue(); SwitchPreference highQualityAudioPref = getHighQualityAudioPref(); Loading @@ -435,8 +424,8 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont // And re-enabling media audio should make high quality switch to reappear. audioPref.performClick(); verify(audioProfile).setPreferred(mDevice, true); when(audioProfile.isPreferred(mDevice)).thenReturn(true); verify(audioProfile).setEnabled(mDevice, true); when(audioProfile.isEnabled(mDevice)).thenReturn(true); mController.onDeviceAttributesChanged(); highQualityAudioPref = getHighQualityAudioPref(); assertThat(highQualityAudioPref.isVisible()).isTrue(); Loading Loading
src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java +4 −6 Original line number Diff line number Diff line Loading @@ -109,7 +109,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll profilePref.setChecked(profile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED); } else { profilePref.setChecked(profile.isPreferred(device)); profilePref.setChecked(profile.isEnabled(device)); } if (profile instanceof A2dpProfile) { Loading @@ -117,7 +117,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll SwitchPreference highQualityPref = (SwitchPreference) mProfilesContainer.findPreference( HIGH_QUALITY_AUDIO_PREF_TAG); if (highQualityPref != null) { if (a2dp.isPreferred(device) && a2dp.supportsHighQualityAudio(device)) { if (a2dp.isEnabled(device) && a2dp.supportsHighQualityAudio(device)) { highQualityPref.setVisible(true); highQualityPref.setTitle(a2dp.getHighQualityAudioOptionLabel(device)); highQualityPref.setChecked(a2dp.isHighQualityAudioEnabled(device)); Loading @@ -142,8 +142,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll if (profile instanceof MapProfile) { bluetoothDevice.setMessageAccessPermission(BluetoothDevice.ACCESS_ALLOWED); } profile.setPreferred(bluetoothDevice, true); mCachedDevice.connectProfile(profile); profile.setEnabled(bluetoothDevice, true); } /** Loading @@ -151,8 +150,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll */ private void disableProfile(LocalBluetoothProfile profile) { final BluetoothDevice bluetoothDevice = mCachedDevice.getDevice(); mCachedDevice.disconnect(profile); profile.setPreferred(bluetoothDevice, false); profile.setEnabled(bluetoothDevice, false); if (profile instanceof MapProfile) { bluetoothDevice.setMessageAccessPermission(BluetoothDevice.ACCESS_REJECTED); } else if (profile instanceof PbapServerProfile) { Loading
tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java +15 −26 Original line number Diff line number Diff line Loading @@ -114,18 +114,6 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont return true; } @Override public boolean connect(BluetoothDevice device) { mConnectedDevices.add(device); return true; } @Override public boolean disconnect(BluetoothDevice device) { mConnectedDevices.remove(device); return false; } @Override public int getConnectionStatus(BluetoothDevice device) { if (mConnectedDevices.contains(device)) { Loading @@ -136,20 +124,21 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont } @Override public boolean isPreferred(BluetoothDevice device) { public boolean isEnabled(BluetoothDevice device) { return mPreferred.getOrDefault(device, false); } @Override public int getPreferred(BluetoothDevice device) { return isPreferred(device) ? BluetoothProfile.CONNECTION_POLICY_ALLOWED public int getConnectionPolicy(BluetoothDevice device) { return isEnabled(device) ? BluetoothProfile.CONNECTION_POLICY_ALLOWED : BluetoothProfile.CONNECTION_POLICY_FORBIDDEN; } @Override public void setPreferred(BluetoothDevice device, boolean preferred) { mPreferred.put(device, preferred); public boolean setEnabled(BluetoothDevice device, boolean enabled) { mPreferred.put(device, enabled); return true; } @Override Loading Loading @@ -192,7 +181,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont private LocalBluetoothProfile addFakeProfile(int profileNameResId, boolean deviceIsPreferred) { LocalBluetoothProfile profile = new FakeBluetoothProfile(mContext, profileNameResId); profile.setPreferred(mDevice, deviceIsPreferred); profile.setEnabled(mDevice, deviceIsPreferred); mConnectableProfiles.add(profile); when(mProfileManager.getProfileByName(eq(profile.toString()))).thenReturn(profile); return profile; Loading Loading @@ -266,7 +255,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont assertThat(pref.isChecked()).isTrue(); pref.performClick(); assertThat(pref.isChecked()).isFalse(); assertThat(mConnectableProfiles.get(0).isPreferred(mDevice)).isFalse(); assertThat(mConnectableProfiles.get(0).isEnabled(mDevice)).isFalse(); // Make sure no new preferences were added. assertThat(mProfiles.getPreferenceCount()).isEqualTo(2); Loading @@ -274,7 +263,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont // Clicking the pref again should make the profile once again preferred. pref.performClick(); assertThat(pref.isChecked()).isTrue(); assertThat(mConnectableProfiles.get(0).isPreferred(mDevice)).isTrue(); assertThat(mConnectableProfiles.get(0).isEnabled(mDevice)).isTrue(); // Make sure we still haven't gotten any new preferences added. assertThat(mProfiles.getPreferenceCount()).isEqualTo(2); Loading Loading @@ -364,7 +353,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont mContext.getString(R.string.bluetooth_profile_a2dp_high_quality_unknown_codec)); when(profile.supportsHighQualityAudio(mDevice)).thenReturn(supportsHighQualityAudio); when(profile.isHighQualityAudioEnabled(mDevice)).thenReturn(highQualityAudioEnabled); when(profile.isPreferred(mDevice)).thenReturn(preferred); when(profile.isEnabled(mDevice)).thenReturn(preferred); when(profile.isProfileReady()).thenReturn(true); mConnectableProfiles.add(profile); return profile; Loading Loading @@ -426,8 +415,8 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont SwitchPreference audioPref = (SwitchPreference) mScreen.findPreference(audioProfile.toString()); audioPref.performClick(); verify(audioProfile).setPreferred(mDevice, false); when(audioProfile.isPreferred(mDevice)).thenReturn(false); verify(audioProfile).setEnabled(mDevice, false); when(audioProfile.isEnabled(mDevice)).thenReturn(false); mController.onDeviceAttributesChanged(); assertThat(audioPref.isVisible()).isTrue(); SwitchPreference highQualityAudioPref = getHighQualityAudioPref(); Loading @@ -435,8 +424,8 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont // And re-enabling media audio should make high quality switch to reappear. audioPref.performClick(); verify(audioProfile).setPreferred(mDevice, true); when(audioProfile.isPreferred(mDevice)).thenReturn(true); verify(audioProfile).setEnabled(mDevice, true); when(audioProfile.isEnabled(mDevice)).thenReturn(true); mController.onDeviceAttributesChanged(); highQualityAudioPref = getHighQualityAudioPref(); assertThat(highQualityAudioPref.isVisible()).isTrue(); Loading