Search in sources :

Example 21 with BluetoothCodecConfig

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

the class DevelopmentSettings method writeBluetoothConfigurationOption.

private void writeBluetoothConfigurationOption(Preference preference, Object newValue) {
    String[] summaries;
    int index;
    int codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID;
    int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
    int sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_NONE;
    int bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE;
    int channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_NONE;
    long codecSpecific1Value = 0;
    long codecSpecific2Value = 0;
    long codecSpecific3Value = 0;
    long codecSpecific4Value = 0;
    // Codec Type
    String codecType = mBluetoothSelectA2dpCodec.getValue();
    if (preference == mBluetoothSelectA2dpCodec) {
        codecType = newValue.toString();
        index = mBluetoothSelectA2dpCodec.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_summaries);
            mBluetoothSelectA2dpCodec.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpCodec.findIndexOfValue(codecType);
    switch(index) {
        case 0:
            // Reset the priority of the current codec to default
            String oldValue = mBluetoothSelectA2dpCodec.getValue();
            switch(mBluetoothSelectA2dpCodec.findIndexOfValue(oldValue)) {
                case 0:
                    // No current codec
                    break;
                case 1:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
                    break;
                case 2:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC;
                    break;
                case 3:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
                    break;
                case 4:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
                    break;
                case 5:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
                    break;
                default:
                    break;
            }
            break;
        case 1:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 2:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 3:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 4:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 5:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 6:
            synchronized (mBluetoothA2dpLock) {
                if (mBluetoothA2dp != null) {
                    mBluetoothA2dp.enableOptionalCodecs();
                }
            }
            return;
        case 7:
            synchronized (mBluetoothA2dpLock) {
                if (mBluetoothA2dp != null) {
                    mBluetoothA2dp.disableOptionalCodecs();
                }
            }
            return;
        default:
            break;
    }
    // Sample Rate
    String sampleRate = mBluetoothSelectA2dpSampleRate.getValue();
    if (preference == mBluetoothSelectA2dpSampleRate) {
        sampleRate = newValue.toString();
        index = mBluetoothSelectA2dpSampleRate.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries);
            mBluetoothSelectA2dpSampleRate.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpSampleRate.findIndexOfValue(sampleRate);
    switch(index) {
        case 0:
            // Reset to default
            break;
        case 1:
            sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_44100;
            break;
        case 2:
            sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_48000;
            break;
        case 3:
            sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_88200;
            break;
        case 4:
            sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_96000;
            break;
        default:
            break;
    }
    // Bits Per Sample
    String bitsPerSample = mBluetoothSelectA2dpBitsPerSample.getValue();
    if (preference == mBluetoothSelectA2dpBitsPerSample) {
        bitsPerSample = newValue.toString();
        index = mBluetoothSelectA2dpBitsPerSample.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries);
            mBluetoothSelectA2dpBitsPerSample.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpBitsPerSample.findIndexOfValue(bitsPerSample);
    switch(index) {
        case 0:
            // Reset to default
            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;
    }
    // Channel Mode
    String channelMode = mBluetoothSelectA2dpChannelMode.getValue();
    if (preference == mBluetoothSelectA2dpChannelMode) {
        channelMode = newValue.toString();
        index = mBluetoothSelectA2dpChannelMode.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries);
            mBluetoothSelectA2dpChannelMode.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpChannelMode.findIndexOfValue(channelMode);
    switch(index) {
        case 0:
            // Reset to default
            break;
        case 1:
            channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_MONO;
            break;
        case 2:
            channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_STEREO;
            break;
        default:
            break;
    }
    // LDAC Playback Quality
    String ldacPlaybackQuality = mBluetoothSelectA2dpLdacPlaybackQuality.getValue();
    if (preference == mBluetoothSelectA2dpLdacPlaybackQuality) {
        ldacPlaybackQuality = newValue.toString();
        index = mBluetoothSelectA2dpLdacPlaybackQuality.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries);
            mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpLdacPlaybackQuality.findIndexOfValue(ldacPlaybackQuality);
    switch(index) {
        case 0:
        case 1:
        case 2:
        case 3:
            codecSpecific1Value = 1000 + index;
            break;
        default:
            break;
    }
    BluetoothCodecConfig codecConfig = new BluetoothCodecConfig(codecTypeValue, codecPriorityValue, sampleRateValue, bitsPerSampleValue, channelModeValue, codecSpecific1Value, codecSpecific2Value, codecSpecific3Value, codecSpecific4Value);
    synchronized (mBluetoothA2dpLock) {
        if (mBluetoothA2dp != null) {
            mBluetoothA2dp.setCodecConfigPreference(codecConfig);
        }
    }
}
Also used : BluetoothCodecConfig(android.bluetooth.BluetoothCodecConfig)

Example 22 with BluetoothCodecConfig

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

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)

Example 23 with BluetoothCodecConfig

use of android.bluetooth.BluetoothCodecConfig in project platform_packages_apps_Settings by BlissRoms.

the class DevelopmentSettings method writeBluetoothConfigurationOption.

private void writeBluetoothConfigurationOption(Preference preference, Object newValue) {
    String[] summaries;
    int index;
    int codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID;
    int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
    int sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_NONE;
    int bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE;
    int channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_NONE;
    long codecSpecific1Value = 0;
    long codecSpecific2Value = 0;
    long codecSpecific3Value = 0;
    long codecSpecific4Value = 0;
    // Codec Type
    String codecType = mBluetoothSelectA2dpCodec.getValue();
    if (preference == mBluetoothSelectA2dpCodec) {
        codecType = newValue.toString();
        index = mBluetoothSelectA2dpCodec.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_summaries);
            mBluetoothSelectA2dpCodec.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpCodec.findIndexOfValue(codecType);
    switch(index) {
        case 0:
            // Reset the priority of the current codec to default
            String oldValue = mBluetoothSelectA2dpCodec.getValue();
            switch(mBluetoothSelectA2dpCodec.findIndexOfValue(oldValue)) {
                case 0:
                    // No current codec
                    break;
                case 1:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
                    break;
                case 2:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC;
                    break;
                case 3:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
                    break;
                case 4:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
                    break;
                case 5:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
                    break;
                default:
                    break;
            }
            break;
        case 1:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 2:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 3:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 4:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 5:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 6:
            synchronized (mBluetoothA2dpLock) {
                if (mBluetoothA2dp != null) {
                    mBluetoothA2dp.enableOptionalCodecs();
                }
            }
            return;
        case 7:
            synchronized (mBluetoothA2dpLock) {
                if (mBluetoothA2dp != null) {
                    mBluetoothA2dp.disableOptionalCodecs();
                }
            }
            return;
        default:
            break;
    }
    // Sample Rate
    String sampleRate = mBluetoothSelectA2dpSampleRate.getValue();
    if (preference == mBluetoothSelectA2dpSampleRate) {
        sampleRate = newValue.toString();
        index = mBluetoothSelectA2dpSampleRate.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries);
            mBluetoothSelectA2dpSampleRate.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpSampleRate.findIndexOfValue(sampleRate);
    switch(index) {
        case 0:
            // Reset to default
            break;
        case 1:
            sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_44100;
            break;
        case 2:
            sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_48000;
            break;
        case 3:
            sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_88200;
            break;
        case 4:
            sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_96000;
            break;
        default:
            break;
    }
    // Bits Per Sample
    String bitsPerSample = mBluetoothSelectA2dpBitsPerSample.getValue();
    if (preference == mBluetoothSelectA2dpBitsPerSample) {
        bitsPerSample = newValue.toString();
        index = mBluetoothSelectA2dpBitsPerSample.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries);
            mBluetoothSelectA2dpBitsPerSample.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpBitsPerSample.findIndexOfValue(bitsPerSample);
    switch(index) {
        case 0:
            // Reset to default
            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;
    }
    // Channel Mode
    String channelMode = mBluetoothSelectA2dpChannelMode.getValue();
    if (preference == mBluetoothSelectA2dpChannelMode) {
        channelMode = newValue.toString();
        index = mBluetoothSelectA2dpChannelMode.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries);
            mBluetoothSelectA2dpChannelMode.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpChannelMode.findIndexOfValue(channelMode);
    switch(index) {
        case 0:
            // Reset to default
            break;
        case 1:
            channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_MONO;
            break;
        case 2:
            channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_STEREO;
            break;
        default:
            break;
    }
    // LDAC Playback Quality
    String ldacPlaybackQuality = mBluetoothSelectA2dpLdacPlaybackQuality.getValue();
    if (preference == mBluetoothSelectA2dpLdacPlaybackQuality) {
        ldacPlaybackQuality = newValue.toString();
        index = mBluetoothSelectA2dpLdacPlaybackQuality.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries);
            mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpLdacPlaybackQuality.findIndexOfValue(ldacPlaybackQuality);
    switch(index) {
        case 0:
        case 1:
        case 2:
        case 3:
            codecSpecific1Value = 1000 + index;
            break;
        default:
            break;
    }
    BluetoothCodecConfig codecConfig = new BluetoothCodecConfig(codecTypeValue, codecPriorityValue, sampleRateValue, bitsPerSampleValue, channelModeValue, codecSpecific1Value, codecSpecific2Value, codecSpecific3Value, codecSpecific4Value);
    synchronized (mBluetoothA2dpLock) {
        if (mBluetoothA2dp != null) {
            mBluetoothA2dp.setCodecConfigPreference(codecConfig);
        }
    }
}
Also used : BluetoothCodecConfig(android.bluetooth.BluetoothCodecConfig)

