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

Commit 576ee0f3 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: fe448844 am: fe818506 am: 91270012
am: 81fdd727

Change-Id: I7404a075b06b9ce1323f93673d41fcce5cb20c11
parents aea88920 81fdd727
Loading
Loading
Loading
Loading
+14 −26
Original line number Original line Diff line number Diff line
@@ -57,7 +57,7 @@ class A2dpCodecConfig {


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


        // Check whether the codecConfig is selectable for this Bluetooth device.
        // Check whether the codecConfig is selectable for this Bluetooth device.
@@ -66,34 +66,36 @@ class A2dpCodecConfig {
                codec.isMandatoryCodec())) {
                codec.isMandatoryCodec())) {
            // Do not set codec preference to native if the selectableCodecs not contain mandatory
            // 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.
            // 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;
            return;
        }
        }
        if (!isCodecConfigSelectable(codecConfig, selectableCodecs)) {
        if (!codecStatus.isCodecConfigSelectable(newCodecConfig)) {
            Log.w(TAG, "Codec is not selectable: " + codecConfig);
            Log.w(TAG, "setCodecConfigPreference: invalid codec "
                    + Objects.toString(newCodecConfig));
            return;
            return;
        }
        }


        // Check whether the codecConfig would change current codec config.
        // Check whether the codecConfig would change current codec config.
        int prioritizedCodecType = getPrioitizedCodecType(codecConfig, selectableCodecs);
        int prioritizedCodecType = getPrioitizedCodecType(newCodecConfig, selectableCodecs);
        BluetoothCodecConfig currentCodecConfig = codecStatus.getCodecConfig();
        BluetoothCodecConfig currentCodecConfig = codecStatus.getCodecConfig();
        if (prioritizedCodecType == currentCodecConfig.getCodecType()
        if (prioritizedCodecType == currentCodecConfig.getCodecType()
                && (currentCodecConfig.getCodecType() != codecConfig.getCodecType()
                && (prioritizedCodecType != newCodecConfig.getCodecType()
                || currentCodecConfig.sameAudioFeedingParameters(codecConfig))) {
                || (currentCodecConfig.similarCodecFeedingParameters(newCodecConfig)
                && currentCodecConfig.sameCodecSpecificParameters(newCodecConfig)))) {
            // Same codec with same parameters, no need to send this request to native.
            // 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;
            return;
        }
        }


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


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


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


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


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

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

File changed.

Preview size limit exceeded, changes collapsed.