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

Commit 5a2ad34b authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "VolumeShaper: Add to native IPlayer interface"

parents d05402ff 61081050
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <sys/types.h>

#include <media/VolumeShaper.h>
#include <utils/RefBase.h>
#include <utils/Errors.h>
#include <binder/IInterface.h>
@@ -45,6 +46,9 @@ public:

    virtual void setStartDelayMs(int delayMs) = 0;

    virtual void applyVolumeShaper(
            const sp<VolumeShaper::Configuration>& configuration,
            const sp<VolumeShaper::Operation>& operation) = 0;
};

// ----------------------------------------------------------------------------
+53 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ enum {
    SET_VOLUME = IBinder::FIRST_CALL_TRANSACTION + 3,
    SET_PAN    = IBinder::FIRST_CALL_TRANSACTION + 4,
    SET_START_DELAY_MS = IBinder::FIRST_CALL_TRANSACTION + 5,
    APPLY_VOLUME_SHAPER = IBinder::FIRST_CALL_TRANSACTION + 6,
};

class BpPlayer : public BpInterface<IPlayer>
@@ -88,6 +89,36 @@ public:
        data.writeInt32(delayMs);
        remote()->transact(SET_START_DELAY_MS, data, &reply);
    }

    virtual void applyVolumeShaper(
            const sp<VolumeShaper::Configuration>& configuration,
            const sp<VolumeShaper::Operation>& operation) {
        Parcel data, reply;
        data.writeInterfaceToken(IPlayer::getInterfaceDescriptor());

        status_t status = configuration.get() == nullptr
                ? data.writeInt32(0)
                :  data.writeInt32(1)
                    ?: configuration->writeToParcel(&data);
        if (status != NO_ERROR) {
            ALOGW("applyVolumeShaper failed configuration parceling: %d", status);
            return; // ignore error
        }

        status = operation.get() == nullptr
                ? status = data.writeInt32(0)
                : data.writeInt32(1)
                    ?: operation->writeToParcel(&data);
        if (status != NO_ERROR) {
            ALOGW("applyVolumeShaper failed operation parceling: %d", status);
            return; // ignore error
        }

        status = remote()->transact(APPLY_VOLUME_SHAPER, data, &reply);

        ALOGW_IF(status != NO_ERROR, "applyVolumeShaper failed transact: %d", status);
        return; // one way transaction, ignore error
    }
};

IMPLEMENT_META_INTERFACE(Player, "android.media.IPlayer");
@@ -128,6 +159,28 @@ status_t BnPlayer::onTransact(
            setStartDelayMs(data.readInt32());
            return NO_ERROR;
        } break;
        case APPLY_VOLUME_SHAPER: {
            CHECK_INTERFACE(IPlayer, data, reply);
            sp<VolumeShaper::Configuration> configuration;
            sp<VolumeShaper::Operation> operation;

            int32_t present;
            status_t status = data.readInt32(&present);
            if (status == NO_ERROR && present != 0) {
                configuration = new VolumeShaper::Configuration();
                status = configuration->readFromParcel(data);
            }
            status = status ?: data.readInt32(&present);
            if (status == NO_ERROR && present != 0) {
                operation = new VolumeShaper::Operation();
                status = operation->readFromParcel(data);
            }
            if (status == NO_ERROR) {
                // one way transaction, no error returned
                applyVolumeShaper(configuration, operation);
            }
            return NO_ERROR;
        } break;
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }