This patch extends SetProperty method of the Handsfree interface
allowing to disable echo canceling and noise reduction feature in
the audio gateway through a D-Bus method call. Once disabled, it
is not allowed to enable it using this procedure.
---
 src/handsfree.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 47 insertions(+), 9 deletions(-)

diff --git a/src/handsfree.c b/src/handsfree.c
index 75751e8..9487aec 100644
--- a/src/handsfree.c
+++ b/src/handsfree.c
@@ -46,6 +46,7 @@ static GSList *g_drivers = NULL;
 
 struct ofono_handsfree {
        ofono_bool_t nrec;
+       ofono_bool_t nrec_pending;
        ofono_bool_t inband_ringing;
        ofono_bool_t voice_recognition;
        ofono_bool_t voice_recognition_pending;
@@ -220,11 +221,36 @@ static void voicerec_set_cb(const struct ofono_error 
*error, void *data)
                                        &hf->voice_recognition);
 }
 
+static void nrec_set_cb(const struct ofono_error *error, void *data)
+{
+       struct ofono_handsfree *hf = data;
+       DBusConnection *conn = ofono_dbus_get_connection();
+       const char *path = __ofono_atom_get_path(hf->atom);
+
+       if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+               __ofono_dbus_pending_reply(&hf->pending,
+                                       __ofono_error_failed(hf->pending));
+               return;
+       }
+
+       hf->nrec = hf->nrec_pending;
+
+       __ofono_dbus_pending_reply(&hf->pending,
+                               dbus_message_new_method_return(hf->pending));
+
+       ofono_dbus_signal_property_changed(conn, path,
+                                       OFONO_HANDSFREE_INTERFACE,
+                                       "EchoCancelingNoiseReduction",
+                                       DBUS_TYPE_BOOLEAN,
+                                       &hf->nrec);
+}
+
 static DBusMessage *handsfree_set_property(DBusConnection *conn,
                                                DBusMessage *msg, void *data)
 {
        struct ofono_handsfree *hf = data;
        DBusMessageIter iter, var;
+       ofono_bool_t enabled;
        const char *name;
 
        if (hf->pending)
@@ -244,28 +270,40 @@ static DBusMessage *handsfree_set_property(DBusConnection 
*conn,
 
        dbus_message_iter_recurse(&iter, &var);
 
+       if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN)
+               return __ofono_error_invalid_args(msg);
+
+       dbus_message_iter_get_basic(&var, &enabled);
+
        if (g_str_equal(name, "VoiceRecognition") == TRUE) {
-               ofono_bool_t enabled;
 
                if (!hf->driver->voice_recognition)
                        return __ofono_error_not_implemented(msg);
 
-               if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN)
-                       return __ofono_error_invalid_args(msg);
-
-               dbus_message_iter_get_basic(&var, &enabled);
-
                if (hf->voice_recognition == enabled)
                        return dbus_message_new_method_return(msg);
 
                hf->voice_recognition_pending = enabled;
                hf->pending = dbus_message_ref(msg);
                hf->driver->voice_recognition(hf, enabled, voicerec_set_cb, hf);
+       } else if (g_str_equal(name, "EchoCancelingNoiseReduction") == TRUE) {
 
-               return NULL;
-       }
+               if (!(hf->ag_features & HFP_AG_FEATURE_ECNR))
+                       return __ofono_error_not_supported(msg);
 
-       return __ofono_error_invalid_args(msg);
+               if (!hf->driver->nrec || enabled == TRUE)
+                       return __ofono_error_not_implemented(msg);
+
+               if (hf->nrec == enabled)
+                       return dbus_message_new_method_return(msg);
+
+               hf->pending = dbus_message_ref(msg);
+               hf->nrec_pending = enabled;
+               hf->driver->nrec(hf, enabled, nrec_set_cb, hf);
+       } else
+               return __ofono_error_invalid_args(msg);
+
+       return NULL;
 }
 
 static void request_phone_number_cb(const struct ofono_error *error,
-- 
1.7.11.7

_______________________________________________
ofono mailing list
ofono@ofono.org
https://lists.ofono.org/mailman/listinfo/ofono

Reply via email to