Search in sources :

Example 31 with A2dpProfile

use of com.android.settingslib.bluetooth.A2dpProfile in project android_packages_apps_Settings by LineageOS.

the class BluetoothDetailsProfilesController method maybeAddHighQualityAudioPref.

/**
 * This is a helper method to be called after adding a Preference for a profile. If that
 * profile happened to be A2dp and the device supports high quality audio, it will add a
 * separate preference for controlling whether to actually use high quality audio.
 *
 * @param profile the profile just added
 */
private void maybeAddHighQualityAudioPref(LocalBluetoothProfile profile) {
    if (!(profile instanceof A2dpProfile)) {
        return;
    }
    BluetoothDevice device = mCachedDevice.getDevice();
    A2dpProfile a2dp = (A2dpProfile) profile;
    if (a2dp.supportsHighQualityAudio(device)) {
        SwitchPreference highQualityAudioPref = new SwitchPreference(mProfilesContainer.getContext());
        highQualityAudioPref.setKey(HIGH_QUALITY_AUDIO_PREF_TAG);
        highQualityAudioPref.setVisible(false);
        highQualityAudioPref.setOnPreferenceClickListener(clickedPref -> {
            boolean enable = ((SwitchPreference) clickedPref).isChecked();
            a2dp.setHighQualityAudioEnabled(mCachedDevice.getDevice(), enable);
            return true;
        });
        mProfilesContainer.addPreference(highQualityAudioPref);
    }
}
Also used : A2dpProfile(com.android.settingslib.bluetooth.A2dpProfile) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) SwitchPreference(android.support.v14.preference.SwitchPreference)

Example 32 with A2dpProfile

use of com.android.settingslib.bluetooth.A2dpProfile in project android_packages_apps_Settings by LineageOS.

the class DeviceProfilesSettings method refreshProfilePreference.

private void refreshProfilePreference(CheckBox profilePref, LocalBluetoothProfile profile) {
    BluetoothDevice device = mCachedDevice.getDevice();
    // Gray out checkbox while connecting and disconnecting.
    profilePref.setEnabled(!mCachedDevice.isBusy());
    if (profile instanceof MapProfile) {
        profilePref.setChecked(mCachedDevice.getMessagePermissionChoice() == CachedBluetoothDevice.ACCESS_ALLOWED);
    } else if (profile instanceof PbapServerProfile) {
        profilePref.setChecked(mCachedDevice.getPhonebookPermissionChoice() == CachedBluetoothDevice.ACCESS_ALLOWED);
    } else if (profile instanceof PanProfile) {
        profilePref.setChecked(profile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED);
    } else {
        profilePref.setChecked(profile.isPreferred(device));
    }
    if (profile instanceof A2dpProfile) {
        A2dpProfile a2dpProfile = (A2dpProfile) profile;
        View v = mProfileContainer.findViewWithTag(HIGH_QUALITY_AUDIO_PREF_TAG);
        if (v instanceof CheckBox) {
            CheckBox highQualityPref = (CheckBox) v;
            highQualityPref.setText(a2dpProfile.getHighQualityAudioOptionLabel(device));
            highQualityPref.setChecked(a2dpProfile.isHighQualityAudioEnabled(device));
            if (a2dpProfile.isPreferred(device)) {
                v.setVisibility(View.VISIBLE);
                v.setEnabled(!mCachedDevice.isBusy());
            } else {
                v.setVisibility(View.GONE);
            }
        }
    }
}
Also used : MapProfile(com.android.settingslib.bluetooth.MapProfile) PbapServerProfile(com.android.settingslib.bluetooth.PbapServerProfile) A2dpProfile(com.android.settingslib.bluetooth.A2dpProfile) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) PanProfile(com.android.settingslib.bluetooth.PanProfile) CheckBox(android.widget.CheckBox) View(android.view.View) TextView(android.widget.TextView)

Example 33 with A2dpProfile

use of com.android.settingslib.bluetooth.A2dpProfile in project android_packages_apps_Settings by LineageOS.

the class BluetoothDetailsProfilesControllerTest method highQualityAudio_prefIsPresentWhenSupported.

@Test
public void highQualityAudio_prefIsPresentWhenSupported() {
    setupDevice(makeDefaultDeviceConfig());
    addMockA2dpProfile(true, true, true);
    showScreen(mController);
    SwitchPreference pref = getHighQualityAudioPref();
    assertThat(pref.getKey()).isEqualTo(BluetoothDetailsProfilesController.HIGH_QUALITY_AUDIO_PREF_TAG);
    // Make sure the preference works when clicked on.
    pref.performClick();
    A2dpProfile profile = (A2dpProfile) mConnectableProfiles.get(0);
    verify(profile).setHighQualityAudioEnabled(mDevice, false);
    pref.performClick();
    verify(profile).setHighQualityAudioEnabled(mDevice, true);
}
Also used : A2dpProfile(com.android.settingslib.bluetooth.A2dpProfile) SwitchPreference(android.support.v14.preference.SwitchPreference) Test(org.junit.Test)

