Search in sources :

Example 16 with BluetoothCodecConfig

use of android.bluetooth.BluetoothCodecConfig in project android_packages_apps_Settings by omnirom.

the class BluetoothBitPerSampleDialogPreferenceController method writeConfigurationValues.

@Override
protected void writeConfigurationValues(final int index) {
    int bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE;
    switch(index) {
        case 0:
            final BluetoothCodecConfig currentConfig = getCurrentCodecConfig();
            if (currentConfig != null) {
                bitsPerSampleValue = getHighestBitsPerSample(getSelectableByCodecType(currentConfig.getCodecType()));
            }
            break;
        case 1:
            bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_16;
            break;
        case 2:
            bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_24;
            break;
        case 3:
            bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_32;
            break;
        default:
            break;
    }
    mBluetoothA2dpConfigStore.setBitsPerSample(bitsPerSampleValue);
}
Also used : BluetoothCodecConfig(android.bluetooth.BluetoothCodecConfig)

Example 17 with BluetoothCodecConfig

use of android.bluetooth.BluetoothCodecConfig in project android_packages_apps_Settings by omnirom.

the class AbstractBluetoothDialogPreferenceController method onIndexUpdated.

@Override
public void onIndexUpdated(int index) {
    final BluetoothA2dp bluetoothA2dp = mBluetoothA2dp;
    if (bluetoothA2dp == null) {
        return;
    }
    writeConfigurationValues(index);
    final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig();
    BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
    if (activeDevice != null) {
        bluetoothA2dp.setCodecConfigPreference(activeDevice, codecConfig);
    }
    mPreference.setSummary(((BaseBluetoothDialogPreference) mPreference).generateSummary(index));
}
Also used : BluetoothA2dp(android.bluetooth.BluetoothA2dp) BluetoothDevice(android.bluetooth.BluetoothDevice) BluetoothCodecConfig(android.bluetooth.BluetoothCodecConfig)

Example 18 with BluetoothCodecConfig

use of android.bluetooth.BluetoothCodecConfig in project android_packages_apps_Settings by omnirom.

the class AbstractBluetoothDialogPreferenceController method initConfigStore.

private void initConfigStore() {
    final BluetoothCodecConfig config = getCurrentCodecConfig();
    if (config == null) {
        return;
    }
    mBluetoothA2dpConfigStore.setCodecType(config.getCodecType());
    mBluetoothA2dpConfigStore.setSampleRate(config.getSampleRate());
    mBluetoothA2dpConfigStore.setBitsPerSample(config.getBitsPerSample());
    mBluetoothA2dpConfigStore.setChannelMode(config.getChannelMode());
    mBluetoothA2dpConfigStore.setCodecPriority(CODEC_PRIORITY_HIGHEST);
    mBluetoothA2dpConfigStore.setCodecSpecific1Value(config.getCodecSpecific1());
}
Also used : BluetoothCodecConfig(android.bluetooth.BluetoothCodecConfig)

Example 19 with BluetoothCodecConfig

use of android.bluetooth.BluetoothCodecConfig in project android_packages_apps_Settings by omnirom.

the class AbstractBluetoothDialogPreferenceController method getSelectableByCodecType.

/**
 * To get the selectable A2DP config by codec type.
 *
 * @return {@link BluetoothCodecConfig}.
 */
protected BluetoothCodecConfig getSelectableByCodecType(int codecTypeValue) {
    BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
    if (activeDevice == null) {
        Log.d(TAG, "Unable to get selectable config. No active device.");
        return null;
    }
    final BluetoothCodecConfig[] configs = getSelectableConfigs(activeDevice);
    if (configs == null) {
        Log.d(TAG, "Unable to get selectable config. Selectable configs is empty.");
        return null;
    }
    for (BluetoothCodecConfig config : configs) {
        if (config.getCodecType() == codecTypeValue) {
            return config;
        }
    }
    Log.d(TAG, "Unable to find matching codec config, type is " + codecTypeValue);
    return null;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) BluetoothCodecConfig(android.bluetooth.BluetoothCodecConfig)

Example 20 with BluetoothCodecConfig

use of android.bluetooth.BluetoothCodecConfig in project android_packages_apps_Settings by SudaMod.

the class DevelopmentSettings method updateBluetoothA2dpConfigurationValues.