Example 24 with BluetoothCodecConfig

use of android.bluetooth.BluetoothCodecConfig in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AbstractBluetoothA2dpPreferenceController method onPreferenceChange.

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
    if (mBluetoothA2dp == null) {
        return false;
    }
    writeConfigurationValues(newValue);
    final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig();
    synchronized (mBluetoothA2dpConfigStore) {
        if (mBluetoothA2dp != null) {
            // Use current active device
            setCodecConfigPreference(null, codecConfig);
        }
    }
    // Because the setting is not persisted into permanent storage, we cannot call update state
    // here to update the preference.
    // Instead, we just assume it was set and update the preference here.
    final int index = mPreference.findIndexOfValue(newValue.toString());
    // We only want to append "Streaming" if not using default
    if (index == getDefaultIndex()) {
        mPreference.setSummary(mListSummaries[index]);
    } else {
        mPreference.setSummary(mContext.getResources().getString(STREAMING_LABEL_ID, mListSummaries[index]));
    }
    return true;
}
Also used : BluetoothCodecConfig(android.bluetooth.BluetoothCodecConfig)

Example 25 with BluetoothCodecConfig

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

the class DevelopmentSettings method writeBluetoothConfigurationOption.

private void writeBluetoothConfigurationOption(Preference preference, Object newValue) {
    String[] summaries;
    int index;
    int codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID;
    int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
    int sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_NONE;
    int bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE;
    int channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_NONE;
    long codecSpecific1Value = 0;
    long codecSpecific2Value = 0;
    long codecSpecific3Value = 0;
    long codecSpecific4Value = 0;
    // Codec Type
    String codecType = mBluetoothSelectA2dpCodec.getValue();
    if (preference == mBluetoothSelectA2dpCodec) {
        codecType = newValue.toString();
        index = mBluetoothSelectA2dpCodec.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_summaries);
            mBluetoothSelectA2dpCodec.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpCodec.findIndexOfValue(codecType);
    switch(index) {
        case 0:
            // Reset the priority of the current codec to default
            String oldValue = mBluetoothSelectA2dpCodec.getValue();
            switch(mBluetoothSelectA2dpCodec.findIndexOfValue(oldValue)) {
                case 0:
                    // No current codec
                    break;
                case 1:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
                    break;
                case 2:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC;
                    break;
                case 3:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
                    break;
                case 4:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
                    break;
                case 5:
                    codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
                    break;
                default:
                    break;
            }
            break;
        case 1:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 2:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 3:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 4:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 5:
            codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
            codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
            break;
        case 6:
            synchronized (mBluetoothA2dpLock) {
                if (mBluetoothA2dp != null) {
                    mBluetoothA2dp.enableOptionalCodecs();
                }
            }
            return;
        case 7:
            synchronized (mBluetoothA2dpLock) {
                if (mBluetoothA2dp != null) {
                    mBluetoothA2dp.disableOptionalCodecs();
                }
            }
            return;
        default:
            break;
    }
    // Sample Rate
    String sampleRate = mBluetoothSelectA2dpSampleRate.getValue();
    if (preference == mBluetoothSelectA2dpSampleRate) {
        sampleRate = newValue.toString();
        index = mBluetoothSelectA2dpSampleRate.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_sample_rate_summaries);
            mBluetoothSelectA2dpSampleRate.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpSampleRate.findIndexOfValue(sampleRate);
    switch(index) {
        case 0:
            // Reset to default
            break;
        case 1:
            sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_44100;
            break;
        case 2:
            sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_48000;
            break;
        case 3:
            sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_88200;
            break;
        case 4:
            sampleRateValue = BluetoothCodecConfig.SAMPLE_RATE_96000;
            break;
        default:
            break;
    }
    // Bits Per Sample
    String bitsPerSample = mBluetoothSelectA2dpBitsPerSample.getValue();
    if (preference == mBluetoothSelectA2dpBitsPerSample) {
        bitsPerSample = newValue.toString();
        index = mBluetoothSelectA2dpBitsPerSample.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_bits_per_sample_summaries);
            mBluetoothSelectA2dpBitsPerSample.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpBitsPerSample.findIndexOfValue(bitsPerSample);
    switch(index) {
        case 0:
            // Reset to default
            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;
    }
    // Channel Mode
    String channelMode = mBluetoothSelectA2dpChannelMode.getValue();
    if (preference == mBluetoothSelectA2dpChannelMode) {
        channelMode = newValue.toString();
        index = mBluetoothSelectA2dpChannelMode.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_channel_mode_summaries);
            mBluetoothSelectA2dpChannelMode.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpChannelMode.findIndexOfValue(channelMode);
    switch(index) {
        case 0:
            // Reset to default
            break;
        case 1:
            channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_MONO;
            break;
        case 2:
            channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_STEREO;
            break;
        default:
            break;
    }
    // LDAC Playback Quality
    String ldacPlaybackQuality = mBluetoothSelectA2dpLdacPlaybackQuality.getValue();
    if (preference == mBluetoothSelectA2dpLdacPlaybackQuality) {
        ldacPlaybackQuality = newValue.toString();
        index = mBluetoothSelectA2dpLdacPlaybackQuality.findIndexOfValue(newValue.toString());
        if (index >= 0) {
            summaries = getResources().getStringArray(R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries);
            mBluetoothSelectA2dpLdacPlaybackQuality.setSummary(summaries[index]);
        }
    }
    index = mBluetoothSelectA2dpLdacPlaybackQuality.findIndexOfValue(ldacPlaybackQuality);
    switch(index) {
        case 0:
        case 1:
        case 2:
        case 3:
            codecSpecific1Value = 1000 + index;
            break;
        default:
            break;
    }
    BluetoothCodecConfig codecConfig = new BluetoothCodecConfig(codecTypeValue, codecPriorityValue, sampleRateValue, bitsPerSampleValue, channelModeValue, codecSpecific1Value, codecSpecific2Value, codecSpecific3Value, codecSpecific4Value);
    synchronized (mBluetoothA2dpLock) {
        if (mBluetoothA2dp != null) {
            mBluetoothA2dp.setCodecConfigPreference(codecConfig);
        }
    }
}
Also used : BluetoothCodecConfig(android.bluetooth.BluetoothCodecConfig)

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