Example 34 with A2dpProfile

use of com.android.settingslib.bluetooth.A2dpProfile in project android_packages_apps_Settings by LineageOS.

the class BluetoothDetailsProfilesControllerTest method addMockA2dpProfile.

private A2dpProfile addMockA2dpProfile(boolean preferred, boolean supportsHighQualityAudio, boolean highQualityAudioEnabled) {
    A2dpProfile profile = mock(A2dpProfile.class);
    when(mProfileManager.getProfileByName(eq(profile.toString()))).thenReturn(profile);
    when(profile.getNameResource(mDevice)).thenReturn(R.string.bluetooth_profile_a2dp);
    when(profile.getHighQualityAudioOptionLabel(mDevice)).thenReturn(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);
    mConnectableProfiles.add(profile);
    return profile;
}
Also used : A2dpProfile(com.android.settingslib.bluetooth.A2dpProfile)

Example 35 with A2dpProfile

use of com.android.settingslib.bluetooth.A2dpProfile in project android_packages_apps_Settings by omnirom.

the class DeviceProfilesSettings method addPreferencesForProfiles.

private void addPreferencesForProfiles() {
    mProfileContainer.removeAllViews();
    for (LocalBluetoothProfile profile : mCachedDevice.getConnectableProfiles()) {
        CheckBox pref = createProfilePreference(profile);
        mProfileContainer.addView(pref);
        if (profile instanceof A2dpProfile) {
            BluetoothDevice device = mCachedDevice.getDevice();
            A2dpProfile a2dpProfile = (A2dpProfile) profile;
            if (a2dpProfile.supportsHighQualityAudio(device)) {
                CheckBox highQualityPref = new CheckBox(getActivity());
                highQualityPref.setTag(HIGH_QUALITY_AUDIO_PREF_TAG);
                highQualityPref.setOnClickListener(v -> {
                    a2dpProfile.setHighQualityAudioEnabled(device, highQualityPref.isChecked());
                });
                highQualityPref.setVisibility(View.GONE);
                mProfileContainer.addView(highQualityPref);
            }
            refreshProfilePreference(pref, profile);
        }
    }
    final int pbapPermission = mCachedDevice.getPhonebookPermissionChoice();
    // Only provide PBAP cabability if the client device has requested PBAP.
    if (pbapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
        final PbapServerProfile psp = mManager.getProfileManager().getPbapProfile();
        CheckBox pbapPref = createProfilePreference(psp);
        mProfileContainer.addView(pbapPref);
    }
    final MapProfile mapProfile = mManager.getProfileManager().getMapProfile();
    final int mapPermission = mCachedDevice.getMessagePermissionChoice();
    if (mapPermission != CachedBluetoothDevice.ACCESS_UNKNOWN) {
        CheckBox mapPreference = createProfilePreference(mapProfile);
        mProfileContainer.addView(mapPreference);
    }
    showOrHideProfileGroup();
}
Also used : LocalBluetoothProfile(com.android.settingslib.bluetooth.LocalBluetoothProfile) PbapServerProfile(com.android.settingslib.bluetooth.PbapServerProfile) MapProfile(com.android.settingslib.bluetooth.MapProfile) A2dpProfile(com.android.settingslib.bluetooth.A2dpProfile) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) CheckBox(android.widget.CheckBox)

Aggregations

A2dpProfile (com.android.settingslib.bluetooth.A2dpProfile)57 BluetoothDevice (android.bluetooth.BluetoothDevice)29 CachedBluetoothDevice (com.android.settingslib.bluetooth.CachedBluetoothDevice)26 SwitchPreference (android.support.v14.preference.SwitchPreference)25 Test (org.junit.Test)21 MapProfile (com.android.settingslib.bluetooth.MapProfile)19 PbapServerProfile (com.android.settingslib.bluetooth.PbapServerProfile)19 PanProfile (com.android.settingslib.bluetooth.PanProfile)13 CheckBox (android.widget.CheckBox)12 SwitchPreference (androidx.preference.SwitchPreference)10 View (android.view.View)6 TextView (android.widget.TextView)6 LocalBluetoothProfile (com.android.settingslib.bluetooth.LocalBluetoothProfile)6