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

Commit b99cc75f authored by Kevin Rocard's avatar Kevin Rocard
Browse files

Add application wide capture policy



Apps were previously forced to set their allowed capture policy from
either their manifest which is not flexible or from each track which is
a very fine grain but difficult when using libraries like exoplayer.

Thus add an application level policy set with AudioManager.

Test: atest android.media.cts.AudioPlaybackCaptureTest
Bug: 111453086
Change-Id: Ic890b5b041affea757fbd3f2707ff2ce18771828
Signed-off-by: default avatarKevin Rocard <krocard@google.com>
parent 68646ba6
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1133,6 +1133,12 @@ void AudioSystem::clearAudioConfigCache()
    }
}

status_t AudioSystem::setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags) {
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == nullptr) return PERMISSION_DENIED;
    return aps->setAllowedCapturePolicy(uid, flags);
}

bool AudioSystem::isOffloadSupported(const audio_offload_info_t& info)
{
    ALOGV("isOffloadSupported()");
+21 −2
Original line number Diff line number Diff line
@@ -101,7 +101,8 @@ enum {
    LIST_AUDIO_PRODUCT_STRATEGIES,
    GET_STRATEGY_FOR_ATTRIBUTES,
    LIST_AUDIO_VOLUME_GROUPS,
    GET_VOLUME_GROUP_FOR_ATTRIBUTES
    GET_VOLUME_GROUP_FOR_ATTRIBUTES,
    SET_ALLOWED_CAPTURE_POLICY,
};

#define MAX_ITEMS_PER_LIST 1024
@@ -603,6 +604,15 @@ public:
        return status;
    }

    status_t setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags) override {
        Parcel data, reply;
        data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
        data.writeInt32(uid);
        data.writeInt32(flags);
        remote()->transact(SET_ALLOWED_CAPTURE_POLICY, data, &reply);
        return reply.readInt32();
    }

    virtual bool isOffloadSupported(const audio_offload_info_t& info)
    {
        Parcel data, reply;
@@ -2285,6 +2295,15 @@ status_t BnAudioPolicyService::onTransact(
            return NO_ERROR;
        }

        case SET_ALLOWED_CAPTURE_POLICY: {
            CHECK_INTERFACE(IAudioPolicyService, data, reply);
            uid_t uid = data.readInt32();
            audio_flags_mask_t flags = data.readInt32();
            status_t status = setAllowedCapturePolicy(uid, flags);
            reply->writeInt32(status);
            return NO_ERROR;
        }

        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
+2 −0
Original line number Diff line number Diff line
@@ -299,6 +299,8 @@ public:

    static status_t setLowRamDevice(bool isLowRamDevice, int64_t totalMemory);

    static status_t setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags);

    // Check if hw offload is possible for given format, stream type, sample rate,
    // bit rate, duration, video and streaming or offload property is enabled
    static bool isOffloadSupported(const audio_offload_info_t& info);
+1 −0
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ public:
                                            audio_unique_id_t* id) = 0;
    virtual status_t removeSourceDefaultEffect(audio_unique_id_t id) = 0;
    virtual status_t removeStreamDefaultEffect(audio_unique_id_t id) = 0;
    virtual status_t setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags) = 0;
   // Check if offload is possible for given format, stream type, sample rate,
    // bit rate, duration, video and streaming or offload property is enabled
    virtual bool isOffloadSupported(const audio_offload_info_t& info) = 0;
+1 −0
Original line number Diff line number Diff line
@@ -198,6 +198,7 @@ public:
    //dump state
    virtual status_t    dump(int fd) = 0;

    virtual status_t setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t flags) = 0;
    virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo) = 0;
    virtual bool isDirectOutputSupported(const audio_config_base_t& config,
                                         const audio_attributes_t& attributes) = 0;
Loading