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