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

Commit ba809b86 authored by Atneya Nair's avatar Atneya Nair
Browse files

Avoid callback promotion in set

We don't need to promote a wp to check if it is null. Avoiding
this promote prevents racy behavior when the callee passes themselves
during construction.

Test: atest AudioTrackTest
Change-Id: Ia1ba37e4f2bed5ea2da2858cec6a750d2bea3a12
parent b428b009
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -545,7 +545,6 @@ status_t AudioTrack::set(
    pid_t myPid;
    uid_t uid = VALUE_OR_FATAL(aidl2legacy_int32_t_uid_t(attributionSource.uid));
    pid_t pid = VALUE_OR_FATAL(aidl2legacy_int32_t_pid_t(attributionSource.pid));
    sp<IAudioTrackCallback> _callback = callback.promote();
    std::string errorMessage;
    // Note mPortId is not valid until the track is created, so omit mPortId in ALOG for set.
    ALOGV("%s(): streamType %d, sampleRate %u, format %#x, channelMask %#x, frameCount %zu, "
@@ -608,7 +607,7 @@ status_t AudioTrack::set(
    case TRANSFER_DEFAULT:
        if (sharedBuffer != 0) {
            transferType = TRANSFER_SHARED;
        } else if (_callback == nullptr|| threadCanCallJava) {
        } else if (callback == nullptr|| threadCanCallJava) {
            transferType = TRANSFER_SYNC;
        } else {
            transferType = TRANSFER_CALLBACK;
@@ -616,7 +615,7 @@ status_t AudioTrack::set(
        break;
    case TRANSFER_CALLBACK:
    case TRANSFER_SYNC_NOTIF_CALLBACK:
        if (_callback == nullptr || sharedBuffer != 0) {
        if (callback == nullptr || sharedBuffer != 0) {
            errorMessage = StringPrintf(
                    "%s: Transfer type %s but callback == nullptr || sharedBuffer != 0",
                    convertTransferToText(transferType), __func__);
@@ -771,7 +770,7 @@ status_t AudioTrack::set(
    mAuxEffectId = 0;
    mCallback = callback;

    if (_callback != nullptr) {
    if (callback != nullptr) {
        mAudioTrackThread = sp<AudioTrackThread>::make(*this);
        mAudioTrackThread->run("AudioTrack", ANDROID_PRIORITY_AUDIO, 0 /*stack*/);
        // thread begins in paused state, and will not reference us until start()