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

Commit 3fde6584 authored by Shubhasini Sugumaran's avatar Shubhasini Sugumaran
Browse files

hal: Add support to close streams on power policy callback



* Close existing streams during power policy disable callback

* Stop new streams from starting if current policy is in disabled state

Signed-off-by: default avatarShubhasini Sugumaran <quic_c_shubsu@quicinc.com>
Change-Id: I4960e336f03086d1322708e155a4a4f02098b3fb
parent 57b349f9
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -51,7 +51,11 @@ constexpr PowerComponent kMicComponent = PowerComponent::MICROPHONE;

}  // namespace

PowerPolicyClient::PowerPolicyClient() {
PowerPolicyClient::PowerPolicyClient(power_policy_init_config_t init_config) {

    fp_in_set_power_policy = init_config.fp_in_set_power_policy;
    fp_out_set_power_policy = init_config.fp_out_set_power_policy;

    plugin_handle = dlopen(LIB_AUDIO_HAL_PLUGIN, RTLD_NOW);
    if (plugin_handle == NULL) {
        LOG(ERROR) << "Failed to open plugin library";
@@ -89,12 +93,16 @@ ScopedAStatus PowerPolicyClient::onPolicyChanged(const CarPowerPolicy& powerPoli
    if (hasComponent(powerPolicy.enabledComponents, kAudioComponent)) {
        LOG(ERROR) << "Power policy: Audio component is enabled";
        disable = 0;

        fp_out_set_power_policy(!disable);
        if (hal_plugin_send_msg != NULL)
            hal_plugin_send_msg(AUDIO_HAL_PLUGIN_MSG_SILENT_MODE,
                                &disable, sizeof(disable));
    } else if (hasComponent(powerPolicy.disabledComponents, kAudioComponent)) {
        LOG(ERROR) << "Power policy: Audio component is disabled";
        disable = 1;

        fp_out_set_power_policy(!disable);
        if (hal_plugin_send_msg != NULL)
            hal_plugin_send_msg(AUDIO_HAL_PLUGIN_MSG_SILENT_MODE,
                                &disable, sizeof(disable));
@@ -103,11 +111,15 @@ ScopedAStatus PowerPolicyClient::onPolicyChanged(const CarPowerPolicy& powerPoli
    if (hasComponent(powerPolicy.enabledComponents, kMicComponent)) {
        LOG(ERROR) << "Power policy: Microphone component is enabled";
        disable = 0;

        fp_in_set_power_policy(!disable);
        if (hal_plugin_send_msg != NULL)
            hal_plugin_send_msg(AUDIO_HAL_PLUGIN_MSG_MIC_STATE,
                                &disable, sizeof(disable));
    } else if (hasComponent(powerPolicy.disabledComponents, kMicComponent)) {
        disable = 1;

        fp_in_set_power_policy(!disable);
        if (hal_plugin_send_msg != NULL)
            hal_plugin_send_msg(AUDIO_HAL_PLUGIN_MSG_MIC_STATE,
                                &disable, sizeof(disable));
+11 −1
Original line number Diff line number Diff line
@@ -32,11 +32,19 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
#include "audio_hal_plugin.h"

typedef int32_t (*hal_plugin_send_msg_t) (audio_hal_plugin_msg_type_t, void*, uint32_t);
typedef void (*fp_in_set_power_policy_t) (uint8_t);
typedef void (*fp_out_set_power_policy_t) (uint8_t);

typedef struct power_policy_init_config {
    fp_in_set_power_policy_t                      fp_in_set_power_policy;
    fp_out_set_power_policy_t                     fp_out_set_power_policy;
} power_policy_init_config_t;


class PowerPolicyClient
    : public ::android::frameworks::automotive::powerpolicy::PowerPolicyClientBase {
  public:
    explicit PowerPolicyClient();
    explicit PowerPolicyClient(power_policy_init_config init_config);
    ~PowerPolicyClient();

    void onInitFailed();
@@ -48,6 +56,8 @@ class PowerPolicyClient
  private:
        void* plugin_handle;
        hal_plugin_send_msg_t hal_plugin_send_msg;
        fp_out_set_power_policy_t fp_out_set_power_policy;
        fp_in_set_power_policy_t fp_in_set_power_policy;
};

#endif  // QTI_AUDIO_POWERPOLICYCLIENT_H_

hal/audio_extn/audio_extn.c

100755 → 100644
+5 −2
Original line number Diff line number Diff line
@@ -6526,10 +6526,13 @@ static void* power_policy_thread_func(void* arg __unused) {
        goto exit;
    }
    ALOGD("%s: Launching Power Policy Client", __func__);
    launch_power_policy();
    power_policy_init_config_t init_config;
    init_config.fp_in_set_power_policy = in_set_power_policy;
    init_config.fp_out_set_power_policy = out_set_power_policy;
    launch_power_policy(init_config);

exit:
    pthread_exit(NULL);
    return NULL;
}

static int power_policy_feature_init(bool is_feature_enabled)

hal/audio_extn/audio_extn.h

100755 → 100644
+11 −0
Original line number Diff line number Diff line
@@ -1428,6 +1428,17 @@ typedef struct synth_init_config {
} synth_init_config_t;
// END: SYNTH_HAL FEATURE ==================================================

// START: POWER_POLICY FEATURE ==================================================

typedef void (*fp_in_set_power_policy_t) (uint8_t);
typedef void (*fp_out_set_power_policy_t) (uint8_t);

typedef struct power_policy_init_config {
    fp_in_set_power_policy_t                      fp_in_set_power_policy;
    fp_out_set_power_policy_t                     fp_out_set_power_policy;
} power_policy_init_config_t;
// END: POWER_POLICY FEATURE ==================================================

bool audio_extn_edid_is_supported_sr(edid_audio_info* info, int sr);
bool audio_extn_edid_is_supported_bps(edid_audio_info* info, int bps);
int audio_extn_edid_get_highest_supported_sr(edid_audio_info* info);
+2 −2
Original line number Diff line number Diff line
@@ -34,11 +34,11 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/

extern "C" {

    int launchPowerPolicyClient() {
    int launchPowerPolicyClient(power_policy_init_config_t init_config) {
        ALOGD("%s: power policy launcher called", __func__);
        ABinderProcess_setThreadPoolMaxThreadCount(0);
        std::shared_ptr<PowerPolicyClient> powerPolicyClient =
                ::ndk::SharedRefBase::make<PowerPolicyClient>();
                ::ndk::SharedRefBase::make<PowerPolicyClient>(init_config);
        ALOGD("%s:Instantiating power policy client from launcher", __func__);
        powerPolicyClient->init();
        ALOGD("%s: Power Policy class inited, joining threadpool", __func__);
Loading