private void updateBluetoothA2dpConfigurationValues() {
    int index;
    String[] summaries;
    BluetoothCodecStatus codecStatus = null;
    BluetoothCodecConfig codecConfig = null;
    BluetoothCodecConfig[] codecsLocalCapabilities = null;
    BluetoothCodecConfig[] codecsSelectableCapabilities = null;
    String streaming;
    Resources resources = null;
    synchronized (mBluetoothA2dpLock) {
        if (mBluetoothA2dp != null) {
            codecStatus = mBluetoothA2dp.getCodecStatus();
            if (codecStatus != null) {
                codecConfig = codecStatus.getCodecConfig();
                codecsLocalCapabilities = codecStatus.getCodecsLocalCapabilities();
                codecsSelectableCapabilities = codecStatus.getCodecsSelectableCapabilities();
            }
        }
    }
    if (codecConfig == null) {
        return;
    }
    try {
        resources = getResources();
    } catch (IllegalStateException e) {
        return;
    }
    if (resources == null) {
        return;
    }
    // Update the Codec Type
    index = -1;
    switch(codecConfig.getCodecType()) {
        case BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC:
            index = 1;
            break;
        case BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC:
            index = 2;
            break;
        case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX:
            index = 3;
            break;
        case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD:
            index = 4;
            break;
        case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC:
            index = 5;
            break;
        case BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID:
        default:
            break;
    }
    if (index >= 0 && mBluetoothSelectA2dpCodec != null) {
        summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_summaries);
        streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
        mBluetoothSelectA2dpCodec.setSummary(streaming);
    }
    // Update the Sample Rate
    index = -1;
    switch(codecConfig.getSampleRate()) {
        case BluetoothCodecConfig.SAMPLE_RATE_44100:
            index = 1;
            break;
        case BluetoothCodecConfig.SAMPLE_RATE_48000:
            index = 2;
            break;
        case BluetoothCodecConfig.SAMPLE_RATE_88200:
            index = 3;
            break;
        case BluetoothCodecConfig.SAMPLE_RATE_96000:
            index = 4;
            break;
        case BluetoothCodecConfig.SAMPLE_RATE_176400:
        case BluetoothCodecConfig.SAMPLE_RATE_192000:
        case BluetoothCodecConfig.SAMPLE_RATE_NONE:
        default:
            break;
    }
    if (index >= 0 && mBluetoothSelectA2dpSampleRate != null) {
        summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries);
        streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
        mBluetoothSelectA2dpSampleRate.setSummary(streaming);
    }
    // Update the Bits Per Sample
    index = -1;
    switch(codecConfig.getBitsPerSample()) {
        case BluetoothCodecConfig.BITS_PER_SAMPLE_16:
            index = 1;
            break;
        case BluetoothCodecConfig.BITS_PER_SAMPLE_24:
            index = 2;
            break;
        case BluetoothCodecConfig.BITS_PER_SAMPLE_32:
            index = 3;
            break;
        case BluetoothCodecConfig.BITS_PER_SAMPLE_NONE:
        default:
            break;
    }
    if (index >= 0 && mBluetoothSelectA2dpBitsPerSample != null) {
        summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries);
        streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
        mBluetoothSelectA2dpBitsPerSample.setSummary(streaming);
    }
    // Update the Channel Mode
    index = -1;
    switch(codecConfig.getChannelMode()) {
        case BluetoothCodecConfig.CHANNEL_MODE_MONO:
            index = 1;
            break;
        case BluetoothCodecConfig.CHANNEL_MODE_STEREO:
            index = 2;
            break;
        case BluetoothCodecConfig.CHANNEL_MODE_NONE:
        default:
            break;
    }
    if (index >= 0 && mBluetoothSelectA2dpChannelMode != null) {
        summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries);
        streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
        mBluetoothSelectA2dpChannelMode.setSummary(streaming);
    }
    // Update the LDAC Playback Quality
    // The actual values are 0, 1, 2 - those are extracted
    // as mod-10 remainders of a larger value.
    // The reason is because within BluetoothCodecConfig we cannot use
    // a codec-specific value of zero.
    index = (int) codecConfig.getCodecSpecific1();
    if (index > 0) {
        index %= 10;
    } else {
        index = -1;
    }
    switch(index) {
        case 0:
        case 1:
        case 2:
        case 3:
            break;
        default:
            index = -1;
            break;
    }
    if (index >= 0 && mBluetoothSelectA2dpLdacPlaybackQuality != null) {
        summaries = resources.getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries);
        streaming = resources.getString(R.string.bluetooth_select_a2dp_codec_streaming_label, summaries[index]);
        mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(streaming);
    }
}
Also used : BluetoothCodecStatus(android.bluetooth.BluetoothCodecStatus) BluetoothCodecConfig(android.bluetooth.BluetoothCodecConfig) Resources(android.content.res.Resources)

Aggregations

BluetoothCodecConfig (android.bluetooth.BluetoothCodecConfig)45 BluetoothCodecStatus (android.bluetooth.BluetoothCodecStatus)17 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)7 Resources (android.content.res.Resources)6 BluetoothA2dpConfigStore (com.android.settings.development.BluetoothA2dpConfigStore)6 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)6 Before (org.junit.Before)6 BluetoothDevice (android.bluetooth.BluetoothDevice)5 BluetoothA2dp (android.bluetooth.BluetoothA2dp)2