Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4988cd8 authored by Cheney Ni's avatar Cheney Ni Committed by android-build-merger
Browse files

Merge "Apply the new A2DP codec config only when passed the check with codec...

Merge "Apply the new A2DP codec config only when passed the check with codec status" am: 855cca25 am: f757cbea
am: 0e5a1585

Change-Id: I5bd7e390aa2e330d15e54cef6978cb6742388e83
parents 0363d74a 0e5a1585
Loading
Loading
Loading
Loading
+14 −26
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ class A2dpCodecConfig {

    void setCodecConfigPreference(BluetoothDevice device,
                                  BluetoothCodecStatus codecStatus,
                                  BluetoothCodecConfig codecConfig) {
                                  BluetoothCodecConfig newCodecConfig) {
        Objects.requireNonNull(codecStatus);

        // Check whether the codecConfig is selectable for this Bluetooth device.
@@ -66,34 +66,36 @@ class A2dpCodecConfig {
                codec.isMandatoryCodec())) {
            // Do not set codec preference to native if the selectableCodecs not contain mandatory
            // codec. The reason could be remote codec negotiation is not completed yet.
            Log.w(TAG, "Cannot find mandatory codec in selectableCodecs.");
            Log.w(TAG, "setCodecConfigPreference: must have mandatory codec before changing.");
            return;
        }
        if (!isCodecConfigSelectable(codecConfig, selectableCodecs)) {
            Log.w(TAG, "Codec is not selectable: " + codecConfig);
        if (!codecStatus.isCodecConfigSelectable(newCodecConfig)) {
            Log.w(TAG, "setCodecConfigPreference: invalid codec "
                    + Objects.toString(newCodecConfig));
            return;
        }

        // Check whether the codecConfig would change current codec config.
        int prioritizedCodecType = getPrioitizedCodecType(codecConfig, selectableCodecs);
        int prioritizedCodecType = getPrioitizedCodecType(newCodecConfig, selectableCodecs);
        BluetoothCodecConfig currentCodecConfig = codecStatus.getCodecConfig();
        if (prioritizedCodecType == currentCodecConfig.getCodecType()
                && (currentCodecConfig.getCodecType() != codecConfig.getCodecType()
                || currentCodecConfig.sameAudioFeedingParameters(codecConfig))) {
                && (prioritizedCodecType != newCodecConfig.getCodecType()
                || (currentCodecConfig.similarCodecFeedingParameters(newCodecConfig)
                && currentCodecConfig.sameCodecSpecificParameters(newCodecConfig)))) {
            // Same codec with same parameters, no need to send this request to native.
            Log.i(TAG, "setCodecConfigPreference: codec not changed.");
            Log.w(TAG, "setCodecConfigPreference: codec not changed.");
            return;
        }

        BluetoothCodecConfig[] codecConfigArray = new BluetoothCodecConfig[1];
        codecConfigArray[0] = codecConfig;
        codecConfigArray[0] = newCodecConfig;
        mA2dpNativeInterface.setCodecConfigPreference(device, codecConfigArray);
    }

    void enableOptionalCodecs(BluetoothDevice device, BluetoothCodecConfig currentCodecConfig) {
        if (currentCodecConfig != null && !currentCodecConfig.isMandatoryCodec()) {
            Log.i(TAG, "enableOptionalCodecs: already using optional codec: "
                    + currentCodecConfig.getCodecType());
            Log.i(TAG, "enableOptionalCodecs: already using optional codec "
                    + currentCodecConfig.getCodecName());
            return;
        }

@@ -115,7 +117,7 @@ class A2dpCodecConfig {

    void disableOptionalCodecs(BluetoothDevice device, BluetoothCodecConfig currentCodecConfig) {
        if (currentCodecConfig != null && currentCodecConfig.isMandatoryCodec()) {
            Log.i(TAG, "disableOptionalCodecs: already using mandatory codec");
            Log.i(TAG, "disableOptionalCodecs: already using mandatory codec.");
            return;
        }

@@ -150,20 +152,6 @@ class A2dpCodecConfig {
        return prioritizedCodecConfig.getCodecType();
    }

    // Check whether the codecConfig is selectable
    private static boolean isCodecConfigSelectable(BluetoothCodecConfig codecConfig,
            BluetoothCodecConfig[] selectableCodecs) {
        for (BluetoothCodecConfig config : selectableCodecs) {
            if (codecConfig.getCodecType() == config.getCodecType()
                    && (codecConfig.getSampleRate() & config.getSampleRate()) != 0
                    && (codecConfig.getBitsPerSample() & config.getBitsPerSample()) != 0
                    && (codecConfig.getChannelMode() & config.getChannelMode()) != 0) {
                return true;
            }
        }
        return false;
    }

    // Assign the A2DP Source codec config priorities
    private BluetoothCodecConfig[] assignCodecConfigPriorities() {
        Resources resources = mContext.getResources();
+10 −11
Original line number Diff line number Diff line
@@ -712,17 +712,16 @@ public class A2dpService extends ProfileService {
            device = mActiveDevice;
        }
        if (device == null) {
            Log.e(TAG, "Cannot set codec config preference: no active A2DP device");
            Log.e(TAG, "setCodecConfigPreference: Invalid device");
            return;
        }
        if (getSupportsOptionalCodecs(device) != BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED) {
            Log.e(TAG, "Cannot set codec config preference: not supported");
        if (codecConfig == null) {
            Log.e(TAG, "setCodecConfigPreference: Codec config can't be null");
            return;
        }

        BluetoothCodecStatus codecStatus = getCodecStatus(device);
        if (codecStatus == null) {
            Log.e(TAG, "Codec status is null on " + device);
            Log.e(TAG, "setCodecConfigPreference: Codec status is null");
            return;
        }
        mA2dpCodecConfig.setCodecConfigPreference(device, codecStatus, codecConfig);
@@ -744,16 +743,16 @@ public class A2dpService extends ProfileService {
            device = mActiveDevice;
        }
        if (device == null) {
            Log.e(TAG, "Cannot enable optional codecs: no active A2DP device");
            Log.e(TAG, "enableOptionalCodecs: Invalid device");
            return;
        }
        if (getSupportsOptionalCodecs(device) != BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED) {
            Log.e(TAG, "Cannot enable optional codecs: not supported");
            Log.e(TAG, "enableOptionalCodecs: No optional codecs");
            return;
        }
        BluetoothCodecStatus codecStatus = getCodecStatus(device);
        if (codecStatus == null) {
            Log.e(TAG, "Cannot enable optional codecs: codec status is null");
            Log.e(TAG, "enableOptionalCodecs: Codec status is null");
            return;
        }
        mA2dpCodecConfig.enableOptionalCodecs(device, codecStatus.getCodecConfig());
@@ -775,16 +774,16 @@ public class A2dpService extends ProfileService {
            device = mActiveDevice;
        }
        if (device == null) {
            Log.e(TAG, "Cannot disable optional codecs: no active A2DP device");
            Log.e(TAG, "disableOptionalCodecs: Invalid device");
            return;
        }
        if (getSupportsOptionalCodecs(device) != BluetoothA2dp.OPTIONAL_CODECS_SUPPORTED) {
            Log.e(TAG, "Cannot disable optional codecs: not supported");
            Log.e(TAG, "disableOptionalCodecs: No optional codecs");
            return;
        }
        BluetoothCodecStatus codecStatus = getCodecStatus(device);
        if (codecStatus == null) {
            Log.e(TAG, "Cannot disable optional codecs: codec status is null");
            Log.e(TAG, "disableOptionalCodecs: Codec status is null");
            return;
        }
        mA2dpCodecConfig.disableOptionalCodecs(device, codecStatus.getCodecConfig());
+702 −216

File changed.

Preview size limit exceeded, changes collapsed.