core: Add SetProperty for EchoCancelingNoiseReduction
authorClaudio Takahasi <claudio.takahasi@openbossa.org>
Tue, 23 Apr 2013 17:21:43 +0000 (14:21 -0300)
committerDenis Kenzior <denkenz@gmail.com>
Tue, 23 Apr 2013 15:30:15 +0000 (10:30 -0500)
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

index 6b15a243aeddec37c6c4a72b81ba2155d125f781..b23cc3ab97e489d2c6994f592dd267b8bdc76223 100644 (file)
@@ -217,11 +217,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 = FALSE;
+
+       __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)
@@ -241,28 +266,39 @@ 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->disable_nrec || enabled == TRUE)
+                       return __ofono_error_not_implemented(msg);
+
+               if (hf->nrec == FALSE)
+                       return dbus_message_new_method_return(msg);
+
+               hf->pending = dbus_message_ref(msg);
+               hf->driver->disable_nrec(hf, nrec_set_cb, hf);
+       } else
+               return __ofono_error_invalid_args(msg);
+
+       return NULL;
 }
 
 static void request_phone_number_cb(const struct ofono_error *error,